1import{b6 as ce,c9 as ot,bz as N,b1 as ae,c3 as it,ca as Q,c5 as w,bV as h,b4 as ve,bZ as le,bF as y,bt as e,a as me,a3 as ye,b0 as f,a8 as pe,aT as we,bw as de,v as ze,bu as Ge,r as lt,s as ct,J as je,a4 as ut,l as I,bY as _e,O as Xe,V as He,P as Be,Q as Fe,aL as be,u as We,bJ as dt,a6 as mt,ad as pt,aA as Ie}from"./index-TH6SuPE4.js";import{D as Re,a as Ke,d as Te,e as Me,b as Le,c as Oe}from"./dialog-CtTd1luY.js";import{r as ht,m as gt,a as xt,b as E,p as J,c as Ee}from"./usePlatformPosts-BKSmXED4.js";import{s as Ne}from"./storeKeys-Ba_ywMcN.js";import{p as Pe}from"./productKeys-omeP7tNf.js";import{b as Se}from"./brandKeys-CYnxj_mA.js";import{S as yt,C as Qe}from"./SignInPrompt-3cTk1F1U.js";const ft=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],Ye=ce("ArrowDown",ft);const vt=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],Je=ce("ArrowUp",vt);const bt=[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]],wt=ce("ChevronLeft",bt);const jt=[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]],Nt=ce("ChevronUp",jt);const Pt=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]],Ze=ce("Ellipsis",Pt);const St=[["path",{d:"M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z",key:"i9b6wo"}],["line",{x1:"4",x2:"4",y1:"22",y2:"15",key:"1cm3nv"}]],et=ce("Flag",St);const Ct=[["path",{d:"M16 5h6",key:"1vod17"}],["path",{d:"M19 2v6",key:"4bpg5p"}],["path",{d:"M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5",key:"1ue2ih"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}]],tt=ce("ImagePlus",Ct);const Dt=[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]],st=ce("Send",Dt),Ve=10;function fs(t){return it({queryKey:ae.collectionPosts(t??""),queryFn:async({pageParam:r})=>await N.apiPostsCollectionCollectionIdGet({collectionId:t,pageNumber:r,pageSize:Ve},{signal:AbortSignal.timeout(1e4)})??[],initialPageParam:1,getNextPageParam:(r,a,s)=>r.length===Ve?s+1:void 0,enabled:!!t,staleTime:1e3*60*5,retry:1})}function Qt(t){return ot({queryKey:ae.postComments(t??""),queryFn:async()=>await N.apiPostsIdCommentsGet({id:t},{signal:AbortSignal.timeout(1e4)})??[],enabled:!!t,staleTime:1e3*60*3,retry:1})}function at(){const t=le.getState().user;return{userId:t?.sub??void 0,userName:t?.preferred_username??t?.name??void 0,profilePictureUrl:t?.picture??""}}function kt(t){const r=Q();return w({mutationFn:async({title:a,content:s,mediaItems:o})=>{await N.apiPostsPost({postDto:{content:s,title:a,collectionId:t,user:at(),mediaItems:(o??[]).map(n=>({...n,metadata:{}})),metadata:{}}},{signal:AbortSignal.timeout(3e4)})},retry:0,onSuccess:()=>{r.invalidateQueries({queryKey:ae.collectionPosts(t)})},onError:()=>{h.error("Failed to create post. Please try again.")}})}function Ut(t,r){const a=Q(),s=ae.collectionPosts(r);return w({mutationFn:async()=>{await N.apiPostsIdDelete({id:t},{signal:AbortSignal.timeout(1e4)})},retry:0,onMutate:async()=>{await a.cancelQueries({queryKey:s});const o=a.getQueryData(s);return a.setQueryData(s,n=>n&&{...n,pages:n.pages.map(l=>l.filter(i=>i.id!==t))}),{snapshot:o}},onError:(o,n,l)=>{const i=l;i?.snapshot!==void 0&&a.setQueryData(s,i.snapshot),h.error("Failed to delete post. Please try again.")},onSuccess:()=>{h.success("Post deleted.")},onSettled:()=>{a.invalidateQueries({queryKey:s})}})}function qt(t,r){const a=Q();return w({mutationFn:async({content:s,mediaItems:o,parentCommentId:n})=>{const l={content:s,user:at(),mediaItems:(o??[]).map(i=>({...i,metadata:{}})),metadata:{}};if(n){await ve.apiCommentsPostIdCommentsCommentIdCommentsPost({postId:t,commentId:n,commentDto:l},{signal:AbortSignal.timeout(3e4)});return}await N.apiPostsIdCommentsPost({id:t,commentDto:l},{signal:AbortSignal.timeout(3e4)})},retry:0,onSuccess:()=>{a.invalidateQueries({queryKey:ae.postComments(t)}),r&&a.invalidateQueries({queryKey:r})},onError:()=>{h.error("Failed to add comment. Please try again.")}})}function At(t,r,a){const s=Q(),o=ae.postComments(t);return w({mutationFn:async()=>{await ve.apiCommentsPostIdCommentsCommentIdDelete({postId:t,commentId:r},{signal:AbortSignal.timeout(1e4)})},retry:0,onMutate:async()=>{await s.cancelQueries({queryKey:o});const n=s.getQueryData(o);return s.setQueryData(o,l=>l&&ht(l,r)),{snapshot:n}},onError:(n,l,i)=>{const d=i;d?.snapshot!==void 0&&s.setQueryData(o,d.snapshot),h.error("Failed to delete comment. Please try again.")},onSuccess:()=>{h.success("Comment deleted.")},onSettled:()=>{s.invalidateQueries({queryKey:o}),a&&s.invalidateQueries({queryKey:a})}})}function Ft(t,r){const a=t.userScore??0;let s=t.upvotes??0,o=t.downvotes??0,n;return r==="up"?a===1?(s-=1,n=0):(s+=1,a===-1&&(o-=1),n=1):a===-1?(o-=1,n=0):(o+=1,a===1&&(s-=1),n=-1),{...t,upvotes:s,downvotes:o,userScore:n}}function Et(t,r){const a=Q(),s=ae.collectionPosts(r),o=i=>{a.setQueryData(s,d=>d&&{...d,pages:d.pages.map(m=>m.map(u=>u.id===t?Ft(u,i):u))})},n=w({mutationFn:async()=>{await N.apiPostsIdUpvotePost({id:t},{signal:AbortSignal.timeout(1e4)})},retry:0,onMutate:async()=>{await a.cancelQueries({queryKey:s});const i=a.getQueryData(s);return o("up"),{snapshot:i}},onError:(i,d,m)=>{const u=m;u?.snapshot!==void 0&&a.setQueryData(s,u.snapshot),h.error("Failed to upvote. Please try again.")},onSettled:()=>{a.invalidateQueries({queryKey:s})}}),l=w({mutationFn:async()=>{await N.apiPostsIdDownvotePost({id:t},{signal:AbortSignal.timeout(1e4)})},retry:0,onMutate:async()=>{await a.cancelQueries({queryKey:s});const i=a.getQueryData(s);return o("down"),{snapshot:i}},onError:(i,d,m)=>{const u=m;u?.snapshot!==void 0&&a.setQueryData(s,u.snapshot),h.error("Failed to downvote. Please try again.")},onSettled:()=>{a.invalidateQueries({queryKey:s})}});return{upvote:n,downvote:l}}function _t(t,r){const a=Q(),s=ae.postComments(t),o=i=>{a.setQueryData(s,d=>d&>(d,r,m=>xt(m,i)))},n=w({mutationFn:async()=>{await ve.apiCommentsPostIdCommentsCommentIdUpvotePost({postId:t,commentId:r},{signal:AbortSignal.timeout(1e4)})},retry:0,onMutate:async()=>{await a.cancelQueries({queryKey:s});const i=a.getQueryData(s);return o("up"),{snapshot:i}},onError:(i,d,m)=>{const u=m;u?.snapshot!==void 0&&a.setQueryData(s,u.snapshot),h.error("Failed to upvote. Please try again.")},onSettled:()=>{a.invalidateQueries({queryKey:s})}}),l=w({mutationFn:async()=>{await ve.apiCommentsPostIdCommentsCommentIdDownvotePost({postId:t,commentId:r},{signal:AbortSignal.timeout(1e4)})},retry:0,onMutate:async()=>{await a.cancelQueries({queryKey:s});const i=a.getQueryData(s);return o("down"),{snapshot:i}},onError:(i,d,m)=>{const u=m;u?.snapshot!==void 0&&a.setQueryData(s,u.snapshot),h.error("Failed to downvote. Please try again.")},onSettled:()=>{a.invalidateQueries({queryKey:s})}});return{upvote:n,downvote:l}}function Rt(){const t=le.getState().user;return{userId:t?.sub??void 0,userName:t?.preferred_username??t?.name??void 0,profilePictureUrl:t?.picture??""}}function Kt(t){const r=Q(),a=Ne.storePosts(t);return w({mutationFn:async({title:s,content:o,mediaItems:n})=>{await N.apiPostsPost({postDto:{content:o,title:s,storeId:t,user:Rt(),mediaItems:(n??[]).map(l
1=>({...l,metadata:{}})),metadata:{}}},{signal:AbortSignal.timeout(3e4)})},retry:0,onSuccess:()=>{r.invalidateQueries({queryKey:a})},onError:()=>{h.error("Failed to create post. Please try again.")}})}function Tt(t,r){const a=Q(),s=Ne.storePosts(r);return w({mutationFn:async()=>{await N.apiPostsIdDelete({id:t},{signal:AbortSignal.timeout(1e4)})},retry:0,onMutate:async()=>{await a.cancelQueries({queryKey:s});const o=a.getQueryData(s);return a.setQueryData(s,n=>n&&{...n,pages:n.pages.map(l=>l.filter(i=>i.id!==t))}),{snapshot:o}},onError:(o,n,l)=>{const i=l;i?.snapshot!==void 0&&a.setQueryData(s,i.snapshot),h.error("Failed to delete post. Please try again.")},onSuccess:()=>{h.success("Post deleted.")},onSettled:()=>{a.invalidateQueries({queryKey:s})}})}function Mt(t,r){const a=t.userScore??0;let s=t.upvotes??0,o=t.downvotes??0,n;return r==="up"?a===1?(s-=1,n=0):(s+=1,a===-1&&(o-=1),n=1):a===-1?(o-=1,n=0):(o+=1,a===1&&(s-=1),n=-1),{...t,upvotes:s,downvotes:o,userScore:n}}function Lt(t,r){const a=Q(),s=Ne.storePosts(r),o=i=>{a.setQueryData(s,d=>d&&{...d,pages:d.pages.map(m=>m.map(u=>u.id===t?Mt(u,i):u))})},n=w({mutationFn:async()=>{await N.apiPostsIdUpvotePost({id:t},{signal:AbortSignal.timeout(1e4)})},retry:0,onMutate:async()=>{await a.cancelQueries({queryKey:s});const i=a.getQueryData(s);return o("up"),{snapshot:i}},onError:(i,d,m)=>{const u=m;u?.snapshot!==void 0&&a.setQueryData(s,u.snapshot),h.error("Failed to upvote. Please try again.")},onSettled:()=>{a.invalidateQueries({queryKey:s})}}),l=w({mutationFn:async()=>{await N.apiPostsIdDownvotePost({id:t},{signal:AbortSignal.timeout(1e4)})},retry:0,onMutate:async()=>{await a.cancelQueries({queryKey:s});const i=a.getQueryData(s);return o("down"),{snapshot:i}},onError:(i,d,m)=>{const u=m;u?.snapshot!==void 0&&a.setQueryData(s,u.snapshot),h.error("Failed to downvote. Please try again.")},onSettled:()=>{a.invalidateQueries({queryKey:s})}});return{upvote:n,downvote:l}}function Ot(){const t=le.getState().user;return{userId:t?.sub??void 0,userName:t?.preferred_username??t?.name??void 0,profilePictureUrl:t?.picture??""}}function $t(t){const r=Q(),a=Pe.productPosts(t.productId);return w({mutationFn:async({title:s,content:o,mediaItems:n})=>{await N.apiPostsPost({postDto:{content:o,title:s,productData:{productId:t.productId,name:t.name??void 0,imageUrl:t.imageUrl??void 0},user:Ot(),mediaItems:(n??[]).map(l=>({...l,metadata:{}})),metadata:{}}},{signal:AbortSignal.timeout(3e4)})},retry:0,onSuccess:()=>{r.invalidateQueries({queryKey:a})},onError:()=>{h.error("Failed to create post. Please try again.")}})}function It(t,r){const a=Q(),s=Pe.productPosts(r);return w({mutationFn:async()=>{await N.apiPostsIdDelete({id:t},{signal:AbortSignal.timeout(1e4)})},retry:0,onMutate:async()=>{await a.cancelQueries({queryKey:s});const o=a.getQueryData(s);return a.setQueryData(s,n=>n&&{...n,pages:n.pages.map(l=>l.filter(i=>i.id!==t))}),{snapshot:o}},onError:(o,n,l)=>{const i=l;i?.snapshot!==void 0&&a.setQueryData(s,i.snapshot),h.error("Failed to delete post. Please try again.")},onSuccess:()=>{h.success("Post deleted.")},onSettled:()=>{a.invalidateQueries({queryKey:s})}})}function Vt(t,r){const a=t.userScore??0;let s=t.upvotes??0,o=t.downvotes??0,n;return r==="up"?a===1?(s-=1,n=0):(s+=1,a===-1&&(o-=1),n=1):a===-1?(o-=1,n=0):(o+=1,a===1&&(s-=1),n=-1),{...t,upvotes:s,downvotes:o,userScore:n}}function zt(t,r){const a=Q(),s=Pe.productPosts(r),o=i=>{a.setQueryData(s,d=>d&&{...d,pages:d.pages.map(m=>m.map(u=>u.id===t?Vt(u,i):u))})},n=w({mutationFn:async()=>{await N.apiPostsIdUpvotePost({id:t},{signal:AbortSignal.timeout(1e4)})},retry:0,onMutate:async()=>{await a.cancelQueries({queryKey:s});const i=a.getQueryData(s);return o("up"),{snapshot:i}},onError:(i,d,m)=>{const u=m;u?.snapshot!==void 0&&a.setQueryData(s,u.snapshot),h.error("Failed to upvote. Please try again.")},onSettled:()=>{a.invalidateQueries({queryKey:s})}}),l=w({mutationFn:async()=>{await N.apiPostsIdDownvotePost({id:t},{signal:AbortSignal.timeout(1e4)})},retry:0,onMutate:async()=>{await a.cancelQueries({queryKey:s});const i=a.getQueryData(s);return o("down"),{snapshot:i}},onError:(i,d,m)=>{const u=m;u?.snapshot!==void 0&&a.setQueryData(s,u.snapshot),h.error("Failed to downvote. Please try again.")},onSettled:()=>{a.invalidateQueries({queryKey:s})}});return{upvote:n,downvote:l}}function Gt(){const t=le.getState().user;return{userId:t?.sub??void 0,userName:t?.preferred_username??t?.name??void 0,profilePictureUrl:t?.picture??""}}function Xt(t){const r=Q(),a=Se.brandPosts(t);return w({mutationFn:async({title:s,content:o,mediaItems:n})=>{await N.apiPostsPost({postDto:{content:o,title:s,brandId:t,user:Gt(),mediaItems:(n??[]).map(l
1=>({...l,metadata:{}})),metadata:{}}},{signal:AbortSignal.timeout(3e4)})},retry:0,onSuccess:()=>{r.invalidateQueries({queryKey:a})},onError:()=>{h.error("Failed to create post. Please try again.")}})}function Ht(t,r){const a=Q(),s=Se.brandPosts(r);return w({mutationFn:async()=>{await N.apiPostsIdDelete({id:t},{signal:AbortSignal.timeout(1e4)})},retry:0,onMutate:async()=>{await a.cancelQueries({queryKey:s});const o=a.getQueryData(s);return a.setQueryData(s,n=>n&&{...n,pages:n.pages.map(l=>l.filter(i=>i.id!==t))}),{snapshot:o}},onError:(o,n,l)=>{const i=l;i?.snapshot!==void 0&&a.setQueryData(s,i.snapshot),h.error("Failed to delete post. Please try again.")},onSuccess:()=>{h.success("Post deleted.")},onSettled:()=>{a.invalidateQueries({queryKey:s})}})}function Bt(t,r){const a=t.userScore??0;let s=t.upvotes??0,o=t.downvotes??0,n;return r==="up"?a===1?(s-=1,n=0):(s+=1,a===-1&&(o-=1),n=1):a===-1?(o-=1,n=0):(o+=1,a===1&&(s-=1),n=-1),{...t,upvotes:s,downvotes:o,userScore:n}}function Wt(t,r){const a=Q(),s=Se.brandPosts(r),o=i=>{a.setQueryData(s,d=>d&&{...d,pages:d.pages.map(m=>m.map(u=>u.id===t?Bt(u,i):u))})},n=w({mutationFn:async()=>{await N.apiPostsIdUpvotePost({id:t},{signal:AbortSignal.timeout(1e4)})},retry:0,onMutate:async()=>{await a.cancelQueries({queryKey:s});const i=a.getQueryData(s);return o("up"),{snapshot:i}},onError:(i,d,m)=>{const u=m;u?.snapshot!==void 0&&a.setQueryData(s,u.snapshot),h.error("Failed to upvote. Please try again.")},onSettled:()=>{a.invalidateQueries({queryKey:s})}}),l=w({mutationFn:async()=>{await N.apiPostsIdDownvotePost({id:t},{signal:AbortSignal.timeout(1e4)})},retry:0,onMutate:async()=>{await a.cancelQueries({queryKey:s});const i=a.getQueryData(s);return o("down"),{snapshot:i}},onError:(i,d,m)=>{const u=m;u?.snapshot!==void 0&&a.setQueryData(s,u.snapshot),h.error("Failed to downvote. Please try again.")},onSettled:()=>{a.invalidateQueries({queryKey:s})}});return{upvote:n,downvote:l}}function Yt(t,r){const a=t.userScore??0;let s=t.upvotes??0,o=t.downvotes??0,n;return r==="up"?a===1?(s-=1,n=0):(s+=1,a===-1&&(o-=1),n=1):a===-1?(o-=1,n=0):(o+=1,a===1&&(s-=1),n=-1),{...t,upvotes:s,downvotes:o,userScore:n}}function Jt(t,r,a){t.setQueryData(E,s=>s&&{...s,pages:s.pages.map(o=>o.map(n=>n.id===r?a(n):n))}),t.setQueryData(J(r),s=>s&&a(s))}function Zt(t){const r=Q();return w({mutationFn:async()=>{await N.apiPostsIdDelete({id:t},{signal:AbortSignal.timeout(1e4)})},retry:0,onMutate:async()=>{await r.cancelQueries({queryKey:E});const a=r.getQueryData(E);return r.setQueryData(E,s=>s&&{...s,pages:s.pages.map(o=>o.filter(n=>n.id!==t))}),{snapshot:a}},onError:(a,s,o)=>{const n=o;n?.snapshot!==void 0&&r.setQueryData(E,n.snapshot),h.error("Failed to delete post. Please try again.")},onSuccess:()=>{h.success("Post deleted."),r.removeQueries({queryKey:J(t)})},onSettled:()=>{r.invalidateQueries({queryKey:E})}})}function es(t){const r=Q(),a=n=>{Jt(r,t,l=>Yt(l,n))},s=w({mutationFn:async()=>{await N.apiPostsIdUpvotePost({id:t},{signal:AbortSignal.timeout(1e4)})},retry:0,onMutate:async()=>{await r.cancelQueries({queryKey:E}),t&&await r.cancelQueries({queryKey:J(t)});const n=r.getQueryData(E),l=t?r.getQueryData(J(t)):void 0;return a("up"),{listSnapshot:n,detailSnapshot:l}},onError:(n,l,i)=>{const d=i;d?.listSnapshot!==void 0&&r.setQueryData(E,d.listSnapshot),t&&d?.detailSnapshot!==void 0&&r.setQueryData(J(t),d.detailSnapshot),h.error("Failed to upvote. Please try again.")},onSettled:()=>{r.invalidateQueries({queryKey:E}),t&&r.invalidateQueries({queryKey:J(t)})}}),o=w({mutationFn:async()=>{await N.apiPostsIdDownvotePost({id:t},{signal:AbortSignal.timeout(1e4)})},retry:0,onMutate:async()=>{await r.cancelQueries({queryKey:E}),t&&await r.cancelQueries({queryKey:J(t)});const n=r.getQueryData(E),l=t?r.getQueryData(J(t)):void 0;return a("down"),{listSnapshot:n,detailSnapshot:l}},onError:(n,l,i)=>{const d=i;d?.listSnapshot!==void 0&&r.setQueryData(E,d.listSnapshot),t&&d?.detailSnapshot!==void 0&&r.setQueryData(J(t),d.detailSnapshot),h.error("Failed to downvote. Please try again.")},onSettled:()=>{r.invalidateQueries({queryKey:E}),t&&r.invalidateQueries({queryKey:J(t)})}});return{upvote:s,downvote:o}}const ke=1e4,Ue=120,fe=6,ts="image/jpeg,image/png,image/webp,image/gif";function vs({collectionId:t,storeId:r,productId:a,brandId:s,productName:o,productImageUrl:n,canView:l=!0}){const i=le(P=>P.user),d=le(P=>P.isAuthenticated()),[m,u]=y.useState(""),[x,v]=y.useState(""),[c,g]=y.useState([]),[V,k]=y.useState(!1),[j,A]=y.useState(null),[_,F]=y.useState(null),[Z,C]=y.useState(null),T=y.useRef(null),M=y.useRef(m),B=y.useRef(x);M.current=m,B.current=x;const W=kt(t??""),ee=Kt(r??""),z=$t({productId:a??"",name:o,imageUrl:n}),ue=Xt(s??""),L=a?z:s?ue:r?ee:W,{mutate:p,isPending:S}=L,G=V||m.length>0||x.length>0||c.length>0,D=c.some(P=>P.uploading),te=!S&&!D&&m.trim().length>0&&x.trim().length>0,U=()=>
1{c.forEach(P=>URL.revokeObjectURL(P.previewUrl)),u(""),v(""),g([]),k(!1),A(null),F(null),C(null)},se=y.useCallback(async P=>{const O=Array.from(P.target.files??[]);if(!O.length)return;P.target.value="";const H=fe-c.length,K=O.slice(0,H);O.length>H&&h.error(`Max ${fe} images per post.`);const oe=K.map(q=>({previewUrl:URL.createObjectURL(q),remoteUrl:null,uploading:!0,fileName:q.name,mediaType:q.type}));g(q=>[...q,...oe]),await Promise.all(K.map(async(q,$)=>{const ge=oe[$].previewUrl;try{const xe=await Ge.apiMediaUploadPost({file:q,mediaType:q.type},{signal:AbortSignal.timeout(3e4)});g(b=>b.map(Y=>Y.previewUrl===ge?{...Y,remoteUrl:xe,uploading:!1}:Y))}catch{h.error(`Failed to upload "${q.name}". Removed.`),g(xe=>{const b=xe.filter(Y=>Y.previewUrl!==ge);return URL.revokeObjectURL(ge),b})}}))},[c.length]),ne=P=>{g(O=>{const H=O.filter(K=>K.previewUrl!==P);return URL.revokeObjectURL(P),H})},re=P=>{if(P.preventDefault(),!te)return;const O=m.trim(),H=x.trim();let K=!0;if(O?O.length>Ue?(A(`Title must be ${Ue} characters or fewer.`),K=!1):A(null):(A("Title is required."),K=!1),H?H.length>ke?(F(`Content must be ${ke.toLocaleString()} characters or fewer.`),K=!1):F(null):(F("Post content cannot be empty."),K=!1),!K)return;C(null);const oe=M.current,q=B.current;p({title:O,content:H,mediaItems:c.filter($=>$.remoteUrl!==null).map($=>({fileName:$.fileName,fileUrl:$.remoteUrl,mediaType:$.mediaType}))},{onSuccess:()=>U(),onError:$=>{u(oe),v(q),C($.message??"Failed to post. Please try again.")}})};if(!d)return e.jsx(yt,{signInHref:"/auth/signin",className:"max-w-full mx-0 shadow-sm"});if(!l)return null;const X=i?.preferred_username??i?.name??"You",R=i?.picture??null,he=ke-x.length,De=he<200;return e.jsx(lt,{className:"border border-slate-200 bg-white shadow-md rounded-2xl overflow-hidden",children:e.jsx(ct,{className:"p-0",children:e.jsxs("form",{onSubmit:re,noValidate:!0,children:[e.jsxs("div",{className:"flex items-start gap-3 px-4 pt-4 pb-3",children:[e.jsx("div",{className:"flex-shrink-0",children:R?e.jsx(ye,{src:R,alt:X,width:40,height:40,className:"rounded-full h-10 w-10 object-cover ring-2 ring-slate-100"}):e.jsx("div",{className:"h-10 w-10 rounded-full bg-gradient-to-br from-snag-primary/20 to-snag-blue/20 flex items-center justify-center ring-2 ring-slate-100",children:e.jsx(je,{className:"h-6 w-6 text-snag-primary/60","aria-hidden":"true"})})}),e.jsxs("div",{className:"flex-1 min-w-0 space-y-2.5",children:[e.jsx("p",{className:"text-xs font-semibold text-snag-primary",children:X}),e.jsxs("div",{children:[e.jsx(ut,{value:m,onChange:P=>{u(P.target.value),j&&A(null),V||k(!0)},onFocus:()=>k(!0),placeholder:"Give your post a titleâ¦",maxLength:Ue+20,disabled:S,"aria-label":"Post title","aria-invalid":!!j,className:f("border-0 border-b rounded-none shadow-none px-0 text-[15px] font-semibold placeholder:text-slate-400 focus-visible:ring-0 focus-visible:border-snag-primary/50 bg-transparent h-auto py-1",j&&"border-snag-red")}),j&&e.jsxs("p",{role:"alert",className:"text-xs text-snag-red mt-0.5 flex items-center gap-1",children:[e.jsx(Qe,{className:"h-3 w-3"})," ",j]})]}),e.jsx(me,{children:G&&e.jsxs(de.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.16},className:"overflow-hidden",children:[e.jsx("textarea",{value:x,onChange:P=>{v(P.target.value),_&&F(null)},onFocus:()=>k(!0),placeholder:"What do you want to share about this collection?",rows:4,disabled:S,"aria-label":"Post content","aria-invalid":!!_,className:f("w-full resize-none bg-transparent text-sm text-slate-700 placeholder:text-slate-400 outline-none leading-relaxed mt-1","disabled:opacity-50")}),e.jsxs("div",{className:"flex items-center justify-between mt-0.5",children:[_?e.jsxs("p",{role:"alert",className:"text-xs text-snag-red flex items-center gap-1",children:[e.jsx(Qe,{className:"h-3 w-3"})," ",_]}):e.jsx("span",{}),e.jsx("span",{className:f("text-xs tabular-nums",De?"text-snag-orange font-medium":"text-muted-foreground",he<0&&"text-snag-red font-semibold"),children:he.toLocaleString()})]})]})})]})]}),e.jsx(me,{children:c.length>0&&e.jsx(de.div,{initial:{opacity:0,height:0}
1,animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"px-4 pb-3 max-w-[50%]",children:e.jsx(Ce,{images:c,onRemove:ne,editable:!0})})}),e.jsx(me,{children:Z&&e.jsxs(de.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0},role:"alert",className:"mx-4 mb-3 flex items-center gap-2 rounded-lg bg-destructive/10 px-3 py-2 text-xs text-destructive",children:[e.jsx(Qe,{className:"h-3.5 w-3.5 flex-shrink-0"}),Z]})}),e.jsx(me,{children:G&&e.jsxs(de.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.12},className:"flex items-center justify-between gap-3 border-t border-slate-100 px-4 py-2.5 bg-slate-50/70",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("input",{ref:T,type:"file",accept:ts,multiple:!0,className:"sr-only",onChange:se,"aria-label":"Attach images"}),e.jsxs(I,{type:"button",variant:"ghost",size:"sm",disabled:S||c.length>=fe,onClick:()=>T.current?.click(),className:"h-8 px-2.5 gap-1.5 text-xs text-slate-500 hover:text-snag-primary hover:bg-snag-primary/5",title:`Add images (${c.length}/${fe})`,children:[e.jsx(tt,{className:"h-4 w-4","aria-hidden":"true"}),e.jsx("span",{className:"hidden sm:inline",children:"Photo"}),c.length>0&&e.jsx("span",{className:"ml-0.5 rounded-full bg-snag-primary text-white text-[10px] font-bold h-4 w-4 flex items-center justify-center",children:c.length})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(I,{type:"button",variant:"ghost",size:"sm",onClick:U,disabled:S,className:"h-8 px-2 text-xs text-slate-500 hover:text-slate-700 gap-1",children:[e.jsx(we,{className:"h-3.5 w-3.5"}),"Discard"]}),e.jsx(I,{type:"submit",size:"sm",disabled:!te,className:"h-8 px-4 gap-1.5 text-xs font-semibold bg-snag-primary text-white hover:bg-snag-primary/90 disabled:opacity-50",children:S||D?e.jsxs(e.Fragment,{children:[e.jsx(pe,{className:"h-3.5 w-3.5 animate-spin"}),D?"Uploadingâ¦":"Postingâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(st,{className:"h-3.5 w-3.5"}),"Post"]})})]})]})})]})})})}function ie({item:t,idx:r,totalCount:a,displayCount:s,editable:o,onRemove:n,onOpen:l,tileClass:i}){const d=r===s-1&&a>s,m=a-s+1;return e.jsxs("div",{className:f("relative overflow-hidden rounded-lg bg-slate-100 group",i,!o&&!t.uploading?"cursor-pointer":""),onClick:()=>{!o&&!t.uploading&&l(r)},role:!o&&!t.uploading?"button":void 0,tabIndex:!o&&!t.uploading?0:void 0,onKeyDown:u=>{!o&&!t.uploading&&(u.key==="Enter"||u.key===" ")&&(u.preventDefault(),l(r))},"aria-label":o?void 0:`View image ${r+1}`,children:[e.jsx(ye,{src:t.url,alt:t.alt,fill:!0,className:f("object-cover transition-all duration-200",t.uploading?"opacity-40":"opacity-100",!o&&!t.uploading?"group-hover:scale-[1.02]":"")}),!o&&!t.uploading&&e.jsx("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/10 transition-colors duration-150 pointer-events-none"}),t.uploading&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/20",children:e.jsx(pe,{className:"h-5 w-5 text-white animate-spin"})}),d&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/55",children:e.jsxs("span",{className:"text-white font-bold text-xl",children:["+",m]})}),o&&n&&!t.uploading&&e.jsx("button",{type:"button",onClick:u=>{u.stopPropagation(),n(t.previewUrl??t.url)},className:"absolute top-1 right-1 h-5 w-5 rounded-full bg-black/60 text-white flex items-center justify-center hover:bg-black/80 transition-colors opacity-0 group-hover:opacity-100 z-10","aria-label":"Remove image",children:e.jsx(we,{className:"h-3 w-3"})})]})}function ss({items:t,index:r,onClose:a,onPrev:s,onNext:o,onGoTo:n}){return y.useEffect(()=>{const l=i=>{i.key==="Escape"&&a(),i.key==="ArrowLeft"&&s(),i.key==="ArrowRight"&&o()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[a,s,o]),e.jsxs(de.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},transition:{duration:.18},className:"fixed inset-0 z-50 flex items-center justify-center bg-black/90",onClick:a,role:"dialog","aria-modal":"true","aria-label":"Image viewer",children:[e.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),a()},className:"absolute top-4 right-4 z-10 h-9 w-9 rounded-full bg-white/10 hover:bg-white/20 text-white flex items-center justify-center transition-colors","aria-label":"Close image viewer",children:e.jsx(we,{className:"h-5 w-5"})}),t.length>1&&e.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),s()},className:"absolute left-4 z-10 h-10 w-10 rounded-full bg-white/10 hover:bg-white/25 text-white flex items-center justify-center transition-colors","aria-label":"Previous image",children:e.jsx(wt,{className:"h-6 w-6"})}),e.jsx(de.div,{initial:{opacity:0,scale:.96},animate:{opacity:1,scale:1},exit:{opacity:0},transition:{duration:.15},className:"relative",onClick:l=>l.stopPropagation(),children:e.jsx("img",{src:t[r].url,alt:t[r].alt,className:"max-h-[90vh] max-w-[90vw] rounded-xl object-contain shadow-2xl"})},r),t.length>1&&e.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),o()},className:"absolute right-4 z-10 h-10 w-10 rounded-full bg-white/10 hover:bg-white/25 text-white flex items-center justify-center transition-colors","aria-label":"Next image",children:e.jsx(ze,{className:"h-6 w-6"})}),t.length>1&&e.jsxs("div",{className:"absolute bottom-4 left-1/2 -translate-x-1/2 flex flex-col items-center gap-2",children:[e.jsxs("span",{className:"text-white/80 text-sm font-medium tabular-nums",children:[r+1," / ",t.length]}),e.jsx("div",{className:"flex gap-1.5",children:t.map((l,i)=>e.jsx("button",{type:"button",onClick:d=>{d.stopPropagation(),n(i)},className:f("h-1.5 rounded-full transition-all",i===r?"w-4 bg-white":"w-1.5 bg-white/40 hover:bg-white/70"),"aria-label":`Go to image ${i+1}`},i))})]})]},"lightbox")}function Ce({images:t,onRemove:r,editable:a=!1}){const[s,o]=y.useState(null),n=t.length;if(n===0)return null;const l=t.map(c=>({url:c.url??c.previewUrl??"",uploading:c.uploading??!1,previewUrl:c.previewUrl,alt:c.alt??c.fileName??"Image"})),i=Math.min(n,6),d=c=>{a||o(c)},m=()=>
1o(null),u=()=>o(c=>c!==null?(c-1+n)%n:null),x=()=>o(c=>c!==null?(c+1)%n:null);let v;return n===1?v=e.jsx("div",{className:"w-full",children:e.jsx(ie,{item:l[0],idx:0,totalCount:n,displayCount:i,editable:a,onRemove:r,onOpen:d,tileClass:"aspect-video w-full"})}):n===2?v=e.jsx("div",{className:"grid grid-cols-2 gap-1",children:l.slice(0,2).map((c,g)=>e.jsx(ie,{item:c,idx:g,totalCount:n,displayCount:i,editable:a,onRemove:r,onOpen:d,tileClass:"aspect-square"},c.previewUrl??c.url??g))}):n===3?v=e.jsxs("div",{className:"grid grid-cols-2 gap-1",style:{gridTemplateRows:"auto"},children:[e.jsx(ie,{item:l[0],idx:0,totalCount:n,displayCount:i,editable:a,onRemove:r,onOpen:d,tileClass:"row-span-2 aspect-square"}),l.slice(1,3).map((c,g)=>e.jsx(ie,{item:c,idx:g+1,totalCount:n,displayCount:i,editable:a,onRemove:r,onOpen:d,tileClass:"aspect-square"},c.previewUrl??c.url??g))]}):n===4?v=e.jsx("div",{className:"grid grid-cols-2 gap-1",children:l.slice(0,4).map((c,g)=>e.jsx(ie,{item:c,idx:g,totalCount:n,displayCount:i,editable:a,onRemove:r,onOpen:d,tileClass:"aspect-square"},c.previewUrl??c.url??g))}):n===5?v=e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("div",{className:"grid grid-cols-2 gap-1",children:l.slice(0,2).map((c,g)=>e.jsx(ie,{item:c,idx:g,totalCount:n,displayCount:i,editable:a,onRemove:r,onOpen:d,tileClass:"aspect-square"},c.previewUrl??c.url??g))}),e.jsx("div",{className:"grid grid-cols-3 gap-1",children:l.slice(2,5).map((c,g)=>e.jsx(ie,{item:c,idx:g+2,totalCount:n,displayCount:i,editable:a,onRemove:r,onOpen:d,tileClass:"aspect-square"},c.previewUrl??c.url??g))})]}):v=e.jsx("div",{className:"grid grid-cols-3 gap-1",children:l.slice(0,6).map((c,g)=>e.jsx(ie,{item:c,idx:g,totalCount:n,displayCount:i,editable:a,onRemove:r,onOpen:d,tileClass:"aspect-square"},c.previewUrl??c.url??g))}),e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-full rounded-xl overflow-hidden",children:v}),e.jsx(me,{children:s!==null&&e.jsx(ss,{items:l,index:s,onClose:m,onPrev:u,onNext:x,onGoTo:o})})]})}const qe=5e3,Ae=4,as="image/jpeg,image/png,image/webp,image/gif";function nt({postId:t,boardQueryKey:r,parentCommentId:a,placeholder:s="Write a commentâ¦",autoFocus:o=!1,onCancel:n,onSuccess:l}){const i=le(p=>p.user),{isAuthenticated:d,signIn:m}=_e(),[u,x]=y.useState(""),[v,c]=y.useState([]),[g,V]=y.useState(!1),[k,j]=y.useState(null),A=y.useRef(null),_=y.useRef(null),F=y.useRef(u);F.current=u,y.useEffect(()=>{o&&_.current?.focus()},[o]);const{mutate:Z,isPending:C}=qt(t,r),T=v.some(p=>p.uploading),M=!C&&!T&&u.trim().length>0,B=y.useCallback(async p=>{const S=Array.from(p.target.files??[]);if(!S.length)return;p.target.value="";const G=Ae-v.length,D=S.slice(0,G);S.length>G&&h.error(`Max ${Ae} images per comment.`);const te=D.map(U=>({previewUrl:URL.createObjectURL(U),remoteUrl:null,uploading:!0,fileName:U.name,mediaType:U.type}));c(U=>[...U,...te]),await Promise.all(D.map(async(U,se)=>{const ne=te[se].previewUrl;try{const re=await Ge.apiMediaUploadPost({file:U,mediaType:U.type},{signal:AbortSignal.timeout(3e4)});c(X=>X.map(R=>R.previewUrl===ne?{...R,remoteUrl:re,uploading:!1}:R))}catch{h.error(`Failed to upload "${U.name}".`),c(re=>{const X=re.filter(R=>R.previewUrl!==ne);return URL.revokeObjectURL(ne),X})}}))},[v.length]);if(!d)return e.jsxs("p",{className:"text-xs text-muted-foreground",children:[e.jsx("button",{type:"button",onClick:()=>m(),className:"font-medium text-snag-primary hover:underline",children:"Sign in"})," ","to leave a comment."]});const W=p=>{c(S=>{const G=S.filter(D=>D.previewUrl!==p);return URL.revokeObjectURL(p),G})},ee=p=>{if(p.preventDefault(),!M)return;const S=u.trim();if(S.length>qe){j(`Comment must be ${qe.toLocaleString()} characters or fewer.`);return}j(null);const G=F.current;Z({content:S,parentCommentId:a,mediaItems:v.filter(D=>D.remoteUrl!==null).map(D=>({fileName:D.fileName,fileUrl:D.remoteUrl,mediaType:D.mediaType}))},{onSuccess:()=>{v.forEach(D=>{URL.revokeObjectURL(D.previewUrl)}),x(""),c([]),V(!1),l?.()},onError:()=>{x(G)}})},z=i?.picture??null,ue=i?.preferred_username??i?.name??"You",L=g||u.length>0||v.length>0||o||!!a;return e.jsxs("form",{onSubmit:ee,noValidate:!0,className:"flex gap-2.5",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:z?e.jsx(ye,{src:z,alt:ue,width:28,height:28,className:"rounded-full h-7 w-7 object-cover"}):e.jsx(je,{className:"h-7 w-7 text-muted-foreground","aria-hidden":"true"})}),e.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[e.jsxs("div",{className:f("rounded-xl border bg-white transition-shadow",L?"border-slate-200 shadow-sm":"border-slate-200"),children:[e.jsx("textarea",{ref:_,value:u,onChange:p=>{x(p.target.value),k&&j(null)},onFocus:()=>V(!0),placeholder:s,rows:L?3:1,maxLength:qe+100,disabled:C,"aria-label":s,className:f("w-full resize-none bg-transparent text-sm text-slate-700 placeholder:text-slate-400 outline-none px-3 pt-2 leading-relaxed rounded-xl","disabled:opacity-50",!L&&"pb-2")}),v.length>0&&e.jsx("div",{className:"px-3 pb-2",children:e.jsx(Ce,{images:v,onRemove:W,editable:!0})}),L&&e.jsxs("div",{className:"flex items-center justify-between px-2 pb-1.5 pt-0.5 border-t border-slate-100",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("input",{ref:A,type:"file",accept:as,multiple:!0,className:"sr-only",onChange:B,"aria-label":"Attach images"}
1),e.jsx(I,{type:"button",variant:"ghost",size:"sm",disabled:C||v.length>=Ae,onClick:()=>A.current?.click(),className:"h-7 w-7 p-0 text-slate-400 hover:text-snag-primary hover:bg-snag-primary/5",title:"Add images",children:e.jsx(tt,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[(u.length>0||n)&&e.jsxs(I,{type:"button",variant:"ghost",size:"sm",onClick:()=>{x(""),V(!1),n?.()},disabled:C,className:"h-6 px-2 text-[11px] text-slate-400 hover:text-slate-600",children:[e.jsx(we,{className:"h-3 w-3 mr-0.5"}),n?"Cancel":"Clear"]}),e.jsx(I,{type:"submit",size:"sm",disabled:!M,className:"h-7 px-3 gap-1 text-[11px] font-semibold bg-snag-primary text-white hover:bg-snag-primary/90 disabled:opacity-40",children:C||T?e.jsx(pe,{className:"h-3 w-3 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(st,{className:"h-3 w-3"}),"Reply"]})})]})]})]}),k&&e.jsx("p",{role:"alert",className:"text-xs text-snag-red px-1",children:k})]})]})}const ns=4;function rt({comment:t,postId:r,currentUserId:a,boardQueryKey:s,depth:o=0}){const[n,l]=y.useState(!1),[i,d]=y.useState(!1),[m,u]=y.useState(!1),{isAuthenticated:x,signIn:v}=_e(),c=At(r,t.id??"",s),{upvote:g,downvote:V}=_t(r,t.id??""),k=t.user?.userName??"Someone",j=t.user?.profilePictureUrl??null,A=t.createdAt?new Date(t.createdAt).toLocaleDateString("en-US",{month:"short",day:"numeric"}):"",_=(t.mediaItems??[]).filter(p=>p.fileUrl&&p.mediaType?.startsWith("image/")).map(p=>({url:p.fileUrl??"",alt:p.fileName??void 0})),F=t.content==="[DELETED]",Z=!!a&&t.user?.userId===a&&!F,C=t.userScore??0,T=C>0,M=C<0,B=(t.upvotes??0)-(t.downvotes??0),W=g.isPending||V.isPending,ee=t.replies??[],z=Ee(ee),ue=()=>{c.mutate(void 0,{onSuccess:()=>l(!1)})},L=p=>{if(!x){v();return}p()};return e.jsxs("li",{children:[e.jsxs("div",{className:"flex gap-2.5",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:j?e.jsx(ye,{src:j,alt:k,width:28,height:28,className:"rounded-full h-7 w-7 object-cover"}):e.jsx(je,{className:"h-7 w-7 text-muted-foreground","aria-hidden":"true"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"group relative bg-white rounded-xl px-3 py-2 shadow-sm border border-slate-100",children:[e.jsxs("div",{className:"flex items-baseline gap-2 mb-0.5 pr-6",children:[e.jsx("span",{className:"text-xs font-semibold text-snag-primary",children:k}),A&&e.jsx("span",{className:"text-[10px] text-muted-foreground",children:A})]}),e.jsx("p",{className:"text-sm text-slate-700 leading-relaxed",children:t.content}),Z&&e.jsx("div",{className:"absolute top-1.5 right-1.5",children:e.jsxs(Xe,{children:[e.jsx(He,{asChild:!0,children:e.jsx("button",{type:"button",className:"h-6 w-6 rounded-full flex items-center justify-center text-slate-400 hover:bg-slate-100 hover:text-slate-600 transition-colors opacity-0 group-hover:opacity-100 focus-visible:opacity-100","aria-label":"Comment options",children:e.jsx(Ze,{className:"h-3.5 w-3.5"})})}),e.jsx(Be,{align:"end",className:"w-40",children:e.jsxs(Fe,{variant:"destructive",onSelect:p=>{p.preventDefault(),l(!0)},children:[e.jsx(be,{className:"h-4 w-4"}),"Delete comment"]})})]})})]}),_.length>0&&e.jsx("div",{className:"mt-1.5 max-w-xs",children:e.jsx(Ce,{images:_})}),(!F||z>0)&&e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-0.5",children:[!F&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>L(()=>g.mutate()),disabled:W,"aria-label":x?T?"Remove upvote":"Upvote":"Sign in to vote","aria-pressed":T,title:x?void 0:"Sign in to vote",className:f("h-6 w-6 rounded-full flex items-center justify-center transition-all cursor-pointer",x?T?"bg-snag-primary/10 text-snag-primary":"hover:bg-snag-primary/10 hover:text-snag-primary text-slate-400":"text-slate-400 hover:bg-snag-primary/10 hover:text-snag-primary",W&&"opacity-50 cursor-not-allowed"),children:e.jsx(Je,{className:f("h-3.5 w-3.5",T&&"fill-current")})}),e.jsx("span",{className:f("min-w-[1.25rem] text-center text-[11px] font-bold tabular-nums leading-none",B>0?"text-snag-primary":B<0?"text-snag-red":"text-slate-400"),children:B}),e.jsx("button",{type:"button",onClick:()=>L(()=>V.mutate()),disabled:W,"aria-label":x?M?"Remove downvote":"Downvote":"Sign in to vote","aria-pressed":M,title:x?void 0:"Sign in to vote",className:f("h-6 w-6 rounded-full flex items-center justify-center transition-all cursor-pointer",x?M?"bg-snag-red/10 text-snag-red":"hover:bg-snag-red/10 hover:text-snag-red text-slate-400":"text-slate-400 hover:bg-snag-red/10 hover:text-snag-red",W&&"opacity-50 cursor-not-allowed"),children:e.jsx(Ye,{className:f("h-3.5 w-3.5",M&&"fill-current")})}),e.jsx("button",{type:"button",onClick:()=>L(()=>d(p=>!p)),"aria-expanded":i,className:f("ml-1.5 px-2 h-6 rounded-md text-[11px] font-semibold transition-colors",i?"text-snag-primary bg-snag-primary/10":"text-slate-500 hover:text-snag-primary hover:bg-snag-primary/5"),children:"Reply"})]}),z>0&&e.jsxs("button",{type:"button",onClick:()=>u(p=>!p),"aria-expanded":!m,className:"ml-0.5 inline-flex h-6 items-center gap-0.5 rounded-md px-1.5 text-[11px] font-semibold text-slate-500 hover:text-snag-primary hover:bg-snag-primary/5 transition-colors",children:[m?e.jsx(ze,{className:"h-3 w-3","aria-hidden":"true"}):e.jsx(We,{className:"h-3 w-3","aria-hidden":"true"}),m?`${z} ${z===1?"reply":"replies"}`:"Hide replies"]})]}),i&&t.id&&e.jsx("div",{className:"mt-2",children:e.jsx(nt,{postId:r,boardQueryKey:s,parentCommentId:t.id,placeholder:`Reply to ${k}
1â¦`,autoFocus:!0,onCancel:()=>d(!1),onSuccess:()=>d(!1)})}),ee.length>0&&!m&&e.jsx("ul",{className:f("mt-2 space-y-3",o<ns&&"border-l-2 border-slate-200 pl-3 sm:pl-4"),"aria-label":`Replies to ${k}`,children:ee.map((p,S)=>e.jsx(rt,{comment:p,postId:r,currentUserId:a,boardQueryKey:s,depth:o+1},p.id??S))})]})]}),e.jsx(Re,{open:n,onOpenChange:p=>{c.isPending||l(p)},children:e.jsxs(Ke,{className:"bg-white sm:max-w-sm",children:[e.jsxs(Te,{children:[e.jsx(Me,{children:"Delete comment?"}),e.jsx(Le,{children:"This will permanently remove your comment. This action cannot be undone."})]}),e.jsxs(Oe,{children:[e.jsx(I,{type:"button",variant:"outline",disabled:c.isPending,onClick:()=>l(!1),children:"Cancel"}),e.jsx(I,{type:"button",variant:"destructive",disabled:c.isPending,onClick:ue,className:"bg-red-500",children:c.isPending?e.jsxs(e.Fragment,{children:[e.jsx(pe,{className:"h-4 w-4 animate-spin"}),"Deletingâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(be,{className:"h-4 w-4"}),"Delete"]})})]})]})})]})}function rs({className:t,...r}){return e.jsx("textarea",{"data-slot":"textarea",className:f("placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input flex min-h-[60px] w-full rounded-md border bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm","focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]","aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",t),...r})}const bs=[{value:"incorrect_info",label:"Incorrect product information"},{value:"wrong_price",label:"Wrong or misleading price"},{value:"inappropriate",label:"Inappropriate content"},{value:"spam",label:"Spam or scam"},{value:"other",label:"Other"}],os=[{value:"spam",label:"Spam"},{value:"harassment",label:"Harassment or hate speech"},{value:"inappropriate",label:"Inappropriate content"},{value:"misinformation",label:"False or misleading information"},{value:"other",label:"Other"}];function is({open:t,onOpenChange:r,title:a,description:s,reasons:o,isPending:n,onSubmit:l}){const[i,d]=y.useState(null),[m,u]=y.useState(""),x=c=>{n||(r(c),c||(d(null),u("")))},v=()=>{const c=o.find(g=>g.value===i);c&&l(c.value,c.label,m.trim())};return e.jsx(Re,{open:t,onOpenChange:x,children:e.jsxs(Ke,{className:"bg-white sm:max-w-md",children:[e.jsxs(Te,{children:[e.jsx(Me,{children:a}),e.jsx(Le,{children:s})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex flex-col gap-2",role:"radiogroup","aria-label":"Report reason",children:o.map(c=>e.jsx("button",{type:"button",role:"radio","aria-checked":i===c.value,onClick:()=>d(c.value),className:f("rounded-xl border px-3 py-2 text-left text-sm transition-colors",i===c.value?"border-snag-primary bg-snag-primary/5 font-semibold text-snag-primary":"border-slate-200 text-slate-700 hover:border-slate-300 hover:bg-slate-50"),children:c.label},c.value))}),e.jsx(rs,{value:m,onChange:c=>u(c.target.value),placeholder:"Add details (optional)",rows:3,maxLength:500,className:"resize-none"})]}),e.jsxs(Oe,{children:[e.jsx(I,{type:"button",variant:"outline",disabled:n,onClick:()=>x(!1),children:"Cancel"}),e.jsx(I,{type:"button",disabled:!i||n,onClick:v,className:"bg-snag-red text-white hover:bg-snag-red/90",children:n?e.jsxs(e.Fragment,{children:[e.jsx(pe,{className:"h-4 w-4 animate-spin"}),"Submittingâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(et,{className:"h-4 w-4"}),"Submit report"]})})]})]})})}const ls={userReports:["userReports"]};function ws(){const t=Q();return w({mutationFn:async({productId:r,type:a,note:s})=>{const o=await dt.apiReportsAddUserReportPost({reportDataRequest:{productId:r,type:a,note:s?.trim()||void 0}},{signal:AbortSignal.timeout(1e4)});if(o.success===!1)throw new Error(o.errorMessage??o.error??"Report failed");return o},retry:0,onSuccess:()=>{t.invalidateQueries({queryKey:ls.userReports})},onError:()=>{h.error("Failed to submit report. Please try again.")}})}function cs(){return w({mutationFn:async({postId:t,reason:r})=>{await N.apiPostsIdReportPost({id:t,reportDto:{reason:r}},{signal:AbortSignal.timeout(1e4)})},retry:0,onError:()=>{h.error("Failed to submit report. Please try again.")}})}function us(t){if(t.platform)return E;if(t.productId)return Pe.productPosts(t.productId);if(t.brandId)return Se.brandPosts(t.brandId);if(t.storeId)return Ne.storePosts(t.storeId);if(t.collectionId)return ae.collectionPosts(t.collectionId)}function js({post:t,collectionId:r,storeId:a,productId:s,brandId:o,platform:n=!1,defaultShowComments:l=!1,linkToDetail:i=!1,layout:d="card",className:m}){const u=d==="detail",[x,v]=y.useState(l),[c,g]=y.useState(!1),[V,k]=y.useState(!1),{isAuthenticated:j,signIn:A}=_e(),_=le(b=>b.user?.sub),F=cs(),Z=us({collectionId:r,storeId:a,productId:s,brandId:o,platform:n}),{data:C,isPending:T,isError:M}=Qt(x?t.id:null),B=Et(t.id??"",r??""),W=Lt(t.id??"",a??""),ee=zt(t.id??"",s??""),z=Wt(t.id??"",o??""),ue=es(t.id??""),L=Ut(t.id??"",r??""),p=Tt(t.id??"",a??""),S=It(t.id??"",s??""),G=Ht(t.id??"",o??""),D=Zt(t.id??""),{upvote:te,downvote:U}
1=s?ee:o?z:a?W:n?ue:B,se=s?S:o?G:a?p:n?D:L,ne=!!_&&t.user?.userId===_&&t.content!=="[DELETED]",re=t.userScore??0,X=re>0,R=re<0,he=()=>{se.mutate(void 0,{onSuccess:()=>g(!1)})},De=()=>{if(!j){A();return}k(!0)},P=(b,Y,$e)=>{t.id&&F.mutate({postId:t.id,reason:$e?`${Y}: ${$e}`:Y},{onSuccess:()=>{k(!1),h.success("Report submitted",{description:"Thanks â our team will review this post."})}})},O=t.user?.userName?.trim()||t.metadata?.authorName?.trim()||"Anonymous",H=t.user?.profilePictureUrl?.trim()||t.metadata?.authorImageUrl?.trim()||null,K=t.createdAt?new Date(t.createdAt).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"",oe=(t.upvotes??0)-(t.downvotes??0),q=x&&C?Ee(C):Ee(t.comments),$=(t.mediaItems??[]).filter(b=>b.fileUrl&&b.mediaType?.startsWith("image/")).map(b=>({url:b.fileUrl,alt:b.fileName??void 0})),ge=()=>{if(!j){A();return}te.mutate()},xe=()=>{if(!j){A();return}U.mutate()};return e.jsxs("article",{className:f("flex flex-col bg-white overflow-hidden",u?"rounded-xl border border-slate-200 shadow-sm":"rounded-2xl border border-slate-100 shadow-sm hover:shadow-md transition-shadow duration-200",m),children:[e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:f("flex flex-1 items-start gap-3",u?"gap-4 px-5 pt-5 pb-4 sm:px-6 sm:pt-6":"px-4 pt-4 pb-3"),children:[e.jsxs("div",{className:f("flex flex-col items-center gap-0.5 flex-shrink-0 mt-0.5",u&&"rounded-lg bg-slate-50 px-1.5 py-2"),children:[e.jsx("button",{type:"button",onClick:ge,disabled:te.isPending,"aria-label":j?X?"Remove upvote":"Upvote":"Sign in to vote","aria-pressed":X,title:j?void 0:"Sign in to vote",className:f("h-7 w-7 rounded-full flex items-center justify-center transition-all cursor-pointer",j?X?"bg-snag-primary/10 text-snag-primary":"hover:bg-snag-primary/10 hover:text-snag-primary text-slate-400":"text-slate-400 hover:bg-snag-primary/10 hover:text-snag-primary",te.isPending&&"opacity-50 cursor-not-allowed"),children:e.jsx(Je,{className:f("h-4 w-4",X&&"fill-current")})}),e.jsx("span",{className:f("text-xs font-bold tabular-nums leading-none",oe>0?"text-snag-primary":oe<0?"text-snag-red":"text-slate-400"),children:oe}),e.jsx("button",{type:"button",onClick:xe,disabled:U.isPending,"aria-label":j?R?"Remove downvote":"Downvote":"Sign in to vote","aria-pressed":R,title:j?void 0:"Sign in to vote",className:f("h-7 w-7 rounded-full flex items-center justify-center transition-all cursor-pointer",j?R?"bg-snag-red/10 text-snag-red":"hover:bg-snag-red/10 hover:text-snag-red text-slate-400":"text-slate-400 hover:bg-snag-red/10 hover:text-snag-red",U.isPending&&"opacity-50 cursor-not-allowed"),children:e.jsx(Ye,{className:f("h-4 w-4",R&&"fill-current")})})]}),e.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[H?e.jsx(ye,{src:H,alt:O,width:28,height:28,className:"rounded-full h-7 w-7 object-cover flex-shrink-0"}):e.jsx(je,{className:"h-7 w-7 text-muted-foreground flex-shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"text-sm font-semibold text-snag-primary truncate",children:O}),K&&e.jsx("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:K}),(ne||j)&&e.jsx("div",{className:"ml-auto flex-shrink-0",children:e.jsxs(Xe,{children:[e.jsx(He,{asChild:!0,children:e.jsx("button",{type:"button",className:"h-7 w-7 rounded-full flex items-center justify-center text-slate-400 hover:bg-slate-100 hover:text-slate-600 transition-colors","aria-label":"Post options",children:e.jsx(Ze,{className:"h-4 w-4"})})}),e.jsx(Be,{align:"end",className:"w-40",children:ne?e.jsxs(Fe,{variant:"destructive",onSelect:b=>{b.preventDefault(),g(!0)},children:[e.jsx(be,{className:"h-4 w-4"}),"Delete post"]}):e.jsxs(Fe,{onSelect:b=>{b.preventDefault(),De()},children:[e.jsx(et,{className:"h-4 w-4"}),"Report post"]})})]})})]}),t.title&&(u?e.jsx("h1",{className:"font-nunito text-2xl font-extrabold text-slate-900 leading-snug mb-3 sm:text-[1.75rem]",children:t.title}):e.jsx("h3",{className:"font-nunito text-base font-bold text-slate-900 leading-snug mb-1.5",children:i&&n&&t.id?e.jsx(mt,{to:"/boards/$postId",params:{postId:t.id},className:"hover:text-snag-primary transition-colors",children:t.title}):t.title})),t.content&&e.jsx("p",{className:f("flex-1 text-slate-600 leading-relaxed whitespace-pre-wrap",u?"text-[15px] sm:text-base leading-7":"text-sm"),children:t.content})]})]}),$.length>0&&e.jsx("div",{className:f("pb-3",u?"px-5 sm:px-6 max-w-3xl":"px-4 max-w-[50%]"),children:e.jsx(Ce,{images:$})})]}),e.jsx("div",{className:f("mt-auto flex items-center gap-1 border-t border-slate-50",u?"px-5 py-3 sm:px-6":"px-4 py-2.5"),
1children:e.jsxs("button",{type:"button",onClick:()=>v(b=>!b),"aria-expanded":x,className:"flex items-center gap-1.5 text-xs font-medium text-slate-500 hover:text-snag-primary transition-colors px-2.5 py-1.5 rounded-lg hover:bg-snag-primary/5",children:[e.jsx(pt,{className:"h-3.5 w-3.5","aria-hidden":"true"}),q>0?`${q} comment${q!==1?"s":""}`:"Comment",x?e.jsx(Nt,{className:"h-3 w-3"}):e.jsx(We,{className:"h-3 w-3"})]})}),e.jsx(me,{children:x&&e.jsx(de.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.18},className:"overflow-hidden",children:e.jsxs("div",{className:f("border-t border-slate-100 bg-slate-50/60 space-y-4",u?"px-5 py-4 sm:px-6 sm:py-5":"px-4 py-3"),children:[T?e.jsx("div",{className:"space-y-3",children:[1,2].map(b=>e.jsxs("div",{className:"flex gap-2.5",children:[e.jsx(Ie,{className:"h-7 w-7 rounded-full flex-shrink-0"}),e.jsx(Ie,{className:"h-10 flex-1 rounded-xl"})]},b))}):M?e.jsx("p",{className:"text-xs text-snag-red",children:"Failed to load comments."}):C&&C.length>0?e.jsx("ul",{className:"space-y-3","aria-label":"Comments",children:C.map((b,Y)=>e.jsx(rt,{comment:b,postId:t.id??"",currentUserId:_,boardQueryKey:Z},b.id??Y))}):e.jsx("p",{className:"text-xs text-muted-foreground text-center py-2",children:"No comments yet â be the first!"}),e.jsx(nt,{postId:t.id??"",boardQueryKey:Z})]})})}),e.jsx(Re,{open:c,onOpenChange:b=>{se.isPending||g(b)},children:e.jsxs(Ke,{className:"bg-white sm:max-w-sm",children:[e.jsxs(Te,{children:[e.jsx(Me,{children:"Delete post?"}),e.jsxs(Le,{children:["This will permanently remove your post",q>0?" and its comments":"",". This action cannot be undone."]})]}),e.jsxs(Oe,{children:[e.jsx(I,{type:"button",variant:"outline",disabled:se.isPending,onClick:()=>g(!1),children:"Cancel"}),e.jsx(I,{type:"button",variant:"destructive",disabled:se.isPending,onClick:he,className:"bg-red-500",children:se.isPending?e.jsxs(e.Fragment,{children:[e.jsx(pe,{className:"h-4 w-4 animate-spin"}),"Deletingâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(be,{className:"h-4 w-4"}),"Delete"]})})]})]})}),e.jsx(is,{open:V,onOpenChange:k,title:"Report post",description:"Let us know what's wrong with this post. Reports are reviewed by our team.",reasons:os,isPending:F.isPending,onSubmit:P})]})}export{Ye as A,wt as C,Ze as E,et as F,bs as P,is as R,Je as a,Nt as b,js as c,vs as d,fs as e,ws as u};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.