1import{r as e,j as s}from"./vendor-react-C9yDzYQD.js";import{B as r}from"./button-CcIRk75H.js";import{I as a}from"./input-CJADGzyX.js";import{S as t}from"./switch-CM-712rT.js";import{C as i}from"./checkbox-ClobpLtU.js";import{A as l,a as o,b as n}from"./avatar-BhqY-G3f.js";import{S as d,a as c,b as m,c as u,d as x}from"./select-BE1IGN5Z.js";import{D as h,f as p,a as b,c as g,d as f}from"./dialog-DHNNRuDw.js";import{A as v,a as j,b as w,c as N,d as y,e as k,f as _,g as C}from"./alert-dialog-BZjXuitG.js";import{a as S}from"./runtime-utils-GN4cODRt.js";import{u as M}from"./useBoards-KZlRZb0G.js";import{b as I,o as P,g as E}from"./image-utils-AdRSPECl.js";import{u as B}from"./useSharedBoards-HZIBsbff.js";import{u as L,a as U}from"./useAuth-Dz3EPsxs.js";import{supabase as O}from"./supabase-client-_h80EYw_.js";import{b as T,a as z}from"./shareUrls-BBmEIcFl.js";import{n as A,D,e as V}from"./boardViewSettings-CdKftBZg.js";import{s as $,a as H,p as R}from"./boardSectionMemberships-BIWAwBQ2.js";import{z as F,t as q,S as G}from"./useUserSettings-COPNty3J.js";import{MoveToBoardDialog as W}from"./MoveToBoardDialog-BIqXAB0t.js";import{u as J}from"./useImageCompression-CcXi4sud.js";import{b as K}from"./r2-upload-BKh8xYPI.js";import{n as Y}from"./inviteCandidates-D32NnMx2.js";import{i as Z}from"./heic-26Yd2oA8.js";import{VideoPreview as X}from"./VideoPreview-smtYi5cl.js";import{u as Q}from"./usePerfBudget-B6X6q34-.js";import{P as ee}from"./pencil-uXnRhiXs.js";import{C as se}from"./dropdown-menu-BEBSGtMc.js";import{S as re}from"./shuffle-DeVauovo.js";import{S as ae}from"./search-D7ByVMw5.js";import{L as te}from"./lock-Dh-2FzOx.js";import{E as ie}from"./eye-off-Dee1325O.js";import{G as le}from"./globe-DJqDK8z8.js";import{S as oe}from"./sparkles-COPkKMBj.js";import{C as ne}from"./copy-BrZVoqd7.js";import{C as de}from"./chevron-up-DmrAct_7.js";import{C as ce}from"./chevron-down-BFi_I8Zn.js";import{L as me}from"./loader-circle-CWK_zhHB.js";import{U as ue}from"./upload-DddxHbzP.js";import{V as xe}from"./video-DibMJbQh.js";import{X as he}from"./x-lNdY5pWw.js";import{C as pe}from"./check-MQhLD6FV.js";import{P as be}from"./plus-CNl86JwM.js";import{G as ge}from"./grid-3x3-AfiTgJMo.js";import{T as fe}from"./trash-2-B7zVZuh_.js";import{L as ve}from"./log-out-EKNp0o3i.js";import{I as je}from"./info-Cn1cLZ-U.js";import{I as we}from"./image-Bt9rnFUc.js";import{U as Ne}from"./users-DC2VReCB.js";import{G as ye}from"./grip-vertical-DC3L8uyk.js";import{C as ke}from"./clock-Qxd67VZh.js";import{E as _e}from"./eye-Dkh28JiF.js";import{U as Ce}from"./user-plus-BPTeVkvT.js";import{M as Se}from"./mail-BW3XjlGt.js";import{c as Me}from"./createLucideIcon-DNcTU-zM.js";import{U as Ie}from"./user-minus-Bw9zDeRR.js";const Pe=Me("Crown",[["path",{d:"M11.562 3.266a.5.5 0 0 1 .876 0L15.39 8.87a1 1 0 0 0 1.516.294L21.183 5.5a.5.5 0 0 1 .798.519l-2.834 10.246a1 1 0 0 1-.956.734H5.81a1 1 0 0 1-.957-.734L2.02 6.02a.5.5 0 0 1 .798-.519l4.276 3.664a1 1 0 0 0 1.516-.294z",key:"1vdc57"}],["path",{d:"M5 21h14",key:"11awu3"}]]),Ee=(e=[],s=[])=>e.length===s.length&&e.every((e,r)=>e===s[r]),Be=({videoUrl:r,imageUrl:a,className:t,style:i,autoPlay:l=!1})=>{const o=e.useMemo(()=>I(a,"thumbnail")||(r?P(r):null),[a,r]),n=e.useMemo(()=>E(r),[r]);return n||o?s.jsx(X,{src:n,fallbackSrc:r,posterSrc:o,posterFallbackSrc:a,alt:"Video thumbnail",className:t,mediaClassName:t,mediaStyle:i,playMode:l?"always":"never",showVideoBadge:!1}):s.jsx("div",{className:S("w-full h-full bg-muted flex items-center justify-center",t),style:i,children:s.jsx(xe,{className:"w-8 h-8 text-muted-foreground/20"})})};function Le({boardId:i,boardName:h,isOwner:p,isActive:b,ownerUsername:g,boardSlug:f}){const{user:M,profile:I}=U();null==I||I.public_sharing_disabled;const{toast:P}=L(),{getMembers:E,createInviteForUser:A,deleteInvite:D,kickMember:V,leaveBoard:$,subscribeToMemberChanges:H,updateMemberPermission:R,transferOwnership:F,isLoading:G}=B(),[W,J]=e.useState([]),[K,Z]=e.useState("edit"),[X,Q]=e.useState(""),[se,te]=e.useState(""),[ie,le]=e.useState(null),[oe,de]=e.useState([]),[ce,ue]=e.useState(!1),[xe,he]=e.useState(null),[be,ge]=e.useState(!1),[fe,je]=e.useState(null),[we,ye]=e.useState(!1),[ke,Me]=e.useState(!1),Ee=e.useMemo(()=>
1{if(!fe)return"";const e=z({id:i,ownerUsername:g,slug:f});return`${T(e)}?share=${encodeURIComponent(fe)}`},[i,f,g,fe]);e.useEffect(()=>{const e=setTimeout(()=>te(X.trim()),180);return()=>clearTimeout(e)},[X]),e.useEffect(()=>{if(!b||!p)return;if(se.length<2)return void de([]);let e=!1;return(async()=>{ue(!0);const{data:s,error:r}=await O.rpc("search_invitable_users",{p_board_id:i,p_query:se,p_limit:8});e||(de(r?[]:Y(s)),ue(!1))})(),()=>{e=!0}},[b,p,i,se]);const Be=e.useCallback(async()=>{const e=await E(i);J(e)},[i,E]);e.useEffect(()=>{b&&Be()},[b,Be]);const Le=e.useCallback(async()=>{if(p)try{const{data:e,error:s}=await O.rpc("get_board_private_share_link",{p_board_id:i});if(s)throw s;const r=Array.isArray(e)?e[0]:null;ge(Boolean(null==r?void 0:r.enabled)),je((null==r?void 0:r.token)||null)}catch(e){}},[i,p]);e.useEffect(()=>{b&&p&&Le()},[b,p,Le]),e.useEffect(()=>{if(b)return H(i,()=>Be())},[b,i,Be,H]);const Ue=e.useMemo(()=>{if(ie)return ie;const e=X.trim().toLowerCase();if(!e)return null;const s=e.replace(/^@/,"");return oe.find(r=>{var a;return r.username.toLowerCase()===s||(null==(a=r.full_name)?void 0:a.toLowerCase())===e})||null},[ie,X,oe]),Oe=async()=>{const e=Ue;e?await A(i,e.user_id,K,7)&&(P({title:`Invite sent to @${e.username}`}),Q(""),te(""),le(null),de([]),Be()):P({title:"Select a registered Echo user",description:"Choose a user from suggestions.",variant:"error"})},Te=async(e,s=!1)=>
1{if(p&&!we){ye(!0);try{const{data:r,error:a}=await O.rpc("set_board_private_share_link",{p_board_id:i,p_enabled:e,p_rotate:s});if(a)throw a;const t=Array.isArray(r)?r[0]:null;ge(Boolean(null==t?void 0:t.enabled)),je((null==t?void 0:t.token)||null),!e||!s&&fe?e||P({title:"Secret link disabled"}):P({title:s?"Secret link regenerated":"Secret link enabled",description:s?"The previous link no longer works.":"Anyone with the link can view this board."})}catch(r){P({title:"Could not update secret link",description:(null==r?void 0:r.message)||"Please try again.",variant:"error"})}finally{ye(!1)}}},ze=async()=>{Ee&&(await navigator.clipboard.writeText(Ee),Me(!0),window.setTimeout(()=>Me(!1),1600),q({content_type:"board",method:"copy_secret_link",board_id:i,share_location:"board_editor_people"}),P({title:"Secret board link copied",description:Ee,variant:"success"}))},Ae=e=>e.split(" ").map(e=>e[0]).join("").toUpperCase().slice(0,2),De=W.filter(e=>"follower"!==e.role);return s.jsxs("div",{className:"space-y-6 animate-in fade-in slide-in-from-right-4 duration-300",children:[s.jsxs("div",{className:"flex items-center gap-3 pb-2",children:[s.jsx("div",{className:"w-10 h-10 rounded-2xl bg-blue-500/10 flex items-center justify-center text-blue-500 shrink-0",children:s.jsx(Ne,{className:"w-5 h-5"})}),s.jsxs("div",{children:[s.jsx("h2",{className:"text-lg font-bold tracking-tight",children:"Collaborators"}),s.jsxs("p",{className:"text-xs text-muted-foreground font-medium",children:[De.length," ",1===De.length?"member":"members"]})]})]}),p&&s.jsxs("div",{className:"space-y-3 p-4 rounded-2xl bg-muted/30 border border-border/10",children:[s.jsxs("div",{className:"flex items-start justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"text-[10px] font-bold uppercase tracking-widest text-muted-foreground",children:"Secret Link"}),s.jsx("p",{className:"mt-1 text-xs text-muted-foreground font-medium",children:"Anyone with this link can view the board without logging in."})]}),s.jsx(t,{checked:be,onCheckedChange:e=>Te(e),disabled:we,className:"data-[state=checked]:bg-primary shrink-0"})]}),be&&Ee&&s.jsxs("div",{className:"flex items-center gap-2 bg-background/70 p-1.5 pl-3 rounded-xl border border-border/20",children:[s.jsx("span",{className:"text-xs font-mono text-muted-foreground truncate flex-1 leading-none",children:Ee}),s.jsx("button",{type:"button",onClick:ze,className:"p-2 rounded-lg hover:bg-muted transition-colors shrink-0 text-muted-foreground hover:text-foreground active:scale-95 bg-background shadow-xs border border-border/30",children:ke?s.jsx(pe,{className:"w-3.5 h-3.5 text-green-500"}):s.jsx(ne,{className:"w-3.5 h-3.5"})})]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsxs(r,{type:"button",variant:"outline",size:"sm",onClick:()=>be&&Ee?ze():Te(!0),disabled:we,className:"flex-1 h-9 rounded-xl gap-2 font-bold",children:[we?s.jsx(me,{className:"w-3.5 h-3.5 animate-spin"}):ke?s.jsx(pe,{className:"w-3.5 h-3.5"}):s.jsx(ne,{className:"w-3.5 h-3.5"}),be&&Ee?ke?"Copied":"Copy link":"Turn on link"]}),s.jsxs(r,{type:"button",variant:"outline",size:"sm",onClick:()=>Te(!0,!0),disabled:we,className:"h-9 rounded-xl gap-2 font-bold",children:[s.jsx(re,{className:"w-3.5 h-3.5"}),"New link"]})]})]}),p&&s.jsxs("div",{className:"space-y-3 p-4 rounded-2xl bg-muted/30 border border-border/10",children:[s.jsx("p",{className:"text-[10px] font-bold uppercase tracking-widest text-muted-foreground",children:"Invite User"}),s.jsxs("div",{className:"flex gap-2",children:[s.jsxs("button",{onClick:()=>Z("edit"),className:S("flex-1 flex items-center justify-center gap-1.5 py-2 rounded-xl text-xs font-bold transition-all","edit"===K?"bg-primary text-primary-foreground shadow-sm":"bg-muted/50 text-muted-foreground hover:bg-muted"),children:[s.jsx(ee,{className:"w-3 h-3"}),"Can edit"]}),s.jsxs("button",{onClick:()=>Z("read"),className:S("flex-1 flex items-center justify-center gap-1.5 py-2 rounded-xl text-xs font-bold transition-all","read"===K?"bg-primary text-primary-foreground shadow-sm":"bg-muted/50 text-muted-foreground hover:bg-muted"),children:[s.jsx(_e,{className:"w-3 h-3"}),"View only"]})]}),s.jsxs("div",{className:"relative",children:[s.jsx(ae,{className:"w-4 h-4 absolute left-3.5 to
1p-1/2 -translate-y-1/2 text-muted-foreground"}),s.jsx(a,{placeholder:"Search by nickname or username...",value:X,onChange:e=>{Q(e.target.value),le(null)},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),Oe())},className:"h-11 pl-10 rounded-xl bg-background border-border/30 focus-visible:ring-primary"})]}),ie&&s.jsxs("div",{className:"flex items-center gap-2 rounded-xl border border-primary/30 bg-primary/5 px-3 py-2",children:[s.jsxs(l,{className:"w-7 h-7",children:[s.jsx(o,{src:ie.avatar_url||void 0}),s.jsx(n,{className:"text-xs",children:Ae(ie.full_name||ie.username)})]}),s.jsxs("div",{className:"min-w-0 flex-1",children:[ie.full_name&&s.jsx("p",{className:"text-sm font-medium truncate",children:ie.full_name}),s.jsxs("p",{className:S("truncate",ie.full_name?"text-xs text-muted-foreground":"text-sm font-medium"),children:["@",ie.username]})]}),s.jsx("button",{type:"button",className:"text-xs text-muted-foreground hover:text-foreground",onClick:()=>le(null),children:"Clear"})]}),!ie&&se.length>=2&&s.jsx("div",{className:"rounded-xl border bg-muted/20 max-h-44 overflow-y-auto",children:ce?s.jsx("div",{className:"px-3 py-2.5 text-xs text-muted-foreground",children:"Searching users..."}):0===oe.length?s.jsx("div",{className:"px-3 py-2.5 text-xs text-muted-foreground",children:"No matching users found."}):oe.map(e=>s.jsxs("button",{type:"button",onClick:()=>{le(e),Q(e.username)},className:"w-full text-left px-3 py-2 flex items-center gap-2 hover:bg-muted transition-colors",children:[s.jsxs(l,{className:"w-7 h-7",children:[s.jsx(o,{src:e.avatar_url||void 0}),s.jsx(n,{className:"text-xs",children:Ae(e.full_name||e.username)})]}),s.jsxs("div",{className:"min-w-0",children:[e.full_name&&s.jsx("p",{className:"text-sm font-medium truncate",children:e.full_name}),s.jsxs("p",{className:S("truncate",e.full_name?"text-xs text-muted-foreground":"text-sm font-medium"),children:["@",e.username]})]})]},e.user_id))}),s.jsxs(r,{className:"w-full h-10 rounded-xl gap-2 font-bold",onClick:Oe,disabled:!Ue||G,children:[s.jsx(Ce,{className:"w-4 h-4"}),"Send Invite"]})]}),De.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsxs("p",{className:"text-[10px] font-bold uppercase tracking-widest text-muted-foreground px-1 mb-3",children:["Members · ",De.length]}),De.map(e=>{var r,a;return s.jsxs("div",{className:S("flex items-center gap-3 p-3 rounded-2xl hover:bg-muted/30 transition-colors","invited"===e.status&&"opacity-60"),children:[s.jsxs(l,{className:"w-9 h-9 shrink-0",children:[s.jsx(o,{src:e.avatar_url||void 0}),s.jsx(n,{className:"text-xs bg-primary/10 text-primary",children:"invited"===e.status&&!e.avatar_url&&(null==(r=e.username)?void 0:r.includes("@"))?s.jsx(Se,{className:"w-3 h-3"}):Ae(e.username)})]}),s.jsx("div",{className:"flex-1 min-w-0",children:s.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[s.jsx("span",{className:"text-sm font-semibold truncate",children:e.username}),"owner"===e.role&&s.jsx(Pe,{className:"w-3 h-3 text-amber-500 shrink-0"}),e.user_id===(null==M?void 0:M.id)&&s.jsx("span",{className:"text-[10px] text-muted-foreground shrink-0",children:"you"}),"invited"===e.status&&s.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-bold uppercase tracking-wide",children:"Pending"})]})}),"owner"===e.role?s.jsx("span",{className:"text-[10px] text-amber-600 font-bold shrink-0",children:"Owner"}):p&&e.user_id!==(null==M?void 0:M.id)&&"invited"!==e.status?s.jsxs(d,{value:e.permission||"edit",onValueChange:s=>(async(e,s)=>{await R(i,e,s)&&Be()})(e.user_id,s),children:[s.jsx(c,{className:"h-7 w-24 text-[10px] border-none bg-muted/50 px-2 shrink-0 rounded-lg",children:s.jsx(m,{})}),s.jsxs(u,{children:[s.jsx(x,{value:"edit",className:"text-xs",children:"Can edit"}),s.jsx(x,{value:"read",className:"text-xs",children:"View only"})]})]}):s.jsx("span",{className:"text-[10px] text-muted-foreground shrink-0 font-medium",children:(a=e.permission||"edit","owner"===a?"Owner":"edit"===a?"Can edit":"read"===a?"View only":a)}),p&&e.user_id!==(null==M?void 0:M.id)&&"owner"!==e.role&&"invited"!==e.status&&s.jsx("button",{onClick:()=>he({userId:e.user_id,username:e.username}),disabled:G,className:"p-1.5 rounded-lg hover:bg-amber-500/10 text-muted-foreground hover:text-amber-500 transition-colors shrink-0",title:"Transfer ownership",children:s.jsx(Pe,{className:"w-3.5 h-3.5"})}),p&&e.user_id!==(null==M?void 0:M.id)&&"owner"!==e.role&&s.jsx("button",{onClick:()=>"invited"===e.status?(async e=>{await D(e)&&Be()})(e.invite_id):(async e=>{await V(i,e)&&Be()})(e.user_id),disabled:G,className:"p-1.5 rounded-lg hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors shrink-0",title:"invited"===e.status?"Revoke invite":"Remove member",children:s.jsx(Ie,{className:"w-3.5 h-3.5"})})]},e.id)})]}):p?s.jsxs("div",{className:"flex flex-col items-center justify-center py-10 text-center opacity-40 space-y-3",children:[s.jsx(Ne,{className:"w-8 h-8"}),s.jsx("p",{className:"text-sm font-medium",children:"No collaborators yet"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"Invite users above to collaborate"})]}):null,!p&&s.jsx("div",{className:"pt-4 border-t border-border/10",children:s.jsxs(r,{variant:"ghost",size:"sm",className:"w-full gap-2 text-destructive hover:bg-destructive/10 h-10 text-sm font-bold rounded-xl",onClick:async()=>{await $(i)&&(window.location.href="/boards")},disabled:G,children:[s.jsx(ve,{className:"w-4 h-4"}),"Leave Board"]})}),s.jsx(v,{open:!!xe,onOpenChange:e=>!e&&he(null),children:s.jsxs(j,{children:[s.jsxs(w,{children:[s.jsx(N,{children:"Transfer ownership?"}),s.jsx(y,{children:xe?`Are you sure you want to transfer "${h}" to @${xe.username}? You will become a regular member with edit access.`:"Are you sure you want to transfer this board?"})]}),s.jsxs(k,{children:[s.jsx(_,{children:"Cancel"}),s.jsx(C,{onClick:async()=>
1{if(!xe)return;const{userId:e,username:s}=xe;await F(i,e)&&(await Be(),P({title:`@${s} is now the owner`,description:"You still have edit access as a collaborator."})),he(null)},children:"Transfer ownership"})]})]})})]})}function Ue(e){return e?new Date(e).toLocaleDateString(void 0,{year:"numeric",month:"long",day:"numeric"}):"â"}function Oe({board:l,onUpdate:o,onDelete:n,isOwner:d=!0,initialSection:c="info",open:m,onOpenChange:u,hideTrigger:x=!1,children:P}){var E,B,Y;const{lowEnd:X}=Q(),{toast:_e}=L(),{profile:Ce}=U(),Se=!!(null==Ce?void 0:Ce.public_sharing_disabled),[Me,Ie]=e.useState(!1),Pe=m??Me,Oe=e=>{void 0===m&&Ie(e),null==u||u(e)},Te=e.useRef(null),[ze,Ae]=e.useState(l.name),[De,Ve]=e.useState(l.description||""),[$e,He]=e.useState(l.header_image_id||null),[Re,Fe]=e.useState(l.custom_header_image_url||null),[qe,Ge]=e.useState(l.header_image_position??50),[We,Je]=e.useState(l.header_image_zoom??100),[Ke,Ye]=e.useState(l.preview_image_ids||[]),[Ze,Xe]=e.useState(void 0!==l.is_public&&null!==l.is_public?!l.is_public:l.is_private??!1),[Qe,es]=e.useState(l.is_mature||!1),[ss,rs]=e.useState(()=>F(l.sensitive_categories)),[as,ts]=e.useState(l.is_hidden||!1),[is,ls]=e.useState(l.pin_code||""),[os,ns]=e.useState(!!l.pin_code),[ds,cs]=e.useState(!1),[ms,us]=e.useState(!1),[xs,hs]=e.useState(!1),[ps,bs]=e.useState(!1),[gs,fs]=e.useState(!1),[vs,js]=e.useState(!1),[ws,Ns]=e.useState([]),[ys,ks]=e.useState(!1),[_s,Cs]=e.useState(!1),[Ss,Ms]=e.useState(!1),Is=e.useRef(0),{boards:Ps,addMemoriesToBoard:Es,fetchBoardMemoriesPaginated:Bs}=M({enabled:Pe}),{user:Ls}=U(),{compressImage:Us}=J(),Os=e.useRef(null),[Ts,zs]=e.useState(""),[As,Ds]=e.useState("info"),[Vs,$s]=e.useState(24),Hs=e.useRef(null),Rs=e.useRef(null),[Fs,qs]=e.useState(()=>A(l.view_config||D)),Gs=!l.memories||(l.memory_count||0)>((null==(E=l.memories)?void 0:E.length)||0),Ws=e.useMemo(()=>{const e=new Map;return[...l.memories||[],...ws].forEach(s=>{(null==s?void 0:s.id)&&e.set(s.id,s)}),Array.from(e.values())},[l.memories,ws]),Js=e.useMemo(()=>Ws.filter(e=>("image"===e.type||"url"===e.type||"video"===e.type)&&(e.image_url||e.video_url))||[],[Ws]),Ks=e.useMemo(()=>Js.filter(e=>!Ts.trim()||e.title&&e.title.toLowerCase().includes(Ts.toLowerCase())||e.content&&e.content.toLowerCase().includes(Ts.toLowerCase())||e.description&&e.description.toLowerCase().includes(Ts.toLowerCase())),[Js,Ts]),Ys=e.useMemo(()=>Ps.filter(e=>e.id!==l.id&&!e.is_following&&(e.is_owner||e.can_edit)),[Ps,l.id]);e.useEffect(()=>{Pe?Te.current!==l.id&&(Te.current=l.id,Ae(l.name),Ve(l.description||""),He(l.header_image_id||null),Fe(l.custom_header_image_url||null),Ge(l.header_image_position??50),Je(l.header_image_zoom??100),Ye(l.preview_image_ids||[]),Xe(void 0!==l.is_public&&null!==l.is_public?!l.is_public:l.is_private??!1),es(l.is_mature||!1),rs(F(l.sensitive_categories)),ts(l.is_hidden||!1),ls(l.pin_code||""),ns(!!l.pin_code),$s(24),zs(""),Ds(c),Ns([]),Ms(!1),Cs(!1),Is.current=0,qs(A(l.view_config||D))):Te.current=null},[Pe,l.id,l,c]),e.useEffect(()=>{Se&&(Xe(!0),es(!1),rs([]))},[Se]);const Zs=e.useCallback(async(e,s={})=>{if(Pe&&Gs){s.append?Cs(!0):ks(!0);try{const r=await Bs(l.id,96,e);Ns(e=>{if(!s.append)return r;const a=new Set(e.map(e=>e.id));return[...e,...r.filter(e=>!a.has(e.id))]}),Is.current=e+r.length,Ms(96===r.length)}catch(r){}finally{s.append?Cs(!1):ks(!1)}}},[l.id,Bs,Pe,Gs]);e.useEffect(()=>{Pe&&Gs&&("preview"===As||"header"===As)&&(ys||ws.length>0||(Is.current=0,Zs(0)))},[As,ys,Zs,ws.length,Pe,Gs]);const Xs=(e,s)=>{qs(r=>{const a={...r,tabOrder:[...r.tabOrder]},t=e+s;return t<0||t>=a.tabOrder.length?r:([a.tabOrder[e],a.tabOrder[t]]=[a.tabOrder[t],a.tabOrder[e]],A(a))})},Qs=async()=>{if(!ze.trim())return;cs(!0);const e={},s=ze.trim(),r=De.trim()||null,a=l.description||null,t=l.header_image_id||null,i=l.custom_header_image_url||null,n=l.header_image_position??50,c=l.header_image_zoom??100,m=l.preview_image_ids||[],u=A(l.view_config||D),x=void 0!==l.is_public&&null!==l.is_public?!l.is_public:l.is_private??!1,h=!!Se||Ze,p=!h&&Qe,b=h&&os&&is.trim()||null;s!==l.name&&(e.name=s),r!==a&&(e.description=r),void 0===l.header_image_id&&null===$e||$e===t||(e.header_image_id=$e),Re!==i&&(e.custom_header_image_url=Re);const g=Boolean($e||Re||t||i);var f,v;g&&qe!==n&&(e.header_image_position=qe),g&&We!==c&&(e.header_image_zoom=We),(void 0!==l.preview_image_ids||Ke.length>0)&&!Ee(m,Ke)&&(e.preview_image_ids=Ke),f=Fs,v=u,JSON.stringify(f)!==JSON.stringify(v)&&(e.view_config=$(await H(l.id,Fs,{currentConfig:l.view_config}))),(h!==x||Se)&&(e.is_private=h,e.is_public=!h),p!==(l.is_mature||!1)&&(e.is_mature=p);const j=p?ss:[],w=F(l.sensitive_categories);if(Ee([...w].sort(),[...j].sort())||(e.sensitive_categories=j),d&&as!==(l.is_hidden||!1)&&(e.is_hidden=as),b!==(l.pin_code||null)&&(e.pin_code=b),0===Object.keys(e).length)return cs(!1),void Oe(!1);try{await o(l.id,e)&&Oe(!1)}catch(N){_e({title:"Failed to update",description:(null==N?void 0:N.message)||"Echo could not save this board update. Please retry.",variant:"error"})}finally{cs(!1)}},er=e=>{Ye(s=>{if(s.includes(e))return s.filter(s=>s!==e);const r=[...s,e];return r.length>4?r.slice(r.length-4):r})},sr=Ws.find(e=>e.id===$e),rr="header"===As?Boolean($e||Re):Ke.length>0,ar=e.useMemo(()=>"header"===As?$e?Js.filter(e=>e.id===$e):[]:"preview"===As?Ke.map(e=>Js.find(s=>
1s.id===e)).filter(Boolean):[],[As,$e,Ke,Js]),tr=e.useMemo(()=>{const e=new Set(ar.map(e=>e.id));return Ks.filter(s=>!e.has(s.id))},[Ks,ar]),ir=tr.slice(0,Vs),lr=tr.length>Vs,or=Gs&&Ss,nr=e.useCallback(()=>{lr?$s(e=>e+24):!or||_s||ys||Zs(Is.current,{append:!0})},[or,lr,ys,_s,Zs]);e.useEffect(()=>{const e=Hs.current;if(!Pe||!e||"preview"!==As&&"header"!==As)return;if(!lr&&!or)return;const s=new IntersectionObserver(e=>{var s;(null==(s=e[0])?void 0:s.isIntersecting)&&nr()},{root:Rs.current,rootMargin:"800px 0px",threshold:0});return s.observe(e),()=>s.disconnect()},[As,or,lr,nr,Pe,ir.length]);const dr=Math.max(l.memory_count||0,(null==(B=l.memories)?void 0:B.length)||0),cr=[{key:"info",label:"Info",icon:s.jsx(je,{className:"w-4 h-4"})},{key:"tabs",label:"Tabs",icon:s.jsx(re,{className:"w-4 h-4"})},{key:"header",label:"Header",icon:s.jsx(we,{className:"w-4 h-4"})},{key:"preview",label:"Preview",icon:s.jsx(ge,{className:"w-4 h-4"})},{key:"privacy",label:"Privacy",icon:s.jsx(te,{className:"w-4 h-4"})},{key:"collaborators",label:"People",icon:s.jsx(Ne,{className:"w-4 h-4"})},...n&&d?[{key:"delete",label:"Delete",icon:s.jsx(fe,{className:"w-4 h-4"}),danger:!0}]:[]],mr=Ze?"Private":as?"Hidden":"Public",ur={recent:{label:"Newest",icon:s.jsx(ke,{className:"w-3.5 h-3.5"})},oldest:{label:"Oldest",icon:s.jsx(ke,{className:"w-3.5 h-3.5"})},manual:{label:"Canvas",icon:s.jsx(ye,{className:"w-3.5 h-3.5"})},random:{label:"Random",icon:s.jsx(re,{className:"w-3.5 h-3.5"})}},xr=Fs.tabOrder.find(e=>Fs.tabsVisible[e]);return s.jsxs(h,{open:Pe,onOpenChange:Oe,children:[!x&&s.jsx(p,{asChild:!0,children:P||s.jsx(r,{variant:"outline",size:"icon",className:"rounded-full shadow-sm",children:s.jsx(ee,{className:"w-4 h-4"})})}),s.jsxs(b,{hideClose:!0,className:"sm:max-w-[920px] bg-background/95 backdrop-blur-3xl border-border/20 rounded-t-[2rem] md:rounded-[2.5rem] overflow-hidden h-[95dvh] mt-auto md:mt-0 md:h-auto md:max-h-[90vh] flex flex-col p-0 shadow-2xl transition-all",children:[s.jsx(g,{className:"sr-only",children:"Board Settings"}),s.jsx(f,{className:"sr-only",children:"Edit board details, privacy settings, and collaborators."}),s.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col md:flex-row min-h-0",children:[s.jsxs("div",{className:"w-full md:w-[200px] md:border-r border-border/10 shrink-0 md:overflow-y-auto bg-muted/10 md:bg-transparent",children:[s.jsxs("div",{className:"hidden md:hidden border-b border-border/10 bg-gradient-to-b from-muted/25 to-background/95 px-4 py-4",children:[s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"text-[10px] font-black uppercase tracking-[0.24em] text-muted-foreground",children:"Sections"}),s.jsx("p",{className:"truncate text-sm font-semibold text-foreground",children:null==(Y=cr.find(e=>e.key===As))?void 0:Y.label})]}),s.jsxs("div",{className:"rounded-full border border-border/20 bg-background/80 px-3 py-1 text-[10px] font-bold uppercase tracking-[0.18em] text-muted-foreground shadow-sm",children:[cr.length," tabs"]})]}),s.jsx("div",{className:"grid grid-cols-3 gap-2",children:cr.map(e=>s.jsxs("button",{onClick:()=>Ds(e.key),className:S("flex min-h-[72px] flex-col items-center justify-center gap-1.5 rounded-2xl border px-2 py-3 text-center transition-all",As===e.key?e.danger?"border-destructive/30 bg-destructive text-destructive-foreground shadow-md":"border-primary/25 bg-primary text-primary-foreground shadow-md":e.danger?"border-destructive/10 bg-background text-destructive/80":"border-border/20 bg-background text-muted-foreground hover:border-border/30 hover:bg-muted/50 hover:text-foreground"),children:[s.jsx("span",{className:"flex h-8 w-8 items-center justify-center rounded-full bg-black/10",children:e.icon}),s.jsx("span",{className:"text-[11px] font-bold leading-tight",children:e.label})]},e.key))})]}),s.jsx("div",{className:"hidden md:flex flex-col h-full bg-muted/5",children:s.jsx("nav",{className:"flex-1 p-3 space-y-0.5 overflow-y-auto custom-scrollbar pt-4",children:cr.map(e=>s.jsxs("button",{onClick:()=>Ds(e.key),className:S("flex items-center gap-3 w-full px-4 py-3 rounded-2xl transition-all font-bold text-sm text-left group",As===e.key?e.danger?"bg-destructive/10 text-destructive":"bg-primary/10 text-primary":e.danger?"text-muted-foreground hover:text-destructive hover:bg-destructive/5":"text-muted-foreground hover:text-foreground hover:bg-muted/60"),
1children:[e.icon,s.jsx("span",{className:"flex-1",children:e.label}),As===e.key&&s.jsx(se,{className:"w-3.5 h-3.5 opacity-[0.6] group-hover:opacity-100 transition-opacity"})]},e.key))})})]}),s.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden min-h-0 bg-background md:bg-transparent",children:[s.jsxs("div",{ref:Rs,className:"flex-1 overflow-y-auto p-5 pb-28 md:p-8 md:pb-8 custom-scrollbar space-y-8",children:[s.jsx("div",{className:"space-y-0.5 pb-5 border-b border-border/10",children:s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsxs("div",{className:"space-y-0.5 min-w-0",children:[s.jsx("h2",{className:"text-xl md:text-2xl font-black tracking-tight",children:"Board Settings"}),s.jsx("p",{className:"text-sm text-muted-foreground font-medium truncate max-w-[180px] md:max-w-xs",children:l.name})]}),s.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[s.jsx("div",{className:S("text-[10px] font-bold uppercase tracking-widest px-3 py-1.5 rounded-full border shadow-sm",{"text-orange-500 border-orange-500/30 bg-
1orange-500/10":Ze,"text-purple-500 border-purple-500/30 bg-purple-500/10":!Ze&&as,"text-emerald-500 border-emerald-500/30 bg-emerald-500/10":!Ze&&!as}),children:mr}),s.jsxs("div",{className:"hidden md:flex items-center gap-2",children:[s.jsx(r,{variant:"outline",onClick:()=>Oe(!1),className:"rounded-xl font-bold h-9 px-4 border-border/30 hover:bg-muted shadow-sm text-sm",children:"Cancel"}),s.jsx(r,{onClick:Qs,disabled:!ze.trim()||ds,className:"rounded-xl bg-foreground text-background px-5 h-9 font-bold hover:scale-[1.02] active:scale-95 transition-all shadow-md text-sm",children:ds?"Saving...":"Save Changes"})]})]})]})}),s.jsx("div",{className:"md:hidden -mx-5 -mt-8 border-b border-border/10 bg-gradient-to-b from-muted/25 to-background/95 px-4 py-4",children:s.jsx("div",{className:"grid grid-cols-3 gap-2",children:cr.map(e=>s.jsxs("button",{onClick:()=>Ds(e.key),className:S("flex min-h-[72px] flex-col items-center justify-center gap-1.5 rounded-2xl border px-2 py-3 text-center transition-all",As===e.key?e.danger?"border-destructive/30 bg-destructive text-destructive-foreground shadow-md":"border-primary/25 bg-primary text-primary-foreground shadow-md":e.danger?"border-destructive/10 bg-background text-destructive/80":"border-border/20 bg-background text-muted-foreground hover:border-border/30 hover:bg-muted/50 hover:text-foreground"),children:[s.jsx("span",{className:"flex h-8 w-8 items-center justify-center rounded-full bg-black/10",children:e.icon}),s.jsx("span",{className:"text-[11px] font-bold leading-tight",children:e.label})]},e.key))})}),("header"===As||"preview"===As)&&s.jsxs("div",{className:"space-y-4 mb-1",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("h2",{className:"text-lg font-bold tracking-tight",children:"header"===As?"Select Header Image":"Select Preview Echoes"}),"preview"===As&&s.jsxs(r,{variant:"outline",size:"sm",onClick:()=>{0!==Js.length&&Ye([...Js].sort(()=>.5-Math.random()).slice(0,4).map(e=>e.id))},className:"rounded-xl text-[11px] font-bold gap-1.5 h-8 px-3 border-border/30 hover:bg-background shadow-sm hover:text-foreground",children:[s.jsx(re,{className:"w-3 h-3"}),"Randomize"]})]}),s.jsxs("div",{className:"relative group",children:[s.jsx(ae,{className:"absolute left-4 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground group-focus-within:text-primary transition-colors"}),s.jsx(a,{value:Ts,onChange:e=>zs(e.target.value),placeholder:"Filter images...",className:"h-11 pl-11 rounded-2xl bg-background border border-border/20 focus-visible:ring-2 focus-visible:ring-primary text-sm font-medium shadow-sm transition-all"})]})]}),"info"===As&&s.jsxs("div",{className:"space-y-6 md:space-y-8 animate-in fade-in slide-in-from-right-4 duration-400",children:[s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("label",{className:"text-[10px] font-black text-muted-foreground mb-2 block uppercase tracking-widest pl-1",children:"Board Name"}),s.jsx(a,{value:ze,onChange:e=>Ae(e.target.value),placeholder:"e.g. Dream Home",className:"h-12 rounded-2xl bg-background border border-border/20 focus-visible:ring-2 focus-visible:ring-primary font-bold shadow-sm"})]}),s.jsxs("div",{children:[s.jsx("label",{className:"text-[10px] font-black text-muted-foreground mb-2 block uppercase tracking-widest pl-1",children:"Description"}),s.jsx(a,{value:De,onChange:e=>Ve(e.target.value),placeholder:"What's this board about?",className:"h-12 rounded-2xl bg-background border border-border/20 focus-visible:ring-2 focus-visible:ring-primary shadow-sm font-medium"})]})]}),s.jsxs("div",{className:"flex flex-wrap gap-2.5",children:[s.jsxs("span",{className:S("inline-flex items-center gap-1.5 text-[11px] font-bold uppercase tracking-[0.15em] px-4 py-2 rounded-xl border shadow-sm transition-colors",{"text-orange-500 border-orange-500/30 bg-
1orange-500/10 hover:bg-orange-500/15":Ze,"text-purple-500 border-purple-500/30 bg-purple-500/10 hover:bg-purple-500/15":!Ze&&as,"text-emerald-500 border-emerald-500/30 bg-emerald-500/10 hover:bg-emerald-500/15":!Ze&&!as}),children:[Ze?s.jsx(te,{className:"w-3.5 h-3.5"}):as?s.jsx(ie,{className:"w-3.5 h-3.5"}):s.jsx(le,{className:"w-3.5 h-3.5"}),mr]}),l.is_smart&&s.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[11px] font-bold uppercase tracking-[0.15em] px-4 py-2 rounded-xl border text-primary border-primary/30 bg-primary/10 shadow-sm hover:bg-primary/15 transition-colors",children:[s.jsx(oe,{className:"w-3.5 h-3.5"}),"Smart Board"]})]}),s.jsx("div",{className:"grid grid-cols-2 gap-3 md:gap-4",children:[{label:"Total Echoes",value:dr.toLocaleString()},{label:"Created",value:Ue(l.created_at)},{label:"Last Updated",value:Ue(l.updated_at)},{label:"Board Link",value:s.jsxs("div",{className:"flex items-center gap-3 bg-background/50 p-1.5 pl-3 rounded-xl border border-border/10",children:[s.jsx("span",{className:"text-xs font-mono text-muted-foreground truncate flex-1 leading-none",children:T(z({id:l.id,ownerUsername:l.owner_username,slug:l.slug}))}),s.jsx("button",{onClick:async()=>{const e=T(z({id:l.id,ownerUsername:l.owner_username,slug:l.slug}));await navigator.clipboard.writeText(e),q({content_type:"board",method:"copy_link",board_id:l.id,share_location:"board_editor"}),_e({title:"Board link copied",description:e,variant:"success"})},className:"p-2 rounded-lg hover:bg-muted transition-colors shrink-0 text-muted-foreground hover:text-foreground active:scale-95 bg-background shadow-xs border border-border/30",children:s.jsx(ne,{className:"w-3.5 h-3.5"})})]})}].map(({label:e,value:r})=>s.jsxs("div",{className:"p-4 md:p-5 rounded-2xl bg-muted/20 border border-border/20 space-y-1.5 hover:bg-muted/40 transition-colors shadow-sm",children:[s.jsx("p",{className:"text-[10px] font-black uppercase tracking-widest text-muted-foreground/80",children:e}),s.jsx("div",{className:"text-sm md:text-base font-bold text-foreground",children:r})]},e))})]}),"tabs"===As&&s.jsxs("div",{className:"space-y-6 animate-in fade-in slide-in-from-right-4 duration-400",children:[s.jsxs("div",{className:"flex items-center gap-3 pb-3 border-b border-border/10",children:[s.jsx("div",{className:"w-10 h-10 rounded-2xl bg-primary/10 flex items-center justify-center text-primary shrink-0 shadow-inner",children:s.jsx(re,{className:"w-5 h-5"})}),s.jsxs("div",{children:[s.jsx("h2",{className:"text-xl font-bold tracking-tight",children:"Sort Tabs"}),s.jsx("p",{className:"text-xs mt-0.5 text-muted-foreground font-medium",children:"Choose your tabs and order"})]})]}),s.jsx("div",{className:"space-y-2",children:Fs.tabOrder.map((e,r)=>{const a=ur[e],i=Fs.tabsVisible[e],l=xr===e&&i;return s.jsx("div",{className:S("p-3 rounded-2xl border transition-colors",i?"bg-muted/20 border-border/20":"bg-muted/10 border-border/10 opacity-70"),children:s.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx("button",{type:"button",onClick:()=>Xs(r,-1),disabled:0===r,className:"p-1 rounded-md hover:bg-muted disabled:opacity-30 disabled:cursor-not-allowed",children:s.jsx(de,{className:"w-3 h-3"})}),s.jsx("button",{type:"button",onClick:()=>Xs(r,1),disabled:r===Fs.tabOrder.length-1,className:"p-1 rounded-md hover:bg-muted disabled:opacity-30 disabled:cursor-not-allowed",children:s.jsx(ce,{className:"w-3 h-3"})})]}),s.jsx("div",{className:"w-8 h-8 rounded-xl bg-background border border-border/20 flex items-center justify-center text-muted-foreground",children:a.icon}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"text-sm font-bold",children:a.label}),s.jsx("p",{className:"text-[10px] text-muted-foreground font-medium",children:"Sort mode"})]}),l&&s.jsx("span",{className:"text-[9px] px-2 py-1 rounded-full bg-primary/10 text-primary font-bold uppercase tracking-wide",children:"Default"}),s.jsx(t,{checked:i,onCheckedChange:s=>((e,s)=>{qs(r=>{const a={...r.tabsVisible,[e]:s};
1return 0===Object.values(a).filter(Boolean).length?r:A({...r,tabsVisible:a})})})(e,s)})]})},e)})})]}),("header"===As||"preview"===As)&&s.jsxs("div",{className:"space-y-6",children:["header"===As&&s.jsxs("div",{className:"rounded-2xl border border-dashed border-border/40 bg-muted/20 p-4",children:[s.jsx("input",{ref:Os,type:"file",accept:"image/*,.heic,.heif",className:"sr-only",onChange:e=>{var s;return(async e=>{var s,r,a;if(e)if(e.type.startsWith("image/")||Z(e)){js(!0);try{const{data:t,error:i}=await O.auth.getSession(),n=null==(s=t.session)?void 0:s.access_token,d=(null==(a=null==(r=t.session)?void 0:r.user)?void 0:a.id)||(null==Ls?void 0:Ls.id);if(i||!n||!d)throw new Error("Please sign in again before uploading a board header.");const c=(e=>"image/gif"===e.type.trim().toLowerCase()||e.name.trim().toLowerCase().endsWith(".gif"))(e);if(c&&e.size>15728640)throw new Error("Animated GIF headers must be 15 MB or smaller.");const m=c?e:await Us(e,{maxSizeMB:2.5,maxWidthOrHeight:2400,fileType:"image/webp"}),u=await K(m,d,n,"_board_header");if(He(null),Fe(u),Ge(50),Je(100),!(await o(l.id,{header_image_id:null,custom_header_image_url:u,header_image_position:50,header_image_zoom:100})))throw new Error("The image uploaded, but Echo could not save it as this board header.");_e({title:"Header image uploaded and saved"})}catch(t){_e({title:"Upload failed",description:(null==t?void 0:t.message)||"Echo could not upload that header image. Please retry.",variant:"error"})}finally{js(!1),Os.current&&(Os.current.value="")}}else _e({title:"Choose an image",description:"Board headers support image files only.",variant:"error"})})(null==(s=e.target.files)?void 0:s[0])}}),s.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("h3",{className:"text-sm font-bold text-foreground",children:"Upload Header Image"}),s.jsx("p",{className:"mt-0.5 text-xs font-medium text-muted-foreground",children:"Use an image without saving it as an Echo."})]}),s.jsxs(r,{type:"button",variant:"outline",className:"h-10 rounded-xl border-border/30 font-bold",disabled:vs,onClick:()=>{var e;return null==(e=Os.current)?void 0:e.click()},children:[vs?s.jsx(me,{className:"w-4 h-4 mr-2 animate-spin"}):s.jsx(ue,{className:"w-4 h-4 mr-2"}),vs?"Uploading...":"Upload Image"]})]})]}),rr&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("h3",{className:"text-[10px] font-bold text-primary uppercase tracking-widest",children:"Current Selection"}),s.jsx(r,{variant:"ghost",size:"sm",className:"h-6 text-[10px] font-bold text-muted-foreground px-2",onClick:()=>{"header"===As?(He(null),Fe(null)):Ye([])},children:"Clear All"})]}),"header"===As&&(sr||Re)&&s.jsxs("div",{className:"p-4 bg-primary/5 rounded-2xl border border-primary/10 space-y-4",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("label",{className:"text-[9px] font-bold text-primary/60 uppercase tracking-widest flex items-center gap-2",children:["Vertical Position ",s.jsxs("span",{className:"text-primary",children:[qe,"%"]})]}),s.jsx(r,{variant:"ghost",size:"sm",className:"h-5 text-[9px] font-bold text-primary/40 hover:text-primary p-0",onClick:()=>Ge(50),disabled:50===qe,children:"Center"})]}),s.jsx("input",{type:"range",min:"0",max:"100",value:qe,onInput:e=>Ge(Number(e.currentTarget.value)),onChange:e=>Ge(Number(e.currentTarget.value)),"aria-label":"Header vertical position",className:"w-full accent-primary h-1.5 rounded-full appearance-none cursor-pointer"}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("label",{className:"text-[9px] font-bold text-primary/60 uppercase tracking-widest flex items-center gap-2",children:["Zoom ",s.jsxs("span",{className:"text-primary",children:[We,"%"]})]}),s.jsx(r,{variant:"ghost",size:"sm",className:"h-5 text-[9px] font-bold text-primary/40 hover:text-primary p-0",onClick:()=>Je(100),disabled:100===We,children:"Reset"})]}),s.jsx("input",{type:"range",min:"100",max:"300",step:"5",value:We,onInput:e=>Je(Number(e.currentTarget.value)),onChange:e=>Je(Number(e.currentTarget.value)),"aria-label":"Header zoom",className:"w-full accent-primary h-1.5 rounded-full appearance-none cursor-pointer"}),s.jsx("div",{className:"h-24 w-full rounded-xl overflow-hidden relative shadow-inner flex items-center justify-center bg-black",children:sr?s.jsx(Be,{videoUrl:sr.video_url,imageUrl:sr.image_url,autoPlay:!X,style:{objectPosition:`center ${qe}%`,transform:`scale(${We/100})`},className:"w-full h-full object-cover transition-all"}):s.jsx("img",{src:Re,alt:"",style:{objectPosition:`center ${qe}%`,transform:`scale(${We/100})`},className:"w-full h-full object-cover transition-all",decoding:"async"})})]}),s.jsx("div",{className:"grid grid-cols-3 md:grid-cols-4 gap-2",children:ar.map((e,r)=>{const a=I(e.image_url,"thumbnail");return s.jsxs("div",{className:"aspect-square rounded-xl overflow-hidden relative group cursor-pointer ring-2 ring-primary ring-offset-2 ring-offset-background/50 shadow-lg animate-in zoom-in-95 duration-200 bg-black",onClick:()=>{"header"===As?(He(null),Fe(null)):er(e.id)},children:["video"===e.type?s.jsxs(s.Fragment,{children:[s.jsx(Be,{videoUrl:e.video_url,imageUrl:e.image_url,className:"w-full h-full object-cover"}),s.jsx("div",{className:"absolute top-1.5 right-1.5 p-1 rounded-full bg-black/40",children:s.jsx(xe,{className:"w-2.5 h-2.5 text-white"})})]}):s.jsx("img",{src:a||e.image_url,alt:"",className:"w-full h-full object-cover",decoding:"async"}),s.jsx("div",{className:"absolute inset-0 bg-black/40 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center",children:s.jsx(he,{className:"w-5 h-5 text-white"})}),s.jsx("div",{className:"absolute top-1.5 left-1.5 w-4 h-4 rounded-full bg-primary text-[9px] font-bold text-white flex items-center justify-center",children:"header"===As?"H":r+1})]},`pinned-${e.id}`)})})]}),tr.length>0&&s.jsxs("div",{className:"space-y-3",children:[s.jsx("h3",{className:"text-[10px] font-bold text-muted-foreground uppercase tracking-widest",children:"All Media Echoes"}),s.jsx("div",{className:"grid grid-cols-3 md:grid-cols-4 gap-2",children:ir.map(e=>{const r=$e===e.id,a=Ke.includes(e.id),t=I(e.image_url,"thumbnail");return s.jsxs("div",{onClick:()=>{"header"===As?(He(e.id),Fe(null)):er(e.id)},className:S("aspect-square rounded-xl overflow-hidden relative group cursor-pointer transition-all duration-200 bg-black",("header"===As?r:a)?"opacity-40 scale-95":"opacity-80 hover:opacity-100 hover:scale-[1.04] hover:shadow-lg"),children:["video"===e.type?s.jsxs(s.Fragment,{children:[s.jsx(Be,{videoUrl:e.video_url,imageUrl:e.image_url,className:"w-full h-full object-cover"}),s.jsx("div",{className:"absolute top-1.5 right-1.5 p-1 rounded-full bg-black/40",children:s.jsx(xe,{className:"w-2.5 h-2.5 text-white"})})]}):s.jsx("img",{src:t||e.image_url,alt:"",className:"w-full h-full object-cover",loading:"lazy",decoding:"async"}),("header"===As?r:a)&&s.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:s.jsx("div",{className:"w-7 h-7 rounded-full bg-primary flex items-center justify-center shadow-lg animate-in zoom-in duration-200",children:s.jsx(pe,{className:"w-3.5 h-3.5 text-white"})})})]},e.id)})}),(lr||or)&&s.jsx("div",{ref:Hs,className:"flex min-h-24 w-full items-center justify-center pt-4",children:s.jsxs(r,{variant:"outline",className:"w-full rounded-xl h-10 font-bold border-border/30 hover:bg-muted/50",onClick:nr,disabled:_s,children:[_s?s.jsx(me,{className:"w-3.5 h-3.5 mr-2 animate-spin"}):s.jsx(be,{className:"w-3.5 h-3.5 mr-2"}),_s?"Loading...":"Load More"]})})]}),ys&&s.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center opacity-60 space-y-3",children:[s.jsx(me,{className:"w-8 h-8 animate-spin text-primary"}),s.jsx("p",{className:"text-sm font-medium",children:"Loading media echoes..."})]}),!ys&&0===Js.length&&s.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center opacity-30 space-y-3",children:[s.jsx(ge,{className:"w-8 h-8"}),s.jsx("p",{className:"text-sm font-medium",children:"No media echoes in this board"})]})]}),"privacy"===As&&s.jsxs("div",{className:"space-y-6 animate-in fade-in slide-in-from-right-4 duration-400",children:[s.jsxs("div",{className:"flex items-center gap-3 pb-3 border-b border-border/10 mb-2",children:[s.jsx("div",{className:"w-10 h-10 rounded-2xl bg-orange-500/10 flex items-center justify-center text-orange-500 shrink-0 shadow-inner",children:s.jsx(te,{className:"w-5 h-5"})}),s.jsxs("div",{children:[s.jsx("h2",{className:"text-xl font-bold tracking-tight",children:"Privacy"}),s.jsx("p",{className:"text-xs mt-0.5 text-muted-foreground font-medium",children:"Control who can see this board"})]})]}),d&&s.jsxs("div",{className:"p-4 rounded-2xl bg-muted/30 border border-border/10 flex items-center justify-between gap-3 hover:bg-muted/50 transition-colors",children:[s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[s.jsx("div",{className:"w-8 h-8 rounded-xl bg-purple-500/10 flex items-center justify-center text-purple-500 shrink-0",children:s.jsx(ie,{className:"w-4 h-4"})}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"font-semibold text-sm",children:"Hidden Board"}),s.jsx("p",{className:"text-xs text-muted-foreground font-medium",children:"Hides echoes from your feeds only. Public boards stay visible to others."})]})]}),s.jsx(t,{checked:as,onCheckedChange:ts,className:"data-[state=checked]:bg-purple-500 shrink-0"})]}),s.jsxs("div",{className:"p-4 rounded-2xl bg-muted/30 border border-border/10 flex items-center justify-between gap-3 hover:bg-muted/50 transition-colors",children:[s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[s.jsx("div",{className:S("w-8 h-8 rounded-xl flex items-center justify-center shrink-0",Ze?"bg-orange-500/10 text-orange-500":"bg-emerald-500/10 text-emerald-500"),children:Ze?s.jsx(te,{className:"w-4 h-4"}):s.jsx(le,{className:"w-4 h-4"})}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"font-semibold text-sm",children:Se||Ze?"Private Board":"Public Board"}),s.jsx("p",{className:"text-xs text-muted-foreground font-medium",children:Se?"Public publishing is unavailable for this account":d?Ze?"Only you and collaborators can see it":"Visible on Explore & your profile":`Only the board owner can change visibility. This board is ${Ze?"private":"public"}.`})]})]}),s.jsx(t,{checked:!Se&&!Ze,disabled:Se||!d,onCheckedChange:e=>{if(Se||!d)return;const s=!e;Xe(s),s||(ns(!1),ls(""))},"aria-label":d?"Make board public":"Board visibility can only be changed by its owner",className:"data-[state=checked]:bg-primary shrink-0"})]}),s.jsx("div",{className:S("space-y-3 transition-all duration-400 overflow-hidden",Ze?"opacity-100 max-h-[400px]":"opacity-0 max-h-0 pointer-events-none"),children:s.jsxs("div",{className:"p-4 rounded-2xl bg-primary/5 border border-primary/10 space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-2 text-primary",children:[s.jsx(te,{className:"w-3.5 h-3.5"}),s.jsx("p",{className:"text-[10px] font-bold uppercase tracking-widest",children:"PIN Protection"})]}),os&&s.jsx(r,{variant:"ghost",size:"sm",onClick:()=>{ns(!1),ls("")},className:"h-6 text-[10px] font-bold text-muted-foreground hover:text-destructive px-2",children:"Remove PIN"})]}),os?s.jsx(a,{type:"password",value:is,onChange:e=>ls(e.target.value),placeholder:"Enter a PIN...",className:"h-12 rounded-xl bg-background border-border/50 text-center text-lg font-bold tracking-[0.5em] focus-visible:ring-primary",maxLength:16,autoComplete:"new-password",autoFocus:!0}):s.jsxs(r,{variant:"outline",onClick:()=>ns(!0),className:"w-full h-11 rounded-xl bg-primary/5 border-primary/20 text-primary font-bold gap-2 hover:bg-primary/10",children:[s.jsx(be,{className:"w-4 h-4"}),"Enable PIN Protection"]})]})}),s.jsx("div",{className:S("transition-all duration-400 overflow-hidden",Ze?"opacity-0 max-h-0 pointer-events-none":"opacity-100 max-h-[620px]"),children:s.jsxs("div",{className:"space-y-3 rounded-2xl border border-border/10 bg-muted/30 p-4",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"font-semibold text-sm",children:"Sensitive Material"}),s.jsx("p",{className:"text-xs text-muted-foreground font-medium",children:"Label the categories viewers may choose to hide."})]}),s.jsx(t,{checked:Qe,onCheckedChange:es,className:"data-[state=checked]:bg-primary shrink-0"})]}),Qe&&s.jsx("div",{className:"grid gap-1 border-t border-border/10 pt-3 sm:grid-cols-2",children:G.map(e=>s.jsxs("label",{className:"flex cursor-pointer items-start gap-2 rounded-xl p-2 text-sm hover:bg-background/60",children:[s.jsx(i,{checked:ss.includes(e.id),onCheckedChange:s=>rs(r=>s?[...r,e.id]:r.filter(s=>s!==e.id))}),s.jsx("span",{className:"leading-4",children:e.label})]},e.id))})]})})]}),"collaborators"===As&&s.jsx(Le,{boardId:l.id,boardName:l.name,isOwner:d,isActive:"collaborators"===As,ownerUsername:l.owner_username,boardSlug:l.slug}),"delete"===As&&n&&d&&s.jsxs("div",{className:"space-y-5 animate-in fade-in slide-in-from-right-4 duration-300",children:[s.jsxs("div",{className:"flex items-center gap-3 pb-2",children:[s.jsx("div",{className:"w-10 h-10 rounded-2xl bg-destructive/10 flex items-center justify-center text-destructive shrink-0",children:s.jsx(fe,{className:"w-5 h-5"})}),s.jsxs("div",{children:[s.jsx("h2",{className:"text-lg font-bold tracking-tight",children:"Delete Board"}),s.jsx("p",{className:"text-xs text-muted-foreground font-medium",children:"This cannot be undone"})]})]}),s.jsxs("div",{className:"p-4 rounded-2xl bg-muted/30 border border-border/10 space-y-1",children:[s.jsx("p",{className:"text-[10px] font-bold text-destructive uppercase tracking-widest",children:"â Important"}),s.jsxs("p",{className:"text-xs font-medium text-muted-foreground",children:["The board will be permanently deleted. Choose what should happen to its ",dr," echo",1!==dr?"es":""," first."]})]}),0===dr?ms?s.jsxs("div",{className:"space-y-3 animate-in fade-in slide-in-from-bottom-2 duration-200",children:[s.jsx("p",{className:"text-sm font-bold text-center text-destructive",children:"Are you sure? This is permanent."}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx(r,{variant:"outline",onClick:()=>us(!1),className:"flex-1 h-12 rounded-xl font-bold",children:"Cancel"}),s.jsxs(r,{variant:"destructive",onClick:async()=>
1{if(n&&!ps){bs(!0);try{await n(l.id,{isEmpty:!0}),Oe(!1)}catch(e){}finally{bs(!1)}}},disabled:ps,className:"flex-1 h-12 rounded-xl font-bold gap-2",children:[s.jsx(fe,{className:"w-4 h-4"}),"Delete Forever"]})]})]}):s.jsxs(r,{variant:"destructive",onClick:()=>us(!0),disabled:ps,className:"w-full h-13 rounded-2xl font-bold text-base gap-3",children:[s.jsx(fe,{className:"w-5 h-5"}),'Delete "',l.name,'"']}):s.jsxs("div",{className:"space-y-3",children:[s.jsx(W,{open:gs,onOpenChange:fs,boards:Ys,onMove:async(e,s)=>{if(n&&!ps){bs(!0),fs(!1);try{const r=await(async()=>{const{data:e,error:s}=await O.from("memory_boards").select("memory_id").eq("board_id",l.id);if(s)throw s;return Array.from(new Set((e||[]).map(e=>e.memory_id).filter(Boolean)))})();if(r.length>0){const a=await Es(r,e);if(!a.ok)return void _e({title:"Could not move echoes",description:a.message||"The board was not deleted. Please try again.",variant:"error"});if(s){const a=await R({boardId:e,memoryIds:r,sectionId:s,mode:"replace"});V(e,a)}}await n(l.id),Oe(!1)}catch(r){_e({title:"Could not delete board",description:(null==r?void 0:r.message)||"Something went wrong while deleting this board.",variant:"error"})}finally{bs(!1)}}},disabled:ps,title:"Move Echoes First",description:`Select a board for the ${dr} echo${1!==dr?"es":""} before deleting this board.`,emptyMessage:"No other editable boards available.",trigger:s.jsxs(r,{variant:"outline",disabled:ps||0===Ys.length,className:"w-full h-13 rounded-2xl font-bold text-base gap-3",children:[s.jsx(ve,{className:"w-5 h-5"}),"Move echoes, then delete board"]})}),s.jsxs(r,{variant:"destructive",onClick:()=>hs(!0),disabled:ps,className:"w-full h-13 rounded-2xl font-bold text-base gap-3",children:[s.jsx(fe,{className:"w-5 h-5"}),"Delete echoes and board"]}),0===Ys.length&&s.jsx("p",{className:"text-xs text-center text-muted-foreground",children:"Create another editable board to move these echoes before deleting."}),s.jsx(v,{open:xs,onOpenChange:hs,children:s.jsxs(j,{className:"rounded-3xl",children:[s.jsxs(w,{children:[s.jsx(N,{children:"Delete echoes and board?"}),s.jsxs(y,{children:["This moves ",dr," echo",1!==dr?"es":"",' to trash and permanently deletes "',l.name,'".']})]}),s.jsxs(k,{children:[s.jsx(_,{className:"rounded-full",children:"Cancel"}),s.jsx(C,{onClick:async()=>{if(n&&!ps){bs(!0),hs(!1);try{await n(l.id,{deleteEchoes:!0}),Oe(!1)}catch(e){_e({title:"Could not delete echoes",description:(null==e?void 0:e.message)||"The board was not deleted. Please try again.",variant:"error"})}finally{bs(!1)}}},className:"rounded-full bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete echoes and board"})]})]})})]})]})]}),s.jsx("div",{className:"md:hidden sticky bottom-0 z-20 bg-background/95 backdrop-blur-xl border-t border-border/10 px-4 pt-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]",children:s.jsxs("div",{className:"flex gap-3",children:[s.jsx(r,{variant:"outline",onClick:()=>Oe(!1),className:"rounded-2xl font-bold h-12 px-6 flex-1 border-border/30 hover:bg-muted shadow-sm",children:"Cancel"}),s.jsx(r,{onClick:Qs,disabled:!ze.trim()||ds,className:"rounded-2xl bg-foreground text-background px-8 h-12 font-bold hover:scale-[1.02] active:scale-95 transition-all shadow-lg flex-1 text-[15px]",children:ds?"Saving...":"Save Changes"})]})})]})]})]})]})}export{Oe as BoardEditor,Be as VideoThumbnail};
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.