import{r,m as ye,j as e,i as Nt,q as Ht,u as Kt,n as We,z as ne,P as Wt}from"./index-BVAJPyoi.js";import{S as qt}from"./folder-DP1y2aY4.js";import{S as Ct,u as Gt,D as Vt,a as Ae,b as Xt,c as Ee,T as Ie,I as dt,d as Yt,B as Oe,e as ct,f as Qt,g as Zt,h as ut}from"./TextField-Co2uoZNe.js";import{S as et,F as Jt,C as er,a as tr,R as rr,b as ar}from"./RemoteFileDialog-BOeC2nT4.js";import{M as sr,i as nr,u as St,P as or,a as lr,b as ir,L as dr,m as Te}from"./proxy-CgmHClDn.js";import{X as qe}from"./x-CzJs-Tw5.js";import{S as Pt}from"./search-GkEEVNuM.js";import"./clsx-B-dksMZM.js";import"./tslib.es6-BUas5LQb.js";import"./utils-Bdm9QozO.js";import"./bundle-mjs-COJ8Fh6m.js";import"./refresh-cw-DoD9eHF9.js";const mt=a=>r.createElement("svg",{className:"size-6",width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...a},r.createElement("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M8 2C8.41421 2 8.75 2.33579 8.75 2.75V3.75H15.25V2.75C15.25 2.33579 15.5858 2 16 2C16.4142 2 16.75 2.33579 16.75 2.75V3.75H18.5C19.7426 3.75 20.75 4.75736 20.75 6V9V19C20.75 20.2426 19.7426 21.25 18.5 21.25H5.5C4.25736 21.25 3.25 20.2426 3.25 19V9V6C3.25 4.75736 4.25736 3.75 5.5 3.75H7.25V2.75C7.25 2.33579 7.58579 2 8 2ZM8 5.25H5.5C5.08579 5.25 4.75 5.58579 4.75 6V8.25H19.25V6C19.25 5.58579 18.9142 5.25 18.5 5.25H16H8ZM19.25 9.75H4.75V19C4.75 19.4142 5.08579 19.75 5.5 19.75H18.5C18.9142 19.75 19.25 19.4142 19.25 19V9.75Z",fill:"currentColor"})),cr=a=>r.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:"icon icon-tabler icons-tabler-outline icon-tabler-database",...a},r.createElement("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),r.createElement("path",{d:"M12 6m-8 0a8 3 0 1 0 16 0a8 3 0 1 0 -16 0"}),r.createElement("path",{d:"M4 6v6a8 3 0 0 0 16 0v-6"}),r.createElement("path",{d:"M4 12v6a8 3 0 0 0 16 0v-6"})),Et=a=>r.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:"icon icon-tabler icons-tabler-outline icon-tabler-signature",...a},r.createElement("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),r.createElement("path",{d:"M3 17c3.333 -3.333 5 -6 5 -8c0 -3 -1 -3 -2 -3s-2.032 1.085 -2 3c.034 2.048 1.658 4.877 2.5 6c1.5 2 2.5 2.5 3.5 1l2 -3c.333 2.667 1.333 4 3 4c.53 0 2.639 -2 3 -2c.517 0 1.517 .667 3 2"}));/**
 * @license lucide-react v0.544.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const ur=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M8 12h8",key:"1wcyev"}],["path",{d:"M12 8v8",key:"napkw2"}]],It=ye("circle-plus",ur);/**
 * @license lucide-react v0.544.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const mr=[["path",{d:"M12 13v8l-4-4",key:"1f5nwf"}],["path",{d:"m12 21 4-4",key:"1lfcce"}],["path",{d:"M4.393 15.269A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.436 8.284",key:"ui1hmy"}]],xr=ye("cloud-download",mr);/**
 * @license lucide-react v0.544.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const gr=[["path",{d:"M12 15V3",key:"m9g1x1"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["path",{d:"m7 10 5 5 5-5",key:"brsn70"}]],hr=ye("download",gr);/**
 * @license lucide-react v0.544.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const br=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],xt=ye("shield-check",br);/**
 * @license lucide-react v0.544.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const fr=[["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"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]],pr=ye("user-minus",fr);/**
 * @license lucide-react v0.544.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const yr=[["path",{d:"M2 21a8 8 0 0 1 13.292-6",key:"bjp14o"}],["circle",{cx:"10",cy:"8",r:"5",key:"o932ke"}],["path",{d:"M19 16v6",key:"tddt3s"}],["path",{d:"M22 19h-6",key:"vcuq98"}]],Dt=ye("user-round-plus",yr);/**
 * @license lucide-react v0.544.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const kr=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["path",{d:"M16 3.128a4 4 0 0 1 0 7.744",key:"16gr8j"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}]],wr=ye("users",kr);function gt(a,t){if(typeof a=="function")return a(t);a!=null&&(a.current=t)}function vr(...a){return t=>{let i=!1;const u=a.map(m=>{const l=gt(m,t);return!i&&typeof l=="function"&&(i=!0),l});if(i)return()=>{for(let m=0;m<u.length;m++){const l=u[m];typeof l=="function"?l():gt(a[m],null)}}}}function jr(...a){return r.useCallback(vr(...a),a)}class Nr extends r.Component{getSnapshotBeforeUpdate(t){const i=this.props.childRef.current;if(i&&t.isPresent&&!this.props.isPresent){const u=i.offsetParent,m=nr(u)&&u.offsetWidth||0,l=this.props.sizeRef.current;l.height=i.offsetHeight||0,l.width=i.offsetWidth||0,l.top=i.offsetTop,l.left=i.offsetLeft,l.right=m-l.width-l.left}return null}componentDidUpdate(){}render(){return this.props.children}}function Cr({children:a,isPresent:t,anchorX:i,root:u}){const m=r.useId(),l=r.useRef(null),w=r.useRef({width:0,height:0,top:0,left:0,right:0}),{nonce:P}=r.useContext(sr),E=jr(l,a==null?void 0:a.ref);return r.useInsertionEffect(()=>{const{width:j,height:D,top:N,left:I,right:A}=w.current;if(t||!l.current||!j||!D)return;const v=i==="left"?`left: ${I}`:`right: ${A}`;l.current.dataset.motionPopId=m;const k=document.createElement("style");P&&(k.nonce=P);const O=u!=null?u:document.head;return O.appendChild(k),k.sheet&&k.sheet.insertRule(`
          [data-motion-pop-id="${m}"] {
            position: absolute !important;
            width: ${j}px !important;
            height: ${D}px !important;
            ${v}px !important;
            top: ${N}px !important;
          }
        `),()=>{O.contains(k)&&O.removeChild(k)}},[t]),e.jsx(Nr,{isPresent:t,childRef:l,sizeRef:w,children:r.cloneElement(a,{ref:E})})}const Sr=({children:a,initial:t,isPresent:i,onExitComplete:u,custom:m,presenceAffectsLayout:l,mode:w,anchorX:P,root:E})=>{const j=St(Pr),D=r.useId();let N=!0,I=r.useMemo(()=>(N=!1,{id:D,initial:t,isPresent:i,custom:m,onExitComplete:A=>{j.set(A,!0);for(const v of j.values())if(!v)return;u&&u()},register:A=>(j.set(A,!1),()=>j.delete(A))}),[i,j,u]);return l&&N&&(I={...I}),r.useMemo(()=>{j.forEach((A,v)=>j.set(v,!1))},[i]),r.useEffect(()=>{!i&&!j.size&&u&&u()},[i]),w==="popLayout"&&(a=e.jsx(Cr,{isPresent:i,anchorX:P,root:E,children:a})),e.jsx(or.Provider,{value:I,children:a})};function Pr(){return new Map}const Be=a=>a.key||"";function ht(a){const t=[];return r.Children.forEach(a,i=>{r.isValidElement(i)&&t.push(i)}),t}const bt=({children:a,custom:t,initial:i=!0,onExitComplete:u,presenceAffectsLayout:m=!0,mode:l="sync",propagate:w=!1,anchorX:P="left",root:E})=>{const[j,D]=lr(w),N=r.useMemo(()=>ht(a),[a]),I=w&&!j?[]:N.map(Be),A=r.useRef(!0),v=r.useRef(N),k=St(()=>new Map),[O,C]=r.useState(N),[y,x]=r.useState(N);ir(()=>{A.current=!1,v.current=N;for(let z=0;z<y.length;z++){const p=Be(y[z]);I.includes(p)?k.delete(p):k.get(p)!==!0&&k.set(p,!1)}},[y,I.length,I.join("-")]);const M=[];if(N!==O){let z=[...N];for(let p=0;p<y.length;p++){const B=y[p],F=Be(B);I.includes(F)||(z.splice(p,0,B),M.push(B))}return l==="wait"&&M.length&&(z=M),x(ht(z)),C(N),null}const{forceRender:L}=r.useContext(dr);return e.jsx(e.Fragment,{children:y.map(z=>{const p=Be(z),B=w&&!j?!1:N===y||I.includes(p),F=()=>{if(k.has(p))k.set(p,!0);else return;let W=!0;k.forEach(q=>{q||(W=!1)}),W&&(L==null||L(),x(v.current),w&&(D==null||D()),u&&u())};return e.jsx(Sr,{isPresent:B,initial:!A.current||i?void 0:!1,custom:t,presenceAffectsLayout:m,mode:l,root:E,onExitComplete:B?void 0:F,anchorX:P,children:z},p)})})};function se(...a){return a.filter(Boolean).join(" ")}const ft="subpixel-antialiased [text-rendering:optimizeLegibility]",ze=a=>t=>{if(a)return;const i=t.currentTarget;document.activeElement!==i&&i.focus()},Er=({onOpen:a,onRename:t,onRemove:i,onShare:u,className:m})=>{const[l,w]=r.useState(!1),[P,E]=r.useState({left:0,top:0}),j=r.useRef(null),D=r.useRef(null),N=r.useRef([]),I=r.useId(),A=typeof document!="undefined"?document.body:null,v=!a,k=!t,O=!u,C=!i,y=r.useCallback(()=>{const n=j.current;if(!n)return;const d=n.getBoundingClientRect(),g=8,T=176,Y=184,s=window.innerWidth,h=window.innerHeight;let b=d.right-T,f=d.bottom+8;b=Math.max(g,Math.min(b,s-T-g)),f+Y>h-g&&(f=d.top-Y-8),f=Math.max(g,Math.min(f,h-Y-g)),E({left:b,top:f})},[]),x=r.useCallback(()=>{w(!1),queueMicrotask(()=>{var n;return(n=j.current)==null?void 0:n.focus()})},[]),M=r.useCallback(n=>{n.preventDefault(),n.stopPropagation(),w(d=>{const g=!d;return g&&queueMicrotask(()=>y()),g})},[y]),L=r.useCallback(()=>{w(!0),queueMicrotask(()=>y())},[y]),z=r.useCallback(n=>{(n.key==="Enter"||n.key===" "||n.key==="F10"||n.key==="ArrowDown")&&(n.preventDefault(),n.stopPropagation(),L())},[L]);r.useEffect(()=>{if(!l)return;const n=g=>{const T=g.target;T&&(D.current&&D.current.contains(T)||j.current&&j.current.contains(T)||x())},d=g=>{g.key==="Escape"&&(g.preventDefault(),g.stopPropagation(),x())};return window.addEventListener("pointerdown",n,!0),window.addEventListener("keydown",d,!0),()=>{window.removeEventListener("pointerdown",n,!0),window.removeEventListener("keydown",d,!0)}},[l,x]),r.useEffect(()=>{if(!l)return;y();const n=()=>y();return window.addEventListener("resize",n),window.addEventListener("scroll",n,!0),()=>{window.removeEventListener("resize",n),window.removeEventListener("scroll",n,!0)}},[l,y]),r.useEffect(()=>{l&&queueMicrotask(()=>{const d=N.current.filter(Boolean).find(g=>g.dataset.disabled!=="true");d==null||d.focus()})},[l]);const p=r.useCallback(n=>d=>{N.current[n]=d},[]),B=n=>d=>{d.preventDefault(),d.stopPropagation(),n==null||n(),x()},F=r.useCallback(n=>{const d=N.current.filter(Boolean);if(!d.length)return;const g=s=>(s==null?void 0:s.dataset.disabled)==="true",T=d.findIndex(s=>s===document.activeElement),Y=s=>{let h=T;for(let b=0;b<d.length;b++)if(h=(h+s+d.length)%d.length,!g(d[h])){d[h].focus();break}};switch(n.key){case"ArrowDown":n.preventDefault(),Y(1);break;case"ArrowUp":n.preventDefault(),Y(-1);break;case"Home":{n.preventDefault();const s=d.find(h=>!g(h));s==null||s.focus();break}case"End":{n.preventDefault();for(let s=d.length-1;s>=0;s--)if(!g(d[s])){d[s].focus();break}break}case"Tab":x();break;case"Escape":n.preventDefault(),x();break}},[x]),W="px-4 py-2.5 outline-none flex items-center gap-2 text-sm font-medium",q="cursor-pointer transition hover:bg-gray-50 focus:bg-gray-100 dark:hover:bg-slate-800/70 dark:focus:bg-slate-800/70",G="cursor-not-allowed opacity-50 text-gray-400 dark:text-gray-500",ee=se(ft,"flex h-9 w-9 items-center justify-center rounded-xl border transition","border-gray-300/80 bg-white text-gray-700 shadow-sm hover:border-gray-400 hover:shadow-md","dark:border-gray-700 dark:bg-slate-900 dark:text-gray-200 dark:hover:border-gray-600",l?"border-indigo-500/40 ring-2 ring-indigo-500/15":""),Q=e.jsx("div",{ref:D,id:I,role:"menu",tabIndex:-1,onKeyDown:F,className:se(ft,"fixed z-[10000] w-44 overflow-hidden rounded-xl border shadow-2xl","border-gray-300/90 bg-white","dark:border-gray-700 dark:bg-slate-900"),style:{left:P.left,top:P.top},onMouseDown:n=>{n.preventDefault(),n.stopPropagation()},children:e.jsxs("ul",{className:"py-1 text-gray-800 dark:text-gray-200",children:[e.jsxs("li",{ref:p(0),tabIndex:-1,role:"menuitem","aria-disabled":v,"data-disabled":v?"true":"false",className:se(W,v?G:q),onClick:v?void 0:B(a),onPointerMove:ze(v),onKeyDown:v?void 0:n=>{(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),a==null||a(),x())},children:[e.jsx(et,{className:se("h-5 w-5",v?"text-gray-400 dark:text-gray-500":"text-gray-700 dark:text-gray-200")}),e.jsx("span",{children:"Open"})]}),e.jsxs("li",{ref:p(1),tabIndex:-1,role:"menuitem","aria-disabled":k,"data-disabled":k?"true":"false",className:se(W,k?G:q),onClick:k?void 0:B(t),onPointerMove:ze(k),onKeyDown:k?void 0:n=>{(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),t==null||t(),x())},children:[e.jsx(Et,{className:se("h-5 w-5",k?"text-gray-400 dark:text-gray-500":"text-gray-700 dark:text-gray-200")}),e.jsx("span",{children:"Rename"})]}),e.jsxs("li",{ref:p(2),tabIndex:-1,role:"menuitem","aria-disabled":O,"data-disabled":O?"true":"false",className:se(W,O?G:q),onClick:O?void 0:B(u),onPointerMove:ze(O),onKeyDown:O?void 0:n=>{(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),u==null||u(),x())},children:[e.jsx(Dt,{className:se("h-4 w-4",O?"text-gray-400 dark:text-gray-500":"text-gray-700 dark:text-gray-200")}),e.jsx("span",{children:"Share"})]}),e.jsxs("li",{ref:p(3),tabIndex:-1,role:"menuitem","aria-disabled":C,"data-disabled":C?"true":"false",className:se(W,C?G:q,C?"":"hover:bg-red-50 focus:bg-red-50 dark:hover:bg-red-950/20 dark:focus:bg-red-950/20"),onClick:C?void 0:B(i),onPointerMove:ze(C),onKeyDown:C?void 0:n=>{(n.key==="Enter"||n.key===" ")&&(n.preventDefault(),i==null||i(),x())},children:[e.jsx(Ct,{className:se("h-5 w-5",C?"text-gray-400 dark:text-gray-500":"text-red-700 dark:text-red-300")}),e.jsx("span",{className:C?void 0:"text-red-700 dark:text-red-300",children:"Remove"})]})]})});return e.jsxs("div",{className:se("relative flex items-center",m),children:[e.jsx("button",{ref:j,type:"button",onClick:M,onKeyDown:z,className:ee,"aria-haspopup":"menu","aria-expanded":l,"aria-controls":I,children:e.jsx(Ht,{className:se("h-6 w-6",l?"text-indigo-600 dark:text-indigo-300":"")})}),l&&A?Nt.createPortal(Q,A):null]})},Ir=2e4,pt=new Map,Dr=180,Ne=new Map,Ye=new Map;function Qe(a){const t=Ne.get(a);return t?(t.touchedAt=Date.now(),t.url):null}function yt(a,t){for(Ne.set(a,{url:t,touchedAt:Date.now()});Ne.size>Dr;){let i=null,u=Number.POSITIVE_INFINITY;for(const[l,w]of Ne.entries())w.touchedAt<u&&(u=w.touchedAt,i=l);if(!i)break;const m=Ne.get(i);m!=null&&m.url&&URL.revokeObjectURL(m.url),Ne.delete(i)}}async function Mr(a,t,i){if(!a.length)return;let u=0;async function m(){for(;;){const w=u;if(u+=1,w>=a.length)return;await i(a[w])}}const l=Array.from({length:Math.min(t,a.length)},()=>m());await Promise.all(l)}function _(...a){return a.filter(Boolean).join(" ")}function kt(a){if(typeof a=="boolean")return a;if(typeof a=="number")return a===1;if(typeof a=="string"){const t=a.trim().toLowerCase();return t==="true"||t==="1"||t==="owner"||t==="yes"}return!1}function wt(a){if(!a)return"—";const t=new Date(a);if(Number.isNaN(t.getTime()))return"—";try{return new Intl.DateTimeFormat(void 0,{year:"numeric",month:"short",day:"2-digit"}).format(t)}catch(i){return t.toISOString().slice(0,10)}}function vt(a){const t=String(a!=null?a:"").trim().toLowerCase();return t?t.includes("done")||t.includes("finished")||t.includes("complete")||t.includes("success")?_("border-emerald-300/80 bg-emerald-50 text-emerald-800","dark:border-emerald-700 dark:bg-emerald-950/30 dark:text-emerald-200"):t.includes("running")||t.includes("active")||t.includes("progress")||t.includes("queue")?_("border-sky-300/80 bg-sky-50 text-sky-800","dark:border-sky-700 dark:bg-sky-950/30 dark:text-sky-200"):t.includes("warn")||t.includes("hold")||t.includes("pending")||t.includes("pause")?_("border-amber-300/80 bg-amber-50 text-amber-800","dark:border-amber-700 dark:bg-amber-950/30 dark:text-amber-200"):t.includes("fail")||t.includes("error")||t.includes("stopped")||t.includes("aborted")||t.includes("failed")||t.includes("abort")?_("border-rose-300/80 bg-rose-50 text-rose-800","dark:border-rose-700 dark:bg-rose-950/30 dark:text-rose-200"):_("border-violet-300/80 bg-violet-50 text-violet-800","dark:border-violet-700 dark:bg-violet-950/30 dark:text-violet-200"):_("border-gray-300/80 bg-white/90 text-gray-700","dark:border-gray-700 dark:bg-slate-800 dark:text-gray-200")}function $e(a,t){const i=new URL(a,window.location.origin);return Object.entries(t).forEach(([u,m])=>{if(m==null)return;const l=String(m).trim();l&&i.searchParams.set(u,l)}),i.toString()}const Fe="subpixel-antialiased [text-rendering:optimizeLegibility]";function _r(a){const{id:t,label:i,badgeValue:u,createdAt:m,updatedAt:l,diskUsage:w,isSelected:P,onSelect:E,description:j="",status:D,icon:N=e.jsx(qt,{className:"h-5 w-5 text-gray-900 dark:text-white"}),onDelete:I,onRename:A,onShare:v,isShared:k,isOwner:O,permission:C,thumbnailUrl:y,thumbnailRebuildUrl:x,thumbnailItemsUrl:M,thumbnailVersion:L}=a,z=Kt(),p=We(),[B,F]=r.useState(!1),[W,q]=r.useState(i),[G,ee]=r.useState(j),[Q,n]=r.useState(!1),[d,g]=r.useState(""),[T,Y]=r.useState({open:!1,x:0,y:0}),s=r.useRef(null),h=r.useRef([]),b=typeof document!="undefined"?document.body:null,f=kt(O),Z=!!(kt(k)&&!f),K=f,[ue,de]=r.useState([]),[ce,me]=r.useState(!1),[xe,ke]=r.useState(!1),[De,we]=r.useState(!1),[be,fe]=r.useState(null),[Me,Ce]=r.useState(!1),[_e,ve]=r.useState(!1),je=r.useRef(null),[ge,Mt]=r.useState(!1),_t=r.useMemo(()=>`P${String(t)}`,[t]),Lt=r.useMemo(()=>Z?C!=null&&C.trim()?`Shared · ${C}`:"Shared":C!=null&&C.trim()?C:f?"Owner":"Private",[Z,C,f]),Ge=r.useMemo(()=>{var c;return String((c=D!=null?D:u)!=null?c:"").trim()||null},[D,u]),tt=r.useCallback(async o=>{const c=p.resolveBackendUrl(o);if(!c)return null;const S=Qe(c);if(S)return S;const R=Ye.get(c);if(R)return R;const $=p.fetchBlobObjectUrl(c,{cache:"no-store"}).then(U=>(yt(c,U),U)).catch(()=>null).finally(()=>{Ye.delete(c)});return Ye.set(c,$),$},[p]);r.useEffect(()=>{q(i),ee(j||"")},[i,j]),r.useEffect(()=>{if(ge||!je.current)return;const o=new IntersectionObserver(c=>{c.some(R=>R.isIntersecting||R.intersectionRatio>0)&&(Mt(!0),o.disconnect())},{root:null,rootMargin:"240px 0px",threshold:.01});return o.observe(je.current),()=>{o.disconnect()}},[ge]),r.useEffect(()=>{let o=!1;const c=new AbortController;async function S(){if(!(!ge||!M)){me(!0),we(!1);try{fe(null),ve(!1);const R=[String(t),String(M!=null?M:""),String(L!=null?L:""),"size=320","maxProtocols=12","maxOutputsPerProtocol=4"].join("|");let $=[];const U=pt.get(R);if(U&&Date.now()-U.ts<Ir&&U.data.length>0)$=U.data;else{const X=p.resolveBackendUrl(M),te=X?$e(X,{v:L!=null?L:""}):M;$=await p.fetchProjectThumbnailItems(t,{sourceUrl:te,size:320,maxProtocols:12,maxOutputsPerProtocol:4,signal:c.signal,cache:"no-store"})}if(o)return;if(!$.length){de([]),ke(!1),we(!1);return}pt.set(R,{ts:Date.now(),data:$});const V=$.map(X=>({...X,outputs:(X.outputs||[]).map(te=>{const ae=p.resolveBackendUrl(te.thumbnailUrl),J=ae?$e(ae,{size:320,v:L!=null?L:""}):null,le=J?Qe(J):null;return{...te,src:le,hasError:!J}})}));de(V),ke(!0);const re=V.flatMap((X,te)=>X.outputs.map((ae,J)=>{var le;return{groupIndex:te,outputIndex:J,requestUrl:ae.thumbnailUrl?$e((le=p.resolveBackendUrl(ae.thumbnailUrl))!=null?le:"",{size:320,v:L!=null?L:""}):null}}));await Mr(re,6,async X=>{if(!X.requestUrl){if(o)return;de(ae=>ae.map((J,le)=>le!==X.groupIndex?J:{...J,outputs:J.outputs.map((Pe,Xe)=>Xe!==X.outputIndex?Pe:{...Pe,src:null,hasError:!0})}));return}const te=await tt(X.requestUrl);o||de(ae=>ae.map((J,le)=>le!==X.groupIndex?J:{...J,outputs:J.outputs.map((Pe,Xe)=>Xe!==X.outputIndex?Pe:{...Pe,src:te,hasError:!te})}))})}catch(R){if(c.signal.aborted||o)return;de([]),we(!0)}finally{o||(me(!1),ke(!1))}}}return S(),()=>{o=!0,c.abort()}},[t,ge,M,p,L,tt]);const rt=r.useMemo(()=>ue.some(o=>(o.outputs||[]).some(c=>!!c.src)),[ue]),at=!!M,st=r.useMemo(()=>!(!y||at||ce||xe||rt),[y,at,ce,xe,rt]);r.useEffect(()=>{let o=!1;async function c(){if(!(!ge||!st||!y)){Ce(!0),ve(!1);try{const S=p.resolveBackendUrl(y),R=S?$e(S,{size:960,v:L!=null?L:""}):null;if(!R)throw new Error("Project thumbnail is not available");const $=Qe(R);if($){o||fe($);return}const U=await p.fetchBlobObjectUrl(R,{cache:"no-store"});o||(yt(R,U),fe(U))}catch(S){o||(fe(null),ve(!0))}finally{o||Ce(!1)}}}return c(),()=>{o=!0}},[t,ge,st,y,p,L]);const Se=r.useCallback(()=>{B||z(`/project/load/${t}`)},[t,B,z]),Rt=r.useCallback(()=>{Se()},[Se]),nt=r.useCallback(()=>{q(i),ee(j||""),F(!0),g("")},[i,j]),ot=r.useCallback(()=>{n(!0)},[]),lt=r.useCallback(()=>{K&&(v==null||v(t))},[K,t,v]),Ut=r.useCallback(async()=>{try{await p.deleteProject(String(t)),ne.success(`Project "${i}" deleted successfully`),n(!1),I==null||I(t)}catch(o){ne.error((o==null?void 0:o.message)||"Error deleting project")}},[p,t,i,I]),it=r.useCallback(async()=>{if(!W.trim()){g("Project name cannot be empty.");return}if(G&&G.trim().length>0&&G.trim().length<3){g("Description must be at least 3 characters.");return}try{await p.renameProject(String(t),W.trim(),(G||"").trim()),ne.success("Project renamed successfully"),F(!1),g(""),A==null||A(t,W.trim(),(G||"").trim())}catch(o){ne.error((o==null?void 0:o.message)||"Failed to rename project"),g("Failed to update project.")}},[p,t,W,G,A]),oe=r.useCallback(()=>{Y(o=>o.open?{...o,open:!1}:o)},[]),At=r.useCallback(o=>{if(B||Q)return;o.preventDefault(),o.stopPropagation(),E==null||E();const c=8,S=192,R=196,$=window.innerWidth,U=window.innerHeight,V=o.clientX,re=o.clientY,X=Math.max(c,Math.min(V,$-S-c)),te=Math.max(c,Math.min(re,U-R-c));Y({open:!0,x:X,y:te})},[B,Q,E]),Le=r.useCallback(o=>c=>{h.current[o]=c},[]),Re=o=>c=>{if(o)return;const S=c.currentTarget;document.activeElement!==S&&S.focus()},Ue=(o,c)=>S=>{S.preventDefault(),S.stopPropagation(),!o&&(c==null||c(),oe())},Ot=r.useCallback(o=>{const c=h.current.filter(Boolean);if(!c.length)return;const S=U=>(U==null?void 0:U.dataset.disabled)==="true",R=c.findIndex(U=>U===document.activeElement),$=U=>{let V=R;for(let re=0;re<c.length;re++)if(V=(V+U+c.length)%c.length,!S(c[V])){c[V].focus();break}};switch(o.key){case"ArrowDown":o.preventDefault(),$(1);break;case"ArrowUp":o.preventDefault(),$(-1);break;case"Home":{o.preventDefault();const U=c.find(V=>!S(V));U==null||U.focus();break}case"End":{o.preventDefault();for(let U=c.length-1;U>=0;U--)if(!S(c[U])){c[U].focus();break}break}case"Escape":o.preventDefault(),oe();break}},[oe]);r.useEffect(()=>{(B||Q)&&oe()},[B,Q,oe]),r.useEffect(()=>{if(!T.open)return;const o=R=>{const $=R.target;$&&s.current&&!s.current.contains($)&&oe()},c=R=>{R.key==="Escape"&&oe()},S=()=>oe();return window.addEventListener("pointerdown",o,!0),window.addEventListener("keydown",c,!0),window.addEventListener("scroll",S,!0),window.addEventListener("wheel",S,!0),window.addEventListener("touchmove",S,!0),()=>{window.removeEventListener("pointerdown",o,!0),window.removeEventListener("keydown",c,!0),window.removeEventListener("scroll",S,!0),window.removeEventListener("wheel",S,!0),window.removeEventListener("touchmove",S,!0)}},[T.open,oe]),r.useEffect(()=>{T.open&&queueMicrotask(()=>{const c=h.current.filter(Boolean).find(S=>S.dataset.disabled!=="true");c==null||c.focus()})},[T.open]);const Tt=_(Fe,"relative min-h-[248px] cursor-pointer overflow-hidden rounded-[22px] border p-4 transition-all duration-300 md:p-5","border-slate-200/90 bg-[radial-gradient(circle_at_top_right,rgba(99,102,241,0.10),transparent_26%),linear-gradient(145deg,rgba(255,255,255,0.98),rgba(248,250,252,0.96))]","shadow-[0_12px_40px_rgba(15,23,42,0.07)] border-slate-300 hover:border-slate-500","dark:border-slate-800 dark:bg-[radial-gradient(circle_at_top_right,rgba(99,102,241,0.16),transparent_24%),linear-gradient(145deg,rgba(15,23,42,0.96),rgba(2,6,23,0.98))]",P?"":"hover:border-slate-300 dark:hover:border-slate-700 ",!B&&!P?"hover:-translate-y-0.5 hover:shadow-[0_20px_50px_rgba(15,23,42,0.12)]":"","active:border-indigo-500/45 active:ring-2 active:ring-inset active:ring-indigo-500/12",P?"border-indigo-500/55 ring-2 ring-inset ring-indigo-500/14":""),Ve=ue.length>0,Bt=Ve,zt=!!be&&!Ve&&!ce&&!xe,$t=!Ve&&ce,Ft=r.useCallback(o=>{const c=Math.max(1,o);return c===1?240:c===2?480:c===3?624:c===4?880:1188+(c-4)*260},[]);return e.jsxs(e.Fragment,{children:[e.jsx(Te.div,{ref:je,initial:{opacity:0,y:14},animate:{opacity:1,y:0},transition:{duration:.22,ease:"easeOut"},className:"relative",children:e.jsxs("div",{tabIndex:0,onClick:E,onDoubleClick:Rt,onContextMenu:At,className:Tt,children:[e.jsxs("div",{className:"pointer-events-none absolute inset-0",children:[e.jsx("div",{className:"absolute inset-x-0 top-0 h-px bg-gradient-to-r from-transparent via-indigo-400/40 to-transparent"}),e.jsx("div",{className:"absolute -right-12 -top-12 h-32 w-32 rounded-full bg-indigo-300/25 blur-3xl dark:bg-indigo-500/12"}),e.jsx("div",{className:"absolute -left-8 bottom-4 h-24 w-24 rounded-full bg-cyan-200/30 blur-3xl dark:bg-cyan-500/10"}),e.jsx("div",{className:"absolute inset-x-0 bottom-0 h-24 bg-gradient-to-t from-white/55 to-transparent dark:from-slate-950/20 dark:to-transparent"})]}),e.jsxs("div",{className:"relative flex h-full flex-col",children:[e.jsx("div",{className:_("-mx-4 -mt-4 mb-0 rounded-t-[22px] border-b px-4 pb-3.5 pt-4 md:-mx-5 md:-mt-7 md:px-5 md:pt-5","border-slate-200/80 bg-[linear-gradient(180deg,rgba(255,255,255,0.98),rgba(248,250,252,0.92))]","dark:border-slate-800 dark:bg-[linear-gradient(180deg,rgba(15,23,42,0.92),rgba(2,6,23,0.78))]"),children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-start gap-3",children:[e.jsx("div",{className:_("flex h-11 w-11 shrink-0 items-center justify-center rounded-[16px] border shadow-sm","border-white/80 bg-[linear-gradient(145deg,rgba(255,255,255,1),rgba(238,242,255,0.95))]","dark:border-slate-700 dark:bg-[linear-gradient(145deg,rgba(30,41,59,0.96),rgba(15,23,42,0.96))]"),children:N}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"mb-1.5 flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:_("inline-flex items-center rounded-full border px-2.5 py-0.5 text-[10px] font-semibold tracking-[0.08em]","border-indigo-300/80 bg-indigo-50 text-indigo-800","dark:border-indigo-700 dark:bg-indigo-950/30 dark:text-indigo-200"),children:_t}),e.jsx("span",{className:_("inline-flex items-center rounded-full border px-2.5 py-0.5 text-[10px] font-semibold","border-slate-300/80 bg-white/90 text-slate-700","dark:border-slate-700 dark:bg-slate-800 dark:text-slate-200"),children:Lt}),Z?e.jsx("span",{className:"shrink-0 rounded-full border border-sky-300/80 bg-sky-50 px-2.5 py-0.5 text-[10px] font-semibold text-sky-800 dark:border-sky-700 dark:bg-sky-950/30 dark:text-sky-200",children:"Guest"}):null,Ge?e.jsx("span",{className:_("shrink-0 rounded-full border px-2.5 py-0.5 text-[10px] font-semibold",vt(Ge)),children:Ge}):null]}),e.jsx("div",{className:"flex min-w-0 items-center gap-2",children:e.jsx("span",{className:"truncate text-[16px] font-semibold leading-5 tracking-[0.01em] text-slate-950 dark:text-white",title:i,children:W})})]})]}),e.jsx("div",{className:"shrink-0 pt-0.5",children:e.jsx(Er,{icon:null,label:"",onOpen:Se,onRename:K?nt:void 0,onRemove:K?ot:void 0,onShare:K?lt:void 0})})]})}),e.jsx("div",{className:"mt-3",children:e.jsx("div",{className:_("overflow-hidden rounded-[20px] border","border-slate-200/80 bg-[linear-gradient(180deg,rgba(255,255,255,0.88),rgba(248,250,252,0.96))]","shadow-[inset_0_1px_0_rgba(255,255,255,0.65),0_10px_24px_rgba(15,23,42,0.06)]","dark:border-slate-800 dark:bg-[linear-gradient(180deg,rgba(15,23,42,0.56),rgba(2,6,23,0.82))]"),children:e.jsx("div",{className:"relative h-[268px] w-full bg-slate-50/80 dark:bg-slate-900/70",children:$t?e.jsx("div",{className:"h-full overflow-hidden px-2.5 py-2.5",children:e.jsx("div",{className:"flex h-full min-w-max items-stretch gap-2.5",children:Array.from({length:4}).map((o,c)=>e.jsxs("div",{className:_("h-full w-[284px] shrink-0 overflow-hidden rounded-[18px] border","border-slate-200/80 bg-white/95","dark:border-slate-800 dark:bg-slate-950/90"),children:[e.jsx("div",{className:"h-[34px] border-b border-slate-200/80 bg-slate-50 dark:border-slate-800 dark:bg-slate-900"}),e.jsx("div",{className:"h-[calc(100%-34px)] animate-pulse bg-gradient-to-br from-slate-100 via-slate-50 to-slate-100 dark:from-slate-800 dark:via-slate-900 dark:to-slate-800"})]},c))})}):Bt?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 z-[1] w-8 bg-gradient-to-r from-gray-50 via-gray-50/90 to-transparent dark:from-slate-900 dark:via-slate-900/90 dark:to-transparent"}),e.jsx("div",{className:"pointer-events-none absolute inset-y-0 right-0 z-[1] w-8 bg-gradient-to-l from-gray-50 via-gray-50/90 to-transparent dark:from-slate-900 dark:via-slate-900/90 dark:to-transparent"}),e.jsx("div",{className:"h-full overflow-x-auto overflow-y-hidden px-3 py-3 [scrollbar-width:thin]",children:e.jsx("div",{className:"flex h-full min-w-max items-stretch gap-3",children:ue.map(o=>{var R,$,U;const c=(R=o.outputs)!=null?R:[],S=c.length;return e.jsx("div",{className:"group h-full shrink-0",style:{width:`${Ft(S)}px`},title:($=o.label)!=null?$:`Protocol ${String(o.protocolId)}`,children:e.jsxs("div",{className:_("grid h-full grid-rows-[auto,1fr,auto] overflow-hidden rounded-[20px] border transition","border-gray-200/90 bg-white shadow-[0_8px_24px_rgba(15,23,42,0.08)]","dark:border-slate-800 dark:bg-slate-950 dark:shadow-[0_8px_24px_rgba(0,0,0,0.26)]","group-hover:-translate-y-0.5 group-hover:shadow-[0_14px_30px_rgba(15,23,42,0.14)]"),children:[e.jsx("div",{className:_("flex items-center justify-between gap-2 border-b px-3 py-1.5","border-gray-200/80 bg-gray-50","dark:border-slate-800 dark:bg-slate-900"),children:e.jsx("div",{className:"truncate text-[12px]  text-gray-800 dark:text-slate-200",children:(U=o.label)!=null?U:`Protocol ${String(o.protocolId)}`})}),e.jsx("div",{className:"min-h-0 p-2",children:e.jsx("div",{className:"flex h-full items-stretch gap-2",children:c.map((V,re)=>{var X,te,ae,J,le;return e.jsx("div",{className:_("min-w-0 flex-1 overflow-hidden rounded-[14px] border","border-gray-200 bg-gray-50","dark:border-slate-800 dark:bg-slate-900"),title:(te=(X=V.outputName)!=null?X:V.outputClassName)!=null?te:"Output",children:V.src?e.jsx("img",{src:V.src,alt:(J=(ae=V.outputName)!=null?ae:V.outputClassName)!=null?J:"Output",className:"block h-full w-full object-contain",draggable:!1}):e.jsx("div",{className:"h-full w-full animate-pulse bg-gradient-to-br from-slate-100 via-slate-50 to-slate-100 dark:from-slate-800 dark:via-slate-900 dark:to-slate-800"})},`${String(o.protocolId)}-${(le=V.outputName)!=null?le:re}`)})})}),e.jsx("div",{className:_("border-t px-3 py-1.5","border-gray-200/80 bg-white","dark:border-slate-800 dark:bg-slate-950"),children:o.status?e.jsx("span",{className:_("inline-flex max-w-[96px] items-center truncate rounded-full border px-2 py-0.5 text-[12px]",vt(o.status)),children:o.status}):null})]})},String(o.protocolId))})})})]}):zt?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 z-[1] w-8 bg-gradient-to-r from-slate-50 via-slate-50/90 to-transparent dark:from-slate-900 dark:via-slate-900/90 dark:to-transparent"}),e.jsx("div",{className:"pointer-events-none absolute inset-y-0 right-0 z-[1] w-8 bg-gradient-to-l from-slate-50 via-slate-50/90 to-transparent dark:from-slate-900 dark:via-slate-900/90 dark:to-transparent"}),e.jsx("div",{className:"h-full overflow-x-auto overflow-y-hidden px-2.5 py-2.5 [scrollbar-width:thin]",children:e.jsx("div",{className:"flex h-full min-w-max items-stretch",children:e.jsx("div",{className:_("h-full overflow-hidden rounded-[18px] border","border-slate-200/90 bg-white/95 shadow-[0_10px_28px_rgba(15,23,42,0.08)]","dark:border-slate-800 dark:bg-slate-950/95 dark:shadow-[0_12px_28px_rgba(0,0,0,0.24)]"),children:e.jsx("img",{src:be!=null?be:void 0,alt:`${i} thumbnail`,className:"block h-full w-auto max-w-none",draggable:!1})})})})]}):e.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center text-sm text-slate-500 dark:text-slate-400",children:Me?"Loading preview...":De||_e?"Preview not available":"No thumbnails yet"})})})}),e.jsx("div",{className:"mt-auto pt-3",children:e.jsxs("div",{className:_("flex flex-wrap items-center justify-between gap-2.5 border-t pt-3","border-slate-200/80 dark:border-slate-800"),children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[13px]",children:[l?e.jsxs("span",{className:_("inline-flex items-center gap-2 rounded-full border px-3 py-1.25","border-slate-200 bg-white/88 text-slate-700","dark:border-slate-800 dark:bg-slate-900/88 dark:text-slate-300"),children:[e.jsx(mt,{className:"h-3.5 w-3.5 text-violet-600 dark:text-violet-300"}),e.jsx("span",{className:"text-slate-500 dark:text-slate-400",children:"Updated"}),e.jsx("span",{className:"font-semibold text-slate-900 dark:text-white",children:wt(l)})]}):m?e.jsxs("span",{className:_("inline-flex items-center gap-2 rounded-full border px-3 py-1.25","border-slate-200 bg-white/88 text-slate-700","dark:border-slate-800 dark:bg-slate-900/88 dark:text-slate-300"),children:[e.jsx(mt,{className:"h-3.5 w-3.5 text-indigo-600 dark:text-indigo-300"}),e.jsx("span",{className:"text-slate-500 dark:text-slate-400",children:"Created"}),e.jsx("span",{className:"font-semibold text-slate-900 dark:text-white",children:wt(m)})]}):null,w?e.jsxs("span",{className:_("inline-flex items-center gap-2 rounded-full border px-3 py-1.25","border-slate-200 bg-white/88 text-slate-700","dark:border-slate-800 dark:bg-slate-900/88 dark:text-slate-300"),children:[e.jsx(cr,{className:"h-3.5 w-3.5 text-cyan-700 dark:text-cyan-300"}),e.jsx("span",{className:"font-semibold text-slate-900 dark:text-white",children:w})]}):null]}),e.jsxs("button",{type:"button",onClick:o=>{o.preventDefault(),o.stopPropagation(),Se()},className:_("inline-flex items-center gap-2 rounded-[12px] px-4 py-2 text-[13px] font-semibold transition-all duration-200","bg-[linear-gradient(135deg,rgba(79,70,229,1),rgba(14,165,233,1),rgba(6,182,212,1))] text-white shadow-[0_10px_24px_rgba(59,130,246,0.28)]","hover:-translate-y-0.5 hover:brightness-[1.02] hover:shadow-[0_16px_30px_rgba(59,130,246,0.32)]"),children:[e.jsx(et,{className:"h-4 w-4"}),"Open project"]})]})})]}),e.jsx(bt,{children:B&&e.jsx(Te.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.15},className:_(Fe,"absolute inset-0 z-20 overflow-hidden rounded-[28px] border","border-gray-300/90 bg-white","dark:border-gray-700 dark:bg-slate-900"),role:"dialog","aria-modal":"true",onClick:o=>o.stopPropagation(),onKeyDown:o=>{var S;o.key==="Escape"&&F(!1);const c=(S=o.target)==null?void 0:S.tagName;o.key==="Enter"&&c!=="TEXTAREA"&&(o.preventDefault(),it())},children:e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-gray-300/80 px-4 py-3 dark:border-gray-700",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-xl border border-gray-300/80 bg-gray-100 dark:border-gray-700 dark:bg-slate-800",children:N}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-gray-950 dark:text-white",children:"Rename project"}),e.jsx("div",{className:"truncate text-sm text-gray-700 dark:text-gray-300",children:i})]})]}),e.jsx("button",{type:"button",onClick:()=>F(!1),className:_("inline-flex h-9 w-9 items-center justify-center rounded-xl border transition","border-gray-300/80 bg-white text-gray-800 hover:shadow-sm","dark:border-gray-700 dark:bg-slate-900 dark:text-gray-200"),"aria-label":"Close",children:e.jsx(qe,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-auto px-4 py-4",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("label",{className:"text-sm font-medium text-gray-800 dark:text-gray-300",children:["Name",e.jsx("input",{type:"text",value:W,onChange:o=>q(o.target.value),placeholder:"Project name",className:_(Fe,"mt-1 w-full rounded-xl border px-3 py-2.5 text-sm font-medium outline-none","border-gray-300/80 bg-white text-gray-950","focus:border-indigo-500/40 focus:ring-2 focus:ring-indigo-500/10","dark:border-gray-700 dark:bg-slate-900 dark:text-white"),autoFocus:!0})]}),e.jsxs("label",{className:"text-sm font-medium text-gray-800 dark:text-gray-300",children:["Description",e.jsx("textarea",{value:G,onChange:o=>ee(o.target.value),placeholder:"Project description",rows:4,className:_(Fe,"mt-1 w-full rounded-xl border px-3 py-2.5 text-sm leading-6 outline-none","border-gray-300/80 bg-white text-gray-950","focus:border-indigo-500/40 focus:ring-2 focus:ring-indigo-500/10","dark:border-gray-700 dark:bg-slate-900 dark:text-white")})]}),d?e.jsx("div",{className:"rounded-xl border border-red-200/80 bg-red-50 px-3 py-2 text-sm leading-6 text-red-700 dark:border-red-900/50 dark:bg-red-950/30 dark:text-red-200",children:d}):null]})}),e.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-gray-300/80 bg-white px-4 py-3 dark:border-gray-700 dark:bg-slate-900",children:[e.jsx("button",{type:"button",onClick:()=>F(!1),className:_("rounded-xl border px-4 py-2 text-sm font-semibold transition","border-gray-300/80 bg-white text-gray-800 hover:shadow-sm","dark:border-gray-700 dark:bg-slate-900 dark:text-gray-200"),children:"Cancel"}),e.jsx("button",{type:"button",onClick:it,className:"rounded-xl bg-gradient-to-r from-indigo-600 via-sky-600 to-cyan-600 px-4 py-2 text-sm font-semibold text-white shadow-sm transition hover:brightness-[0.98] hover:shadow-md",children:"Save"})]})]})})})]})}),T.open&&b?Nt.createPortal(e.jsx("div",{className:"fixed inset-0 z-[9999]",onClick:o=>{o.preventDefault(),o.stopPropagation(),oe()},onContextMenu:o=>{o.preventDefault(),o.stopPropagation(),oe()},children:e.jsx("div",{ref:s,role:"menu",tabIndex:-1,onKeyDown:Ot,className:"fixed w-48 overflow-hidden rounded-xl border border-gray-300/90 bg-white shadow-2xl dark:border-gray-700 dark:bg-slate-900",style:{left:T.x,top:T.y},onClick:o=>{o.preventDefault(),o.stopPropagation()},onContextMenu:o=>{o.preventDefault(),o.stopPropagation()},children:(()=>{const c=!K,S=!K,R=!K,$="flex items-center gap-2 px-4 py-2.5 outline-none text-sm",U="cursor-pointer transition hover:bg-gray-50 focus:bg-gray-100 dark:hover:bg-slate-800/70 dark:focus:bg-slate-800/70",V="cursor-not-allowed opacity-50 text-gray-400 dark:text-gray-500",re=X=>_($,X?V:U);return e.jsxs("ul",{className:"py-1 text-gray-800 dark:text-gray-200",children:[e.jsxs("li",{ref:Le(0),tabIndex:-1,role:"menuitem","aria-disabled":!1,"data-disabled":"false",className:re(!1),onPointerMove:Re(!1),onClick:Ue(!1,Se),children:[e.jsx(et,{className:"h-5 w-5 text-gray-700 dark:text-gray-200"}),e.jsx("span",{children:"Open"})]}),e.jsxs("li",{ref:Le(1),tabIndex:-1,role:"menuitem","aria-disabled":c,"data-disabled":c?"true":"false",className:re(c),onPointerMove:Re(c),onClick:Ue(c,nt),children:[e.jsx(Et,{className:_("h-5 w-5",c?"text-gray-400 dark:text-gray-500":"text-gray-700 dark:text-gray-200")}),e.jsx("span",{children:"Rename"})]}),e.jsxs("li",{ref:Le(2),tabIndex:-1,role:"menuitem","aria-disabled":S,"data-disabled":S?"true":"false",className:re(S),onPointerMove:Re(S),onClick:Ue(S,lt),children:[e.jsx(Dt,{className:_("h-4 w-4",S?"text-gray-400 dark:text-gray-500":"text-gray-700 dark:text-gray-200")}),e.jsx("span",{children:"Share"})]}),e.jsxs("li",{ref:Le(3),tabIndex:-1,role:"menuitem","aria-disabled":R,"data-disabled":R?"true":"false",className:_(re(R),R?"":"hover:bg-red-50 focus:bg-red-50 dark:hover:bg-red-950/20 dark:focus:bg-red-950/20"),onPointerMove:Re(R),onClick:Ue(R,ot),children:[e.jsx(Ct,{className:_("h-5 w-5",R?"text-gray-400 dark:text-gray-500":"text-red-700 dark:text-red-300")}),e.jsx("span",{className:R?void 0:"text-red-700 dark:text-red-300",children:"Remove"})]})]})})()})}),b):null,e.jsx(bt,{children:Q&&e.jsx(Te.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center bg-black/35",role:"dialog","aria-modal":"true",onClick:()=>n(!1),children:e.jsxs(Te.div,{initial:{scale:.96,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.96,opacity:0},transition:{duration:.18},className:"w-full max-w-sm rounded-2xl border border-gray-300/90 bg-white p-6 shadow-2xl subpixel-antialiased dark:border-gray-700 dark:bg-slate-900",onClick:o=>o.stopPropagation(),children:[e.jsx("h2",{className:"mb-4 text-lg font-semibold text-gray-950 dark:text-white",children:"Delete project?"}),e.jsxs("p",{className:"mb-6 text-sm leading-6 text-gray-800 dark:text-gray-200",children:["This action cannot be undone. Are you sure you want to delete ",e.jsx("strong",{children:i}),"?"]}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{type:"button",onClick:()=>n(!1),className:"rounded-xl border border-gray-300/80 bg-white px-4 py-2 text-sm font-semibold text-gray-800 hover:shadow-sm dark:border-gray-700 dark:bg-slate-900 dark:text-gray-200",children:"Cancel"}),e.jsx("button",{type:"button",onClick:Ut,className:"rounded-xl bg-gradient-to-r from-red-600 via-rose-600 to-orange-600 px-4 py-2 text-sm font-semibold text-white transition hover:brightness-[0.98] hover:shadow-md",children:"Delete"})]})]})})})]})}function pe(...a){return a.filter(Boolean).join(" ")}const He="subpixel-antialiased [text-rendering:optimizeLegibility]";function Lr({open:a,onClose:t,onCreate:i}){const u=We(),[m,l]=r.useState(""),[w,P]=r.useState(""),[E,j]=r.useState(!1),[D,N]=r.useState(""),I=r.useRef(null),A=r.useRef(null);r.useEffect(()=>{a||(l(""),P(""),j(!1),N(""))},[a]),r.useEffect(()=>{a&&queueMicrotask(()=>{var x;return(x=A.current)==null?void 0:x.focus()})},[a]);const v=r.useCallback(()=>{const x=m.trim();return x?x.length<2?(N("Project name must be at least 2 characters."),!1):x.length>120?(N("Project name is too long (max 120)."),!1):(N(""),!0):(N("Project name is required."),!1)},[m]),k=r.useCallback(async()=>{if(v()){j(!0);try{const x=await u.createProject({name:m.trim(),description:w.trim()});ne.success(`Project "${m}" created successfully`),i==null||i(x),t()}catch(x){console.error("Failed to create project",x),ne.error((x==null?void 0:x.message)||"Failed to create project")}finally{j(!1)}}},[u,m,w,i,t,v]),O=r.useCallback(x=>{I.current&&!I.current.contains(x.target)&&t()},[t]),C=r.useCallback(x=>{x.key==="Escape"&&(x.stopPropagation(),t())},[t]),y=x=>{x.key==="Enter"&&!(x.shiftKey||x.ctrlKey||x.metaKey)&&(x.preventDefault(),k())};return a?e.jsx("div",{className:pe(He,"fixed inset-0 z-50 flex items-center justify-center"),onMouseDown:O,onKeyDown:C,role:"dialog","aria-modal":"true","aria-labelledby":"new-project-title","aria-describedby":"new-project-desc",children:e.jsx("div",{ref:I,className:pe(He,"relative w-full max-w-md overflow-hidden rounded-2xl border p-5 shadow-2xl","border-gray-300/90 bg-white","ring-1 ring-inset ring-black/[0.08]","dark:border-gray-700 dark:bg-slate-900","dark:ring-white/[0.08]"),onMouseDown:x=>x.stopPropagation(),children:e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"mb-4 flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-11 w-11 items-center justify-center rounded-xl border border-gray-300/80 bg-gray-100 text-gray-800 dark:border-gray-700 dark:bg-slate-800 dark:text-gray-200",children:e.jsx(It,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h3",{id:"new-project-title",className:"text-[15px] font-semibold tracking-[0.01em] text-gray-950 dark:text-white",children:"New project"}),e.jsx("p",{id:"new-project-desc",className:"text-sm leading-6 text-gray-700 dark:text-gray-300",children:"Create a new project with a name and optional description."})]})]}),e.jsx("button",{type:"button",onClick:t,disabled:E,className:pe("inline-flex items-center justify-center rounded-xl border p-2 transition","border-gray-300/80 bg-white text-gray-800 hover:shadow-sm","dark:border-gray-700 dark:bg-slate-900 dark:text-gray-200",E?"opacity-60":""),"aria-label":"Close",children:e.jsx(qe,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("label",{className:"text-sm font-medium text-gray-800 dark:text-gray-200",children:["Name ",e.jsx("span",{className:"text-red-500",children:"*"}),e.jsx("input",{ref:A,value:m,onChange:x=>l(x.target.value),onKeyDown:y,placeholder:"Project name",className:pe(He,"mt-1 w-full rounded-xl border px-3 py-2.5 text-sm font-medium outline-none transition","border-gray-300/80 bg-white text-gray-950 placeholder:text-gray-400","focus:border-indigo-500/40 focus:ring-2 focus:ring-indigo-500/10","dark:border-gray-700 dark:bg-slate-900 dark:text-white dark:placeholder:text-gray-500"),"aria-invalid":!!D,"aria-describedby":D?"new-project-error":void 0,maxLength:120})]}),e.jsxs("label",{className:"text-sm font-medium text-gray-800 dark:text-gray-200",children:["Description ",e.jsx("span",{className:"font-medium text-gray-400",children:"(optional)"}),e.jsx("textarea",{value:w,onChange:x=>P(x.target.value),onKeyDown:y,placeholder:"A short description",className:pe(He,"mt-1 w-full rounded-xl border px-3 py-2.5 text-sm leading-6 outline-none transition","border-gray-300/80 bg-white text-gray-950 placeholder:text-gray-400","focus:border-indigo-500/40 focus:ring-2 focus:ring-indigo-500/10","dark:border-gray-700 dark:bg-slate-900 dark:text-white dark:placeholder:text-gray-500"),rows:3,maxLength:2e3})]}),D&&e.jsx("div",{id:"new-project-error",className:"rounded-xl border border-red-200/80 bg-red-50 px-3 py-2 text-sm leading-6 text-red-700 dark:border-red-900/50 dark:bg-red-950/30 dark:text-red-200",children:D}),e.jsxs("div",{className:"mt-2 flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:t,disabled:E,className:pe("rounded-xl border px-4 py-2 text-sm font-semibold transition disabled:opacity-60","border-gray-300/80 bg-white text-gray-800 hover:shadow-sm","dark:border-gray-700 dark:bg-slate-900 dark:text-gray-200"),children:"Cancel"}),e.jsx("button",{type:"button",onClick:k,disabled:E,className:pe("rounded-xl px-4 py-2 text-sm font-semibold text-white transition disabled:opacity-60","bg-gradient-to-r from-indigo-600 via-sky-600 to-cyan-600 hover:brightness-[0.98] hover:shadow-md"),children:E?"Creating...":"Create"})]})]})]})})}):null}function ie(...a){return a.filter(Boolean).join(" ")}const Ze="subpixel-antialiased [text-rendering:optimizeLegibility]";function Rr({open:a,projectId:t,projectName:i,projectOwnerId:u,onClose:m}){const l=We(),[w,P]=r.useState([]),[E,j]=r.useState([]),[D,N]=r.useState(""),[I,A]=r.useState(!1),[v,k]=r.useState(!1),[O,C]=r.useState(""),[y,x]=r.useState(null),M=r.useRef(null),L=r.useCallback(()=>{P([]),j([]),N(""),A(!1),k(!1),C(""),x(null)},[]);r.useEffect(()=>{if(!a||!t){L();return}(async()=>{A(!0),C("");try{const[d,g]=await Promise.all([l.listUsers(),l.listProjectShares(String(t))]),T=Array.isArray(g)?g:(g==null?void 0:g.results)||(g==null?void 0:g.shares)||[],Y=new Set(T.map(b=>{var f,H,Z,K;return(K=(Z=(H=(f=b.userId)!=null?f:b.sharedUserId)!=null?H:b.shared_with_id)!=null?Z:b.targetUserId)!=null?K:b.user_id})),s=u!=null?String(u):null,h=d.map(b=>{var me,xe,ke,De,we,be,fe,Me,Ce,_e,ve,je;const f=(De=(ke=(xe=(me=b.id)!=null?me:b.pk)!=null?xe:b.username)!=null?ke:b.email)!=null?De:"",H=String(f),Z=(be=(we=b.firstName)!=null?we:b.first_name)!=null?be:void 0,K=(Me=(fe=b.lastName)!=null?fe:b.last_name)!=null?Me:void 0,ue=s!==null&&H===s,de=Y.has(f)||Y.has(H);let ce=(je=(ve=(_e=(Ce=b.name)!=null?Ce:b.fullName)!=null?_e:b.username)!=null?ve:b.email)!=null?je:"Unknown user";if(!b.name&&(Z||K)){const ge=`${Z!=null?Z:""} ${K!=null?K:""}`.trim();ge&&(ce=ge)}return{id:f,name:ce,email:b.email,firstName:Z,lastName:K,isOwner:ue,alreadyShared:de}});P(h)}catch(d){console.error("Failed to load users for sharing",d),C((d==null?void 0:d.message)||"Failed to load users."),P([])}finally{A(!1)}})()},[a,l,L,t,u]);const z=r.useMemo(()=>{const n=D.trim().toLowerCase();return n?w.filter(d=>{const g=String(d.name||"").toLowerCase(),T=String(d.email||"").toLowerCase();return g.includes(n)||T.includes(n)}):w},[w,D]),p=r.useCallback(n=>{j(d=>d.includes(n)?d.filter(g=>g!==n):[...d,n])},[]),B=r.useCallback(n=>{n.key==="Escape"&&(n.stopPropagation(),y?x(null):m())},[m,y]),F=r.useCallback(n=>{M.current&&!M.current.contains(n.target)&&m()},[m]),W=r.useCallback(async()=>{if(!t)return;const n=E.filter(d=>{const g=w.find(T=>String(T.id)===String(d));return!(!g||g.isOwner||g.alreadyShared)});if(!n.length){C("Select at least one new user.");return}k(!0),C("");try{await l.shareProject(String(t),n.map(d=>String(d))),ne.success("Project shared successfully"),m()}catch(d){console.error("Failed to share project",d),C((d==null?void 0:d.message)||"Failed to share project."),ne.error((d==null?void 0:d.message)||"Failed to share project")}finally{k(!1)}},[l,t,E,m,w]),q=r.useCallback(n=>{n.isOwner||(C(""),x(n))},[]),G=r.useCallback(()=>x(null),[]),ee=r.useCallback(async()=>{if(!t||!y)return;const n=y.email||y.name;k(!0);try{await l.revokeProjectShare(String(t),String(y.id)),ne.success(`Access revoked for ${n}`),P(d=>d.map(g=>String(g.id)===String(y.id)?{...g,alreadyShared:!1}:g)),j(d=>d.filter(g=>String(g)!==String(y.id))),x(null)}catch(d){console.error("Failed to revoke project share",d),ne.error((d==null?void 0:d.message)||"Failed to revoke project share")}finally{k(!1)}},[t,y,l]);if(!a)return null;const Q=E.length;return e.jsx("div",{className:ie(Ze,"fixed inset-0 z-50 flex items-center justify-center","bg-black/[0.02] dark:bg-white/[0.02]"),onMouseDown:F,onKeyDown:B,role:"dialog","aria-modal":"true","aria-labelledby":"share-project-title","aria-describedby":"share-project-desc",children:e.jsx("div",{ref:M,className:ie(Ze,"relative flex max-h-[82vh] w-full max-w-xl flex-col overflow-hidden rounded-2xl border shadow-2xl","border-gray-300/90 bg-white","ring-1 ring-inset ring-black/[0.08]","dark:border-gray-700 dark:bg-slate-900","dark:ring-white/[0.08]"),onMouseDown:n=>n.stopPropagation(),children:e.jsxs("div",{className:"relative flex h-full flex-col",children:[e.jsxs("div",{className:"flex items-start justify-between border-b border-gray-300/80 px-5 pb-3 pt-4 dark:border-gray-700",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-11 w-11 items-center justify-center rounded-xl border border-gray-300/80 bg-gray-100 text-gray-800 dark:border-gray-700 dark:bg-slate-800 dark:text-gray-200",children:e.jsx(wr,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h3",{id:"share-project-title",className:"text-[15px] font-semibold tracking-[0.01em] text-gray-950 dark:text-white",children:"Share project"}),e.jsxs("p",{id:"share-project-desc",className:"mt-1 text-sm leading-6 text-gray-700 dark:text-gray-300",children:["Share access to ",e.jsx("span",{className:"font-semibold",children:i||"this project"}),"."]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"hidden items-center gap-2 rounded-full border border-amber-300/80 bg-amber-50 px-3 py-1 text-xs font-semibold text-amber-800 dark:border-amber-700 dark:bg-amber-950/30 dark:text-amber-200 sm:inline-flex",children:[e.jsx(xt,{className:"h-4 w-4"}),"Owner only"]}),e.jsx("button",{type:"button",onClick:m,disabled:v,className:ie("inline-flex items-center justify-center rounded-xl border p-2 transition","border-gray-300/80 bg-white text-gray-800 hover:shadow-sm","dark:border-gray-700 dark:bg-slate-900 dark:text-gray-200",v?"opacity-60":""),"aria-label":"Close",children:e.jsx(qe,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"border-b border-gray-300/80 px-5 py-3 dark:border-gray-700",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx("span",{className:"pointer-events-none absolute inset-y-0 left-2 flex items-center",children:e.jsx(Pt,{className:"h-4 w-4 text-gray-500 dark:text-gray-400"})}),e.jsx("input",{type:"text",value:D,onChange:n=>N(n.target.value),placeholder:"Search users…",className:ie(Ze,"w-full rounded-xl border px-8 py-2.5 text-sm font-medium outline-none transition","border-gray-300/80 bg-white text-gray-950 placeholder:text-gray-400","focus:border-indigo-500/40 focus:ring-2 focus:ring-indigo-500/10","dark:border-gray-700 dark:bg-slate-900 dark:text-white dark:placeholder:text-gray-500")})]}),e.jsxs("div",{className:"hidden items-center gap-2 rounded-xl border border-amber-300/80 bg-amber-50 px-3 py-2 text-sm font-medium text-amber-800 dark:border-amber-700 dark:bg-amber-950/30 dark:text-amber-200 md:flex",children:[e.jsx(xt,{className:"h-4 w-4"}),e.jsx("span",{children:"Only the owner can change access."})]})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-3",children:[e.jsxs("div",{className:"rounded-2xl border border-gray-300/80 bg-white shadow-sm dark:border-gray-700 dark:bg-slate-900",children:[I&&e.jsx("div",{className:"py-6 text-center text-sm leading-6 text-gray-700 dark:text-gray-300",children:"Loading users..."}),!I&&!z.length&&e.jsx("div",{className:"py-6 text-center text-sm leading-6 text-gray-700 dark:text-gray-300",children:"No users found."}),!I&&z.length>0&&e.jsx("ul",{className:"divide-y divide-gray-200/90 dark:divide-gray-700",children:z.map(n=>{const d=E.includes(n.id),g=!!(n.isOwner||n.alreadyShared),T=n.isOwner?"Owner":n.alreadyShared?"Shared":"Invite",Y=n.isOwner?"border-emerald-300/80 bg-emerald-50 text-emerald-800 dark:border-emerald-700 dark:bg-emerald-950/30 dark:text-emerald-200":n.alreadyShared?"border-sky-300/80 bg-sky-50 text-sky-800 dark:border-sky-700 dark:bg-sky-950/30 dark:text-sky-200":"border-gray-300/80 bg-gray-100 text-gray-700 dark:border-gray-700 dark:bg-slate-800 dark:text-gray-200",s=!!(n.alreadyShared&&!n.isOwner);return e.jsxs("li",{className:"flex items-center justify-between px-4 py-3 text-sm",children:[e.jsxs("label",{className:ie("flex min-w-0 flex-1 items-center gap-3",g?"cursor-default opacity-60":"cursor-pointer"),children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500",checked:d,disabled:g||v,onChange:()=>!g&&!v&&p(n.id)}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate text-sm font-medium text-gray-950 dark:text-white",children:n.name}),e.jsx("span",{className:ie("inline-flex items-center rounded-full border px-2 py-0.5 text-xs font-semibold",Y),children:T})]}),e.jsx("span",{className:"mt-1 truncate text-sm leading-6 text-gray-700 dark:text-gray-300",children:n.email})]})]}),s&&e.jsx("button",{type:"button",onClick:()=>q(n),disabled:v,className:ie("ml-3 shrink-0 rounded-xl px-3 py-2 text-xs font-semibold text-white transition disabled:opacity-60","bg-gradient-to-r from-red-600 via-rose-600 to-orange-600 hover:brightness-[0.98] hover:shadow-md"),children:"Remove"})]},String(n.id))})})]}),O?e.jsx("div",{className:"mt-2 text-sm leading-6 text-red-600 dark:text-red-300",children:O}):null]}),e.jsxs("div",{className:"flex items-center justify-between border-t border-gray-300/80 px-5 py-3 text-sm text-gray-700 dark:border-gray-700 dark:text-gray-300",children:[e.jsx("div",{className:"leading-6",children:Q>0?`${Q} user${Q>1?"s":""} selected.`:"No new users selected."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:m,disabled:v,className:ie("rounded-xl border px-4 py-2 text-sm font-semibold transition disabled:opacity-60","border-gray-300/80 bg-white text-gray-800 hover:shadow-sm","dark:border-gray-700 dark:bg-slate-900 dark:text-gray-200"),children:"Cancel"}),e.jsx("button",{type:"button",onClick:W,disabled:v||Q===0,className:ie("rounded-xl px-4 py-2 text-sm font-semibold text-white transition disabled:opacity-60","bg-gradient-to-r from-indigo-600 via-sky-600 to-cyan-600 hover:brightness-[0.98] hover:shadow-md"),children:v?"Sharing...":Q>0?`Share (${Q})`:"Share"})]})]}),y&&e.jsx("div",{className:"absolute inset-0 z-20 flex items-center justify-center bg-black/35",children:e.jsxs("div",{className:"w-full max-w-sm overflow-hidden rounded-2xl border border-red-300/80 bg-white px-5 py-4 text-sm shadow-2xl dark:border-red-800/70 dark:bg-slate-900",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 flex h-10 w-10 items-center justify-center rounded-xl bg-red-50 text-red-700 dark:bg-red-950/30 dark:text-red-200",children:e.jsx(pr,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"text-base font-semibold text-gray-950 dark:text-white",children:"Remove access"}),e.jsxs("p",{className:"mt-1 text-sm leading-6 text-gray-700 dark:text-gray-300",children:["Remove access to ",e.jsx("span",{className:"font-semibold",children:i||"this project"})," for:"]}),e.jsx("p",{className:"mt-2 text-sm font-semibold text-gray-950 dark:text-white",children:y.name}),y.email?e.jsx("span",{className:"block text-sm leading-6 text-gray-700 dark:text-gray-300",children:y.email}):null,e.jsx("p",{className:"mt-2 text-sm leading-6 text-gray-700 dark:text-gray-300",children:"The user will no longer see this project or its data."})]})]}),e.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:G,disabled:v,className:ie("rounded-xl border px-4 py-2 text-sm font-semibold transition disabled:opacity-60","border-gray-300/80 bg-white text-gray-800 hover:shadow-sm","dark:border-gray-700 dark:bg-slate-900 dark:text-gray-200"),children:"Cancel"}),e.jsx("button",{type:"button",onClick:ee,disabled:v,className:ie("rounded-xl px-4 py-2 text-sm font-semibold text-white transition disabled:opacity-60","bg-gradient-to-r from-red-600 via-rose-600 to-orange-600 hover:brightness-[0.98] hover:shadow-md"),children:v?"Removing...":"Remove access"})]})]})})]})})})}function Ur(a){if(typeof a=="string"&&a.trim())return a.trim();if(a instanceof Error&&a.message.trim())return a.message.trim();if(a&&typeof a=="object"){const t=a,i=l=>{if(!Array.isArray(l))return null;const w=l.map(P=>String(P!=null?P:"").trim()).filter(P=>P.length>0);return w.length?w.join(`
`):null},u=typeof t.detail=="string"&&t.detail.trim()?t.detail.trim():i(t.detail);if(u)return u;const m=i(t.errors);if(m)return m;if(typeof t.message=="string"&&t.message.trim())return t.message.trim();if(t.data&&typeof t.data=="object"){const l=t.data,w=typeof l.detail=="string"&&l.detail.trim()?l.detail.trim():i(l.detail);if(w)return w;const P=i(l.errors);if(P)return P;if(typeof l.message=="string"&&l.message.trim())return l.message.trim()}}return"Failed to import project"}function Ar({open:a,onClose:t,onImport:i,resolveBrowserPaths:u,listRemoteDirectory:m,previewRemoteEntry:l,buildDownloadUrl:w,title:P="Import project"}){const E=Gt(),[j,D]=r.useState(""),[N,I]=r.useState(""),[A,v]=r.useState(!0),[k,O]=r.useState(!1),[C,y]=r.useState(!1);r.useEffect(()=>{a&&(D(""),I(""),v(!0),O(!1),y(!1))},[a]);const x=async()=>{const M=j.trim();if(M){O(!0);try{await i({projectLocation:M,projectName:N.trim()||void 0,copyProject:A}),t()}catch(L){ne.error(Ur(L))}finally{O(!1)}}};return e.jsxs(e.Fragment,{children:[e.jsxs(Vt,{open:a,onClose:k||C?void 0:t,maxWidth:"sm",fullWidth:!0,disableEnforceFocus:!0,disableAutoFocus:!0,disableRestoreFocus:!0,PaperProps:{sx:{borderRadius:2,overflow:"hidden",border:`1px solid ${Ae(E.palette.divider,.9)}`}},children:[e.jsx(Xt,{sx:{px:2.5,py:1.5,backgroundColor:"#333d49",borderBottom:"1px solid rgba(255,255,255,0.08)"},children:e.jsxs(Ee,{direction:"row",alignItems:"center",justifyContent:"space-between",spacing:2,children:[e.jsx(Ie,{variant:"subtitle1",sx:{color:"#ffffff",fontWeight:700,letterSpacing:.1},children:P}),e.jsx(dt,{onClick:t,size:"small",disabled:k,sx:{color:"#ffffff",border:"1px solid rgba(255,255,255,0.14)",backgroundColor:"rgba(255,255,255,0.06)","&:hover":{backgroundColor:"rgba(255,255,255,0.12)"}},children:e.jsx(qe,{size:16})})]})}),e.jsx(Yt,{sx:{px:2.5,py:2.25},children:e.jsxs(Ee,{spacing:2,children:[e.jsxs(Oe,{children:[e.jsx(Ie,{variant:"body2",sx:{mb:.75,fontWeight:600,color:E.palette.text.primary},children:"Project location"}),e.jsxs(Ee,{direction:"row",spacing:1,children:[e.jsx(ct,{fullWidth:!0,size:"small",value:j,onChange:M=>D(M.target.value),placeholder:"/path/to/project",disabled:k,sx:{"& .MuiOutlinedInput-root":{borderRadius:1}}}),e.jsx(dt,{onClick:()=>y(!0),disabled:k,sx:{border:`1px solid ${Ae(E.palette.text.primary,.16)}`,borderRadius:1},children:e.jsx(Jt,{size:18})})]})]}),e.jsx(Oe,{children:e.jsxs(Ee,{spacing:.75,children:[e.jsxs(Ee,{direction:"row",alignItems:"center",spacing:1,children:[e.jsx(er,{checked:A,onChange:M=>v(M.target.checked),disabled:k,size:"small",sx:{p:.5}}),e.jsx(Ie,{variant:"body2",sx:{fontWeight:500},children:"Copy project"}),e.jsx(Qt,{title:"If disabled, the imported project will be linked using a symbolic link instead of copying the whole directory.",arrow:!0,placement:"top",children:e.jsx(Oe,{component:"span",sx:{display:"inline-flex",alignItems:"center",color:Ae(E.palette.text.primary,.72)},children:e.jsx(tr,{size:15})})})]}),e.jsx(Ie,{variant:"caption",sx:{pl:4.5,color:E.palette.text.secondary,lineHeight:1.45},children:"If disabled, the project will be imported as a symbolic link instead of duplicating the files."})]})}),e.jsxs(Oe,{children:[e.jsx(Ie,{variant:"body2",sx:{mb:.75,fontWeight:600,color:E.palette.text.primary},children:"Project name (Optional)"}),e.jsx(ct,{fullWidth:!0,size:"small",value:N,onChange:M=>I(M.target.value),placeholder:"Imported project name",disabled:k,sx:{"& .MuiOutlinedInput-root":{borderRadius:1}}})]})]})}),e.jsxs(Zt,{sx:{px:2.5,py:1.75,borderTop:`1px solid ${Ae(E.palette.divider,.9)}`,justifyContent:"flex-end",gap:1},children:[e.jsx(ut,{onClick:x,variant:"contained",color:"error",disabled:k||!j.trim(),sx:{minWidth:100,textTransform:"none",fontWeight:700,boxShadow:"none",borderRadius:3},children:k?"Importing...":"Import"}),e.jsx(ut,{onClick:t,variant:"outlined",disabled:k,sx:{minWidth:100,textTransform:"none",fontWeight:700,borderRadius:3},children:"Cancel"})]})]}),e.jsx(rr,{open:C,onClose:()=>y(!1),title:"Select project location",resolveBrowserPaths:u,listRemoteDirectory:m,previewRemoteEntry:l,buildDownloadUrl:w,onPick:M=>{D(M),y(!1)}})]})}const Or=250;function he(...a){return a.filter(Boolean).join(" ")}const Ke="subpixel-antialiased [text-rendering:optimizeLegibility]";function jt(a){var w,P,E,j,D,N,I,A,v,k,O,C,y,x,M,L,z,p,B,F,W,q,G,ee,Q,n,d,g,T,Y,s,h,b,f;const t=a!=null?a:{},i=(w=t.createdAt)!=null?w:t.created_at,u=(P=t.updatedAt)!=null?P:t.updated_at,m=!!t.isShared,l=t.isOwner!==void 0&&t.isOwner!==null?!!t.isOwner:!m;return{id:(N=(D=(j=(E=t.id)!=null?E:t.pk)!=null?j:t._id)!=null?D:t.name)!=null?N:"",name:(v=(A=(I=t.name)!=null?I:t.label)!=null?A:t.title)!=null?v:"Untitled project",shortName:(C=(O=(k=t.shortName)!=null?k:t.short_name)!=null?O:t.slug)!=null?C:t.name?String(t.name).slice(0,20):"",description:(x=(y=t.description)!=null?y:t.desc)!=null?x:"",createdAt:i?new Date(i):new Date,updatedAt:u?new Date(u):void 0,status:(M=t.status)!=null?M:"unknown",protocolsCount:(z=(L=t.protocolsCount)!=null?L:t.protocols_count)!=null?z:Array.isArray(t.protocols)?t.protocols.length:0,diskUsage:(F=(B=(p=t.diskUsage)!=null?p:t.disk_usage)!=null?B:t.storage)!=null?F:void 0,protocols:(q=(W=t.protocols)!=null?W:t.protocolsMap)!=null?q:void 0,isShared:m,isOwner:l,permission:(G=t.permission)!=null?G:"full",projectOwnerId:(n=(Q=(ee=t.projectOwnerId)!=null?ee:t.ownerId)!=null?Q:t.owner_id)!=null?n:null,thumbnailUrl:(g=(d=t.thumbnailUrl)!=null?d:t.thumbnail_url)!=null?g:null,thumbnailRebuildUrl:(Y=(T=t.thumbnailRebuildUrl)!=null?T:t.thumbnail_rebuild_url)!=null?Y:null,thumbnailItemsUrl:(h=(s=t.thumbnailItemsUrl)!=null?s:t.thumbnail_items_url)!=null?h:null,thumbnailVersion:(f=(b=t.thumbnailVersion)!=null?b:t.thumbnail_version)!=null?f:null}}function Je(a){return e.jsxs("div",{className:he(Ke,"rounded-xl border p-3 shadow-sm","border-gray-300/80 bg-white","dark:border-gray-700 dark:bg-slate-900"),children:[e.jsx("div",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:a.label}),e.jsx("div",{className:"mt-1 text-xl font-bold tracking-[-0.01em] text-gray-950 dark:text-white",children:a.value})]})}function Yr({service:a,fetchList:t}){var T,Y;const i=We(),u=a!=null?a:i,[m,l]=r.useState([]),[w,P]=r.useState(""),[E,j]=r.useState(null),[D,N]=r.useState(!1),I=r.useRef(null),[A,v]=r.useState(null),[k,O]=r.useState(!1),[C,y]=r.useState(!0),[x,M]=r.useState(null),[L,z]=r.useState(!1),[p,B]=r.useState(null),F=r.useCallback(async(s={})=>{var b;const{silent:h=!1}=s;h||(y(!0),M(null));try{const f=await(t?t():u.fetchList());let H=[];Array.isArray(f)?H=f:f&&Array.isArray(f.results)?H=f.results:f&&typeof f=="object"&&(H=Object.values(f)),l(H.map(jt))}catch(f){console.error("[Projects] failed to load projects:",f),h||(M((b=f==null?void 0:f.message)!=null?b:String(f)),l([]))}finally{h||y(!1)}},[t,u]);r.useCallback(async()=>{const s=u;if(typeof s.resolveImportBrowserPaths=="function")return s.resolveImportBrowserPaths();throw new Error("Missing ProjectService.resolveImportBrowserPaths()")},[u]),r.useCallback(async s=>{const h=u;if(typeof h.listImportRemoteDirectory=="function")return h.listImportRemoteDirectory(s);throw new Error("Missing ProjectService.listImportRemoteDirectory()")},[u]),r.useCallback(async s=>{const h=u;return typeof h.previewImportRemoteEntry=="function"?h.previewImportRemoteEntry(s):null},[u]),r.useCallback((s,h)=>{const b=u;return typeof b.buildImportDownloadUrl=="function"?b.buildImportDownloadUrl(s,!!h):""},[u]);const W=r.useCallback(async s=>{const h=u;if(typeof h.importProject!="function")throw new Error("Missing ProjectService.importProject()");await h.importProject({projectLocation:s.projectLocation,projectName:s.projectName,copyProject:s.copyProject}),ne.success("Project imported successfully."),await F({silent:!0})},[u,F]);r.useEffect(()=>{F()},[F]),r.useEffect(()=>{const s=()=>{document.visibilityState==="visible"&&F({silent:!0})},h=window.setInterval(s,15e3);return window.addEventListener("focus",s),document.addEventListener("visibilitychange",s),()=>{window.clearInterval(h),window.removeEventListener("focus",s),document.removeEventListener("visibilitychange",s)}},[F]),r.useEffect(()=>{const s=h=>{I.current&&!I.current.contains(h.target)&&N(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[]);const q=w.trim().toLowerCase(),G=r.useMemo(()=>q?m.filter(s=>{var H,Z,K;const h=String((H=s.name)!=null?H:"").toLowerCase(),b=String((Z=s.id)!=null?Z:"").toLowerCase(),f=String((K=s.description)!=null?K:"").toLowerCase();return h.includes(q)||b.includes(q)||f.includes(q)}):m,[m,q]),ee=r.useMemo(()=>{const s=m.length,h=m.filter(f=>!!f.isShared&&!f.isOwner).length,b=m.filter(f=>!!f.isOwner).length;return{total:s,shared:h,owned:b}},[m]),Q=r.useCallback(s=>{const h=String(s);l(b=>b.filter(f=>String(f.id)!==h))},[]),n=r.useCallback((s,h,b)=>{l(f=>f.map(H=>String(H.id)===String(s)?{...H,name:h,description:b}:H))},[]),d=r.useCallback(s=>{var f;const h=(f=s&&(s.project||s.data||s.result))!=null?f:s,b=jt(h);l(H=>[b,...H]),P("")},[]),g=r.useCallback((s,h,b)=>{B({id:s,name:h,projectOwnerId:b!=null?b:null})},[]);return e.jsxs(e.Fragment,{children:[e.jsx(Wt,{title:"Scipion | Projects",description:"Projects page"}),e.jsx("div",{className:he(Ke,"relative overflow-hidden rounded-2xl border p-5 shadow-sm","border-gray-300/90 bg-white","dark:border-gray-700 dark:bg-slate-900","lg:p-6"),children:e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-[15px] font-semibold tracking-[0.01em] text-gray-950 dark:text-white",children:"Projects"}),e.jsx("span",{className:"rounded-full border border-gray-300/80 bg-gray-100 px-2 py-0.5 text-xs font-semibold text-gray-800 dark:border-gray-700 dark:bg-slate-800 dark:text-gray-200",children:ee.total})]}),e.jsx("p",{className:"mt-1 text-sm leading-6 text-gray-700 dark:text-gray-300",children:"Browse your projects, open workflows, and manage sharing."})]}),e.jsx("div",{className:"flex flex-wrap items-center justify-start gap-2 sm:justify-end",children:e.jsxs("div",{className:"relative",ref:I,children:[e.jsxs("button",{type:"button",onClick:()=>N(s=>!s),className:he("inline-flex items-center gap-2 rounded-[10px] px-3 py-2 text-sm font-semibold transition","text-white shadow-sm hover:shadow-md hover:brightness-[0.98]","bg-gradient-to-r from-indigo-600 via-sky-600 to-cyan-600"),children:[e.jsx("span",{className:"whitespace-nowrap",children:"Actions"}),e.jsx(ar,{className:"h-5 w-5 opacity-90"})]}),D&&e.jsx("div",{className:he(Ke,"absolute right-0 z-50 mt-2 w-56 overflow-hidden rounded-xl border shadow-xl","border-gray-300/90 bg-white","dark:border-gray-700 dark:bg-slate-900"),children:e.jsxs("ul",{className:"text-sm text-gray-800 dark:text-gray-200",children:[e.jsx("li",{children:e.jsxs("button",{type:"button",className:he("flex w-full items-center gap-2 px-4 py-3 text-left transition","hover:bg-gray-50 dark:hover:bg-slate-800/70"),onClick:()=>{N(!1),O(!0)},children:[e.jsx(It,{className:"h-4 w-4"}),e.jsx("span",{children:"New project"})]})}),e.jsx("li",{children:e.jsxs("button",{type:"button",className:he("flex w-full items-center gap-2 px-4 py-3 text-left transition","hover:bg-gray-50 dark:hover:bg-slate-800/70"),onClick:()=>{N(!1),z(!0)},children:[e.jsx(hr,{className:"h-4 w-4"}),e.jsx("span",{children:"Import project"})]})}),e.jsx("li",{children:e.jsxs("button",{type:"button",className:he("flex w-full items-center gap-2 px-4 py-3 text-left transition","hover:bg-gray-50 dark:hover:bg-slate-800/70"),onClick:()=>{N(!1),console.log("Import Workflow")},children:[e.jsx(xr,{className:"h-4 w-4"}),e.jsx("span",{children:"Import workflow"})]})})]})})]})})]}),e.jsxs("div",{className:"mb-4 grid grid-cols-1 gap-3 lg:grid-cols-12",children:[e.jsx("div",{className:"lg:col-span-6",children:e.jsxs("div",{className:"relative",children:[e.jsx(Pt,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-500 dark:text-gray-400"}),e.jsx("input",{type:"text",placeholder:"Search projects…",value:w,onChange:s=>P(s.target.value),className:he(Ke,"w-full rounded-xl border py-2.5 pl-9 pr-3 text-sm font-medium outline-none transition","border-gray-300/80 bg-white text-gray-950 placeholder:text-gray-400","focus:border-indigo-500/40 focus:ring-2 focus:ring-indigo-500/10","dark:border-gray-700 dark:bg-slate-900 dark:text-white dark:placeholder:text-gray-500","dark:focus:border-indigo-400/40 dark:focus:ring-indigo-400/15")})]})}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 lg:col-span-6 sm:grid-cols-3",children:[e.jsx(Je,{label:"Total",value:ee.total}),e.jsx(Je,{label:"Owned",value:ee.owned}),e.jsx(Je,{label:"Shared",value:ee.shared})]})]}),e.jsxs("div",{className:"overscroll-contain",style:{height:`calc(100vh - ${Or}px)`,overflowY:"auto",WebkitOverflowScrolling:"touch",paddingRight:4},children:[C&&e.jsx("div",{className:"grid grid-cols-1 items-start gap-6 sm:grid-cols-2 lg:grid-cols-3",children:Array.from({length:6}).map((s,h)=>e.jsxs("div",{className:he("h-[210px] animate-pulse rounded-2xl border p-5 shadow-sm","border-gray-300/80 bg-white","dark:border-gray-700 dark:bg-slate-900"),children:[e.jsx("div",{className:"h-5 w-2/3 rounded bg-gray-200 dark:bg-slate-700"}),e.jsx("div",{className:"mt-3 h-4 w-1/2 rounded bg-gray-200 dark:bg-slate-700"}),e.jsx("div",{className:"mt-6 h-12 rounded bg-gray-100 dark:bg-slate-800"}),e.jsx("div",{className:"mt-3 h-4 w-1/3 rounded bg-gray-200 dark:bg-slate-700"})]},h))}),!C&&x&&e.jsxs("div",{className:"rounded-2xl border border-red-200/80 bg-red-50 p-4 text-sm leading-6 text-red-700 dark:border-red-900/50 dark:bg-red-950/30 dark:text-red-200",children:["Error loading projects: ",x]}),!C&&!x&&G.length===0&&e.jsx("div",{className:"rounded-2xl border border-gray-300/80 bg-white p-6 text-sm leading-6 text-gray-700 dark:border-gray-700 dark:bg-slate-900 dark:text-gray-300",children:"No projects found."}),!C&&!x&&G.length>0&&e.jsx("div",{className:"grid grid-cols-1 items-start gap-6 sm:grid-cols-2 lg:grid-cols-3","aria-label":"Projects list",children:G.map(s=>{var h,b,f,H,Z,K,ue,de,ce;return e.jsx("div",{className:"mt-2 h-full",children:e.jsx(_r,{id:s.id,label:s.name,value:(h=s.protocolsCount)!=null?h:"0",createdAt:s.createdAt?String(s.createdAt):void 0,updatedAt:s.updatedAt?String(s.updatedAt):void 0,diskUsage:(b=s.diskUsage)==null?void 0:b.toString(),isSelected:E===s.name,onSelect:()=>j(s.name),isExpanded:A===s.name,description:(f=s.description)!=null?f:"No description available.",onToggleExpand:()=>v(me=>me===s.name?null:s.name),onDelete:Q,onRename:n,onShare:me=>{var xe;return g(me,s.name,(xe=s.projectOwnerId)!=null?xe:null)},isShared:s.isShared,isOwner:s.isOwner,permission:(H=s.permission)==null?void 0:H.toString(),projectOwnerId:(Z=s.projectOwnerId)!=null?Z:null,thumbnailUrl:(K=s.thumbnailUrl)!=null?K:null,thumbnailRebuildUrl:(ue=s.thumbnailRebuildUrl)!=null?ue:null,thumbnailItemsUrl:(de=s.thumbnailItemsUrl)!=null?de:null,thumbnailVersion:(ce=s.thumbnailVersion)!=null?ce:0})},String(s.id))})})]})]})}),e.jsx(Lr,{open:k,onClose:()=>O(!1),onCreate:d}),e.jsx(Ar,{open:L,onClose:()=>z(!1),onImport:W,resolveBrowserPaths:()=>u.resolveBrowserPaths(-1,-1),listRemoteDirectory:s=>u.listRemoteDirectory(-1,-1,s),previewRemoteEntry:s=>u.previewRemoteEntry(-1,-1,s),buildDownloadUrl:(s,h)=>u.buildProtocolDownloadUrl("-1","-1",s,!!h)}),e.jsx(Rr,{open:!!p,projectId:(T=p==null?void 0:p.id)!=null?T:null,projectName:p==null?void 0:p.name,projectOwnerId:(Y=p==null?void 0:p.projectOwnerId)!=null?Y:void 0,onClose:()=>B(null)})]})}export{Yr as default};
