PageSourceSearch

https://morphyx.io/assets/OrganizationsPage-BxqkKSMb.js

js morphyx.io collected 2026-10-05 03:10:49 UTC 222,281 bytes, 143 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/transactionReport-9zL14eTi.js","assets/vendor-google-CFE1saLJ.js","assets/vendor-react-CNpY0XEk.js"])))=>i.map(i=>d[i]);
2import{f as ge,u as Ae,e as Pt,j as e,D as ot,T as Ye,o as Ve,V as rt,t as qe,d as Nt,X as he,C as ve,A as zt,m as we,F as Dt,s as ze,I as Ge,v as Lt,p as dt,k as Je,i as ct,w as Ft,c as Ot}from"./index-DknunFSe.js";import{r as s,R as kt,e as fe,f as It,L as Rt}from"./vendor-react-CNpY0XEk.js";import{r as Bt}from"./pricingUtils-s3REMoq4.js";import{g as Ut,c as Vt}from"./currency-pio-qEz7.js";import{aP as it,aO as St}from"./BarChart-BGNrOSaB.js";import{C as Ct}from"./credit-card-Cpkd0fVv.js";import{U as ue}from"./users-Cvhu48qp.js";import{M as Te}from"./mail-Bo2MU45n.js";import{L as Re}from"./link-CC8ICAWH.js";import{C as Ee}from"./clock-DjWElGhc.js";import{U as ye,R as tt,Z as qt}from"./zap-BtJRPBGF.js";import{L as $e}from"./loader-circle-No_a8ytV.js";import{C as be}from"./check-BHKmhq0R.js";import{C as Be}from"./copy-Ck94zaIm.js";import{P as De}from"./plus-tvIz3Upw.js";import{I as Gt,S as Ue,M as Jt,C as _t,P as nt,a as Le,B as mt,F as xt}from"./MemberSpendingCapModal-DaA46uRT.js";import{_ as Wt}from"./vendor-google-CFE1saLJ.js";import{F as st}from"./file-text-DObY4t03.js";import{F as Ht,O as Yt}from"./OrgAnalyticsDashboard-cwuNBplI.js";import{A as ht}from"./arrow-left-CnPyNGOL.js";import{M as Kt}from"./menu-Drz9hzWC.js";import{C as Qt}from"./crown-DdofBha7.js";import{P as pt}from"./plug-Di2_CGZJ.js";import{F as Tt}from"./folder-open-ojySWzYF.js";import{S as We}from"./star-CnACA1mv.js";import{V as Et}from"./video-CJpAGFpA.js";import{M as $t}from"./message-square-B0m4SlGu.js";import{D as Zt}from"./download-DUSsWPgU.js";import{U as Xt}from"./user-plus-CQuSkIRA.js";import{T as At}from"./trash-2-CdQhNDFL.js";import{U as es}from"./upload-DTBDQnRm.js";import{T as ut}from"./target-DL532Zdw.js";import{A as ts}from"./activity-CLAEcMT_.js";import{R as ss}from"./rocket-CRDVWXiL.js";import{E as as}from"./eye-DYyGr3Wl.js";import{G as rs}from"./globe-CZL_az3w.js";import{L as is}from"./lock-CVicX9J6.js";import{C as ns}from"./CreditSourceSwitcher-eXNjK27O.js";import{B as gt}from"./building-2-DjYuxQ7U.js";import{S as ls}from"./sparkles-sQY3NrVr.js";import{C as os}from"./chevron-right-BmO06LY4.js";import"./value-CUBxuzm4.js";import"./history-Cg7aGee8.js";/**
3 * @license lucide-react v1.8.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 ds=[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]],cs=ge("archive",ds);/**
8 * @license lucide-react v1.8.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 ms=[["path",{d:"M5 21v-6",key:"1hz6c0"}],["path",{d:"M12 21V3",key:"1lcnhd"}],["path",{d:"M19 21V9",key:"unv183"}]],Fe=ge("chart-no-axes-column",ms);/**
13 * @license lucide-react v1.8.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 xs=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M12 18v-6",key:"17g6i2"}],["path",{d:"m9 15 3 3 3-3",key:"1npd3o"}]],hs=ge("file-down",xs);/**
18 * @license lucide-react v1.8.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 ps=[["path",{d:"M5 22h14",key:"ehvnwv"}],["path",{d:"M5 2h14",key:"pdyrp9"}],["path",{d:"M17 22v-4.172a2 2 0 0 0-.586-1.414L12 12l-4.414 4.414A2 2 0 0 0 7 17.828V22",key:"1d314k"}],["path",{d:"M7 2v4.172a2 2 0 0 0 .586 1.414L12 12l4.414-4.414A2 2 0 0 0 17 6.172V2",key:"1vvvr6"}]],He=ge("hourglass",ps);/**
23 * @license lucide-react v1.8.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 us=[["path",{d:"m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4",key:"g0fldk"}],["path",{d:"m21 2-9.6 9.6",key:"1j0ho8"}],["circle",{cx:"7.5",cy:"15.5",r:"5.5",key:"yqb3hr"}]],_e=ge("key",us);/**
28 * @license lucide-react v1.8.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 gs=[["path",{d:"M5.8 11.3 2 22l10.7-3.79",key:"gwxi1d"}],["path",{d:"M4 3h.01",key:"1vcuye"}],["path",{d:"M22 8h.01",key:"1mrtc2"}],["path",{d:"M15 2h.01",key:"1cjtqr"}],["path",{d:"M22 20h.01",key:"1mrys2"}],["path",{d:"m22 2-2.24.75a2.9 2.9 0 0 0-1.96 3.12c.1.86-.57 1.63-1.45 1.63h-.38c-.86 0-1.6.6-1.76 1.44L14 10",key:"hbicv8"}],["path",{d:"m22 13-.82-.33c-.86-.34-1.82.2-1.98 1.11c-.11.7-.72 1.22-1.43 1.22H17",key:"1i94pl"}],["path",{d:"m11 2 .33.82c.34.86-.2 1.82-1.11 1.98C9.52 4.9 9 5.52 9 6.23V7",key:"1cofks"}],["path",{d:"M11 13c1.93 1.93 2.83 4.17 2 5-.83.83-3.07-.07-5-2-1.93-1.93-2.83-4.17-2-5 .83-.83 3.07.07 5 2Z",key:"4kbmks"}]],bs=ge("party-popper",gs);/**
33 * @license lucide-react v1.8.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 fs=[["path",{d:"m10.344 4.688 1.181-2.393a.53.53 0 0 1 .95 0l2.31 4.679a2.12 2.12 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.237 3.152",key:"19ctli"}],["path",{d:"m17.945 17.945.43 2.505a.53.53 0 0 1-.771.56l-4.618-2.428a2.12 2.12 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.12 2.12 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a8 8 0 0 0 .4-.099",key:"ptqqvy"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],ys=ge("star-off",fs);/**
38 * @license lucide-react v1.8.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 ws=[["path",{d:"M16 17h6v-6",key:"t6n2it"}],["path",{d:"m22 17-8.5-8.5-5 5L2 7",key:"x473p"}]],js=ge("trending-down",ws);/**
43 * @license lucide-react v1.8.0 - ISC
44 *
45 * This source code is licensed under the ISC license.
46 * See the LICENSE file in the root directory of this source tree.
47 */const vs=[["path",{d:"m16 11 2 2 4-4",key:"9rsbq5"}],["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"}]],Ns=ge("user-check",vs);/**
48 * @license lucide-react v1.8.0 - ISC
49 *
50 * This source code is licensed under the ISC license.
51 * See the LICENSE file in the root directory of this source tree.
52 */const ks=[["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"}]],Ss=ge("user-minus",ks);/**
53 * @license lucide-react v1.8.0 - ISC
54 *
55 * This source code is licensed under the ISC license.
56 * See the LICENSE file in the root directory of this source tree.
57 */const Cs=[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]],_s=ge("wrench",Cs),xe=50,Ce=5e4,bt=10,Ts=[50,150,500,1500,5e3],Es=r=>!isFinite(r)||r<=0?0:r<=100?r*10:r<=500?1e3+(r-100)*12:1e3+400*12+(r-500)*15,ft=r=>!isFinite(r)||r<=0?xe:Math.min(Ce,Math.max(xe,Math.round(r*100)/100)),$s=({isOpen:r,onClose:f,orgId:c}
57)=>{const{pauseSessionValidation:n}=Ae(),{currency:T}=Pt(),[v,$]=s.useState(150),[_,g]=s.useState(null),[o,k]=s.useState(!1),w=Ut(T),N=(l,j)=>Bt(Vt(l,j)),u=Es(v),x=async()=>{if(g(null),!v||v<xe){g(`Please enter a valid amount (minimum RM${xe})`);return}k(!0);try{const l=localStorage.getItem("morphyxToken");if(!l){g("Please log in first"),k(!1);return}const j=await fetch(`/api/organizations/${c}/topup-custom`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${l}`},body:JSON.stringify({amount:v})}),M=await j.json();if(j.ok&&M.paymentData){n();const B=document.createElement("form");B.method="POST",B.action=M.paymentData.redirectUrl,Object.entries(M.paymentData.payload).forEach(([Y,C])=>{const P=document.createElement("input");P.type="hidden",P.name=Y,P.value=String(C),B.appendChild(P)}),document.body.appendChild(B),B.submit(),document.body.removeChild(B)}else g(M.message||"Failed to initiate payment"),k(!1)}catch(l){console.error("Error initiating org topup:",l),g(l.message||"An error occurred while processing the topup"),k(!1)}};return r?e.jsxs("div",{className:"w-full h-full bg-transparent flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"p-4 sm:p-6 border-b border-gray-700/50 flex items-center justify-between gap-4 bg-black/40 backdrop-blur-md sticky top-0 z-20",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("span",{className:"text-2xl sm:text-3xl flex-shrink-0",children:e.jsx(ot,{className:"w-8 h-8 drop-shadow-[0_0_12px_rgba(191,0,255,0.4)]"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-xl sm:text-2xl font-bold text-white truncate",children:"Organization Credits"}),e.jsx("p",{className:"text-xs sm:text-sm text-gray-400",children:"Purchase credits for your team"})]})]}),e.jsx("button",{onClick:f,className:"flex-shrink-0 p-2 text-gray-400 hover:text-white hover:bg-gray-700/50 rounded-full transition-all bg-gray-800 sm:bg-transparent",title:"Close modal",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-6 w-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto scrollbar-hide bg-transparent",children:e.jsxs("div",{className:"p-4 sm:p-6 pb-6",children:[_&&e.jsxs("div",{className:"mb-6 p-4 bg-red-500/10 border border-red-500/30 text-red-300 rounded-xl flex items-center gap-3",children:[e.jsx(Ye,{className:"w-5 h-5 flex-shrink-0"}),e.jsx("p",{className:"text-sm",children:_})]}),e.jsxs("div",{className:"text-center mb-6",children:[e.jsx("div",{className:"text-xs uppercase tracking-widest text-gray-400 font-semibold mb-1",children:"You pay"}),e.jsx("div",{className:"flex items-baseline justify-center gap-2",children:e.jsxs("span",{className:"text-4xl sm:text-5xl font-bold text-white",children:["RM ",v.toFixed(2)]})}),T!=="MYR"&&e.jsxs("div",{className:"mt-1 text-sm text-gray-500",children:["≈ ",w,N(v,T)," ",T," · charged in MYR"]}),e.jsx("div",{className:"mt-4 inline-flex p-[1.5px] rounded-xl animated-gradient-border shadow-[0_0_15px_rgba(255,255,255,0.1)]",children:e.jsxs("div",{className:"flex items-center gap-2 bg-black rounded-[10px] px-5 py-3",children:[e.jsx("span",{className:"text-gray-300 text-sm font-medium",children:"You get"}),e.jsxs("span",{className:"text-3xl font-bold bg-gradient-to-r from-brand-primary to-purple-500 bg-clip-text text-transparent flex items-center gap-2",children:[u.toLocaleString()," ",e.jsx(ot,{className:"w-7 h-7 drop-shadow-[0_0_8px_rgba(191,0,255,0.4)]"})]})]})})]}),e.jsxs("div",{className:"px-1 mb-2",children:[e.jsx("style",{children:`
58                .org-topup-slider {
59                  -webkit-appearance: none;
60                  appearance: none;
61                  height: 6px;
62                  border-radius: 999px;
63                  outline: none;
64                }
65                .org-topup-slider::-webkit-slider-thumb {
66                  -webkit-appearance: none;
67                  appearance: none;
68                  width: 18px;
69                  height: 18px;
70                  border-radius: 50%;
71                  background: white;
72                  cursor: pointer;
73                  box-shadow: 0 0 10px rgba(191,0,255,0.6);
74                }
75                .org-topup-slider::-moz-range-thumb {
76                  width: 18px;
77                  height: 18px;
78                  border-radius: 50%;
79                  background: white;
80                  cursor: pointer;
81                  box-shadow: 0 0 10px rgba(191,0,255,0.6);
82                  border: none;
83                }
84              `}),e.jsx("input",{type:"range",min:xe,max:Ce,step:bt,value:v,onCh
84ange:l=>$(ft(parseFloat(l.target.value))),className:"w-full cursor-pointer org-topup-slider",style:{background:`linear-gradient(to right, #b9ff00 0%, #BF00FF ${(v-xe)/(Ce-xe)*100}%, #262626 ${(v-xe)/(Ce-xe)*100}%, #262626 100%)`},"aria-label":"Select top-up amount"}),e.jsxs("div",{className:"flex justify-between text-[11px] text-gray-500 mt-2",children:[e.jsxs("span",{children:["RM ",xe]}),e.jsxs("span",{children:["RM ",Ce.toLocaleString()]})]})]}),e.jsxs("div",{className:"mt-5 flex items-center justify-center gap-2",children:[e.jsx("label",{htmlFor:"org-topup-amount",className:"text-sm text-gray-400",children:"Custom amount (RM)"}),e.jsx("input",{id:"org-topup-amount",type:"number",min:xe,max:Ce,step:bt,value:v,onChange:l=>$(parseFloat(l.target.value)||xe),onBlur:l=>$(ft(parseFloat(l.target.value))),className:"w-28 bg-black border border-gray-600 rounded-lg px-3 py-2 text-white text-center focus:border-white/50 focus:outline-none"})]}),e.jsx("div",{className:"mt-5 flex flex-wrap justify-center gap-2",children:Ts.map(l=>{const j=Math.abs(v-l)<.001;return e.jsxs("button",{type:"button",onClick:()=>$(l),className:`px-4 py-2 rounded-full text-sm font-semibold border transition-all ${j?"bg-white text-black border-white":"bg-black/60 text-gray-300 border-gray-600 hover:border-gray-500"}`,children:["RM ",l.toLocaleString()]},l)})}),e.jsxs("div",{className:"mt-6 bg-white/5 p-5 rounded-xl border border-white/10",children:[e.jsxs("p",{className:"text-xs text-gray-400 font-medium mb-3 flex items-center gap-1.5",children:[e.jsx(it,{className:"w-4 h-4"})," Pricing Tiers"]}),e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-gray-400",children:"RM 0 - 100"}),e.jsx("span",{className:"text-gray-300 font-medium",children:"10 cr/RM"})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-gray-400",children:"RM 101 - 500"}),e.jsx("span",{className:"text-gray-300 font-medium",children:"12 cr/RM"})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-gray-400",children:"RM 500+"}),e.jsx("span",{className:"text-white font-medium",children:"15 cr/RM"})]})]})]}),e.jsxs("div",{className:"flex flex-col items-center pt-4 sm:pt-6",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5 w-full mb-3",children:[e.jsx("span",{className:"text-xs sm:text-sm text-gray-400 font-medium",children:"Secured payment by"}),e.jsx("img",{src:"/logos/fiuu.svg",alt:"Fiuu",className:"h-4 sm:h-5"})]}),e.jsx("button",{onClick:x,disabled:o,className:"w-full bg-white hover:bg-gray-200 disabled:bg-gray-600 disabled:cursor-not-allowed text-black text-sm sm:text-base font-bold py-2.5 sm:py-3 px-4 sm:px-6 rounded-lg transition-all transform hover:scale-[1.01] active:scale-[0.98] disabled:scale-100",children:o?e.jsxs("span",{className:"flex items-center justify-center gap-2",children:[e.jsxs("svg",{className:"animate-spin h-4 w-4 sm:h-5 sm:w-5",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),e.jsx("span",{className:"text-sm sm:text-base text-black/70",children:"Processing..."})]}):e.jsxs("span",{className:"flex items-center justify-center gap-2",children:[e.jsx(Ct,{className:"w-4 h-4 text-black"}),e.jsx("span",{children:"Purchase Credits"})]})})]}),e.jsxs("div",{className:"mt-4 sm:mt-6 bg-white/5 border border-white/10 rounded-lg p-3 sm:p-4",children:[e.jsxs("p",{className:"text-white font-semibold text-xs sm:text-sm mb-1.5 flex items-center gap-1.5",children:[e.jsx(Ve,{className:"w-4 h-4 sm:w-4 sm:h-4 text-white/70"}),e.jsx("span",{children:"What happens next?"})]}),e.jsxs("ul",{className:"text-gray-400 text-xs sm:text-sm space-y-1 pl-5 list-decimal marker:text-gray-500",children:[e.jsx("li",{className:"pl-1",children:"You'll be redirected to secure payment"}),e.jsx("li",{className:"pl-1",children:"Complete your payment"}),e.jsx("li",{className:"pl-1",children:"Credits added to organization wallet"})]})]})]})})]}):null},As=/^[a-z]{1,3}(?:_[^,/]+)(?:,[a-z]{1,3}_[^,/]+)*$/i,yt=r=>{const f=r.split("/");let c=0;for(;c<f.length-1&&As.test(f[c]);)c++;return f.slice(c).join("/")},wt=r=>{const f=r.cloudinary_url;if(!f||!f.includes("cloudinary.com/"))return f;if(r.type==="video"){const $="/video/upload/",_=f.indexOf($);if(_===-1)return f;
84const g=f.slice(0,_+$.length),o=yt(f.slice(_+$.length)).replace(/\.\w+$/,".jpg");return`${g}so_0,w_400,h_400,c_fill,q_auto,f_auto/${o}`}const c="/image/upload/",n=f.indexOf(c);if(n===-1)return f;const T=f.slice(0,n+c.length),v=yt(f.slice(n+c.length));return`${T}w_400,h_400,c_fill,q_auto,f_auto/${v}`},Ms=({orgId:r,orgName:f})=>{Ae();const[c,n]=s.useState([]),[T,v]=s.useState(!0),[$,_]=s.useState(null),[g,o]=s.useState("all"),[k,w]=s.useState("all"),[N,u]=s.useState([]),[x,l]=s.useState(null),[j,M]=s.useState(1),[B,Y]=s.useState(!1),[C,P]=s.useState(null),U=16,V=localStorage.getItem("morphyxToken"),J=s.useCallback(async()=>{v(!0),_(null);try{const a=await fetch(`/api/organizations/${r}/gallery`,{headers:{Authorization:`Bearer ${V}`,"Content-Type":"application/json"}});if(!a.ok)throw new Error(await a.text());const A=await a.json();n(Array.isArray(A)?A:A.images||[]);const L=Array.from(new Map(A.map(G=>[G.user_id,{id:G.user_id,name:G.user_name}])).values());u(L)}catch(a){_(a instanceof Error?a.message:"Failed to fetch gallery")}finally{v(!1)}},[r,V]);s.useEffect(()=>{J()},[J]);const I=c.filter(a=>{const A=g==="all"||a.user_id.toString()===g,L=k==="all"||a.type===k;return A&&L}),b=Math.ceil(I.length/U),m=(j-1)*U,D=I.slice(m,m+U),O=Array.from(new Set(c.map(a=>a.type))).sort(),Q=c.filter(a=>a.type==="image").length,h=c.filter(a=>a.type==="video").length,S=async(a,A)=>{const L=(x==null?void 0:x.type)==="video",G=qe(A||void 0,L?"video":"image");await Nt(a,G,L?"video":"image")},E=async a=>{if(!(a.type==="video"||B)){Y(!0),P(null);try{const A=await fetch("/api/community/gallery",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${V}`},body:JSON.stringify({imageUrl:a.cloudinary_url,title:a.title||void 0,description:a.description||void 0,generationType:"IMAGE_GENERATION"})});if(A.ok)P("Shared to Community Gallery!"),setTimeout(()=>P(null),3e3);else{const L=await A.json().catch(()=>({}));_(L.message||"Failed to share.")}}catch{_("Failed to share.")}finally{Y(!1)}}},W=a=>{M(a),setTimeout(()=>{const A=document.querySelector("[data-gallery-grid]");A&&A.scrollIntoView({behavior:"smooth",block:"start"})},0)},ee=a=>new Date(a).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),re=(g!=="all"?1:0)+(k!=="all"?1:0);return e.jsxs("div",{className:"space-y-5 relative",children:[C&&e.jsx("div",{className:"fixed top-4 left-1/2 -translate-x-1/2 z-[60] bg-violet-600 text-white px-5 py-2.5 rounded-xl shadow-lg text-sm font-medium",children:C}),e.jsx("div",{className:"bg-black/40 rounded-2xl border border-white/10 p-5 sm:p-6",children:e.jsx("div",{className:"flex items-start justify-between gap-4",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl sm:text-2xl font-bold text-white flex items-center gap-2.5",children:"Organization Gallery"}),e.jsx("p",{className:"text-gray-400 text-sm mt-1",children:"Media generated by team members"}),e.jsx("p",{className:"text-sm text-brand-primary font-semibold mt-2",children:f})]})})}),e.jsxs("div",{className:"grid grid-cols-4 gap-2 sm:gap-3",children:[e.jsxs("div",{className:"bg-black/40 border border-white/10 rounded-xl p-3 sm:p-4 text-center",children:[e.jsx("p",{className:"text-xl sm:text-2xl font-bold text-white",children:c.length}),e.jsx("p",{className:"text-gray-500 text-[10px] sm:text-xs mt-0.5",children:"Total"})]}),e.jsxs("div",{className:"bg-black/40 border border-white/10 rounded-xl p-3 sm:p-4 text-center",children:[e.jsx("p",{className:"text-xl sm:text-2xl font-bold text-white",children:Q}),e.jsx("p",{className:"text-gray-500 text-[10px] sm:text-xs mt-0.5",children:"Images"})]}),e.jsxs("div",{className:"bg-black/40 border border-white/10 rounded-xl p-3 sm:p-4 text-center",children:[e.jsx("p",{className:"text-xl sm:text-2xl font-bold text-white",children:h}),e.jsx("p",{className:"text-gray-500 text-[10px] sm:text-xs mt-0.5",children:"Videos"})]}),e.jsxs("div",{className:"bg-black/40 border border-white/10 rounded-xl p-3 sm:p-4 text-center",children:[e.jsx("p",{className:"text-xl sm:text-2xl font-bold text-white",children:N.length}),e.jsx("p",{className:"text-gray-500 text-[10px] sm:text-xs mt-0.5",children:"Members"})]})]}),e.jsx("div",{className:"bg-black/40 border border-white/10 rounded-xl p-3 sm:p-4",children:e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 sm:gap-3",children:[e.jsxs("select",{value:g,onChange:a=>{o(a.target.value),M(1)},className:"flex-1 px-3 py-2.5 bg-black/40 border border-white/10 rounded-xl text-sm text-white focus:outline-none focus:border-white/20 transition-all appearance-none cursor-pointer",children:[e.jsx("option",{value:"all",children:"All Members"}),N.map(a=>e.jsx("option",{value:a.id,children:a.name},a.id))]}),e.jsxs("select",{value:k,onChange:a=>{w(a.target.value),M(1)},className:"flex-1 sm:max-w-[180px] px-3 py-2.5 bg-black/40 border border-white/10 rounded-xl text-sm text-white focus:outline-none focus:border-white/20 transition-all appearance-none cursor-pointer",children:[e.jsx("option",{value:"all",children:"All Types"}),O.map(a=>e.jsx("option",{value:a,children:a==="image"?"Images":a==="video"?"Videos":a.toUpperCase()},a))]}),re>0&&e.jsxs("button",{onClick:()=>{o("all"),w("all"),M(1)},className:"px-4 py-2.5 bg-red-500/10 border border-red-500/30 rounded-xl text-red-400 text-sm font-medium hover:bg-red-500/20 transition-all",children:["Clear (",re,")"]}),e.jsxs("div",{className:"flex items-center text-xs text-gray-500 sm:ml-auto whitespace-nowrap",children:[I.length," item",I.length!==1?"s":""]})]})}),$&&e.jsx("div",{className:"p-4 bg-red-500/10 border border-red-500/30 text-red-300 rounded-xl text-sm flex items-center gap-3",children:$}),T?e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-2 sm:gap-3",children:[...Array(8)].map((a,A)=>e.jsx("div",{className:"aspect-square bg-gray-800/60 rounded-xl animate-pulse"},A))}):I.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 sm:py-20 bg-black/40 border border-white/10 rounded-2xl",children:[e.jsx("p",{className:"text-gray-300 font-medium mb-1",children:"No media found"}),e.jsx("p",{className:"text-gray-500 text-sm mb-4",children:"Try adjusting your filters"}),re>0&&e.jsx("button",{onClick:()=>{o("all"),w("all"),M(1)},className:"text-brand-primary hover:text-brand-secondary text-sm font-medium",children:"Reset Filters"})]}):e.jsxs("div",{className:"space-y-5",children:[e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-2 sm:gap-3","data-gallery-grid":!0,children:D.map(a=>e.jsxs("div",{onClick:()=>l(a),className:"group relative aspect-square bg-gray-900/50 border border-gray-800/50 rounded-xl sm:rounded-2xl overflow-hidden cursor-pointer hover:border-gray-600/50 transition-all duration-300 hover:shadow-xl hover:shadow-black/20",children:[a.type==="video"?e.jsxs(e.Fragment,{children:[e.jsx("img",{src:wt(a),alt:a.title||"Organization media",className:"w-full h-full object-cover transition-transform duration-300 group-hover:scale-105 bg-gray-800",loading:"lazy",onError:A=>{A.currentTarget.style.display="none"}}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/30 group-hover:bg-black/40 transition-colors",children:e.jsx("div",{className:"w-12 h-12 sm:w-14 sm:h-14 roun
84ded-full bg-white/20 backdrop-blur-sm flex items-center justify-center",children:e.jsx("span",{className:"text-white text-xl ml-1",children:"▶"})})})]}):e.jsx("img",{src:wt(a),alt:a.title||"Organization media",className:"w-full h-full object-cover transition-transform duration-300 group-hover:scale-105",loading:"lazy"}),e.jsx("div",{className:"absolute top-2 left-2 px-2 py-1 bg-black/60 backdrop-blur-sm text-[10px] sm:text-xs font-medium text-white rounded-lg flex items-center gap-1",children:e.jsx("span",{className:"uppercase",children:a.type})}),e.jsxs("div",{className:"absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/80 via-black/30 to-transparent p-2.5 sm:p-3 opacity-100 sm:opacity-0 sm:group-hover:opacity-100 transition-opacity duration-200",children:[e.jsx("p",{className:"text-white text-xs sm:text-sm font-medium truncate",children:a.title||"Untitled"}),e.jsxs("div",{className:"flex items-center justify-between mt-1",children:[e.jsx("span",{className:"text-gray-300 text-[10px] sm:text-xs truncate",children:a.user_name}),e.jsx("span",{className:"text-gray-400 text-[10px] flex-shrink-0",children:ee(a.created_at)})]})]})]},a.id))}),b>1&&e.jsxs("div",{className:"flex justify-center items-center gap-2 sm:gap-3 pt-2",children:[e.jsxs("button",{onClick:()=>W(Math.max(1,j-1)),disabled:j===1,className:"px-3 sm:px-4 py-2 bg-gray-800/50 hover:bg-gray-700/50 disabled:opacity-30 text-white rounded-xl transition-all text-sm font-medium border border-gray-700/50 disabled:cursor-not-allowed",children:["← ",e.jsx("span",{className:"hidden sm:inline",children:"Prev"})]}),e.jsxs("div",{className:"text-gray-400 text-sm px-3",children:[e.jsx("span",{className:"font-medium text-white",children:j}),e.jsx("span",{children:" / "}),e.jsx("span",{className:"text-gray-500",children:b})]}),e.jsxs("button",{onClick:()=>W(Math.min(b,j+1)),disabled:j===b,className:"px-3 sm:px-4 py-2 bg-gray-800/50 hover:bg-gray-700/50 disabled:opacity-30 text-white rounded-xl transition-all text-sm font-medium border border-gray-700/50 disabled:cursor-not-allowed",children:[e.jsx("span",{className:"hidden sm:inline",children:"Next "}),"→"]})]})]}),x&&e.jsxs("div",{className:"fixed inset-0 bg-black/95 backdrop-blur-md z-[60] flex flex-col",onClick:a=>a.target===a.currentTarget&&l(null),children:[e.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between px-4 sm:px-6 py-3 sm:py-4 border-b border-gray-800/50 bg-gray-950/50 backdrop-blur-sm",children:[e.jsx("div",{className:"flex items-center gap-3 min-w-0",children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-sm sm:text-lg font-semibold text-white truncate",children:x.title||"Untitled"}),e.jsxs("p",{className:"text-xs text-gray-500 hidden sm:block",children:["by ",x.user_name," • ",ee(x.created_at)]})]})}),e.jsx("button",{onClick:()=>l(null),className:"w-10 h-10 flex items-center justify-center bg-gray-800/50 hover:bg-gray-700/50 rounded-xl transition-colors",children:e.jsx("span",{className:"text-xl text-gray-400 hover:text-white",children:"✕"})})]}),e.jsxs("div",{className:"flex-1 flex flex-col lg:flex-row overflow-hidden",children:[e.jsx("div",{className:"flex-1 flex items-center justify-center p-4 sm:p-6 bg-black/50 min-h-0",children:x.type==="video"?e.jsx(rt,{src:x.cloudinary_url,autoPlay:!0,className:"max-w-full max-h-full rounded-lg shadow-2xl",maxHeight:"calc(100vh - 200px)",downloadFilename:qe(x.title||void 0,"video",`media_${x.id}`),onDownload:()=>S(x.cloudinary_url,x.title||"video.mp4")}):e.jsx("img",{src:x.cloudinary_url,alt:x.title||"Image",className:"max-w-full max-h-full rounded-lg shadow-2xl object-contain",style:{maxHeight:"calc(100vh - 200px)"}})}),e.jsx("div",{className:"flex-shrink-0 w-full lg:w-80 bg-gray-900/80 backdrop-blur-sm border-t lg:border-t-0 lg:border-l border-gray-800/50 overflow-y-auto",children:e.jsxs("div",{className:"p-4 sm:p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold text-gray-400 uppercase tracking-wider mb-2",children:"Created By"}),e.jsxs("div",{className:"flex items-center gap-3 bg-gray-800/40 border border-gray-700/30 rounded-lg p-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-full bg-brand-primary/20 flex items-center justify-center text-brand-primary font-bold text-sm",children:x.user_name.charAt(0).toUpperCase()}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-white font-medium text-sm truncate",children:x.user_name}),e.jsx("p",{className:"text-gray-500 text-xs",children:ee(x.created_at)})]})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold text-gray-400 uppercase tracking-wider mb-2",children:"Details"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"bg-gray-800/40 border border-gray-700/30 rounded-lg p-3",children:[e.jsx("p",{className:"text-gray-500 text-[10px] uppercase mb-0.5",children:"Type"}),e.jsx("p",{className:"text-white text-sm font-medium capitalize",children:x.type})]}),e.jsxs("div",{className:"bg-gray-800/40 border border-gray-700/30 rounded-lg p-3",children:[e.jsx("p",{className:"text-gray-500 text-[10px] uppercase mb-0.5",children:"Date"}),e.jsx("p",{className:"text-white text-sm font-medium",children:new Date(x.created_at).toLocaleDateString("en-US",{month:"short",day:"numeric"})})]})]})]}),x.description&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-semibold text-gray-400 uppercase tracking-wider mb-2",children:"Description"}),e.jsx("p",{className:"text-gray-300 text-sm bg-gray-800/40 border border-gray-700/30 rounded-lg p-3",children:x.description})]}),e.jsxs("button",{onClick:()=>S(x.cloudinary_url,x.title||`media.${x.type==="video"?"mp4":"jpg"}`),className:"w-full px-4 py-3 bg-brand-primary text-black font-bold rounded-xl hover:bg-brand-secondary transition-all duration-200 flex items-center justify-center gap-2 text-sm",children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"})}),"Download"]}),x.type==="image"&&e.jsx("button",{onClick:()=>E(x),disabled:B,className:"w-full px-4 py-3 bg-violet-600 hover:bg-violet-500 text-white font-bold rounded-xl transition-all duration-200 flex items-center justify-center gap-2 text-sm disabled:opacity-50",children:B?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"w-4 h-4 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})," ","Sharing..."]}):e.jsxs(e.Fragment,{children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8.684 13.342C8.886 12.938 9 12.482 9 12c0-.482-.114-.938-.316-1.342m0 2.684a3 3 0 110-2.684m0 2.684l6.632 3.316m-6.632-6l6.632-3.3
8416m0 0a3 3 0 105.367-2.684 3 3 0 00-5.367 2.684zm0 9.316a3 3 0 105.368 2.684 3 3 0 00-5.368-2.684z"})})," ","Share to Community"]})})]})})]})]})]})},Ps=kt.memo(Ms),zs=({orgId:r,orgName:f,onClose:c})=>{const[n,T]=s.useState("email"),[v,$]=s.useState([]),[_,g]=s.useState([]),[o,k]=s.useState(!1),[w,N]=s.useState(null),[u,x]=s.useState(null),[l,j]=s.useState(null),[M,B]=s.useState(""),[Y,C]=s.useState("member"),[P,U]=s.useState(null),[V,J]=s.useState(""),[I,b]=s.useState("member"),[m,D]=s.useState(""),[O,Q]=s.useState(""),[h,S]=s.useState(!1),[E,W]=s.useState(null),[ee,re]=s.useState(null),[a,A]=s.useState(!1),L=localStorage.getItem("morphyxToken");s.useEffect(()=>{n==="links"&&G(),n==="pending"&&p()},[n]);const G=async()=>{k(!0);try{const i=await fetch(`/api/organizations/${r}/invite-links`,{headers:{Authorization:`Bearer ${L}`}});if(!i.ok)throw new Error("Failed to fetch invite links");const K=await i.json();$(K.links||[])}catch(i){N(i instanceof Error?i.message:"Failed to load invite links")}finally{k(!1)}},p=async()=>{k(!0);try{const i=await fetch(`/api/organizations/${r}/pending-invites`,{headers:{Authorization:`Bearer ${L}`}});if(!i.ok)throw new Error("Failed to fetch pending invites");const K=await i.json();g(K.invitations||[])}catch(i){N(i instanceof Error?i.message:"Failed to load pending invites")}finally{k(!1)}},R=async i=>{if(i.preventDefault(),!!M){k(!0),N(null),U(null);try{const K=await fetch(`/api/organizations/${r}/invites`,{method:"POST",headers:{Authorization:`Bearer ${L}`,"Content-Type":"application/json"},body:JSON.stringify({email:M,role:Y,access_level:Y==="admin"?"edit":"view"})}),ie=await K.json();if(!K.ok)throw new Error(ie.message||"Failed to send invitation");x(ie.message),U(ie.inviteLink||null),B(""),setTimeout(()=>x(null),1e4)}catch(K){N(K instanceof Error?K.message:"Failed to send invitation")}finally{k(!1)}}},H=async i=>{i.preventDefault(),k(!0),N(null);try{const K=await fetch(`/api/organizations/${r}/invite-links`,{method:"POST",headers:{Authorization:`Bearer ${L}`,"Content-Type":"application/json"},body:JSON.stringify({name:V||null,role:I,access_level:I==="admin"?"edit":"view",max_uses:m?parseInt(m):null,expires_in_days:O?parseInt(O):null})}),ie=await K.json();if(!K.ok)throw new Error(ie.message||"Failed to create invite link");x("Invite link created!"),S(!1),J(""),D(""),Q(""),G(),setTimeout(()=>x(null),5e3)}catch(K){N(K instanceof Error?K.message:"Failed to create invite link")}finally{k(!1)}},te=async()=>{if(E){A(!0);try{if(!(await fetch(`/api/organizations/${r}/invite-links`,{method:"DELETE",headers:{Authorization:`Bearer ${L}`,"Content-Type":"application/json"},body:JSON.stringify({linkId:E.id})})).ok)throw new Error("Failed to deactivate link");x("Link deactivated"),G(),setTimeout(()=>x(null),3e3)}catch(i){N(i instanceof Error?i.message:"Failed to deactivate link")}finally{A(!1),W(null)}}},se=async i=>{try{const K=await fetch(`/api/organizations/${r}/pending-invites`,{method:"PATCH",headers:{Authorization:`Bearer ${L}`,"Content-Type":"application/json"},body:JSON.stringify({inviteId:i,extendDays:7})}),ie=await K.json();if(!K.ok)throw new Error(ie.message||"Failed to resend");x(ie.message),p(),setTimeout(()=>x(null),5e3)}catch(K){N(K instanceof Error?K.message:"Failed to resend invitation")}},le=async()=>{if(ee){A(!0);try{if(!(await fetch(`/api/organizations/${r}/pending-invites`,{method:"DELETE",headers:{Authorization:`Bearer ${L}`,"Content-Type":"application/json"},body:JSON.stringify({inviteId:ee.id})})).ok)throw new Error("Failed to cancel invitation");x("Invitation cancelled"),p(),setTimeout(()=>x(null),3e3)}catch(i){N(i instanceof Error?i.message:"Failed to cancel invitation")}finally{A(!1),re(null)}}},y=async(i,K)=>{try{await navigator.clipboard.writeText(i),j(K),setTimeout(()=>j(null),2e3)}catch{const ie=document.createElement("textarea");ie.value=i,document.body.appendChild(ie),ie.select(),document.execCommand("copy"),document.body.removeChild(ie),j(K),setTimeout(()=>j(null),2e3)}},X=i=>new Date(i).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"});return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-2 sm:p-4",children:[e.jsx("div",{className:"absolute inset-0 bg-black/90 backdrop-blur-2xl",onClick:c}),e.jsxs("div",{className:"relative bg-black border border-white/10 rounded-xl sm:rounded-2xl w-full max-w-2xl max-h-[95vh] sm:max-h-[90vh] overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"p-4 sm:p-6 border-b border-white/10",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("h2",{className:"text-lg sm:text-xl font-bold text-white flex items-center gap-2",children:[e.jsx(ue,{className:"w-5 h-5 flex-shrink-0"}),e.jsxs("span",{className:"truncate",children:["Invite to ",f]})]})}),c&&e.jsx("button",{onClick:c,className:"p-2 text-gray-400 hover:text-white rounded-lg hover:bg-white/10",children:"✕"})]}),e.jsx("div",{role:"tablist","aria-label":"Invite management tabs",className:"flex gap-2 mt-4 sm:mt-6 overflow-x-auto pb-2 scrollbar-hide",children:[{id:"email",label:"Email",icon:e.jsx(Te,{className:"w-4 h-4"})},{id:"links",label:"Links",icon:e.jsx(Re,{className:"w-4 h-4"})},{id:"pending",label:"Pending",icon:e.jsx(Ee,{className:"w-4 h-4"})}].map(i=>e.jsxs("button",{role:"tab","aria-selected":n===i.id,"aria-controls":`tabpanel-${i.id}`,onClick:()=>T(i.id),className:`flex items-center gap-1.5 flex-shrink-0 px-3 sm:px-4 py-2 rounded-lg text-xs sm:text-sm transition-colors whitespace-nowrap ${n===i.id?"bg-white text-black font-bold":"bg-white/5 border border-white/10 text-gray-300 hover:bg-white/10 font-medium"}`,children:[i.icon,i.label]},i.id))})]}),w&&e.jsxs("div",{className:"mx-4 sm:mx-6 mt-3 sm:mt-4 p-2 sm:p-3 bg-red-500/20 border border-red-500/30 rounded-lg text-red-300 text-xs sm:text-sm",children:[w,e.jsx("button",{onClick:()=>N(null),className:"float-right text-red-400 hover:text-red-200",children:"✕"})]}),u&&e.jsx("div",{className:"mx-4 sm:mx-6 mt-3 sm:mt-4 p-2 sm:p-3 bg-green-500/20 border border-green-500/30 rounded-lg text-green-300 text-xs sm:text-sm",children:u}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6",children:[n==="email"&&e.jsxs("div",{role:"tabpanel",id:"tabpanel-email",className:"space-y-4 sm:sp
84ace-y-6",children:[e.jsxs("form",{onSubmit:R,className:"space-y-4 sm:space-y-5",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-gray-200 mb-1.5 flex items-center gap-1.5",children:[e.jsx(Te,{className:"w-3.5 h-3.5 text-white/50"})," Email Address"]}),e.jsx("input",{type:"email",value:M,onChange:i=>B(i.target.value),placeholder:"[email protected]",className:"w-full px-3 sm:px-4 py-2.5 sm:py-3 rounded-lg bg-white/5 border border-white/10 hover:border-white/20 text-white text-sm focus:outline-none focus:ring-1 focus:ring-white/20 transition-all",required:!0})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-gray-200 mb-1.5 flex items-center gap-1.5",children:[e.jsx(_e,{className:"w-3.5 h-3.5 text-white/50"})," Role to Assign"]}),e.jsx("div",{className:"flex flex-wrap gap-2 sm:gap-3",children:[{value:"member",label:"Member",icon:e.jsx(ye,{className:"w-3.5 h-3.5 text-white/70"}),desc:"Can generate images & view gallery"},{value:"admin",label:"Admin",icon:e.jsx(_e,{className:"w-3.5 h-3.5 text-white/70"}),desc:"Can manage members & settings"}].map(i=>e.jsxs("button",{type:"button",onClick:()=>C(i.value),className:`flex-1 flex flex-col items-center sm:items-start p-2.5 sm:p-3 rounded-lg border text-left transition-all ${Y===i.value?"border-white/50 bg-white/10":"border-white/10 bg-white/5 hover:border-white/20"}`,children:[e.jsxs("span",{className:"font-bold text-white text-xs sm:text-sm flex items-center gap-1.5",children:[i.icon," ",i.label]}),e.jsx("span",{className:"text-[10px] sm:text-xs text-gray-400 mt-1 hidden sm:block",children:i.desc})]},i.value))})]}),e.jsxs("button",{type:"submit",disabled:o||!M,className:"w-full py-2.5 sm:py-3 bg-white hover:bg-gray-200 text-black text-sm sm:text-base font-bold rounded-lg transition-all disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2",children:[o?e.jsx($e,{className:"w-4 h-4 animate-spin"}):e.jsx(Te,{className:"w-4 h-4"}),e.jsx("span",{children:o?"Sending...":"Send Invitation Email"})]})]}),P&&e.jsxs("div",{className:"p-3 sm:p-4 rounded-lg bg-black border border-white/10 shadow-lg",children:[e.jsx("p",{className:"text-gray-300 text-xs sm:text-sm font-medium mb-2",children:"Or copy the direct link (valid for 7 days):"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:P,readOnly:!0,className:"flex-1 px-3 py-2 rounded-lg bg-white/5 text-gray-300 text-xs sm:text-sm border border-white/10 focus:outline-none"}),e.jsxs("button",{onClick:()=>y(P,"lastInvite"),className:`px-3 py-2 rounded-lg text-xs sm:text-sm font-semibold transition-colors flex items-center justify-center gap-1.5 ${l==="lastInvite"?"bg-white text-black":"bg-white/5 text-white hover:bg-white/10 border border-white/10"}`,children:[l==="lastInvite"?e.jsx(be,{className:"w-3.5 h-3.5"}):e.jsx(Be,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:l==="lastInvite"?"Copied":"Copy"})]})]})]}),e.jsxs("div",{className:"text-center text-gray-500 text-xs sm:text-sm pt-4 border-t border-white/10 flex items-center justify-center gap-1.5",children:[e.jsx(Ve,{className:"w-3.5 h-3.5 text-white/50"}),e.jsxs("span",{children:["Tip: If emails aren't being received, use"," ",e.jsx("button",{onClick:()=>T("links"),className:"text-white font-semibold hover:underline",children:"Invite Links"})," ","instead"]})]})]}),n==="links"&&e.jsxs("div",{role:"tabpanel",id:"tabpanel-links",className:"space-y-4",children:[h?e.jsxs("form",{onSubmit:H,className:"p-3 sm:p-4 rounded-lg bg-white/5 border border-white/10 space-y-3 sm:space-y-4 shadow-lg",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h4",{className:"text-white font-medium text-sm sm:text-base flex items-center gap-1.5",children:[e.jsx(Re,{className:"w-4 h-4 text-white/70"})," Create Invite Link"]}),e.jsx("button",{type:"button",onClick:()=>S(!1),className:"text-gray-400 hover:text-white p-1 rounded-lg hover:bg-white/5 transition-colors",children:e.jsx(he,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 sm:gap-4",children:[e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx("label",{className:"block text-[10px] sm:text-xs text-gray-400 mb-1",children:"Link Name (optional)"}),e.jsx("input",{type:"text",value:V,onChange:i=>J(i.target.value),placeholder:"e.g., Marketing Team",className:"w-full px-3 py-2 rounded-lg bg-black border border-white/10 text-white text-xs sm:text-sm focus:border-white/20 focu
84s:ring-1 focus:ring-white/20 focus:outline-none transition-all"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] sm:text-xs text-gray-400 mb-1",children:"Role"}),e.jsxs("select",{value:I,onChange:i=>b(i.target.value),className:"w-full px-3 py-2 rounded-lg bg-black border border-white/10 text-white text-xs sm:text-sm focus:border-white/20 focus:ring-1 focus:ring-white/20 focus:outline-none transition-all",children:[e.jsx("option",{value:"member",className:"bg-gray-900",children:"Member"}),e.jsx("option",{value:"admin",className:"bg-gray-900",children:"Admin"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] sm:text-xs text-gray-400 mb-1",children:"Max Uses"}),e.jsx("input",{type:"number",value:m,onChange:i=>D(i.target.value),placeholder:"∞",min:"1",className:"w-full px-3 py-2 rounded-lg bg-black border border-white/10 text-white text-xs sm:text-sm focus:border-white/20 focus:ring-1 focus:ring-white/20 focus:outline-none transition-all"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[10px] sm:text-xs text-gray-400 mb-1",children:"Expires (days)"}),e.jsx("input",{type:"number",value:O,onChange:i=>Q(i.target.value),placeholder:"∞",min:"1",className:"w-full px-3 py-2 rounded-lg bg-black border border-white/10 text-white text-xs sm:text-sm focus:border-white/20 focus:ring-1 focus:ring-white/20 focus:outline-none transition-all"})]})]}),e.jsxs("button",{type:"submit",disabled:o,className:"w-full py-2 bg-white text-black text-sm font-bold rounded-lg hover:bg-gray-200 transition-all disabled:opacity-50 flex items-center justify-center gap-1.5 mt-2",children:[o?e.jsx($e,{className:"w-4 h-4 animate-spin"}):e.jsx(Re,{className:"w-4 h-4"}),e.jsx("span",{children:o?"Creating...":"Create Link"})]})]}):e.jsxs("button",{onClick:()=>S(!0),className:"w-full py-3 border-2 border-dashed border-white/20 rounded-lg text-gray-400 hover:border-white/50 hover:text-white transition-colors flex items-center justify-center gap-2",children:[e.jsx(De,{className:"w-4 h-4"})," Create New Invite Link"]}),o&&v.length===0?e.jsx("div",{className:"text-center py-8 text-gray-400 text-sm",children:"Loading..."}):v.length===0?e.jsx("div",{className:"text-center py-8 text-gray-500 text-sm",children:"No invite links yet. Create one above."}):e.jsx("div",{className:"space-y-2 sm:space-y-3",children:v.map(i=>e.jsx("div",{className:`p-3 sm:p-4 rounded-xl border shadow-lg ${i.is_active&&!i.isExpired&&!i.isMaxedOut?"bg-black border-white/10 hover:border-white/20":"bg-[#0a0a0a] border-white/5 opacity-60"}`,children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start justify-between gap-3 sm:gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 sm:gap-2 mb-1",children:[e.jsx("span",{className:"text-white font-bold text-sm sm:text-base truncate",children:i.name||`Link ${i.link_code}`}),e.jsx("span",{className:`px-1.5 sm:px-2 py-0.5 rounded-full border text-[10px] sm:text-xs font-semibold ${i.role==="admin","bg-white/5 border-white/10 text-white"}`,children:i.role==="admin"?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(_e,{className:"w-3 h-3 text-white/70"})," Admin"]}):e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ye,{className:"w-3 h-3 text-white/70"})," Member"]})}),(!i.is_active||i.isExpired||i.isMaxedOut)&&e.jsx("span",{className:"px-1.5 sm:px-2 py-0.5 rounded-full border border-white/10 text-[10px] sm:text-xs bg-white/5 text-gray-500 font-bold",children:i.is_active?i.isExpired?"Expired":"Maxed":"Off"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-stretch sm:items-center gap-2 mt-2",children:[e.jsx("code",{className:"flex-1 px-2 py-1.5 rounded-lg bg-white/5 text-gray-300 text-[10px] sm:text-xs border border-white/10 truncate",children:i.inviteUrl}),e.jsxs("div",{className:"flex gap-1.5 sm:gap-2",children:[e.jsxs("button",{onClick:()=>y(i.inviteUrl,`link-${i.id}`),className:`flex-1 sm:flex-none px-3 py-1.5 rounded-lg text-[10px] sm:text-xs font-semibold transition-colors border flex items-center justify-center gap-1 ${l===`link-${i.id}`?"bg-white border-white text-black":"bg-white/5 border-white/10 text-white hover:bg-white/10"}`,children:[l===`link-${i.id}`?e.jsx(be,{className:"w-3 h-3"}):e.jsx(Be,{className:"w-3 h-3"}),e.jsx("span",{children:l===`link-${i.id}`?"Copied":"Link"})]}),e.jsx("button",{onClick:()=>y(i.link_code,`code-${i.id}`),className:`flex-1 sm:flex-none px-3 py-1.5 rounded-lg text-[10px] sm:text-xs font-semibold transition-colors border flex items-center justify-center gap-1 ${l===`code-${i.id}`?"bg-white border-white text-black":"bg-white/5 border-white/10 text-white hover:bg-white/10"}`,title:"Copy short code",children:l===`code-${i.id}`?e.jsx(be,{className:"w-3 h-3"}):i.link_code})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 sm:gap-4 mt-3 text-[10px] sm:text-xs text-gray-500 font-medium",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ue,{className:"w-3 h-3"})," ",i.use_count,i.max_uses?`/${i.max_uses}`:""]}),i.expires_at&&e.jsxs("span",{className:"hidden sm:flex items-center gap-1",children:[e.jsx(Ee,{className:"w-3 h-3"})," ",X(i.expires_at)]}),e.jsxs("span",{className:"hidden sm:flex items-center gap-1",children:[e.jsx(ye,{className:"w-3 h-3"})," ",i.created_by_name]})]})]}),i.is_active&&e.jsx("button",{onClick:()=>W(i),className:"self-start px-3 py-1.5 rounded-lg border border-white/10 text-[10px] sm:text-xs bg-white/5 text-white hover:bg-white/10 whitespace-nowrap font-semibold transition-all",children:"Deactivate"})]})},i.id))})]}),n==="pending"&&e.jsx("div",{role:"tabpanel",id:"tabpanel-pending",className:"space-y-3",children:o?e.jsx("div",{className:"text-center py-8 text-gray-400 text-sm",children:"Loading..."}):_.length===0?e.jsx("div",{className:"text-center py-8 text-gray-500 text-sm",children:"No pending invitations"}):_.map(i=>
84e.jsx("div",{className:"p-3 sm:p-4 rounded-xl border border-white/10 bg-black shadow-lg",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start justify-between gap-3 sm:gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 sm:gap-2 mb-1",children:[e.jsx("span",{className:"text-white font-bold text-sm sm:text-base truncate",children:i.email}),e.jsx("span",{className:`px-1.5 sm:px-2 py-0.5 rounded-full border border-white/10 text-[10px] sm:text-xs font-semibold ${i.current_status==="pending"?"bg-white/5 text-white":i.current_status==="expired"?"bg-white/5 text-gray-500":"bg-white/5 text-white"}`,children:i.current_status}),e.jsx("span",{className:`px-1.5 sm:px-2 py-0.5 rounded-full border text-[10px] sm:text-xs font-semibold ${i.role==="admin","bg-white/5 border-white/10 text-white"}`,children:i.role==="admin"?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(_e,{className:"w-3 h-3 text-white/70"})," Admin"]}):e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ye,{className:"w-3 h-3 text-white/70"})," Member"]})})]}),i.current_status!=="accepted"&&e.jsxs("div",{className:"flex flex-col sm:flex-row items-stretch sm:items-center gap-2 mt-2",children:[e.jsx("code",{className:"flex-1 px-2 py-1.5 rounded-lg bg-white/5 text-gray-300 text-[10px] sm:text-xs border border-white/10 truncate",children:i.inviteLink}),e.jsxs("button",{onClick:()=>y(i.inviteLink,`invite-${i.id}`),className:`px-3 py-1.5 rounded-lg text-[10px] sm:text-xs font-semibold transition-colors border flex items-center justify-center gap-1 ${l===`invite-${i.id}`?"bg-white border-white text-black":"bg-white/5 border-white/10 text-white hover:bg-white/10"}`,children:[l===`invite-${i.id}`?e.jsx(be,{className:"w-3 h-3"}):e.jsx(Be,{className:"w-3 h-3"}),e.jsx("span",{children:l===`invite-${i.id}`?"Copied":"Copy Link"})]})]}),e.jsxs("div",{className:"text-[10px] sm:text-xs text-gray-500 font-medium mt-3 flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"hidden sm:flex items-center gap-1",children:[e.jsx(ye,{className:"w-3 h-3"})," Invited by ",i.invited_by_name]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Ee,{className:"w-3 h-3"})," ",X(i.created_at)]}),i.expires_at&&e.jsxs("span",{className:"hidden sm:flex items-center gap-1",children:["Expires: ",X(i.expires_at)]})]})]}),i.canResend&&e.jsxs("div",{className:"flex gap-2 self-start",children:[e.jsx("button",{onClick:()=>se(i.id),className:"px-3 py-1.5 rounded-lg border border-white/10 text-[10px] sm:text-xs bg-white/5 text-white hover:bg-white/10 whitespace-nowrap font-semibold transition-all",children:"Resend"}),e.jsx("button",{onClick:()=>re(i),className:"px-3 py-1.5 rounded-lg border border-white/10 text-[10px] sm:text-xs bg-white/5 text-white hover:bg-white/10 whitespace-nowrap font-semibold transition-all",children:"Cancel"})]})]})},i.id))})]})]}),e.jsx(ve,{isOpen:!!E,title:"Deactivate Invite Link?",message:"Are you sure you want to deactivate this invite link? Users will no longer be able to join using this link.",confirmText:"Deactivate",confirmStyle:"danger",isLoading:a,onConfirm:te,onCancel:()=>W(null)}),e.jsx(ve,{isOpen:!!ee,title:"Cancel Invitation?",message:`Are you sure you want to cancel the invitation to ${ee==null?void 0:ee.email}?`,confirmText:"Cancel Invitation",confirmStyle:"danger",isLoading:a,onConfirm:le,onCancel:()=>re(null)})]})},Ds=kt.memo(zs),jt=({taskId:r})=>{const[f,c]=s.useState(!1),n=()=>{navigator.clipboard.writeText(r),c(!0),setTimeout(()=>c(!1),2e3)};return e.jsx("button",{onClick:n,className:"ml-2 inline-flex items-center justify-center p-1 hover:bg-white/10 rounded transition-colors text-gray-500 hover:text-white",title:"Copy Task ID",children:f?e.jsx(be,{className:"w-3.5 h-3.5 text-green-400"}):e.jsx(Be,{className:"w-3.5 h-3.5"})})},Ls=20,Fs=(r,f)=>{const c=new Date;if(r==="7d"){const n=new Date(c);return n.setDate(n.getDate()-7),n.toISOString().slice(0,10)}if(r==="30d"){const n=new Date(c);return n.setDate(n.getDate()-30),n.toISOString().slice(0,10)}if(r==="90d"){const n=new Date(c);return n.setDate(n.getDate()-90),n.toISOString().slice(0,10)}if(r==="ytd")return`${c.getFullYear()}-01-01`;if(r==="custom")return f||void 0},Os=(r,f,c)=>{switch(r){case"7d":return"Last 7 days";case"30d":return"Last 30 days";case"90d":return"Last 90 days";case"ytd":return"Year to date";
84case"custom":return`${f||"start"} to ${c||"today"}`;default:return"All time"}},Pe=r=>r.toLocaleString(void 0,{maximumFractionDigits:2,minimumFractionDigits:0}),Is=({orgId:r,orgName:f})=>{const c=localStorage.getItem("morphyxToken"),[n,T]=s.useState([]),[v,$]=s.useState({totalTopup:0,totalUsage:0,totalCount:0}),[_,g]=s.useState(1),[o,k]=s.useState(1),[w,N]=s.useState(!0),[u,x]=s.useState(null),[l,j]=s.useState(null),[M,B]=s.useState("30d"),[Y,C]=s.useState(""),[P,U]=s.useState(""),[V,J]=s.useState("All"),[I,b]=s.useState(""),[m,D]=s.useState("");s.useEffect(()=>{const a=setTimeout(()=>b(m),400);return()=>clearTimeout(a)},[m]);const O=s.useMemo(()=>Fs(M,Y),[M,Y]),Q=M==="custom"&&P||void 0,h=s.useCallback(async a=>{var A;N(!0),x(null);try{const L=new URLSearchParams({page:String(a),limit:String(Ls)});V!=="All"&&L.append("type",V),O&&L.append("dateFrom",O),Q&&L.append("dateTo",Q),I.trim()&&L.append("search",I.trim());const G=await fetch(`/api/organizations/${r}/transactions?${L}`,{headers:{Authorization:`Bearer ${c}`}});if(!G.ok){const R=await G.json().catch(()=>({}));throw new Error(R.message||"Failed to load report data.")}const p=await G.json();T(p.items||[]),$(p.summary||{totalTopup:0,totalUsage:0,totalCount:0}),k(((A=p.pagination)==null?void 0:A.pages)||1)}catch(L){x(L instanceof Error?L.message:"Failed to load report data.")}finally{N(!1)}},[r,c,V,O,Q,I]);s.useEffect(()=>{g(1)},[V,O,Q,I]),s.useEffect(()=>{h(_)},[h,_]);const S=()=>({title:`Organization Usage — ${f}`,organizationName:f,dateFrom:O,dateTo:Q,rangeLabel:Os(M,Y,P),type:V!=="All"?V:void 0,search:I.trim()||void 0}),E=async()=>{const a=new URLSearchParams({page:"1",limit:"10000"});V!=="All"&&a.append("type",V),O&&a.append("dateFrom",O),Q&&a.append("dateTo",Q),I.trim()&&a.append("search",I.trim());const A=await fetch(`/api/organizations/${r}/transactions?${a}`,{headers:{Authorization:`Bearer ${c}`}});if(!A.ok)throw new Error("Failed to fetch report data for export.");return(await A.json()).items||[]},W=a=>{const A=["Date","User","Project","Type","Model","Task ID","Amount","Description"],L=y=>`"${String(y??"").replace(/"/g,'""')}"`,G=a.map(y=>{var X;return[L(new Date(y.created_at).toLocaleString()),L(y.user_name||""),L(y.project_name||"N/A"),L(y.type),L(y.model_label||""),L(((X=y.metadata)==null?void 0:X.provider_task_id)||""),y.amount,L(y.description||"")]}),R=`"* Note: Project attribution tracking for credit deductions was introduced on Sept 15, 2026. Records prior to this date, as well as current generations made via Film Agents, will not have project names attached."
85
86${[A.join(","),...G.map(y=>y.join(","))].join(`
87`)}`,H=new Blob(["\uFEFF"+R],{type:"text/csv;charset=utf-8;"}),te=URL.createObjectURL(H),se=document.createElement("a");se.href=te;const le=f.replace(/[^a-z0-9]+/gi,"-").toLowerCase();se.download=`morphyx-${le}-report-${new Date().toISOString().slice(0,10)}.csv`,document.body.appendChild(se),se.click(),document.body.removeChild(se),URL.revokeObjectURL(te)},ee=async a=>{j(a),x(null);try{const A=await E();if(A.length===0){x("No transactions found for the selected filters.");return}if(a==="csv")W(A);else{const{exportTransactionsPdf:L,exportTransactionsExcel:G}=await Wt(async()=>{const{exportTransactionsPdf:R,exportTransactionsExcel:H}=await import("./transactionReport-9zL14eTi.js").then(te=>te.t);return{exportTransactionsPdf:R,exportTransactionsExcel:H}},__vite__mapDeps([0,1,2])),p=S();a==="pdf"?await L(A,p):await G(A,p)}}catch(A){x(A instanceof Error?A.message:"Export failed. Please try again.")}finally{j(null)}},re=v.totalTopup-v.totalUsage;return e.jsxs("div",{className:"space-y-5",role:"region","aria-label":"Organization usage reports",children:[e.jsx("div",{className:"flex items-center gap-2 mb-1",children:e.jsx("h3",{className:"text-sm font-bold text-white",children:"Usage & Credit Reports"})}),e.jsx("p",{className:"text-xs text-gray-400 -mt-2",children:"Track your organization's credit topups and usage, then export a filtered report for accounting or review."}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"bg-black/40 rounded-xl border border-white/10 p-3 sm:p-4",children:[e.jsx("p",{className:"text-[10px] sm:text-xs text-gray-400 font-semibold uppercase tracking-wide",children:"Topped Up"}),e.jsxs("p",{className:"text-lg sm:text-xl font-bold text-white mt-1",children:["+",Pe(v.totalTopup)]})]}),e.jsxs("div",{className:"bg-black/40 rounded-xl border border-white/10 p-3 sm:p-4",children:[e.jsx("p",{className:"text-[10px] sm:text-xs text-gray-400 font-semibold uppercase tracking-wide",children:"Used"}),e.jsxs("p",{className:"text-lg sm:text-xl font-bold text-white mt-1",children:["-",Pe(v.totalUsage)]})]}),e.jsxs("div",{className:"bg-black/40 rounded-xl border border-white/10 p-3 sm:p-4 col-span-2 sm:col-span-1",children:[e.jsx("p",{className:"text-[10px] sm:text-xs text-gray-400 font-semibold uppercase tracking-wide",children:"Net"}),e.jsxs("p",{className:"text-lg sm:text-xl font-bold mt-1 text-white",children:[re>=0?"+":"",Pe(re)]})]})]}),e.jsxs("div",{className:"bg-black/40 rounded-xl border border-white/10 p-3 sm:p-4 space-y-3",children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:["7d","30d","90d","ytd","all","custom"].map(a=>e.jsx("button",{type:"button",onClick:()=>B(a),"aria-pressed":M===a,className:`px-3 py-1.5 text-xs font-semibold rounded-lg border transition-all ${M===a?"bg-brand-primary text-black border-brand-primary":"bg-gray-900/50 text-gray-300 border-gray-700 hover:border-gray-600"}`,children:a==="7d"?"7 Days":a==="30d"?"30 Days":a==="90d"?"90 Days":a==="ytd"?"YTD":a==="all"?"All Time":"Custom"},a))}),M==="custom"&&e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"report-date-from",className:"block text-[10px] font-semibold text-gray-400 mb-1",children:"From"}),e.jsx("input",{id:"report-date-from",type:"date",value:Y,onChange:a=>C(a.target.value),className:"w-full px-2.5 py-1.5 bg-black/40 border border-white/10 rounded-lg text-white text-xs focus:outline-none focus:border-white/30 transition-colors"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"report-date-to",className:"block text-[10px] font-semibold text-gray-400 mb-1",children:"To"}),e.jsx("input",{id:"report-date-to",type:"date",value:P,onChange:a=>U(a.target.value),className:"w-full px-2.5 py-1.5 bg-black/40 border border-white/10 rounded-lg text-white text-xs focus:outline-none focus:border-white/30 transition-colors"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"report-type-filter",className:"block text-[10px] font-semibold text-gray-400 mb-1",children:"Type"}),e.jsxs("select",{id:"report-type-filter",value:V,onChange:a=>J(a.target.value),className:"w-full px-2.5 py-1.5 bg-black/40 border border-white/10 rounded-lg text-white text-xs focus:outline-none focus:border-white/30 transition-colors appearance-none",children:[e.jsx("option",{value:"All",className:"bg-gray-900",children:"All Types"}),e.jsx("option",{value:"TOPUP",className:"bg-gray-900",children:"Topups"}),e.jsx("option",{value:"USAGE",className:"bg-gray-900",children:"Usage"}),e.jsx("option",{value:"ADMIN_TOPUP",className:"bg-gray-900",children:"Admin Topup"}),e.jsx("option",{value:"ADMIN_SET",className:"bg-gray-900",children:"Admin Adjustment"})]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"report-search",className:"block text-[10px] font-semibold text-gray-400 mb-1",children:"Search member"}),e.jsx("input",{id:"report-search",type:"text",value:m,onChange:a=>D(a.target.value),placeholder:"Search by name...",className:"w-full px-2.5 py-1.5 bg-black/40 border border-white/10 rounded-lg text-white placeholder-gray-500 text-xs focus:outline-none focus:border-white/30 transition-colors"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 pt-1",children:[e.jsxs("button",{type:"button",onClick:()=>ee("pdf"),disabled:l!==null,className:"flex-1 sm:flex-none px-3 py-2 text-xs font-semibold rounded-lg bg-white/5 hover:bg-white/10 text-white border border-white/10 disabled:opacity-50 disabled:cursor-not-allowed transition-all flex items-center justify-center gap-1.5",children:[l==="pdf"?e.jsx($e,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(st,{className:"w-3.5 h-3.5"}),l==="pdf"?"Exporting…":"Export PDF"]}),e.jsxs("button",{type:"button",onClick:()=>ee("excel"),disabled:l!==null,className:"flex-1 sm:flex-none px-3 py-2 text-xs font-semibold rounded-lg bg-white/5 hover:bg-white/10 text-white border border-white/10 disabled:opacity-50 disabled:cursor-not-allowed transition-all flex items-center justify-center gap-1.5",children:[l==="excel"?e.jsx($e,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(Ht,{className:"w-3.5 h-3.5"}),l==="excel"?"Exporting…":"Export Excel"]}),e.jsxs("button",{type:"button",onClick:()=>ee("csv"),disabled:l!==null,className:"flex-1 sm:flex-none px-3 py-2 text-xs font-semibold rounded-lg bg-white/5 hover:bg-white/10 text-white border border-white/10 disabled:opacity-50 disabled:cursor-not-allowed transition-all flex items-center justify-center gap-1.5",children:[l==="csv"?e.jsx($e,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(hs,{className:"w-3.5 h-3.5"}),l==="csv"?"Exporting…":"Export CSV"]})]})]}),u&&e.jsx("div",{className:"p-3 bg-red-500/10 border border-red-500/20 text-red-400 rounded-xl text-sm font-medium",children:u}),w?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 bg-black/40 rounded-xl border border-white/10 border-dashed",children:[e.jsx("div",{className:"w-8 h-8 border-3 border-brand-primary/30 border-t-brand-primary rounded-full animate-spin mb
87-3"}),e.jsx("p",{className:"text-gray-400 text-sm font-medium",children:"Loading report…"})]}):n.length===0?e.jsxs("div",{className:"text-center py-12 bg-black/40 rounded-xl border border-white/10 border-dashed",children:[e.jsx("p",{className:"text-gray-300 text-sm font-medium mb-1",children:"No transactions found"}),e.jsx("p",{className:"text-gray-500 text-xs",children:"Try adjusting your filters or date range"})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"hidden md:block overflow-x-auto rounded-xl border border-gray-700/50",children:e.jsxs("table",{className:"w-full text-xs text-left",children:[e.jsx("thead",{className:"bg-gray-800/70 text-gray-400 uppercase tracking-wide",children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",className:"px-4 py-2.5 font-semibold",children:"Date"}),e.jsx("th",{scope:"col",className:"px-4 py-2.5 font-semibold",children:"Member"}),e.jsx("th",{scope:"col",className:"px-4 py-2.5 font-semibold",children:"Project"}),e.jsx("th",{scope:"col",className:"px-4 py-2.5 font-semibold",children:"Type"}),e.jsx("th",{scope:"col",className:"px-4 py-2.5 font-semibold",children:"Description"}),e.jsx("th",{scope:"col",className:"px-4 py-2.5 font-semibold",children:"Task ID"}),e.jsx("th",{scope:"col",className:"px-4 py-2.5 font-semibold text-right",children:"Amount"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-800",children:n.map(a=>{var L,G,p;const A=["TOPUP","ADMIN_TOPUP"].includes(a.transaction_type||"");return e.jsxs("tr",{className:"bg-gray-900/30 hover:bg-gray-800/40 transition-colors",children:[e.jsx("td",{className:"px-4 py-2.5 text-gray-300 whitespace-nowrap",children:new Date(a.created_at).toLocaleDateString()}),e.jsx("td",{className:"px-4 py-2.5 text-white font-medium",children:a.user_name||"—"}),e.jsx("td",{className:"px-4 py-2.5 text-gray-400",children:a.project_name||"—"}),e.jsx("td",{className:"px-4 py-2.5 text-gray-400",children:a.type}),e.jsx("td",{className:"px-4 py-2.5 text-gray-400 max-w-xs truncate",children:a.description||"—"}),e.jsx("td",{className:"px-4 py-2.5 whitespace-nowrap",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"text-gray-500 font-mono text-[10px] max-w-[120px] truncate",title:(L=a.metadata)!=null&&L.provider_task_id?String(a.metadata.provider_task_id):void 0,children:(G=a.metadata)!=null&&G.provider_task_id?String(a.metadata.provider_task_id):"—"}),((p=a.metadata)==null?void 0:p.provider_task_id)&&e.jsx(jt,{taskId:String(a.metadata.provider_task_id)})]})}),e.jsxs("td",{className:"px-4 py-2.5 text-right font-semibold whitespace-nowrap text-white",children:[A?"+":"-",Pe(Math.abs(Number(a.amount)))]})]},`${a.id}-${a.transaction_type}`)})})]})}),e.jsx("div",{className:"md:hidden space-y-2",children:n.map(a=>{var L;const A=["TOPUP","ADMIN_TOPUP"].includes(a.transaction_type||"");return e.jsxs("div",{className:"bg-black/40 rounded-lg border border-white/10 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-white font-semibold text-sm truncate",children:a.user_name||"—"}),e.jsxs("p",{className:"font-bold text-sm whitespace-nowrap text-white",children:[A?"+":"-",Pe(Math.abs(Number(a.amount)))]})]}),e.jsx("p",{className:"text-gray-400 text-xs mt-1 truncate",children:a.description||a.type}),((L=a.metadata)==null?void 0:L.provider_task_id)&&e.jsxs("div",{className:"flex items-center mt-0.5",children:[e.jsxs("p",{className:"text-gray-500 font-mono text-[10px] truncate",children:["Task: ",String(a.metadata.provider_task_id)]}),e.jsx(jt,{taskId:String(a.metadata.provider_task_id)})]}),e.jsx("p",{className:"text-gray-500 text-[10px] mt-1",children:new Date(a.created_at).toLocaleString()})]},`${a.id}-${a.transaction_type}-card`)})}),o>1&&e.jsxs("div",{className:"flex items-center justify-between pt-1",children:[e.jsx("button",{type:"button",onClick:()=>g(a=>Math.max(1,a-1)),disabled:_<=1,className:"px-3 py-1.5 text-xs font-semibold rounded-lg bg-gray-800/50 border border-gray-700 text-gray-300 disabled:opacity-40 disabled:cursor-not-allowed hover:border-gray-600 transition-all",children:"← Previous"}),e.jsxs("span",{className:"text-xs text-gray-400",children:["Page ",_," of ",o]}),e.jsx("button",{type:"button",onClick:()=>g(a=>Math.min(o,a+1)),disabled:_>=o,className:"px-3 py-1.5 text-xs font-semibold rounded-lg bg-gray-800/50 border border-gray-700 text-gray-300 disabled:opacity-40 disabled:cursor-not-allowed hover:border-gray-600 transition-all",children:"Next →"})]})]})]})},at={INVITE_SENT:{label:"Invite sent",tone:"text-white"},INVITE_RESENT:{label:"Invite resent",tone:"text-white"},INVITE_CANCELLED:{label:"Invite cancelled",tone:"text-white"},INVITE_ACCEPTED:{label:"Invite accepted",tone:"text-white"},INVITE_LINK_CREATED:{label:"Invite link created",tone:"text-white"},INVITE_LINK_DEACTIVATED:{label:"Invite link deactivated",tone:"text-white"},MEMBER_ADDED:{label:"Member added",tone:"text-white"},MEMBER_JOINED_VIA_LINK:{label:"Joined via invite link",tone:"text-white"},MEMBER_JOINED_VIA_INVITE:{label:"Joined via invite",tone:"text-white"},MEMBER_ROLE_UPDATED:{label:"Role changed",tone:"text-white"},MEMBER_REMOVED:{label:"Member removed",tone:"text-white"}
87,MEMBER_LEFT:{label:"Member left",tone:"text-white"},ORGANIZATION_UPDATED:{label:"Organization updated",tone:"text-white"},ORGANIZATION_DELETED:{label:"Organization deleted",tone:"text-white"},OWNERSHIP_TRANSFERRED:{label:"Ownership transferred",tone:"text-white"},SPENDING_CAP_UPDATED:{label:"Spending cap updated",tone:"text-white"}},Rs=["All",...Object.keys(at)],Bs=25,Us=r=>{const f=Math.floor((Date.now()-new Date(r).getTime())/1e3);if(f<60)return"just now";const c=Math.floor(f/60);if(c<60)return`${c}m ago`;const n=Math.floor(c/60);if(n<24)return`${n}h ago`;const T=Math.floor(n/24);return T<30?`${T}d ago`:new Date(r).toLocaleDateString()},Vs=({orgId:r})=>{const f=localStorage.getItem("morphyxToken"),[c,n]=s.useState([]),[T,v]=s.useState(1),[$,_]=s.useState(1),[g,o]=s.useState(!0),[k,w]=s.useState(null),[N,u]=s.useState("All"),x=s.useCallback(async l=>{var j;o(!0),w(null);try{const M=new URLSearchParams({page:String(l),limit:String(Bs)});N!=="All"&&M.append("actionType",N);const B=await fetch(`/api/organizations/${r}/audit-log?${M}`,{headers:{Authorization:`Bearer ${f}`}});if(!B.ok){const C=await B.json().catch(()=>({}));throw new Error(C.message||"Failed to load activity log.")}const Y=await B.json();n(Y.items||[]),_(((j=Y.pagination)==null?void 0:j.pages)||1)}catch(M){w(M instanceof Error?M.message:"Failed to load activity log.")}finally{o(!1)}},[r,f,N]);return s.useEffect(()=>{v(1)},[N]),s.useEffect(()=>{x(T)},[x,T]),e.jsxs("div",{className:"space-y-4",role:"region","aria-label":"Organization activity log",children:[e.jsx("p",{className:"text-xs text-gray-400",children:"A record of security-relevant actions in this organization — invites, membership and role changes, ownership transfers, and settings updates."}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"audit-action-filter",className:"sr-only",children:"Filter by action type"}),e.jsx("select",{id:"audit-action-filter",value:N,onChange:l=>u(l.target.value),className:"w-full sm:w-auto px-2.5 py-1.5 bg-black/40 border border-white/10 rounded-lg text-white text-xs focus:outline-none focus:border-white/30 transition-colors appearance-none",children:Rs.map(l=>{var j;return e.jsx("option",{value:l,children:l==="All"?"All actions":((j=at[l])==null?void 0:j.label)||l},l)})})]}),k&&e.jsx("div",{className:"p-3 bg-red-500/10 border border-red-500/20 text-red-400 rounded-xl text-sm font-medium",children:k}),g?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 bg-black/40 rounded-xl border border-white/10 border-dashed",children:[e.jsx("div",{className:"w-8 h-8 border-3 border-brand-primary/30 border-t-brand-primary rounded-full animate-spin mb-3"}),e.jsx("p",{className:"text-gray-400 text-sm font-medium",children:"Loading activity…"})]}):c.length===0?e.jsxs("div",{className:"text-center py-12 bg-black/40 rounded-xl border border-white/10 border-dashed",children:[e.jsx("p",{className:"text-gray-300 text-sm font-medium mb-1",children:"No activity yet"}),e.jsx("p",{className:"text-gray-500 text-xs",children:"Actions taken in this organization will appear here"})]}):e.jsx("ul",{className:"space-y-2",children:c.map(l=>{const j=at[l.action_type]||{label:l.action_type,tone:"text-white"};return e.jsxs("li",{className:"flex items-start gap-3 bg-black/40 rounded-lg border border-white/10 p-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:`text-sm font-semibold ${j.tone}`,children:l.action||j.label}),e.jsxs("p",{className:"text-xs text-gray-400 mt-0.5",children:[l.actor_name?e.jsx("span",{className:"text-gray-300 font-medium",children:l.actor_name}):e.jsx("span",{className:"italic",children:"System"}),l.target_name&&e.jsxs(e.Fragment,{children:[" ","→ ",e.jsx("span",{className:"text-gray-300 font-medium",children:l.target_name})]})]})]}),e.jsx("span",{className:"text-[10px] text-gray-500 whitespace-nowrap mt-0.5",title:new Date(l.created_at).toLocaleString(),children:Us(l.created_at)})]},l.id)})}),$>1&&e.jsxs("div",{className:"flex items-center justify-between pt-1",children:[e.jsx("button",{type:"button",onClick:()=>v(l=>Math.max(1,l-1)),disabled:T<=1,className:"px-3 py-1.5 text-xs font-semibold rounded-lg bg-black/40 border border-white/10 text-gray-300 disabled:opacity-40 disabled:cursor-not-allowed hover:border-white/20 transition-all",children:"← Previous"}),e.jsxs("span",{className:"text-xs text-gray-400",children:["Page ",T," of ",$]}),e.jsx("button",{type:"button",onClick:()=>v(l=>Math.min($,l+1)),disabled:T>=$,className:"px-3 py-1.5 text-xs font-semibold rounded-lg bg-black/40 border border-white/10 text-gray-300 disabled:opacity-40 disabled:cursor-not-allowed hover:border-white/20 transition-all",children:"Next →"})]})]})},vt=({items:r,activeTab:f,onSelect:c,memberCount:n,layoutIdPrefix:T})=>e.jsx("nav",{className:"flex flex-col gap-0.5",children:r.map(v=>{const $=f===v.id,_=v.icon;return e.jsxs("button",{onClick:()=>c(v.id),className:"relative flex items-center gap-3 px-3 py-2.5 rounded-lg text-sm font-medium transition-colors duration-150 text-left",style:{color:$?"#b9ff00":"#9ca3af"},onMouseEnter:g=>{$||(g.currentTarget.style.color="#e5e7eb")},onMouseLeave:g=>{$||(g.currentTarget.style.color="#9ca3af")},children:[$&&e.jsx(we.div,{layoutId:`${T}-org-active-pill`,className:"absolute inset-0 rounded-lg",style:{background:"linear-gradient(135deg, rgba(185,255,0,0.16) 0%, rgba(191,0,255,0.10) 100%)",border:"1px solid rgba(185,255,0,0.28)",boxShadow:"0 2px 12px rgba(185,255,0,0.10)"},transition:{type:"spring",stiffness:500,damping:40}}),e.jsx(_,{className:"w-4 h-4 relative z-10 shrink-0"}),e.jsx("span",{className:"relative z-10 flex-1 truncate",children:v.label}),v.id==="members"&&e.jsx("span",{className:"relative z-10 text-[10px] font-bold px-1.5 py-0.5 rounded-full shrink-0",style:{background:$?"rgba(0,0,0,0.25)":"rgba(255,255,255,0.08)",color:$?"#b9ff00":"#9ca3af"},children:n})]},v.id)})}),qs=({activeTab:r,onSelect:f,memberCount:c,showOwnerTabs:n,orgName:T,onBack:v})=>{const[$,_]=s.useState(!1);s.useEffect(()=>{if($)return document.body.style.overflow="hidden",()=>{document.body.style.overflow=""}},[$]);
87const g=[{id:"members",label:"Members",icon:ue},{id:"gallery",label:"Gallery",icon:Gt},...n?[{id:"reports",label:"Reports",icon:it}]:[],...n?[{id:"settings",label:"Settings",icon:Ue}]:[]],o=N=>{f(N),_(!1)},k=g.find(N=>N.id===r)||g[0],w=k.icon;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"lg:hidden w-full mb-3",children:[e.jsxs("button",{onClick:v,className:"flex items-center gap-1.5 text-xs font-semibold text-gray-400 hover:text-white transition-colors mb-3",children:[e.jsx(ht,{className:"w-3.5 h-3.5"}),"Organization HQ"]}),e.jsxs("button",{onClick:()=>_(!0),className:"w-full flex items-center justify-between gap-3 px-4 py-3 rounded-xl bg-[#050505] border border-white/10",children:[e.jsxs("span",{className:"flex items-center gap-2.5 text-white font-semibold text-sm min-w-0",children:[e.jsx(w,{className:"w-4 h-4 shrink-0",style:{color:"#b9ff00"}}),e.jsx("span",{className:"truncate",children:k.label})]}),e.jsx(Kt,{className:"w-5 h-5 text-gray-400 shrink-0"})]})]}),e.jsx(zt,{children:$&&e.jsxs(e.Fragment,{children:[e.jsx(we.div,{initial:{opacity:0}
87,animate:{opacity:1},exit:{opacity:0},onClick:()=>_(!1),className:"fixed inset-0 z-[60] bg-black/60 backdrop-blur-sm lg:hidden"}),e.jsxs(we.div,{initial:{x:"-100%"},animate:{x:0},exit:{x:"-100%"},transition:{type:"spring",stiffness:400,damping:40},className:"fixed top-0 left-0 bottom-0 z-[70] w-[85vw] max-w-xs overflow-y-auto p-4 lg:hidden",style:{background:"#000000",borderRight:"1px solid rgba(255,255,255,0.08)"},children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("span",{className:"text-white font-bold text-sm truncate pr-2",children:T}),e.jsx("button",{onClick:()=>_(!1),className:"text-gray-400 hover:text-white p-1 shrink-0",children:e.jsx(he,{className:"w-5 h-5"})})]}),e.jsx(vt,{items:g,activeTab:r,onSelect:o,memberCount:c,layoutIdPrefix:"mobile"})]})]})}),e.jsxs("aside",{className:"hidden lg:block lg:sticky lg:top-24 w-56 shrink-0 rounded-2xl p-3 self-start max-h-[calc(100vh-7rem)] overflow-y-auto",style:{background:"#050505",border:"1px solid rgba(255,255,255,0.08)",boxShadow:"0 4px 24px rgba(0,0,0,0.3)"},children:[e.jsxs("button",{onClick:v,className:"flex items-center gap-1.5 text-xs font-semibold text-gray-400 hover:text-white transition-colors mb-3 px-1",children:[e.jsx(ht,{className:"w-3.5 h-3.5"}),"Organization HQ"]}),e.jsxs("div",{className:"px-1 pb-3 mb-2 border-b border-gray-700/50",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-wider font-semibold text-gray-500",children:"Managing"}),e.jsx("p",{className:"text-sm font-bold text-white truncate",children:T})]}),e.jsx(vt,{items:g,activeTab:r,onSelect:f,memberCount:c,layoutIdPrefix:"desktop"})]})]})},Gs=({orgId:r,orgName:f,onClose:c})=>{var lt;const{user:n}=Ae(),[T,v]=s.useState([]),[$,_]=s.useState(!0),[g,o]=s.useState(null),[k,w]=s.useState(null),[N,u]=s.useState(null),[x,l]=s.useState(!1),[j,M]=s.useState(""),[B,Y]=s.useState("member"),[C,P]=s.useState(!1),[U,V]=s.useState(null),[J,I]=s.useState("members"),[b,m]=s.useState("usage"),[D,O]=s.useState(!1),[Q,h]=s.useState(null),[S,E]=s.useState(""),[W,ee]=s.useState(!1),[re,a]=s.useState(!1),[A,L]=s.useState(new Set),[G,p]=s.useState("member"),[R,H]=s.useState(!1),[te,se]=s.useState(!1),[le,y]=s.useState(!1),[X,i]=s.useState(!1),[K,ie]=s.useState(!1),[ne,pe]=s.useState(!1),[Oe,Me]=s.useState(!1),ce=localStorage.getItem("morphyxToken"),oe=T.find(d=>
87String(d.user_id)===String(n==null?void 0:n.id)),je=(oe==null?void 0:oe.role)==="owner"||(oe==null?void 0:oe.role)==="admin",Ie=(oe==null?void 0:oe.role)==="owner",Ke=(oe==null?void 0:oe.role)==="admin";s.useEffect(()=>{Z()},[r]),s.useEffect(()=>{let d=!1;return(async()=>{try{const q=await fetch(`/api/organizations/${r}`,{headers:{Authorization:`Bearer ${ce}`}});if(!q.ok)return;const z=await q.json();if(d)return;y(!!(z!=null&&z.require_project_selection)),pe(!!(z!=null&&z.allow_personal_mcp)),ie(!0)}catch{}})(),()=>{d=!0}},[r,ce]);const Qe=async d=>{i(!0),o(null);const q=le;y(d);try{const z=await fetch(`/api/organizations/${r}`,{method:"PUT",headers:{Authorization:`Bearer ${ce}`,"Content-Type":"application/json"},body:JSON.stringify({require_project_selection:d})});if(!z.ok){const de=await z.text();throw new Error(de||"Failed to update policy")}w(d?"Project selection is now required for Cinema Studio generations ✓":"Project selection is now optional for Cinema Studio generations"),setTimeout(()=>w(null),4e3),window.dispatchEvent(new CustomEvent("cinema-studio:policy-refresh"))}catch(z){y(q),o(z instanceof Error?z.message:"Failed to update policy")}finally{i(!1)}},Ze=async d=>{Me(!0),o(null);const q=ne;pe(d);try{const z=await fetch(`/api/organizations/${r}`,{method:"PUT",headers:{Authorization:`Bearer ${ce}`,"Content-Type":"application/json"},body:JSON.stringify({allow_personal_mcp:d})});if(!z.ok){const de=await z.text();throw new Error(de||"Failed to update policy")}w(d?"Members can now add personal MCP tool servers ✓":"Personal MCP tool servers are now blocked for members"),setTimeout(()=>w(null),4e3)}catch(z){pe(q),o(z instanceof Error?z.message:"Failed to update policy")}finally{Me(!1)}},Xe=async()=>{if(S){a(!0),o(null);try{const d=await fetch(`/api/organizations/${r}/transfer-ownership`,{method:"POST",headers:{Authorization:`Bearer ${ce}`,"Content-Type":"application/json"},body:JSON.stringify({newOwnerUserId:S})});if(!d.ok){const q=await d.json().catch(()=>({}));throw new Error(q.message||"Failed to transfer ownership")}w("Ownership transferred successfully ✓"),setTimeout(()=>w(null),4e3),E(""),await Z()}catch(d){o(d instanceof Error?d.message:"Failed to transfer ownership")}finally{a(!1),ee(!1)}}},Ne=d=>
87je&&d.role!=="owner"&&String(d.user_id)!==String(n==null?void 0:n.id),t=d=>{L(q=>{const z=new Set(q),de=String(d);return z.has(de)?z.delete(de):z.add(de),z})},F=()=>{const d=T.filter(Ne).map(q=>String(q.user_id));L(q=>q.size===d.length?new Set:new Set(d))},ae=async()=>{H(!0),o(null);try{const q=(await Promise.allSettled(Array.from(A).map(z=>fetch(`/api/organizations/${r}/members?userId=${z}`,{method:"DELETE",headers:{Authorization:`Bearer ${ce}`,"Content-Type":"application/json"}})))).filter(z=>z.status==="rejected"||z.status==="fulfilled"&&!z.value.ok);L(new Set),await Z(),q.length>0?o(`${q.length} member(s) could not be removed. Please try again.`):(w("Selected members removed successfully ✓"),setTimeout(()=>w(null),4e3))}catch(d){o(d instanceof Error?d.message:"Bulk removal failed")}finally{H(!1),se(!1)}},me=async()=>{H(!0),o(null);try{const q=(await Promise.allSettled(Array.from(A).map(z=>fetch(`/api/organizations/${r}/members`,{method:"PATCH",headers:{Authorization:`Bearer ${ce}`,"Content-Type":"application/json"},body:JSON.stringify({user_id:z,role:G,access_level:G==="admin"?"edit":"view"})})))).filter(z=>z.status==="rejected"||z.status==="fulfilled"&&!z.value.ok);L(new Set),await Z(),q.length>0?o(`${q.length} member(s) could not be updated. Please try again.`):(w(`Role updated to ${G} for selected members ✓`),setTimeout(()=>w(null),4e3))}catch(d){o(d instanceof Error?d.message:"Bulk role update failed")}finally{H(!1)}},Z=async()=>{_(!0),o(null);try{const d=await fetch(`/api/organizations/${r}/members`,{headers:{Authorization:`Bearer ${ce}`,"Content-Type":"application/json"}});if(!d.ok)throw new Error(await d.text());const q=await d.json();v(Array.isArray(q)?q:q.members||[])}catch(d){o(d instanceof Error?d.message:"Failed to fetch members")}finally{_(!1)}},ke=async d=>{if(d.preventDefault(),!j){o("Please enter an email address");return}P(!0),o(null);try{const q=await fetch(`/api/organizations/${r}/invites`,{method:"POST",headers:{Authorization:`Bearer ${ce}`,"Content-Type":"application/json"},body:JSON.stringify({email:j,role:B,access_level:B==="admin"?"edit":"view"})});if(!q.ok){const z=await q.json();throw new Error(z.message||"Failed to send invitation")}w(`Invitation sent to ${j}!`),M(""),l(!1),setTimeout(()=>w(null),4e3),await Z()}catch(q){o(q instanceof Error?q.message:"Failed to send invitation")}finally{P(!1)}},et=async()=>{if(N){V(N.id.toString()),o(null);try{const d=T.find(z=>z.id===N.id),q=await fetch(`/api/organizations/${r}/members?userId=${d==null?void 0:d.user_id}`,{method:"DELETE",headers:{Authorization:`Bearer ${ce}`,"Content-Type":"application/json"}});if(!q.ok){let z=`HTTP ${q.status}`;try{const de=q.headers.get("content-type");de&&de.includes("application/json")?z=(await q.json()).message||z:z=await q.text()}catch{}throw new Error(z)}v(T.filter(z=>z.id!==N.id)),w("Member removed successfully"),setTimeout(()=>w(null),3e3)}catch(d){console.error("Remove member error:",d),o(`Failed to remove member: ${d.message}`)}finally{V(null),u(null)}}},Mt=d=>"bg-white/5 text-white border border-white/10";return e.jsxs("div",{className:"w-full",children:[e.jsxs("header",{className:"mb-6 opacity-0 animate-slide-in-left",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[e.jsx("div",{className:"w-1 h-8 rounded-full",style:{background:"linear-gradient(180deg, #b9ff00 0%, #6F00FF 100%)"}}),e.jsx("h1",{className:"text-2xl sm:text-3xl font-black",style:{background:"linear-gradient(90deg, #fff 0%, #9ca3af 100%)",WebkitBackgroundClip:"text",WebkitTextFillColor:"transparent"},children:"Organization Settings"})]}),e.jsx("p",{className:"text-gray-500 mt-1 ml-4 text-sm truncate",children:f})]}),e.jsxs("div",{className:"flex flex-col lg:flex-row gap-4 lg:gap-6 items-start",children:[e.jsx(qs,{activeTab:J,onSelect:I,memberCount:T.length,showOwnerTabs:je,orgName:f,onBack:()=>c&&c()}),e.jsxs("div",{className:"flex-1 w-full min-w-0 bg-black/40 backdrop-blur-md border border-white/10 rounded-xl p-4 sm:p-8 shadow-lg opacity-0 animate-fade-in-up",style:{animationDelay:"150ms"},children:[k&&e.jsxs("div",{className:"mb-4 p-3 bg-green-500/10 border border-green-500/20 text-green-400 rounded-xl text-sm font-medium flex items-center gap-2 animate-in fade-in slide-in-from-top-2",children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),k]}),g&&e.jsxs("div",{className:"mb-4 p-3 bg-red-500/10 border border-red-500/20 text-red-400 rounded-xl text-sm font-medium flex items-center gap-2 animate-in fade-in slide-in-from-top-2",children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),g]}),J==="members"&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(De,{className:"w-5 h-5 text-brand-primary shrink-0"}),e.jsx("h3",{className:"text-sm font-bold text-white",children:"Add Team Member"})]}),e.jsxs("div",{className:"bg-black rounded-lg border border-white/10 overflow-hidden shadow-lg",children:[e.jsxs("button",{onClick:()=>l(!x),className:"w-full px-4 py-3 flex items-center justify-between hover:bg-gray-900 transition-colors group",children:[e.jsxs("span",{className:"font-medium text-white flex items-center gap-2 text-sm",children:[e.jsx(Te,{className:"w-4 h-4 text-white/70"}),e.jsx("span",{children:x?"Close":"Send Invitation"})]}),e.jsx("svg",{className:`w-4 h-4 text-gray-400 transition-transform duration-300 ${x?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),x&&e.jsxs("div",{className:"px-4 py-3 border-t border-white/10 bg-black animate-in slide-in-from-top-2 space-y-3",children:[e.jsxs("form",{onSubmit:ke,className:"space-y-3",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-semibold text-gray-300 mb-2 flex items-center gap-1.5",children:[e.jsx(Te,{className:"w-3.5 h-3.5 text-white/50"}),"Email Address"]}),e.jsx("input",{type:"email",value:j,onChange:d=>M(d.target.value),placeholder:"[email protected]",className:"w-full px-3 py-2 bg-white/5 border border-white/10 rounded-lg text-white placeholder-gray-500 text-xs sm:text-sm focus:outline-none focus:border-white/20 focu
87s:ring-1 focus:ring-white/20 transition-all",required:!0})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-semibold text-gray-300 mb-2 flex items-center gap-1.5",children:[e.jsx(_e,{className:"w-3.5 h-3.5 text-white/50"}),"Role"]}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:B,onChange:d=>Y(d.target.value),className:"w-full px-3 py-2 bg-white/5 border border-white/10 rounded-lg text-white text-xs sm:text-sm appearance-none focus:outline-none focus:border-white/20 focus:ring-1 focus:ring-white/20 transition-all",children:[e.jsx("option",{value:"member",className:"bg-gray-900",children:"Member"}),e.jsx("option",{value:"admin",className:"bg-gray-900",children:"Admin"})]}),e.jsx("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 pointer-events-none text-gray-500",children:e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})})]})]}),e.jsx("button",{type:"submit",disabled:C||!j,className:"w-full sm:w-auto px-4 py-2 bg-white hover:bg-gray-200 disabled:bg-gray-600 disabled:cursor-not-allowed text-black text-xs sm:text-sm font-bold rounded-lg transition-all flex items-center justify-center gap-1.5 mt-auto h-[38px] sm:h-[40px]",children:C?e.jsx($e,{className:"w-4 h-4 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(De,{className:"w-4 h-4"}),e.jsx("span",{children:"Invite"})]})})]}),e.jsxs("div",{className:"text-xs text-gray-400 pt-1 flex items-start gap-1.5",children:[e.jsx(Ve,{className:"w-3.5 h-3.5 text-brand-primary flex-shrink-0 mt-0.5"}),e.jsx("span",{children:B==="admin"?"Admins manage members & credits":"Members generate images & view gallery"})]})]}),e.jsx("div",{className:"pt-3 border-t border-white/10",children:e.jsxs("button",{onClick:()=>O(!0),className:"w-full px-3 py-2 text-xs text-gray-400 hover:text-white hover:bg-white/10 rounded-lg transition-colors flex items-center justify-center gap-2 border border-transparent hover:border-white/10",children:[e.jsx(Re,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"Email not working? Use invite links or codes"}),e.jsx("span",{children:"→"})]})})]})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(ue,{className:"w-5 h-5 text-brand-primary shrink-0"}),e.jsx("h3",{className:"text-sm font-bold text-white",children:"Team Members"})]}),je&&T.some(Ne)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-3 p-2.5 bg-black rounded-lg border border-white/10 shadow-lg",children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-gray-300 cursor-pointer select-none",children:[e.jsx("input",{type:"checkbox",checked:A.size>0&&A.size===T.filter(Ne).length,onChange:F,className:"w-3.5 h-3.5 rounded border-gray-600 bg-gray-900 text-white focus:ring-white/50"}),"Select all"]}),A.size>0&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-xs text-gray-500",children:[A.size," selected"]}),e.jsxs("div",{className:"flex items-center gap-1.5 ml-auto",children:[e.jsxs("select",{value:G,onChange:d=>p(d.target.value),className:"px-2 py-1 bg-white/5 border border-white/10 rounded-lg text-white text-xs focus:outline-none focus:border-white/20",children:[e.jsx("option",{value:"member",className:"bg-gray-900",children:"Member"}),e.jsx("option",{value:"admin",className:"bg-gray-900",children:"Admin"})]}),e.jsx("button",{type:"button",onClick:me,disabled:R,className:"px-2.5 py-1 text-xs font-semibold rounded-lg bg-white/5 hover:bg-white/10 text-white border border-white/10 disabled:opacity-50 disabled:cursor-not-allowed transition-all whitespace-nowrap",children:"Apply Role"}),e.jsx("button",{type:"button",onClick:()=>se(!0),disabled:R,className:"px-2.5 py-1 text-xs font-semibold rounded-lg bg-white/5 hover:bg-white/10 text-white border border-white/10 disabled:opacity-50 disabled:cursor-not-allowed transition-all whitespace-nowrap",children:"Remove"})]})]})]}),$?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 bg-black rounded-xl border border-white/10 border-dashed shadow-lg",children:[e.jsx("div",{className:"w-8 h-8 border-3 border-white/30 border-t-white rounded-full animate-spin mb
87-3"}),e.jsx("p",{className:"text-gray-400 text-sm font-medium",children:"Loading team members..."})]}):T.length===0?e.jsxs("div",{className:"flex flex-col items-center text-center py-12 bg-black rounded-xl border border-white/10 border-dashed shadow-lg",children:[e.jsx(ue,{className:"w-10 h-10 text-gray-600 mb-3 opacity-60"}),e.jsx("p",{className:"text-gray-300 text-sm font-medium mb-1",children:"No team members yet"}),e.jsx("p",{className:"text-gray-500 text-xs",children:"Invite members above to build your team"})]}):e.jsx("div",{className:"space-y-3",children:T.map(d=>e.jsxs("div",{className:"group p-4 bg-black border border-white/10 hover:border-white/20 rounded-xl transition-all duration-200 shadow-lg",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0 relative pr-20",children:[Ne(d)&&e.jsx("input",{type:"checkbox",checked:A.has(String(d.user_id)),onChange:()=>t(d.user_id),"aria-label":`Select ${d.name}`,className:"w-3.5 h-3.5 rounded border-gray-600 bg-gray-900 text-white focus:ring-white/50 flex-shrink-0 cursor-pointer"}),e.jsx("div",{className:"w-10 h-10 rounded-full bg-gradient-to-br from-brand-primary to-brand-primary/60 flex items-center justify-center text-black font-bold text-sm shadow-lg shadow-brand-primary/25 flex-shrink-0 border border-brand-primary/50",children:d.name.charAt(0).toUpperCase()}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("p",{className:"text-white font-semibold text-sm transition-colors truncate",children:d.name}),d.role!=="owner"&&d.spending_cap!=null&&e.jsxs("span",{className:"flex items-center gap-1 text-[10px] font-semibold px-2 py-0.5 rounded-full bg-white/5 text-white border border-white/10 whitespace-nowrap",children:[e.jsx(Ct,{className:"w-3 h-3 text-white/70 shrink-0"}),e.jsxs("span",{children:[Number(d.spending_cap).toLocaleString(),d.spending_cap_period==="daily"?"/day":d.spending_cap_period==="weekly"?"/week":d.spending_cap_period==="lifetime"?" lifetime":"/mo"]})]})]}),e.jsx("p",{className:"text-gray-400 text-xs truncate mt-0.5",children:d.email})]}),e.jsx("div",{className:"absolute top-0 right-0",children:e.jsx("span",{className:`flex items-center gap-1 text-[10px] font-bold px-2 py-0.5 rounded-full border ${Mt(d.role)}`,children:d.role==="owner"?e.jsxs(e.Fragment,{children:[e.jsx(Qt,{className:"w-3 h-3 text-white shrink-0"})," Owner"]}):d.role==="admin"?e.jsxs(e.Fragment,{children:[e.jsx(_e,{className:"w-3 h-3 text-white shrink-0"})," Admin"]}):e.jsxs(e.Fragment,{children:[e.jsx(ye,{className:"w-3 h-3 text-white shrink-0"})," Member"]})})})]}),(()=>
87{const q=String(d.user_id)!==String(n==null?void 0:n.id),z=q&&(Ie&&d.role!=="owner"||Ke&&d.role==="member"),de=je&&d.role!=="owner"&&q;return!z&&!de?null:e.jsxs("div",{className:"flex items-center gap-2 mt-3 pt-3 border-t border-gray-700/40",children:[z&&e.jsxs("button",{onClick:()=>h(d),className:"flex-1 flex items-center justify-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-semibold bg-white/5 hover:bg-white/10 text-white border border-white/10 hover:border-white/20 transition-all",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),d.spending_cap!=null?"Edit Cap":"Set Cap"]}),de&&e.jsxs("button",{onClick:()=>u(d),disabled:U===d.id.toString(),className:"flex items-center justify-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-semibold bg-white/5 hover:bg-white/10 text-white border border-white/10 hover:border-white/20 disabled:opacity-50 disabled:cursor-not-allowed transition-all",children:[U===d.id.toString()?e.jsx("div",{className:"w-3.5 h-3.5 border-2 border-red-500/40 border-t-red-400 rounded-full animate-spin"}):e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})}),"Remove"]})]})})()]},d.id))})]})]}),J==="gallery"&&e.jsx("div",{className:"animate-in fade-in slide-in-from-bottom-4 duration-300",children:e.jsx(Ps,{orgId:r,orgName:f})}),J==="reports"&&je&&e.jsxs("div",{className:"animate-in fade-in slide-in-from-bottom-4 duration-300 space-y-4",children:[e.jsxs("div",{className:"flex gap-2 p-1 bg-gray-800/50 rounded-lg border border-gray-700/50 w-full sm:w-auto sm:inline-flex",children:[e.jsxs("button",{onClick:()=>m("usage"),className:`flex-1 sm:flex-none flex items-center justify-center gap-1.5 px-3 py-1.5 text-xs font-semibold rounded-md transition-all ${b==="usage"?"bg-brand-primary text-black shadow shadow-brand-primary/30":"text-gray-300 hover:text-white"}`,children:[e.jsx(Fe,{className:"w-3.5 h-3.5 shrink-0"}),e.jsx("span",{children:"Usage Report"})]}),e.jsxs("button",{onClick:()=>m("activity"),className:`flex-1 sm:flex-none flex items-center justify-center gap-1.5 px-3 py-1.5 text-xs font-semibold rounded-md transition-all ${b==="activity"?"bg-brand-primary text-black shadow shadow-brand-primary/30":"text-gray-300 hover:text-white"}`,children:[e.jsx(Ee,{className:"w-3.5 h-3.5 shrink-0"}),e.jsx("span",{children:"Activity Log"})]})]}),b==="usage"?e.jsx(Is,{orgId:r,orgName:f}):e.jsx(Vs,{orgId:r})]}),J==="settings"&&je&&e.jsxs("div",{className:"animate-in fade-in slide-in-from-bottom-4 duration-300 space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Dt,{className:"w-5 h-5 text-brand-primary shrink-0"}),e.jsx("h3",{className:"text-sm font-bold text-white",children:"Cinema Studio Generation Policy"})]}),e.jsx("p",{className:"text-xs text-gray-400 -mt-2",children:"Govern how members in this organization use Cinema Studio so generated media stays organized and credit spend stays predictable."}),e.jsxs("div",{className:"bg-black/40 rounded-xl border border-white/10 overflow-hidden",children:[e.jsxs("div",{className:"p-4 sm:p-5 flex flex-col sm:flex-row items-start sm:items-center gap-4",children:[e.jsx(ze,{className:"w-6 h-6 text-brand-primary shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Require project selection before generating"}),e.jsxs("p",{className:"text-xs text-gray-400 mt-1 leading-relaxed",children:["When ON, every member must pick an organization Project folder in Cinema Studio before they can generate images or videos."," ",e.jsx("span",{className:"text-white font-semibold",children:"Renders are saved only to that project — nothing goes to the member's personal library."})," ","This keeps every generation owned by the organization, prevents off-platform reuse of paid renders, and lets you attribute spend cleanly."]})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":le,disabled:X||!K,onClick:()=>Qe(!le),className:`relative inline-flex h-7 w-12 shrink-0 items-center rounded-full transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-900 focus:ring-brand-primary ${le?"bg-brand-primary shadow-lg shadow-brand-primary/30":"bg-gray-600"} ${X||!K?"opacity-60 cursor-wait":"cursor-pointer"}`,children:e.jsx("span",{className:`inline-block h-5 w-5 transform rounded-full bg-white shadow transition-transform duration-200 ${le?"translate-x-6":"translate-x-1"}`})})]}),e.jsxs("div",{className:`px-4 sm:px-5 py-2.5 text-[11px] font-semibold border-t flex items-center gap-2 ${le?"bg-brand-primary/10 border-brand-primary/30 text-brand-primary":"bg-black/40 border-white/10 text-gray-400"}`,children:[e.jsx("span",{className:`inline-block w-1.5 h-1.5 rounded-full ${le?"bg-brand-primary":"bg-gray-500"}`}),le?"ENFORCED — members must pick a project before they can generate.":"OPTIONAL — members can generate freely, projects are not required."]})]}),e.jsxs("div",{className:"bg-black/40 border border-white/10 rounded-xl p-4 text-xs text-gray-400 leading-relaxed",children:[e.jsxs("p",{className:"text-white font-semibold text-[11px] flex items-center gap-1.5 uppercase tracking-wider mb-1.5",children:[e.jsx(Ve,{className:"w-3.5 h-3.5 text-brand-primary"})," Tip"]}),"Members can create projects from the Projects panel. Once enforcement is ON, anyone without a project selected will see a clear blocker in Cinema Studio with a single button to choose one — no support tickets needed."]}),e.jsxs("div",{className:"flex items-center gap-2 mb-1 pt-2",children:[e.jsx(pt,{className:"w-5 h-5 text-brand-primary shrink-0"}),e.jsx("h3",{className:"text-sm font-bold text-white",children:"Exter
87nal MCP Tool Policy"})]}),e.jsx("p",{className:"text-xs text-gray-400 -mt-2",children:"Control whether members may connect their own external MCP tool servers to the AI assistant."}),e.jsxs("div",{className:"bg-black/40 rounded-xl border border-white/10 overflow-hidden",children:[e.jsxs("div",{className:"p-4 sm:p-5 flex flex-col sm:flex-row items-start sm:items-center gap-4",children:[e.jsx(pt,{className:"w-6 h-6 text-brand-primary shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Allow personal MCP servers"}),e.jsxs("p",{className:"text-xs text-gray-400 mt-1 leading-relaxed",children:["When ON, members can add their own external MCP tool servers in Account Settings and use them in the AI assistant."," ",e.jsx("span",{className:"text-white font-semibold",children:"Chat content sent to those tools leaves the platform and goes to the member's chosen third-party server."})," ","Keep this OFF if your organization handles confidential briefs or client material in chat."]})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":ne,disabled:Oe||!K,onClick:()=>Ze(!ne),className:`relative inline-flex h-7 w-12 shrink-0 items-center rounded-full transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-900 focus:ring-brand-primary ${ne?"bg-brand-primary shadow-lg shadow-brand-primary/30":"bg-gray-600"} ${Oe||!K?"opacity-60 cursor-wait":"cursor-pointer"}`,children:e.jsx("span",{className:`inline-block h-5 w-5 transform rounded-full bg-white shadow transition-transform duration-200 ${ne?"translate-x-6":"translate-x-1"}`})})]}),e.jsxs("div",{className:`px-4 sm:px-5 py-2.5 text-[11px] font-semibold border-t flex items-center gap-2 ${ne?"bg-brand-primary/10 border-brand-primary/30 text-brand-primary":"bg-black/40 border-white/10 text-gray-400"}`,children:[e.jsx("span",{className:`inline-block w-1.5 h-1.5 rounded-full ${ne?"bg-brand-primary":"bg-gray-500"}`}),ne?"ALLOWED — members may connect personal MCP tool servers.":"BLOCKED — members can only use the platform's vetted MCP tools."]})]}),Ie&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1 pt-2",children:[e.jsx(Ye,{className:"w-5 h-5 text-red-400 shrink-0"}),e.jsx("h3",{className:"text-sm font-bold text-red-400",children:"Danger Zone"})]}),e.jsxs("div",{className:"bg-red-500/5 border border-red-500/20 rounded-xl p-4 sm:p-5 space-y-3",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-white",children:"Transfer Ownership"}),e.jsxs("p",{className:"text-xs text-gray-400 mt-1 leading-relaxed",children:["Hand over full ownership of ",e.jsx("span",{className:"text-white font-semibold",children:f})," to another member. You will be demoted to admin and can no longer undo this yourself."]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsxs("select",{value:S,onChange:d=>E(d.target.value),className:"flex-1 px-3 py-2 bg-gray-900/80 border border-gray-600/50 rounded-lg text-white text-xs sm:text-sm focus:outline-none focus:border-red-500 focus:ring-1 focus:ring-red-500/50 transition-all",children:[e.jsx("option",{value:"",children:"Select a member…"}),T.filter(d=>
87String(d.user_id)!==String(n==null?void 0:n.id)).map(d=>e.jsxs("option",{value:d.user_id,children:[d.name," (",d.email,") — ",d.role]},d.user_id))]}),e.jsx("button",{type:"button",disabled:!S,onClick:()=>ee(!0),className:"px-4 py-2 bg-red-500/10 hover:bg-red-500/20 disabled:opacity-40 disabled:cursor-not-allowed text-red-300 hover:text-red-200 border border-red-500/30 hover:border-red-500/50 text-xs sm:text-sm font-bold rounded-lg transition-all whitespace-nowrap",children:"Transfer Ownership"})]})]})]})]})]})]}),D&&e.jsx(Ds,{orgId:r,orgName:f,onClose:()=>O(!1)}),e.jsx(ve,{isOpen:W,title:"Transfer Ownership?",message:`Transfer ownership of "${f}" to ${((lt=T.find(d=>String(d.user_id)===S))==null?void 0:lt.name)||"this member"}? You will be demoted to admin immediately. This cannot be undone by you.`,confirmText:"Transfer",confirmStyle:"danger",isLoading:re,onConfirm:Xe,onCancel:()=>ee(!1)}),e.jsx(ve,{isOpen:te,title:"Remove Selected Members?",message:`Remove ${A.size} selected member(s) from the organization? They will need to be re-invited to access.`,confirmText:"Remove",confirmStyle:"danger",isLoading:R,onConfirm:ae,onCancel:()=>se(!1)}),Q&&e.jsx(Jt,{isOpen:!!Q,onClose:()=>h(null),orgId:r,member:Q,onSaved:d=>{v(q=>q.map(z=>z.user_id===d.user_id?{...z,spending_cap:d.spending_cap,spending_cap_period:d.spending_cap_period??null}:z)),h(null),w(`Spending cap updated for ${d.name}`),setTimeout(()=>w(null),4e3)}}),e.jsx(ve,{isOpen:!!N,title:"Remove Member?",message:`Remove ${N==null?void 0:N.email} from the organization? They will need to be re-invited to access.`,confirmText:"Remove",confirmStyle:"danger",isLoading:U===(N==null?void 0:N.id.toString()),onConfirm:et,onCancel:()=>u(null)})]})},Js=({project:r,onClose:f})=>{const[c,n]=s.useState([]),[T,v]=s.useState(!0),[$,_]=s.useState(null),[g,o]=s.useState(null),[k,w]=s.useState("all"),[N,u]=s.useState(1),[x,l]=s.useState(1),[j,M]=s.useState([]),[B,Y]=s.useState(""),[C,P]=s.useState(!1),[U,V]=s.useState(!1),[J,I]=s.useState(!1),[b,m]=s.useState(null),[D,O]=s.useState(!1),[Q,h]=s.useState(null),S=localStorage.getItem("morphyxToken"),E=async()=>{var p;v(!0);try{const R=new URLSearchParams;R.append("page",N.toString()),R.append("limit","24"),(k==="image"||k==="video")&&R.append("mediaType",k),k==="favorites"&&R.append("favoritesOnly","true");const H=await fetch(`/api/organization/projects/${r.id}/media?${R}`,{headers:{Authorization:`Bearer ${S}`}});if(!H.ok){const se=await H.json();throw new Error(se.message||"Failed to fetch project media")}const te=await H.json();n(te.media||[]),l(((p=te.pagination)==null?void 0:p.totalPages)||1),_(null)}catch(R){_(R instanceof Error?R.message:"Error fetching media")}finally{v(!1)}},W=async p=>{P(!0);try{const R=await fetch(`/api/organization/projects/${r.id}/comments?mediaId=${p}`,{headers:{Authorization:`Bearer ${S}`}});if(R.ok){const H=await R.json();M(H.comments||[])}}catch(R){console.error("Error fetching comments:",R)}finally{P(!1)}},ee=async()=>{if(!(!B.trim()||!g)){I(!0),m(null);try{const p=await fetch(`/api/organization/projects/${r.id}/comments?mediaId=${g.id}`,{method:"POST",headers:{Authorization:`Bearer ${S}`,"Content-Type":"application/json"},body:JSON.stringify({comment:B.trim()})}),R=await p.json();p.ok?(M(H=>[...H,R.comment]),Y(""),m(null)):m(R.message||"Failed to submit comment. Please try again.")}catch(p){console.error("Error adding comment:",p),m("Network error. Please check your connection and try again.")}finally{I(!1)}}},re=async p=>{try{const R=await fetch(`/api/organization/projects/${r.id}/favorite`,{method:"POST",headers:{Authorization:`Bearer ${S}`,"Content-Type":"application/json"},body:JSON.stringify({mediaId:p.id})});if(R.ok){const H=await R.json();n(te=>te.map(se=>se.id===p.id?{...se,is_favorite:H.isFavorite}:se)),(g==null?void 0:g.id)===p.id&&o({...g,is_favorite:H.isFavorite})}}catch(R){console.error("Error toggling favorite:",R)}};s.useEffect(()=>{E()},[r.id,k,N]),s.useEffect(()=>{g&&(W(g.id),V(!1))},[g==null?void 0:g.id]);const a=async p=>{const R=p.media_type==="video"?"video":"image",H=qe(p.title||void 0,R,`media_${p.id}`);await Nt(p.url,H,R)},A=async p=>{var R,H;
87if(p.media_type!=="video"&&!D){O(!0),h(null);try{const te=await fetch("/api/community/gallery",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${S}`},body:JSON.stringify({imageUrl:p.url,title:p.title||void 0,description:p.description||void 0,prompt:p.prompt||void 0,modelUsed:((R=p.metadata)==null?void 0:R.model)||void 0,aspectRatio:((H=p.metadata)==null?void 0:H.aspect_ratio)||void 0,generationType:p.operation_type||"IMAGE_GENERATION"})});if(te.ok)h("Shared to Community Gallery!"),setTimeout(()=>h(null),3e3);else{const se=await te.json().catch(()=>({}));_(se.message||"Failed to share.")}}catch{_("Failed to share.")}finally{O(!1)}}},L=p=>new Date(p).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"}),G=p=>{const R=new Date(p),te=Math.floor((new Date().getTime()-R.getTime())/1e3);return te<60?"just now":te<3600?`${Math.floor(te/60)}m ago`:te<86400?`${Math.floor(te/3600)}h ago`:te<604800?`${Math.floor(te/86400)}d ago`:R.toLocaleDateString("en-US",{month:"short",day:"numeric"})};return typeof document>"u"?null:fe.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[100] flex flex-col px-3 py-3 sm:px-4 sm:py-4",children:[Q&&e.jsx("div",{className:"fixed top-24 left-1/2 -translate-x-1/2 z-[110] bg-violet-600 text-white px-5 py-2.5 rounded-xl shadow-lg text-sm font-medium animate-fade-in",children:Q}),e.jsx("div",{className:"absolute inset-0 bg-black/80 backdrop-blur-sm",onClick:f}),e.jsxs("div",{className:"relative flex-1 flex flex-col max-w-6xl w-full mx-auto bg-black/80 backdrop-blur-md border border-gray-700/50 shadow-2xl rounded-2xl overflow-hidden",children:[e.jsx("div",{className:"flex-shrink-0 p-4 sm:p-6 border-b border-gray-700/50",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ze,{className:"w-6 h-6 text-white"}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-white",children:r.name}),r.description&&e.jsx("p",{className:"text-gray-400 text-sm mt-0.5",children:r.description})]})]}),e.jsx("button",{onClick:f,className:"p-2 hover:bg-gray-700 rounded-lg transition-colors",children:e.jsx("svg",{className:"w-5 h-5 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsx("div",{className:"flex overflow-x-auto pb-2 -mx-1 px-1 justify-start",children:e.jsx("div",{className:"relative p-[1.5px] rounded-full animated-gradient-border shadow-[0_0_15px_rgba(163,230,53,0.35)] shrink-0",children:e.jsx("div",{className:"flex items-center gap-0.5 sm:gap-1 p-1 bg-black rounded-full",children:["all","image","video","favorites"].map(p=>e.jsxs("button",{onClick:()=>{w(p),u(1)},className:"relative px-4 sm:px-6 py-1.5 sm:py-2 rounded-full text-xs sm:text-sm font-semibold transition-all duration-300 flex flex-row items-center gap-1.5",children:[k===p&&e.jsx(we.div,{layoutId:"gallery-filter-indicator",className:"absolute inset-0 rounded-full bg-lime-400 shadow-md",transition:{type:"spring",stiffness:400,damping:30}}),e.jsxs("span",{className:`relative z-10 flex items-center gap-1.5 transition-colors duration-300 whitespace-nowrap ${k===p?"text-black font-bold":"text-gray-400 hover:text-white"}`,children:[p==="all"&&"All Media",p==="image"&&"Images",p==="video"&&"Videos",p==="favorites"&&"Favorites"]})]},p))})})})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6",children:[T?e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-4",children:[1,2,3,4,5,6,7,8].map(p=>e.jsx("div",{className:"aspect-square bg-gray-800 rounded-xl animate-pulse"},p))}):$?e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 text-center",children:[e.jsx(Ye,{className:"w-12 h-12 mb-3 text-red-400 mx-auto"}),e.jsx("p",{className:"text-red-400",children:$})]}):c.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 text-center",children:[e.jsx(Tt,{className:"w-12 h-12 mb-4 text-gray-500 mx-auto"}),e.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:k==="favorites"?"No Favorites Yet":"No Media Yet"}),e.jsx("p",{className:"text-gray-400 text-sm max-w-sm",children:k==="favorites"?"Mark items as favorites by clicking the star icon.":"Generate content in the Studio with this project selected to start filling the gallery."})]}):e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-3 sm:gap-4",children:c.map(p=>e.jsxs("div",{onClick:()=>o(p),className:"group relative aspect-square rounded-xl overflow-hidden border border-white/10 hover:border-white/20 cursor-pointer transition-all duration-200 hover:shadow-lg",children:[p.media_type==="video"?e.jsxs(e.Fragment,{children:[e.jsx("video",{src:p.url,className:"w-full h-full object-cover group-hover:scale-105 transition-transform duration-300",muted:!0,preload:"metadata"}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/20",children:e.jsx("div",{className:"w-10 h-10 rounded-full bg-white/20 backdrop-blur-sm flex items-center justify-center group-hover:bg-white/30 transition-colors",children:e.jsx("svg",{className:"w-5 h-5 text-white ml-0.5",fill:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{d:"M8 5v14l11-7z"})})})})]}):e.jsx("img",{src:p.thumbnail_url||p.url,alt:p.title||"Project media",className:"w-full h-full object-cover group-hover:scale-105 transition-transform duration-300",loading:"lazy"}),e.jsx("div",{className:"absolute inset-0 bg-gradient-to-t from-black/80 via-trans
87parent to-transparent opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsxs("div",{className:"absolute bottom-0 left-0 right-0 p-3",children:[e.jsx("p",{className:"text-white text-sm font-medium truncate",children:p.title||"Untitled"}),e.jsx("p",{className:"text-gray-400 text-xs",children:p.creator_name})]})}),e.jsxs("div",{className:"absolute top-2 right-2 flex items-center gap-1",children:[p.is_favorite&&e.jsx("span",{className:"px-1.5 py-1 rounded bg-black/60 backdrop-blur-sm border border-white/10 flex items-center justify-center",children:e.jsx(We,{className:"w-3.5 h-3.5 text-yellow-400 fill-yellow-400"})}),e.jsx("span",{className:"px-1.5 py-1 rounded bg-black/60 backdrop-blur-sm border border-white/10 flex items-center justify-center text-white",children:p.media_type==="video"?e.jsx(Et,{className:"w-3.5 h-3.5"}):e.jsx(Ge,{className:"w-3.5 h-3.5"})})]})]},p.id))}),x>1&&e.jsxs("div",{className:"flex items-center justify-center gap-2 mt-6",children:[e.jsx("button",{onClick:()=>u(p=>Math.max(1,p-1)),disabled:N===1,className:"px-4 py-2 rounded-lg bg-white/5 border border-white/10 text-gray-300 disabled:opacity-50 disabled:cursor-not-allowed hover:bg-white/10 hover:text-white",children:"Previous"}),e.jsxs("span",{className:"text-gray-400 text-sm",children:["Page ",N," of ",x]}),e.jsx("button",{onClick:()=>u(p=>Math.min(x,p+1)),disabled:N===x,className:"px-4 py-2 rounded-lg bg-white/5 border border-white/10 text-gray-300 disabled:opacity-50 disabled:cursor-not-allowed hover:bg-white/10 hover:text-white",children:"Next"})]})]})]}),g&&e.jsx("div",{className:"fixed inset-0 z-[60] overflow-y-auto",children:e.jsxs("div",{className:"min-h-full flex items-center justify-center p-3 sm:p-4",children:[e.jsx("div",{className:"absolute inset-0 bg-black/90",onClick:()=>o(null)}),e.jsxs("div",{className:"relative max-w-5xl w-full max-h-[90vh] bg-black/80 backdrop-blur-md border border-white/10 rounded-2xl overflow-hidden flex flex-col lg:flex-row shadow-2xl",children:[e.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-white/10",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-white font-semibold truncate",children:g.title||"Untitled"}),e.jsxs("p",{className:"text-gray-400 text-sm",children:["By ",g.creator_name," • ",L(g.created_at)]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>re(g),className:`p-2 rounded-lg transition-colors border border-transparent hover:border-white/10 ${g.is_favorite?"bg-yellow-500/20 hover:bg-yellow-500/30":"bg-white/5 hover:bg-white/10"}`,title:g.is_favorite?"Remove from favorites":"Add to favorites",children:e.jsx(We,{className:`w-5 h-5 ${g.is_favorite?"text-yellow-400 fill-yellow-400":"text-gray-300"}`})}),e.jsxs("button",{onClick:()=>V(!U),className:`p-2 rounded-lg transition-colors flex items-center gap-1 border border-transparent hover:border-white/10 ${U?"bg-brand-primary/20 text-brand-primary":"bg-white/5 text-gray-300 hover:bg-white/10"}`,title:"Comments",children:[e.jsx($t,{className:"w-5 h-5"})," ",j.length>0&&e.jsx("span",{className:"text-xs",children:j.length})]}),e.jsx("button",{onClick:()=>a(g),className:"p-2 bg-white/5 hover:bg-white/10 rounded-lg transition-colors border border-transparent hover:border-white/10",title:"Download",children:e.jsx(Zt,{className:"w-5 h-5 text-gray-300"})}),g.media_type==="image"&&e.jsx("button",{onClick:()=>A(g),disabled:D,className:"p-2 bg-white/5 hover:bg-violet-600/70 rounded-lg transition-colors border border-transparent hover:border-white/10 disabled:opacity-50",title:"Share to Community Gallery",children:D?e.jsxs("svg",{className:"w-5 h-5 text-violet-300 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}):e.jsx(Lt,{className:"w-5 h-5 text-violet-300"})}),e.jsx("button",{onClick:()=>o(null),className:"p-2 bg-white/5 hover:bg-white/10 border border-transparent hover:border-white/10 rounded-lg transition-colors lg:hidden",children:e.jsx(he,{className:"w-5 h-5 text-gray-400"})})]})]}),e.jsx("div",{className:"flex-1 flex items-center justify-center p-4 bg-transparent min-h-[300px]",children:g.media_type==="video"?e.jsx(rt,{src:g.url,autoPlay:!0,className:"max-w-full max-h-[50vh] lg:max-h-[60vh] rounded-lg",maxHeight:"60vh",downloadFilename:qe(g.title||void 0,"video",`media_${g.id}`),onDownload:()=>a(g)}):e.jsx("img",{src:g.url,alt:g.title||"Media preview",className:"max-w-full max-h-[50vh] lg:max-h-[60vh] rounded-lg object-contain"})}),g.prompt&&e.jsxs("div",{className:"p-4 border-t border-white/10 max-h-32 overflow-y-auto bg-black/40",children:[e.jsx("p",{className:"text-xs text-gray-400 uppercase tracking-wide mb-1",children:"Prompt"}),e.jsx("p",{className:"text-sm text-gray-300",children:g.prompt})]})]}),U&&e.jsxs("div",{className:"w-full lg:w-80 border-t lg:border-t-0 lg:border-l border-white/10 bg-black/50 flex flex-col max-h-[40vh] lg:max-h-none",children:[e.jsxs("div",{className:"p-4 border-b border-white/10 flex items-center justify-between",children:[e.jsxs("h4",{className:"text-white font-semibold",children:["Comments (",j.length,")"]}),e.jsx("button",{onClick:()=>V(!1),className:"p-1 hover:bg-white/10 rounded lg:hidden",children:e.jsx(he,{className:"w-4 h-4 text-gray-400"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4 space-y-3",children:C?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx("div",{className:"animate-spin w-6 h-6 border-2 border-brand-primary border-t-transparent roun
87ded-full"})}):j.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-gray-400 text-sm",children:"No comments yet."}),e.jsx("p",{className:"text-gray-500 text-xs mt-1",children:"Be the first to comment!"})]}):j.map(p=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-white/10 flex-shrink-0 overflow-hidden flex items-center justify-center border border-white/20",children:p.user_avatar?e.jsx("img",{src:p.user_avatar,alt:`${p.user_name}'s avatar`,className:"w-full h-full object-cover"}):e.jsx(ye,{className:"w-4 h-4 text-white"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-white",children:p.user_name}),e.jsx("span",{className:"text-xs text-gray-500",children:G(p.created_at)})]}),e.jsx("p",{className:"text-sm text-gray-300 mt-0.5 break-words",children:p.comment})]})]},p.id))}),e.jsxs("div",{className:"p-4 border-t border-white/10",children:[b&&e.jsx("div",{className:"mb-2 p-2 bg-red-500/20 border border-red-500/50 rounded-lg text-red-300 text-xs",children:b}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:B,onChange:p=>{Y(p.target.value),m(null)},onKeyDown:p=>p.key==="Enter"&&!J&&ee(),placeholder:"Add a comment...",disabled:J,className:"flex-1 px-3 py-2 bg-black/40 border border-white/10 rounded-lg text-white text-sm placeholder-gray-400 focus:outline-none focus:border-white/30 disabled:opacity-50 transition-colors"}),e.jsx("button",{onClick:ee,disabled:!B.trim()||J,className:"px-3 py-2 bg-brand-primary text-white rounded-lg text-sm font-medium disabled:opacity-50 disabled:cursor-not-allowed hover:bg-brand-primary/80 transition-colors min-w-[60px]",children:J?e.jsx("span",{className:"inline-block w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin"}):"Send"})]})]})]}),e.jsx("button",{onClick:()=>o(null),className:"hidden lg:block absolute top-4 right-4 p-2 hover:bg-white/10 bg-black/40 border border-white/10 rounded-lg transition-colors z-10",children:e.jsx(he,{className:"w-5 h-5 text-gray-400 hover:text-white"})})]})]})})]}),document.body)},Ws=({project:r,onClose:f})=>{const[c,n]=s.useState(null),[T,v]=s.useState([]),[$,_]=s.useState(!0),[g,o]=s.useState("overview"),k=localStorage.getItem("morphyxToken");s.useEffect(()=>{(async()=>{_(!0);try{const[x,l]=await Promise.all([fetch(`/api/organization/projects/${r.id}/stats`,{headers:{Authorization:`Bearer ${k}`}}),fetch(`/api/organization/projects/${r.id}/activity?limit=50`,{headers:{Authorization:`Bearer ${k}`}})]);if(x.ok){const j=await x.json();n(j)}if(l.ok){const j=await l.json();v(j.activities||[])}}catch(x){console.error("Error fetching stats:",x)}finally{_(!1)}})()},[r.id,k]);const w=u=>{switch(u){case"created":return e.jsx(st,{className:"w-5 h-5 text-white"});case"updated":return e.jsx(nt,{className:"w-5 h-5 text-white"});case"archived":return e.jsx(cs,{className:"w-5 h-5 text-white"});case"restored":return e.jsx(tt,{className:"w-5 h-5 text-white"});case"uploaded":return e.jsx(es,{className:"w-5 h-5 text-white"});case"deleted_media":return e.jsx(At,{className:"w-5 h-5 text-white"});case"added_member":return e.jsx(Xt,{className:"w-5 h-5 text-white"});case"removed_member":return e.jsx(Ss,{className:"w-5 h-5 text-white"});case"updated_member":return e.jsx(Ns,{className:"w-5 h-5 text-white"});case"commented":return e.jsx($t,{className:"w-5 h-5 text-white"});case"favorited":return e.jsx(We,{className:"w-5 h-5 text-white"});case"unfavorited":return e.jsx(ys,{className:"w-5 h-5 text-white"});default:return e.jsx(st,{className:"w-5 h-5 text-white"})}},N=u=>({IMAGE_GENERATION:"Image Generation",VIDEO_GENERATION:"Video Generation",IMAGE_EDIT:"Image Editing",IMAGE_TO_VIDEO:"Image to Video",REFERENCE_IMAGE:"Reference Image",unknown:"Other"})[u]||(u==null?void 0:u.replace(/_/g," ").replace(/\b\w/g,l=>l.toUpperCase()))||"Unknown";return typeof document>"u"?null:$?fe.createPortal(e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-black/80 backdrop-blur-sm",children:e.jsx("div",{className:"animate-spin w-8 h-8 border-4 border-brand-primary border-t-transparent roun
87ded-full"})}),document.body):fe.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[100] flex flex-col px-3 py-3 sm:px-4 sm:py-4",children:[e.jsx("div",{className:"absolute inset-0 bg-black/80 backdrop-blur-sm",onClick:f}),e.jsxs("div",{className:"relative flex-1 flex flex-col max-w-6xl w-full mx-auto bg-black/80 backdrop-blur-md border border-gray-700/50 shadow-2xl rounded-2xl overflow-hidden",children:[e.jsx("div",{className:"flex-shrink-0 p-4 sm:p-6 border-b border-gray-700/50",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Fe,{className:"w-6 h-6 text-white"}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-xl font-bold text-white",children:[r.name," - Analytics"]}),r.description&&e.jsx("p",{className:"text-gray-400 text-sm mt-0.5",children:r.description})]})]}),e.jsx("button",{onClick:f,className:"p-2 hover:bg-gray-700 rounded-lg transition-colors",children:e.jsx("svg",{className:"w-5 h-5 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsx("div",{className:"flex overflow-x-auto pb-2 -mx-1 px-1 justify-start",children:e.jsx("div",{className:"relative p-[1.5px] rounded-full animated-gradient-border shadow-[0_0_15px_rgba(163,230,53,0.35)] shrink-0",children:e.jsx("div",{className:"flex items-center gap-0.5 sm:gap-1 p-1 bg-black rounded-full",children:["overview","activity","contributors"].map(u=>e.jsxs("button",{onClick:()=>o(u),className:"relative px-4 sm:px-6 py-1.5 sm:py-2 rounded-full text-xs sm:text-sm font-semibold transition-all duration-300 flex flex-row items-center gap-1.5",children:[g===u&&e.jsx(we.div,{layoutId:"stats-tab-indicator",className:"absolute inset-0 rounded-full bg-lime-400 shadow-md",transition:{type:"spring",stiffness:400,damping:30}}),e.jsxs("span",{className:`relative z-10 flex items-center gap-1.5 transition-colors duration-300 whitespace-nowrap capitalize ${g===u?"text-black font-bold":"text-gray-400 hover:text-white"}`,children:[u==="overview"&&"Overview",u==="activity"&&"Activity",u==="contributors"&&"Contributors"]})]},u))})})})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6",children:[g==="overview"&&e.jsx(e.Fragment,{children:!c||c.overview.totalMedia===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full min-h-[300px] text-center",children:[e.jsx("div",{className:"w-20 h-20 rounded-full bg-gray-800 flex items-center justify-center mb-4",children:e.jsx(Fe,{className:"w-10 h-10 text-gray-400"})}),e.jsx("h3",{className:"text-xl font-semibold text-white mb-2",children:"No Analytics Data Yet"}),e.jsx("p",{className:"text-gray-400 text-sm max-w-sm mb-6",children:"Start adding content to this project to see analytics and insights about your team's work."}),e.jsxs("div",{className:"flex flex-col gap-2 text-sm text-gray-500",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-6 h-6 rounded-full bg-gray-700 flex items-center justify-center text-xs text-white",children:"1"}),e.jsx("span",{children:"Generate or upload content in the Studio"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-6 h-6 rounded-full bg-gray-700 flex items-center justify-center text-xs text-white",children:"2"}),e.jsx("span",{children:"Select this project when saving"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-6 h-6 rounded-full bg-gray-700 flex items-center justify-center text-xs text-white",children:"3"}),e.jsx("span",{children:"Analytics will appear here automatically"})]})]})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"bg-black border border-white/10 rounded-xl p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx(Ge,{className:"w-6 h-6 text-lime-400"}),e.jsx("span",{className:"text-xs text-lime-400 bg-lime-400/20 px-2 py-0.5 rounded",children:"Media"})]}),e.jsx("p",{className:"text-2xl font-bold text-white",children:c.overview.totalMedia}),e.jsx("p",{className:"text-xs text-gray-400",children:"Total items"})]}),e.jsxs("div",{className:"bg-black border border-white/10 rounded-xl p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx(Ge,{className:"w-6 h-6 text-lime-400"}),e.jsx("span",{className:"text-xs text-lime-400 bg-lime-400/20 px-2 py-0.5 rounded",children:"Images"})]}),e.jsx("p",{className:"text-2xl font-bold text-white",children:c.overview.totalImages}),e.jsx("p",{className:"text-xs text-gray-400",children:"Total images"})]}),e.jsxs("div",{className:"bg-black border border-white/10 rounded-xl p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx(Et,{className:"w-6 h-6 text-lime-400"}),e.jsx("span",{className:"text-xs text-lime-400 bg-lime-400/20 px-2 py-0.5 rounded",children:"Videos"})]}),e.jsx("p",{className:"text-2xl font-bold text-white",children:c.overview.totalVideos}),e.jsx("p",{className:"text-xs text-gray-400",children:"Total videos"})]}),e.jsxs("div",{className:"bg-black border border-white/10 rounded-xl p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx(We,{className:"w-6 h-6 text-lime-400"}),e.jsx("span",{className:"text-xs text-lime-400 bg-lime-400/20 px-2 py-0.5 rounded",children:"Favorites"})]}),e.jsx("p",{className:"text-2xl font-bold text-white",children:c.overview.favoritesCount}),e.jsx("p",{className:"text-xs text-gray-400",children:"Marked items"})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{className:"bg-black border border-white/10 rounded-xl p-4 text-center",children:[e.jsx("p",{className:"text-gray-400 text-sm mb-1",children:"Team Members"}),e.jsx("p",{className:"text-xl font-semibold text-white",children:c.overview.memberCount})]}),e.jsxs("div",{className:"bg-black border border-white/10 rounded-xl p-4 text-center",children:[e.jsx("p",{className:"text-gray-400 text-sm mb-1",children:"Storage Used"}),e.jsx("p",{className:"text-xl font-semibold text-white",children:c.overview.totalSize})]}),e.jsxs("div",{className:"bg-black border border-white/10 rounded-xl p-4 text-center",children:[e.jsx("p",{className:"text-gray-400 text-sm mb-1",children:"This Week"}),e.jsxs("p",{className:"text-xl font-semibold text-white",children:[c.overview.recentActivityCount," actions"]})]})]}),c.operationBreakdown.length>0&&e.jsxs("div",{className:"bg-black border border-white/10 rounded-xl p-4",children:[e.jsxs("h3",{className:"text-white font-semibold mb-4 flex items-center gap-2",children:[e.jsx(_s,{className:"w-5 h-5 text-gray-400"})," Content Breakdown"]}),e.jsx("div",{className:"space-y-3",children:c.operationBreakdown.map((u,x)=>{const l=c.overview.totalMedia>0?Math.round(u.count/c.overview.totalMedia*100):0;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[e.jsx("span",{className:"text-gray-300",children:N(u.type)}),e.jsxs("span",{className:"text-gray-400",children:[u.count," (",l,"%)"]})]}),e.jsx("div",{className:"h-2 bg-gray-700 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-gradient-to-r from-brand-primary to-brand-secondary rounded-full transition-all duration-500",style:{width:`${l}%`}})})]},x)})})]}),c.activityTrend.length>0&&e.jsxs("div",{className:"bg-black border border-white/10 rounded-xl p-4",children:[e.jsxs("h3",{className:"text-white font-semibold mb-4 flex items-center gap-2",children:[e.jsx(St,{className:"w-5 h-5 text-gray-400"})," Activity (Last 30 Days)"]}),e.jsx("div",{className:"flex items-end gap-1 h-24",children:c.activityTrend.map((u,x)=>{const l=Math.max(...c.activityTrend.map(M=>M.count)),j=l>0?u.count/l*100:0;return e.jsx("div",{className:"flex-1 bg-brand-primary/50 hover:bg-brand-primary transition-colors rounded-t cursor-pointer group relative",style:{height:`${Math.max(j,4)}%`},title:`${new Date(u.date).toLocaleDateString()}: ${u.count} items`,children:e.jsxs("div",{className:"absolute bottom-full left-1/2 -translate-x-1/2 mb-2 opacity-0 group-hover:opacity-100 transition-opacity bg-gray-900 text-white text-xs px-2 py-1 rounded whitespace-nowrap pointer-events-none",children:[u.count," items"]})},x)})}),e.jsxs("div",{className:"flex justify-between text-xs text-gray-500 mt-2",children:[e.jsx("span",{children:"30 days ago"}),e.jsx("span",{children:"Today"})]})]})]})}),g==="activity"&&e.jsx("div",{className:"space-y-3",children:T.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(_t,{className:"w-12 h-12 mb-4 text-gray-500 mx-auto"}),e.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No Activity Yet"}),e.jsx("p",{className:"text-gray-400 text-sm",children:"Project activity will appear here."})]}):T.map(u=>e.jsxs("div",{className:"flex items-start gap-3 p-3 bg-black border border-white/10 rounded-xl hover:border-white/20 transition-colors",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-gray-700 flex items-center justify-center flex-shrink-0 overflow-hidden",children:u.user_avatar?e.jsx("img",{src:u.user_avatar,alt:`${u.user_name}'s avatar`,className:"w-full h-full object-cover"}):w(u.action)}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"text-white text-sm",children:[e.jsx("span",{className:"font-semibold",children:u.user_name}),e.jsxs("span",{className:"text-gray-400",children:[" ",u.action_text]})]}),e.jsx("p",{className:"text-gray-500 text-xs mt-0.5",children:u.time_ago})]}),e.jsx("div",{className:"flex-shrink-0 pt-0.5",children:w(u.action)})]},u.id))}),g==="contributors"&&c&&e.jsx("div",{className:"space-y-4",children:c.topContributors.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(ue,{className:"w-12 h-12 mb-4 text-gray-500 mx-auto"}),e.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No Contributors Yet"}),e.jsx("p",{className:"text-gray-400 text-sm",children:"Team members who contribute will appear here."})]}):e.jsx("div",{className:"space-y-3",children:c.topContributors.map((u,x)=>e.jsxs("div",{className:"flex items-center gap-4 p-4 bg-black border border-white/10 rounded-xl",children:[e.jsxs("div",{className:"flex items-center justify-center w-8 h-8 bg-gray-700 rounded-lg text-sm font-bold text-gray-300",children:["#",x+1]}),e.jsx("div",{className:"w-12 h-12 rounded-full bg-gray-700 flex items-center justify-center flex-shrink-0 overflow-hidden text-gray-400",children:u.avatar?e.jsx("img",{src:u.avatar,alt:`${u.name}'s avatar`,className:"w-full h-full object-cover"}):e.jsx(ue,{className:"w-6 h-6"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-white font-semibold truncate",children:u.name}),e.jsxs("p",{className:"text-gray-400 text-sm",children:[u.mediaCount," items · ",u.images," images · ",u.videos," videos"]})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-2xl font-bold text-brand-primary",children:u.mediaCount}),e.jsx("p",{className:"text-xs text-gray-500",children:"contributions"})]})]},u.id))})})]})]})]}),document.body)},Hs=({project:r,onClose:f,onApprovalComplete:c})=>
87{const[n,T]=s.useState([]),[v,$]=s.useState({pending:0,approved:0,rejected:0,auto_approved:0}),[_,g]=s.useState(!0),[o,k]=s.useState(null),[w,N]=s.useState("pending"),[u,x]=s.useState(new Set),[l,j]=s.useState(null),[M,B]=s.useState(""),[Y,C]=s.useState(!1),[P,U]=s.useState(new Set),V=localStorage.getItem("morphyxToken"),J=async()=>{g(!0),k(null);try{const h=w==="all"?"pending,approved,rejected,auto_approved":w,S=await fetch(`/api/organization/projects/${r.id}/approval?status=${h}`,{headers:{Authorization:`Bearer ${V}`}});if(S.ok){const E=await S.json();T(E.media||[]),$(E.stats||{pending:0,approved:0,rejected:0,auto_approved:0})}else{const E=await S.json().catch(()=>({}));k(E.message||`Error: ${S.status}`),console.error("Approval fetch error:",E)}}catch(h){k("Failed to load approval queue. Please try again."),console.error("Error fetching approvals:",h)}finally{g(!1)}};s.useEffect(()=>{J()},[r.id,w]);const I=async h=>{U(S=>new Set([...S,h]));try{(await fetch(`/api/organization/projects/${r.id}/approval`,{method:"POST",headers:{Authorization:`Bearer ${V}`,"Content-Type":"application/json"},body:JSON.stringify({mediaId:h,action:"approve"})})).ok&&(T(E=>E.map(W=>W.id===h?{...W,approval_status:"approved"}:W)),$(E=>({...E,pending:E.pending-1,approved:E.approved+1})),c==null||c())}catch(S){console.error("Error approving:",S)}finally{U(S=>{const E=new Set(S);return E.delete(h),E})}},b=async h=>{if(M.trim()){U(S=>new Set([...S,h]));try{(await fetch(`/api/organization/projects/${r.id}/approval`,{method:"POST",headers:{Authorization:`Bearer ${V}`,"Content-Type":"application/json"},body:JSON.stringify({mediaId:h,action:"reject",rejectionReason:M.trim()})})).ok&&(T(E=>E.map(W=>W.id===h?{...W,approval_status:"rejected",rejection_reason:M.trim()}:W)),$(E=>({...E,pending:E.pending-1,rejected:E.rejected+1})),C(!1),B(""),j(null),c==null||c())}catch(S){console.error("Error rejecting:",S)}finally{U(S=>{const E=new Set(S);return E.delete(h),E})}}},m=async()=>{if(u.size===0)return;const h=Array.from(u);U(new Set(h));try{const S=await fetch(`/api/organization/projects/${r.id}/approval`,{method:"PATCH",headers:{Authorization:`Bearer ${V}`,"Content-Type":"application/json"},body:JSON.stringify({mediaIds:h,action:"approve"})});S.ok&&(await S.json(),J(),x(new Set),c==null||c())}catch(S){console.error("Error bulk approving:",S)}finally{U(new Set)}},D=h=>{x(S=>{const E=new Set(S);return E.has(h)?E.delete(h):E.add(h),E})},O=()=>{u.size===n.filter(h=>h.approval_status==="pending").length?x(new Set):x(new Set(n.filter(h=>h.approval_status==="pending").map(h=>h.id)))},Q=h=>{const S={pending:{bg:"bg-yellow-500/20",text:"text-yellow-400",label:"Pending",icon:e.jsx(He,{className:"w-3 h-3"})},approved:{bg:"bg-green-500/20",text:"text-green-400",label:"Approved",icon:e.jsx(be,{className:"w-3 h-3"})},rejected:{bg:"bg-red-500/20",text:"text-red-400",label:"Rejected",icon:e.jsx(he,{className:"w-3 h-3"})},auto_approved:{bg:"bg-blue-500/20",text:"text-blue-400",label:"Auto",icon:e.jsx(mt,{className:"w-3 h-3"})}};return S[h]||S.pending};return typeof document>"u"?null:fe.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[100] flex flex-col px-3 py-3 sm:px-4 sm:py-4",children:[e.jsx("div",{className:"absolute inset-0 bg-black/80 backdrop-blur-sm",onClick:f}),e.jsxs("div",{className:"relative flex-1 flex flex-col max-w-6xl w-full mx-auto bg-black/80 backdrop-blur-md border border-gray-700/50 shadow-2xl rounded-2xl overflow-hidden",children:[e.jsx("div",{className:"flex-shrink-0 p-4 sm:p-6 border-b border-gray-700/50",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Le,{className:"w-6 h-6 text-white"}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-xl font-bold text-white",children:[r.name," - Approval Queue"]}),e.jsx("p",{className:"text-gray-400 text-sm mt-0.5",children:"Review and approve content before it goes live"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>{J()},disabled:_,className:`p-2 hover:bg-gray-700 rounded-lg transition-colors ${_?"animate-spin":""}`,title:"Refresh",children:e.jsx(tt,{className:"w-5 h-5 text-gray-400"})}),e.jsx("button",{onClick:f,className:"p-2 hover:bg-gray-700 rounded-lg transition-colors",children:e.jsx(he,{className:"w-5 h-5 text-gray-400"})})]})]}),e.jsx("div",{className:"flex overflow-x-auto pb-2 -mx-1 px-1 justify-start",children:e.jsx("div",{className:"relative p-[1.5px] rounded-full animated-gradient-border shadow-[0_0_15px_rgba(163,230,53,0.35)] shrink-0",children:e.jsx("div",{className:"flex items-center gap-0.5 sm:gap-1 p-1 bg-black rounded-full",children:[{key:"all",label:"All",icon:e.jsx(_t,{className:"w-4 h-4"}),count:v.pending+v.approved+v.rejected+v.auto_approved},{key:"pending",label:"Pending",icon:e.jsx(He,{className:"w-4 h-4"}),count:v.pending},{key:"approved",label:"Approved",icon:e.jsx(Le,{className:"w-4 h-4"}),count:v.approved},{key:"rejected",label:"Rejected",icon:e.jsx(dt,{className:"w-4 h-4"}),count:v.rejected},{key:"auto_approved",label:"Auto",icon:e.jsx(mt,{className:"w-4 h-4"}),count:v.auto_approved}].map(({key:h,label:S,icon:E,count:W})=>e.jsxs("button",{onClick:()=>
87N(h),className:"relative px-4 sm:px-6 py-1.5 sm:py-2 rounded-full text-xs sm:text-sm font-semibold transition-all duration-300 flex flex-row items-center gap-1.5",children:[w===h&&e.jsx(we.div,{layoutId:"approval-tab-indicator",className:"absolute inset-0 rounded-full bg-lime-400 shadow-md",transition:{type:"spring",stiffness:400,damping:30}}),e.jsxs("span",{className:`relative z-10 flex items-center gap-1 transition-colors duration-300 whitespace-nowrap capitalize ${w===h?"text-black font-bold":"text-gray-400 hover:text-white"}`,children:[S," ",e.jsx("span",{className:`text-xs px-1.5 rounded-full ${w===h?"bg-black/20 text-black":"bg-white/10 text-gray-300"}`,children:W})]})]},h))})})}),w==="pending"&&u.size>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 sm:gap-3 mt-2 p-2 sm:p-3 bg-brand-primary/10 border border-brand-primary/30 rounded-lg sm:rounded-xl",children:[e.jsxs("span",{className:"text-xs sm:text-sm text-brand-primary",children:[u.size," selected"]}),e.jsxs("button",{onClick:m,className:"px-3 sm:px-4 py-1 sm:py-1.5 bg-green-500 hover:bg-green-600 text-white text-xs sm:text-sm font-medium rounded-lg transition-colors flex items-center gap-1",children:[e.jsx(be,{className:"w-4 h-4"})," Approve All"]}),e.jsx("button",{onClick:()=>x(new Set),className:"px-3 sm:px-4 py-1 sm:py-1.5 bg-gray-700 hover:bg-gray-600 text-gray-300 text-xs sm:text-sm rounded-lg transition-colors",children:"Clear"})]})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6",children:[o&&e.jsxs("div",{className:"mb-4 p-4 bg-red-500/20 border border-red-500/30 rounded-xl text-center",children:[e.jsx("p",{className:"text-red-400 text-sm",children:o}),e.jsxs("button",{onClick:()=>{k(null),J()},className:"mt-2 px-4 py-1.5 bg-red-500/30 hover:bg-red-500/50 text-red-300 text-xs rounded-lg transition-colors flex items-center gap-1 mx-auto",children:[e.jsx(tt,{className:"w-3 h-3"})," Try Again"]})]}),_?e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-4",children:[1,2,3,4,5,6,7,8].map(h=>e.jsx("div",{className:"aspect-square bg-gray-800 rounded-lg sm:rounded-xl animate-pulse"},h))}):n.length===0&&!o?e.jsxs("div",{className:"flex flex-col items-center justify-center h-48 sm:h-64 text-center",children:[w==="pending"?e.jsx(bs,{className:"w-12 h-12 mb-4 text-green-400 mx-auto"}):w==="all"?e.jsx(ze,{className:"w-12 h-12 mb-4 text-gray-500 mx-auto"}):e.jsx(Tt,{className:"w-12 h-12 mb-4 text-gray-500 mx-auto"}),e.jsx("h3",{className:"text-base sm:text-lg font-semibold text-white mb-1.5 sm:mb-2",children:w==="pending"?"All Caught Up!":w==="all"?"No Media Yet":"No Items Found"}),e.jsx("p",{className:"text-gray-400 text-xs sm:text-sm",children:w==="pending"?"No content is waiting for approval.":w==="all"?"This project has no media items yet.":`No ${w.replace("_"," ")} items in this project.`})]}):e.jsxs(e.Fragment,{children:[w==="pending"&&n.length>0&&e.jsxs("div",{className:"flex items-center gap-2 mb-3 sm:mb-4",children:[e.jsx("input",{type:"checkbox",checked:u.size===n.filter(h=>h.approval_status==="pending").length,onChange:O,className:"w-4 h-4 rounded border-gray-600 bg-gray-700 text-brand-primary focus:ring-brand-primary"}),e.jsx("span",{className:"text-xs sm:text-sm text-gray-400",children:"Select all"})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-3 sm:gap-4",children:n.map(h=>{Q(h.approval_status);const S=P.has(h.id);return e.jsxs("div",{className:`group relative aspect-square bg-black rounded-xl overflow-hidden border transition-all ${u.has(h.id)?"border-brand-primary":"border-white/10 hover:border-white/20 hover:shadow-xl"} ${S?"opacity-50":""}`,children:[h.approval_status==="pending"&&e.jsx("div",{className:"absolute top-2 left-2 z-10",children:e.jsx("input",{type:"checkbox",checked:u.has(h.id),onChange:()=>D(h.id),onClick:E=>E.stopPropagation(),className:"w-5 h-5 rounded border-gray-600 bg-gray-700/80 text-brand-primary focus:ring-brand-primary"})}),e.jsx("div",{onClick:()=>j(h),className:"cursor-pointer w-full h-full",children:h.media_type==="video"?e.jsx("video",{src:h.url,className:"w-full h-full object-cover group-hover:scale-105 transition-transform duration-300",muted:!0}
87):e.jsx("img",{src:h.thumbnail_url||h.url,alt:h.prompt?h.prompt.slice(0,80):"Gallery submission",className:"w-full h-full object-cover group-hover:scale-105 transition-transform duration-300"})}),e.jsx("div",{className:"absolute inset-0 bg-gradient-to-t from-black/90 via-black/20 to-transparent opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsxs("div",{className:"absolute bottom-0 left-0 right-0 p-3",children:[e.jsx("p",{className:"text-white text-sm font-medium truncate",children:h.title||"Untitled"}),e.jsx("p",{className:"text-gray-400 text-xs",children:h.creator_name}),h.approval_status==="pending"&&e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsxs("button",{onClick:E=>{E.stopPropagation(),I(h.id)},disabled:S,className:"flex-1 px-2 py-1.5 bg-green-500/80 hover:bg-green-500 border border-green-400/30 text-white text-xs font-semibold rounded-lg transition-colors disabled:opacity-50 flex items-center justify-center gap-1",children:[e.jsx(be,{className:"w-3 h-3"})," Approve"]}),e.jsxs("button",{onClick:E=>{E.stopPropagation(),j(h),C(!0)},disabled:S,className:"flex-1 px-2 py-1.5 bg-red-500/80 hover:bg-red-500 border border-red-400/30 text-white text-xs font-semibold rounded-lg transition-colors disabled:opacity-50 flex items-center justify-center gap-1",children:[e.jsx(he,{className:"w-3 h-3"})," Reject"]})]}),h.approval_status==="rejected"&&h.rejection_reason&&e.jsxs("p",{className:"text-red-400 text-xs mt-2 line-clamp-2 bg-red-500/10 p-1.5 rounded border border-red-500/20",children:["Reason: ",h.rejection_reason]})]})})]},h.id)})})]})]})]}),l&&!Y&&e.jsxs("div",{className:"fixed inset-0 z-[60] flex items-center justify-center p-2 sm:p-4",children:[e.jsx("div",{className:"absolute inset-0 bg-black/90 backdrop-blur-sm",onClick:()=>j(null)}),e.jsxs("div",{className:"relative max-w-3xl w-full bg-black border border-white/10 rounded-xl sm:rounded-2xl overflow-hidden max-h-[95vh] flex flex-col shadow-2xl",children:[e.jsxs("div",{className:"p-3 sm:p-4 border-b border-white/10 flex items-center justify-between",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h3",{className:"text-white font-semibold text-sm sm:text-base truncate",children:l.title||"Untitled"}),e.jsxs("p",{className:"text-gray-400 text-xs sm:text-sm truncate",children:["By ",l.creator_name]})]}),e.jsx("button",{onClick:()=>j(null),className:"p-1.5 sm:p-2 hover:bg-white/10 rounded-lg flex-shrink-0 ml-2 transition-colors",children:e.jsx(he,{className:"w-4 h-4 sm:w-5 sm:h-5 text-gray-400"})})]}),e.jsx("div",{className:"flex items-center justify-center p-2 sm:p-4 bg-black/50 flex-1 min-h-0",children:l.media_type==="video"?e.jsx(rt,{src:l.url,autoPlay:!0,className:"max-w-full max-h-[50vh] sm:max-h-[60vh] rounded-lg",maxHeight:"60vh"}):e.jsx("img",{src:l.url,alt:l.prompt?l.prompt.slice(0,80):"Preview",className:"max-w-full max-h-[50vh] sm:max-h-[60vh] rounded-lg object-contain"})}),l.prompt&&e.jsxs("div",{className:"p-3 sm:p-4 border-t border-white/10 bg-black/40",children:[e.jsx("p",{className:"text-[10px] sm:text-xs text-gray-400 uppercase tracking-wide mb-1",children:"Prompt"}),e.jsx("p",{className:"text-xs sm:text-sm text-gray-300 line-clamp-3",children:l.prompt})]}),l.approval_status==="pending"&&e.jsxs("div",{className:"p-3 sm:p-4 border-t border-white/10 flex gap-2 sm:gap-3 bg-black",children:[e.jsxs("button",{onClick:()=>I(l.id),disabled:P.has(l.id),className:"flex-1 px-3 sm:px-4 py-2 bg-green-500 hover:bg-green-600 border border-green-400/50 text-white text-sm font-medium rounded-lg transition-colors disabled:opacity-50 flex items-center justify-center gap-1.5",children:[e.jsx(be,{className:"w-4 h-4"})," Approve"]}),e.jsxs("button",{onClick:()=>C(!0),disabled:P.has(l.id),className:"flex-1 px-3 sm:px-4 py-2 bg-red-500 hover:bg-red-600 border border-red-400/50 text-white text-sm font-medium rounded-lg transition-colors disabled:opacity-50 flex items-center justify-center gap-1.5",children:[e.jsx(he,{className:"w-4 h-4"})," Reject"]})]})]})]}),Y&&l&&e.jsxs("div",{className:"fixed inset-0 z-[70] flex items-center justify-center p-3 sm:p-4",children:[e.jsx("div",{className:"absolute inset-0 bg-black/90 backdrop-blur-sm",onClick:()=>C(!1)}),e.jsxs("div",{className:"relative max-w-md w-full bg-black border border-white/10 rounded-xl sm:rounded-2xl p-4 sm:p-6 shadow-2xl",children:[e.jsxs("h3",{className:"text-lg sm:text-xl font-bold text-white mb-3 sm:mb-4 flex items-center gap-2",children:[e.jsx(dt,{className:"w-6 h-6 text-red-400"})," Reject Content"]}),e.jsx("p",{className:"text-gray-400 text-xs sm:text-sm mb-3 sm:mb-4",children:"Please provide a reason for rejection."}),e.jsx("textarea",{value:M,onChange:h=>B(h.target.value),placeholder:"Enter rejection reason...",className:"w-full px-3 sm:px-4 py-2.5 sm:py-3 bg-white/5 border border-white/10 rounded-lg text-white text-sm placeholder-gray-500 focus:outline-none focus:border-red-500 resize-none transition-colors",rows:3}),e.jsxs("div",{className:"flex gap-2 sm:gap-3 mt-3 sm:mt-4",children:[e.jsx("button",{onClick:()=>{C(!1),B("")},className:"flex-1 px-3 sm:px-4 py-2 bg-white/5 hover:bg-white/10 border border-white/10 text-gray-300 text-sm font-medium rounded-lg transition-colors",children:"Cancel"}),e.jsx("button",{onClick:()=>b(l.id),disabled:!M.trim()||P.has(l.id),className:"flex-1 px-3 sm:px-4 py-2 bg-red-500 hover:bg-red-600 border border-red-400/50 text-white text-sm font-medium rounded-lg transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:"Reject"})]})]})]})]}),document.body)},Ys=({project:r,onClose:f,onUpdate:c})=>{const[n,T]=s.useState(null),[v,$]=s.useState(!0),[_,g]=s.useState(!1),[o,k]=s.useState(!1),[w,N]=s.useState(""),[u,x]=s.useState("18:00"),[l,j]=s.useState(""),[M,B]=s.useState("normal"),Y=localStorage.getItem("morphyxToken"),C=async()=>{$(!0);try{const m=await fetch(`/api/organization/projects/${r.id}/deadline`,{headers:{Authorization:`Bearer ${Y}`}});if(m.ok){const D=await m.json();if(T(D),D.deadline.date){const O=new Date(D.deadline.date);
87N(O.toISOString().split("T")[0]),x(O.toTimeString().slice(0,5))}D.progress.target>0&&j(D.progress.target.toString()),B(D.deadline.priority||"normal")}}catch(m){console.error("Error fetching deadline data:",m)}finally{$(!1)}};s.useEffect(()=>{C()},[r.id]);const P=async()=>{k(!0);try{const m={priority:M};w?m.deadlineAt=new Date(`${w}T${u}`).toISOString():m.deadlineAt=null,l?m.targetMediaCount=parseInt(l):m.targetMediaCount=null,(await fetch(`/api/organization/projects/${r.id}/deadline`,{method:"PATCH",headers:{Authorization:`Bearer ${Y}`,"Content-Type":"application/json"},body:JSON.stringify(m)})).ok&&(g(!1),C(),c==null||c())}catch(m){console.error("Error saving deadline:",m)}finally{k(!1)}},U=m=>({no_deadline:{bg:"bg-black",text:"text-white",border:"border-white/10"},on_track:{bg:"bg-black",text:"text-white",border:"border-white/10"},soon:{bg:"bg-black",text:"text-white",border:"border-white/10"},urgent:{bg:"bg-black",text:"text-white",border:"border-white/10"},overdue:{bg:"bg-black",text:"text-white",border:"border-white/10"},completed:{bg:"bg-black",text:"text-white",border:"border-white/10"}})[m]||{bg:"bg-black",text:"text-white",border:"border-white/10"},V=m=>{const D={low:{color:"text-blue-400",dot:"bg-blue-400"},normal:{color:"text-green-400",dot:"bg-green-400"},high:{color:"text-orange-400",dot:"bg-orange-400"},urgent:{color:"text-red-400",dot:"bg-red-400"}};return D[m]||D.normal},J=m=>new Date(m).toLocaleDateString("en-US",{weekday:"short",month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"});if(typeof document>"u")return null;if(v)return fe.createPortal(e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center bg-black/80 backdrop-blur-sm",children:e.jsx("div",{className:"animate-spin w-8 h-8 border-4 border-brand-primary border-t-transparent rounded-full"})}),document.body);if(!n)return null;const I=U(n.deadline.status),b=V(n.deadline.priority);return fe.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[100] flex flex-col px-3 py-3 sm:px-4 sm:py-4",children:[e.jsx("div",{className:"absolute inset-0 bg-black/80 backdrop-blur-sm",onClick:f}),e.jsxs("div",{className:"relative flex-1 flex flex-col max-w-4xl w-full mx-auto bg-black/80 backdrop-blur-md border border-gray-700/50 shadow-2xl rounded-2xl overflow-hidden",children:[e.jsx("div",{className:"flex-shrink-0 p-4 sm:p-6 border-b border-gray-700/50",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(Je,{className:"w-6 h-6 text-white flex-shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-xl font-bold text-white truncate",children:r.name}),e.jsx("p",{className:"text-gray-400 text-sm mt-0.5",children:"Deadline & Progress"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[!_&&e.jsxs("button",{onClick:()=>g(!0),className:"px-3 py-1.5 hover:bg-white/10 border border-white/10 text-gray-300 text-sm font-medium rounded-lg transition-colors flex items-center gap-1.5",children:[e.jsx(nt,{className:"w-4 h-4"})," Edit"]}),e.jsx("button",{onClick:f,className:"p-2 hover:bg-white/10 rounded-lg transition-colors",children:e.jsx(he,{className:"w-5 h-5 text-gray-400"})})]})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6 space-y-4 sm:space-y-6",children:_?e.jsxs("div",{className:"space-y-4 sm:space-y-6",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm font-medium text-gray-300 mb-2",children:[e.jsx(Je,{className:"w-4 h-4 text-gray-400"})," Deadline Date & Time"]}),e.jsxs("div",{className:"flex gap-2 sm:gap-3",children:[e.jsx("input",{type:"date",value:w,onChange:m=>N(m.target.value),className:"flex-1 px-4 py-2 bg-white/5 border border-white/10 rounded-lg text-white text-sm focus:outline-none focus:border-brand-primary transition-colors"}),e.jsx("input",{type:"time",value:u,onChange:m=>x(m.target.value),className:"w-32 px-4 py-2 bg-white/5 border border-white/10 rounded-lg text-white text-sm focus:outline-none focus:border-brand-primary transition-colors"})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1.5",children:"Leave empty for no deadline"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm font-medium text-gray-300 mb-2",children:[e.jsx(ut,{className:"w-4 h-4 text-gray-400"})," Target Media Count"]}
87),e.jsx("input",{type:"number",value:l,onChange:m=>j(m.target.value),placeholder:"e.g., 50",min:"0",max:"10000",className:"w-full px-4 py-2 bg-white/5 border border-white/10 rounded-lg text-white text-sm focus:outline-none focus:border-brand-primary transition-colors"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm font-medium text-gray-300 mb-2",children:[e.jsx(ts,{className:"w-4 h-4 text-gray-400"})," Priority"]}),e.jsx("div",{className:"grid grid-cols-4 gap-2",children:["low","normal","high","urgent"].map(m=>{const D=V(m);return e.jsxs("button",{type:"button",onClick:()=>B(m),className:`p-3 rounded-lg border transition-all text-center capitalize flex flex-col items-center justify-center gap-1.5 ${M===m?"border-brand-primary bg-brand-primary/10":"border-white/10 bg-white/5 hover:border-white/20 hover:bg-white/10"}`,children:[e.jsx("div",{className:`w-2.5 h-2.5 rounded-full ${D.dot}`}),e.jsx("p",{className:`text-xs font-semibold ${D.color}`,children:m})]},m)})})]}),e.jsxs("div",{className:"flex gap-3 pt-4 border-t border-white/10",children:[e.jsx("button",{onClick:()=>g(!1),className:"flex-1 px-4 py-2.5 bg-white/5 hover:bg-white/10 border border-white/10 text-gray-300 text-sm font-semibold rounded-lg transition-colors",children:"Cancel"}),e.jsx("button",{onClick:P,disabled:o,className:"flex-1 px-4 py-2.5 bg-gradient-to-r from-brand-primary to-brand-secondary hover:opacity-90 text-black text-sm font-bold rounded-lg disabled:opacity-50 transition-all shadow-lg shadow-brand-primary/20",children:o?"Saving...":"Save"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`p-4 rounded-xl border ${I.border} ${I.bg}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm text-gray-400 mb-1 flex items-center gap-1.5",children:[e.jsx(Ee,{className:"w-4 h-4"})," Status"]}),e.jsx("p",{className:`text-xl font-bold capitalize ${I.text}`,children:n.deadline.status.replace("_"," ")})]}),e.jsx("div",{className:"text-right",children:e.jsxs("span",{className:`text-sm font-semibold flex items-center gap-1.5 ${b.color}`,children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${b.dot}`})," ",n.deadline.priority]})})]}),n.deadline.date&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-white/10",children:[e.jsx("p",{className:"text-sm text-gray-400 mb-1",children:"Due Date"}),e.jsx("p",{className:"text-white font-medium text-base",children:J(n.deadline.date)}),n.deadline.daysRemaining!==null&&e.jsx("p",{className:`text-sm mt-1 font-medium ${n.deadline.isOverdue?"text-red-400":"text-gray-400"}`,children:n.deadline.isOverdue?`${Math.abs(n.deadline.daysRemaining)} days overdue`:`${n.deadline.daysRemaining} days remaining`})]})]}),n.progress.target>0&&e.jsxs("div",{className:"bg-black border border-white/10 rounded-xl p-4",children:[e.jsxs("div",{className:"flex justify-between mb-2",children:[e.jsxs("span",{className:"text-sm text-gray-400 flex items-center gap-1.5",children:[e.jsx(ut,{className:"w-4 h-4"})," Progress"]}),e.jsxs("span",{className:"text-sm font-semibold text-white",children:[n.progress.current," / ",n.progress.target,n.progress.pending>0&&e.jsxs("span",{className:"text-yellow-400 ml-2",children:["(+",n.progress.pending," pending)"]})]})]}),e.jsx("div",{className:"h-4 bg-gray-800 rounded-full overflow-hidden border border-white/5",children:e.jsx("div",{className:`h-full transition-all duration-500 ${n.progress.isComplete?"bg-gradient-to-r from-green-500 to-emerald-400":"bg-gradient-to-r from-brand-primary to-brand-secondary"}`,style:{width:`${n.progress.percentage}%`}})}),e.jsxs("div",{className:"flex justify-between mt-2",children:[e.jsx("span",{className:"text-xs text-gray-500 flex items-center gap-1",children:n.progress.isComplete?e.jsxs(e.Fragment,{children:[e.jsx(Le,{className:"w-3 h-3 text-green-400"})," Done!"]}):`${n.progress.percentage}%`}),e.jsxs("span",{className:"text-xs text-gray-500",children:[n.progress.target-n.progress.current," more needed"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"bg-black border border-white/10 rounded-xl p-4 text-center",children:[e.jsx("p",{className:"text-3xl font-bold text-white mb-1",children:n.stats.totalMedia}),e.jsx("p",{className:"text-sm text-gray-400",children:"Total Media"})]}),e.jsxs("div",{className:"bg-black border border-white/10 rounded-xl p-4 text-center",children:[e.jsx("p",{className:"text-3xl font-bold text-white mb-1",children:n.forecast.avgDailyRate}),e.jsx("p",{className:"text-sm text-gray-400",children:"Avg/Day"})]})]}),n.forecast.estimatedCompletionDate&&!n.progress.isComplete&&e.jsxs("div",{className:"bg-black border border-blue-500/30 rounded-xl p-4",children:[e.jsxs("p",{className:"text-sm text-blue-400 mb-1 flex items-center gap-1.5",children:[e.jsx(St,{className:"w-4 h-4"})," Estimated Completion"]}),e.jsx("p",{className:"text-white font-medium text-base",children:J(n.forecast.estimatedCompletionDate)}),e.jsxs("p",{className:"text-xs text-gray-400 mt-1",children:["Based on ",n.forecast.avgDailyRate," items/day"]})]}),n.forecast.dailyUploads.length>0&&e.jsxs("div",{className:"bg-black border border-white/10 rounded-xl p-4",children:[e.jsxs("p",{className:"text-sm text-gray-400 mb-3 flex items-center gap-1.5",children:[e.jsx(Fe,{className:"w-4 h-4"})," Activity (7 Days)"]}),e.jsx("div",{className:"flex items-end gap-1 sm:gap-1.5 h-24",children:[...Array(7)].map((m,D)=>{const O=new Date;O.setDate(O.getDate()-(6-D));const Q=O.toISOString().split("T")[0],h=n.forecast.dailyUploads.find(ee=>ee.date===Q),S=(h==null?void 0:h.count)||0,E=Math.max(...n.forecast.dailyUploads.map(ee=>ee.count),1),W=S/E*100;return e.jsxs("div",{className:"flex-1 flex flex-col items-center",children:[e.jsx("div",{className:"w-full bg-brand-primary/50 hover:bg-brand-primary rounded-t transition-colors",style:{height:`${Math.max(W,4)}%`},title:`${O.toLocaleDateString()}: ${S} items`}),e.jsx("span",{className:"text-[10px] text-gray-500 mt-1.5 font-medium",children:O.toLocaleDateString("en-US",{weekday:"short"}).charAt(0)})]},D)})})]}),n.stats.lastUpload&&e.jsxs("div",{className:"text-center text-sm text-gray-500 pt-2",children:["Last upload: ",J
87(n.stats.lastUpload)]})]})})]})]}),document.body)},Ks=({project:r,onClose:f})=>{const[c,n]=s.useState([]),[T,v]=s.useState(!0),[$,_]=s.useState(!1),[g,o]=s.useState(null),[k,w]=s.useState("all"),[N,u]=s.useState("approved"),[x,l]=s.useState(!1),j=localStorage.getItem("morphyxToken"),M=async()=>{try{const b=await fetch(`/api/organization/projects/${r.id}/export`,{headers:{Authorization:`Bearer ${j}`}});if(b.ok){const m=await b.json();n(m.jobs||[])}}catch(b){console.error("Error fetching export jobs:",b)}finally{v(!1)}},B=async b=>{try{const m=await fetch(`/api/organization/projects/${r.id}/export?jobId=${b}`,{headers:{Authorization:`Bearer ${j}`}});if(m.ok){const O=(await m.json()).job;return n(Q=>Q.map(h=>h.id===b?O:h)),(O.status==="completed"||O.status==="failed")&&o(null),O}}catch(m){console.error("Error polling job status:",m)}return null};s.useEffect(()=>{M()},[r.id]),s.useEffect(()=>{if(g){const b=setInterval(()=>{B(g)},2e3);return()=>clearInterval(b)}},[g]);const Y=async()=>{var b;_(!0);try{const m={};k!=="all"&&(m.mediaType=k),m.approvalStatus=N==="all"?["pending","approved","rejected","auto_approved"]:["approved","auto_approved"],m.favoritesOnly=x;const D=await fetch(`/api/organization/projects/${r.id}/export`,{method:"POST",headers:{Authorization:`Bearer ${j}`,"Content-Type":"application/json"},body:JSON.stringify(m)}),O=await D.json();if(D.ok){const Q=O.job;n(h=>[Q,...h]),o(Q.id)}else D.status===409?o((b=O.job)==null?void 0:b.id):alert(O.message||"Failed to create export")}catch(m){console.error("Error creating export:",m)}finally{_(!1)}},C=b=>{if(b.file_url)try{const m=b.file_url.split(",")[1],D=atob(m),O=JSON.parse(D),Q=P(O),h=new Blob([Q],{type:"text/html"}),S=window.URL.createObjectURL(h),E=document.createElement("a");E.href=S,E.download=`${r.name.replace(/[^a-z0-9]/gi,"_")}_export.html`,document.body.appendChild(E),E.click(),document.body.removeChild(E),window.URL.revokeObjectURL(S)}catch(m){console.error("Error downloading:",m)}},P=b=>`<!DOCTYPE html>
88<html lang="en">
89<head>
90    <meta charset="UTF-8">
91    <meta name="viewport" content="width=device-width, initial-scale=1.0">
92    <title>${b.projectName} - Export</title>
93    <style>
94        * { box-sizing: border-box; margin: 0; padding: 0; }
95        body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #111; color: #fff; padding: 20px; }
96        .header { text-align: center; margin-bottom: 30px; }
97        .header h1 { font-size: 24px; margin-bottom: 5px; }
98        .header p { color: #888; font-size: 14px; }
99        .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 15px; }
100        .item { background: #222; border-radius: 8px; overflow: hidden; }
101        .item img, .item video { width: 100%; height: 150px; object-fit: cover; }
102        .item-info { padding: 10px; }
103        .item-info p { font-size: 12px; color: #aaa; margin-bottom: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
104        .item-info a { display: block; padding: 8px 12px; background: #00D4FF; color: #000; text-decoration: none; border-radius: 4px; text-align: center; font-size: 12px; font-weight: 600; }
105        .item-info a:hover { background: #00b8e6; }
106        .download-all { position: fixed; bottom: 20px; right: 20px; padding: 15px 25px; background: linear-gradient(135deg, #00D4FF, #8B5CF6); color: #000; border: none; border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 14px; }
107    </style>
108</head>
109<body>
110    <div class="header">
111        <h1>📁 ${b.projectName}</h1>
112        <p>Exported ${b.totalFiles} files on ${new Date(b.exportedAt).toLocaleDateString()}</p>
113    </div>
114    <div class="grid">
115        ${b.files.map(m=>`
116        <div class="item">
117            ${m.type==="video"?`<video src="${m.url}" muted></video>`:`<img src="${m.url}" alt="${m.filename}" loading="lazy">`}
118            <div class="item-info">
119                <p>${m.filename}</p>
120                <a href="${m.url}" download="${m.filename}" target="_blank">⬇️ Download</a>
121            </div>
122        </div>
123        `).join("")}
124    </div>
125    <button class="download-all" onclick="downloadAll()">⬇️ Download All Files</button>
126    <script>
127        async function downloadAll() {
128            const files = ${JSON.stringify(b.files)};
129            for (let i = 0; i < files.length; i++) {
130                const file = files[i];
131                const link = document.createElement('a');
132                link.href = file.url;
133                link.download = file.filename;
134                link.target = '_blank';
135                document.body.appendChild(link);
136                link.click();
137                document.body.removeChild(link);
138                await new Promise(r => setTimeout(r, 500));
139            }
140        }
141    <\/script>
142</body>
143</html>`,U=b=>{const m={pending:{bg:"bg-yellow-500/20",text:"text-yellow-400",icon:"⏳"},processing:{bg:"bg-blue-500/20",text:"text-blue-400",icon:"⚙️"},completed:{bg:"bg-green-500/20",text:"text-green-400",icon:"✅"},failed:{bg:"bg-red-500/20",text:"text-red-400",icon:"❌"}};return m[b]||m.pending},V=b=>new Date(b).toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}),J=b=>{if(b===0)return"0 B";const m=1024,D=["B","KB","MB","GB"],O=Math.floor(Math.log(b)/Math.log(m));return parseFloat((b/Math.pow(m,O)).toFixed(2))+" "+D[O]},I=c.find(b=>b.status==="pending"||b.status==="processing");return e.jsxs("div",{className:"fixed inset-0 z-50 flex flex-col",children:[e.jsx("div",{className:"absolute inset-0 bg-black/80 backdrop-blur-sm",onClick:f}),e.jsxs("div",{className:"relative flex-1 flex flex-col max-w-2xl w-full mx-auto my-2 sm:my-4 bg-gray-900 border border-gray-700 rounded-xl sm:rounded-2xl overflow-hidden",children:[e.jsx("div",{className:"flex-shrink-0 p-3 sm:p-4 md:p-6 border-b border-gray-700",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 min-w-0",children:[e.jsx("div",{className:"w-8 h-8 sm:w-10 sm:h-10 rounded-lg flex items-center justify-center flex-shrink-0",style:{backgroundColor:r.color},children:e.jsx("span",{className:"text-lg sm:text-xl",children:"📦"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"text-lg sm:text-xl font-bold text-white truncate",children:r.name}),e.jsx("p",{className:"text-gray-400 text-xs sm:text-sm",children:"Bulk Export & Download"})]})]}),e.jsx("button",{onClick:f,className:"p-1.5 sm:p-2 hover:bg-gray-700 rounded-lg transition-colors flex-shrink-0",children:e.jsx("svg",{className:"w-4 h-4 sm:w-5 sm:h-5 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-3 sm:p-4 md:p-6 space-y-4 sm:sp
143ace-y-6",children:[!I&&e.jsxs("div",{className:"bg-gray-800/50 border border-gray-700 rounded-lg sm:rounded-xl p-3 sm:p-4 space-y-3 sm:space-y-4",children:[e.jsx("h3",{className:"text-white font-semibold text-sm sm:text-base",children:"🆕 New Export"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs sm:text-sm text-gray-400 mb-1.5 sm:mb-2",children:"Media Type"}),e.jsx("div",{className:"flex gap-1.5 sm:gap-2",children:[{value:"all",label:"All",mobileLabel:"🎨"},{value:"image",label:"Images",mobileLabel:"🖼️"},{value:"video",label:"Videos",mobileLabel:"🎬"}].map(({value:b,label:m,mobileLabel:D})=>e.jsxs("button",{onClick:()=>w(b),className:`flex-1 px-2 sm:px-3 py-1.5 sm:py-2 rounded-lg text-xs sm:text-sm transition-all ${k===b?"bg-brand-primary/20 text-brand-primary border border-brand-primary/50":"bg-gray-700/50 text-gray-400 border border-transparent hover:border-gray-600"}`,children:[e.jsx("span",{className:"sm:hidden",children:D}),e.jsxs("span",{className:"hidden sm:inline",children:[D," ",m]})]},b))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs sm:text-sm text-gray-400 mb-1.5 sm:mb-2",children:"Approval Status"}),e.jsxs("div",{className:"flex gap-1.5 sm:gap-2",children:[e.jsx("button",{onClick:()=>u("approved"),className:`flex-1 px-2 sm:px-3 py-1.5 sm:py-2 rounded-lg text-xs sm:text-sm transition-all ${N==="approved"?"bg-green-500/20 text-green-400 border border-green-500/50":"bg-gray-700/50 text-gray-400 border border-transparent hover:border-gray-600"}`,children:"✅ Approved"}),e.jsx("button",{onClick:()=>u("all"),className:`flex-1 px-2 sm:px-3 py-1.5 sm:py-2 rounded-lg text-xs sm:text-sm transition-all ${N==="all"?"bg-purple-500/20 text-purple-400 border border-purple-500/50":"bg-gray-700/50 text-gray-400 border border-transparent hover:border-gray-600"}`,children:"📋 All"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3",children:[e.jsx("input",{type:"checkbox",id:"favoritesOnly",checked:x,onChange:b=>l(b.target.checked),className:"w-4 h-4 rounded border-gray-600 bg-gray-700 text-brand-primary focus:ring-brand-primary"}),e.jsx("label",{htmlFor:"favoritesOnly",className:"text-xs sm:text-sm text-gray-300",children:"⭐ Favorites only"})]}),e.jsx("button",{onClick:Y,disabled:$,className:"w-full px-3 sm:px-4 py-2.5 sm:py-3 bg-gradient-to-r from-brand-primary to-brand-secondary text-black text-sm sm:text-base font-semibold rounded-lg disabled:opacity-50 transition-all hover:shadow-lg",children:$?"⏳ Creating...":"📦 Create Export"})]}),I&&e.jsxs("div",{className:"bg-blue-500/10 border border-blue-500/30 rounded-lg sm:rounded-xl p-3 sm:p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2 sm:mb-3",children:[e.jsx("h3",{className:"text-white font-semibold text-sm sm:text-base",children:I.status==="pending"?"⏳ Preparing...":"⚙️ Generating..."}),e.jsx("span",{className:`px-2 py-0.5 sm:py-1 rounded text-[10px] sm:text-xs ${U(I.status).bg} ${U(I.status).text}`,children:I.status})]}),e.jsx("div",{className:"h-1.5 sm:h-2 bg-gray-700 rounded-full overflow-hidden mb-1.5 sm:mb-2",children:e.jsx("div",{className:"h-full bg-gradient-to-r from-brand-primary to-brand-secondary transition-all duration-500 animate-pulse",style:{width:`${I.total_files>0?I.processed_files/I.total_files*100:50}%`}})}),e.jsxs("p",{className:"text-xs sm:text-sm text-gray-400",children:["Processing ",I.total_files," files..."]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-white font-semibold text-sm sm:text-base mb-2 sm:mb-3",children:"📋 Recent Exports"}),T?e.jsx("div",{className:"space-y-2 sm:space-y-3",children:[1,2].map(b=>e.jsx("div",{className:"h-16 sm:h-20 bg-gray-800 rounded-lg sm:rounded-xl animate-pulse"},b))}):c.length===0?e.jsx("div",{className:"text-center py-6 sm:py-8 text-gray-500 text-sm",children:e.jsx("p",{children:"No exports yet."})}):e.jsx("div",{className:"space-y-2 sm:space-y-3",children:c.map(b=>{const m=U(b.status);return e.jsx("div",{className:"bg-gray-800/50 border border-gray-700 rounded-lg sm:rounded-xl p-3 sm:p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 sm:gap-2 mb-1",children:[e.jsxs("span",{className:`px-1.5 sm:px-2 py-0.5 rounded text-[10px] sm:text-xs ${m.bg} ${m.text}`,children:[m.icon," ",b.status]}),e.jsx("span",{className:"text-[10px] sm:text-xs text-gray-500",children:V(b.created_at)})]}),e.jsxs("p",{className:"text-xs sm:text-sm text-gray-300",children:[b.total_files," files",b.file_size&&` • ${J(b.file_size)}`]}),b.error_message&&e.jsx("p",{className:"text-[10px] sm:text-xs text-red-400 mt-1 truncate",children:b.error_message})]}),b.status==="completed"&&b.file_url&&e.jsx("button",{onClick:()=>
143C(b),className:"px-2 sm:px-3 py-1 sm:py-1.5 bg-green-500 hover:bg-green-600 text-white text-xs sm:text-sm font-medium rounded-lg transition-colors flex-shrink-0",children:"⬇️"})]})},b.id)})})]}),e.jsx("div",{className:"bg-gray-800/30 border border-gray-700/50 rounded-lg sm:rounded-xl p-3 sm:p-4",children:e.jsx("p",{className:"text-xs sm:text-sm text-gray-400",children:"💡 Export generates download links for media. Links expire in 24 hours."})})]})]})]})},Qs=({orgId:r,onProjectSelect:f,selectedProjectId:c})=>{const{user:n}=Ae(),[T,v]=s.useState([]),[$,_]=s.useState(!1),[g,o]=s.useState(null),[k,w]=s.useState(!1),[N,u]=s.useState(!1),[x,l]=s.useState(null),[j,M]=s.useState(null),[B,Y]=s.useState(null),[C,P]=s.useState(null),[U,V]=s.useState(null),[J,I]=s.useState(null),[b,m]=s.useState(null),[D,O]=s.useState(null),[Q,h]=s.useState(!1),[S,E]=s.useState(!1),[W,ee]=s.useState("active"),[re,a]=s.useState(""),[A,L]=s.useState(!1),G=s.useRef(!1),[p,R]=s.useState([]),[H,te]=s.useState([]),[se,le]=s.useState(!1),[y,X]=s.useState({name:"",description:"",color:"#00D4FF",visibility:"team",deadline_at:"",target_media_count:"",priority:"normal",approval_required:!1,auto_approve_admins:!0}),[i,K]=s.useState(!1),ie=[{value:"#00D4FF",name:"Cyan"},{value:"#FF6B6B",name:"Red"},{value:"#4ECDC4",name:"Teal"},{value:"#FFE66D",name:"Yellow"},{value:"#95E1D3",name:"Mint"},{value:"#F38181",name:"Coral"},{value:"#AA96DA",name:"Purple"},{value:"#FCBAD3",name:"Pink"},{value:"#A8E6CF",name:"Green"},{value:"#FF8B94",name:"Salmon"}],ne=localStorage.getItem("morphyxToken"),pe=async()=>{_(!0);try{const t=new URLSearchParams;r&&t.append("orgId",String(r)),W!=="all"&&t.append("status",W),re&&t.append("search",re);const F=await fetch(`/api/organization/projects?${t}`,{headers:{Authorization:`Bearer ${ne}`}});if(!F.ok){const me=await F.json();throw new Error(me.message||"Failed to fetch projects")}const ae=await F.json();v(ae.projects||[]),L(ae.isOrgAdmin||!1),o(null)}catch(t){o(t instanceof Error?t.message:"Error fetching projects")}finally{_(!1)}};s.useEffect(()=>{pe()},[r,W,re]),s.useEffect(()=>{v([]),l(null),M(null),Y(null),P(null),V(null),I(null),m(null),O(null),w(!1),u(!1)},[r]),s.useEffect(()=>{y.visibility==="private"&&(k||N)&&Oe()},[y.visibility,k,N]);const Oe=async()=>{le(!0);try{const t=await fetch(`/api/organizations/${r}/members`,{headers:{Authorization:`Bearer ${ne}`}});if(t.ok){const F=await t.json();R((F==null?void 0:F.members)||F||[])}}catch(t){console.error("Error fetching org members:",t)}finally{le(!1)}},Me=t=>{te(F=>F.includes(t)?F.filter(ae=>ae!==t):[...F,t])},ce=async t=>{var F;if(t.preventDefault(),!G.current){G.current=!0,_(!0);try{const ae=await fetch("/api/organization/projects",{method:"POST",headers:{Authorization:`Bearer ${ne}`,"Content-Type":"application/json"},body:JSON.stringify(y)});if(!ae.ok){const ke=await ae.json();throw new Error(ke.message||"Failed to create project")}const Z=(F=(await ae.json()).project)==null?void 0:F.id;if(y.visibility==="private"&&H.length>0&&Z)for(const ke of H)try{await fetch(`/api/organization/projects/${Z}/members`,{method:"POST",headers:{Authorization:`Bearer ${ne}`,"Content-Type":"application/json"},body:JSON.stringify({memberId:ke,role:"contributor"})})}catch(et){console.error(`Error adding member ${ke}:`,et)}await pe(),w(!1),K(!1),te([]),X({name:"",description:"",color:"#00D4FF",visibility:"team",deadline_at:"",target_media_count:"",priority:"normal",approval_required:!1,auto_approve_admins:!0})}catch(ae){o(ae instanceof Error?ae.message:"Error creating project")}finally{_(!1),G.current=!1}}},oe=async t=>{if(t.preventDefault(),!!x&&!G.current){G.current=!0,_(!0);try{const F=await fetch(`/api/organization/projects/${x.id}`,{method:"PUT",headers:{Authorization:`Bearer ${ne}`,"Content-Type":"application/json"},body:JSON.stringify(y)});if(!F.ok){const ae=await F.json();throw new Error(ae.message||"Failed to update project")}await pe(),u(!1),l(null)}catch(F){o(F instanceof Error?F.message:"Error updating project")}finally{_(!1),G.current=!1}}},je=async()=>{if(D&&!G.current){G.current=!0,E(!0);try{const t=await fetch(`/api/organization/projects/${D.id}?archive=true`,{method:"DELETE",headers:{Authorization:`Bearer ${ne}`}});if(!t.ok){const F=await t.json();throw new Error(F.message||"Failed to archive project")}
143await pe(),O(null)}catch(t){o(t instanceof Error?t.message:"Error archiving project")}finally{E(!1),G.current=!1}}},Ie=async()=>{if(b&&!G.current){G.current=!0,h(!0);try{const t=await fetch(`/api/organization/projects/${b.id}?permanent=true`,{method:"DELETE",headers:{Authorization:`Bearer ${ne}`}});if(!t.ok){const F=await t.json();throw new Error(F.message||"Failed to delete project")}await pe(),m(null)}catch(t){o(t instanceof Error?t.message:"Error deleting project")}finally{h(!1),G.current=!1}}},Ke=t=>n?!!(A||t.created_by===n.id):!1,Qe=t=>{var F;l(t),X({name:t.name,description:t.description||"",color:t.color,visibility:t.visibility,deadline_at:t.deadline_at?t.deadline_at.split("T")[0]:"",target_media_count:((F=t.target_media_count)==null?void 0:F.toString())||"",priority:t.priority||"normal",approval_required:t.approval_required||!1,auto_approve_admins:!0}),K(!1),u(!0)},Ze=t=>{switch(t){case"team":return e.jsx(ue,{className:"w-4 h-4 text-white"});case"private":return e.jsx(is,{className:"w-4 h-4 text-white"});case"public":return e.jsx(rs,{className:"w-4 h-4 text-white"});default:return e.jsx(ue,{className:"w-4 h-4 text-white"})}},Xe=t=>{if(!t)return null;const F=new Date(t),ae=new Date,me=F.getTime()-ae.getTime(),Z=Math.ceil(me/(1e3*60*60*24));return Z<0?{text:`${Math.abs(Z)} day${Math.abs(Z)!==1?"s":""} overdue`,icon:e.jsx(Ye,{className:"w-5 h-5 text-brand-primary"}),urgent:!0}:Z===0?{text:"Due today",icon:e.jsx(xt,{className:"w-5 h-5 text-brand-primary"}),urgent:!0}:Z===1?{text:"Due tomorrow",icon:e.jsx(Ee,{className:"w-5 h-5 text-brand-primary"}),urgent:!0}:Z<=3?{text:`${Z} days left`,icon:e.jsx(He,{className:"w-5 h-5 text-brand-primary"}),urgent:!1}:Z<=7?{text:`${Z} days left`,icon:e.jsx(Je,{className:"w-5 h-5 text-brand-primary"}),urgent:!1}:{text:F.toLocaleDateString("en-US",{month:"short",day:"numeric"}),icon:e.jsx(Le,{className:"w-5 h-5 text-brand-primary"}),urgent:!1}},Ne=(t,F)=>!F||F===0?null:Math.min(Math.round(t/F*100),100);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-1 h-9 rounded-full shrink-0",style:{background:"linear-gradient(180deg, #b9ff00 0%, #6F00FF 100%)"}}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-xl sm:text-2xl font-bold text-white flex items-center gap-2",children:[e.jsx(ze,{className:"w-6 h-6 text-brand-primary"}),e.jsx("span",{children:"Project Workspace"})]}),e.jsx("p",{className:"text-sm font-medium text-gray-400 mt-0.5",children:"Organize, collaborate, and track progress on team projects"})]})]}),e.jsx("div",{className:"relative p-[1.5px] rounded-xl animated-gradient-border shadow-[0_0_15px_rgba(163,230,53,0.35)] shrink-0 w-fit",children:e.jsxs("button",{onClick:()=>w(!0),className:"inline-flex items-center justify-center gap-2 px-5 py-2.5 rounded-[10px] bg-black hover:bg-gray-900 text-white font-bold transition-all shrink-0 text-sm",children:[e.jsx(De,{className:"w-4 h-4 text-brand-primary"}),e.jsx("span",{children:"Create Project"})]})})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4 items-start sm:items-center",children:[e.jsx("div",{className:"flex overflow-x-auto pb-1 -mx-1 px-1 justify-start",children:e.jsx("div",{className:"relative p-[1.5px] rounded-full animated-gradient-border shadow-[0_0_15px_rgba(163,230,53,0.35)] shrink-0",children:e.jsx("div",{className:"flex items-center gap-0.5 sm:gap-1 p-1 bg-black rounded-full",children:["all","active","archived","completed"].map(t=>e.jsxs("button",{onClick:()=>ee(t),className:"relative px-4 sm:px-6 py-1.5 sm:py-2 rounded-full text-xs sm:text-sm font-semibold transition-all duration-300 flex flex-row items-center gap-1.5",children:[W===t&&e.jsx(we.div,{layoutId:"workspace-filter-indicator",className:"absolute inset-0 rounded-full bg-lime-400 shadow-md",transition:{type:"spring",stiffness:400,damping:30}}),e.jsx("span",{className:`relative z-10 flex items-center gap-1 transition-colors duration-300 whitespace-nowrap capitalize ${W===t?"text-black font-bold":"text-gray-400 hover:text-white"}`,children:t})]},t))})})}),e.jsx("div",{className:"flex-1 max-w-sm sm:ml-auto",children:e.jsxs("div",{className:"relative",children:[e.jsx(ct,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-500"}),e.jsx("input",{type:"text",placeholder:"Search projects...",value:re,onChange:t=>a(t.target.value),className:"w-full pl-9 pr-4 py-2 rounded-full bg-black border border-white/10 text-white text-sm focus:border-brand-primary/50 focus:outline-none transition-all"})]})})]}),g&&e.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-red-300 text-sm",children:g}),$&&T.length===0?e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:[1,2,3].map(t=>e.jsx("div",{className:"h-64 bg-black/40 rounded-2xl border border-white/10 animate-pulse"},t))}):T.length===0?e.jsxs("div",{className:"p-12 text-center border border-white/10 rounded-2xl bg-black/40",children:[e.jsx("div",{className:"w-20 h-20 mx-auto mb-6 rounded-2xl bg-black border border-white/10 flex items-center justify-center",children:W!=="all"?e.jsx(ct,{className:"w-8 h-8 text-gray-400"}):e.jsx(ss,{className:"w-8 h-8 text-brand-primary"})}),e.jsx("h4",{className:"text-xl font-bold text-white mb-2",children:W!=="all"?`No ${W} projects`:"Start Your First Project"}),e.jsx("p",{className:"text-gray-400 text-sm mb-6 max-w-md mx-auto",children:W!=="all"?`You don't have any ${W} projects yet. Try a different filter or create a new project.`:"Projects help you organize team content, track deadlines, and collaborate effectively."}),W!=="all"?e.jsx("button",{onClick:()=>ee("all"),className:"text-brand-primary hover:text-brand-secondary transition-colors text-sm font-medium",children:"← Show all projects"}):e.jsx("div",{className:"relative p-[1.5px] rounded-xl animated-gradient-border shadow-[0_0_15px_rgba(163,230,53,0.35)] shrink-0 w-fit mx-auto",children:e.jsxs("button",{onClick:()=>w(!0),className:"inline-flex items-center justify-center gap-2 px-6 py-3 rounded-[10px] bg-black hover:bg-gray-900 text-white font-bold transition-all shrink-0",children:[e.jsx(De,{className:"w-5 h-5 text-brand-primary"}),e.jsx("span",{children:"Create Your First Project"})]})})]}):e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:T.map(t=>{const F=Xe(t.deadline_at),ae=Ne(t.media_count||0,t.target_media_count),me=t.pending_approval_count??0;return e.jsxs("div",{onClick:()=>f==null?void 0:f(t),className:`group relative rounded-2xl border-2 overflow-hidden bg-black cursor-pointer transition-all duration-300 hover:shadow-xl ${c===t.id?"border-brand-primary shadow-lg shadow-brand-primary/20 scale-[1.02]":F!=null&&F.urgent?"border-gray-700/50 hover:border-red-500/50 shadow-red-500/5":"border-gray-700/50 hover:border-brand-primary/50"}`,children:[e.jsxs("div",{className:"h-28 relative overflow-hidden flex flex-col justify-between",style:{backgroundColor:t.color||"#262626"},children:[t.thumbnail_url&&e.jsx("img",{src:t.thumbnail_url,alt:"",className:"absolute inset-0 w-full h-full object-cover",loading:"lazy",onError:Z=>{Z.currentTarget.style.display="none"}}),e.jsx("div",{className:"absolute inset-0 bg-gradient-to-t from-gray-900 via-gray-900/30 to-transparent"}),e.jsx("div",{className:"relative shrink-0 p-2 flex items-start justify-between gap-1.5",children:e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("div",{className:"w-7 h-7 shrink-0 rounded-lg bg-black/40 backdrop-blur-sm flex items-center justify-center text-sm",title:t.visibility,children:Ze(t.visibility)}),t.priority&&t.priority!=="normal"&&e.jsx("div",{className:`shrink-0 flex items-center gap-1 px-2 py-1 rounded-lg text-[10px] font-bold uppercase tracking-wide backdrop-blur-sm ${t.priority==="urgent"?"bg-red-500/80 text-white":t.priority==="high"?"bg-orange-500/80 text-white":"bg-blue-500/80 text-white"}`,children:t.priority==="urgent"?e.jsxs(e.Fragment,{children:[e.jsx(xt,{className:"w-3 h-3"})," URGENT"]}):t.priority==="high"?e.jsxs(e.Fragment,{children:[e.jsx(qt,{className:"w-3 h-3"})," HIGH"]}):e.jsxs(e.Fragment,{children:[e.jsx(js,{className:"w-3 h-3"})," LOW"]})})]})}),e.jsx("div",{className:"relative shrink-0 p-3 pt-1",children:e.jsx("h4",{className:"text-white font-bold text-lg truncate drop-shadow-lg",children:t.name})})]}),e.jsxs("div",{className:"p-4 bg-black border-t border-white/10 space-y-3",children:[t.description?e.jsx("p",{className:"text-gray-400 text-sm line-clamp-2 leading-relaxed",children:t.description}):e.jsx("p",{className:"text-gray-500 text-sm italic",children:"No description added"}),F&&e.jsx("div",{className:`relative p-[1.5px] rounded-xl animated-gradient-border shadow-[0_0_15px_rgba(163,230,53,0.35)] shrink-0 w-full ${F.urgent?"animate-pulse":""}`,children:e.jsxs("div",{className:"bg-black rounded-[10px] p-3 w-full",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"flex-shrink-0",children:F.icon}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-white tracking-tight",children:F.text}),e.jsx("p",{className:"text-[10px] text-gray-400 mt-0.5",children:new Date(t.deadline_at).toLocaleDateString("en-US",{weekday:"short",month:"short",day:"numeric",year:"numeric"})})]})]}),t.target_media_count&&ae!==null&&e.jsxs("div",{className:"text-right",children:[e.jsxs("p",{className:"text-sm font-bold text-white tracking-tight",children:[ae,"%"]}),e.jsx("p",{className:"text-[10px] text-gray-400 mt-0.5",children:"complete"})]})]}),t.target_media_count&&ae!==null&&e.jsx("div",{className:"mt-3 h-1.5 bg-gray-800 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-500 bg-brand-primary",style:{width:`${ae}%`}})})]})}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[t.approval_required&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-lg text-[10px] font-medium bg-white/5 text-white border border-white/20",children:[e.jsx(be,{className:"w-3 h-3"})," Review Required"]}),me>0&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 rounded-lg text-[10px] font-medium bg-white/5 text-white border border-white/20 animate-pulse",children:[e.jsx(He,{className:"w-3 h-3 text-white"})," ",me," Awaiting Review"]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t border-gray-700/50",children:[e.jsxs("div",{className:"flex items-center gap-4 text-sm text-gray-400",children:[e.jsxs("span",{className:"flex items-center gap-1.5",title:"Media files",children:[e.jsx(Ge,{className:"w-4 h-4"}),e.jsx("span",{className:"font-medium",children:t.media_count||0}),t.target_media_count&&e.jsxs("span",{className:"text-gray-600",children:["/ ",t.target_media_count]})]}),e.jsxs("span",{className:"flex items-center gap-1.5",title:"Team members",children:[e.jsx(ue,{className:"w-4 h-4"}),e.jsx("span",{className:"font-medium",children:t.member_count||1})]})]}),e.jsxs("div",{className:"text-gray-500 text-xs opacity-0 group-hover:opacity-100 transition-opacity flex items-center gap-1",children:["Click to select ",e.jsx(Ft,{className:"w-3 h-3"})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2 pt-3 pb-1 border-t border-gray-700/40",children:[e.jsx("button",{onClick:Z=>{Z.stopPropagation(),M(t)},className:"p-1.5 text-gray-400 hover:text-white transition-colors",title:"Browse project gallery",children:e.jsx(as,{className:"w-4 h-4"})}),e.jsx("button",{onClick:Z=>{Z.stopPropagation(),Y(t)},className:"p-1.5 text-gray-400 hover:text-white transition-colors",title:"View project analytics and insights",children:e.jsx(Fe,{className:"w-4 h-4"})}),e.jsxs("button",{onClick:Z=>{Z.stopPropagation(),P(t)},className:"p-1.5 text-gray-400 hover:text-white transition-colors relative",title:"Review and approve content",children:[e.jsx(Le,{className:"w-4 h-4"}),me>0&&e.jsx("span",{className:"absolute -top-1.5 -right-1.5 w-5 h-5 bg-red-500 text-white text-[10px] font-bold rounded-full flex items-center justify-center shadow-lg",children:me>9?"9+":me})]}),e.jsx("button",{onClick:Z=>{Z.stopPropagation(),V(t)},className:"p-1.5 text-gray-400 hover:text-white transition-colors",title:"Manage deadline and track progress",children:e.jsx(Je,{className:"w-4 h-4"})}),e.jsx("button",{onClick:Z=>{Z.stopPropagation(),Qe(t)},className:"p-1.5 text-gray-400 hover:text-white transition-colors",title:"Edit project settings",children:e.jsx(Ue,{className:"w-4 h-4"})}),Ke(t)&&e.jsx("button",{onClick:Z=>{Z.stopPropagation(),m(t)},className:"p-1.5 text-gray-400 hover:text-red-400 transition-colors",title:"Delete project",children:e.jsx(At,{className:"w-4 h-4"})})]})]})]},t.id)})}),k&&typeof document<"u"&&fe.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-2 sm:p-4",children:[e.jsx("div",{className:"absolute inset-0 bg-black/90 backdrop-blur-2xl animate-in fade-in duration-200",onClick:()=>w(!1)}),e.jsxs("div",{className:"relative bg-black border border-white/10 rounded-xl sm:rounded-2xl w-full max-w-lg shadow-2xl animate-in zoom-in-95 duration-200 flex flex-col max-h-[95vh] sm:max-h-[90vh] overflow-hidden",children:[e.jsxs("div",{className:"px-5 py-4 border-b border-white/10 flex items-center justify-between flex-shrink-0 bg-white/5",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(ze,{className:"w-6 h-6 text-white"}),e.jsx("h3",{className:"text-base font-bold text-white truncate",children:"Create New Project"})]}),e.jsx("button",{type:"button",onClick:()=>w(!1),className:"p-1.5 text-gray-400 hover:text-white hover:bg-white/10 rounded-lg transition-all flex-shrink-0 ml-2",children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs("form",{onSubmit:ce,className:"flex-1 overflow-y-auto p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-300 mb-1",children:"Project Name *"}),e.jsx("input",{type:"text",value:y.name,onChange:t=>X({...y,name:t.target.value}),className:"w-full px-4 py-2 rounded-lg bg-white/5 border border-white/10 text-white focus:border-brand-primary focus:outline-none transition-colors",placeholder:"My Awesome Project",required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-300 mb-1",children:"Description"}),e.jsx("textarea",{value:y.description,onChange:t=>X({...y,description:t.target.value}),className:"w-full px-4 py-2 rounded-lg bg-white/5 border border-white/10 text-white focus:border-brand-primary focus:outline-none resize-none transition-colors",placeholder:"What is this project about?",rows:3})]}),e.jsxs("div",{className:"space-y-4 p-4 rounded-xl bg-black border border-white/10",children:[e.jsx("p",{className:"text-[10px] font-bold text-gray-500 uppercase tracking-wider",children:"Appearance & Access"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-300 mb-2",children:"Project Color"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:ie.map(t=>e.jsx("button",{type:"button",onClick:()=>X({...y,color:t.value}
143),className:`w-8 h-8 rounded-full transition-transform ${y.color===t.value?"scale-125 ring-2 ring-white ring-offset-2 ring-offset-black":"hover:scale-110"}`,style:{backgroundColor:t.value},title:t.name},t.value))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-300 mb-2",children:"Visibility"}),e.jsx("div",{className:"relative p-[1.5px] rounded-full animated-gradient-border shadow-[0_0_15px_rgba(163,230,53,0.35)] shrink-0 w-max",children:e.jsx("div",{className:"flex items-center gap-1 p-1 bg-black rounded-full",children:[{value:"team",label:"Team"},{value:"private",label:"Private"}].map(t=>e.jsxs("button",{type:"button",onClick:()=>X({...y,visibility:t.value}),className:"relative px-6 py-2 rounded-full text-sm font-semibold transition-all duration-300",children:[y.visibility===t.value&&e.jsx(we.div,{layoutId:"visibility-indicator",className:"absolute inset-0 rounded-full bg-lime-400 shadow-md",transition:{type:"spring",stiffness:400,damping:30}}),e.jsx("span",{className:`relative z-10 transition-colors duration-300 ${y.visibility===t.value?"text-black font-bold":"text-gray-400 hover:text-white"}`,children:t.label})]},t.value))})}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:y.visibility==="team"?"All org members can access":"Only invited members"})]})]}),y.visibility==="private"&&e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-300 mb-2",children:["Select Team Members (",H.length," selected)"]}),se?e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx("div",{className:"animate-spin w-5 h-5 border-2 border-brand-primary border-t-transparent rounded-full"})}):p.length===0?e.jsx("div",{className:"p-3 bg-white/5 rounded-lg text-center text-gray-400 text-sm",children:"No other team members found"}):e.jsx("div",{className:"max-h-48 overflow-y-auto space-y-2 p-2 bg-black border border-white/10 rounded-lg",children:p.map(t=>e.jsxs("label",{className:`flex items-center gap-3 p-2 rounded-lg cursor-pointer transition-colors ${H.includes(t.user_id)?"bg-brand-primary/20 border border-brand-primary/50":"hover:bg-white/5 border border-transparent"}`,children:[e.jsx("input",{type:"checkbox",checked:H.includes(t.user_id),onChange:()=>Me(t.user_id),className:"w-4 h-4 rounded border-gray-600 bg-gray-700 text-brand-primary focus:ring-brand-primary"}),e.jsx("div",{className:"w-8 h-8 rounded-full bg-white/10 flex items-center justify-center overflow-hidden flex-shrink-0",children:t.profile_image?e.jsx("img",{src:t.profile_image,alt:`${t.name}'s avatar`,className:"w-full h-full object-cover"}):e.jsx(ye,{className:"w-4 h-4 text-white"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-white text-sm font-medium truncate",children:t.name}),e.jsx("p",{className:"text-gray-400 text-xs truncate",children:t.email})]}),e.jsx("span",{className:"px-2 py-0.5 rounded text-xs capitalize bg-white/5 text-gray-300 border border-white/10",children:t.role})]},t.user_id))}),e.jsx("p",{className:"text-gray-500 text-xs mt-1",children:"These members will be added as contributors to the project"})]}),e.jsxs("button",{type:"button",onClick:()=>K(!i),className:"w-full flex items-center justify-between text-sm text-gray-400 hover:text-white py-3 border-t border-white/10 mt-2",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Ue,{className:"w-4 h-4"}),e.jsx("span",{children:"Advanced Settings"})]}),e.jsx("span",{children:i?"▲":"▼"})]}),i&&e.jsxs("div",{className:"space-y-4 p-4 rounded-xl bg-black border border-white/10",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-300 mb-2",children:"Priority"}),e.jsx("div",{className:"grid grid-cols-4 gap-2",children:["low","normal","high","urgent"].map(t=>{const F={low:"bg-blue-400",normal:"bg-green-400",high:"bg-orange-400",urgent:"bg-red-400"};return e.jsxs("button",{type:"button",onClick:()=>X({...y,priority:t}),className:`p-2 rounded-lg border transition-all text-center capitalize flex flex-col items-center justify-center gap-1.5 ${y.priority===t?"border-brand-primary bg-brand-primary/10":"border-white/10 bg-white/5 hover:border-white/20"}`,children:[e.jsx("div",{className:`w-2.5 h-2.5 rounded-full ${F[t]}`}),e.jsx("p",{className:"text-xs font-semibold text-white",children:t})]},t)})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-300 mb-1",children:"Deadline"}),e.jsx("input",{type:"date",value:y.deadline_at,onChange:t=>X({...y,deadline_at:t.target.value}),className:"w-full px-3 py-2 rounded-lg bg-white/5 border border-white/10 text-white focus:border-brand-primary focus:outline-none text-sm transition-colors",min:new Date().toISOString().split("T")[0]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-300 mb-1",children:"Target Media"}),e.jsx("input",{type:"number",value:y.target_media_count,onChange:t=>X({...y,target_media_count:t.target.value}),className:"w-full px-3 py-2 rounded-lg bg-white/5 border border-white/10 text-white focus:border-brand-primary focus:outline-none text-sm transition-colors",placeholder:"e.g., 50",min:"1"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:y.approval_required,onChange:t=>X({...y,approval_required:t.target.checked}),className:"w-4 h-4 rounded border-gray-600 bg-gray-700 text-brand-primary focus:ring-brand-primary"}),e.jsx("span",{className:"text-sm text-gray-300",children:"Require approval for uploads"})]}),y.approval_required&&e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer ml-6",children:[e.jsx("input",{type:"checkbox",checked:y.auto_approve_admins,onChange:t=>X({...y,auto_approve_admins:t.target.checked}),className:"w-4 h-4 rounded border-gray-600 bg-gray-700 text-brand-primary focus:ring-brand-primary"}),e.jsx("span",{className:"text-xs text-gray-400",children:"Auto-approve admin/owner uploads"})]})]})]}),e.jsxs("div",{className:"flex gap-3 pt-4 border-t border-white/10",children:[e.jsx("button",{type:"button",onClick:()=>w(!1),className:"flex-1 px-4 py-2.5 bg-white/5 hover:bg-white/10 border border-white/10 text-gray-300 text-sm font-semibold rounded-lg transition-colors",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:$||!y.name.trim(),className:"flex-1 px-4 py-2.5 bg-gradient-to-r from-brand-primary to-brand-secondary text-black text-sm font-bold rounded-lg hover:shadow-lg transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:$?"Creating...":"Create Project"})]})]})]})]}),document.body),N&&x&&typeof document<"u"&&fe.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-2 sm:p-4",children:[e.jsx("div",{className:"absolute inset-0 bg-black/90 backdrop-blur-2xl animate-in fade-in duration-200",onClick:()=>u(!1)}),e.jsxs("div",{className:"relative bg-black border border-white/10 rounded-xl sm:rounded-2xl w-full max-w-lg shadow-2xl animate-in zoom-in-95 duration-200 flex flex-col max-h-[95vh] sm:max-h-[90vh] overflow-hidden",children:[e.jsxs("div",{className:"px-5 py-4 border-b border-white/10 flex items-center justify-between flex-shrink-0 bg-white/5",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(nt,{className:"w-6 h-6 text-white"}),e.jsx("h3",{className:"text-base font-bold text-white truncate",children:"Edit Project"})]}),e.jsx("button",{type:"button",onClick:()=>u(!1),className:"p-1.5 text-gray-400 hover:text-white hover:bg-white/10 rounded-lg transition-all flex-shrink-0 ml-2",children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs("form",{onSubmit:oe,className:"flex-1 overflow-y-auto p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-300 mb-1",children:"Project Name *"}),e.jsx("input",{type:"text",value:y.name,onChange:t=>X({...y,name:t.target.value}),className:"w-full px-4 py-2 rounded-lg bg-white/5 border border-white/10 text-white focus:border-brand-primary focus:outline-none transition-colors",required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-300 mb-1",children:"Description"}),e.jsx("textarea",{value:y.description,onChange:t=>X({...y,description:t.target.value}),className:"w-full px-4 py-2 rounded-lg bg-white/5 border border-white/10 text-white focus:border-brand-primary focus:outline-none resize-none transition-colors",rows:3})]}),e.jsxs("div",{className:"space-y-4 p-4 rounded-xl bg-black border border-white/10",children:[e.jsx("p",{className:"text-[10px] font-bold text-gray-500 uppercase tracking-wider",children:"Appearance & Access"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-300 mb-2",children:"Project Color"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:ie.map(t=>e.jsx("button",{type:"button",onClick:()=>X({...y,color:t.value}
143),className:`w-8 h-8 rounded-full transition-transform ${y.color===t.value?"scale-125 ring-2 ring-white ring-offset-2 ring-offset-black":"hover:scale-110"}`,style:{backgroundColor:t.value},title:t.name},t.value))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-300 mb-2",children:"Visibility"}),e.jsx("div",{className:"relative p-[1.5px] rounded-full animated-gradient-border shadow-[0_0_15px_rgba(163,230,53,0.35)] shrink-0 w-max",children:e.jsx("div",{className:"flex items-center gap-1 p-1 bg-black rounded-full",children:[{value:"team",label:"Team"},{value:"private",label:"Private"}].map(t=>e.jsxs("button",{type:"button",onClick:()=>X({...y,visibility:t.value}),className:"relative px-6 py-2 rounded-full text-sm font-semibold transition-all duration-300",children:[y.visibility===t.value&&e.jsx(we.div,{layoutId:"visibility-indicator-edit",className:"absolute inset-0 rounded-full bg-lime-400 shadow-md",transition:{type:"spring",stiffness:400,damping:30}}),e.jsx("span",{className:`relative z-10 transition-colors duration-300 ${y.visibility===t.value?"text-black font-bold":"text-gray-400 hover:text-white"}`,children:t.label})]},t.value))})}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:y.visibility==="team"?"All org members can access":"Only invited members"})]})]}),y.visibility==="private"&&e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-300 mb-2",children:["Select Team Members (",H.length," selected)"]}),se?e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx("div",{className:"animate-spin w-5 h-5 border-2 border-brand-primary border-t-transparent rounded-full"})}):p.length===0?e.jsx("div",{className:"p-3 bg-white/5 rounded-lg text-center text-gray-400 text-sm",children:"No other team members found"}):e.jsx("div",{className:"max-h-40 overflow-y-auto space-y-2 p-2 bg-black border border-white/10 rounded-lg",children:p.map(t=>e.jsxs("label",{className:`flex items-center gap-3 p-2 rounded-lg cursor-pointer transition-colors ${H.includes(t.user_id)?"bg-brand-primary/20 border border-brand-primary/50":"hover:bg-white/5 border border-transparent"}`,children:[e.jsx("input",{type:"checkbox",checked:H.includes(t.user_id),onChange:()=>Me(t.user_id),className:"w-4 h-4 rounded border-gray-600 bg-gray-700 text-brand-primary focus:ring-brand-primary"}),e.jsx("div",{className:"w-8 h-8 rounded-full bg-white/10 flex items-center justify-center overflow-hidden flex-shrink-0",children:t.profile_image?e.jsx("img",{src:t.profile_image,alt:`${t.name}'s avatar`,className:"w-full h-full object-cover"}):e.jsx(ye,{className:"w-4 h-4 text-white"})}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("p",{className:"text-white text-sm font-medium truncate",children:t.name})})]},t.user_id))}),e.jsx("p",{className:"text-gray-500 text-xs mt-1",children:"Manage members via the project gallery for more options"})]}),e.jsxs("button",{type:"button",onClick:()=>K(!i),className:"w-full flex items-center justify-between text-sm text-gray-400 hover:text-white py-3 border-t border-white/10 mt-2",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Ue,{className:"w-4 h-4"}),e.jsx("span",{children:"Advanced Settings"})]}),e.jsx("span",{children:i?"▲":"▼"})]}),i&&e.jsxs("div",{className:"space-y-4 p-4 rounded-xl bg-black border border-white/10",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-300 mb-2",children:"Priority"}),e.jsx("div",{className:"grid grid-cols-4 gap-2",children:["low","normal","high","urgent"].map(t=>{const F={low:"bg-blue-400",normal:"bg-green-400",high:"bg-orange-400",urgent:"bg-red-400"};return e.jsxs("button",{type:"button",onClick:()=>X({...y,priority:t}),className:`p-2 rounded-lg border transition-all text-center capitalize flex flex-col items-center justify-center gap-1.5 ${y.priority===t?"border-brand-primary bg-brand-primary/10":"border-white/10 bg-white/5 hover:border-white/20"}`,children:[e.jsx("div",{className:`w-2.5 h-2.5 rounded-full ${F[t]}`}),e.jsx("p",{className:"text-xs font-semibold text-white",children:t})]},t)})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-300 mb-1",children:"Deadline"}),e.jsx("input",{type:"date",value:y.deadline_at,onChange:t=>X({...y,deadline_at:t.target.value}),className:"w-full px-3 py-2 rounded-lg bg-white/5 border border-white/10 text-white focus:border-brand-primary focus:outline-none text-sm transition-colors"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-300 mb-1",children:"Target Media"}),e.jsx("input",{type:"number",value:y.target_media_count,onChange:t=>X({...y,target_media_count:t.target.value}),className:"w-full px-3 py-2 rounded-lg bg-white/5 border border-white/10 text-white focus:border-brand-primary focus:outline-none text-sm transition-colors",placeholder:"e.g., 50",min:"1"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:y.approval_required,onChange:t=>X({...y,approval_required:t.target.checked}),className:"w-4 h-4 rounded border-gray-600 bg-gray-700 text-brand-primary focus:ring-brand-primary"}),e.jsx("span",{className:"text-sm text-gray-300",children:"Require approval for uploads"})]}),y.approval_required&&e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer ml-6",children:[e.jsx("input",{type:"checkbox",checked:y.auto_approve_admins,onChange:t=>X({...y,auto_approve_admins:t.target.checked}),className:"w-4 h-4 rounded border-gray-600 bg-gray-700 text-brand-primary focus:ring-brand-primary"}),e.jsx("span",{className:"text-xs text-gray-400",children:"Auto-approve admin/owner uploads"})]})]})]}),e.jsxs("div",{className:"flex gap-3 pt-4 border-t border-white/10",children:[e.jsx("button",{type:"button",onClick:()=>u(!1),className:"flex-1 px-4 py-2.5 bg-white/5 hover:bg-white/10 border border-white/10 text-gray-300 text-sm font-semibold rounded-lg transition-colors",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:$||!y.name.trim(),className:"flex-1 px-4 py-2.5 bg-gradient-to-r from-brand-primary to-brand-secondary hover:opacity-90 text-black text-sm font-bold rounded-lg disabled:opacity-50 transition-all shadow-lg shadow-brand-primary/20",children:$?"Saving...":"Save Changes"})]})]})]})]}),document.body),j&&e.jsx(Js,{project:j,onClose:()=>M(null)}),B&&e.jsx(Ws,{project:B,onClose:()=>Y(null)}),C&&e.jsx(Hs,{project:C,onClose:()=>P(null),onApprovalComplete:pe}),U&&e.jsx(Ys,{project:U,onClose:()=>V(null),onUpdate:pe}),J&&e.jsx(Ks,{project:J,onClose:()=>I(null)}),e.jsx(ve,{isOpen:!!b,title:"Delete Project?",message:`Are you sure you want to permanently delete "${b==null?void 0:b.name}"? This action cannot be undone.`,confirmText:"Delete",confirmStyle:"danger",isLoading:Q,onConfirm:Ie,onCancel:()=>m(null)}),e.jsx(ve,{isOpen:!!D,title:"Archive Project?",message:`Are you sure you want to archive "${D==null?void 0:D.name}"?`,confirmText:"Archive",confirmStyle:"warning",isLoading:S,onConfirm:je,onCancel:()=>O(null)})]})},Se=r=>typeof r=="number"?r:parseFloat(String(r||0))||0,Zs=r=>"border-white/10 bg-white/5 text-white font-semibold tracking-wider up
143percase",Xs=({onManagingChange:r})=>{Ae(),Ot();const[f,c]=It(),[n,T]=s.useState([]),[v,$]=s.useState(!1),[_,g]=s.useState(null),[o,k]=s.useState(null),[w,N]=s.useState(!1),[u,x]=s.useState(!1),j=!!f.get("manage");s.useEffect(()=>{M()},[]),s.useEffect(()=>{r&&r(j&&o?o:null)},[j,o,r]);const M=async()=>{$(!0);try{const C=await fetch("/api/organizations",{headers:{Authorization:`Bearer ${localStorage.getItem("morphyxToken")}`}});if(!C.ok)throw new Error("Failed to fetch organizations");const P=await C.json();if(T(P),g(null),P.length>0){const U=f.get("manage"),V=U?P.find(J=>String(J.id)===String(U)):null;k(V||P[0])}}catch(C){g(C instanceof Error?C.message:"Error fetching organizations"),T([])}finally{$(!1)}},B=C=>{k(C);const P=new URLSearchParams(f);P.set("manage",String(C.id)),c(P)},Y=()=>{const C=new URLSearchParams(f);C.delete("manage"),c(C)};return j?o?e.jsx(Gs,{orgId:o.id,orgName:o.name,onClose:Y}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 gap-3",children:[e.jsx("div",{className:"w-9 h-9 border-3 border-brand-primary/30 border-t-brand-primary rounded-full animate-spin"}),e.jsx("p",{className:"text-gray-400 text-sm",children:"Loading organization…"})]}):v?e.jsxs("div",{className:"space-y-6 sm:space-y-8 animate-pulse",children:[e.jsx("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 mb-8",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-8 sm:h-10 rounded w-48 sm:w-64 bg-gray-800/60"}),e.jsx("div",{className:"h-4 rounded w-32 sm:w-48 bg-gray-800/40"})]})}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 sm:gap-6",children:[1,2,3].map(C=>e.jsx("div",{className:"h-48 rounded-xl border border-gray-700/50 bg-gray-800/30"},C))})]}):n.length===0?e.jsx("div",{className:"space-y-6 sm:space-y-8",children:e.jsxs("div",{className:"p-8 sm:p-12 rounded-xl border border-gray-700/50 bg-gray-800/40 text-center",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl bg-brand-primary/10 border border-brand-primary/30 flex items-center justify-center mx-auto mb-4",children:e.jsx(gt,{className:"w-7 h-7 text-brand-primary"})}),e.jsx("h3",{className:"text-xl font-bold text-white mb-2",children:"No Organizations Found"}),e.jsx("p",{className:"text-gray-400 max-w-md mx-auto text-sm",children:"You are not currently a member of any organization. Ask an administrator to invite you to their team."})]})}):e.jsxs("div",{className:"space-y-6 sm:space-y-8",children:[e.jsxs("div",{children:[e.jsx("div",{className:"flex flex-col gap-4 mb-6 sm:mb-8",children:n.length>0&&e.jsxs("div",{className:"p-3 sm:p-4 rounded-xl border border-gray-800/60 bg-black",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(ls,{className:"w-4 h-4 text-brand-primary"}),e.jsx("span",{className:"text-xs sm:text-base font-bold text-white",children:"Active Billing Source"})]}),e.jsx(ns,{plainBorder:!0})]})}),e.jsx("div",{className:"mb-6 sm:mb-8",children:e.jsx("div",{className:"flex gap-3 sm:gap-4 overflow-x-auto pb-4 -mx-4 px-4 sm:mx-0 sm:px-0 sm:grid sm:grid-cols-2 lg:grid-cols-3 sm:overflow-visible scrollbar-hide",children:n.map(C=>{const P=Se(C.total_credits),U=Se(C.total_spent),V=P>0?U/P*100:0,J=(o==null?void 0:o.id)===C.id,I=e.jsxs("div",{onClick:()=>k(C),className:`w-full h-full p-4 sm:p-5 rounded-[10px] cursor-pointer transition-all duration-200 flex flex-col justify-between ${J?"bg-black":"bg-black/40 hover:bg-black/60"}`,children:[e.jsx("div",{className:"flex items-start justify-between mb-3 gap-2",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h3",{className:`font-bold text-base sm:text-lg truncate transition-colors ${J?"text-white":"text-gray-200 group-hover:text-white"}`,children:C.name}),e.jsx("div",{className:"flex gap-2.5 mt-2 flex-wrap",children:e.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded border text-[9px] sm:text-[10px] ${Zs(C.role)}`,children:C.role})})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex justify-between items-end",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] sm:text-xs font-semibold uppercase tracking-wide text-gray-500",children:"Available"}),e.jsx("p",{className:"text-xl sm:text-2xl font-black text-white tracking-tight",children:P.toFixed(0)})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-[10px] sm:text-xs font-semibold uppercase tracking-wide text-gray-500",children:"Used"}),e.jsx("p",{className:"text-base sm:text-lg font-bold text-gray-300",children:U.toFixed(0)})]})]}),e.jsx("div",{className:"h-1.5 sm:h-2 rounded-full overflow-hidden bg-gray-800/60",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-500 bg-brand-primary",style:{width:`${Math.min(V,100)}%`}})})]})]});return e.jsx("div",{className:`group relative flex-shrink-0 w-[280px] sm:w-auto transition-all duration-200 rounded-xl ${J?"p-[1.5px] animated-gradient-border shadow-[0_0_15px_rgba(163,230,53,0.35)] shrink-0":"p-[1.5px] bg-transparent border border-gray-800/60 hover:border-white/10"}`,children:e.jsx("div",{className:"w-full h-full rounded-[10px] overflow-hidden bg-black/40",children:I})},C.id)})})}),o&&e.jsxs("div",{className:"rounded-xl sm:rounded-2xl p-4 sm:p-6 lg:p-8 space-y-5 sm:space-y-6 shadow-lg border border-gray-800/60 bg-[#050505] backdrop-blur-sm",children:[e.jsxs("div",{className:"space-y-3 pb-4 sm:pb-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex items-center justify-center flex-shrink-0",children:e.jsx(gt,{className:"w-6 h-6 sm:w-8 sm:h-8 text-white"})}),e.jsx("h3",{className:"text-lg sm:text-xl lg:text-2xl font-black text-white tracking-tight truncate",children:o.name})]}),o.email&&e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-[10px] sm:text-xs w-fit border border-white/10 bg-white/5 text-white font-semibold",children:[e.jsx(Te,{className:"w-3 h-3 shrink-0 text-white/70"}),e.jsx("span",{className:"truncate max-w-[150px] sm:max-w-none",children:o.email})]})]}),o.description&&e.jsx("p",{className:"text-xs sm:text-sm leading-relaxed text-gray-400",children:o.description})]}),e.jsx("div",{className:"grid grid-cols-3 gap-2 sm:gap-4 lg:gap-6",children:(()=>{const C=Se(o.total_credits),P=Se(o.total_spent),U=C>0?P/C*100:0;return[{label:"Credits",value:C.toFixed(0)},{label:"Used",value:P.toFixed(0)},{label:"Usage",value:U.toFixed(0)+"%"}]})().map((C,P)=>e.jsxs("div",{className:"p-3 sm:p-4 lg:p-5 rounded-lg sm:rounded-xl border border-gray-800/60 bg-black/40 text-center sm:text-left hover:border-brand-primary/30 transition-colors",children:[e.jsx("p",{className:"text-[9px] sm:text-[10px] lg:text-xs font-bold mb-1 uppercase tracking-wider text-gray-500",children:C.label}),e.jsx("p",{className:"text-lg sm:text-xl lg:text-3xl font-black text-white",children:C.value})]},P))}),e.jsxs("div",{className:"flex flex-wrap gap-4 sm:gap-6",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs sm:text-sm text-gray-400",children:[e.jsx("span",{className:"font-semibold text-gray-500",children:"Role:"}),e.jsx("span",{className:"text-white font-medium capitalize",children:o.role})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-xs sm:text-sm text-gray-400",children:[e.jsx("span",{className:"font-semibold text-gray-500",children:"Access:"}),e.jsx("span",{className:"text-white font-medium capitalize",children:o.access_level})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-xs sm:text-sm text-gray-400",children:[e.jsx("span",{className:"font-semibold text-gray-500",children:"Team:"}),e.jsxs("span",{className:"text-white font-medium flex items-center gap-1",children:[e.jsx(ue,{className:"w-3.5 h-3.5"})," ",o.member_count]})]})]}),e.jsx("div",{className:"space-y-2 pt-2",children:(()=>{const C=Se(o.total_credits),P=Se(o.total_spent),U=C>0?P/C*100:0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs sm:text-sm font-bold text-gray-300",children:"Credit Usage"}),e.jsxs("span",{className:"text-xs font-bold px-2 py-1 rounded-full bg-white/5 border border-white/10 text-gray-300",children:[U.toFixed(1),"%"]})]}),e.jsx("div",{className:"h-2 sm:h-3 rounded-full overflow-hidden bg-gray-800/80",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-700 bg-brand-primary",style:{width:`${Math.min(U,100)}%`}})})]})})()}),(o.role==="owner"||o.role==="admin")&&e.jsx("div",{className:"flex overflow-x-auto pb-1 -mx-1 px-1 justify-start sm:justify-end",children:e.jsx("div",{className:"relative p-[1.5px] rounded-full animated-gradient-border shadow-[0_0_15px_rgba(163,230,53,0.35)] shrink-0",children:e.jsxs("div",{className:"flex items-center gap-0.5 sm:gap-1 p-1 bg-black rounded-full",children:[e.jsx("button",{onClick:()=>
143N(!0),className:"relative px-4 sm:px-6 py-1.5 sm:py-2 rounded-full text-xs sm:text-sm font-semibold transition-all duration-300 flex flex-row items-center gap-1.5 text-gray-400 hover:text-white hover:bg-white/5",children:"Add Credits"}),e.jsx("button",{onClick:()=>B(o),className:"relative px-4 sm:px-6 py-1.5 sm:py-2 rounded-full text-xs sm:text-sm font-semibold transition-all duration-300 flex flex-row items-center gap-1.5 text-gray-400 hover:text-white hover:bg-white/5",children:"Manage"}),e.jsx("button",{onClick:()=>x(!0),className:"relative px-4 sm:px-6 py-1.5 sm:py-2 rounded-full text-xs sm:text-sm font-semibold transition-all duration-300 flex flex-row items-center gap-1.5 text-gray-400 hover:text-white hover:bg-white/5",children:"Analytics"})]})})})]}),o&&e.jsx("div",{className:"relative mt-6 sm:mt-8 rounded-xl sm:rounded-2xl p-4 sm:p-6 lg:p-8 shadow-lg border border-white/10 bg-black/40 backdrop-blur-sm overflow-hidden",children:e.jsx(Qs,{orgId:o.id})}),_&&e.jsx("div",{className:"mt-4 p-4 rounded-lg border border-red-500/20 bg-red-500/5",children:e.jsx("p",{className:"text-sm text-red-400",children:_})})]}),o&&w&&typeof document<"u"&&fe.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-2 sm:p-4 animate-in fade-in duration-200",children:[e.jsx("div",{className:"absolute inset-0 bg-black/90 backdrop-blur-2xl",onClick:()=>N(!1)}),e.jsx("div",{className:"relative w-full max-w-xl max-h-[95vh] sm:max-h-[90vh] rounded-xl sm:rounded-2xl border border-white/10 overflow-hidden flex flex-col bg-black/60 backdrop-blur-xl shadow-2xl animate-in zoom-in-95 duration-300 z-10",children:e.jsx($s,{isOpen:w,onClose:()=>N(!1),orgId:o.id,onSuccess:()=>{N(!1),M()}})})]}),document.body),o&&u&&typeof document<"u"&&fe.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-2 sm:p-4 animate-in fade-in duration-200",children:[e.jsx("div",{className:"absolute inset-0 bg-black/90 backdrop-blur-2xl",onClick:()=>x(!1)}),e.jsxs("div",{className:"relative w-full max-w-5xl h-[95vh] sm:h-[90vh] rounded-xl sm:rounded-2xl border border-white/10 overflow-hidden flex flex-col bg-black/60 backdrop-blur-xl shadow-2xl animate-in zoom-in-95 duration-300 z-10",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 sm:px-6 py-3 sm:py-4 border-b border-white/10 flex-shrink-0 bg-black/40 backdrop-blur-md",children:[e.jsxs("h3",{className:"text-base sm:text-lg font-black text-white flex items-center gap-2",children:[e.jsx(it,{className:"w-5 h-5 text-brand-primary"})," Analytics"]}),e.jsx("button",{onClick:()=>x(!1),className:"p-1.5 text-gray-400 hover:text-white hover:bg-gray-700/50 rounded-lg transition-all",children:e.jsx(he,{className:"w-5 h-5"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6",children:e.jsx(Yt,{orgId:o.id,orgName:o.name,onClose:()=>x(!1)})})]})]}),document.body)]})},qa=()=>{const{user:r}=Ae(),[f,c]=s.useState(null);return r?e.jsxs("div",{className:"min-h-screen relative overflow-x-hidden bg-cover bg-center bg-no-repeat bg-fixed bg-[url('/img/MORPHYX%20BG%20DASHBOARD-9-16.jpg.jpeg')] sm:bg-[url('/img/MORPHYX%20BG%20DASHBOARD-16-9.jpg.jpeg')]",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50 pointer-events-none z-0"}),e.jsx("div",{className:"pt-20 pb-12 relative z-10",children:e.jsxs("div",{className:"container mx-auto px-4 py-8 sm:py-12 relative",children:[!f&&e.jsxs(e.Fragment,{children:[e.jsxs("nav",{className:"flex items-center gap-2 text-sm mb-6 text-gray-400 font-medium",children:[e.jsx(Rt,{to:"/dashboard",className:"hover:text-white transition-colors",children:"Dashboard"}),e.jsx(os,{className:"w-4 h-4 text-gray-500"}),e.jsx("span",{className:"text-white font-semibold",children:"Organization HQ"})]}),e.jsx("header",{className:"mb-8 opacity-0 animate-slide-in-left",children:e.jsx("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-1 h-8 rounded-full shrink-0",style:{background:"linear-gradient(180deg, #b9ff00 0%, #6F00FF 100%)"}}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-black",style:{background:"linear-gradient(90deg, #fff 0%, #9ca3af 100%)",WebkitBackgroun
143dClip:"text",WebkitTextFillColor:"transparent"},children:"Organization HQ"}),e.jsx("p",{className:"text-gray-400 mt-0.5 text-sm",children:"Manage your teams, projects, and shared credits"})]})]})})})]}),e.jsx(Xs,{onManagingChange:c})]})})]}):null};export{qa 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.