import{v as ce,u as de,K as he,j as e,x as K,L as ue,I as C}from"./index-CmAiVN5e.js";import{r as i}from"./vendor-animations-CsoOZIH8.js";import{u as me}from"./useQuery-ver6bBcI.js";import{W as Q}from"./WallsService-BUXK93Tu.js";import{C as xe}from"./ConfirmationPopUp--YGd-q8F.js";import{g as S}from"./getSocialFormat-CDK45c1l.js";import{c as ge}from"./copyToClipboard-C3humaIY.js";const ve=()=>{var X,E,q,z,F;const{nickname:f}=ce();de();const O=he(),h=i.useRef(null),[d,y]=i.useState(1),[m,g]=i.useState({x:0,y:0}),[k,$]=i.useState(!1),[A,Z]=i.useState({x:0,y:0}),[I,_]=i.useState(null),[N,G]=i.useState(null),[P,D]=i.useState(null),[we,R]=i.useState(!1),[x,J]=i.useState("none"),[b,M]=i.useState(!0),[U,ee]=i.useState(!1),te=async()=>{if(P){R(!0);try{await Q.deleteWallItem(P),O.invalidateQueries({queryKey:["wall",f]}),D(null)}catch{}finally{R(!1)}}},{data:l,isLoading:V}=me({queryKey:["wall",f],queryFn:()=>Q.getWallByNickname(f||"").then(t=>t.data),enabled:!!f});i.useEffect(()=>{if(l&&!V&&!U&&h.current){ee(!0);const t=l.items||[];if(t.length>0){const s=t.slice().sort((oe,ie)=>new Date(ie.createdAt).getTime()-new Date(oe.createdAt).getTime())[0],r=h.current.getBoundingClientRect(),n=r.width/2,o=r.height/2,u=5,p=s.x+s.width/2,j=s.y+s.height/2;y(u),g({x:n-p*u,y:o-j*u})}else{const a=l.wall;if(a&&h.current){const s=h.current.getBoundingClientRect();y(1),g({x:s.width/2-a.width/2,y:s.height/2-a.height/2})}}}},[l,V,U]);const L=(t,a,s)=>{const r=Math.max(.1,Math.min(t,5));if(r!==d){if(a!==void 0&&s!==void 0){const n=(a-m.x)/d,o=(s-m.y)/d;g({x:a-n*r,y:s-o*r})}else if(h.current){const n=h.current.getBoundingClientRect(),o=n.width/2,u=n.height/2,p=(o-m.x)/d,j=(u-m.y)/d;g({x:o-p*r,y:u-j*r})}else{y(r);return}y(r)}},se=t=>{if(t.preventDefault(),!h.current)return;const s=d-t.deltaY*.001,r=h.current.getBoundingClientRect(),n=t.clientX-r.left,o=t.clientY-r.top;L(s,n,o)},ae=t=>{(x==="pan"||t.button===1)&&($(!0),Z({x:t.clientX-m.x,y:t.clientY-m.y}),t.currentTarget.setPointerCapture(t.pointerId))},re=t=>{k&&g({x:t.clientX-A.x,y:t.clientY-A.y})},W=t=>{$(!1),t.currentTarget.releasePointerCapture(t.pointerId)},B=t=>{var s;const a=N!==t;if(G(a?t:null),a){b||M(!0),setTimeout(()=>{const n=document.getElementById(`author-row-${t}`);n&&n.scrollIntoView({behavior:"smooth",block:"nearest"})},50);const r=(s=l==null?void 0:l.items)==null?void 0:s.find(n=>n.id===t);if(r&&h.current){const n=h.current.getBoundingClientRect(),o=n.width/2,u=n.height/2,p=r.x+r.width/2,j=r.y+r.height/2;g({x:o-p*d,y:u-j*d})}}},v=l==null?void 0:l.wall,c=l==null?void 0:l.streamer,w=(l==null?void 0:l.items)||[],ne=(l==null?void 0:l.isModerate)||!1,le=i.useMemo(()=>{const t={};return w.forEach(a=>{const s=a.donatorName||"Аноним";t[s]=(t[s]||0)+a.width*a.height}),Object.entries(t).sort((a,s)=>s[1]-a[1]).slice(0,5)},[w]),T=i.useMemo(()=>w.slice().sort((t,a)=>new Date(a.createdAt).getTime()-new Date(t.createdAt).getTime()),[w]);if(V)return e.jsx("div",{className:"wall-reader-loading",children:"Загрузка стены..."});if(!v||!c)return e.jsx("div",{className:"wall-reader-error",children:"Стена не найдена"});const Y=c.avatar||v.streamerAvatar,H=Y?`/img/avatars/100/${Y}`:void 0;return e.jsxs("div",{className:"wall-reader",children:[e.jsx("div",{className:"wall-reader__topbar",children:e.jsxs(K,{to:"/walls",className:"wall-reader__brand",children:[e.jsx(ue,{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(K,{to:`/d/${c.login}`,className:"wall-reader__streamer-avatar",children:H?e.jsx("img",{src:H,alt:c.login}):e.jsx("span",{children:(X=c.login)==null?void 0:X.charAt(0).toUpperCase()})}),e.jsxs("div",{className:"wall-reader__streamer-details",children:[e.jsx("div",{className:"wall-reader__streamer-name",children:c.login}),e.jsxs("div",{className:"wall-reader__streamer-socials",children:[((E=c.socials)==null?void 0:E.twitch)&&e.jsx("a",{href:S(c.socials.twitch,{type:"twitch",withProtocol:!0}),target:"_blank",rel:"noreferrer",className:"social-icon",children:e.jsx(C,{type:"twitch"})}),((q=c.socials)==null?void 0:q.youtube)&&e.jsx("a",{href:S(c.socials.youtube,{type:"youtube",withProtocol:!0}),target:"_blank",rel:"noreferrer",className:"social-icon",children:e.jsx(C,{type:"youtube"})}),((z=c.socials)==null?void 0:z.telegram)&&e.jsx("a",{href:S(c.socials.telegram,{type:"telegram",withProtocol:!0}),target:"_blank",rel:"noreferrer",className:"social-icon",children:e.jsx(C,{type:"telegram"})}),((F=c.socials)==null?void 0:F.vk)&&e.jsx("a",{href:S(c.socials.vk,{type:"vk",withProtocol:!0}),target:"_blank",rel:"noreferrer",className:"social-icon",children:e.jsx(C,{type:"vk"})})]})]})]}),e.jsxs("div",{className:"wall-reader__streamer-stats",children:["Всего закрашено: ",e.jsxs("strong",{children:[v.totalPaintedPixels.toLocaleString("ru-RU")," px"]})]})]}),e.jsxs("div",{className:"wall-reader__workspace",children:[e.jsx("div",{className:"wall-reader__viewport",ref:h,onWheel:se,onPointerDown:ae,onPointerMove:re,onPointerUp:W,onPointerLeave:W,style:{cursor:x==="pan"||k?k?"grabbing":"grab":"default"},children:e.jsxs("div",{className:"wall-reader__canvas-container",style:{width:v.width,height:v.height,transform:`translate(${m.x}px, ${m.y}px) scale(${d})`,transformOrigin:"0 0"},children:[e.jsx("div",{className:"wall-reader__canvas-bg"}),w.map(t=>{const a=N===t.id,s=I===t.id,r=a||s,n=(N||I)&&!r,o=!!t.imageUrl&&t.imageUrl!=="null"&&t.imageUrl!=="undefined"&&t.imageUrl!=="";return e.jsx("div",{className:`wall-reader__item ${r?"is-hovered":n?"is-dimmed":""}`,style:{left:t.x,top:t.y,width:t.width,height:t.height,position:"absolute",cursor:x==="pan"?"inherit":"pointer",boxSizing:"border-box",backgroundColor:o?"transparent":"rgba(255, 255, 255, 0.1)",border:o?"none":`${Math.max(1,1/d)}px dashed rgba(255, 255, 255, 0.3)`},onMouseEnter:()=>{x!=="pan"&&_(t.id)},onMouseLeave:()=>_(null),onPointerDown:()=>{x!=="pan"&&B(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:()=>L(d+.2),children:"+"}),e.jsx("button",{className:"wall-tool-btn",onClick:()=>L(d-.2),children:"-"}),e.jsx("div",{className:"wall-tool-divider"}),e.jsx("button",{className:`wall-tool-btn ${x==="pan"?"active":""}`,onClick:()=>J(x==="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"})})})]}),b&&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:()=>M(!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:le.map(([t,a],s)=>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"]})]},s))}),e.jsx("div",{className:"authors-panel__divider"}),e.jsxs("div",{className:"authors-panel__list authors-panel__list--all",children:[T.map(t=>{const a=t.createdAt?new Date(t.createdAt).toLocaleDateString("ru-RU"):"",s=t.width*t.height,r=N===t.id,n=I===t.id,o=r||n;return e.jsxs("div",{id:`author-row-${t.id}`,className:`authors-panel__row-interactive ${o?"is-active":""}`,onMouseEnter:()=>_(t.id),onMouseLeave:()=>_(null),onClick:()=>B(t.id),children:[e.jsx("span",{className:"name",children:t.donatorName||"Аноним"}),e.jsxs("div",{className:"meta",children:[e.jsxs("span",{className:"area",children:[s.toLocaleString("ru-RU")," px"]}),e.jsx("span",{className:"date",children:a}),ne&&e.jsx("button",{className:"delete-btn",title:"Удалить рисунок (модерация)",onClick:u=>{u.stopPropagation(),D(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)}),T.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:()=>ge(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 ${b?"action-btn--primary active":"action-btn--secondary"}`,onClick:()=>M(!b),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(xe,{isVisible:!!P,onClose:()=>D(null),onConfirm:te,title:"Удалить этот рисунок на стене?",text:"Это действие нельзя отменить. Площадь, занятая этим рисунком будет доступна для нового рисунка",confirmText:"Подтвердить",confirmStyle:"accent",cancelStyle:"secondary"})]})},Ce=()=>e.jsx("div",{style:{width:"100vw",height:"100vh",overflow:"hidden"},children:e.jsx(ve,{})});export{Ce as WallViewPage};