import{x as me,h as ue,O as xe,Q as ge,j as e,y as B,L as ve,I as k}from"./index-BwK72RNz.js";import{r as c}from"./vendor-animations-CsoOZIH8.js";import{u as we}from"./useQuery-DTdOygMU.js";import{W as K}from"./WallsService-DaROhOT5.js";import{C as pe}from"./ConfirmationPopUp-sRH7mJ8k.js";import{g as I}from"./getSocialFormat-sNKDLQQA.js";import{c as je}from"./copyToClipboard-BMg5jyIQ.js";const fe=()=>{var z,q,Q,F,O;const{nickname:_}=me();ue();const[Z]=xe(),N=Z.get("itemId"),G=ge(),d=c.useRef(null),[h,j]=c.useState(1),[x,v]=c.useState({x:0,y:0}),[P,R]=c.useState(!1),[W,J]=c.useState({x:0,y:0}),[M,b]=c.useState(null),[C,ee]=c.useState(N),[D,L]=c.useState(null),[ye,A]=c.useState(!1),[w,te]=c.useState("none"),[p,S]=c.useState(!0),[U,se]=c.useState(!1),ae=async()=>{if(D){A(!0);try{await K.deleteWallItem(D),G.invalidateQueries({queryKey:["wall",_]}),L(null)}catch{}finally{A(!1)}}},{data:l,isLoading:V}=we({queryKey:["wall",_],queryFn:()=>K.getWallByNickname(_||"").then(t=>t.data),enabled:!!_});c.useEffect(()=>{if(l&&!V&&!U&&d.current){se(!0);const t=l.items||[];let a=null;if(N&&(a=t.find(n=>n.id===N)),a){p||S(!0),setTimeout(()=>{const g=document.getElementById(`author-row-${a.id}`);g&&g.scrollIntoView({behavior:"smooth",block:"nearest"})},50);const n=d.current.getBoundingClientRect(),s=n.width/2,r=n.height/2,o=5,m=a.x+a.width/2,u=a.y+a.height/2;j(o),v({x:s-m*o,y:r-u*o})}else if(t.length>0){const s=t.slice().sort((de,he)=>new Date(he.createdAt).getTime()-new Date(de.createdAt).getTime())[0],r=d.current.getBoundingClientRect(),o=r.width/2,m=r.height/2,u=5,g=s.x+s.width/2,ce=s.y+s.height/2;j(u),v({x:o-g*u,y:m-ce*u})}else{const n=l.wall;if(n&&d.current){const s=d.current.getBoundingClientRect();j(1),v({x:s.width/2-n.width/2,y:s.height/2-n.height/2})}}}},[l,V,U,N,p]);const $=(t,a,n)=>{const s=Math.max(.1,Math.min(t,5));if(s!==h){if(a!==void 0&&n!==void 0){const r=(a-x.x)/h,o=(n-x.y)/h;v({x:a-r*s,y:n-o*s})}else if(d.current){const r=d.current.getBoundingClientRect(),o=r.width/2,m=r.height/2,u=(o-x.x)/h,g=(m-x.y)/h;v({x:o-u*s,y:m-g*s})}else{j(s);return}j(s)}},ne=t=>{if(t.preventDefault(),!d.current)return;const n=h-t.deltaY*.001,s=d.current.getBoundingClientRect(),r=t.clientX-s.left,o=t.clientY-s.top;$(n,r,o)},re=t=>{(w==="pan"||t.button===1)&&(R(!0),J({x:t.clientX-x.x,y:t.clientY-x.y}),t.currentTarget.setPointerCapture(t.pointerId))},oe=t=>{P&&v({x:t.clientX-W.x,y:t.clientY-W.y})},T=t=>{R(!1),t.currentTarget.releasePointerCapture(t.pointerId)},Y=t=>{var n;const a=C!==t;if(ee(a?t:null),a){p||S(!0),setTimeout(()=>{const r=document.getElementById(`author-row-${t}`);r&&r.scrollIntoView({behavior:"smooth",block:"nearest"})},50);const s=(n=l==null?void 0:l.items)==null?void 0:n.find(r=>r.id===t);if(s&&d.current){const r=d.current.getBoundingClientRect(),o=r.width/2,m=r.height/2,u=s.x+s.width/2,g=s.y+s.height/2;v({x:o-u*h,y:m-g*h})}}},f=l==null?void 0:l.wall,i=l==null?void 0:l.streamer,y=(l==null?void 0:l.items)||[],le=(l==null?void 0:l.isModerate)||!1,ie=c.useMemo(()=>{const t={};return y.forEach(a=>{const n=a.donatorName||"Ðноним";t[n]=(t[n]||0)+a.width*a.height}),Object.entries(t).sort((a,n)=>n[1]-a[1]).slice(0,5)},[y]),X=c.useMemo(()=>y.slice().sort((t,a)=>new Date(a.createdAt).getTime()-new Date(t.createdAt).getTime()),[y]);if(V)return e.jsx("div",{className:"wall-reader-loading",children:"Загрузка Ñтены..."});if(!f||!i)return e.jsx("div",{className:"wall-reader-error",children:"Стена не найдена"});const H=i.avatar||f.streamerAvatar,E=H?`/img/avatars/100/${H}`:void 0;return e.jsxs("div",{className:"wall-reader",children:[e.jsx("div",{className:"wall-reader__topbar",children:e.jsxs(B,{to:"/walls",className:"wall-reader__brand",children:[e.jsx(ve,{theme:"light"}),e.jsx("img",{src:"/design/oorno.webp",alt:"oorno",className:"header-oorno-image"})]})}),e.jsxs("div",{className:"wall-reader__streamer-info",children:[e.jsxs("div",{className:"wall-reader__streamer-profile",children:[e.jsx(B,{to:`/d/${i.login}`,className:"wall-reader__streamer-avatar",children:E?e.jsx("img",{src:E,alt:i.login}):e.jsx("span",{children:(z=i.login)==null?void 0:z.charAt(0).toUpperCase()})}),e.jsxs("div",{className:"wall-reader__streamer-details",children:[e.jsx("div",{className:"wall-reader__streamer-name",children:i.login}),e.jsxs("div",{className:"wall-reader__streamer-socials",children:[((q=i.socials)==null?void 0:q.twitch)&&e.jsx("a",{href:I(i.socials.twitch,{type:"twitch",withProtocol:!0}),target:"_blank",rel:"noreferrer",className:"social-icon",children:e.jsx(k,{type:"twitch"})}),((Q=i.socials)==null?void 0:Q.youtube)&&e.jsx("a",{href:I(i.socials.youtube,{type:"youtube",withProtocol:!0}),target:"_blank",rel:"noreferrer",className:"social-icon",children:e.jsx(k,{type:"youtube"})}),((F=i.socials)==null?void 0:F.telegram)&&e.jsx("a",{href:I(i.socials.telegram,{type:"telegram",withProtocol:!0}),target:"_blank",rel:"noreferrer",className:"social-icon",children:e.jsx(k,{type:"telegram"})}),((O=i.socials)==null?void 0:O.vk)&&e.jsx("a",{href:I(i.socials.vk,{type:"vk",withProtocol:!0}),target:"_blank",rel:"noreferrer",className:"social-icon",children:e.jsx(k,{type:"vk"})})]})]}),e.jsxs(B,{to:`/d/${i.login}`,className:"action-btn action-btn--primary",style:{height:"36px",fontSize:"14px",padding:"0 16px",marginLeft:"8px"},children:[e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})}),"ÐариÑовать"]})]}),e.jsxs("div",{className:"wall-reader__streamer-stats",children:["Ð’Ñего закрашено: ",e.jsxs("strong",{children:[f.totalPaintedPixels.toLocaleString("ru-RU")," px"]})]})]}),e.jsxs("div",{className:"wall-reader__workspace",children:[e.jsx("div",{className:"wall-reader__viewport",ref:d,onWheel:ne,onPointerDown:re,onPointerMove:oe,onPointerUp:T,onPointerLeave:T,style:{cursor:w==="pan"||P?P?"grabbing":"grab":"default"},children:e.jsxs("div",{className:"wall-reader__canvas-container",style:{width:f.width,height:f.height,transform:`translate(${x.x}px, ${x.y}px) scale(${h})`,transformOrigin:"0 0"},children:[e.jsx("div",{className:"wall-reader__canvas-bg"}),y.map(t=>{const a=C===t.id,n=M===t.id,s=a||n,r=(C||M)&&!s,o=!!t.imageUrl&&t.imageUrl!=="null"&&t.imageUrl!=="undefined"&&t.imageUrl!=="";return e.jsx("div",{className:`wall-reader__item ${s?"is-hovered":r?"is-dimmed":""}`,style:{left:t.x,top:t.y,width:t.width,height:t.height,position:"absolute",cursor:w==="pan"?"inherit":"pointer",boxSizing:"border-box",backgroundColor:o?"transparent":"rgba(255, 255, 255, 0.1)",border:o?"none":`${Math.max(1,1/h)}px dashed rgba(255, 255, 255, 0.3)`},onMouseEnter:()=>{w!=="pan"&&b(t.id)},onMouseLeave:()=>b(null),onPointerDown:()=>{w!=="pan"&&Y(t.id)},children:o&&e.jsx("img",{draggable:!1,src:`/images/donations/${t.imageUrl}`,alt:`Донат от ${t.donatorName}`,style:{width:"100%",height:"100%",display:"block",objectFit:"contain"}})},t.id)})]})}),e.jsxs("div",{className:"wall-reader__floating-left",children:[e.jsx("button",{className:"wall-tool-btn",onClick:()=>$(h+.2),children:"+"}),e.jsx("button",{className:"wall-tool-btn",onClick:()=>$(h-.2),children:"-"}),e.jsx("div",{className:"wall-tool-divider"}),e.jsx("button",{className:`wall-tool-btn ${w==="pan"?"active":""}`,onClick:()=>te(w==="pan"?"none":"pan"),children:e.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M10 9.5V5.5C10 4.67 10.67 4 11.5 4C12.33 4 13 4.67 13 5.5V11H13.5V3.5C13.5 2.67 14.17 2 15 2C15.83 2 16.5 2.67 16.5 3.5V11H17V6.5C17 5.67 17.67 5 18.5 5C19.33 5 20 5.67 20 6.5V13.84C20 17.51 16.32 21 12.35 21C8.28 21 5 18.06 5 14.39V10.5C5 9.67 5.67 9 6.5 9C7.33 9 8 9.67 8 10.5V13H8.5V8.5C8.5 7.67 9.17 7 10 7C10.83 7 11.5 7.67 11.5 8.5V9.5H10Z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),p&&e.jsx("div",{className:"wall-reader__floating-right",children:e.jsxs("div",{className:"authors-panel",children:[e.jsxs("div",{className:"authors-panel__header",children:[e.jsx("h3",{children:"Ðвторы риÑунков"}),e.jsx("button",{className:"authors-panel__close",onClick:()=>S(!1),children:e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsxs("div",{className:"authors-panel__content",children:[e.jsx("div",{className:"authors-panel__section-title",children:"ТОП-5 художников ★"}),e.jsx("div",{className:"authors-panel__list authors-panel__list--top",children:ie.map(([t,a],n)=>e.jsxs("div",{className:"authors-panel__row",children:[e.jsx("span",{className:"name",children:t}),e.jsxs("span",{className:"area",children:[a.toLocaleString("ru-RU")," px"]})]},n))}),e.jsx("div",{className:"authors-panel__divider"}),e.jsxs("div",{className:"authors-panel__list authors-panel__list--all",children:[X.map(t=>{const a=t.createdAt?new Date(t.createdAt).toLocaleDateString("ru-RU"):"",n=t.width*t.height,s=C===t.id,r=M===t.id,o=s||r;return e.jsxs("div",{id:`author-row-${t.id}`,className:`authors-panel__row-interactive ${o?"is-active":""}`,onMouseEnter:()=>b(t.id),onMouseLeave:()=>b(null),onClick:()=>Y(t.id),children:[e.jsx("span",{className:"name",children:t.donatorName||"Ðноним"}),e.jsxs("div",{className:"meta",children:[e.jsxs("span",{className:"area",children:[n.toLocaleString("ru-RU")," px"]}),e.jsx("span",{className:"date",children:a}),le&&e.jsx("button",{className:"delete-btn",title:"Удалить риÑунок (модерациÑ)",onClick:m=>{m.stopPropagation(),L(t.id)},children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M3 6h18M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2M10 11v6M14 11v6"})})})]})]},t.id)}),X.length===0&&e.jsx("div",{className:"authors-panel__empty",children:"Пока никто ничего не нариÑовал."})]})]})]})}),e.jsxs("div",{className:"wall-reader__floating-bottom",children:[e.jsxs("button",{className:"action-btn action-btn--secondary",onClick:()=>je(window.location.href),children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("circle",{cx:"18",cy:"5",r:"3"}),e.jsx("circle",{cx:"6",cy:"12",r:"3"}),e.jsx("circle",{cx:"18",cy:"19",r:"3"}),e.jsx("line",{x1:"8.59",y1:"13.51",x2:"15.42",y2:"17.49"}),e.jsx("line",{x1:"15.41",y1:"6.51",x2:"8.59",y2:"10.49"})]}),"ПоделитьÑÑ"]}),e.jsxs("button",{className:`action-btn ${p?"action-btn--primary active":"action-btn--secondary"}`,onClick:()=>S(!p),children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),e.jsx("circle",{cx:"12",cy:"7",r:"4"})]}),"Ðвторы"]})]})]}),e.jsx(pe,{isVisible:!!D,onClose:()=>L(null),onConfirm:ae,title:"Удалить Ñтот риÑунок на Ñтене?",text:"Ðто дейÑтвие Ð½ÐµÐ»ÑŒÐ·Ñ Ð¾Ñ‚Ð¼ÐµÐ½Ð¸Ñ‚ÑŒ. Площадь, занÑÑ‚Ð°Ñ Ñтим риÑунком будет доÑтупна Ð´Ð»Ñ Ð½Ð¾Ð²Ð¾Ð³Ð¾ риÑунка",confirmText:"Подтвердить",confirmStyle:"accent",cancelStyle:"secondary"})]})},Pe=()=>e.jsx("div",{style:{width:"100vw",height:"100vh",overflow:"hidden"},children:e.jsx(fe,{})});export{Pe as WallViewPage};