PageSourceSearch

https://getvsble.com/assets/FileSharing-DbfsOM0S.js

js getvsble.com collected 2026-10-09 04:53:59 UTC 188,182 bytes, 74 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/upload-branding-ClqCFvGd.js","assets/upload-logo-CcfplDqL.js","assets/upload-retry-CkYHsLSi.js"])))=>i.map(i=>d[i]);
2import{d as Mt,u as Et,aj as xr,H as bt,r as s,j as e,D as vt,e as yt,a7 as St,f as wt,g as Pt,L as Rt,N as Ia,C as Ls,cJ as pr,s as U,aK as G,c as Ve,ak as Ms,a9 as ht,a8 as Lt,B as ae,T as Ns,aw as Da,cK as jr,cL as la,cM as os,cN as na,X as Ts,S as Dt,b as Ra,cO as Ea,aR as Us,ac as qs,h as ps,aA as zt,ab as Bs,G as zs,au as At,aT as br,cP as vr,cQ as Ta,cR as ia,az as yr,cA as $s,t as ks,ar as Ba,cC as as,ai as Gs,ae as Oa,at as Sr,am as wr}from"./index-ByYYWl6V.js";import{P as oa,S as Aa,R as Nr,b as ca,a as kr}from"./resizable-B0_7r2eN.js";import{S as _r,a as Cr}from"./sheet-ke76V1vr.js";import{H as cs,B as ss,S as Fr,D as da,F as Ir,a as Dr}from"./FileSharingTopBar-BKCQqyJ7.js";import{w as Rr,R as Os}from"./upload-retry-CkYHsLSi.js";import{F as Pa,c as $t,g as ds,a as Gt,A as La,S as Er,G as Tr,u as Br,b as Or,E as Ar,I as Pr,i as Ma,h as us,L as fs,d as Ua}from"./SelectionBar-Hu4Iampu.js";import{r as qa,I as Lr}from"./parallel-upload-D_9irpXW.js";import{g as za,f as Hs,S as Mr,r as Ur,u as qr,a as ua,T as zr,P as $r,d as Gr,D as Hr,M as Wr,b as Yr,p as Kr,h as Vr,c as Xr}from"./sortable.esm-CFcZ9Lyv.js";import{A as Jr,b as Zr,a as Qr}from"./avatar-DfyiTc_8.js";import{G as el}from"./grip-vertical-CLNdFa0Z.js";import{C as js}from"./chevron-right-X_hlXzqd.js";import{F as Ht}from"./folder-CJPKIQi5.js";import{L as We}from"./label-Dast61oh.js";import{P as bs}from"./plus-CwyWY8pM.js";import{i as Zt}from"./supabase-functions-CBdNz-q5.js";import{C as tl}from"./circle-check-DOzaU1SH.js";import{extractStorageKey as hs,downloadSingleFile as Ws,downloadZip as sl}from"./download-share-C57d6_DY.js";import{u as $a,a as al,b as rl,c as ll}from"./use-fs-global-settings-B3TDjFTS.js";import{P as Ys}from"./progress-BNcERlIT.js";import{f as nl}from"./format-relative-time-C2tafYUB.js";import{F as il,a as Ga,S as Ha,b as Wa}from"./StarFlagOverlay-DDoe9_fI.js";import{D as Ks,a as Vs,b as Xs,c as jt}from"./dropdown-menu-BZRKspBv.js";import{B as ol}from"./badge-DuSeH5ON.js";import{T as cl,a as dl,b as _s,c as Cs}from"./tabs-DWXE4Edw.js";import{U as ms}from"./upload-MFMh3Tjq.js";import{u as vs,a as ul}from"./use-posthog-analytics-6Qqrf_m9.js";import{S as Wt,a as Yt,b as Kt,c as Vt,d as Ie}from"./select-B7Jb7eSA.js";import{C as fl}from"./color-picker-Co1J2vdd.js";import{B as hl}
2from"./BrandingTabContent-AxGSxtF7.js";import{s as Ya}from"./socialIcons-Dlte2CRe.js";import{L as ys}from"./link-2-C5arFvZC.js";import{C as Ss}from"./clock-CUm8QZGC.js";import{d as fa,a as ha,P as ml}from"./PresentationLayoutTab-DJquzsVI.js";import{P as ls}from"./pencil-B-pqnzl9.js";import{D as Js}from"./download-BCb29Zdu.js";import{T as Ka}from"./trash-2-250o4KTP.js";import{S as gl}from"./settings-Cp6SvoNk.js";import{P as Va}from"./palette-B9pczpnA.js";import{L as Xa}from"./layout-grid-_L0PwbdX.js";import{S as xl}from"./shield-check-B0UX5bny.js";import{E as Ja}from"./eye-BhPuToFK.js";import{S as Zs}from"./share-2-DrBJv4wL.js";import{P as ma,a as ga,b as xa}from"./popover-iAHc-IZW.js";import{S as pl}from"./star-D_vJGcvx.js";import{M as Qs}from"./message-square-UsUNDqt9.js";import{U as jl}from"./user-DZPeHrpM.js";import{L as bl}from"./save-BaQtVCdH.js";import{P as Fs}from"./panel-left-MR5e7au6.js";import{P as Za}from"./play-Dtjk4TBP.js";import{E as Qa}from"./ellipsis-CAg5Wdfa.js";import"./StandaloneAccountPanel-D043IwtX.js";import"./card-CsB1Huog.js";import"./alert-dialog-Cm0yc26w.js";import"./rotate-ccw-C6kbywiV.js";import"./circle-x-BI9LabY8.js";import"./ThemeToggle-BMzpTRWb.js";import"./sun-CAzXMSBU.js";import"./chevron-left-yeSSr-Cv.js";import"./WatermarkOverlay-B0QrXr1q.js";import"./info-CA6lfwP8.js";import"./users-8DqkLtTC.js";import"./index-C4Lchjjk.js";import"./triggerBrowserDownload-BPysCpKo.js";import"./GlobalBadgesPage-C-PDT4x_.js";import"./en-US-D0KhEKBm.js";import"./index-CnBNeFET.js";import"./circle-DcpkfI2n.js";import"./chevron-up-DJ99KL3C.js";import"./slider-CIs_wqYq.js";import"./upload-branding-ClqCFvGd.js";import"./upload-logo-CcfplDqL.js";import"./debounced-textarea-teDmVD5p.js";import"./monitor-DTXzMkCS.js";import"./smartphone-CRfaQD3C.js";import"./arrow-down-H-W4g0lv.js";import"./align-right-DPvz-fbO.js";/**
3 * @license lucide-react v0.462.0 - ISC
4 *
5 * This source code is licensed under the ISC license.
6 * See the LICENSE file in the root directory of this source tree.
7 */const vl=Mt("Dot",[["circle",{cx:"12.1",cy:"12.1",r:"1",key:"18d7e5"}]]);/**
8 * @license lucide-react v0.462.0 - ISC
9 *
10 * This source code is licensed under the ISC license.
11 * See the LICENSE file in the root directory of this source tree.
12 */const yl=Mt("EllipsisVertical",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]]);/**
13 * @license lucide-react v0.462.0 - ISC
14 *
15 * This source code is licensed under the ISC license.
16 * See the LICENSE file in the root directory of this source tree.
17 */const As=Mt("FolderPlus",[["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]);/**
18 * @license lucide-react v0.462.0 - ISC
19 *
20 * This source code is licensed under the ISC license.
21 * See the LICENSE file in the root directory of this source tree.
22 */const ea=Mt("Link2Off",[["path",{d:"M9 17H7A5 5 0 0 1 7 7",key:"10o201"}],["path",{d:"M15 7h2a5 5 0 0 1 4 8",key:"1d3206"}],["line",{x1:"8",x2:"12",y1:"12",y2:"12",key:"rvw6j4"}],["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}]]);/**
23 * @license lucide-react v0.462.0 - ISC
24 *
25 * This source code is licensed under the ISC license.
26 * See the LICENSE file in the root directory of this source tree.
27 */const Sl=Mt("PanelLeftClose",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"m16 15-3-3 3-3",key:"14y99z"}]]);/**
28 * @license lucide-react v0.462.0 - ISC
29 *
30 * This source code is licensed under the ISC license.
31 * See the LICENSE file in the root directory of this source tree.
32 */const Ps=Mt("PinOff",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89",key:"znwnzq"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11",key:"c9qhm2"}]]);/**
33 * @license lucide-react v0.462.0 - ISC
34 *
35 * This source code is licensed under the ISC license.
36 * See the LICENSE file in the root directory of this source tree.
37 */const er=Mt("Pin",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7
37a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]]);/**
38 * @license lucide-react v0.462.0 - ISC
39 *
40 * This source code is licensed under the ISC license.
41 * See the LICENSE file in the root directory of this source tree.
42 */const wl=Mt("UserCheck",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["polyline",{points:"16 11 18 13 22 9",key:"1pwet4"}]]);function Nl(){const{user:t,isAdmin:r}=Et(),a=xr();return{hasAccess:!!t&&(r||a.file_sharing.active),userEmail:t==null?void 0:t.email}}const kl=[{name:"Starter",storage:ss.starter,taglineKey:"fileSharing.storage.starterTagline",taglineFallback:"Perfect for getting started",features:[{key:"fileSharing.storage.starterFeature1",fallback:"10 pages · 250 images"},{key:"fileSharing.storage.starterFeature2",fallback:"Canvas Pages"},{key:"fileSharing.storage.starterFeature3",fallback:"Custom Domain"}]},{name:"Creator",storage:ss.creator,taglineKey:"fileSharing.storage.creatorTagline",taglineFallback:"For professionals & creatives",features:[{key:"fileSharing.storage.creatorFeature1",fallback:"50 pages · 400 images"},{key:"fileSharing.storage.creatorFeature2",fallback:"Blog & AI Pages"},{key:"fileSharing.storage.creatorFeature3",fallback:"10 min Video Upload"}]},{name:"Studio",storage:ss.studio,taglineKey:"fileSharing.storage.studioTagline",taglineFallback:"For studios & teams",features:[{key:"fileSharing.storage.studioFeature1",fallback:"150 pages · 1,000 images"},{key:"fileSharing.storage.studioFeature2",fallback:"Custom Fonts · PDF Maker"},{key:"fileSharing.storage.studioFeature3",fallback:"50 min Video Upload"}]},{name:"Business",storage:ss.business,taglineKey:"fileSharing.storage.businessTagline",taglineFallback:"For agencies & businesses",features:[{key:"fileSharing.storage.businessFeature1",fallback:"Unlimited pages & images"},{key:"fileSharing.storage.businessFeature2",fallback:"Advanced SEO & Analytics Export"},{key:"fileSharing.storage.businessFeature3",fallback:"1h 40 min Video Upload"}]}];function tr({open:t,onOpenChange:r}){const{t:a}=bt(),[g,o]=s.useState(null),l=(h,C)=>{const N=a(h);return N===h?C:N},S=async h=>{o(h);try{const C=pr[h].monthly,{data:N,error:f}=await U.functions.invoke("create-checkout",{body:{priceId:C}});if(f)throw f;if(N!=null&&N.error)throw new Error(N.error);N!=null&&N.url&&(window.open(N.url,"_blank"),r(!1))}catch(C){G.error(C.message||"Failed to start checkout")}finally{o(null)}};return e.jsx(vt,{open:t,onOpenChange:r,children:e.jsxs(yt,{className:"sm:max-w-2xl",children:[e.jsxs(St,{children:[e.jsxs(wt,{className:"flex items-center gap-2",children:[e.jsx(cs,{className:"h-5 w-5 text-primary"}),l("fileSharing.storage.upgradePlanRequired","Upgrade Your Plan")]}),e.jsx(Pt,{children:l("fileSharing.storage.legacyDescription","Your current plan doesn't support storage add-ons. Choose a modern plan below to unlock extra storage and premium features.")})]}),e.jsx("div",{className:"grid gap-2 pt-1 sm:grid-cols-2",children:kl.map(({name:h,storage:C,taglineKey:N,taglineFallback:f,features:v})=>e.jsxs("button",{disabled:g!==null,onClick:()=>S(h),className:"group flex w-full flex-col gap-2 rounded-lg border border-border px-3 py-3 text-left transition-colors hover:border-primary/50 hover:bg-accent disabled:opacity-50",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-sm font-semibold text-foreground",children:h}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:l(N,f)})]}),g===h?e.jsx(Rt,{className:"h-4 w-4 animate-spin text-primary"}):e.jsx(Ia,{className:"h-4 w-4 text-muted-foreground transition-transform group-hover:translate-x-0.5 group-hover:text-primary"})]}),e.jsxs("div",{className:"flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 w-fit",children:[e.jsx(cs,{className:"h-3 w-3 text-primary"}),e.jsxs("span",{className:"text-[11px] font-medium text-primary",children:[C," GB ",l("fileSharing.storage.gbIncluded","included")]})]}),e.jsx("ul",{className:"flex flex-col gap-1",children:v.map(({key:I,fallback:x})=>e.jsxs("li",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[e.jsx(Ls,{className:"h-3 w-3 shrink-0 text-primary"}),l(I,x)]},I))})]},h))})]})})}function sr({open:t,onOpenChange:r,usedBytes:a,totalBytes:g,onSuccess:o}){const{t:l}=bt(),[S,h]=s.useState(null),[C,N]=s.useState(!1),f=a/1024**3,v=g/1024**3,I=async x=>{h(x);try{const{data:d,error:E}=await U.functions.invoke("manage-extra-storage",{body:{action:"add",tier:x}});if((d==null?void 0:d.error)==="legacy_plan"||E&&JSON.stringify(E).includes("legacy_plan")){r(!1),N(!0);return}if(E)throw E;if(d!=null&&d.error)throw new Error(d.error);G.success(l("fileSharing.storage.upgraded")||"Storage upgraded!"),o(),r(!1)}catch(d){G.error(d.message||"Failed to purchase storage")}finally{h(null)}};return e.jsxs(e.Fragment,{children:[e.jsx(vt,{open:t,onOpenChange:r,children:e.jsxs(yt,{className:"sm:max-w-md",children:[e.jsxs(St,{children:[e.jsxs(wt,{className:"flex items-center gap-2",children:[e.jsx(cs,{className:"h-5 w-5 text-primary"}),l("fileSharing.storage.limitReached")||"Storage limit reached"]}),e.jsx(Pt,{children:l("fileSharing.storage.limitDescription")||"You've reached your storage limit. Add more space to continue uploading."})]}),e.jsxs("div",{className:"mb-2",children:[e.jsx("div",{className:"relative h-2.5 w-full overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full rounded-full bg-destructive transition-all",style:{width:"100%"}})}),e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:[f.toFixed(1)," GB / ",v.toFixed(0)," GB"]})]}),e.jsx("div",{className:"space-y-2",children:Fr.map(x=>e.jsxs("button",{disabled:S!==null,onClick:()=>I(x.key),className:"flex w-full items-center justify-between rounded-md border border-border px-4 py-3 text-sm hover:bg-accent hover:text-accent-foreground transition-colors disabled:opacity-50",children:[e.jsx("span",{className:"font-medium",children:x.label}),e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-muted-foreground",children:["€",x.priceEur,"/mo"]}),S===x.key&&e.jsx(Rt,{className:"h-4 w-4 animate-spin"})]})]},x.key))})]})}),e.jsx(tr,{open:C,onOpenChange:N})]})}function _l(){const{user:t}=Et(),[r,a]=s.useState(0),[g,o]=s.useState([]),[l,S]=s.useState(da*1024**3),[h,C]=s.useState(!0),N=s.useCallback(async()=>{var H,Q;if(!t)return;const[x,d,E]=await Promise.all([U.rpc("get_fs_user_storage_bytes"),U.from("fs_storage_addons").select("id, tier_key, extra_bytes").eq("user_id",t.id),U.from("profiles").select("plan_name").eq("id",t.id).single()]);x.data!=null&&a(Number(x.data)),d.data&&o(d.data);const T=((Q=(H=E.data)==null?void 0:H.plan_name)==null?void 0:Q.toLowerCase())||"",A=ss[T]??da;S(A*1024**3),C(!1)},[t]);s.useEffect(()=>{N()},[N]);const f=g.reduce((x,d)=>x+Number(d.extra_bytes),0),v=l+f,I=Math.max(v-r,0);return{usedBytes:r,totalBytes:v,remainingBytes:I,addons:g,loading:h,refreshStorage:N}}const Cl="https://dc-loader.govsble.com/v1",Fl="gGT3JWZBR*5uP%";function Il(t,r,a){return new Promise((g,o)=>{const l=new XMLHttpRequest;l.open("POST",`${Cl}/${t}/upload/share`),l.setRequestHeader("Authorization",`Bearer ${Fl}`),a&&l.upload.addEventListener("progress",h=>{h.lengthComputable&&a(Math.round(h.loaded/h.total*100))}),l.addEventListener("load",()=>{if(l.status>=200&&l.status<300)try{g(JSON.parse(l.responseText))}catch{o(new Error("Invalid JSON response from share upload"))}else l.status>=500?o(new Os(`Share upload failed (${l.status}): ${l.statusText}`,l.status)):o(new Error(`Share upload failed (${l.status}): ${l.statusText}`))}),l.addEventListener("error",()=>o(new Os("Network error during share upload"))),l.addEventListener("abort",()=>o(new Error("Share upload aborted")));let S=new FormData;S.append("file",r),l.send(S),S=null})}function Dl(t,r,a){return Rr(()=>(a==null||a(0),Il(t,r,a)))}function Is(t,r){var a;return(a=t.find(g=>g.targetSize===r))==null?void 0:a.url}async function pa(t){var r,a;try{const{stage:g,error:o,fileName:l,fileSize:S,fileMime:h,projectId:C,folderId:N}=t;let f="Unknown error",v,I;
42if(o instanceof Error)f=o.message,v=o.stack;else if(typeof o=="string")f=o;else if(o&&typeof o=="object")try{f=JSON.stringify(o)}catch{f=String(o)}o instanceof Os&&o.statusCode!=null&&(I=o.statusCode);let x=null,d=null;try{const{data:E}=await U.auth.getUser();x=((r=E.user)==null?void 0:r.id)??null,d=((a=E.user)==null?void 0:a.email)??null}catch{}await U.from("fs_upload_errors").insert({stage:g,error_message:f.slice(0,4e3),error_stack:v?v.slice(0,8e3):null,status_code:I??null,file_name:l??null,file_size:S??null,file_mime:h??null,project_id:C??null,folder_id:N??null,user_id:x,user_email:d,user_agent:typeof navigator<"u"?navigator.userAgent.slice(0,500):null,url:typeof window<"u"?window.location.href.slice(0,500):null})}catch{}}const ar=25*1024*1024,Rl=["image/jpeg","image/png","image/webp","image/gif","image/avif"];function El(t){return t.size>ar?!1:t.type&&Rl.includes(t.type)?!0:/\.(jpe?g|png|webp|gif|avif)$/i.test(t.name)}const Ds=1e3;async function ns(t){const r=[];for(let a=0;;a+=Ds){const{data:g,error:o}=await t().range(a,a+Ds-1);if(o)throw o;const l=g??[];if(r.push(...l),l.length<Ds)return r}}function Tl({node:t,depth:r,isSelected:a,hasChildren:g,onSelect:o,onToggleExpand:l,onTogglePin:S,dropIntent:h,isDragActive:C}){const{attributes:N,listeners:f,setNodeRef:v,isDragging:I}=za({id:t.id,data:{type:"tree-item",node:t}}),{setNodeRef:x,isOver:d}=Hs({id:t.id,data:{type:"tree-item",node:t}}),E=s.useRef(null),T=s.useRef(null),A=le=>{v(le),x(le),E.current=le},H=h==="inside"&&!I;s.useEffect(()=>(d&&h==="inside"&&!I&&g&&!t.expanded&&C&&(T.current=setTimeout(()=>{l(t.id)},600)),()=>{T.current&&(clearTimeout(T.current),T.current=null)}),[d,h,I,g,t.expanded,t.id,C,l]);const Q=r*14,re=8+Q;return e.jsxs("div",{className:"relative",children:[h==="above"&&!I&&e.jsx("div",{className:"absolute right-2 top-[-1.5px] z-10 h-[3px] rounded-full bg-primary transition-all duration-150 ease-out",style:{left:`${re}px`,animation:"reorder-line-in 150ms ease-out"},children:e.jsx("div",{className:"absolute -left-[5px] -top-[3.5px] h-[10px] w-[10px] rounded-full bg-primary"})}),e.jsxs("div",{ref:A,className:Ve("group relative flex items-center gap-1 rounded-md px-2 py-1.5 text-sm cursor-pointer select-none","transition-all duration-200 ease-out",a&&!H?"bg-accent text-accent-foreground":"text-sidebar-foreground hover:bg-accent/50",I&&"opacity-40 scale-95",H&&"bg-primary/15 ring-2 ring-primary/50 ring-inset rounded-md scale-[1.03] shadow-[0_0_12px_-2px_hsl(var(--primary)/0.25)]"),onClick:()=>o(t.id),children:[e.jsx("span",{className:Ve("cursor-grab transition-opacity duration-150",C?"opacity-40":"opacity-0 group-hover:opacity-60"),...N,...f,children:e.jsx(el,{className:"h-3.5 w-3.5 text-muted-foreground"})}),r>0&&e.jsx("span",{style:{width:Q},className:"shrink-0"}),g?e.jsx("button",{className:"shrink-0 p-0.5 rounded hover:bg-muted transition-colors",onClick:le=>{le.stopPropagation(),l(t.id)},children:t.expanded?e.jsx(Ms,{className:"h-3.5 w-3.5 transition-transform duration-200"}):e.jsx(js,{className:"h-3.5 w-3.5 transition-transform duration-200"})}):e.jsx("span",{className:"w-5 shrink-0"}),H?e.jsx(Pa,{className:"h-4 w-4 shrink-0 text-primary transition-all duration-200 scale-110"}):e.jsx(Ht,{className:"h-4 w-4 shrink-0 text-muted-foreground transition-colors duration-200"}),e.jsx("span",{className:"truncate flex-1",children:t.name}),t.imageCount>0&&e.jsx("span",{className:"text-xs text-muted-foreground tabular-nums mr-1",children:t.imageCount}),e.jsx("button",{className:Ve("shrink-0 p-0.5 rounded hover:bg-muted transition-all duration-150",t.pinned?"opacity-100 text-primary":"opacity-0 group-hover:opacity-60 text-muted-foreground"),onClick:le=>{le.stopPropagation(),S(t.id)},children:t.pinned?e.jsx(Ps,{className:"h-3.5 w-3.5"}):e.jsx(er,{className:"h-3.5 w-3.5"})})]}),h==="below"&&!I&&e.jsx("div",{className:"absolute right-2 bottom-[-1.5px] z-10 h-[3px] rounded-full bg-primary transition-all duration-150 ease-out",style:{left:`${re}px`,animation:"reorder-line-in 150ms ease-out"},children:e.jsx("div",{className:"absolute -left-[5px] -top-[3.5px] h-[10px] w-[10px] rounded-full bg-primary"})}),e.jsx("style",{children:`
43        @keyframes reorder-line-in {
44          from {
45            transform: scaleX(0);
46            transform-origin: left;
47            opacity: 0;
48          }
49          to {
50            transform: scaleX(1);
51            transform-origin: left;
52            opacity: 1;
53          }
54        }
55      `})]})}function is({open:t,onOpenChange:r,onCreateProject:a,mode:g="project"}){const{t:o}=bt(),[l,S]=s.useState(""),h=g==="folder",C=o(h?"fileSharing.createProject.createNewFolder":"fileSharing.createProject.createNewProject"),N=o(h?"fileSharing.createProject.folderName":"fileSharing.createProject.projectName"),f=o(h?"fileSharing.createProject.folderPlaceholder":"fileSharing.createProject.projectPlaceholder"),v=o(h?"fileSharing.createProject.createFolder":"fileSharing.createProject.createProject"),I=()=>{const x=l.trim();x&&(a(x),S(""),r(!1))};return e.jsx(vt,{open:t,onOpenChange:r,children:e.jsxs(yt,{className:"sm:max-w-md",children:[e.jsx(St,{children:e.jsx(wt,{children:C})}),e.jsxs("div",{className:"space-y-3 py-2",children:[e.jsx(We,{htmlFor:"project-name",children:N}
55),e.jsx(ht,{id:"project-name",placeholder:f,value:l,onChange:x=>S(x.target.value),onKeyDown:x=>x.key==="Enter"&&I(),autoFocus:!0})]}),e.jsxs(Lt,{children:[e.jsx(ae,{variant:"outline",onClick:()=>r(!1),children:o("fileSharing.createProject.cancel")}),e.jsx(ae,{onClick:I,disabled:!l.trim(),children:v})]})]})})}function Bl(t,r){return t.filter(a=>a.parentId===r)}function rr(t,r,a){const g=[],o=Bl(t,r);for(const l of o){g.push({node:l,depth:a});const S=t.some(h=>h.parentId===l.id);l.expanded&&S&&g.push(...rr(t,l.id,a+1))}return g}function Ol({nodes:t=[],selectedId:r,onSelect:a,onToggleExpand:g,onAddProject:o,onTogglePin:l,sidebarDropTarget:S,isDragActive:h,onToggleCollapse:C,onDeselectAll:N,onOpenImport:f}){const{t:v}=bt(),{user:I}=Et(),[x,d]=s.useState(!1),[E,T]=s.useState(!0),[A,H]=s.useState(null),[Q,re]=s.useState(null);s.useEffect(()=>{if(!I)return;let k=!1;return U.from("profiles").select("display_name, avatar_url").eq("id",I.id).single().then(({data:y})=>{k||!y||(re(y.display_name??null),H(y.avatar_url??null))}),()=>{k=!0}},[I]);const de=((I==null?void 0:I.email)??"").split("@")[0]||"User",oe=(Q==null?void 0:Q.trim())||de.charAt(0).toUpperCase()+de.slice(1),ee=oe.charAt(0).toUpperCase(),W=s.useMemo(()=>rr(t,null,0),[t]),w=s.useMemo(()=>{const k=t.filter(Ee=>Ee.pinned),y=k.filter(Ee=>Ee.parentId===null),L=k.filter(Ee=>Ee.parentId!==null);return[...y,...L]},[t]);return e.jsxs("aside",{className:"flex w-full h-full flex-col border-r border-border bg-sidebar",children:[e.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-3 border-b border-border",children:[e.jsxs(Jr,{className:"h-8 w-8",children:[A?e.jsx(Zr,{src:A,alt:oe}):null,e.jsx(Qr,{className:"bg-primary text-primary-foreground text-xs font-semibold",children:ee})]}),e.jsxs("div",{className:"min-w-0 leading-tight",children:[e.jsx("div",{className:"text-sm font-semibold truncate",children:oe}),e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground",children:"File Sharing"})]})]}),e.jsxs("div",{className:"flex items-center justify-between px-4 py-3",children:[e.jsx("button",{onClick:N,className:"text-sm font-semibold text-sidebar-foreground hover:text-primary transition-colors cursor-pointer",children:v("fileSharing.sidebar.yourProjects")}),e.jsxs("div",{className:"flex items-center gap-0.5",children:[e.jsx(ae,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>d(!0),children:e.jsx(bs,{className:"h-4 w-4"})}),C&&e.jsx(ae,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:C,title:v("fileSharing.sidebar.collapseSidebar"),children:e.jsx(Sl,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-2 pb-4",children:[w.length>0&&e.jsxs("div",{className:"mb-1",children:[e.jsxs("button",{className:"flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-xs font-medium text-muted-foreground hover:text-sidebar-foreground transition-colors",onClick:()=>T(k=>!k),children:[E?e.jsx(Ms,{className:"h-3 w-3"}):e.jsx(js,{className:"h-3 w-3"}),e.jsx(er,{className:"h-3 w-3"}),e.jsx("span",{children:v("fileSharing.sidebar.pinned")})]}),E&&e.jsxs("div",{className:"mt-0.5 space-y-0.5",children:[w.filter(k=>k.parentId===null).length>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"block text-[10px] uppercase tracking-wider text-muted-foreground px-2 pt-1",children:v("fileSharing.sidebar.projects")}),w.filter(k=>k.parentId===null).map(k=>e.jsxs("div",{className:Ve("group flex items-center gap-2 rounded-md px-2 py-1.5 text-sm cursor-pointer select-none transition-colors",k.id===r?"bg-accent text-accent-foreground":"text-sidebar-foreground hover:bg-accent/50"),onClick:()=>a(k.id),children:[e.jsx(Ht,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"truncate flex-1",children:k.name}),e.jsx("button",{className:"shrink-0 p-0.5 rounded hover:bg-muted text-primary opacity-60 hover:opacity-100 transition-opacity",onClick:y=>{y.stopPropagation(),l(k.id)},children:e.jsx(Ps,{className:"h-3 w-3"})})]},k.id))]}),w.filter(k=>k.parentId!==null).length>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"block text-[10px] uppercase tracking-wider text-muted-foreground px-2 pt-1",children:v("fileSharing.sidebar.folders")}),w.filter(k=>k.parentId!==null).map(k=>e.jsxs("div",{className:Ve("group flex items-center gap-2 rounded-md px-2 py-1.5 text-sm cursor-pointer select-none transition-colors",k.id===r?"bg-accent text-accent-foreground":"text-sidebar-foreground hover:bg-accent/50"),onClick:()=>a(k.id),children:[e.jsx(Ht,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"truncate flex-1",children:k.name}),e.jsx("button",{className:"shrink-0 p-0.5 rounded hover:bg-muted text-primary opacity-60 hover:opacity-100 transition-opacity",onClick:y=>{y.stopPropagation(),l(k.id)},children:e.jsx(Ps,{className:"h-3 w-3"})})]},k.id))]})]}),e.jsx("div",{className:"my-2 mx-2 border-t border-border"})]}),t.length===0?e.jsx("p",{className:"py-8 text-center text-xs text-muted-foreground",children:v("fileSharing.sidebar.noProjectsYet")}):W.map(({node:k,depth:y})=>e.jsx(Tl,{node:k,depth:y,isSelected:k.id===r,hasChildren:t.some(L=>L.parentId===k.id),onSelect:a,onToggleExpand:g,onTogglePin:l,dropIntent:(S==null?void 0:S.id)===k.id?S.intent:null,isDragActive:h},k.id)),e.jsx(Al,{isDragActive:h,isTarget:(S==null?void 0:S.id)==="sidebar-tail"})]}),e.jsx(is,{open:x,onOpenChange:d,onCreateProject:o})]})}function Al({isDragActive:t,isTarget:r}){const{setNodeRef:a,isOver:g}=Hs({id:"sidebar-tail",data:{type:"tree-item-tail"}});return t?e.jsx("div",{ref:a,className:"relative min-h-[40px] flex-1",children:(g||r)&&e.jsx("div",{className:"absolute top-0 right-2 h-[3px] rounded-full bg-primary",style:{left:"8px",animation:"reorder-line-in 150ms ease-out"},children:e.jsx("div",{className:"absolute -left-[5px] -top-[3.5px] h-[10px] w-[10px] rounded-full bg-primary"})})}):null}var Pl=Object.defineProperty,Ll=Object.defineProperties,Ml=Object.getOwnPropertyDescriptors,gs=Object.getOwnPropertySymbols,lr=Object.prototype.hasOwnProperty,nr=Object.prototype.propertyIsEnumerable,ja=(t,r,a)=>r in t?Pl(t,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[r]=a,Ul=(t,r)=>{for(var a in r||(r={}))lr.call(r,a)&&ja(t,a,r[a]);if(gs)for(var a of gs(r))nr.call(r,a)&&ja(t,a,r[a]);return t},ql=(t,r)=>Ll(t,Ml(r)),zl=(t,r)=>{var a={};for(var g in t)lr.call(t,g)&&r.indexOf(g)<0&&(a[g]=t[g]);if(t!=null&&gs)for(var g of gs(t))r.indexOf(g)<0&&nr.call(t,g)&&(a[g]=t[g]);return a};function $l(t){let r=setTimeout(t,0),a=setTimeout(t,10),g=setTimeout(t,50);return[r,a,g]}function Gl(t){let r=s.useRef();return s.useEffect(()=>{r.current=t}),r.current}var Hl=18,ir=40,Wl=`${ir}px`,Yl=["[data-lastpass-icon-root]","com-1password-button","[data-dashlanecreated]",'[style$="2147483647 !important;"]'].join(",");function Kl({containerRef:t,inputRef:r,pushPasswordManagerStrategy:a,isFocused:g}){let[o,l]=s.useState(!1),[S,h]=s.useState(!1),[C,N]=s.useState(!1),f=s.useMemo(()=>a==="none"?!1:(a==="increase-width"||a==="experimental-no-flickering")&&o&&S,[o,S,a]),v=s.useCallback(()=>{let I=t.current,x=r.current;if(!I||!x||C||a==="none")return;let d=I,E=d.getBoundingClientRect().left+d.offsetWidth,T=d.getBoundingClientRect().top+d.offsetHeight/2,A=E-Hl,H=T;document.querySelectorAll(Yl).length===0&&document.elementFromPoint(A,H)===I||(l(!0),N(!0))},[t,r,C,a]);return s.useEffect(()=>{let I=t.current;if(!I||a==="none")return;function x(){let E=window.innerWidth-I.getBoundingClientRect().right;h(E>=ir)}x();let d=setInterval(x,1e3);return()=>{clearInterval(d)}},[t,a]),s.useEffect(()=>{let I=g||document.activeElement===r.current;if(a==="none"||!I)return;let x=setTimeout(v,0),d=setTimeout(v,2e3),E=setTimeout(v,5e3),T=setTimeout(()=>{N(!0)},6e3);return()=>{clearTimeout(x),clearTimeout(d),clearTimeout(E),clearTimeout(T)}},[r,g,a,v]),{hasPWMBadge:o,willPushPWMBadge:f,PWM_BADGE_SPACE_WIDTH:Wl}}var or=s.createContext({}),cr=s.forwardRef((t,r)=>{var a=t,{value:g,onChange:o,maxLength:l,textAlign:S="left",pattern:h,placeholder:C,inputMode:N="numeric",onComplete:f,pushPasswordManagerStrategy:v="increase-width",pasteTransformer:I,c
55ontainerClassName:x,noScriptCSSFallback:d=Vl,render:E,children:T}=a,A=zl(a,["value","onChange","maxLength","textAlign","pattern","placeholder","inputMode","onComplete","pushPasswordManagerStrategy","pasteTransformer","containerClassName","noScriptCSSFallback","render","children"]),H,Q,re,le,de;let[oe,ee]=s.useState(typeof A.defaultValue=="string"?A.defaultValue:""),W=g??oe,w=Gl(W),k=s.useCallback(se=>{o==null||o(se),ee(se)},[o]),y=s.useMemo(()=>h?typeof h=="string"?new RegExp(h):h:null,[h]),L=s.useRef(null),Ee=s.useRef(null),Ye=s.useRef({value:W,onChange:k,isIOS:typeof window<"u"&&((Q=(H=window==null?void 0:window.CSS)==null?void 0:H.supports)==null?void 0:Q.call(H,"-webkit-touch-callout","none"))}),$e=s.useRef({prev:[(re=L.current)==null?void 0:re.selectionStart,(le=L.current)==null?void 0:le.selectionEnd,(de=L.current)==null?void 0:de.selectionDirection]});s.useImperativeHandle(r,()=>L.current,[]),s.useEffect(()=>{let se=L.current,J=Ee.current;if(!se||!J)return;Ye.current.value!==se.value&&Ye.current.onChange(se.value),$e.current.prev=[se.selectionStart,se.selectionEnd,se.selectionDirection];function he(){if(document.activeElement!==se){ue(null),Se(null);return}let pe=se.selectionStart,we=se.selectionEnd,ct=se.selectionDirection,Ue=se.maxLength,lt=se.value,Ne=$e.current.prev,Oe=-1,ce=-1,Xe;if(lt.length!==0&&pe!==null&&we!==null){let Ae=pe===we,qe=pe===lt.length&&lt.length<Ue;if(Ae&&!qe){let it=pe;if(it===0)Oe=0,ce=1,Xe="forward";else if(it===Ue)Oe=it-1,ce=it,Xe="backward";else if(Ue>1&&lt.length>1){let et=0;if(Ne[0]!==null&&Ne[1]!==null){Xe=it<Ne[1]?"backward":"forward";let _t=Ne[0]===Ne[1]&&Ne[0]<Ue;Xe==="backward"&&!_t&&(et=-1)}Oe=et+it,ce=et+it+1}}Oe!==-1&&ce!==-1&&Oe!==ce&&L.current.setSelectionRange(Oe,ce,Xe)}let Ge=Oe!==-1?Oe:pe,rt=ce!==-1?ce:we,Qe=Xe??ct;ue(Ge),Se(rt),$e.current.prev=[Ge,rt,Qe]}if(document.addEventListener("selectionchange",he,{capture:!0}),he(),document.activeElement===se&&Y(!0),!document.getElementById("input-otp-style")){let pe=document.createElement("style");if(pe.id="input-otp-style",document.head.appendChild(pe),pe.sheet){let we="background: transparent !important; color: transparent !important; border-color: transparent !important; opacity: 0 !important; box-shadow: none !important; -webkit-box-shadow: none !important; -webkit-text-fill-color: transparent !important;";Qt(pe.sheet,"[data-input-otp]::selection { background: transparent !important; color: transparent !important; }"),Qt(pe.sheet,`[data-input-otp]:autofill { ${we} }`),Qt(pe.sheet,`[data-input-otp]:-webkit-autofill { ${we} }`),Qt(pe.sheet,"@supports (-webkit-touch-callout: none) { [data-input-otp] { letter-spacing: -.6em !important; font-weight: 100 !important; font-stretch: ultra-condensed; font-optical-sizing: none !important; left: -1px !important; right: 1px !important; } }"),Qt(pe.sheet,"[data-input-otp] + * { pointer-events: all !important; }")}}let _e=()=>{J&&J.style.setProperty("--root-height",`${se.clientHeight}px`)};_e();let ve=new ResizeObserver(_e);return ve.observe(se),()=>{document.removeEventListener("selectionchange",he,{capture:!0}),ve.disconnect()}},[]);let[mt,Te]=s.useState(!1),[De,Y]=s.useState(!1),[z,ue]=s.useState(null),[Me,Se]=s.useState(null);s.useEffect(()=>{$l(()=>{var se,J,he,_e;(se=L.current)==null||se.dispatchEvent(new Event("input"));let ve=(J=L.current)==null?void 0:J.selectionStart,pe=(he=L.current)==null?void 0:he.selectionEnd,we=(_e=L.current)==null?void 0:_e.selectionDirection;ve!==null&&pe!==null&&(ue(ve),Se(pe),$e.current.prev=[ve,pe,we])})},[W,De]),s.useEffect(()=>{w!==void 0&&W!==w&&w.length<l&&W.length===l&&(f==null||f(W))},[l,f,w,W]);let X=Kl({containerRef:Ee,inputRef:L,pushPasswordManagerStrategy:v,isFocused:De}),xe=s.useCallback(se=>{let J=se.currentTarget.value.slice(0,l);if(J.length>0&&y&&!y.test(J)){se.preventDefault();return}typeof w=="string"&&J.length<w.length&&document.dispatchEvent(new Event("selectionchange")),k(J)},[l,k,w,y]),me=s.useCallback(()=>{var se;if(L.current){let J=Math.min(L.current.value.length,l-1),he=L.current.value.length;(se=L.current)==null||se.setSelectionRange(J,he),ue(J),Se(he)}Y(!0)},[l]),te=s.useCallback(se=>{var J,he;let _e=L.current;if(!I&&(!Ye.current.isIOS||!se.clipboardData||!_e))return;let ve=se.clipboardData.getData("text/plain"),pe=I?I(ve):ve;se.preventDefault();let we=(J=L.current)==null?void 0:J.selectionStart,ct=(he=L.current)==null?void 0:he.selectionEnd,Ue=(we!==ct?W.slice(0,we)+pe+W.slice(ct):W.slice(0,we)+pe+W.slice(we)).slice(0,l);if(Ue.length>0&&y&&!y.test(Ue))return;_e.value=Ue,k(Ue);let lt=Math.min(Ue.length,l-1),Ne=Ue.length;_e.setSelectionRange(lt,Ne),ue(lt),Se(Ne)},[l,k,y,W]),V=s.useMemo(()=>
55({position:"relative",cursor:A.disabled?"default":"text",userSelect:"none",WebkitUserSelect:"none",pointerEvents:"none"}),[A.disabled]),ie=s.useMemo(()=>({position:"absolute",inset:0,width:X.willPushPWMBadge?`calc(100% + ${X.PWM_BADGE_SPACE_WIDTH})`:"100%",clipPath:X.willPushPWMBadge?`inset(0 ${X.PWM_BADGE_SPACE_WIDTH} 0 0)`:void 0,height:"100%",display:"flex",textAlign:S,opacity:"1",color:"transparent",pointerEvents:"all",background:"transparent",caretColor:"transparent",border:"0 solid transparent",outline:"0 solid transparent",boxShadow:"none",lineHeight:"1",letterSpacing:"-.5em",fontSize:"var(--root-height)",fontFamily:"monospace",fontVariantNumeric:"tabular-nums"}),[X.PWM_BADGE_SPACE_WIDTH,X.willPushPWMBadge,S]),be=s.useMemo(()=>s.createElement("input",ql(Ul({autoComplete:A.autoComplete||"one-time-code"},A),{"data-input-otp":!0,"data-input-otp-placeholder-shown":W.length===0||void 0,"data-input-otp-mss":z,"data-input-otp-mse":Me,inputMode:N,pattern:y==null?void 0:y.source,"aria-placeholder":C,style:ie,maxLength:l,value:W,ref:L,onPaste:se=>{var J;te(se),(J=A.onPaste)==null||J.call(A,se)},onChange:xe,onMouseOver:se=>{var J;Te(!0),(J=A.onMouseOver)==null||J.call(A,se)},onMouseLeave:se=>{var J;Te(!1),(J=A.onMouseLeave)==null||J.call(A,se)},onFocus:se=>{var J;me(),(J=A.onFocus)==null||J.call(A,se)},onBlur:se=>{var J;Y(!1),(J=A.onBlur)==null||J.call(A,se)}})),[xe,me,te,N,ie,l,Me,z,A,y==null?void 0:y.source,W]),Be=s.useMemo(()=>({slots:Array.from({length:l}).map((se,J)=>{var he;let _e=De&&z!==null&&Me!==null&&(z===Me&&J===z||J>=z&&J<Me),ve=W[J]!==void 0?W[J]:null,pe=W[0]!==void 0?null:(he=C==null?void 0:C[J])!=null?he:null;return{char:ve,placeholderChar:pe,isActive:_e,hasFakeCaret:_e&&ve===null}}),isFocused:De,isHovering:!A.disabled&&mt}),[De,mt,l,Me,z,A.disabled,W]),gt=s.useMemo(()=>E?E(Be):s.createElement(or.Provider,{value:Be},T),[T,Be,E]);return s.createElement(s.Fragment,null,d!==null&&s.createElement("noscript",null,s.createElement("style",null,d)),s.createElement("div",{ref:Ee,"data-input-otp-container":!0,style:V,className:x},gt,s.createElement("div",{style:{position:"absolute",inset:0,pointerEvents:"none"}},be)))});cr.displayName="Input";function Qt(t,r){try{t.insertRule(r)}catch{console.error("input-otp could not insert CSS rule:",r)}}var Vl=`
56[data-input-otp] {
57  --nojs-bg: white !important;
58  --nojs-fg: black !important;
59
60  background-color: var(--nojs-bg) !important;
61  color: var(--nojs-fg) !important;
62  caret-color: var(--nojs-fg) !important;
63  letter-spacing: .25em !important;
64  text-align: center !important;
65  border: 1px solid var(--nojs-fg) !important;
66  border-radius: 4px !important;
67  width: 100% !important;
68}
69@media (prefers-color-scheme: dark) {
70  [data-input-otp] {
71    --nojs-bg: black !important;
72    --nojs-fg: white !important;
73  }
74}`;const dr=s.forwardRef(({className:t,containerClassName:r,...a},g)=>e.jsx(cr,{ref:g,containerClassName:Ve("flex items-center gap-2 has-[:disabled]:opacity-50",r),className:Ve("disabled:cursor-not-allowed",t),...a}));dr.displayName="InputOTP";const ur=s.forwardRef(({className:t,...r},a)=>e.jsx("div",{ref:a,className:Ve("flex items-center",t),...r}));ur.displayName="InputOTPGroup";const fr=s.forwardRef(({index:t,className:r,...a},g)=>{const o=s.useContext(or),{char:l,hasFakeCaret:S,isActive:h}=o.slots[t];return e.jsxs("div",{ref:g,className:Ve("relative flex h-10 w-10 items-center justify-center border-y border-r border-input text-sm transition-all first:rounded-l-md first:border-l last:rounded-r-md",h&&"z-10 ring-2 ring-ring ring-offset-background",r),...a,children:[l,S&&e.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:e.jsx("div",{className:"animate-caret-blink h-4 w-px bg-foreground duration-1000"})})]})});fr.displayName="InputOTPSlot";const Xl=s.forwardRef(({...t},r)=>e.jsx("div",{ref:r,role:"separator",...t,children:e.jsx(vl,{})}));Xl.displayName="InputOTPSeparator";const Jl=5,Zl=6e4,Ql=2500,en=20*6e4,tn=15*60*1e3,Rs=5;function rs(t){if(!t)return"0 B";const r=t/1024**3;if(r>=1)return`${r.toFixed(2)} GB`;const a=t/1024**2;return a>=1?`${a.toFixed(1)} MB`:`${(t/1024).toFixed(0)} KB`}function es(t,r){const a=t;return a!=null&&a.error?a.error:r?r.message??"Request failed":null}function sn(t){const r=(t??"").toLowerCase();return r==="loader_unauthorized"||r.includes("invalid api key")||r.includes("unauthorized")}function ts(t){const r=t.filter(a=>a.status==="failed");return r.length===0?null:r.every(a=>sn(a.error))?"Previous transfer failed because the loader rejected the key. Retry now to test the current deployed key.":r.some(a=>a.error==="signed_url_expired"||a.error==="code_expired")?"Some file links expired. Request a new PIKD code, then retry the failed files.":null}function an({open:t,onOpenChange:r,onImported:a}){const{user:g}=Et(),[o,l]=s.useState("email"),[S,h]=s.useState(""),[C,N]=s.useState(""),[f,v]=s.useState(!1),[I,x]=s.useState(null),[d,E]=s.useState(null),[T,A]=s.useState({total:0,done:0,failed:0}),[H,Q]=s.useState([]),[re,le]=s.useState(null),[de,oe]=s.useState(!1),ee=s.useRef(!1),W=s.useRef(!1),w=s.useCallback(Y=>{const z=[...Y.values()];A({total:z.length,done:z.filter(ue=>ue==="done"||ue==="skipped").length,failed:z.filter(ue=>ue==="failed").length})},[]),k=s.useCallback(async()=>{x(null),l("listing");const{data:Y,error:z}=await Zt("pikd-list-tree",{body:{},retryable:!0,timeoutMs:12e4}),ue=es(Y,z);if(ue||!(Y!=null&&Y.migrationId)){x(ue??"Could not read your PIKD library."),l("email");return}E(Y),l("summary")}
74,[]),y=s.useCallback(async()=>{x(null),v(!0);try{const{data:Y,error:z}=await Zt("pikd-request-code",{body:{email:S.trim()},retryable:!1}),ue=es(Y,z);if(ue){x(ue);return}l("code")}finally{v(!1)}},[S]),L=s.useCallback(async()=>{x(null),v(!0);try{const{data:Y,error:z}=await Zt("pikd-verify-code",{body:{email:S.trim(),code:C.trim()},retryable:!1});if(Y!=null&&Y.verified){await k();return}x(es(Y,z)??"Invalid or expired code.")}finally{v(!1)}},[S,C,k]),Ee=s.useCallback(async(Y,z,ue,Me)=>{const Se=Date.now();for(;!W.current&&Date.now()-Se<en&&[...z.values()].filter(te=>te==="importing").length!==0;){await new Promise(te=>setTimeout(te,Ql));const{data:xe}=await U.from("pikd_migration_items").select("id, name, status, bytes, sort_index, error").eq("migration_id",Y);for(const te of xe??[])z.set(te.id,te.status),Me.set(te.id,te.error??null),ue.set(te.id,{name:te.name??"",bytes:Number(te.bytes??0),sort:Number(te.sort_index??0)});w(z),le(ts([...z.entries()].map(([te,V])=>({status:V,error:Me.get(te)}))));const me=[...z.entries()].filter(([,te])=>te==="importing").map(([te])=>{const V=ue.get(te);return{id:te,name:(V==null?void 0:V.name)??"",bytes:(V==null?void 0:V.bytes)??0,sort:(V==null?void 0:V.sort)??0}}).sort((te,V)=>te.sort-V.sort).map(({id:te,name:V,bytes:ie})=>({id:te,name:V,bytes:ie}));Q(me)}Q([])},[w]),Ye=s.useCallback(async Y=>{l("importing"),le(null),ee.current=!0;const z=new Map(Y.items.map(V=>[V.id,V.status])),ue=new Map(Y.items.map(V=>[V.id,V.error??null])),Me=new Map(Y.items.map((V,ie)=>[V.id,{name:V.name,bytes:V.bytes,sort:ie}]));w(z),Q([]);const Se=Y.items.filter(V=>V.status==="pending"||V.status==="failed"||V.status==="importing");let X=!1;const xe=new Set,me=()=>{const V=[...xe].map(ie=>{const be=Me.get(ie);return{id:ie,name:(be==null?void 0:be.name)??"",bytes:(be==null?void 0:be.bytes)??0,sort:(be==null?void 0:be.sort)??0}}).sort((ie,be)=>ie.sort-be.sort).map(({id:ie,name:be,bytes:Be})=>({id:ie,name:be,bytes:Be}));Q(V)},te=Se.map(V=>async()=>{if(!(X||W.current)){xe.add(V.id),me();try{const{data:ie,error:be}=await Zt("pikd-migrate-file",{body:{item_id:V.id},retryable:!1,timeoutMs:Zl}),Be=es(ie,be);if(Be&&!(ie!=null&&ie.status))z.set(V.id,"failed"),ue.set(V.id,Be);else{const gt=(ie==null?void 0:ie.status)??"failed";z.set(V.id,gt),ue.set(V.id,(ie==null?void 0:ie.error)??(ie==null?void 0:ie.reason)??null),(ie==null?void 0:ie.reason)==="code_expired"&&(X=!0)}}catch(ie){z.set(V.id,"failed"),ue.set(V.id,ie instanceof Error?ie.message:String(ie))}finally{xe.delete(V.id),w(z),le(ts([...z.entries()].map(([ie,be])=>({status:be,error:ue.get(ie)})))),me()}}});if(await qa(te,Jl),Q([]),X){x("Your PIKD code expired. Request a new code to finish importing."),l("email");return}await Ee(Y.migrationId,z,Me,ue),w(z),le(ts([...z.entries()].map(([V,ie])=>({status:ie,error:ue.get(V)})))),l("done")},[w,Ee]),$e=s.useCallback(async()=>{d&&await Ye(d)},[d,Ye]),mt=s.useCallback(async()=>{v(!0),x(null),le(null),l("listing");try{const{data:Y,error:z}=await Zt("pikd-list-tree",{body:{},retryable:!0,timeoutMs:12e4}),ue=es(Y,z);if(ue||!(Y!=null&&Y.migrationId)){x(ue??"Could not read your PIKD library."),l("done");return}if(E(Y),Y.quota.needsUpgrade){l("summary");return}await Ye(Y)}finally{v(!1)}},[Ye]);s.useEffect(()=>{if(!t){W.current=!0;return}W.current=!1,x(null),le(null),N(""),h(z=>z||(g==null?void 0:g.email)||""),ee.current=!1;let Y=!1;return(async()=>{if(!g)return;const{data:z}=await U.from("pikd_migrations").select("pikd_email, verified_at, code_requested_at").eq("user_id",g.id).maybeSingle();if(Y)return;const ue=!!(z!=null&&z.code_requested_at)&&Date.now()-new Date(z.code_requested_at).getTime()<tn;if(z!=null&&z.verified_at&&ue){h(z.pikd_email),k();return}z!=null&&z.pikd_email&&h(z.pikd_email),l("email")})(),()=>{Y=!0}},[t,g,k]);const Te=Y=>{!Y&&ee.current&&a(),r(Y)},De=d==null?void 0:d.quota;return e.jsxs(e.Fragment,{children:[e.jsx(vt,{open:t,onOpenChange:Te,children:e.jsxs(yt,{className:"sm:max-w-lg",children:[e.jsxs(St,{children:[e.jsxs(wt,{className:"flex items-center gap-2",children:[e.jsx(Ir,{className:"h-5 w-5"})," Import from PIKD"]}),e.jsx(Pt,{children:"Move your files and folders from PIKD into vsble. Nothing is deleted from PIKD."})]}),o==="email"&&e.jsxs("div",{className:"space-y-3 py-2",children:[e.jsx(We,{htmlFor:"pikd-email",children:"Your PIKD email"}),e.jsx(ht,{id:"pikd-email",type:"email",placeholder:"[email protected]",value:S,onChange:Y=>h(Y.target.value),onKeyDown:Y=>Y.key==="Enter"&&S.trim()&&y(),autoFocus:!0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"We'll email you a verification code to confirm you own this PIKD account."}),I&&e.jsx("p",{className:"text-sm text-destructive",children:I})]}),o==="code"&&e.jsxs("div",{className:"space-y-3 py-2",children:[e.jsxs(We,{children:["Enter the code sent to ",S]}),e.jsx("div",{className:"flex justify-center py-2",children:e.jsx(dr,{maxLength:4,value:C,onChange:N,children:e.jsx(ur,{children:[0,1,2,3].map(Y=>e.jsx(fr,{index:Y},Y))})})}),e.jsx("button",{type:"button",className:"text-xs text-muted-foreground underline",onClick:()=>l("email"),children:"Use a different email / resend code"}),I&&e.jsx("p",{className:"text-sm text-destructive",children:I})]}),o==="listing"&&e.jsxs("div",{className:"flex items-center gap-3 py-8 justify-center text-muted-foreground",children:[e.jsx(Rt,{className:"h-5 w-5 animate-spin"})," Reading your PIKD library…"]}),o==="summary"&&d&&De&&e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"rounded-lg border border-border p-4 space-y-1 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Files to import"}),e.jsx("span",{className:"font-medium",children:d.counts.pending})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Already imported"}),e.jsx("span",{className:"font-medium",children:d.counts.done})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Folders"}),e.jsx("span",{className:"font-medium",children:d.folders.length})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Size to import"}),e.jsx("span",{className:"font-medium",children:rs(De.pendingBytes)})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Storage available"}),e.jsx("span",{className:"font-medium",children:rs(De.remainingBytes)})]})]}),De.needsUpgrade&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg bg-destructive/10 p-3 text-sm text-destructive",children:[e.jsx(Ns,{className:"h-4 w-4 mt-0.5 shrink-0"}),e.jsxs("span",{children:["This import needs ",rs(De.deficitBytes)," more storage than your plan allows. Upgrade to continue."]})]}),ts(d.items)&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg bg-destructive/10 p-3 text-sm text-destructive",children:[e.jsx(Ns,{className:"h-4 w-4 mt-0.5 shrink-0"}),e.jsx("span",{children:ts(d.items)})]}),I&&e.jsx("p",{className:"text-sm text-destructive",children:I})]}),(o==="importing"||o==="done")&&e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[o==="importing"?e.jsx(Rt,{className:"h-5 w-5 animate-spin text-primary"}):e.jsx(tl,{className:"h-5 w-5 text-primary"}),e.jsx("div",{className:"text-sm",children:o==="importing"?"Importing your files…"
74:"Import complete"})]}),e.jsx("div",{className:"h-2 w-full overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full bg-primary transition-all",style:{width:T.total?`${Math.round(T.done/T.total*100)}%`:"0%"}})}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsxs("span",{children:[T.done," / ",T.total," files"]}),T.failed>0&&e.jsxs("span",{className:"text-destructive",children:[T.failed," failed"]})]}),re&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg bg-destructive/10 p-3 text-sm text-destructive",children:[e.jsx(Ns,{className:"h-4 w-4 mt-0.5 shrink-0"}),e.jsx("span",{children:re})]}),o==="importing"&&H.length>0&&e.jsxs("div",{className:"rounded-lg border border-border bg-muted/30 p-3 space-y-2",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Transferring now"}),e.jsx("ul",{className:"space-y-1.5",children:H.slice(0,Rs).map(Y=>e.jsxs("li",{className:"flex items-center gap-2 text-xs min-w-0",children:[e.jsx(Rt,{className:"h-3 w-3 shrink-0 animate-spin text-primary"}),e.jsx("span",{className:"truncate flex-1 min-w-0",title:Y.name,children:Y.name}),e.jsx("span",{className:"text-muted-foreground shrink-0 tabular-nums",children:rs(Y.bytes)})]},Y.id))}),H.length>Rs&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["+",H.length-Rs," more"]})]})]}),e.jsxs(Lt,{children:[o==="email"&&e.jsxs(ae,{onClick:y,disabled:f||!S.trim(),children:[f&&e.jsx(Rt,{className:"h-4 w-4 animate-spin"})," Send code"]}),o==="code"&&e.jsxs(ae,{onClick:L,disabled:f||C.trim().length<4,children:[f&&e.jsx(Rt,{className:"h-4 w-4 animate-spin"})," Verify"]}),o==="summary"&&d&&De&&e.jsx(e.Fragment,{children:De.needsUpgrade?e.jsx(ae,{onClick:()=>oe(!0),children:"Upgrade storage"}):e.jsx(ae,{onClick:$e,disabled:d.counts.pending===0,children:"Start import"})}),o==="done"&&e.jsxs(e.Fragment,{children:[T.failed>0&&e.jsxs(ae,{variant:"outline",onClick:mt,disabled:f,children:[f&&e.jsx(Rt,{className:"h-4 w-4 animate-spin"})," Retry failed"]}),e.jsx(ae,{onClick:()=>Te(!1),children:"Done"})]})]})]})}),De&&e.jsx(sr,{open:de,onOpenChange:oe,usedBytes:De.usedBytes,totalBytes:De.totalBytes,onSuccess:()=>{oe(!1),k()}})]})}function rn(t){const r=t.includes(".")?t.slice(t.lastIndexOf(".")):"";return{base:t.includes(".")?t.slice(0,t.lastIndexOf(".")):t,ext:r}}function ba(t,r,{baseName:a,prefix:g,suffix:o,findText:l,replaceText:S,addNumbering:h,startNumber:C}){const{base:N,ext:f}=rn(t.name);let v;return a?v=a:(v=N,l&&(v=v.split(l).join(S)),g&&(v=g+v),o&&(v=v+o)),h&&(v=v+"_"+String(C+r).padStart(3,"0")),v+f}function va(t,r){if(t.length<=r)return t;const a=Math.floor((r-1)/2);return t.slice(0,a)+"…"+t.slice(t.length-a)}function ln({open:t,onOpenChange:r,files:a,onRenamed:g}){const{t:o}=bt(),[l,S]=s.useState(""),[h,C]=s.useState(""),[N,f]=s.useState(""),[v,I]=s.useState(""),[x,d]=s.useState(""),[E,T]=s.useState(!1),[A,H]=s.useState(1),[Q,re]=s.useState(!1),le={baseName:l,prefix:h,suffix:N,findText:v,replaceText:x,addNumbering:E,startNumber:A},de=s.useMemo(()=>a.slice(0,5).map((w,k)=>({original:w.name,renamed:ba(w,k,le)})),[a,l,h,N,v,x,E,A]),oe=!!(l||h||N||v||E),ee=!!l,W=async()=>{if(oe){re(!0);try{const w=a.map((k,y)=>({id:k.id,newName:ba(k,y,le)}));await Promise.all(w.map(k=>U.from("fs_files").update({name:k.newName}).eq("id",k.id))),g(w),G.success(o("fileSharing.bulkRename.renamedSuccess",{count:w.length})),r(!1)}catch{G.error(o("fileSharing.bulkRename.failedRename"))}finally{re(!1)}}};return e.jsx(vt,{open:t,onOpenChange:r,children:e.jsxs(yt,{className:"sm:max-w-lg bg-[hsl(0,0%,10%)] border-[hsl(0,0%,20%)] text-[hsl(0,0%,95%)]",children:[e.jsx(St,{children:e.jsxs(wt,{children:[o("fileSharing.bulkRename.title")," · ",o("fileSharing.bulkRename.filesCount",{count:a.length})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(We,{className:"text-xs text-[hsl(0,0%,60%)]",children:o("fileSharing.bulkRename.renameTo")}),e.jsx(ht,{value:l,onChange:w=>S(w.target.value),placeholder:o("fileSharing.bulkRename.renamePlaceholder"),className:"h-8 bg-[hsl(0,0%,14%)] border-[hsl(0,0%,25%)] text-[hsl(0,0%,90%)] text-sm"}),e.jsx("p",{className:"text-[10px] text-[hsl(0,0%,40%)]",children:o("fileSharing.bulkRename.leaveEmpty")})]}),e.jsxs("div",{className:`grid grid-cols-2 gap-3 transition-opacity ${ee?"opacity-35 pointer-events-none":""}`,children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(We,{className:"text-xs text-[hsl(0,0%,60%)]",children:o("fileSharing.bulkRename.addPrefix")}),e.jsx(ht,{value:h,onChange:w=>C(w.target.value),placeholder:o("fileSharing.bulkRename.prefixPlaceholder"),disabled:ee,className:"h-8 bg-[hsl(0,0%,14%)] border-[hsl(0,0%,25%)] text-[hsl(0,0%,90%)] text-sm"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(We,{className:"text-xs text-[hsl(0,0%,60%)]",children:o("fileSharing.bulkRename.addSuffix")}),e.jsx(ht,{value:N,onChange:w=>f(w.target.value),placeholder:o("fileSharing.bulkRename.suffixPlaceholder"),disabled:ee,className:"h-8 bg-[hsl(0,0%,14%)] border-[hsl(0,0%,25%)] text-[hsl(0,0%,90%)] text-sm"})]})]}),e.jsxs("div",{className:`grid grid-cols-2 gap-3 transition-opacity ${ee?"opacity-35 pointer-events-none":""}`,children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(We,{className:"text-xs text-[hsl(0,0%,60%)]",children:o("fileSharing.bulkRename.findText")}
74),e.jsx(ht,{value:v,onChange:w=>I(w.target.value),placeholder:o("fileSharing.bulkRename.findPlaceholder"),disabled:ee,className:"h-8 bg-[hsl(0,0%,14%)] border-[hsl(0,0%,25%)] text-[hsl(0,0%,90%)] text-sm"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(We,{className:"text-xs text-[hsl(0,0%,60%)]",children:o("fileSharing.bulkRename.replaceWith")}),e.jsx(ht,{value:x,onChange:w=>d(w.target.value),placeholder:o("fileSharing.bulkRename.replacePlaceholder"),disabled:ee,className:"h-8 bg-[hsl(0,0%,14%)] border-[hsl(0,0%,25%)] text-[hsl(0,0%,90%)] text-sm"})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:E,onChange:w=>T(w.target.checked),className:"rounded border-[hsl(0,0%,25%)]"}),o("fileSharing.bulkRename.addNumbering")]}),E&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-[hsl(0,0%,60%)]",children:o("fileSharing.bulkRename.startAt")}),e.jsx(ht,{type:"number",value:A,onChange:w=>H(parseInt(w.target.value)||1),className:"h-7 w-20 bg-[hsl(0,0%,14%)] border-[hsl(0,0%,25%)] text-[hsl(0,0%,90%)] text-sm"})]})]}),oe&&e.jsxs("div",{className:"rounded-md bg-[hsl(0,0%,6%)] border border-[hsl(0,0%,20%)] p-3 space-y-1.5",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-[hsl(0,0%,45%)] mb-2",children:o("fileSharing.bulkRename.preview")}),de.map((w,k)=>e.jsxs("div",{className:"flex items-center gap-2 text-xs min-w-0",children:[e.jsx("span",{className:"text-[hsl(0,0%,45%)] truncate flex-1 min-w-0",title:w.original,children:va(w.original,28)}),e.jsx("span",{className:"text-[hsl(0,0%,35%)] shrink-0",children:"→"}),e.jsx("span",{className:"text-[hsl(0,0%,85%)] truncate flex-1 min-w-0 font-medium",title:w.renamed,children:va(w.renamed,28)})]},k)),a.length>5&&e.jsx("p",{className:"text-[10px] text-[hsl(0,0%,40%)]",children:o("fileSharing.bulkRename.andMore",{count:a.length-5})})]})]}),e.jsxs(Lt,{children:[e.jsx(ae,{variant:"ghost",onClick:()=>r(!1),className:"text-[hsl(0,0%,60%)]",children:o("fileSharing.bulkRename.cancel")}),e.jsx(ae,{onClick:W,disabled:!oe||Q,children:o(Q?"fileSharing.bulkRename.renaming":"fileSharing.bulkRename.renameFiles")})]})]})})}function Es({imageUrl:t,focusX:r,focusY:a,onFocusChange:g}){const{t:o}=bt(),l=s.useRef(null),S=s.useCallback(N=>{var x;const f=(x=l.current)==null?void 0:x.getBoundingClientRect();if(!f)return;const v=Math.max(0,Math.min(100,(N.clientX-f.left)/f.width*100)),I=Math.max(0,Math.min(100,(N.clientY-f.top)/f.height*100));g(Math.round(v),Math.round(I))},[g]),h=s.useCallback(N=>{N.target.setPointerCapture(N.pointerId),S(N)},[S]),C=s.useCallback(N=>{N.buttons===1&&S(N)},[S]);return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:o("fileSharing.bannerCover.clickOrDrag")}),e.jsxs("span",{className:"text-[10px] text-muted-foreground font-mono",children:[r,"%, ",a,"%"]})]}),e.jsxs("div",{ref:l,className:"relative rounded-md overflow-hidden border border-border cursor-crosshair select-none bg-muted max-h-[250px] w-fit",style:{touchAction:"none"},onPointerDown:h,onPointerMove:C,children:[e.jsx("img",{src:t,alt:"Focus selector",className:"max-h-[250px] w-auto block pointer-events-none",draggable:!1}),e.jsx("div",{className:"absolute pointer-events-none",style:{left:`${r}%`,top:`${a}%`,transform:"translate(-50%, -50%)"},children:e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute -top-3 left-1/2 -translate-x-1/2 w-px h-6 bg-[hsl(0,0%,100%)]/80"}),e.jsx("div",{className:"absolute top-1/2 -left-3 -translate-y-1/2 h-px w-6 bg-[hsl(0,0%,100%)]/80"}),e.jsx("div",{className:"w-3 h-3 rounded-full border-2 border-[hsl(0,0%,100%)] shadow-[0_0_4px_rgba(0,0,0,0.5)]"})]})}),e.jsx("div",{className:"absolute inset-0 bg-[hsl(0,0%,0%)]/10 pointer-events-none"})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("div",{className:"flex-1 flex flex-col gap-1",children:[e.jsx("span",{className:"text-[10px] text-muted-foreground font-medium",children:o("fileSharing.bannerCover.bannerPreview")}),e.jsx("div",{className:"w-full rounded-md overflow-hidden border border-border bg-muted",style:{aspectRatio:"16/5"},children:e.jsx("img",{src:t,alt:"Banner preview",className:"h-full w-full object-cover",style:{objectPosition:`${r}% ${a}%`}})})]}),e.jsxs("div",{className:"w-[120px] shrink-0 flex flex-col gap-1",children:[e.jsx("span",{className:"text-[10px] text-muted-foreground font-medium",children:o("fileSharing.bannerCover.cardPreview")}),e.jsx("div",{className:"w-full rounded-md overflow-hidden border border-border bg-muted",style:{aspectRatio:"140/90"},children:e.jsx("img",{src:t,alt:"Card preview",className:"h-full w-full object-cover",style:{objectPosition:`${r}% ${a}%`}})})]})]})]})}function nn({open:t,onOpenChange:r,currentCoverUrl:a,currentFocusX:g=50,currentFocusY:o=50,folderFiles:l,onSave:S}){const{t:h}=bt(),[C,N]=s.useState(a?"focus":"select"),[f,v]=s.useState(null),[I,x]=s.useState(g),[d,E]=s.useState(o),[T,A]=s.useState(null),H=s.useRef(null),Q=C==="custom"&&T?T:C==="select"&&f?f:
74a||null,re=l.filter($t),le=s.useCallback((w,k)=>{x(w),E(k)},[]),de=s.useCallback(w=>{const k=ds(w);k&&(v(k),x(50),E(50),N("select"))},[]),oe=s.useCallback(w=>{var L;const k=(L=w.target.files)==null?void 0:L[0];if(!k)return;const y=URL.createObjectURL(k);A(y),x(50),E(50)},[]),ee=s.useCallback(()=>{Q&&(S(Q,I,d),r(!1))},[Q,I,d,S,r]),W=s.useCallback(w=>{w&&(v(null),A(null),x(g),E(o),N(a?"focus":"select")),r(w)},[r,a,g,o]);return e.jsx(vt,{open:t,onOpenChange:W,children:e.jsxs(yt,{className:"sm:max-w-2xl",children:[e.jsx(St,{children:e.jsx(wt,{children:h("fileSharing.bannerCover.setCoverImage")})}),e.jsxs(cl,{value:C,onValueChange:N,children:[e.jsxs(dl,{className:"w-full",children:[a&&e.jsx(_s,{value:"focus",children:h("fileSharing.bannerCover.focusPoint")}),e.jsx(_s,{value:"select",children:h("fileSharing.bannerCover.selectFromFolder")}),e.jsx(_s,{value:"custom",children:h("fileSharing.bannerCover.customImage")})]}),a&&e.jsx(Cs,{value:"focus",children:e.jsx(Es,{imageUrl:a,focusX:I,focusY:d,onFocusChange:le})}),e.jsx(Cs,{value:"select",children:re.length===0?e.jsx("div",{className:"py-8 text-center text-sm text-muted-foreground",children:h("fileSharing.bannerCover.noImagesInFolder")}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"grid gap-2 max-h-[200px] overflow-y-auto",style:{gridTemplateColumns:"repeat(auto-fill, minmax(80px, 1fr))"},children:re.map(w=>{const k=Gt(w,"small"),y=f===ds(w);return e.jsx("button",{onClick:()=>de(w),className:`aspect-square rounded-md overflow-hidden border-2 transition-all ${y?"border-primary ring-1 ring-primary":"border-border hover:border-primary/50"}`,children:e.jsx("img",{src:k,alt:w.name,className:"h-full w-full object-cover",draggable:!1})},w.id)})}),f&&e.jsx(Es,{imageUrl:f,focusX:I,focusY:d,onFocusChange:le})]})}),e.jsx(Cs,{value:"custom",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("input",{ref:H,type:"file",accept:"image/*",className:"hidden",onChange:oe}),e.jsxs(ae,{variant:"outline",className:"w-full gap-2",onClick:()=>{var w;return(w=H.current)==null?void 0:w.click()},children:[e.jsx(ms,{className:"h-4 w-4"}),h("fileSharing.bannerCover.uploadCustomImage")]}),T&&e.jsx(Es,{imageUrl:T,focusX:I,focusY:d,onFocusChange:le})]})})]}),e.jsxs(Lt,{children:[e.jsx(ae,{variant:"outline",onClick:()=>r(!1),children:h("fileSharing.bannerCover.cancel")}),e.jsx(ae,{onClick:ee,disabled:!Q,children:h("fileSharing.bannerCover.saveCover")})]})]})})}function hr({open:t,onOpenChange:r,shareUrl:a,senderName:g,galleryName:o,password:l}){const[S,h]=s.useState(""),[C,N]=s.useState(""),[f,v]=s.useState(!1),I=vs(),x=async()=>{if(S.trim()){v(!0);try{const{error:d}=await U.functions.invoke("send-share-link-email",{body:{recipientEmail:S.trim(),shareUrl:a,senderName:g||void 0,message:C.trim()||void 0,galleryName:o||void 0,password:l||void 0}});if(d)throw d;I("fs_share_link_emailed",{has_message:!!C.trim(),has_password:!!l}),G.success("Email sent successfully"),h(""),N(""),r(!1)}catch(d){console.error("Failed to send email:",d),G.error("Failed to send email")}finally{v(!1)}}};return e.jsx(vt,{open:t,onOpenChange:r,children:e.jsxs(yt,{className:"sm:max-w-md",children:[e.jsx(St,{children:e.jsx(wt,{children:"Send link via email"})}),e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(We,{htmlFor:"recipient-email",children:"Recipient email"}),e.jsx(ht,{id:"recipient-email",type:"email",placeholder:"[email protected]",value:S,onChange:d=>h(d.target.value),onKeyDown:d=>d.key==="Enter"&&x()})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(We,{htmlFor:"share-message",children:"Message (optional)"}),e.jsx(Da,{id:"share-message",placeholder:"Add a personal message...",value:C,onChange:d=>N(d.target.value),rows:3})]})]}),e.jsx(Lt,{children:e.jsxs(ae,{onClick:x,disabled:!S.trim()||f,children:[e.jsx(jr,{className:"h-4 w-4 mr-2"}),f?"Sending…":"Send"]})})]})})}const xs="https://getvsble.com";function on(t){if(!t)return xs;const r=t.trim();return r?r.startsWith("http")?r:`https://${r}`:xs}async function ya(){const{data:{user:t}}=await U.auth.getUser();if(!t)return xs;const{data:r}=await U.from("fs_user_settings").select("custom_domain_mode, custom_domain").eq("user_id",t.id).maybeSingle();return!r||r.custom_domain_mode==="default"||!r.custom_domain?xs:on(r.custom_domain)}function Sa(t){switch(t){case"reserved":return"This URL is reserved — please choose another one";case"too_short":return"Minimum 3 characters required";case"error":return"Could not verify this URL right now — please try again";default:return"This URL is already taken"}}function cn({open:t,onOpenChange:r,currentSlug:a,onSave:g,currentLinkId:o,shareBaseUrl:l="https://getvsble.com"}){const[S,h]=s.useState(a),[C,N]=s.useState(!1),[f,v]=s.useState(!1),[I,x]=s.useState(null),[d,E]=s.useState(null),[T,A]=s.useState(!1),H=s.useRef(null),Q=s.useRef(0);s.useEffect(()=>
74{t&&(h(a),v(!1),x(null),E(null),H.current=a)},[t,a]),s.useEffect(()=>{if(!S||S.length<3||S===a){v(!1),x(null),E(null),N(!1);return}const ee=++Q.current;N(!0);const W=setTimeout(async()=>{const w=await la(U,S,{kind:"gallery",currentId:o});ee===Q.current&&(H.current=S,v(!w.available),x(w.available?null:w.reason),E(w.available?null:os(na(S))),N(!1))},400);return()=>clearTimeout(W)},[S,a,o]);const re=S.length>=3,de=re&&S!==a&&!f&&!C&&!T,oe=`${l}/share/${S}`;return e.jsx(vt,{open:t,onOpenChange:ee=>{T||r(ee)},children:e.jsxs(yt,{className:"w-[95vw] sm:max-w-md p-6 overflow-hidden",children:[e.jsxs(St,{children:[e.jsx(wt,{children:"Edit Custom URL"}),e.jsx(Pt,{children:"Customize the URL for your shared folder. Use only letters, numbers, and hyphens."})]}),e.jsxs("div",{className:"space-y-4 pt-2 min-w-0",children:[e.jsxs("div",{className:"space-y-2 min-w-0",children:[e.jsx(We,{children:"Custom URL"}),e.jsxs("div",{className:"flex items-stretch gap-0 rounded-md border border-border overflow-hidden w-full min-w-0",children:[e.jsx("span",{className:"bg-muted px-3 py-2 text-sm text-muted-foreground whitespace-nowrap border-r border-border shrink-0",children:"…/share/"}),e.jsx(ht,{value:S,onChange:ee=>h(na(ee.target.value)),className:"border-0 focus-visible:ring-0 rounded-none flex-1 min-w-0 
74w-full",placeholder:"my-folder"})]}),S.length>0&&!re&&e.jsx("p",{className:"text-xs text-destructive",children:"Minimum 3 characters required"}),f&&!C&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-destructive",children:Sa(I)}),I!=="error"&&d&&e.jsxs("button",{type:"button",className:"text-xs text-primary underline underline-offset-2",onClick:()=>h(d),children:["Use “",d,"” instead"]})]}),C&&e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[e.jsx(Rt,{className:"h-3 w-3 animate-spin"})," Checking availability…"]})]}),e.jsxs("div",{className:"rounded-md bg-muted/50 p-3 min-w-0 overflow-hidden",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Preview"}),e.jsx("p",{className:"text-sm font-medium text-foreground truncate whitespace-nowrap w-full cursor-help",title:oe,children:oe})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(ae,{variant:"outline",disabled:T,onClick:()=>r(!1),children:"Cancel"}),e.jsx(ae,{disabled:!de,className:"bg-green-600 hover:bg-green-700 text-white",onClick:async()=>{A(!0);try{const ee=await la(U,S,{kind:"gallery",currentId:o});if(!ee.available){v(!0),x(ee.reason),G.error(Sa(ee.reason));return}await g(ee.slug),r(!1)}finally{A(!1)}},children:T?e.jsxs(e.Fragment,{children:[e.jsx(Rt,{className:"h-3 w-3 animate-spin mr-1"})," Saving…"]}):"Save"})]})]})]})})}const dn=[{value:"BLACK",label:"Black"},{value:"WHITE",label:"White"},{value:"COLORED",label:"Colored"}],un=Object.entries(Ya);function wa(t,r){var a,g,o;return((a=t.CIRCLE)==null?void 0:a[r])??((g=t.ICON)==null?void 0:g[r])??((o=t.CIRCLE)==null?void 0:o.BLACK)??null}function fn({socialStyle:t,onSocialStyleChange:r,socialLinks:a,onSocialLinksChange:g,customLinks:o,onCustomLinksChange:l}){const S=new Set(a.map(x=>x.platform)),h=x=>{S.has(x)?g(a.filter(d=>d.platform!==x)):g([...a,{platform:x,url:""}])},C=(x,d)=>{g(a.map(E=>E.platform===x?{...E,url:d}:E))},N=()=>{l([...o,{title:"",url:""}])},f=(x,d,E)=>{const T=o.map((A,H)=>H===x?{...A,[d]:E}:A);l(T)},v=x=>{l(o.filter((d,E)=>E!==x))},I=t==="WHITE";return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-foreground",children:"Social Links"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Add social media icons to the shared gallery footer."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(We,{className:"text-xs",children:"Icon Style"}),e.jsx("div",{className:"flex rounded-lg border border-border overflow-hidden",children:dn.map(x=>e.jsx("button",{type:"button",onClick:()=>r(x.value),className:Ve("flex-1 px-3 py-1.5 text-xs font-medium transition-colors",t===x.value?"bg-accent text-accent-foreground":"bg-background text-muted-foreground hover:bg-muted/50"),children:x.label},x.value))})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(We,{className:"text-xs",children:"Choose Platforms"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:un.map(([x,{name:d,icon:E}])=>{const T=S.has(x),A=wa(E,t);return A?e.jsx("button",{type:"button",onClick:()=>h(x),className:Ve("flex items-center justify-center w-7 h-7 cursor-pointer transition-opacity rounded",T?"opacity-40 ring-2 ring-primary/30":"opacity-100 hover:opacity-60",I&&"[&>svg]:drop-shadow-[0_0_7px_rgba(0,0,0,0.25)]"),title:d,children:e.jsx(A,{style:{width:26,height:26}})},x):null})})]}),a.length>0&&e.jsx("div",{className:"space-y-1.5",children:a.map(x=>{const d=Ya[x.platform],E=d?wa(d.icon,t):null,T=(d==null?void 0:d.placeholder)||`https://${x.platform}.com/`;return e.jsxs("div",{className:"flex items-center gap-1.5",children:[E&&e.jsx("span",{className:"shrink-0",children:e.jsx(E,{style:{width:20,height:20}})}),e.jsx(ht,{className:"h-7 flex-1 text-[11px]",value:x.url,placeholder:T,onChange:A=>C(x.platform,A.target.value)}),e.jsx("button",{type:"button",onClick:()=>h(x.platform),className:"shrink-0 rounded p-0.5 text-muted-foreground hover:text-destructive hover:bg-destructive/10 transition-colors",title:`Remove ${(d==null?void 0:d.name)||x.platform}`,children:e.jsx(Ts,{className:"h-3.5 w-3.5"})})]},x.platform)})})]}),e.jsx("div",{className:"border-t border-border"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-foreground",children:"Custom Links"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Add text links to the footer (e.g. Portfolio, Contact)."})]}),o.length>0&&e.jsx("div",{className:"space-y-2",children:o.map((x,d)=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(ys,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}),e.jsx(ht,{className:"h-7 w-[120px] text-[11px]",value:x.title,placeholder:"Title",onCh
74ange:E=>f(d,"title",E.target.value)}),e.jsx(ht,{className:"h-7 flex-1 text-[11px]",value:x.url,placeholder:"https://...",onChange:E=>f(d,"url",E.target.value)}),e.jsx("button",{type:"button",onClick:()=>v(d),className:"shrink-0 rounded p-0.5 text-muted-foreground hover:text-destructive hover:bg-destructive/10 transition-colors",children:e.jsx(Ts,{className:"h-3.5 w-3.5"})})]},d))}),e.jsxs(ae,{variant:"outline",size:"sm",className:"h-7 text-xs gap-1",onClick:N,children:[e.jsx(bs,{className:"h-3.5 w-3.5"}),"Add Link"]})]})]})}const Na=1,ka=4,hn=12,mn=1*1024**3,gn=500*1024**2;function ws(){var le;const{user:t,subscription:r,isAdmin:a}=Et(),[g,o]=s.useState(0),[l,S]=s.useState(0),[h,C]=s.useState(0),[N,f]=s.useState(!0),v=r.standaloneFileSharing,I=!r.subscribed&&!!v,x=I&&(v==null?void 0:v.status)==="trialing"&&!a,d=!!((le=r.universalTrial)!=null&&le.active)&&!r.subscribed&&!a,E=x||d,T=d?gn:mn,A=s.useCallback(async()=>{if(!t){f(!1);return}f(!0);try{const oe=((await U.from("fs_projects").select("id").eq("user_id",t.id)).data??[]).map(w=>w.id);if(o(oe.length),oe.length===0){S(0),C(0);return}const[ee,W]=await Promise.all([U.from("fs_folders").select("id",{count:"exact",head:!0}).in("project_id",oe),U.rpc("get_fs_user_storage_bytes")]);S(ee.count??0),C(Number(W.data??0))}catch(de){console.error("[useFsTrialLimits] count fetch failed",de)}finally{f(!1)}},[t]);s.useEffect(()=>{E?A():f(!1)},[E,A]);const H=!E||g<Na,Q=!x||l<ka,re=s.useCallback(de=>!E||h+de<=T,[E,h,T]);return{isTrialing:E,isStandaloneFs:I,isShareCapped:x||d,maxProjects:Na,maxFolders:ka,maxShareDurationHours:hn,maxBytes:T,projectCount:g,folderCount:l,bytesUsed:h,canCreateProject:H,canCreateFolder:Q,canUpload:re,loading:N,refresh:A}}const xn={project_limit:{title:"One project without a plan",body:"The free demo allows a single project. Pick File Sharing as a standalone tool, or All-in-One, to create unlimited projects."},folder_limit:{title:"Folder limit reached on trial",body:"Your 7-day trial allows up to 4 folders in total. Activate your paid plan now to create as many folders as you need."},share_duration:{title:"Longer share durations are a paid feature",body:"Without a plan, share links expire after 12 hours. Pick a plan to unlock 7-day, 30-day, and never-expiring share links."},generic:{title:"Activate your paid plan",body:"You're currently on a 7-day trial. Activate your paid plan to remove all trial limits and unlock the full tier you selected."}};function ta({open:t,onOpenChange:r,reason:a="generic"}){const{refreshSubscription:g}=Et(),[o,l]=s.useState(!1),S=xn[a],h=async()=>{l(!0);try{const{data:C,error:N}=await U.functions.invoke("end-fs-trial");if(N)throw N;if(C!=null&&C.error)throw new Error(C.error);G.success("Plan activated. Welcome aboard!"),await g(),r(!1)}catch(C){console.error("[ActivateTrialPlanModal] activate failed",C),G.error((C==null?void 0:C.message)||"Failed to activate plan")}finally{l(!1)}};return e.jsx(vt,{open:t,onOpenChange:r,children:e.jsxs(yt,{className:"max-w-md",children:[e.jsxs(St,{children:[e.jsx("div",{className:"mx-auto mb-3 flex h-12 w-12 items-center justify-center rounded-full bg-primary/10",children:e.jsx(Dt,{className:"h-6 w-6 text-primary"})}),e.jsx(wt,{className:"text-center",children:S.title}),e.jsx(Pt,{className:"text-center pt-1",children:S.body})]}),e.jsxs(Lt,{className:"flex flex-col-reverse sm:flex-col-reverse gap-2 mt-2",children:[e.jsx(ae,{variant:"ghost",onClick:()=>r(!1),disabled:o,className:"w-full",children:"Stay in trial"}),e.jsx(ae,{onClick:h,disabled:o,className:"w-full",children:o?e.jsxs(e.Fragment,{children:[e.jsx(Rt,{className:"h-4 w-4 mr-2 animate-spin"}),"Activating…"]}):e.jsxs(e.Fragment,{children:[e.jsx(Dt,{className:"h-4 w-4 mr-2"}),"Activate plan now"]})})]})]})})}function mr({open:t,onOpenChange:r,onSkip:a}){const g=Ra(),o=()=>{r(!1),g("/dashboard/billing")},l=()=>{r(!1),a==null||a()};return e.jsx(vt,{open:t,onOpenChange:r,children:e.jsxs(yt,{className:"max-w-md",children:[e.jsxs(St,{children:[e.jsx("div",{className:"mx-auto mb-3 flex h-12 w-12 items-center justify-center rounded-full bg-primary/10",children:e.jsx(Ss,{className:"h-6 w-6 text-primary"})}),e.jsx(wt,{className:"text-center",children:"Demo share links expire after 12 hours"}),e.jsx(Pt,{className:"text-center pt-1",children:"Without a plan, share links expire after 12 hours and carry a demo badge. Pick a plan for links that never expire."})]}),e.jsxs(Lt,{className:"flex flex-col gap-2 mt-2 sm:flex-col",children:[e.jsxs(ae,{onClick:o,className:"w-full",children:[e.jsx(Dt,{className:"h-4 w-4 mr-2"}),"Upgrade",e.jsx(Ia,{className:"h-4 w-4 ml-2"})]}),e.jsx(ae,{variant:"ghost",onClick:l,className:"w-full",children:"Skip for now"})]})]})})}const pn=[{id:"sharing",labelKey:"fileSharing.shareDialog.sharingOptions",icon:gl},{id:"branding",labelKey:"fileSharing.shareDialog.branding",icon:Va},{id:"layout",labelKey:"fileSharing.shareDialog.presentationLayout",icon:Xa},{id:"permissions",labelKey:"fileSharing.shareDialog.permissions",icon:xl},{id:"badges",labelKey:"fileSharing.shareDialog.customBadges",icon:Ga},{id:"preview",labelKey:"fileSharing.shareDialog.openGraph",icon:zs},{id:"footer",labelKey:"fileSharing.shareDialog.footerLinks",icon:ys}];function jn({open:t,onOpenChange:r,folderName:a,onLinkActivated:g,onShareUrlChange:o,folderImages:l=[],coverUrl:S,initialPresentationMode:h,initialDesignSettings:C,initialPortfolioSettings:N,initialPermissions:f,initialBranding:v,initialIdentify:I,initialDefaultOrder:x,initialSlug:d,activeLinkId:E,shareBaseUrl:T="https://getvsble.com",initialWatermark:A,initialHighRes:H,initialLowRes:Q,initialHasPassword:re,initialExpiry:le,initialFooterSocialStyle:de,initialFooterSocialLinks:oe,initialFooterCustomLinks:ee,initialOgTitle:W,initialOgDescription:w,initialOgImageUrl:k}){const{t:y}
74=bt(),{isShareCapped:L}=ws(),[Ee,Ye]=s.useState(!1),[$e,mt]=s.useState(!1),[Te,De]=s.useState("sharing"),[Y,z]=s.useState(!1),[ue,Me]=s.useState(!1),[Se,X]=s.useState(()=>d||Ea(a)),[xe,me]=s.useState(!1),[te,V]=s.useState(""),[ie,be]=s.useState(!1),[Be,gt]=s.useState(()=>le||"never"),se=s.useRef(!1),J=s.useRef(!1),[he,_e]=s.useState(!0),[ve,pe]=s.useState(!0),[we,ct]=s.useState(!1),[Ue,lt]=s.useState("browser"),[Ne,Oe]=s.useState("user-preference"),[ce,Xe]=s.useState("not-required"),[Ge,rt]=s.useState(!1),[Qe,Ae]=s.useState(null),[qe,it]=s.useState(null),[et,_t]=s.useState(50),[ut,tt]=s.useState(50),[fe,Ct]=s.useState(h||"default"),[nt,st]=s.useState(C||fa),[at,xt]=s.useState(N||ha),[B,c]=s.useState((f==null?void 0:f.allowStarImages)??!0),[Pe,ft]=s.useState((f==null?void 0:f.allowFlagImages)??!0),[Ce,Nt]=s.useState((f==null?void 0:f.allowScribble)??!0),[Ke,ot]=s.useState((f==null?void 0:f.allowComments)??!0),[ze,Tt]=s.useState((f==null?void 0:f.requireIdentityForActions)??!1),ge=$a(),[ne,ye]=s.useState(f!=null&&f.customBadges&&f.customBadges.length>0?f.customBadges:ge.badges??[]),[Re,u]=s.useState(f!=null&&f.hiddenDefaultBadges&&f.hiddenDefaultBadges.length>0?f.hiddenDefaultBadges:ge.hiddenDefaultBadges??[]),[M,P]=s.useState(""),[q,ke]=s.useState("#6366f1"),[Fe,Ft]=s.useState(W||a),[i,m]=s.useState(w??""),[b,n]=s.useState(k??null),[p,_]=s.useState(!1),D=s.useRef(null),[O,R]=s.useState(de??"WHITE"),[F,K]=s.useState(oe??[]),[Z,$]=s.useState(ee??[]),Le=s.useRef({isPrivate:!1,password:"",expiry:"never",highRes:!0,lowRes:!0,watermark:!1,language:"browser",defaultOrder:"user-preference",identify:"not-required",useSpecificBranding:!1,specificLogo:null,specificBackground:null,specificFocusX:50,specificFocusY:50,presentationMode:"default",designSettings:fa,portfolioSettings:ha,allowStarImages:!0,allowFlagImages:!0,allowScribble:!0,allowComments:!0,requireIdentityForActions:!1,ogTitle:a,ogDescription:"",ogImageUrl:null,footerSocialStyle:"WHITE",footerSocialLinks:[],footerCustomLinks:[],customBadges:[],hiddenDefaultBadges:[]});s.useEffect(()=>{if(t){h&&Ct(h),C&&st(C),N&&xt(N),f?(f.allowStarImages!==void 0&&c(f.allowStarImages),f.allowFlagImages!==void 0&&ft(f.allowFlagImages),f.allowScribble!==void 0&&Nt(f.allowScribble),f.allowComments!==void 0&&ot(f.allowComments),f.requireIdentityForActions!==void 0&&Tt(f.requireIdentityForActions),f.customBadges&&f.customBadges.length>0?ye(f.customBadges):ye(ge.badges??[]),f.hiddenDefaultBadges&&f.hiddenDefaultBadges.length>0?u(f.hiddenDefaultBadges):u(ge.hiddenDefaultBadges??[])):(ye(ge.badges??[]),u(ge.hiddenDefaultBadges??[])),v&&(rt(v.useSpecificBranding),Ae(v.specificLogo),it(v.specificBackground),_t(v.specificFocusX),tt(v.specificFocusY)),I&&Xe(I),x&&Oe(x),d&&X(d),A!==void 0&&ct(A),H!==void 0&&_e(H),Q!==void 0&&pe(Q),de&&R(de),oe&&K(oe),ee&&$(ee);const j=W||a,je=w??"",pt=k??null;Ft(j),m(je),n(pt),me(!!re),V(""),be(!1);const Ot=L?"12h":le||"never";gt(Ot),se.current=!1,J.current=!1,setTimeout(()=>{const Ze=v;Le.current={isPrivate:!!re,password:"",expiry:Ot,highRes:he,lowRes:ve,watermark:we,language:Ue,defaultOrder:x||Ne,identify:I||ce,useSpecificBranding:(Ze==null?void 0:Ze.useSpecificBranding)??Ge,specificLogo:(Ze==null?void 0:Ze.specificLogo)??Qe,specificBackground:(Ze==null?void 0:Ze.specificBackground)??qe,specificFocusX:(Ze==null?void 0:Ze.specificFocusX)??et,specificFocusY:(Ze==null?void 0:Ze.specificFocusY)??ut,presentationMode:h||fe,designSettings:C||nt,portfolioSettings:N||at,allowStarImages:(f==null?void 0:f.allowStarImages)??B,allowFlagImages:(f==null?void 0:f.allowFlagImages)??Pe,allowScribble:(f==null?void 0:f.allowScribble)??Ce,allowComments:(f==null?void 0:f.allowComments)??Ke,requireIdentityForActions:(f==null?void 0:f.requireIdentityForActions)??ze,ogTitle:j,ogDescription:je,ogImageUrl:pt,footerSocialStyle:de??O,footerSocialLinks:oe??F,footerCustomLinks:ee??Z,customBadges:(f==null?void 0:f.customBadges)??ne,hiddenDefaultBadges:(f==null?void 0:f.hiddenDefaultBadges)??Re}},0)}},[t]),s.useEffect(()=>{!t||!d||J.current||X(d)},[t,d]),s.useEffect(()=>{if(!t||!L||typeof window>"u")return;const j="vsble.trialShareLimit.seen";sessionStorage.getItem(j)||(mt(!0),sessionStorage.setItem(j,"1"))},[t,L]);const Je=s.useMemo(()=>{const j=Le.current;return xe!==j.isPrivate||te!==j.password||Be!==j.expiry||he!==j.highRes||ve!==j.lowRes||we!==j.watermark||Ue!==j.language||Ne!==j.defaultOrder||ce!==j.identify||Ge!==j.useSpecificBranding||Qe!==j.specificLogo||qe!==j.specificBackgroun
74d||et!==j.specificFocusX||ut!==j.specificFocusY||fe!==j.presentationMode||JSON.stringify(nt)!==JSON.stringify(j.designSettings)||JSON.stringify(at)!==JSON.stringify(j.portfolioSettings)||B!==j.allowStarImages||Pe!==j.allowFlagImages||Ce!==j.allowScribble||Ke!==j.allowComments||ze!==j.requireIdentityForActions||Fe!==j.ogTitle||i!==j.ogDescription||b!==j.ogImageUrl||O!==j.footerSocialStyle||JSON.stringify(F)!==JSON.stringify(j.footerSocialLinks)||JSON.stringify(Z)!==JSON.stringify(j.footerCustomLinks)||JSON.stringify(ne)!==JSON.stringify(j.customBadges)||JSON.stringify(Re)!==JSON.stringify(j.hiddenDefaultBadges)},[xe,te,Be,he,ve,we,Ue,Ne,ce,Ge,Qe,qe,et,ut,fe,nt,at,B,Pe,Ce,Ke,ze,Fe,i,b,O,F,Z,ne,Re]),kt=s.useMemo(()=>{const j=Le.current,je=new Set;return(xe!==j.isPrivate||te!==j.password||Be!==j.expiry||he!==j.highRes||ve!==j.lowRes||we!==j.watermark||Ue!==j.language||Ne!==j.defaultOrder||ce!==j.identify)&&je.add("sharing"),(Ge!==j.useSpecificBranding||Qe!==j.specificLogo||qe!==j.specificBackground||et!==j.specificFocusX||ut!==j.specificFocusY)&&je.add("branding"),(fe!==j.presentationMode||JSON.stringify(nt)!==JSON.stringify(j.designSettings)||JSON.stringify(at)!==JSON.stringify(j.portfolioSettings))&&je.add("layout"),(B!==j.allowStarImages||Pe!==j.allowFlagImages||Ce!==j.allowScribble||Ke!==j.allowComments||ze!==j.requireIdentityForActions)&&je.add("permissions"),(Fe!==j.ogTitle||i!==j.ogDescription||b!==j.ogImageUrl)&&je.add("preview"),(O!==j.footerSocialStyle||JSON.stringify(F)!==JSON.stringify(j.footerSocialLinks)||JSON.stringify(Z)!==JSON.stringify(j.footerCustomLinks))&&je.add("footer"),(JSON.stringify(ne)!==JSON.stringify(j.customBadges)||JSON.stringify(Re)!==JSON.stringify(j.hiddenDefaultBadges))&&je.add("badges"),je},[xe,te,Be,he,ve,we,Ue,Ne,ce,Ge,Qe,qe,et,ut,fe,nt,at,B,Pe,Ce,Ke,ze,Fe,i,b,O,F,Z,ne,Re]),He=`${T}/share/${Se}`,dt=()=>xe?ie&&te?te:void 0:re||ie?"":void 0,Ut=async()=>{if(!g){navigator.clipboard.writeText(`${T}/share/${Se}`),G.success(y("fileSharing.shareDialog.linkCopied")),r(!1);return}const j=await g({identify:ce,allowStarImages:B,allowFlagImages:Pe,allowScribble:Ce,allowComments:Ke,requireIdentityForActions:ze,expiry:Be,expiryTouched:se.current,defaultOrder:Ne,password:dt(),customBadges:ne,hiddenDefaultBadges:Re,presentationMode:fe,designSettings:nt,portfolioSettings:at,useSpecificBranding:Ge,specificLogo:Qe,specificBackground:qe,specificFocusX:et,specificFocusY:ut,watermark:we,highRes:he,lowRes:ve,ogTitle:Fe,ogDescription:i,ogImageUrl:b,footerSocialStyle:O,footerSocialLinks:F,footerCustomLinks:Z,slug:J.current?Se:void 0});typeof j!="string"||!j||(navigator.clipboard.writeText(`${T}/share/${j}`),G.success(y("fileSharing.shareDialog.linkCopied")),r(!1))},Xt=async()=>{if(!Je)return;const j=dt(),je=await(g==null?void 0:g({identify:ce,allowStarImages:B,allowFlagImages:Pe,allowScribble:Ce,allowComments:Ke,requireIdentityForActions:ze,expiry:Be,expiryTouched:se.current,defaultOrder:Ne,password:j,customBadges:ne,hiddenDefaultBadges:Re,presentationMode:fe,designSettings:nt,portfolioSettings:at,useSpecificBranding:Ge,specificLogo:Qe,specificBackground:qe,specificFocusX:et,specificFocusY:ut,watermark:we,highRes:he,lowRes:ve,ogTitle:Fe,ogDescription:i,ogImageUrl:b,footerSocialStyle:O,footerSocialLinks:F,footerCustomLinks:Z,slug:J.current?Se:void 0}));g&&(typeof je!="string"||!je)||(Le.current={isPrivate:xe,password:"",expiry:Be,highRes:he,lowRes:ve,watermark:we,language:Ue,defaultOrder:Ne,identify:ce,useSpecificBranding:Ge,specificLogo:Qe,specificBackground:qe,specificFocusX:et,specificFocusY:ut,presentationMode:fe,designSettings:nt,portfolioSettings:at,allowStarImages:B,allowFlagImages:Pe,allowScribble:Ce,allowComments:Ke,requireIdentityForActions:ze,ogTitle:Fe,ogDescription:i,ogImageUrl:b,footerSocialStyle:O,footerSocialLinks:F,footerCustomLinks:Z,customBadges:ne,hiddenDefaultBadges:Re},V(""),be(!1),G.success(y("fileSharing.shareDialog.settingsSaved")),r(!1))};return e.jsxs(vt,{open:t,onOpenChange:r,children:[e.jsx(yt,{className:"w-[95vw] sm:max-w-3xl p-0 overflow-hidden",children:e.jsxs("div",{className:"flex h-[520px]",children:[e.jsxs("div",{className:"w-[200px] border-r border-border bg-muted/30 flex flex-col shrink-0",children:[e.jsxs("div",{className:"p-3 space-y-1 flex-1",children:[e.jsx(St,{className:"px-2 pb-3",children:e.jsx(wt,{className:"text-sm",children:y("fileSharing.shareDialog.shareSettings")})}),pn.map(j=>e.jsxs("button",{onClick:()=>De(j.id),className:Ve("flex w-full items-center gap-2 rounded-md px-2.5 py-2 text-sm transition-colors text-left",Te===j.id?"bg-accent text-accent-foreground font-medium":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"),children:[e.jsx(j.icon,{className:"h-4 w-4 shrink-0"}),y(j.labelKey),kt.has(j.id)&&e.jsx("span",{className:"ml-auto h-1.5 w-1.5 rounded-full bg-green-500"})]},j.id))]}),e.jsx("div",{className:"p-3 border-t border-border",children:e.jsx(ae,{disabled:!Je,className:Ve("w-full",Je?"bg-green-600 hover:bg-green-700 text-white":"bg-muted text-muted-foreground cursor-not-allowed"),onClick:Xt,children:y("fileSharing.shareDialog.save")})})]}),e.jsx("div",{className:"flex-1 min-w-0 overflow-y-auto p-6 space-y-6",children:Te==="sharing"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-lg border border-green-600/30 bg-green-600/10 p-3 flex items-center gap-2 min-w-0 
74w-full overflow-hidden",children:[e.jsx(ys,{className:"h-4 w-4 text-green-600 shrink-0"}),e.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:e.jsxs("span",{className:"block w-full truncate whitespace-nowrap text-sm text-foreground cursor-help",title:He,children:["…/share/",Se]})}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx(ae,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>z(!0),children:e.jsx(ls,{className:"h-3.5 w-3.5"})}),e.jsx(ae,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>Me(!0),children:e.jsx(Us,{className:"h-3.5 w-3.5"})}),e.jsx(ae,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:Ut,children:e.jsx(qs,{className:"h-3.5 w-3.5"})})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ps,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(We,{children:y("fileSharing.shareDialog.makePrivate")})]}),e.jsx(zt,{checked:xe,onCheckedChange:j=>{me(j),be(!0),j||V("")}})]}),xe&&e.jsxs("div",{className:"pl-6 space-y-1.5",children:[e.jsx(ht,{type:"password",placeholder:y(re&&!ie?"fileSharing.shareDialog.passwordSetPlaceholder":"fileSharing.shareDialog.enterPassword"),value:te,onChange:j=>{V(j.target.value),be(!0)},className:"flex-1"}),ie&&te.length>0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:y("fileSharing.shareDialog.clickSaveToApply")||"Click Save to apply the password."})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ss,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(We,{children:y("fileSharing.shareDialog.linkExpiration")})]}),e.jsxs("div",{className:"pl-6",children:[e.jsxs(Wt,{value:Be,onValueChange:j=>{if(L&&j!=="12h"){Ye(!0);return}gt(j),se.current=!0},children:[e.jsx(Yt,{children:e.jsx(Kt,{})}),e.jsxs(Vt,{children:[L&&e.jsx(Ie,{value:"12h",children:e.jsx("span",{className:"flex items-center gap-1.5",children:"12 hours"})}),e.jsx(Ie,{value:"24h",className:L?"text-muted-foreground":"",children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[y("fileSharing.shareDialog.24hours"),L&&e.jsx(Dt,{className:"h-3 w-3"})]})}),e.jsx(Ie,{value:"48h",className:L?"text-muted-foreground":"",children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[y("fileSharing.shareDialog.48hours"),L&&e.jsx(Dt,{className:"h-3 w-3"})]})}),e.jsx(Ie,{value:"7d",className:L?"text-muted-foreground":"",children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[y("fileSharing.shareDialog.7days"),L&&e.jsx(Dt,{className:"h-3 w-3"})]})}),e.jsx(Ie,{value:"1m",className:L?"text-muted-foreground":"",children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[y("fileSharing.shareDialog.1month"),L&&e.jsx(Dt,{className:"h-3 w-3"})]})}),e.jsx(Ie,{value:"3m",className:L?"text-muted-foreground":"",children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[y("fileSharing.shareDialog.3months"),L&&e.jsx(Dt,{className:"h-3 w-3"})]})}),e.jsx(Ie,{value:"never",className:L?"text-muted-foreground":"text-green-600 font-medium",children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[y("fileSharing.shareDialog.neverExpires"),L&&e.jsx(Dt,{className:"h-3 w-3"})]})})]})]}),L&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1.5 flex items-center gap-1.5",children:[e.jsx(Dt,{className:"h-3 w-3"}),"Trial: links capped at 24 hours."]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Js,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(We,{children:y("fileSharing.shareDialog.downloadOptions")})]}),e.jsxs("div",{className:"pl-6 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-border p-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:y("fileSharing.shareDialog.highResFiles")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:y("fileSharing.shareDialog.highResDesc")})]}),e.jsx(zt,{checked:he,onCheckedChange:_e})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-border p-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:y("fileSharing.shareDialog.lowResFiles")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:y("fileSharing.shareDialog.lowResDesc")})]}),e.jsx(zt,{checked:ve,onCheckedChange:pe})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(wl,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx(We,{children:y("fileSharing.shareDialog.identify")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:y("fileSharing.shareDialog.identifyDesc")})]})]}),e.jsxs("div",{className:"pl-6",children:[e.jsxs(Wt,{value:ce,onValueChange:j=>Xe(j),children:[e.jsx(Yt,{children:e.jsx(Kt,{})}),e.jsxs(Vt,{children:[e.jsx(Ie,{value:"not-required",children:y("fileSharing.shareDialog.notRequired")}),e.jsx(Ie,{value:"optional",children:y("fileSharing.shareDialog.optional")}),e.jsx(Ie,{value:"required",children:y("fileSharing.shareDialog.required")})]})]}),e.jsxs("p",{className:"mt-1.5 text-xs text-muted-foreground",children:[ce==="not-required"&&y("fileSharing.shareDialog.identifyNotRequiredDesc"),ce==="optional"&&y("fileSharing.shareDialog.identifyOptionalDesc"),ce==="required"&&y("fileSharing.shareDialog.identifyRequiredDesc")]})]})]}),e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Bs,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(We,{children:y("fileSharing.shareDialog.previewWatermark")})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{className:"text-xs text-green-600 hover:underline",onClick:()=>{r(!1),window.location.href="/file-sharing/watermark"},children:y("fileSharing.shareDialog.customize")}),e.jsx(zt,{checked:we,onCheckedChange:ct})]})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(zs,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx(We,{children:y("fileSharing.shareDialog.defaultLanguage")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:y("fileSharing.shareDialog.defaultLanguageDesc")})]})]}),e.jsx("div",{className:"pl-6",children:e.jsxs(Wt,{value:Ue,onValueChange:lt,children:[e.jsx(Yt,{children:e.jsx(Kt,{})}),e.jsxs(Vt,{children:[e.jsx(Ie,{value:"browser",children:y("fileSharing.shareDialog.browserDefault")}),e.jsx(Ie,{value:"en",children:"English (US)"}),e.jsx(Ie,{value:"de",children:"Deutsch"}),e.jsx(Ie,{value:"fr",children:"Français"}),e.jsx(Ie,{value:"es",children:"Español"}),e.jsx(Ie,{value:"it",children:"Italiano"})]})]})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(La,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx(We,{children:y("fileSharing.shareDialog.defaultOrder")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:y("fileSharing.shareDialog.defaultOrderDesc")})]})]}),e.jsx("div",{className:"pl-6",children:e.jsxs(Wt,{value:Ne,onValueChange:Oe,children:[e.jsx(Yt,{children:e.jsx(Kt,{})}),e.jsxs(Vt,{children:[e.jsx(Ie,{value:"custom",children:y("fileSharing.shareDialog.customOrder")}),e.jsx(Ie,{value:"user-preference",children:y("fileSharing.shareDialog.userPreference")}),e.jsx(Ie,{value:"newest",children:y("fileSharing.shareDialog.newestFirst")}),e.jsx(Ie,{value:"oldest",children:y("fileSharing.shareDialog.oldestFirst")}),e.jsx(Ie,{value:"largest",children:y("fileSharing.shareDialog.largeFirst")}),e.jsx(Ie,{value:"smallest",children:y("fileSharing.shareDialog.smallFirst")}),e.jsx(Ie,{value:"filename",children:y("fileSharing.shareDialog.filenameAZ")}),e.jsx(Ie,{value:"filename-desc",children:y("fileSharing.shareDialog.filenameZA")})]})]})})]})]}):Te==="branding"?e.jsx(hl,{useSpecificBranding:Ge,onUseSpecificBrandingChange:rt,specificLogo:Qe,onSpecificLogoChange:Ae,specificBackgroun
74d:qe,onSpecificBackgroundChange:it,specificFocusX:et,specificFocusY:ut,onSpecificFocusChange:(j,je)=>{_t(j),tt(je)},onCloseDialog:()=>r(!1)}):Te==="layout"?e.jsx(ml,{mode:fe,onModeChange:Ct,designSettings:nt,onDesignSettingsChange:st,portfolioSettings:at,onPortfolioSettingsChange:xt,folderImages:l,coverUrl:S}):Te==="permissions"?e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-foreground",children:y("fileSharing.shareDialog.userPermissions")}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:y("fileSharing.shareDialog.userPermissionsDesc")})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[e.jsx(At,{checked:B,onCheckedChange:j=>c(j===!0)}),e.jsx("span",{className:"text-sm text-foreground",children:y("fileSharing.shareDialog.allowStar")})]}),e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[e.jsx(At,{checked:Pe,onCheckedChange:j=>ft(j===!0)}),e.jsx("span",{className:"text-sm text-foreground",children:y("fileSharing.shareDialog.allowFlag")})]}),e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[e.jsx(At,{checked:Ce,onCheckedChange:j=>Nt(j===!0)}),e.jsx("span",{className:"text-sm text-foreground",children:y("fileSharing.shareDialog.allowScribble")})]}),e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[e.jsx(At,{checked:Ke,onCheckedChange:j=>ot(j===!0)}),e.jsx("span",{className:"text-sm text-foreground",children:y("fileSharing.shareDialog.allowComments")})]}),e.jsxs("div",{className:"border-t border-border pt-4",children:[e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[e.jsx(At,{checked:ze,onCheckedChange:j=>Tt(j===!0)}),e.jsx("span",{className:"text-sm text-foreground",children:y("fileSharing.shareDialog.requireIdentity")})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2 pl-7",children:y("fileSharing.shareDialog.requireIdentityDesc")})]})]})]}):Te==="badges"?e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-foreground",children:y("fileSharing.shareDialog.customBadgesTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:y("fileSharing.shareDialog.customBadgesDesc")}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:y("fileSharing.shareDialog.customBadgesGlobalHint")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:y("fileSharing.shareDialog.defaultBadges")}),e.jsx("div",{className:"space-y-1.5",children:il.filter(j=>j.value!=="none").map(j=>e.jsxs("div",{className:"flex items-center justify-between rounded-md border border-border px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:Ve("h-3 w-3 rounded-full shrink-0",j.color)}),e.jsx("span",{className:"text-sm text-foreground",children:j.label})]}),e.jsx(zt,{checked:!Re.includes(j.value),onCheckedChange:je=>{u(pt=>je?pt.filter(Ot=>Ot!==j.value):[...pt,j.value])}})]},j.value))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:y("fileSharing.shareDialog.customBadgesTitle")}),ne.length>0&&e.jsx("div",{className:"space-y-1.5",children:ne.map(j=>e.jsxs("div",{className:"flex items-center justify-between rounded-md border border-border px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"h-3 w-3 rounded-full shrink-0",style:{backgroundColor:j.color}}),e.jsx("span",{className:"text-sm text-foreground",children:j.label})]}),e.jsx("button",{className:"p-1 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors",onClick:()=>ye(je=>je.filter(pt=>pt.id!==j.id)),children:e.jsx(Ka,{className:"h-3.5 w-3.5"})})]},j.id))}),ne.length<10&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-dashed border-border px-3 py-2",children:[e.jsx(fl,{value:q,onChange:ke}),e.jsx(ht,{value:M,onChange:j=>P(j.target.value),placeholder:y("fileSharing.shareDialog.badgeNamePlaceholder"),className:"h-8 flex-1 text-sm",onKeyDown:j=>{j.key==="Enter"&&M.trim()&&(ye(je=>[...je,{id:crypto.randomUUID(),label:M.trim(),color:q}]),P(""))}}),e.jsx(ae,{size:"sm",variant:"ghost",className:"h-8 px-2",disabled:!M.trim(),onClick:()=>{ye(j=>[...j,{id:crypto.randomUUID(),label:M.trim(),color:q}]),P("")},children:e.jsx(bs,{className:"h-4 w-4"})})]}),ne.length>=10&&e.jsx("p",{className:"text-xs text-muted-foreground",children:y("fileSharing.shareDialog.maxBadgesReached")})]})]}):Te==="preview"?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium text-foreground",children:y("fileSharing.shareDialog.openGraphImage")}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:y("fileSharing.shareDialog.ogImageDesc")})]}),e.jsxs("div",{children:[e.jsx("input",{ref:D,type:"file",accept:"image/*",className:"hidden",onChange:async j=>{var pt,Ot;const je=(pt=j.target.files)==null?void 0:pt[0];if(je){_(!0);try{const{data:Ze}=await U.auth.getUser(),It=(Ot=Ze.user)==null?void 0:Ot.id;if(!It)throw new Error("Not authenticated");const{uploadBrandingAsset:Bt}=await br(async()=>{const{uploadBrandingAsset:Jt}=await import("./upload-branding-ClqCFvGd.js");return{uploadBrandingAsset:Jt}},__vite__mapDeps([0,1,2])),qt=await Bt(It,je,"background");n(qt),G.success(y("fileSharing.shareDialog.imageUploaded"))}catch(Ze){G.error(Ze.message||y("fileSharing.shareDialog.uploadFailed"))}finally{_(!1),j.target.value=""}}}}),b?e.jsxs("div",{className:"relative group",children:[e.jsx("img",{src:b,alt:"Open Graph preview",className:"w-full rounded-lg border border-border object-cover",style:{aspectRatio:"1.91 / 1"}}),e.jsx("button",{onClick:()=>n(null),className:"absolute top-2 right-2 flex h-7 w-7 items-center justify-center rounded-full bg-background/80 text-foreground shadow-sm backdrop-blur-sm op
74acity-0 group-hover:opacity-100 transition-opacity hover:bg-destructive hover:text-destructive-foreground",children:e.jsx(Ts,{className:"h-4 w-4"})})]}):e.jsxs("button",{onClick:()=>{var j;return(j=D.current)==null?void 0:j.click()},disabled:p,className:"flex w-full items-center justify-center gap-2 rounded-lg border-2 border-dashed border-border bg-muted/30 text-muted-foreground hover:bg-muted/50 transition-colors",style:{aspectRatio:"1.91 / 1"},children:[e.jsx(ms,{className:"h-5 w-5"}),e.jsx("span",{className:"text-sm",children:y(p?"fileSharing.shareDialog.uploading":"fileSharing.shareDialog.uploadImage")})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(We,{className:"text-xs",children:y("fileSharing.shareDialog.title")}),e.jsx(ht,{value:Fe,onChange:j=>Ft(j.target.value),placeholder:y("fileSharing.shareDialog.pageTitlePlaceholder")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(We,{className:"text-xs",children:y("fileSharing.shareDialog.description")}),e.jsx(Da,{value:i,onChange:j=>m(j.target.value),placeholder:y("fileSharing.shareDialog.descriptionPlaceholder"),rows:2,className:"resize-none"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-foreground",children:y("fileSharing.shareDialog.preview")}),e.jsxs("div",{className:"rounded-lg border border-border overflow-hidden bg-muted/20",children:[e.jsx("div",{className:"w-full bg-muted flex items-center justify-center",style:{aspectRatio:"1.91 / 1"},children:b?e.jsx("img",{src:b,alt:"",className:"w-full h-full object-cover"}):e.jsxs("div",{className:"flex flex-col items-center gap-1 text-muted-foreground",children:[e.jsx(Bs,{className:"h-6 w-6"}),e.jsx("span",{className:"text-xs",children:y("fileSharing.shareDialog.noImageSet")})]})}),e.jsxs("div",{className:"p-3 space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:new URL(He).hostname}),e.jsx("p",{className:"text-sm font-semibold text-foreground truncate",children:Fe||a}),i&&e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2",children:i})]})]})]})]}):Te==="footer"?e.jsx(fn,{socialStyle:O,onSocialStyleChange:R,socialLinks:F,onSocialLinksChange:K,customLinks:Z,onCustomLinksChange:$}):null})]})}),e.jsx(cn,{open:Y,onOpenChange:z,currentSlug:Se,currentLinkId:E||void 0,shareBaseUrl:T,onSave:async j=>{J.current=!0;const je=await(g==null?void 0:g({identify:ce,allowStarImages:B,allowFlagImages:Pe,allowScribble:Ce,allowComments:Ke,requireIdentityForActions:ze,expiry:Be,expiryTouched:se.current,defaultOrder:Ne,password:dt(),customBadges:ne,hiddenDefaultBadges:Re,presentationMode:fe,designSettings:nt,portfolioSettings:at,useSpecificBranding:Ge,specificLogo:Qe,specificBackground:qe,specificFocusX:et,specificFocusY:ut,watermark:we,highRes:he,lowRes:ve,ogTitle:Fe,ogDescription:i,ogImageUrl:b,footerSocialStyle:O,footerSocialLinks:F,footerCustomLinks:Z,slug:j}));if(g&&(typeof je!="string"||!je)){J.current=!1;return}const pt=typeof je=="string"&&je?je:j;X(pt),o==null||o(`${T}/share/${pt}`)}}),e.jsx(hr,{open:ue,onOpenChange:Me,shareUrl:He,senderName:a,galleryName:a,password:te}),e.jsx(ta,{open:Ee,onOpenChange:Ye,reason:"share_duration"}),e.jsx(mr,{open:$e,onOpenChange:mt})]})}function bn({name:t,nodeId:r,coverUrl:a,coverFocusX:g=50,coverFocusY:o=50,onRename:l,onDelete:S,onAddSubfolder:h,folderImages:C=[],allNodes:N,ancestors:f,onNavigate:v,folderFiles:I=[],onSaveCover:x}){var xt;const{t:d}=bt(),{subscription:E,isAdmin:T}=Et(),A=vs(),H=al(),Q=rl(),re=ll(),le=s.useRef(re);le.current=re;const[de,oe]=s.useState(!1),[ee,W]=s.useState(!1),[w,k]=s.useState(!1),[y,L]=s.useState(!1),[Ee,Ye]=s.useState("not-required"),[$e,mt]=s.useState(null),[Te,De]=s.useState(t.toLowerCase().replace(/\s+/g,"-")),Y=s.useRef(null),[z,ue]=s.useState(!1),Me=s.useRef(!1),[Se,X]=s.useState("https://getvsble.com"),[xe,me]=s.useState(`https://getvsble.com/share/${Te}`),[te,V]=s.useState("default"),[ie,be]=s.useState(void 0),[Be,gt]=s.useState(void 0),[se,J]=s.useState({}),[he,_e]=s.useState("user-preference");
74s.useState("");const[ve,pe]=s.useState(!1),[we,ct]=s.useState(!0),[Ue,lt]=s.useState(!0),[Ne,Oe]=s.useState(!1),[ce,Xe]=s.useState("never"),[Ge,rt]=s.useState({footerSocialStyle:"WHITE",footerSocialLinks:[],footerCustomLinks:[]}),[Qe,Ae]=s.useState({ogTitle:"",ogDescription:"",ogImageUrl:""}),[qe,it]=s.useState(!1),et=T||!!E.subscribed||!!E.standaloneFileSharing||!!((xt=E.universalTrial)!=null&&xt.active),_t=B=>{z&&(et?B():oe(!0))},[ut,tt]=s.useState({useSpecificBranding:!1,specificLogo:null,specificBackground:null,specificFocusX:50,specificFocusY:50}),fe=r?N.find(B=>B.id===r):N.find(B=>B.name===t),Ct=s.useCallback(B=>{const c=N.find(Pe=>Pe.id===B);return!c||!c.parentId?B:Ct(c.parentId)},[N]);s.useEffect(()=>{ya().then(B=>{X(B),me(`${B}/share/${Te}`)})},[Te]),s.useEffect(()=>{if(!fe)return;const B=fe.id,c=Ct(fe.id),ft=!fe.parentId?null:fe.id;Y.current=null,ue(!1);let Ce=!1;const Nt=Ea(t);L(!1),mt(null),De(Nt),me(`${Se}/share/${Nt}`),J({}),tt({useSpecificBranding:!1,specificLogo:null,specificBackground:null,specificFocusX:50,specificFocusY:50}),Oe(!1),Xe("never"),V("default"),be(void 0),gt(void 0),pe(!1),ct(!0),lt(!0),_e("user-preference"),rt({footerSocialStyle:"WHITE",footerSocialLinks:[],footerCustomLinks:[]}),Ae({ogTitle:"",ogDescription:"",ogImageUrl:""}),Ye("not-required"),Me.current=!1;const Ke=()=>{Ce||(Y.current=B,ue(!0))},ot=ge=>{Ye(ge.identify??"not-required"),_e(ge.default_order||"user-preference"),pe(ge.watermark??!1),ct(ge.allow_high_res??!0),lt(ge.allow_low_res??!0);const ne=ge.share_config??{};J({allowStarImages:ne.allowStarImages,allowFlagImages:ne.allowFlagImages,allowScribble:ne.allowScribble,allowComments:ne.allowComments,requireIdentityForActions:ne.requireIdentityForActions,customBadges:ne.customBadges,hiddenDefaultBadges:ne.hiddenDefaultBadges}),ne.presentationMode&&V(ne.presentationMode),ne.designSettings&&be(ne.designSettings),ne.portfolioSettings&&gt(ne.portfolioSettings),rt({footerSocialStyle:ne.footerSocialStyle??"WHITE",footerSocialLinks:ne.footerSocialLinks??[],footerCustomLinks:ne.footerCustomLinks??[]}),Ae({ogTitle:ne.ogTitle??"",ogDescription:ne.ogDescription??"",ogImageUrl:ne.ogImageUrl??""})},ze=async ge=>{const{data:ne}=await U.from("fs_share_branding").select("use_specific, logo_url, background_url, focus_x, focus_y").eq("share_link_id",ge).maybeSingle();ne&&!Ce&&tt({useSpecificBranding:ne.use_specific,specificLogo:ne.logo_url,specificBackground:ne.background_url,specificFocusX:ne.focus_x??50,specificFocusY:ne.focus_y??50})},Tt=async()=>{var M;const ge=[];let ne=fe.parentId??null;for(;ne;)ge.push(ne),ne=((M=N.find(P=>P.id===ne))==null?void 0:M.parentId)??null;if(ge.length===0)return!1;const ye=ge.filter(P=>P!==c),Re=["folder_id.is.null"];ye.length>0&&Re.unshift(`folder_id.in.(${ye.join(",")})`);const{data:u}=await U.from("fs_share_links").select("id, identify, default_order, watermark, allow_high_res, allow_low_res, share_config, folder_id").eq("project_id",c).or(Re.join(","));if(Ce||!u||u.length===0)return!1;for(const P of ge){const q=u.find(ke=>P===c?ke.folder_id===null:ke.folder_id===P);if(q)return ot(q),await ze(q.id),!Ce}return!1};return(async()=>{const ge=await ya();if(Ce)return;X(ge);let ne=U.from("fs_share_links").select("id, slug, identify, is_active, expires_at, default_order, watermark, allow_high_res, allow_low_res, share_config, password_hash, folder_id").eq("project_id",c);ne=ft?ne.eq("folder_id",ft):ne.is("folder_id",null);const{data:ye}=await ne.order("created_at",{ascending:!1}).limit(1).maybeSingle();if(Ce)return;if(!ye){me(`${ge}/share/${Nt}`);const u=await Tt();if(Ce)return;u||(Me.current=!0,_e(le.current.defaultOrder)),Ke();return}mt(ye.id),De(ye.slug),me(`${ge}/share/${ye.slug}`);const Re=!!ye.expires_at&&new Date(ye.expires_at)<new Date;if(!(Re&&ye.is_active&&(await U.from("fs_share_links").update({is_active:!1}).eq("id",ye.id),Ce))){if(Re||!ye.is_active){ot(ye),Oe(!!ye.password_hash),Re||Xe(st(ye.expires_at)),await ze(ye.id),Ke();return}Ke(),L(!0),ot(ye),Oe(!!ye.password_hash),Xe(st(ye.expires_at)),await ze(ye.id)}})(),()=>{Ce=!0}},[fe==null?void 0:fe.id,fe==null?void 0:fe.parentId,t,Ct,N]),s.useEffect(()=>{Me.current&&_e(re.defaultOrder)},[re.defaultOrder]);const nt=B=>{if(B==="never")return null;const c=new Date,ft={"1h":36e5,"12h":432e5,"24h":864e5,"48h":1728e5,"7d":6048e5,"30d":2592e6,"1m":2592e6,"3m":7776e6}[B];return ft?new Date(c.getTime()+ft).toISOString():null},st=B=>{if(!B)return"never";const c=new Date(B).getTime()-Date.now(),Pe=864e5;return c<=18*36e5?"12h":c<=36*36e5?"24h":c<=3*Pe?"48h":c<=14*Pe?"7d":c<=45*Pe?"1m":"3m"},at=s.useCallback(async(B,c,Pe,ft=!1)=>{var b;if(!fe)return null;if(Y.current!==fe.id)return console.warn("saveShareData: skipped, share state not hydrated for",fe.id),null;const Ce=Ct(fe.id),Ke=!fe.parentId?null:fe.id,ot=n=>N.filter(_=>_.parentId===n).flatMap(_=>[_,...ot(_.id)]),ze=ot(fe.id),Tt=ze.map(n=>{var p;return{id:n.id,name:n.name,coverUrl:n.coverUrl,coverFocusX:n.coverFocusX,coverFocusY:n.coverFocusY,fileCount:((p=N.find(_=>_.id===n.id))==null?void 0:p.imageCount)??0}}),ge=new Set([fe.id,...ze.map(n=>n.id)]),ye=(await ns(()=>U.from("fs_files").select("id, name, storage_path, folder_id, project_id, size, thumb_500_url, thumb_1440_url, thumb_3000_url, exif").eq("project_id",Ce))).map(n=>({id:n.id,name:n.name,url:n.storage_path,folderId:n.folder_id??n.project_id,size:Number(n.size),thumb500Url:n.thumb_500_url??void 0,thumb1440Url:n.thumb_1440_url??void 0,thumb3000Url:n.thumb_3000_url??void 0,exif:n.exif??void 0})).filter(n=>ge.has(n.folderId)),Re=nt(Pe||"never");let u;if(c!=null&&c.password){const n=new TextEncoder,p=await crypto.subtle.digest("SHA-256",
74n.encode(c.password));u=Array.from(new Uint8Array(p)).map(_=>_.toString(16).padStart(2,"0")).join("")}let M;const P=((b=c==null?void 0:c.slug)==null?void 0:b.trim())||null;let q=P??Te;try{let n=U.from("fs_share_links").select("id, slug, is_active, expires_at, share_config, default_order").eq("project_id",Ce);n=Ke?n.eq("folder_id",Ke):n.is("folder_id",null);const{data:p}=await n.order("created_at",{ascending:!1}).limit(1).maybeSingle(),_=vr({existingSlug:(p==null?void 0:p.slug)??null,explicitSlug:P,fallbackSlug:Te}),D=_.mustResolve;let O;if(!D)O=_.slug;else{const Z=await Ta(U,_.slug,{currentId:p==null?void 0:p.id});O=Z.slug,Z.suffixed&&G.info(d("fileSharing.folderHeader.slugAdjusted",{slug:O}))}q=O;const R={};c!=null&&c.customBadges&&(R.customBadges=c.customBadges),c!=null&&c.hiddenDefaultBadges&&(R.hiddenDefaultBadges=c.hiddenDefaultBadges),c!=null&&c.presentationMode&&(R.presentationMode=c.presentationMode),c!=null&&c.designSettings&&(R.designSettings=c.designSettings),c!=null&&c.portfolioSettings&&(R.portfolioSettings=c.portfolioSettings),c!=null&&c.ogTitle&&(R.ogTitle=c.ogTitle),c!=null&&c.ogDescription&&(R.ogDescription=c.ogDescription),c!=null&&c.ogImageUrl&&(R.ogImageUrl=c.ogImageUrl),c!=null&&c.footerSocialLinks&&(R.footerSocialLinks=c.footerSocialLinks),c!=null&&c.footerCustomLinks&&(R.footerCustomLinks=c.footerCustomLinks),c!=null&&c.footerSocialStyle&&(R.footerSocialStyle=c.footerSocialStyle),R.allowStarImages=(c==null?void 0:c.allowStarImages)??!0,R.allowFlagImages=(c==null?void 0:c.allowFlagImages)??!0,R.allowScribble=(c==null?void 0:c.allowScribble)??!0,R.allowComments=(c==null?void 0:c.allowComments)??!0,R.requireIdentityForActions=(c==null?void 0:c.requireIdentityForActions)??!1;const F=H;F&&(R.watermarkConfig=F),!R.designSettings&&Q&&(R.designSettings=Q);const K={identify:B,is_active:!0,share_config:{...(p==null?void 0:p.share_config)??{},...R},watermark:(c==null?void 0:c.watermark)??!1,allow_high_res:(c==null?void 0:c.highRes)??!0,allow_low_res:(c==null?void 0:c.lowRes)??!0};if(c!=null&&c.defaultOrder&&(K.default_order=c.defaultOrder),(c==null?void 0:c.password)!==void 0&&(K.password_hash=c.password?u:null),p){M=p.id;const Z=!!p.expires_at&&new Date(p.expires_at)<new Date;(ft||!p.is_active&&Z)&&(K.expires_at=Re);let $=O,Le=!1;const Je=D?3:1;for(let kt=0;kt<Je;kt++){const{error:He}=await U.from("fs_share_links").update(D?{...K,slug:$}:K).eq("id",p.id);if(!He){Le=!0,q=D?$:p.slug;break}if(He.code!=="23505"||!ia(He))throw He;$=os(O)}if(!Le)return G.error(d("fileSharing.folderHeader.slugTaken")),De(p.slug),me(`${Se}/share/${p.slug}`),null;D&&q!==O&&G.info(d("fileSharing.folderHeader.slugAdjusted",{slug:q})),De(q),me(`${Se}/share/${q}`)}else{let Z=null,$=O;for(let Le=0;Le<3;Le++){const{data:Je,error:kt}=await U.from("fs_share_links").insert({project_id:Ce,folder_id:Ke,default_order:(c==null?void 0:c.defaultOrder)||re.defaultOrder,...K,slug:$,expires_at:Re}).select("id").single();if(!kt){Z=Je,q=$;break}if(kt.code!=="23505"||!ia(kt))throw kt;$=os(O)}if(!Z)return G.error(d("fileSharing.folderHeader.slugTaken")),null;De(q),me(`${Se}/share/${q}`),M=Z==null?void 0:Z.id}mt(M||null)}catch(n){return console.error("Error upserting share link:",n),G.error(d("fileSharing.folderHeader.shareSaveFailed")),null}if(M&&(c==null?void 0:c.useSpecificBranding)!==void 0)try{const{data:n}=await U.from("fs_share_branding").select("id").eq("share_link_id",M).maybeSingle(),p={use_specific:c.useSpecificBranding,logo_url:c.specificLogo??null,background_url:c.specificBackground??null,focus_x:c.specificFocusX??50,focus_y:c.specificFocusY??50};n?await U.from("fs_share_branding").update(p).eq("id",n.id):await U.from("fs_share_branding").insert({share_link_id:M,...p})}catch(n){console.error("Error upserting share branding:",n)}let ke,Fe,Ft,i;try{if(M){const{data:n}=await U.from("fs_share_branding").select("use_specific, logo_url, background_url, focus_x, focus_y").eq("share_link_id",M).maybeSingle();n!=null&&n.use_specific&&(n.logo_url&&(ke=n.logo_url),n.background_url&&(Fe=n.background_url,Ft=n.focus_x??50,i=n.focus_y??50))}if(!ke||!Fe){const{data:n}=await U.from("fs_global_branding").select("logo_url, background_url, focus_x, focus_y").limit(1).maybeSingle();!ke&&(n!=null&&n.logo_url)&&(ke=n.logo_url),!Fe&&(n!=null&&n.background_url)&&(Fe=n.background_url,Ft=n.focus_x??50,i=n.focus_y??50)}}catch(n){console.error("Error resolving branding:",n)}let m;if(u)m=u;else if((c==null?void 0:c.password)===void 0&&M)try{const{data:n}=await U.from("fs_share_links").select("password_hash").eq("id",M).maybeSingle();n!=null&&n.password_hash&&(m=n.password_hash)}catch{}return c==null||c.allowStarImages,c==null||c.allowFlagImages,c==null||c.allowScribble,c==null||c.allowComments,c==null||c.requireIdentityForActions,c==null||c.customBadges,c==null||c.hiddenDefaultBadges,c==null||c.presentationMode,c==null||c.designSettings,c==null||c.portfolioSettings,c!=null&&c.defaultOrder,q&&q!==Te&&(De(q),me(`${Se}/share/${q}`)),q},[fe,N,t,a,g,o,Te,Ct,H,Q,re,Se]);return s.useEffect(()=>{fe&&Y.current===fe.id&&y&&at(Ee,{...se,presentationMode:te,designSettings:ie,portfolioSettings:Be,watermark:ve,highRes:we,lowRes:Ue,defaultOrder:he,...Qe,...Ge})},[y,z,at,Ee,te,ie,se]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative mx-4 mt-4 flex h-48 cursor-pointer items-center justify-center rounded-lg border-2 border-dashed border-border bg-muted/40 transition-colors hover:bg-muted/60",onClick:()=>W(!0),children:[a?e.jsx("img",{src:a,alt:"Cover",className:"h-full w-full rounded-lg object-cover",style:{objectPosition:`${g}% ${o}%`}}):e.jsxs("div",{className:"flex flex-col items-center gap-2 text-muted-foreground",children:[e.jsx(Lr,{className:"h-8 w-8"}),e.jsx("span",{className:"text-xs",children:d("fileSharing.folderHeader.clickToSetCover")})]}),a&&e.jsx("button",{className:"absolute top-2 right-2 flex h-7 w-7 items-center justify-center rounded-full bg-background/80 text-foreground shadow-sm backdrop-blur-sm hover:bg-background transition-colors opacity-0 group-hover:opacity-100 hover:opacity-100",style:{opacity:void 0},onClick:B=>{B.stopPropagation(),W(!0)},title:d("fileSharing.folderHeader.editCover"),children:e.jsx(ls,{className:"h-3.5 w-3.5"})}),y&&e.jsxs("div",{className:"absolute bottom-3 left-3 flex items-center gap-2",onClick:B=>B.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-2 rounded-full bg-green-600/90 px-3 py-1.5 text-white text-xs",children:[e.jsx("button",{className:"hover:text-white/70 transition-colors",onClick:async()=>{L(!1),$e&&await U.from("fs_share_links").update({is_active:!1}).eq("id",$e),G.success(d("fileSharing.folderHeader.linkRemoved"))},children:e.jsx(ea,{className:"h-3.5 w-3.5"})}),e.jsx("span",{className:"max-w-[180px] truncate",children:xe}),e.jsx("button",{className:"hover:text-white/70 transition-colors",onClick:()=>_t(()=>k(!0)),children:e.jsx(ls,{className:"h-3.5 w-3.5"})}),e.jsx("button",{className:"hover:text-white/70 transition-colors",onClick:()=>_t(()=>it(!0)),children:e.jsx(Us,{className:"h-3.5 w-3.5"})}),e.jsx("button",{className:"hover:text-white/70 transition-colors",onClick:()=>{navigator.clipboard.writeText(xe),G.success(d("fileSharing.folderHeader.linkCopied"))},children:e.jsx(qs,{className:"h-3.5 w-3.5"})})]}),e.jsx("button",{className:"flex h-7 w-7 items-center justify-center rounded-full bg-background/80 text-foreground shadow-sm backdrop-blur-sm hover:bg-background transition-colors",onClick:()=>window.open(xe,"_blank"),title:d("fileSharing.folderHeader.previewShareLink"),children:e.jsx(Ja,{className:"h-3.5 w-3.5"})})]})]}),e.jsx(nn,{open:ee,onOpenChange:W,currentCoverUrl:a,currentFocusX:g,currentFocusY:o,folderFiles:I,onSave:(B,c,Pe)=>x==null?void 0:x(B,c,Pe)}),e.jsxs("div",{className:"flex items-center gap-2 px-4 pt-3 pb-1",children:[e.jsxs(Ks,{children:[e.jsx(Vs,{asChild:!0,children:e.jsx(ae,{variant:"ghost",size:"icon",className:"h-8 w-8",children:e.jsx(yl,{className:"h-4 w-4"})})}),e.jsxs(Xs,{align:"start",className:"w-48",children:[e.jsxs(jt,{onClick:l,children:[e.jsx(ls,{className:"mr-2 h-4 w-4"}),d("fileSharing.folderHeader.rename")]}),e.jsxs(jt,{disabled:!z,onClick:()=>_t(()=>k(!0)),children:[e.jsx(ys,{className:"mr-2 h-4 w-4"}),d("fileSharing.folderHeader.generateLink")]}),e.jsxs(jt,{onClick:()=>G.info(d("fileSharing.folderHeader.recentActivityComingSoon")),children:[e.jsx(Ss,{className:"mr-2 h-4 w-4"}),d("fileSharing.folderHeader.recentActivity")]}),e.jsxs(jt,{onClick:S,className:"text-destructive focus:text-destructive",children:[e.jsx(Ka,{className:"mr-2 h-4 w-4"}),d("fileSharing.folderHeader.deleteFolder")]})]})]}),f&&f.length>0?e.jsxs("div",{className:"flex items-center gap-1 text-sm overflow-hidden min-w-0",children:[f.map(B=>e.jsxs("span",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:()=>v==null?void 0:v(B.id),className:"text-muted-foreground hover:text-foreground transition-colors truncate max-w-[120px]",children:B.name}),e.jsx(js,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"})]},B.id)),e.jsx("h2",{className:"text-lg font-semibold text-foreground truncate",children:t})]}):e.jsx("h2",{className:"text-lg font-semibold text-foreground truncate",children:t}),e.jsx(ae,{variant:"ghost",size:"icon",className:"h-8 w-8",disabled:!z,onClick:()=>_t(()=>k(!0)),children:e.jsx(Zs,{className:"h-4 w-4"})}),h&&e.jsxs(ae,{variant:"ghost",size:"sm",className:"h-8 text-xs gap-1",onClick:h,children:[e.jsx(As,{className:"h-4 w-4"}),d("fileSharing.folderHeader.addSubfolder")]})]}),e.jsx(jn,{open:w,onOpenChange:k,folderName:t,shareBaseUrl:Se,initialIdentify:Ee,initialDefaultOrder:he,initialPresentationMode:te,initialDesignSettings:ie,initialPortfolioSettings:Be,initialPermissions:se,initialBranding:ut,initialWatermark:ve,initialHighRes:we,initialLowRes:Ue,initialHasPassword:Ne,initialExpiry:ce,initialFooterSocialStyle:Ge.footerSocialStyle,initialFooterSocialLinks:Ge.footerSocialLinks,initialFooterCustomLinks:Ge.footerCustomLinks,initialOgTitle:Qe.ogTitle,initialOgDescription:Qe.ogDescription,initialOgImageUrl:Qe.ogImageUrl||null,onLinkActivated:async B=>(A("fs_gallery_shared",{folder_name:t}),L(!0),Ye(B.identify),_e(B.defaultOrder),pe(B.watermark),ct(B.highRes),lt(B.lowRes),Xe(B.expiry),V(B.presentationMode),be(B.designSettings),gt(B.portfolioSettings),J({allowStarImages:B.allowStarImages,allowFlagImages:B.allowFlagImages,allowScribble:B.allowScribble,allowComments:B.allowComments,requireIdentityForActions:B.requireIdentityForActions,customBadges:B.customBadges,hiddenDefaultBadges:B.hiddenDefaultBadges}),tt({useSpecificBranding:B.useSpecificBranding,specificLogo:B.specificLogo,specificBackgroun
74d:B.specificBackground,specificFocusX:B.specificFocusX,specificFocusY:B.specificFocusY}),rt({footerSocialStyle:B.footerSocialStyle,footerSocialLinks:B.footerSocialLinks,footerCustomLinks:B.footerCustomLinks}),Ae({ogTitle:B.ogTitle??"",ogDescription:B.ogDescription??"",ogImageUrl:B.ogImageUrl??""}),Me.current=!1,B.password===""?Oe(!1):typeof B.password=="string"&&B.password.length>0&&Oe(!0),await at(B.identify,{...B,presentationMode:B.presentationMode,designSettings:B.designSettings,portfolioSettings:B.portfolioSettings,useSpecificBranding:B.useSpecificBranding,specificLogo:B.specificLogo,specificBackground:B.specificBackground,specificFocusX:B.specificFocusX,specificFocusY:B.specificFocusY,defaultOrder:B.defaultOrder,slug:B.slug},B.expiry,B.expiryTouched)),initialSlug:Te,onShareUrlChange:B=>{const c=B.split("/").pop()||Te;De(c),me(B)},folderImages:C,coverUrl:a,activeLinkId:$e}),e.jsx(hr,{open:qe,onOpenChange:it,shareUrl:xe,senderName:t,galleryName:t}),e.jsx(yr,{open:de,onOpenChange:oe})]})}function sa({open:t,onOpenChange:r,requiredTier:a,featureLabel:g,onUpgraded:o}){const{subscription:l,refreshSubscription:S,user:h}=Et(),[C,N]=s.useState(!1),f=l.interval||"monthly",v="eur",I=async()=>{var d,E;if(!a)return;const x=(E=(d=$s[a])==null?void 0:d[v])==null?void 0:E[f];if(!x){ks({title:"Upgrade unavailable",description:"Could not resolve plan price.",variant:"destructive"});return}N(!0);try{const{data:T,error:A}=await U.functions.invoke("change-subscription",{body:{newPriceId:x}});if(A)throw A;if(T!=null&&T.error)throw new Error(T.error);await S(),ks({title:`✅ ${a} unlocked`,description:`${g} is now available on your plan.`}),r(!1),o==null||o()}catch(T){Ba(T,{source:"UpgradeFsTierModal",action:"change_plan",newPriceId:x,userId:h==null?void 0:h.id,email:h==null?void 0:h.email,currentPlan:l.plan,currentInterval:l.interval,extra:{requiredTier:a,featureLabel:g}}),ks({title:"Upgrade failed",description:T instanceof Error?T.message:"Unknown error",variant:"destructive"})}finally{N(!1)}};return e.jsx(vt,{open:t,onOpenChange:r,children:e.jsxs(yt,{children:[e.jsxs(St,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-10 w-10 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx(ps,{className:"h-5 w-5 text-primary"})}),e.jsx(wt,{children:"Upgrade to unlock"})]}),e.jsxs(Pt,{className:"pt-2",children:[e.jsx("strong",{className:"text-foreground",children:g})," is available",a?e.jsxs(e.Fragment,{children:[" on the ",e.jsx("strong",{className:"text-foreground",children:a})," plan and above."]}):null,e.jsx("br",{}),"Upgrade now to save your changes and start using this feature immediately."]})]}),e.jsxs(Lt,{className:"gap-2 sm:gap-2",children:[e.jsx(ae,{variant:"ghost",onClick:()=>r(!1),disabled:C,children:"Keep current plan"}),e.jsxs(ae,{onClick:I,disabled:C||!a,children:[C?e.jsx(Rt,{className:"h-4 w-4 animate-spin mr-2"}):null,"Upgrade to ",a??"higher plan"]})]})]})})}const vn=["Small","Medium","Large","Studio"],yn={Small:["5 GB storage","Unlimited projects & folders"],Medium:["20 GB storage","Custom domain & slugs","Gallery + Presentation"],Large:["50 GB storage","All Medium features","Custom flags & filters"],Studio:["100 GB storage","Everything in Large","Best for agencies"]};function aa({open:t,onOpenChange:r,featureLabel:a,requiredTier:g,onUpgraded:o}){var re,le;const{subscription:l,refreshSubscription:S}=Et(),[h,C]=s.useState(null),[N,f]=s.useState(!1),v=(re=l.standaloneFileSharing)==null?void 0:re.tier,I=v?as[v]:0,x=g?as[g]:I+1,d=l.interval||"monthly",E="eur",T=((le=l.standaloneFileSharing)==null?void 0:le.trialEnd)??null,A=s.useMemo(()=>{if(!T)return null;try{return new Date(T).toLocaleDateString(void 0,{month:"short",day:"numeric"})}catch{return null}},[T]),H=vn.filter(de=>as[de]>=x&&as[de]>I),Q=async()=>{var oe,ee;if(!h)return;const de=(ee=(oe=$s[h])==null?void 0:oe[E])==null?void 0:ee[d];if(!de){G.error("Could not resolve plan price");return}f(!0);try{const{data:W,error:w}=await U.functions.invoke("upgrade-fs-trial-tier",{body:{newPriceId:de}});if(w)throw w;if(W!=null&&W.error)throw new Error(W.error);await S(),G.success(A?`Trial upgraded to ${h} — you'll be charged when your trial ends on ${A}.`:`Trial upgraded to ${h}.`),r(!1),o==null||o()}catch(W){G.error((W==null?void 0:W.message)||"Failed to upgrade trial tier")}finally{f(!1)}};return e.jsx(vt,{open:t,onOpenChange:r,children:e.jsxs(yt,{className:"max-w-2xl",children:[e.jsxs(St,{children:[e.jsx("div",{className:"mx-auto mb-3 flex h-12 w-12 items-center justify-center rounded-full bg-primary/10",children:e.jsx(Dt,{className:"h-6 w-6 text-primary"})}),e.jsx(wt,{className:"text-center",children:"Upgrade your trial tier"}),e.jsxs(Pt,{className:"text-center pt-1",children:[a?e.jsxs(e.Fragment,{children:[e.jsx("strong",{className:"text-foreground",children:a})," requires a higher tier."," "]}):null,"Pick a higher tier to keep using your 7-day free trial — you won't be charged until it ends",A?` on ${A}`:"","."]})]}),H.length===0?e.jsx("div",{className:"text-center text-sm text-muted-foreground py-6",children:"You're already on the highest tier."}):e.jsx("div",{className:"grid gap-3 sm:grid-cols-2 my-2",children:H.map(de=>{const oe=h===de;return e.jsxs("button",{onClick:()=>C(de),disabled:N,className:`text-left rounded-lg border p-4 transition-colors ${oe?"border-primary bg-primary/5 ring-2 ring-primary":"border-border hover:border-primary/40"}`,children:[e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsx("div",{className:"font-semibold",children:de}),oe?e.jsx("div",{className:"h-5 w-5 rounded-full bg-primary text-primary-foreground flex items-center justify-center",children:e.jsx(Ls,{className:"h-3 w-3"})}):null]}),e.jsx("ul",{className:"text-xs text-muted-foreground space-y-1",children:yn[de].map(ee=>e.jsxs("li",{children:["• ",ee]},ee))})]},de)})}),e.jsxs("div",{className:"flex flex-col-reverse sm:flex-row sm:justify-end gap-2 mt-2",children:[e.jsxs(ae,{variant:"ghost",onClick:()=>r(!1),disabled:N,children:["Stay on ",v??"current tier"]}),e.jsxs(ae,{onClick:Q,disabled:N||!h||H.length===0,children:[N?e.jsx(Rt,{className:"h-4 w-4 mr-2 animate-spin"}):null,"Continue trial on ",h??"…"]})]})]})})}const gr=s.createContext(null);function Sn({children:t}){const r=ws();return e.jsx(gr.Provider,{value:r,children:t})}function ra(){const t=s.useContext(gr);return t||ws()}const wn=[{value:"yes",color:"hsl(142,71%,45%)"},{value:"no",color:"hsl(0,84%,60%)"},{value:"maybe",color:"hsl(48,96%,53%)"},{value:"final",color:"hsl(217,91%,60%)"}],Nn=[0,1,2,3,4,5],kn=[{value:"small-grid",icon:Tr,labelKey:"fileSharing.sharedGallery.smallGrid"},{value:"large-grid",icon:Xa,labelKey:"fileSharing.sharedGallery.largeGrid"},{value:"list",icon:bl,labelKey:"fileSharing.sharedGallery.listView"}];function _n({sortOrder:t,onSortChange:r,hasCustomOrder:a,viewMode:g,onViewModeChange:o,onSelectAll:l,onFilterChange:S,filterComments:h,onFilterCommentsChange:C,customBadges:N=[],hiddenDefaultBadges:f=[]}){const{t:v}=bt(),[I,x]=s.useState([]),[d,E]=s.useState([]),{canAccessFsFeature:T,getRequiredFsTierForFeature:A}=Gs(),H=T("fs_filter_feedback_by_person"),Q=A("fs_filter_feedback_by_person"),[re,le]=s.useState(!1),de=ra(),oe={yes:v("fileSharing.folderToolbar.flagYes"),no:v("fileSharing.folderToolbar.flagNo"),maybe:v("fileSharing.sharedGallery.maybe"),final:v("fileSharing.sharedGallery.final")},ee=s.useMemo(()=>{const k=wn.filter(L=>!f.includes(L.value)),y=N.map(L=>({value:`custom-${L.id}`,label:L.label,color:L.color}));return[...k.map(L=>({value:L.value,label:L.value,color:L.color})),...y]},[N,f]);s.useEffect(()=>{S==null||S({flags:I,ratings:d})},[I,d,S]);const W=k=>x(y=>y.includes(k)?y.filter(L=>L!==k):[...y,k]),w=k=>E(y=>y.includes(k)?y.filter(L=>L!==k):[...y,k]);return e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 md:gap-2 border-b border-border px-2 md:px-4 py-2",children:[e.jsxs(Wt,{value:t,onValueChange:r,children:[e.jsxs(Yt,{className:"h-8 w-[120px] md:w-[150px] text-xs",children:[e.jsx(La,{className:"mr-1 h-3 w-3"}),e.jsx(Kt,{})]}),e.jsxs(Vt,{children:[e.jsx(Ie,{value:"newest",children:v("fileSharing.folderToolbar.newestFirst")}),e.jsx(Ie,{value:"oldest",children:v("fileSharing.folderToolbar.oldestFirst")}),e.jsx(Ie,{value:"large",children:v("fileSharing.folderToolbar.largeFirst")}),e.jsx(Ie,{value:"small",children:v("fileSharing.folderToolbar.smallFirst")}),e.jsx(Ie,{value:"az",children:v("fileSharing.folderToolbar.filenameAZ")}),e.jsx(Ie,{value:"za",children:v("fileSharing.folderToolbar.filenameZA")}),a&&e.jsx(Ie,{value:"custom",children:v("fileSharing.folderToolbar.custom")})]})]}),e.jsxs(ma,{children:[e.jsx(ga,{asChild:!0,children:e.jsxs(ae,{variant:"outline",size:"sm",className:"h-8 text-xs gap-1",children:[e.jsx(Ga,{className:"h-3 w-3"}),e.jsx("span",{className:"hidden md:inline",children:I.length>0?v("fileSharing.folderToolbar.flagsCount",{count:I.length}):v("fileSharing.sharedGallery.allFlags")}),I.length>0&&e.jsx("span",{className:"md:hidden text-[10px]",children:I.length})]})}),e.jsxs(xa,{className:"w-40 p-2",align:"start",children:[e.jsxs("label",{className:"flex items-center gap-2 py-1 text-sm cursor-pointer font-medium",children:[e.jsx(At,{checked:I.length===0,onCheckedChange:()=>x([])}),v("fileSharing.sharedGallery.allFlags")]}),e.jsx("div",{className:"border-t border-border my-1"}),ee.map(k=>e.jsxs("label",{className:"flex items-center gap-2 py-1 text-sm cursor-pointer",children:[e.jsx(At,{checked:I.includes(k.value),onCheckedChange:()=>W(k.value)}),e.jsx("span",{className:"h-2.5 w-2.5 rounded-full shrink-0",style:{backgroundColor:k.color}}),oe[k.value]||k.label]},k.value))]})]}),e.jsxs(ma,{children:[e.jsx(ga,{asChild:!0,children:e.jsxs(ae,{variant:"outline",size:"sm",className:"h-8 text-xs gap-1",children:[e.jsx(pl,{className:"h-3 w-3"}),e.jsx("span",{className:"hidden md:inline",children:d.length>0?v("fileSharing.folderToolbar.ratingCount",{count:d.length}):v("fileSharing.sharedGallery.allRatings")}),d.length>0&&e.jsx("span",{className:"md:hidden text-[10px]",children:d.length})]})}),e.jsxs(xa,{className:"w-36 p-2",align:"start",children:[e.jsxs("label",{className:"flex items-center gap-2 py-1 text-sm cursor-pointer font-medium",children:[e.jsx(At,{checked:d.length===0,onCheckedChange:()=>E([])}),v("fileSharing.sharedGallery.allRatings")]}),e.jsx("div",{className:"border-t border-border my-1"}),Nn.map(k=>e.jsxs("label",{className:"flex items-center gap-2 py-1 text-sm cursor-pointer",children:[e.jsx(At,{checked:d.includes(k),onCheckedChange:()=>w(k)}),k===0?v("fileSharing.sharedGallery.noRating"):k===1?v("fileSharing.sharedGallery.starCount",{count:k}):v("fileSharing.sharedGallery.starsCount",{count:k})]},k))]})]}),C&&e.jsxs(ae,{variant:h?"secondary":"outline",size:"sm",className:"h-8 text-xs gap-1",onClick:()=>C(!h),children:[e.jsx(Qs,{className:"h-3 w-3"}),e.jsx("span",{className:"hidden md:inline",children:v("fileSharing.folderToolbar.comments")})]}),H?null:e.jsxs(ae,{variant:"outline",size:"sm",className:"h-8 text-xs gap-1 opacity-60",onClick:()=>le(!0),title:"Filter feedback by person",children:[e.jsx(jl,{className:"h-3 w-3"}),e.jsx("span",{className:"hidden md:inline",children:"Person"}),e.jsx(ps,{className:"h-3 w-3 ml-0.5"})]}),e.jsx("div",{className:"flex-1"}),l&&e.jsxs(ae,{variant:"outline",size:"sm",className:"h-8 text-xs gap-1",onClick:l,children:[e.jsx(Er,{className:"h-3 w-3"}),e.jsx("span",{className:"hidden md:inline",children:v("fileSharing.sharedGallery.selectAll")})]}),e.jsx("div",{className:"flex items-center rounded-md border border-border",children:kn.map(({value:k,icon:y,labelKey:L})=>e.jsx("button",{title:v(L),onClick:()=>o(k),className:Ve("flex items-center justify-center h-8 w-8 transition-colors",g===k?"bg-accent text-accent-foreground":"text-muted-foreground hover:text-foreground hover:bg-muted"),children:e.jsx(y,{className:"h-3.5 w-3.5"})},k))}),de.isTrialing?e.jsx(aa,{open:re,onOpenChange:le,requiredTier:Q,featureLabel:"Filter feedback by person"}):e.jsx(sa,{open:re,onOpenChange:le,requiredTier:Q,featureLabel:"Filter feedback by person"})]})}function Cn(){return"f-"+crypto.randomUUID().slice(0,12)}async function Fn(t){const r=new TextEncoder,a=await crypto.subtle.digest("SHA-256",r.encode(t));return Array.from(new Uint8Array(a)).map(g=>g.toString(16).padStart(2,"0")).join("")}const _a=[{labelKey:"fileSharing.shareFileDialog.hours12",value:"12h",trialAllowed:!0},{labelKey:"fileSharing.shareFileDialog.days1",value:"1",trialAllowed:!1},{labelKey:"fileSharing.shareFileDialog.days7",value:"7",trialAllowed:!1},{labelKey:"fileSharing.shareFileDialog.days14",value:"14",trialAllowed:!1},{labelKey:"fileSharing.shareFileDialog.days30",value:"30",trialAllowed:!1},{labelKey:"fileSharing.shareFileDialog.days90",value:"90",trialAllowed:!1},{labelKey:"fileSharing.shareFileDialog.never",value:"never",trialAllowed:!1}];function In({open:t,onOpenChange:r,file:a,projectId:g,onShareCreated:o}){const{t:l}=bt(),{user:S}=Et(),{isShareCapped:h}=ws(),[C,N]=s.useState(""),[f,v]=s.useState(!1),[I,x]=s.useState(""),[d,E]=s.useState("14"),[T,A]=s.useState(!0),[H,Q]=s.useState(!1),[re,le]=s.useState(!1),[de,oe]=s.useState(!1);s.useEffect(()=>{if(t&&(N(Cn()),v(!1),x(""),E(h?"12h":"14"),A(!0),h&&typeof window<"u")){const w="vsble.trialShareLimit.seen";sessionStorage.getItem(w)||(oe(!0),sessionStorage.setItem(w,"1"))}},[t,h]);const ee=`${window.location.origin}/share/file/${C}`,W=s.useCallback(async()=>
74{if(S){Q(!0);try{const w=f&&I?await Fn(I):null,k=d==="never"?null:d==="12h"?new Date(Date.now()+12*36e5).toISOString():new Date(Date.now()+parseInt(d)*864e5).toISOString(),y=await Ta(U,C,{kind:"file"});let L=y.slug,Ee=!1;for(let Ye=0;Ye<3;Ye++){const{error:$e}=await U.from("fs_file_shares").insert({file_id:a.id,project_id:g,user_id:S.id,slug:L,password_hash:w,expires_at:k,use_global_branding:T});if(!$e){Ee=!0;break}if($e.code!=="23505")throw $e;L=os(y.slug)}if(!Ee){G.error(l("fileSharing.folderHeader.slugTaken"));return}L!==C&&N(L),o(a.id,L),await navigator.clipboard.writeText(`${window.location.origin}/share/file/${L}`),G.success(l("fileSharing.shareFileDialog.linkCopied")),r(!1)}catch(w){G.error(l("fileSharing.shareFileDialog.failedCreateLink")),console.error(w)}finally{Q(!1)}}},[S,a,g,C,f,I,d,T,ee,o,r,l]);return e.jsxs(vt,{open:t,onOpenChange:r,children:[e.jsxs(yt,{className:"max-w-[420px] gap-5",children:[e.jsx(St,{children:e.jsx(wt,{className:"text-base",children:l("fileSharing.shareFileDialog.shareFile")})}),e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-border bg-muted/30 px-3 py-2",children:[e.jsx("span",{className:"flex-1 text-xs text-muted-foreground truncate",children:ee}),e.jsx("button",{className:"rounded p-1 hover:bg-accent text-muted-foreground hover:text-foreground",onClick:()=>{navigator.clipboard.writeText(ee),G.success(l("fileSharing.shareFileDialog.linkCopied"))},children:e.jsx(qs,{className:"h-3.5 w-3.5"})}),e.jsx("a",{href:`mailto:?subject=${encodeURIComponent(a.name)}&body=${encodeURIComponent(ee)}`,className:"rounded p-1 hover:bg-accent text-muted-foreground hover:text-foreground",children:e.jsx(Us,{className:"h-3.5 w-3.5"})}),e.jsx("a",{href:ee,target:"_blank",rel:"noopener noreferrer",className:"rounded p-1 hover:bg-accent text-muted-foreground hover:text-foreground",children:e.jsx(Ja,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(We,{className:"flex items-center gap-2 text-sm",children:[e.jsx(ps,{className:"h-3.5 w-3.5"})," ",l("fileSharing.shareFileDialog.password")]}),e.jsx(zt,{checked:f,onCheckedChange:v})]}),f&&e.jsx(ht,{type:"password",placeholder:l("fileSharing.shareDialog.enterPassword"),value:I,onChange:w=>x(w.target.value),className:"h-8 text-sm"})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(We,{className:"flex items-center gap-2 text-sm",children:[e.jsx(Ss,{className:"h-3.5 w-3.5"})," ",l("fileSharing.shareFileDialog.expiration")]}),e.jsxs(Wt,{value:d,onValueChange:w=>{const k=_a.find(y=>y.value===w);if(h&&k&&!k.trialAllowed){le(!0);return}E(w)},children:[e.jsx(Yt,{className:"w-[140px] h-8 text-sm",children:e.jsx(Kt,{})}),e.jsx(Vt,{children:_a.map(w=>{const k=h&&!w.trialAllowed;return e.jsx(Ie,{value:w.value,className:k?"text-muted-foreground":"",children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[l(w.labelKey),k&&e.jsx(Dt,{className:"h-3 w-3"})]})},w.value)})})]})]}),h&&e.jsxs("p",{className:"text-xs text-muted-foreground -mt-2 flex items-center gap-1.5",children:[e.jsx(Dt,{className:"h-3 w-3"}),"Free demo: links expire after 12 hours."]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(We,{className:"flex items-center gap-2 text-sm",children:[e.jsx(zs,{className:"h-3.5 w-3.5"})," ",l("fileSharing.shareFileDialog.globalBranding")]}),e.jsx(zt,{checked:T,onCheckedChange:A})]}),!T&&e.jsxs("p",{className:"text-xs text-muted-foreground flex items-start gap-1.5",children:[e.jsx(Va,{className:"h-3.5 w-3.5 shrink-0 mt-0.5"}),l("fileSharing.shareFileDialog.globalBrandingDesc")]})]}),e.jsx(ae,{onClick:W,disabled:H,className:"w-full",children:l("fileSharing.shareFileDialog.createShareLink")})]}),e.jsx(ta,{open:re,onOpenChange:le,reason:"share_duration"}),e.jsx(mr,{open:de,onOpenChange:oe})]})}function Dn({node:t,onSelect:r}){const{setNodeRef:a,isOver:g}=Hs({id:`subfolder-drop-${t.id}`,data:{type:"folder",folderId:t.id}}),{attributes:o,listeners:l,setNodeRef:S,isDragging:h}=za({id:`subfolder-drag-${t.id}`,data:{type:"tree-item",node:t}}),C=N=>{a(N),S(N)};return e.jsx("button",{ref:C,onClick:()=>!h&&r(t.id),className:Ve("shrink-0 w-[140px] h-[90px] rounded-lg border border-border overflow-hidden relative cursor-pointer hover:ring-1 hover:ring-primary/40 transition-all",t.coverUrl?"":"bg-muted/30 flex flex-col items-center justify-center gap-1.5",g&&!h&&"ring-2 ring-primary bg-primary/10 border-primary",h&&"opacity-40 scale-95"),...o,...l,children:t.coverUrl?e.jsxs(e.Fragment,{children:[e.jsx("img",{src:t.coverUrl,alt:t.name,className:"absolute inset-0 w-full h-full object-cover pointer-events-none",style:{objectPosition:`${t.coverFocusX??50}% ${t.coverFocusY??50}%`},draggable:!1}),e.jsx("div",{className:"absolute inset-x-0 bottom-0 bg-background/70 px-2 py-1 pointer-events-none",children:e.jsx("span",{className:"text-xs text-foreground truncate block",children:t.name})})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ht,{className:"h-7 w-7 text-muted-foreground pointer-events-none"}),e.jsx("span",{className:"text-xs text-foreground truncate max-w-[120px] px-1 pointer-events-none",children:t.name})]})})}function Rn({file:t,onDeleteFile:r,setCoverDialogFile:a,setFolderCoverDialogFile:g,size:o,selected:l,onToggleSelect:S,stars:h,flag:C,onSetStars:N,onSetFlag:f,onOpenDetail:v,customBadges:I,hiddenDefaultBadges:x,isShared:d,onShareFile:E,onUnshareFile:T,externalId:A}){const{t:H}=bt(),Q=h>0||C!=="none"||!!l;return e.jsx(Aa,{id:t.id,children:e.jsxs("div",{className:"group relative aspect-square rounded-lg overflow-hidden border border-border bg-muted cursor-pointer",onClick:v,children:[Ma(t)?e.jsxs("div",{className:Ve("relative h-full w-full bg-muted",t.uploading&&"opacity-50"),children:[us(t)?e.jsx(fs,{src:Gt(t,"small"),alt:t.name,className:"h-full w-full object-contain"}):e.jsx("div",{className:"h-full w-full"}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx("div",{className:"rounded-full bg-[hsl(0,0%,0%)]/60 p-2",children:e.jsx(Za,{className:"h-6 w-6 text-[hsl(0,0%,95%)] fill-[hsl(0,0%,95%)]"})})})]}):us(t)?e.jsx(fs,{src:Gt(t,"small"),alt:t.name,className:Ve("h-full w-full object-contain",t.uploading&&"opacity-50")}):e.jsx(Ua,{fileName:t.name,className:Ve(t.uploading&&"opacity-50")}),t.uploading&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx("div",{className:"w-3/4",children:e.jsx(Ys,{value:t.uploadProgress??0,className:"h-1.5"})})}),e.jsxs("div",{className:Ve("absolute top-1.5 right-1.5 flex gap-1 transition-opacity",Q?"opacity-100":"md:opacity-0 md:group-hover:opacity-100"),children:[e.jsx(Ha,{stars:h,onSetStars:N}),e.jsx(Wa,{flag:C,onSetFlag:f,customBadges:I,hiddenDefaultBadges:x}),e.jsx("button",{className:"rounded-full bg-background/80 p-1 hover:bg-accent",onClick:re=>{re.stopPropagation(),v==null||v()},children:e.jsx(Qs,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:Ve("absolute bottom-6 inset-x-1.5 flex items-center justify-between transition-opacity",Q?"opacity-100":"md:opacity-0 md:group-hover:opacity-100"),children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(At,{className:"h-4 w-4 border-background/80 bg-background/80",checked:!!l,onCheckedChange:()=>S==null?void 0:S(t.id),onClick:re=>re.stopPropagation()}),e.jsx("button",{className:"rounded-full bg-background/80 p-1 hover:bg-accent",onClick:async re=>{re.stopPropagation();try{const le=hs(t.url);await Ws(A,t.name,le)}catch{}},children:e.jsx(Js,{className:"h-3.5 w-3.5"})})]}),e.jsxs(Ks,{children:[e.jsx(Vs,{asChild:!0,children:e.jsx("button",{className:"rounded-full bg-background/80 p-1 hover:bg-accent",children:e.jsx(Qa,{className:"h-3.5 w-3.5"})})}),e.jsxs(Xs,{align:"end",className:"w-44",children:[e.jsx(jt,{disabled:!$t(t),onClick:()=>g(t),children:H("fileSharing.workArea.setFolderCover")}),e.jsx(jt,{disabled:!$t(t),onClick:()=>a(t),children:H("fileSharing.workArea.setProjectCover")}),e.jsx(jt,{children:H("fileSharing.workArea.editFilename")}
74),d?e.jsxs(jt,{onClick:T,className:"gap-2",children:[e.jsx(ea,{className:"h-3.5 w-3.5"})," Link shared"]}):e.jsxs(jt,{onClick:E,className:"gap-2",children:[e.jsx(Zs,{className:"h-3.5 w-3.5"})," Share this file"]}),e.jsx(jt,{className:"text-destructive",onClick:()=>r(t.id),children:"Delete"})]})]})]}),e.jsx("div",{className:"absolute bottom-0 inset-x-0 bg-background/80 px-2 py-1 text-xs text-foreground truncate",children:t.name})]})})}function En({file:t,onDeleteFile:r,setCoverDialogFile:a,setFolderCoverDialogFile:g,selected:o,onToggleSelect:l,stars:S,flag:h,onSetStars:C,onSetFlag:N,onOpenDetail:f,customBadges:v,hiddenDefaultBadges:I,isShared:x,onShareFile:d,onUnshareFile:E,externalId:T}){const{t:A}=bt(),H=t.size?t.size>1024*1024?`${(t.size/(1024*1024)).toFixed(1)} MB`:`${Math.round(t.size/1024)} KB`:"";return e.jsx(Aa,{id:t.id,children:e.jsxs("div",{className:"flex items-center gap-4 rounded-lg border border-border bg-muted/30 p-2 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"relative shrink-0 w-[80px] h-[80px] md:w-[120px] md:h-[120px] rounded-md overflow-hidden border border-border bg-muted cursor-pointer",onClick:f,children:[Ma(t)?e.jsxs("div",{className:Ve("relative h-full w-full bg-muted",t.uploading&&"opacity-50"),children:[us(t)?e.jsx(fs,{src:Gt(t,"small"),alt:t.name,className:"h-full w-full object-contain"}):e.jsx("div",{className:"h-full w-full"}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx("div",{className:"rounded-full bg-[hsl(0,0%,0%)]/60 p-2",children:e.jsx(Za,{className:"h-6 w-6 text-[hsl(0,0%,95%)] fill-[hsl(0,0%,95%)]"})})})]}):us(t)?e.jsx(fs,{src:Gt(t,"small"),alt:t.name,className:Ve("h-full w-full object-contain",t.uploading&&"opacity-50")}):e.jsx(Ua,{fileName:t.name,className:Ve(t.uploading&&"opacity-50")}),t.uploading&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx("div",{className:"w-3/4",children:e.jsx(Ys,{value:t.uploadProgress??0,className:"h-1.5"})})})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-foreground truncate",children:t.name}),e.jsx("div",{className:"flex items-center gap-3 mt-1 text-xs text-muted-foreground",children:H&&e.jsx("span",{children:H})})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx(At,{className:"h-4 w-4 mr-2",checked:!!o,onCheckedChange:()=>l==null?void 0:l(t.id),onClick:Q=>Q.stopPropagation()}),e.jsx(Ha,{stars:S,onSetStars:C}),e.jsx(Wa,{flag:h,onSetFlag:N,customBadges:v,hiddenDefaultBadges:I}),e.jsx("button",{className:"rounded-full p-1.5 hover:bg-accent text-muted-foreground hover:text-foreground",onClick:()=>f==null?void 0:f(),children:e.jsx(Qs,{className:"h-4 w-4"})}),e.jsx("button",{className:"rounded-full p-1.5 hover:bg-accent text-muted-foreground hover:text-foreground",onClick:async()=>{try{const Q=hs(t.url);await Ws(T,t.name,Q)}catch{}},children:e.jsx(Js,{className:"h-4 w-4"})}),e.jsxs(Ks,{children:[e.jsx(Vs,{asChild:!0,children:e.jsx("button",{className:"rounded-full p-1.5 hover:bg-accent text-muted-foreground hover:text-foreground",children:e.jsx(Qa,{className:"h-4 w-4"})})}),e.jsxs(Xs,{align:"end",className:"w-44",children:[e.jsx(jt,{disabled:!$t(t),onClick:()=>g(t),children:A("fileSharing.workArea.setFolderCover")}),e.jsx(jt,{disabled:!$t(t),onClick:()=>a(t),children:A("fileSharing.workArea.setProjectCover")}),e.jsx(jt,{children:A("fileSharing.workArea.editFilename")}),x?e.jsxs(jt,{onClick:E,className:"gap-2",children:[e.jsx(ea,{className:"h-3.5 w-3.5"})," Link shared"]}):e.jsxs(jt,{onClick:d,className:"gap-2",children:[e.jsx(Zs,{className:"h-3.5 w-3.5"})," Share this file"]}),e.jsx(jt,{className:"text-destructive",onClick:()=>r(t.id),children:"Delete"})]})]})]})]})})}function Ca({selectedNode:t,nodes:r,sortedFiles:a,onAddProject:g,onAddSubfolder:o,onRenameNode:l,onDeleteNode:S,onAddFiles:h,onDeleteFile:C,onSetProjectCover:N,onSetFolderCover:f,onSelect:v,sortOrder:I,onSortChange:x,hasCustomOrder:d,hasUnsavedCustomOrder:E,onSaveCustomOrder:T,isSidebarCollapsed:A,onExpandSidebar:H,getProjectRoot:Q,selectedIds:re,setSelectedIds:le,onRenameFiles:de,pendingDetailFileId:oe,onClearPendingDetail:ee,filesLoading:W}){const{t:w}=bt(),{user:k}
74=Et(),y=Oa(),L=vs(),Ee=`share_${k.id}`,[Ye,$e]=s.useState(!1),[mt,Te]=s.useState(!1),[De,Y]=s.useState(!0),[z,ue]=s.useState(!1),[Me,Se]=s.useState(null),[X,xe]=s.useState(null),[me,te]=s.useState("small-grid"),[V,ie]=s.useState({flags:[],ratings:[]}),[be,Be]=s.useState(!1),[gt,se]=s.useState(new Set),[J,he]=s.useState(null),[_e,ve]=s.useState(!1),[pe,we]=s.useState(!1),[ct,Ue]=s.useState(null),[lt,Ne]=s.useState(null),[Oe,ce]=s.useState({}),{canAccessFsFeature:Xe,getRequiredFsTierForFeature:Ge}=Gs(),rt=ra(),[Qe,Ae]=s.useState(!1),[qe,it]=s.useState(null),[et,_t]=s.useState(""),ut=s.useCallback((u,M)=>{it(Ge(u)),_t(M),Ae(!0)},[Ge]),tt=t?Q(t.id):null,fe=$a();s.useEffect(()=>{oe&&t&&(he(oe),ee==null||ee())},[oe,t,ee]);const[Ct,nt]=s.useState(null);s.useEffect(()=>{if(!tt){nt(null);return}U.from("fs_share_links").select("slug").eq("project_id",tt).eq("is_active",!0).order("created_at",{ascending:!1}).limit(1).maybeSingle().then(({data:u})=>nt((u==null?void 0:u.slug)??null))},[tt]);const[st,at]=s.useState(fe);s.useEffect(()=>{if(!tt){at(fe);return}(async()=>{var P,q;const{data:u}=await U.from("fs_share_links").select("share_config").eq("project_id",tt).eq("is_active",!0).order("created_at",{ascending:!1}).limit(1).maybeSingle(),M=(u==null?void 0:u.share_config)||{};if((P=M.customBadges)!=null&&P.length||(q=M.hiddenDefaultBadges)!=null&&q.length){const ke=M.customBadges||[],Fe=new Set((fe.badges||[]).map(m=>m.id)),Ft=[...fe.badges||[]];for(const m of ke)Fe.has(m.id)||Ft.push(m);const i=M.hiddenDefaultBadges||fe.hiddenDefaultBadges||[];at({badges:Ft,hiddenDefaultBadges:i})}else at(fe)})()},[tt,fe]),s.useEffect(()=>{k&&U.from("fs_file_shares").select("file_id, slug").eq("user_id",k.id).eq("is_active",!0).then(({data:u})=>{if(u){const M={};u.forEach(P=>{M[P.file_id]=P.slug}),ce(M)}})},[k]);const xt=s.useCallback(async u=>{Oe[u]&&(await U.from("fs_file_shares").update({is_active:!1}).eq("file_id",u),ce(P=>{const q={...P};return delete q[u],q}),G.success(w("fileSharing.workArea.shareLinkRemoved")))},[Oe]),B=s.useCallback((u,M)=>{ce(P=>({...P,[u]:M})),L("fs_share_link_created",{file_id:u})},[L]);s.useEffect(()=>{tt&&U.from("fs_file_comments").select("file_id").eq("project_id",tt).then(({data:u})=>{u&&se(new Set(u.map(M=>M.file_id)))})},[tt]);const{annotations:c,setStars:Pe,setFlag:ft}=Br({projectId:tt,fetchAll:!0}),Ce=s.useRef(0),Nt=s.useRef(null),Ke=t?r.filter(u=>u.parentId===t.id):[],ot=s.useMemo(()=>a.filter(u=>{const M=c[u.id],P=(M==null?void 0:M.stars)??0,q=(M==null?void 0:M.flag)??"none";return!(V.flags.length>0&&!V.flags.includes(q)||V.ratings.length>0&&!V.ratings.includes(P)||be&&!gt.has(u.id))}),[a,c,V,be,gt]),ze=s.useCallback(u=>{if(!u||!t)return;const M=Array.from(u);M.length&&h(t.id,M)},[t,h]),Tt=s.useCallback(u=>{u.preventDefault(),Ce.current++,ue(!0)},[]),ge=s.useCallback(u=>{u.preventDefault(),Ce.current--,Ce.current===0&&ue(!1)},[]),ne=s.useCallback(u=>{u.preventDefault()},[]),ye=s.useCallback(u=>{u.preventDefault(),Ce.current=0,ue(!1),ze(u.dataTransfer.files)},[ze]);if(!t){const u=r.filter(P=>P.parentId===null);if(u.length===0)return e.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-4 bg-background relative",children:[A&&H&&e.jsx(ae,{variant:"ghost",size:"icon",className:"absolute top-3 left-3 h-8 w-8",onClick:H,title:w("fileSharing.workArea.expandSidebar"),children:e.jsx(Fs,{className:"h-4 w-4"})}),e.jsx(As,{className:"h-12 w-12 text-muted-foreground"}),e.jsx("h2",{className:"text-lg font-semibold text-foreground",children:w("fileSharing.workArea.createFirstProject")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:w("fileSharing.workArea.startSharing")}),e.jsxs(ae,{onClick:()=>$e(!0),children:[e.jsx(As,{className:"mr-2 h-4 w-4"}),w("fileSharing.workArea.createProject")]}),e.jsx(is,{open:Ye,onOpenChange:$e,onCreateProject:g})]});const M=P=>r.filter(ke=>ke.parentId===P).flatMap(ke=>[ke.id,...M(ke.id)]);return e.jsxs("div",{className:"flex flex-1 flex-col overflow-y-auto bg-background relative h-full min-h-0",children:[A&&H&&e.jsx(ae,{variant:"ghost",size:"icon",className:"absolute top-3 left-3 z-10 h-8 w-8",onClick:H,title:w("fileSharing.workArea.expandSidebar"),children:e.jsx(Fs,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex items-center justify-between px-6 pt-6 pb-2",children:[e.jsx("h2",{className:"text-xl font-semibold text-foreground",children:w("fileSharing.workArea.yourProjects")}),e.jsxs(ae,{size:"sm",onClick:()=>$e(!0),children:[e.jsx(bs,{className:"mr-1.5 h-4 w-4"}),w("fileSharing.workArea.newWebsite")]})]}),e.jsx("div",{className:"px-6 pb-6 grid gap-5",style:{gridTemplateColumns:"repeat(auto-fill, minmax(280px, 1fr))"},children:u.map(P=>{const q=M(P.id),ke=r.filter(i=>i.parentId===P.id).length,Ft=[P.id,...q].reduce((i,m)=>{var b;return i+(((b=r.find(n=>n.id===m))==null?void 0:b.imageCount)??0)},0);return e.jsxs("button",{onClick:()=>v(P.id),className:"group text-left rounded-xl border border-border bg-card overflow-hidden hover:ring-1 hover:ring-primary/40 hover:shadow-md transition-all cursor-pointer",children:[e.jsx("div",{className:"aspect-[3/2] max-h-[220px] w-full overflow-hidden bg-muted relative",children:P.coverUrl?e.jsx("img",{src:P.coverUrl,alt:P.name,className:"h-full w-full object-cover transition-transform duration-300 group-hover:scale-[1.03]",style:{objectPosition:`${P.coverFocusX??50}% ${P.coverFocusY??50}%`},draggable:!1}):e.jsx("div",{className:"h-full w-full flex items-center justify-center",children:e.jsx(Ht,{className:"h-10 w-10 text-muted-foreground
74/50"})})}),e.jsxs("div",{className:"px-3.5 py-3 space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-foreground truncate",children:P.name}),e.jsxs("div",{className:"flex items-center gap-3 text-xs text-muted-foreground",children:[ke>0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Ht,{className:"h-3 w-3"}),ke]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Bs,{className:"h-3 w-3"}),Ft]}),P.createdAt&&e.jsx("span",{className:"ml-auto",children:nl(P.createdAt)})]})]})]},P.id)})}),e.jsx(is,{open:Ye,onOpenChange:$e,onCreateProject:g})]})}const Re=me==="small-grid"?y?140:190:y?170:260;return e.jsxs("div",{className:"flex flex-1 flex-col overflow-y-auto bg-background relative h-full min-h-0",onDragEnter:Tt,onDragLeave:ge,onDragOver:ne,onDrop:ye,children:[A&&H&&e.jsx(ae,{variant:"ghost",size:"icon",className:"absolute top-3 left-3 z-10 h-8 w-8",onClick:H,title:w("fileSharing.workArea.expandSidebar"),children:e.jsx(Fs,{className:"h-4 w-4"})}),e.jsx(bn,{name:t.name,nodeId:t.id,coverUrl:t.coverUrl,coverFocusX:t.coverFocusX,coverFocusY:t.coverFocusY,onRename:()=>{const u=prompt("Rename folder:",t.name);u!=null&&u.trim()&&l(t.id,u.trim())},onDelete:()=>S(t.id),onAddSubfolder:()=>Te(!0),folderImages:a.map(u=>u.url),allNodes:r,ancestors:(()=>{const u=[];let M=r.find(P=>P.id===t.parentId);for(;M;)u.unshift({id:M.id,name:M.name}),M=r.find(P=>P.id===M.parentId);return u})(),onNavigate:v,folderFiles:a,onSaveCover:(u,M,P)=>{f(t.id,u,M,P);const q=Q(t.id);N(q,u,M,P)}},t.id),Ke.length>0&&e.jsxs("div",{className:"px-4 pt-4 pb-1 space-y-2",children:[e.jsxs("button",{onClick:()=>Y(u=>!u),className:"flex items-center gap-1 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground hover:text-foreground transition-colors",children:[De?e.jsx(Ms,{className:"h-3 w-3"}):e.jsx(js,{className:"h-3 w-3"}),"Subfolders"]}),De&&e.jsx("div",{className:"flex gap-3 overflow-x-auto pb-2 pt-px -mt-px px-px -mx-px",children:Ke.map(u=>e.jsx(Dn,{node:u,onSelect:v},u.id))})]}),e.jsx(_n,{sortOrder:I,onSortChange:x,hasCustomOrder:d,viewMode:me,onViewModeChange:te,onSelectAll:()=>le(new Set(ot.map(u=>u.id))),onFilterChange:ie,filterComments:be,onFilterCommentsChange:Be,customBadges:st.badges,hiddenDefaultBadges:st.hiddenDefaultBadges}),e.jsx("input",{ref:Nt,type:"file",multiple:!0,className:"hidden",onChange:u=>{ze(u.target.files),u.target.value=""}}),z&&e.jsx("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-primary/10 border-2 border-dashed border-primary rounded-xl pointer-events-none",children:e.jsx("p",{className:"text-lg font-semibold text-primary",children:w("fileSharing.workArea.dropImagesHere")})}),(()=>{if(W&&ot.length===0){const u=me==="list"?6:8;return e.jsx("div",{className:"flex-1 p-4 space-y-4",children:me==="list"?e.jsx("div",{className:"flex flex-col gap-2",children:Array.from({length:u}).map((M,P)=>e.jsx("div",{className:"h-14 rounded-lg bg-muted/40 animate-pulse"},P))}):e.jsx("div",{className:"grid gap-3",style:{gridTemplateColumns:`repeat(auto-fill, minmax(${Re}px, 1fr))`},children:Array.from({length:u}).map((M,P)=>e.jsx("div",{className:"aspect-square rounded-lg bg-muted/40 animate-pulse"},P))})})}return ot.length>0?e.jsxs("div",{className:"flex-1 p-4 space-y-4",children:[E&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ol,{variant:"secondary",className:"text-xs",children:w("fileSharing.workArea.customOrder")}),e.jsx(ae,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:T,children:"Save"})]}),e.jsx(Mr,{items:ot.map(u=>u.id),strategy:Ur,children:me==="list"?e.jsx("div",{className:"flex flex-col gap-2",children:ot.map(u=>{var M,P;return e.jsx(En,{file:u,onDeleteFile:C,setCoverDialogFile:Se,setFolderCoverDialogFile:xe,selected:re.has(u.id),onToggleSelect:q=>le(ke=>{const Fe=new Set(ke);return Fe.has(q)?Fe.delete(q):Fe.add(q),Fe}),stars:((M=c[u.id])==null?void 0:M.stars)??0,flag:((P=c[u.id])==null?void 0:P.flag)??"none",onSetStars:q=>Pe(u.id,q),onSetFlag:q=>ft(u.id,q),onOpenDetail:()=>he(u.id),customBadges:st.badges,hiddenDefaultBadges:st.hiddenDefaultBadges,isShared:!!Oe[u.id],onShareFile:()=>Ne(u),onUnshareFile:()=>xt(u.id),externalId:Ee},u.id)})}):e.jsx("div",{className:"grid gap-3",style:{gridTemplateColumns:`repeat(auto-fill, minmax(${Re}px, 1fr))`},children:ot.map(u=>{var M,P;return e.jsx(Rn,{file:u,size:Re,onDeleteFile:C,setCoverDialogFile:Se,setFolderCoverDialogFile:xe,selected:re.has(u.id),onToggleSelect:q=>le(ke=>{const Fe=new Set(ke);return Fe.has(q)?Fe.delete(q):Fe.add(q),Fe}),stars:((M=c[u.id])==null?void 0:M.stars)??0,flag:((P=c[u.id])==null?void 0:P.flag)??"none",onSetStars:q=>Pe(u.id,q),onSetFlag:q=>ft(u.id,q),onOpenDetail:()=>he(u.id),customBadges:st.badges,hiddenDefaultBadges:st.hiddenDefaultBadges,isShared:!!Oe[u.id],onShareFile:()=>Ne(u),onUnshareFile:()=>xt(u.id),externalId:Ee},u.id)})})}),e.jsx("div",{className:"flex items-center justify-center",children:e.jsxs(ae,{variant:"outline",onClick:()=>{var u;return(u=Nt.current)==null?void 0:u.click()},children:[e.jsx(ms,{className:"mr-2 h-4 w-4"}),"Upload more images"]})})]}):e.jsx("div",{className:"flex-1 flex items-center justify-center p-8",children:e.jsxs("div",{className:"flex flex-col items-center gap-4 roun
74ded-xl border-2 border-dashed border-border p-12 text-center",children:[e.jsx(ms,{className:"h-10 w-10 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Drag & drop or upload new images"}),e.jsx(ae,{variant:"outline",onClick:()=>{var u;return(u=Nt.current)==null?void 0:u.click()},children:"Upload images"})]})})})(),e.jsx(is,{open:mt,onOpenChange:Te,onCreateProject:u=>o(t.id,u),mode:"folder"}),Me&&$t(Me)&&e.jsx(oa,{open:!!Me,onOpenChange:u=>{u||Se(null)},imageUrl:ds(Me)??"",onSave:(u,M,P)=>{N(t.id,u,M,P),Se(null)}}),X&&$t(X)&&e.jsx(oa,{open:!!X,onOpenChange:u=>{u||xe(null)},imageUrl:ds(X)??"",title:"Set Folder Cover",previewRatios:[{label:"Banner preview",ratio:"16/5"},{label:"Subfolder card preview",ratio:"140/90"}],onSave:(u,M,P)=>{f(t.id,u,M,P),xe(null)}}),e.jsx(Or,{selectedIds:Array.from(re),files:a.map(u=>({id:u.id,name:u.name,url:u.url,thumb500Url:u.thumb500Url})),onDeselect:u=>le(M=>{const P=new Set(M);return P.delete(u),P}),onClearAll:()=>le(new Set),isOwner:!0,customBadges:st.badges,hiddenDefaultBadges:st.hiddenDefaultBadges,onAction:async(u,M)=>{const P=a.filter(q=>re.has(q.id));if(P.length){if(u==="zip")if(P.length===1)try{const q=hs(P[0].url);await Ws(Ee,P[0].name,q)}catch(q){console.error("Download failed:",q),G.error(w("fileSharing.workArea.failedDownload"))}else{Ue(0);try{const q=P.map(ke=>({name:ke.name,key:hs(ke.url)}));await sl(Ee,(t==null?void 0:t.name)??"files",q),G.success(w("fileSharing.workArea.downloadStarted"))}catch(q){console.error("ZIP download failed:",q),G.error(w("fileSharing.workArea.failedCreateZip"))}finally{Ue(null)}}else if(u==="export-names")ve(!0);else if(u==="rename"){if(!Xe("fs_batch_rename")){ut("fs_batch_rename",w("fileSharing.bulkRename.title"));return}we(!0)}else if(u==="star"){const q=M;await Promise.all(P.map(ke=>Pe(ke.id,q))),G.success(w("fileSharing.workArea.bulkStarApplied",{rating:q,count:P.length}))}else if(u==="flag"){const q=M;await Promise.all(P.map(ke=>ft(ke.id,q))),G.success(w("fileSharing.workArea.bulkFlagApplied",{count:P.length}))}else if(u==="delete"){if(!confirm(`Delete ${P.length} files?`))return;for(const q of P)C(q.id);le(new Set),G.success(w("fileSharing.workArea.deletedFiles",{count:P.length}))}}}}),ct!==null&&e.jsx("div",{className:"fixed bottom-16 inset-x-0 z-50 flex justify-center pointer-events-none",children:e.jsxs("div",{className:"bg-[hsl(0,0%,10%)] border border-[hsl(0,0%,25%)] rounded-lg px-4 py-2 flex items-center gap-3 shadow-lg",children:[e.jsx("span",{className:"text-xs text-[hsl(0,0%,70%)]",children:"Creating ZIP…"}),e.jsx(Ys,{value:ct,className:"h-1.5 w-32"}),e.jsxs("span",{className:"text-xs text-[hsl(0,0%,70%)]",children:[ct,"%"]})]})}),e.jsx(Ar,{open:_e,onOpenChange:ve,filenames:a.filter(u=>re.has(u.id)).map(u=>u.name)}),e.jsx(ln,{open:pe,onOpenChange:we,files:a.filter(u=>re.has(u.id)).map(u=>({id:u.id,name:u.name})),onRenamed:u=>{de(u),le(new Set)}}),J&&t&&e.jsx(Pr,{open:!!J,onClose:()=>he(null),files:a,initialFileId:J,projectId:tt,annotations:c,onSetStars:(u,M)=>Pe(u,M),onSetFlag:(u,M)=>ft(u,M),isOwner:!0,customBadges:st.badges,hiddenDefaultBadges:st.hiddenDefaultBadges}),lt&&tt&&e.jsx(In,{open:!!lt,onOpenChange:u=>{u||Ne(null)},file:lt,projectId:tt,onShareCreated:B}),rt.isTrialing?e.jsx(aa,{open:Qe,onOpenChange:Ae,requiredTier:qe,featureLabel:et}):e.jsx(sa,{open:Qe,onOpenChange:Ae,requiredTier:qe,featureLabel:et})]})}const Tn=["Small","Medium","Large","Studio"],Bn={Small:["5 GB storage","Unlimited projects & folders"],Medium:["20 GB storage","Custom domain & slugs","Gallery + Presentation"],Large:["50 GB storage","All Medium features","Custom flags & filters"],Studio:["100 GB storage","Everything in Large","Best for agencies"]};function On({open:t,onOpenChange:r,onActivated:a}){const{subscription:g,refreshSubscription:o,user:l}=Et(),[S,h]=s.useState(null),[C,N]=s.useState(!1),f=g.interval||"monthly",v="eur",I=async()=>{var d,E;if(!S)return;const x=(E=(d=$s[S])==null?void 0:d[v])==null?void 0:E[f];if(!x){G.error("Could not resolve plan price");return}N(!0);try{const{data:T,error:A}=await U.functions.invoke("change-subscription",{body:{action:"change_standalone",newPriceId:x,product:"file_sharing"}});if(A)throw A;if(T!=null&&T.error)throw new Error(T.error);try{await U.functions.invoke("change-subscription",{body:{action:"activate_trial"}})}catch{}await o(),G.success(`✅ ${S} plan activated — uploads unlocked.`),r(!1),a==null||a()}catch(T){Ba(T,{source:"TrialUploadCapReachedModal",action:"change_standalone",newPriceId:x,userId:l==null?void 0:l.id,email:l==null?void 0:l.email,currentPlan:g.plan,currentInterval:g.interval,extra:{pickedTier:S,product:"file_sharing"}}),G.error((T==null?void 0:T.message)||"Failed to activate plan")}finally{N(!1)}};return e.jsx(vt,{open:t,onOpenChange:r,children:e.jsxs(yt,{className:"max-w-2xl",children:[e.jsxs(St,{children:[e.jsx("div",{className:"mx-auto mb-3 flex h-12 w-12 items-center justify-center rounded-full bg-primary/10",children:e.jsx(cs,{className:"h-6 w-6 text-primary"})}),e.jsx(wt,{className:"text-center",children:"Trial upload limit reached"}),e.jsxs(Pt,{className:"text-center pt-1",children:["Trial accounts can upload up to ",e.jsx("strong",{className:"text-foreground",children:"1 GB"}),". Activate a plan now to keep uploading — you'll be charged immediately and your trial will end."]})]}),e.jsx("div",{className:"grid gap-3 sm:grid-cols-2 my-2",children:T
74n.map(x=>{const d=S===x;return e.jsxs("button",{onClick:()=>h(x),disabled:C,className:`text-left rounded-lg border p-4 transition-colors ${d?"border-primary bg-primary/5 ring-2 ring-primary":"border-border hover:border-primary/40"}`,children:[e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsx("div",{className:"font-semibold",children:x}),d?e.jsx("div",{className:"h-5 w-5 rounded-full bg-primary text-primary-foreground flex items-center justify-center",children:e.jsx(Ls,{className:"h-3 w-3"})}):null]}),e.jsx("ul",{className:"text-xs text-muted-foreground space-y-1",children:Bn[x].map(E=>e.jsxs("li",{children:["• ",E]},E))})]},x)})}),e.jsxs("div",{className:"flex flex-col-reverse sm:flex-row sm:justify-end gap-2 mt-2",children:[e.jsx(ae,{variant:"ghost",onClick:()=>r(!1),disabled:C,children:"Cancel"}),e.jsxs(ae,{onClick:I,disabled:C||!S,children:[C?e.jsx(Rt,{className:"h-4 w-4 mr-2 animate-spin"}):null,"Activate ",S??"plan"," & continue"]})]})]})})}function An({open:t,onOpenChange:r,conflictNames:a,onResolve:g,onCancel:o}){const{t:l}=bt(),S=a.length;return e.jsx(vt,{open:t,onOpenChange:h=>{h||o(),r(h)},children:e.jsxs(yt,{className:"sm:max-w-md",children:[e.jsxs(St,{children:[e.jsx(wt,{children:l("fileSharing.duplicateUpload.title")}),e.jsx(Pt,{children:l("fileSharing.duplicateUpload.description",{count:S})})]}),e.jsx(Sr,{className:"max-h-48 rounded-md border bg-muted/30 p-3",children:e.jsx("ul",{className:"space-y-1 text-sm",children:a.map(h=>e.jsx("li",{className:"truncate text-foreground",children:h},h))})}),e.jsxs(Lt,{className:"flex-col gap-2 sm:flex-col sm:space-x-0",children:[e.jsx(ae,{type:"button",variant:"default",className:"w-full",onClick:()=>g("keep-both"),children:l("fileSharing.duplicateUpload.keepBoth")}),e.jsx(ae,{type:"button",variant:"outline",className:"w-full",onClick:()=>g("replace"),children:l("fileSharing.duplicateUpload.replace")}),e.jsx(ae,{type:"button",variant:"outline",className:"w-full",onClick:()=>g("skip"),children:l("fileSharing.duplicateUpload.skip")}),e.jsx(ae,{type:"button",variant:"ghost",className:"w-full",onClick:o,children:l("fileSharing.duplicateUpload.cancel")})]})]})})}const Pn=.18,Ln=t=>{const r=Kr(t);if(r.length>0)return r;const a=Vr(t);return a.length>0?a:Xr(t)};function Fa(t,r){if(!t)return"inside";const a=t.top,g=Math.max(t.bottom-t.top,1),o=Math.max(5,Math.min(8,g*Pn)),l=r-a;return l<=o?"above":l>=g-o?"below":"inside"}function Mn(){return e.jsx(Sn,{children:e.jsx(Un,{})})}function Un(){const{t}=bt(),{user:r}=Et(),a=Oa();ul();const g=vs(),{usedBytes:o,totalBytes:l,refreshStorage:S}=_l(),h=ra(),[C,N]=s.useState(!1),[f,v]=s.useState("generic"),I=s.useRef(null),[x,d]=s.useState(!1),[E,T]=s.useState(!1),[A,H]=s.useState(!1),[Q,re]=s.useState(!1),[le,de]=s.useState(0),[oe,ee]=s.useState(!1),[W,w]=s.useState(null),[k,y]=s.useState(null),{canAccessFsFeature:L,getRequiredFsTierForFeature:Ee}=Gs(),[Ye,$e]=s.useState(!1),[mt,Te]=s.useState(null),[De,Y]=s.useState(!1),[z,ue]=s.useState(null),Me=s.useCallback((i,m)=>{_e(i),y(m)},[]),Se=s.useCallback(()=>{if(a){T(m=>!m);return}const i=I.current;i&&(i.isCollapsed()?i.expand():i.collapse())},[a]),[X,xe]=s.useState([]),[me,te]=s.useState([]),[V,ie]=s.useState(new Map),[be,Be]=s.useState(new Set),[gt,se]=s.useState(!1),J=s.useRef(new Set);s.useEffect(()=>()=>{for(const i of J.current)try{URL.revokeObjectURL(i)}catch{}J.current.clear()},[]);const[he,_e]=s.useState(null),[ve,pe]=s.useState("newest"),[we,ct]=s.useState(!1),[Ue,lt]=s.useState(!0),[Ne,Oe]=s.useState(new Set);s.useEffect(()=>{Oe(new Set)},[he]);const[ce,Xe]=s.useState(null),[Ge,rt]=s.useState(null),Qe=qr(ua($r,{activationConstraint:{distance:5}}),ua(zr,{activationConstraint:{delay:250,tolerance:5}}));s.useCallback(i=>{const m=X.find(b=>b.id===i);return m?m.parentId===null:!1},[X]);const Ae=s.useCallback(i=>{const m=X.find(b=>b.id===i);return!m||!m.parentId?i:Ae(m.parentId)},[X]);s.useEffect(()=>{if(!r){lt(!1);return}(async()=>{try{const[m,b,n]=await Promise.all([ns(()=>U.from("fs_projects").select("*").eq("user_id",r.id).order("sort_order")),ns(()=>U.from("fs_folders").select("*").order("sort_order")),U.rpc("get_fs_node_counts")]),p=m.map(O=>({id:O.id,name:O.name,parentId:null,expanded:!1,imageCount:0,coverUrl:O.cover_url??void 0,coverFocusX:O.cover_focus_x,coverFocusY:O.cover_focus_y,pinned:O.pinned,createdAt:O.created_at})),_=b.map(O=>({id:O.id,name:O.name,parentId:O.parent_id??O.project_id,expanded:!1,imageCount:0,coverUrl:O.cover_url??void 0,coverFocusX:O.cover_focus_x,coverFocusY:O.cover_focus_y,pinned:O.pinned})),D=new Map((n.data??[]).map(O=>[O.node_id,Number(O.file_count)]));xe([...p,..._]),ie(D),te([]),Be(new Set)}catch(m){console.error("Failed to load file-sharing data:",m),G.error(t("fileSharing.layout.failedLoadProjects"))}finally{lt(!1)}})()},[r,t,le]),s.useEffect(()=>{if(!he||be.has(he))return;const i=X.find(n=>n.id===he);
74if(!i)return;const m=i.parentId===null;let b=!1;return se(!0),(async()=>{try{const n=await ns(()=>{const _=U.from("fs_files").select("*").order("sort_index");return m?_.is("folder_id",null).eq("project_id",i.id):_.eq("folder_id",i.id)});if(b)return;const p=n.map(_=>({id:_.id,name:_.name,url:_.storage_path,size:Number(_.size),type:_.mime_type??"",folderId:_.folder_id??_.project_id,sortIndex:_.sort_index,thumb500Url:_.thumb_500_url??void 0,thumb1440Url:_.thumb_1440_url??void 0,thumb3000Url:_.thumb_3000_url??void 0,originalWidth:_.original_width??void 0,originalHeight:_.original_height??void 0,exif:_.exif??void 0,loaderId:_.loader_id??void 0}));te(_=>{const D=new Set(_.map(R=>R.id)),O=p.filter(R=>!D.has(R.id));return O.length?[..._,...O]:_}),Be(_=>{const D=new Set(_);return D.add(he),D})}catch(n){console.error("Failed to load files for node:",n),G.error(t("fileSharing.layout.failedLoadProjects"))}finally{b||se(!1)}})(),()=>{b=!0}},[he,X,be,t]);const qe=s.useCallback((i,m)=>{ie(b=>{const n=new Map(b);return n.set(i,Math.max(0,(n.get(i)??0)+m)),n})},[]),it=s.useCallback(async i=>{if(!r)return;if(h.isTrialing&&!h.canCreateProject){v("project_limit"),N(!0);return}const{data:m,error:b}=await U.from("fs_projects").insert({name:i,user_id:r.id}).select().single();if(b||!m){G.error(t("fileSharing.layout.failedCreateProject")),console.error(b);return}const n={id:m.id,name:m.name,parentId:null,expanded:!1,imageCount:0,pinned:m.pinned,coverUrl:m.cover_url??void 0,coverFocusX:m.cover_focus_x,coverFocusY:m.cover_focus_y,createdAt:m.created_at};xe(p=>[...p,n]),Be(p=>{const _=new Set(p);return _.add(n.id),_}),_e(n.id),g("fs_project_created",{project_name:i}),h.refresh()},[r,g,h,t]),et=s.useCallback(async(i,m)=>{var O;if(!r)return;if(h.isTrialing&&!h.canCreateFolder){v("folder_limit"),N(!0);return}const b=Ae(i),n=((O=X.find(R=>R.id===i))==null?void 0:O.parentId)===null,{data:p,error:_}=await U.from("fs_folders").insert({name:m,project_id:b,parent_id:n?null:i}).select().single();if(_||!p){G.error(t("fileSharing.layout.failedCreateFolder")),console.error(_);return}const D={id:p.id,name:p.name,parentId:i,expanded:!1,imageCount:0,coverUrl:p.cover_url??void 0,coverFocusX:p.cover_focus_x,coverFocusY:p.cover_focus_y};xe(R=>[...R,D].map(K=>K.id===i?{...K,expanded:!0}:K)),Be(R=>{const F=new Set(R);return F.add(D.id),F}),_e(D.id),h.refresh()},[r,X,Ae,h,t]),_t=s.useCallback(async(i,m)=>{const b=X.find(_=>_.id===i);if(!b)return;xe(_=>_.map(D=>D.id===i?{...D,name:m}:D));const n=b.parentId===null?"fs_projects":"fs_folders",{error:p}=await U.from(n).update({name:m}).eq("id",i);p&&(G.error(t("fileSharing.layout.failedRename")),console.error(p))},[X]),ut=s.useCallback(async i=>{const m=X.find(D=>D.id===i);if(!m)return;const b=new Set,n=D=>{b.add(D),X.filter(O=>O.parentId===D).forEach(O=>n(O.id))};n(i),xe(D=>D.filter(O=>!b.has(O.id))),te(D=>D.filter(O=>!b.has(O.folderId))),ie(D=>{const O=new Map(D);for(const R of b)O.delete(R);return O}),Be(D=>{const O=new Set(D);for(const R of b)O.delete(R);return O}),_e(D=>D===i?null:D);const p=m.parentId===null?"fs_projects":"fs_folders",{error:_}=await U.from(p).delete().eq("id",i);_&&(G.error(t("fileSharing.layout.failedDelete")),console.error(_))},[X,t]),tt=s.useCallback(i=>{xe(m=>m.map(b=>b.id===i?{...b,expanded:!b.expanded}:b))},[]),fe=s.useCallback(async i=>{const m=X.find(_=>_.id===i);if(!m)return;const b=!m.pinned;xe(_=>_.map(D=>D.id===i?{...D,pinned:b}:D));const n=m.parentId===null?"fs_projects":"fs_folders",{error:p}=await U.from(n).update({pinned:b}).eq("id",i);p&&(G.error(t("fileSharing.layout.failedUpdatePin")),console.error(p))},[X]),Ct=s.useCallback(async(i,m,b,n)=>{const p=Ae(i);xe(D=>D.map(O=>O.id===p?{...O,coverUrl:m,coverFocusX:b,coverFocusY:n}:O));const{error:_}=await U.from("fs_projects").update({cover_url:m,cover_focus_x:b,cover_focus_y:n}).eq("id",p);_&&(G.error(t("fileSharing.layout.failedUpdateCover")),console.error(_))},[Ae]),nt=s.useCallback(async(i,m,b,n)=>{const p=X.find(O=>O.id===i);if(!p)return;xe(O=>O.map(R=>R.id===i?{...R,coverUrl:m,coverFocusX:b,coverFocusY:n}:R));const _=p.parentId===null?"fs_projects":"fs_folders",{error:D}=await U.from(_).update({cover_url:m,cover_focus_x:b,cover_focus_y:n}).eq("id",i);D&&(G.error(t("fileSharing.layout.failedUpdateCover")),console.error(D))},[X]),st=s.useCallback(async(i,m)=>{var O;const b=X.find(R=>R.id===i);if(!b||b.parentId===null&&m!==null||(xe(R=>{const F=(K,Z)=>
74K===Z?!0:R.filter($=>$.parentId===K).some($=>F($.id,Z));return m&&F(i,m)?R:R.map(K=>K.id===i?{...K,parentId:m}:K.id===m?{...K,expanded:!0}:K)}),b.parentId===null))return;const n=Ae(m||i),p=m?((O=X.find(R=>R.id===m))==null?void 0:O.parentId)===null:!0,_=Ae(i),{error:D}=await U.from("fs_folders").update({parent_id:p?null:m,project_id:n}).eq("id",i);if(D&&(G.error(t("fileSharing.layout.failedMoveFolder")),console.error(D)),n!==_){const R=$=>{const Le=X.filter(Je=>Je.parentId===$&&Je.parentId!==null);return[$,...Le.flatMap(Je=>R(Je.id))]},F=R(i),K=F.filter($=>$!==i);K.length>0&&await U.from("fs_folders").update({project_id:n}).in("id",K),await U.from("fs_share_links").update({project_id:n}).in("folder_id",F);const Z=me.filter($=>F.includes($.folderId));if(Z.length>0){const $=Z.map(Le=>Le.id);await U.from("fs_files").update({project_id:n}).in("id",$),await Promise.all([U.from("fs_file_annotations").update({project_id:n}).in("file_id",$),U.from("fs_file_comments").update({project_id:n}).in("file_id",$),U.from("fs_file_scribbles").update({project_id:n}).in("file_id",$),U.from("fs_file_activity").update({project_id:n}).in("file_id",$),U.from("fs_file_shares").update({project_id:n}).in("file_id",$)])}}},[X,me,Ae]),at=s.useCallback(async i=>{xe(p=>{const _=new Map(p.map(R=>[R.id,R])),D=i.map(R=>_.get(R)).filter(Boolean),O=p.filter(R=>!i.includes(R.id));return[...D,...O]});const m=i.map((p,_)=>{const D=X.find(R=>R.id===p),O=(D==null?void 0:D.parentId)===null?"fs_projects":"fs_folders";return U.from(O).update({sort_order:_}).eq("id",p)}),n=(await Promise.all(m)).filter(p=>p.error);n.length>0&&(console.error("Failed to persist sort order:",n.map(p=>p.error)),G.error(t("fileSharing.layout.failedSaveOrder")))},[X]),xt=s.useCallback((i,m)=>{var Z;g("fs_files_uploaded",{file_count:m.length});const b=`share_${r.id}`,n=Ae(i),p=((Z=X.find($=>$.id===i))==null?void 0:Z.parentId)===null,_=m.map($=>{const Le=El($)?URL.createObjectURL($):"";return Le&&J.current.add(Le),{id:crypto.randomUUID(),name:$.name,url:Le,size:$.size,type:$.type,folderId:i,uploading:!0,uploadProgress:0}});te($=>[...$,..._]),qe(i,_.length);const D=[...m],O=new Map,R=m.reduce(($,Le)=>Math.max($,Le.size),0),F=R>75*1024*1024?1:R>ar?2:3,K=_.map(($,Le)=>async()=>{var kt;const Je=D[Le];if(Je)try{const He=await Dl(b,Je,It=>{const Bt=O.get($.id)??-1;It!==100&&It-Bt<5||(O.set($.id,It),te(qt=>qt.map(Jt=>Jt.id===$.id?{...Jt,uploadProgress:It}:Jt)))});$.url&&(URL.revokeObjectURL($.url),J.current.delete($.url));const dt=Is(He.thumbnails,500),Ut=Is(He.thumbnails,1440),Xt=Is(He.thumbnails,3e3),j=He.exif&&Object.keys(He.exif).length>0?He.exif:void 0,je=((kt=He.exif)==null?void 0:kt.fullSize)||{},{data:pt,error:Ot}=await U.from("fs_files").insert({name:$.name,storage_path:He.original.url,project_id:n,folder_id:p?null:i,size:$.size,mime_type:$.type,loader_id:He.id,thumb_500_url:dt??null,thumb_1440_url:Ut??null,thumb_3000_url:Xt??null,original_width:je.width??null,original_height:je.height??null,exif:j??null}).select().single();if(Ot||!pt){console.error("Failed to save file to DB:",Ot),pa({stage:"db_insert",error:Ot??new Error("DB insert returned no row"),fileName:$.name,fileSize:$.size,fileMime:$.type,projectId:n,folderId:p?null:i}),G.error(t("fileSharing.layout.failedSaveFile",{name:$.name})),te(It=>It.filter(Bt=>Bt.id!==$.id)),qe(i,-1);return}const Ze=Ut||Xt;if(Ze){const It=X.find(qt=>qt.id===i);It&&!It.coverUrl&&nt(i,Ze,50,50);const Bt=X.find(qt=>qt.id===n);Bt&&!Bt.coverUrl&&Ct(n,Ze,50,50)}te(It=>It.map(Bt=>Bt.id===$.id?{...Bt,id:pt.id,url:He.original.url,uploading:!1,uploadProgress:100,loaderId:He.id,thumb500Url:dt,thumb1440Url:Ut,thumb3000Url:Xt,originalWidth:je.width,originalHeight:je.height,exif:j}:Bt))}catch(He){$.url&&(URL.revokeObjectURL($.url),J.current.delete($.url)),te(dt=>dt.filter(Ut=>Ut.id!==$.id)),qe(i,-1),pa({stage:"loader_upload",error:He,fileName:Je.name,fileSize:Je.size,fileMime:Je.type,projectId:n,folderId:p?null:i}),G.error(t("fileSharing.layout.uploadFailed",{name:Je.name})),console.error("Upload error:",He)}finally{D[Le]=null,O.delete($.id)}});qa(K,F)},[r,X,Ae,nt,Ct,g,qe,t]),B=s.useCallback((i,m)=>{const b=F=>
74F.type&&F.type.startsWith("video/")||/\.(mp4|mov|webm|m4v|avi|mkv|hevc)$/i.test(F.name),n=m.filter(b);let p=m;if(n.length>0&&!L("fs_video_upload")&&(p=m.filter(F=>!b(F)),Te(Ee("fs_video_upload")),$e(!0),G.error(n.length===m.length?"Video uploads are not available on your current plan.":`${n.length} video file(s) skipped — not available on your current plan.`),p.length===0))return;const _=p.reduce((F,K)=>F+K.size,0);if(!h.canUpload(_)){w({folderId:i,files:p}),Y(!0);return}if(o+_>l){w({folderId:i,files:p}),H(!0);return}const D=me.filter(F=>F.folderId===i&&!F.uploading),O=new Map(D.map(F=>[F.name,F.id])),R=p.map(F=>{const K=O.get(F.name);return K?{file:F,existingId:K}:null}).filter(F=>F!==null);if(R.length>0){ue({folderId:i,files:p,conflicts:R});return}xt(i,p)},[o,l,xt,L,Ee,h,me]),c=s.useCallback(i=>{if(!z)return;const{folderId:m,files:b,conflicts:n}=z;ue(null);const p=new Map(n.map(F=>[F.file.name,F])),_=new Set(me.filter(F=>F.folderId===m&&!F.uploading).map(F=>F.name)),D=F=>{const K=F.lastIndexOf("."),Z=K>0?F.slice(0,K):F,$=K>0?F.slice(K):"";let Le=2;for(;_.has(`${Z} (${Le})${$}`);)Le++;return`${Z} (${Le})${$}`};let O=[];const R=[];if(i==="skip")O=b.filter(F=>!p.has(F.name));else if(i==="replace"){O=b;for(const F of n)R.push(F.existingId),_.delete(F.file.name)}else O=b.map(F=>{if(!p.has(F.name))return F;const K=D(F.name);_.add(K);try{return new File([F],K,{type:F.type,lastModified:F.lastModified})}catch{return Object.defineProperty(F,"name",{value:K,configurable:!0}),F}});Promise.all(R.map(F=>Nt(F))).finally(()=>{O.length>0&&xt(m,O)})},[z,me,xt]),Pe=s.useCallback(()=>{ue(null)},[]),ft=s.useCallback(async i=>{const{data:m,error:b}=await U.functions.invoke("manage-extra-storage",{body:{action:"add",tier:i}});if((m==null?void 0:m.error)==="legacy_plan"||b&&JSON.stringify(b).includes("legacy_plan")){ee(!0);return}if(b)throw b;if(m!=null&&m.error)throw new Error(m.error);await S(),G.success(t("fileSharing.layout.storageUpgraded"))},[S]),Ce=s.useCallback(()=>{S().then(()=>{W&&(xt(W.folderId,W.files),w(null))})},[S,W,xt]),Nt=s.useCallback(async i=>{let m=null;te(n=>{const p=n.find(_=>_.id===i);return p?(m=p.folderId,p.url&&p.url.startsWith("blob:")&&(URL.revokeObjectURL(p.url),J.current.delete(p.url)),n.filter(_=>_.id!==i)):n}),m&&qe(m,-1);const{error:b}=await U.from("fs_files").delete().eq("id",i);b&&(G.error(t("fileSharing.layout.failedDeleteFile")),console.error(b))},[qe,t]),Ke=s.useCallback(async(i,m)=>{te(n=>n.map(p=>{if(p.folderId!==i)return p;const _=m.indexOf(p.id);return _!==-1?{...p,sortIndex:_}:p}));const b=m.map((n,p)=>U.from("fs_files").update({sort_index:p}).eq("id",n));await Promise.all(b)},[]),ot=s.useCallback(i=>{},[]),ze=s.useCallback(async(i,m)=>{var R;const b=me.find(F=>F.id===i);if(!b||b.folderId===m)return;const n=b.folderId;te(F=>F.map(K=>K.id===i?{...K,folderId:m,sortIndex:void 0}:K)),qe(n,-1),qe(m,1),G.success(t("fileSharing.layout.imageMovedToFolder"));const p=Ae(m),_=((R=X.find(F=>F.id===m))==null?void 0:R.parentId)===null,D=Ae(b.folderId),{error:O}=await U.from("fs_files").update({folder_id:_?null:m,project_id:p,sort_index:0}).eq("id",i);O&&(G.error(t("fileSharing.layout.failedMoveFile")),console.error(O)),p!==D&&await Promise.all([U.from("fs_file_annotations").update({project_id:p}).eq("file_id",i),U.from("fs_file_comments").update({project_id:p}).eq("file_id",i),U.from("fs_file_scribbles").update({project_id:p}).eq("file_id",i),U.from("fs_file_activity").update({project_id:p}).eq("file_id",i),U.from("fs_file_shares").update({project_id:p}).eq("file_id",i)])},[me,X,Ae,qe,t]),Tt=s.useMemo(()=>X.map(i=>({...i,imageCount:V.get(i.id)??0})),[X,V]),ge=Tt.find(i=>i.id===he)??null,ne=s.useMemo(()=>ge?me.filter(i=>i.folderId===ge.id):[],[me,ge]),ye=ne.some(i=>i.sortIndex!==void 0),Re=s.useMemo(()=>{const i=[...ne];switch(ve){case"az":return i.sort((m,b)=>m.name.localeCompare(b.name));case"za":return i.sort((m,b)=>b.name.localeCompare(m.name));case"large":return i.sort((m,b)=>b.size-m.size);case"small":return i.sort((m,b)=>m.size-b.size);case"custom":return i.sort((m,b)=>(m.sortIndex??0)-(b.sortIndex??0));case"oldest":return i;case"newest":default:return i.reverse()}},[ne,ve]),u=s.useCallback(i=>{const m=i.active.data.current;if((m==null?void 0:m.type)==="file"){const b=me.find(n=>n.id===i.active.id);if(b)if(Ne.has(b.id)&&Ne.size>1){const n=me.filter(p=>Ne.has(p.id));Xe({type:"multi-file",files:n,count:n.length})}else Xe({type:"file",file:b})}else(m==null?void 0:m.type)==="tree-item"&&Xe({type:"tree-item",node:m.node})},[me,Ne]),M=s.useCallback(i=>{var _,D;const{active:m,over:b}=i;if(!b||m.id===b.id){rt(null);return}const n=m.data.current,p=b.data.current;if(((n==null?void 0:n.type)==="file"||(n==null?void 0:n.type)==="multi-file")&&(p==null?void 0:p.type)==="tree-item"){rt({id:b.id,intent:"inside"});return}if((n==null?void 0:n.type)==="tree-item"&&(p==null?void 0:p.type)==="tree-item"){const R=(((_=i.activatorEvent)==null?void 0:_.clientY)??0)+(((D=i.delta)==null?void 0:D.y)??0),F=b.rect??null,K=Fa(F,R);rt({id:b.id,intent:K});return}if((n==null?void 0:n.type)==="tree-item"&&(p==null?void 0:p.type)==="tree-item-tail"){rt({id:"sidebar-tail",intent:"below"});return}if((n==null?void 0:n.type)==="tree-item"&&(p==null?void 0:p.type)==="folder"){rt(null);return}rt(null)},[]),P=s.useCallback(i=>{var _,D;const{active:m,over:b}=i;if(!b||m.id===b.id)return;const n=m.data.current,p=b.data.current;if((n==null?void 0:n.type)==="tree-item"&&(p==null?void 0:p.type)==="tree-item"){const R=(((_=i.activatorEvent)==null?void 0:_.clientY)??0)+(((D=i.delta)==null?void 0:D.y)??0),F=b.rect??null,K=Fa(F,R);rt(Z=>(Z==null?void 0:Z.id)===b.id&&(Z==null?void 0:Z.intent)===K?Z:{id:b.id,intent:K})}},[]),q=s.useCallback(i=>{const{active:m,over:b}=i,n=Ge,p=ce;if(Xe(null),rt(null),!b||m.id===b.id)return;const _=m.data.current,D=b.data.current,O=R=>{const F=String(R);return F.startsWith("subfolder-drag-")?F.replace("subfolder-drag-",""):F};if((p==null?void 0:p.type)==="multi-file"&&(D==null?void 0:D.type)==="tree-item"){const R=b.id;
74p.files.forEach(F=>ze(F.id,R)),G.success(t("fileSharing.layout.movedImages",{count:p.count})),Oe(new Set);return}if((p==null?void 0:p.type)==="multi-file"&&(D==null?void 0:D.type)==="folder"){const R=D.folderId;p.files.forEach(F=>ze(F.id,R)),G.success(t("fileSharing.layout.movedImages",{count:p.count})),Oe(new Set);return}if((_==null?void 0:_.type)==="file"&&(D==null?void 0:D.type)==="tree-item"){ze(m.id,b.id);return}if((_==null?void 0:_.type)==="file"&&(D==null?void 0:D.type)==="folder"){ze(m.id,D.folderId);return}if((_==null?void 0:_.type)==="file"&&(D==null?void 0:D.type)==="file"){if(!ge)return;const R=Re.findIndex(Z=>Z.id===m.id),F=Re.findIndex(Z=>Z.id===b.id);if(R===-1||F===-1)return;const K=Gr(Re,R,F);Ke(ge.id,K.map(Z=>Z.id)),pe("custom"),ct(!0);return}if((_==null?void 0:_.type)==="tree-item"&&(D==null?void 0:D.type)==="folder"){const R=D.folderId,F=O(m.id);if(F===R)return;const K=X.find(Z=>Z.id===F);if((K==null?void 0:K.parentId)===null)return;st(F,R),G.success(t("fileSharing.layout.movedFolder"));return}if((_==null?void 0:_.type)==="tree-item"&&(D==null?void 0:D.type)==="tree-item-tail"){const R=O(m.id),F=X.find(Z=>Z.id===R);if(!F)return;F.parentId!==null&&(st(R,null),G.success(t("fileSharing.layout.movedFolder")));const K=X.filter(Z=>Z.parentId===null).map(Z=>Z.id).filter(Z=>Z!==R);K.push(R),at(K);return}if((_==null?void 0:_.type)==="tree-item"&&(D==null?void 0:D.type)==="tree-item"){const R=O(m.id),F=X.find(dt=>dt.id===R),K=X.find(dt=>dt.id===b.id);if(!F||!K)return;const Z=F.parentId===null,$=(n==null?void 0:n.id)===b.id?n.intent:"inside";if($==="inside"){if(Z)return;st(R,b.id),G.success(t("fileSharing.layout.movedFolder"));return}F.parentId!==K.parentId&&(Z||(st(R,K.parentId),G.success(t("fileSharing.layout.movedFolder"))));const Le=Z?null:K.parentId,Je=X.filter(dt=>dt.parentId===Le).map(dt=>dt.id).filter(dt=>dt!==R),kt=Je.indexOf(b.id),He=$==="above"?kt:kt+1;Je.splice(He,0,R),at(Je)}},[X,Ge,ce,ze,st,at,ge,Re,Ke,Oe]),ke=s.useCallback(()=>{Xe(null),rt(null)},[]),Fe=s.useCallback(()=>{ge&&(ot(ge.id),ct(!1),G.success(t("fileSharing.layout.customOrderSaved")))},[ge,ot]);if(Ue)return e.jsx("div",{className:"flex h-screen items-center justify-center bg-background",children:e.jsx("div",{className:"text-muted-foreground",children:"Loading..."})});const Ft=e.jsx(Ol,{nodes:Tt,selectedId:he,onSelect:i=>{_e(i),a&&T(!1)},onToggleExpand:tt,onAddProject:it,onTogglePin:fe,sidebarDropTarget:Ge,isDragActive:ce!==null,onToggleCollapse:Se,onDeselectAll:()=>{_e(null),a&&T(!1)}});return e.jsxs("div",{className:"flex h-screen flex-col bg-background",children:[e.jsx(Dr,{usedBytes:o,totalBytes:l,onStoragePurchase:ft,onNavigateToFile:Me,onOpenImport:()=>re(!0)}),e.jsx(sr,{open:A,onOpenChange:H,usedBytes:o,totalBytes:l,onSuccess:Ce}),e.jsx(tr,{open:oe,onOpenChange:ee}),e.jsx(an,{open:Q,onOpenChange:re,onImported:()=>{de(i=>i+1),S()}}),e.jsxs(Hr,{sensors:Qe,collisionDetection:Ln,measuring:{droppable:{strategy:Wr.Always}},onDragStart:u,onDragMove:P,onDragOver:M,onDragEnd:q,onDragCancel:ke,children:[a?e.jsxs(e.Fragment,{children:[e.jsx(_r,{open:E,onOpenChange:T,children:e.jsx(Cr,{side:"left",className:"w-[280px] p-0 [&>button]:hidden",children:Ft})}),e.jsxs("div",{className:"flex-1 overflow-hidden relative",children:[!E&&e.jsx(ae,{onClick:()=>T(!0),className:"absolute top-3 left-3 z-30 h-10 w-10 rounded-full bg-primary text-primary-foreground shadow-lg hover:bg-primary/90",size:"icon",children:e.jsx(Pa,{className:"h-5 w-5"})}),e.jsx(Ca,{selectedNode:ge,nodes:Tt,sortedFiles:Re,onAddProject:it,onAddSubfolder:et,onRenameNode:_t,onDeleteNode:ut,onAddFiles:B,onDeleteFile:Nt,onSetProjectCover:Ct,onSetFolderCover:nt,onSelect:_e,sortOrder:ve,onSortChange:pe,hasCustomOrder:ye,hasUnsavedCustomOrder:we,onSaveCustomOrder:Fe,isSidebarCollapsed:x,onExpandSidebar:Se,getProjectRoot:Ae,selectedIds:Ne,setSelectedIds:Oe,onRenameFiles:i=>{te(m=>m.map(b=>{const n=i.find(p=>p.id===b.id);return n?{...b,name:n.newName}:b}))},pendingDetailFileId:k,onClearPendingDetail:()=>y(null),filesLoading:gt})]})]}):e.jsxs(Nr,{direction:"horizontal",className:"flex-1 overflow-hidden",children:[e.jsx(ca,{ref:I,defaultSize:20,minSize:15,maxSize:40,collapsible:!0,collapsedSize:0,onCollapse:()=>d(!0),onExpand:()=>d(!1),children:Ft}),e.jsx(kr,{withHandle:!0}),e.jsx(ca,{defaultSize:80,minSize:40,children:e.jsx(Ca,{selectedNode:ge,nodes:Tt,sortedFiles:Re,onAddProject:it,onAddSubfolder:et,onRenameNode:_t,onDeleteNode:ut,onAddFiles:B,onDeleteFile:Nt,onSetProjectCover:Ct,onSetFolderCover:nt,onSelect:_e,sortOrder:ve,onSortChange:pe,hasCustomOrder:ye,hasUnsavedCustomOrder:we,onSaveCustomOrder:Fe,isSidebarCollapsed:x,onExpandSidebar:Se,getProjectRoot:Ae,selectedIds:Ne,setSelectedIds:Oe,onRenameFiles:i=>{te(m=>m.map(b=>{const n=i.find(p=>p.id===b.id);return n?{...b,name:n.newName}:b}))},pendingDetailFileId:k,onClearPendingDetail:()=>y(null),filesLoading:gt})})]}),e.jsx(Yr,{dropAnimation:{duration:200,easing:"cubic-bezier(0.18, 0.67, 0.6, 1.22)"},children:(ce==null?void 0:ce.type)==="tree-item"?e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-border/60 bg-background px-3 py-1.5 text-sm shadow-[0_8px_24px_-4px_rgba(0,0,0,0.15)] backdrop-blur-sm animate-scale-in",children:[e.jsx(Ht,{className:"h-4 w-4 shrink-0 text-primary"}),e.jsx("span",{className:"truncate font-medium",children:ce.node.name})]}):(ce==null?void 0:ce.type)==="multi-file"?e.jsxs("div",{className:"relative w-20 h-20 animate-scale-in",children:[ce.files.slice(0,3).map((i,m)=>e.jsx("div",{className:"absolute w-20 h-20 rounded-lg border border-border bg-background shadow-lg overflow-hidden",style:{to
74p:m*-4,left:m*4,zIndex:3-m},children:e.jsx("img",{src:Gt(i,"small"),alt:i.name,className:"h-full w-full object-cover"})},i.id)),e.jsx("div",{className:"absolute -top-2 -right-2 z-10 flex h-6 w-6 items-center justify-center rounded-full bg-primary text-primary-foreground text-xs font-bold shadow",children:ce.count})]}):(ce==null?void 0:ce.type)==="file"?e.jsx("div",{className:"w-20 h-20 rounded-lg border border-border bg-background shadow-lg overflow-hidden animate-scale-in",children:e.jsx("img",{src:Gt(ce.file,"small"),alt:ce.file.name,className:"h-full w-full object-cover"})}):null})]}),e.jsx(ta,{open:C,onOpenChange:N,reason:f}),h.isTrialing?e.jsx(aa,{open:Ye,onOpenChange:$e,requiredTier:mt,featureLabel:"Video file uploads"}):e.jsx(sa,{open:Ye,onOpenChange:$e,requiredTier:mt,featureLabel:"Video file uploads"}),e.jsx(On,{open:De,onOpenChange:Y,onActivated:()=>{W&&(xt(W.folderId,W.files),w(null)),S(),h.refresh()}}),e.jsx(An,{open:z!==null,onOpenChange:i=>{i||ue(null)},conflictNames:(z==null?void 0:z.conflicts.map(i=>i.file.name))??[],onResolve:c,onCancel:Pe})]})}function co(){const{hasAccess:t}=Nl(),{subscription:r}=Et(),a=Ra();return t?e.jsx(Mn,{}):e.jsx("div",{className:"flex h-screen items-center justify-center bg-background",children:e.jsxs("div",{className:"text-center max-w-md mx-auto p-8 space-y-4",children:[e.jsx(wr,{className:"h-16 w-16 text-muted-foreground mx-auto"}),e.jsx("h1",{className:"text-2xl font-bold",children:"Backup & Collaboration"}),e.jsx("p",{className:"text-muted-foreground",children:"This tool is included in all Vsble Suite website plans, or available as a standalone subscription."}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(ae,{onClick:()=>{a("/dashboard"),setTimeout(()=>window.dispatchEvent(new CustomEvent("open-account-tab",{detail:"file_sharing"})),100)},className:"w-full",children:"View standalone plans"}),e.jsxs(ae,{variant:"outline",onClick:()=>{a("/dashboard"),setTimeout(()=>window.dispatchEvent(new CustomEvent("start-trial")),100)},className:"w-full",children:[e.jsx(Dt,{className:"h-4 w-4 mr-2"}),r.trialEligible?"Start free trial (includes all tools)":"Subscribe (includes all tools)"]})]})]})})}export{co as default};

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.