1import{r as c,j as t}from"./react-query-B4i0_DlC.js";import{m as ne,c as We}from"./workspace-list-order-BKBTaa66.js";import{u as de}from"./useProjectLifecycleActions-Phz_nLsj.js";import{c as Oe,u as Fe,d as Re,a as Be,e as He,f as Ye,h as Ge,i as Qe,j as Ke,k as Ve,C as Je,l as g,m as ce,n as Xe,o as le}from"./app-sidebar-C3_0V-CV.js";import{u as Ze,l as qe,ak as Y,al as G,B as f,am as Q,an as m,ao as et,ap as tt,aq as rt,ar as K,e as V,k as st,as as at,at as ot,au as N}from"./index-C8rJ6Qwf.js";import{R as me}from"./routable-card-link-DmaUAAFa.js";import{S as A}from"./skeleton-B6QldpBk.js";import{p as he}from"./app-routes-Dnnjxu9O.js";import{M as it}from"./MainAppShell-CDsb8UTJ.js";import{A as nt}from"./AppInsetHeader-Bz6Bqd8I.js";import{W as dt}from"./workspace-page-header-Llh23rVu.js";import{u as ct}from"./useGroupChats-DHVQdfce.js";import{N as lt}from"./firebase-core-BLTXy0Gd.js";import{T as mt,a as ht,b as pt,c as ut}from"./texture-card-52Ulf0I8.js";import{S as jt,C as pe,a as xt,F as ft,P as ue,E as je,b as xe,c as vt,d as gt,A as J,e as T,f as Nt}from"./icons-BBbjOIlu.js";import"./radix-ui-DdHDrzfD.js";import"./utils-BcRwgjx2.js";import"./separator-B6vMQivu.js";import"./MarketingHeaderLockup-TKJzu8k9.js";import"./restore-body-pointer-events-VhhmqVRV.js";import"./firebase-storage-Dvs5WDrb.js";import"./framer-motion-DW1bmm4j.js";import"./last-account-0uJGFLwW.js";import"./react-Bo6yiPQy.js";import"./markdown-renderer-B8tDz8IO.js";import"./md-react-Br4KiRmz.js";import"./firebase-firestore-CgPjk0t4.js";import"./firebase-database-ClaLrFE5.js";import"./familyInvite-BXnkwJ1L.js";import"./accordion-Co2IO0pp.js";import"./UsageQuotaBlock--ouSVDSy.js";import"./storage-sync-display-Dmv92fSw.js";import"./collapsible-Dt1fFzXK.js";function er(){const[,h]=Ze(),{user:r,firebaseUser:L,isAuthenticated:fe,isLoading:ve}=qe(),{data:l=[],isLoading:I,isError:X,isFetching:Z,refetch:ge}=Oe(r==null?void 0:r.id,{includeArchived:!0}),w=c.useMemo(()=>l.filter(e=>!e.archived),[l]),M=c.useMemo(()=>l.filter(e=>e.archived).sort((e,s)=>s.lastUpdated.getTime()-e.lastUpdated.getTime()),[l]),{data:Ne}=Fe(),{groupChats:D}=ct((r==null?void 0:r.id)||null),{data:U=[]}=Re(r==null?void 0:r.id),we=Be(),be=He(),Pe=Ye(),Ie=Ge(),[n,$]=c.useState(null),[b,q]=c.useState(""),[y,ye]=c.useState("updated"),[E,Ce]=c.useState(null),[v,x]=c.useState(null),z=Qe((L==null?void 0:L.uid)??(r==null?void 0:r.id)),p=z.ids,[_,Se]=c.useState(!1),[u,W]=c.useState(null),[j,O]=c.useState(null),C=de(r==null?void 0:r.id,u==null?void 0:u.projectId),S=de(r==null?void 0:r.id,j==null?void 0:j.projectId),ee=C.pending==="delete",te=S.pending==="leave",re={created:"Date created",updated:"Date updated",name:"Name"},se=c.useMemo(()=>{let e=w;return e=e.filter(s=>ne(b,s.title,s.description)),[...e].sort((s,a)=>{const o=p.has(s.projectId),d=p.has(a.projectId);return o!==d?d?1:-1:We({...s,updatedAt:s.lastUpdated},{...a,updatedAt:a.lastUpdated},y)})},[w,b,y,p]),k=M.filter(e=>ne(b,e.title,e.description)),F=(Ne||[]).map(e=>({id:e.id,title:e.title||"Untitled Chat",starred:e.starred||!1,projectId:e.projectId||null,updatedAt:e.updatedAt})),ke=w.map(e=>({projectId:e.projectId,title:e.title,ownerId:e.ownerId,pinned:p.has(e.projectId),archived:e.archived})),Ae=c.useMemo(()=>Ke({notes:U,notesWithMetadata:U,projects:l.map(e=>({projectId:e.projectId,pinned:p.has(e.projectId),archived:e.archived})),chats:F,groupChats:D}),[U,l,p,F,D]),{tryPin:Te,pinLimitModal:Le}=Ve(Ae),R=()=>{h("/projects/new")},Me=async()=>{try{await lt(st),h("/chat")}catch(e){console.error("Error signing out:",e)}},B=e=>{var o;const s=l.find(d=>d.projectId===e),a=((o=s==null?void 0:s.title)==null?void 0:o.trim())||"this project";C.clearError(),W({projectId:e,title:a})},De=async()=>{const e=u;await C.remove()&&W(s=>s===e?null:s)},H=e=>{var o;const s=l.find(d=>d.projectId===e),a=((o=s==null?void 0:s.title)==null?void 0:o.trim())||"this project";S.clearError(),O({projectId:e,title:a})},Ue=async()=>{const e=j;await S.leave()&&O(s=>s===e?null:s)},$e=e=>{const s=l.find(a=>a.projectId===e);if(K(s??{ownerId:void 0},r==null?void 0:r.id)){B(e);return}H(e)},ae=async e=>{try{const s=await at(e),a=(r==null?void 0:r.displayName)||[r==null?void 0:r.firstName,r==null?void 0:r.lastName].filter(
1Boolean).join(" ").trim(),o=ot({projectId:e,inviteToken:s,inviterName:a});if(!o){N({title:"Invite link disabled",description:"Create a new invite link from the project page.",variant:"destructive"});return}await navigator.clipboard.writeText(o),N({description:"Project link copied to clipboard"})}catch(s){console.error("Failed to copy project link:",s),N({title:"Could not copy link",description:"Copy the address from the browser bar or try again.",variant:"destructive"})}},Ee=async(e,s)=>{if(!r||!n)return!1;try{await be.mutateAsync({userId:r.id,projectId:n.projectId,updates:{title:e,description:s}})}catch(a){return console.error("Failed to rename project:",a),N({title:"Could not rename project",description:"Please try again.",variant:"destructive"}),!1}},oe=async e=>{if(r)try{await Pe.mutateAsync({userId:r.id,projectId:e})}catch(s){console.error("Failed to archive project:",s),N({title:"Could not archive project",description:navigator.onLine===!1?"Youâre offline. Reconnect, then try again.":"Please try again.",variant:"destructive"})}},ze=async e=>{if(r)try{await Ie.mutateAsync({userId:r.id,projectId:e})}catch(s){console.error("Failed to unarchive project:",s),N({title:"Could not restore project",description:navigator.onLine===!1?"Youâre offline. Reconnect, then try again.":"Please try again.",variant:"destructive"})}},_e=e=>{const s=p.has(e);Te({isPinning:!s,itemAlreadyPinned:s},()=>{z.setPin(e)})},ie=e=>e.toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"});return ve?t.jsx("div",{className:"h-screen flex items-center justify-center bg-background",children:t.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-2 border-gray-300 border-t-gray-900 dark:border-white/15 dark:border-t-white/80"})}):fe?t.jsxs(t.Fragment,{children:[t.jsx(Je,{isOpen:!!n,scopeKey:`${r==null?void 0:r.id}:${n==null?void 0:n.projectId}`,mode:"edit",initialName:(n==null?void 0:n.title)||"",initialDescription:(n==null?void 0:n.description)||"",onClose:()=>$(null),onSubmit:Ee}),t.jsxs(it,{insetClassName:"h-screen",chats:F,groupChats:D,projects:ke,user:r?{name:r.displayName||r.firstName||"User",email:r.email||"",avatar:""}:null,selectedPlan:r==null?void 0:r.selectedPlan,onNewChat:()=>h("/chat"),onChatSelect:e=>h(`/chat/${e}`),onGroupChatSelect:e=>h(`/group-chat/${e}`),onGroupChatRename:e=>h(`/group-chat/${e}?rename=true`),onProjects:()=>h("/projects"),onNewProject:()=>h("/projects/new"),onProjectPin:z.setPin,onProjectShare:e=>void ae(e),onProjectRename:e=>{const s=w.find(a=>a.projectId===e);s&&$(s)},onProjectArchive:e=>void oe(e),onProjectDelete:e=>void $e(e),onLogout:Me,onChatStar:we,children:[t.jsx(nt,{title:"Projects",className:"md:hidden"}),t.jsxs(dt,{title:"Projects",actionLabel:"New Project",onAction:R,titleTestId:"text-projects-title",actionTestId:"button-new-project",hideHeaderOnMobile:!0,children:[!I&&l.length>0&&t.jsxs("div",{className:"relative mb-3",children:[t.jsx(jt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),t.jsx("input",{type:"text",placeholder:"Search projects...",value:b,onChange:e=>q(e.target.value),className:"w-full h-11 rounded-xl border border-border/70 bg-card pl-9 pr-3 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2","data-testid":"input-search-projects"})]}),!I&&w.length>0&&t.jsx("div",{className:"mb-5 flex items-center justify-end",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-sm text-muted-foreground",children:"Sort by"}),t.jsxs(Y,{children:[t.jsx(G,{asChild:!0,children:t.jsxs(f,{variant:"ghost",size:"sm",className:"h-8 gap-1.5 rounded-full bg-muted px-3 text-sm font-medium text-foreground hover:bg-muted/80",children:[re[y],t.jsx(pe,{className:"h-4 w-4 text-muted-foreground"})]})}),t.jsx(Q,{align:"end",children:["created","updated","name"].map(e=>t.jsxs(m,{onSelect:()=>ye(e),className:"flex items-center justify-between gap-6 pl-2 pr-2",children:[t.jsx("span",{children:re[e]}),y===e?t.jsx(xt,{className:"h-4 w-4 text-foreground"}):t.jsx("span",{className:"h-4 w-4","aria-hidden":!0})]},e))})]})]})}),X&&t.jsxs("div",{role:"alert",className:"mb-4 flex flex-wrap items-center justify-between gap-3 text-sm text-muted-foreground",children:[t.jsx("p",{children:"Could not load your projects. Try again to view your saved projects."}),t.jsx(f,{variant:"settings-outline",size:"sm",disabled:Z,onClick:()=>void ge(),children:Z?"Retryingâ¦":"Retry projects"})]}),I?t.jsx("div",{className:"w-full grid grid-cols-2 md:grid-cols-3 gap-4",children:[1,2,3].map(e=>t.jsxs("div",{className:"flex flex-col p-4 min-h-[160px] rounded-xl bg-card border border-border/60 shadow-[0_1px_3px_rgba(0,0,0,0.04)]",children:[t.jsx("div",{className:"flex items-center gap-3 mb-2",children:t.jsx(A,{className:"h-5 w-40"})}),t.jsxs("div",{className:"space-y-1.5",children:[t.jsx(A,{className:"h-3.5 w-full"}),t.jsx(A,{className:"h-3.5 w-2/3"})]}),t.jsx("div",{className:"mt-auto pt-4",children:t.jsx(A,{className:"h-3 w-24"})})]},e))}):se.length===0?X?null:b.trim()?t.jsxs("div",{className:"py-8 text-center text-sm text-muted-foreground",children:[t.jsx("p",{children:k.length>0?"Matching projects are archived. Open Archived below to view or restore them.":"No projects match your search."}),t.jsx(f,{variant:"ghost",size:"sm",onClick:()=>q(""),children:"Clear search"})]}):t.jsxs(mt,{className:"w-full border-0 shadow-none md:border md:shadow-sm",children:[t.jsxs(ht,{className:"flex flex-col gap-4 justify-center items-center pt-8",children:[t.jsx("div",{className:"p-4 bg-muted rounded-full",children:t.jsx(ft,{className:"h-6 w-6 text-muted-foreground"})}),t.jsx("h3",{className:"text-xl font-semibold text-foreground",children:M.length>0?"Your projects are archived":"No projects yet"}
1),t.jsx("p",{className:"text-sm text-muted-foreground/50 text-balance text-center max-w-xs",children:M.length>0?"Open Archived below to view or restore your projects, or create a new project.":"Get started by creating your first project to organize your AI conversations and files."})]}),t.jsx(pt,{className:"hidden md:block"}),t.jsx(ut,{className:"hidden md:flex flex-col items-center justify-center py-6",children:t.jsxs(f,{onClick:R,size:"sm",className:"h-9 gap-1.5 rounded-full px-5 text-[13px] font-medium","data-testid":"button-create-first-project",children:[t.jsx(ue,{className:"h-3.5 w-3.5"}),"New Project"]})})]}):t.jsx("div",{className:"w-full grid grid-cols-2 md:grid-cols-3 gap-4",children:se.map((e,s)=>{var a,o,d,P;return t.jsxs("div",{className:"group relative flex flex-col p-4 min-h-[160px] rounded-xl bg-card border border-border/60 shadow-[0_1px_3px_rgba(0,0,0,0.04)] text-left transition-all duration-200 hover:shadow-md hover:border-border hover:bg-accent/30 active:translate-y-0 animate-fade-in",style:{animationDelay:`${s*60}ms`,animationFillMode:"backwards"},"data-testid":`project-card-${e.projectId}`,children:[t.jsx(me,{href:he(e.projectId),ariaLabel:((a=e.title)==null?void 0:a.trim())||"Untitled project"}),t.jsxs(Y,{modal:!1,open:E===e.projectId,onOpenChange:i=>{Ce(i?e.projectId:null),(i||v===e.projectId)&&x(null)},children:[t.jsxs(et,{open:v===e.projectId&&E!==e.projectId,onOpenChange:i=>{!i&&v===e.projectId&&x(null)},children:[t.jsx(tt,{asChild:!0,children:t.jsx(G,{asChild:!0,children:t.jsxs(f,{variant:"ghost",size:"icon",className:"absolute top-2 right-2 z-20 h-7 w-7 shrink-0 sm:opacity-0 sm:group-hover:opacity-100 transition-opacity",onPointerEnter:()=>{E!==e.projectId&&x(e.projectId)},onPointerLeave:()=>{v===e.projectId&&x(null)},onBlur:()=>{v===e.projectId&&x(null)},onPointerDown:()=>{v===e.projectId&&x(null)},onClick:i=>{i.stopPropagation(),x(null)},"data-testid":`project-menu-${e.projectId}`,children:[t.jsx(je,{className:"h-4 w-4"}),t.jsx("span",{className:"sr-only",children:"More options"})]})})}),t.jsx(rt,{side:"bottom",align:"center",children:"More options"})]}),t.jsxs(Q,{align:"end",className:V(Xe,"z-50"),onClick:i=>i.stopPropagation(),children:[t.jsxs(m,{className:g,onSelect:i=>{i.stopPropagation(),_e(e.projectId)},"data-testid":`project-pin-toggle-${e.projectId}`,children:[t.jsx(xe,{className:"shrink-0",strokeWidth:1.5}),p.has(e.projectId)?"Unpin project":"Pin project"]}),t.jsxs(m,{className:g,onSelect:()=>void ae(e.projectId),"data-testid":`project-share-${e.projectId}`,children:[t.jsx(vt,{className:"shrink-0",strokeWidth:1.5}),"Share"]}),t.jsxs(m,{className:g,onSelect:()=>$(e),"data-testid":`project-rename-${e.projectId}`,children:[t.jsx(gt,{className:"shrink-0",strokeWidth:1.5}),"Rename project"]}),t.jsxs(m,{className:g,onSelect:()=>void oe(e.projectId),"data-testid":`project-archive-${e.projectId}`,children:[t.jsx(J,{className:"shrink-0",strokeWidth:1.5}),"Archive project"]}),K(e,r==null?void 0:r.id)?t.jsxs(m,{onSelect:()=>void B(e.projectId),className:V(g,ce),"data-testid":`project-delete-${e.projectId}`,children:[t.jsx(T,{className:"shrink-0 text-destructive",strokeWidth:1.5}),"Delete project"]}):t.jsxs(m,{onSelect:()=>void H(e.projectId),className:V(g,ce),"data-testid":`project-leave-${e.projectId}`,children:[t.jsx(T,{className:"shrink-0 text-destructive",strokeWidth:1.5}),"Leave project"]})]})]}),t.jsxs("div",{className:"relative z-10 pointer-events-none flex items-center gap-1.5 pr-8",children:[p.has(e.projectId)?t.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center text-muted-foreground","data-testid":`project-pin-${e.projectId}`,"aria-label":"Pinned project",children:t.jsx(xe,{className:"h-3.5 w-3.5",strokeWidth:1.75})}):null,t.jsx("h3",{className:`min-w-0 truncate text-sm font-medium ${(o=e.title)!=null&&o.trim()?"":"text-muted-foreground/40"}`,children:((d=e.title)==null?void 0:d.trim())||"Untitled project"})]}),t.jsx("p",{className:"relative z-10 pointer-events-none text-xs text-muted-foreground line-clamp-3 break-words mt-1.5",children:((P=e.description)==null?void 0:P.trim())||""}),t.jsx("p",{className:"relative z-10 pointer-events-none text-[11px] text-muted-foreground
1/50 mt-auto",children:ie(e.lastUpdated)})]},e.projectId)})}),!I&&k.length>0&&t.jsxs("div",{className:"mt-8",children:[t.jsxs("button",{type:"button",onClick:()=>Se(e=>!e),className:"flex w-full items-center gap-2 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors","aria-expanded":_,"data-testid":"button-toggle-archived-projects",children:[_?t.jsx(pe,{className:"h-4 w-4",strokeWidth:1.5}):t.jsx(Nt,{className:"h-4 w-4",strokeWidth:1.5}),t.jsx("span",{children:"Archived"}),t.jsx("span",{className:"inline-flex h-5 min-w-5 items-center justify-center rounded-md bg-muted px-1.5 text-[11px] font-medium leading-none tabular-nums text-muted-foreground",children:k.length})]}),_&&t.jsx("div",{className:"mt-3 w-full grid grid-cols-2 md:grid-cols-3 gap-4",children:k.map((e,s)=>{var a,o,d,P;return t.jsxs("div",{className:"group relative flex flex-col p-4 min-h-[160px] rounded-xl bg-muted/30 border border-border/40 text-left opacity-75 transition-all duration-200 hover:opacity-100 hover:shadow-md hover:border-border hover:bg-accent/30 animate-fade-in",style:{animationDelay:`${s*60}ms`,animationFillMode:"backwards"},"data-testid":`archived-project-card-${e.projectId}`,children:[t.jsx(me,{href:he(e.projectId),ariaLabel:((a=e.title)==null?void 0:a.trim())||"Untitled project"}),t.jsxs(Y,{modal:!1,children:[t.jsx(G,{asChild:!0,children:t.jsxs(f,{variant:"ghost",size:"icon",className:"absolute top-2 right-2 z-20 h-7 w-7 shrink-0 sm:opacity-0 sm:group-hover:opacity-100 transition-opacity",onClick:i=>i.stopPropagation(),"data-testid":`archived-project-menu-${e.projectId}`,children:[t.jsx(je,{className:"h-4 w-4"}),t.jsx("span",{className:"sr-only",children:"More options"})]})}),t.jsxs(Q,{align:"end",onClick:i=>i.stopPropagation(),children:[t.jsxs(m,{onSelect:()=>void ze(e.projectId),"data-testid":`archived-project-unarchive-${e.projectId}`,children:[t.jsx(J,{className:"h-4 w-4 mr-2"}),"Unarchive"]}),K(e,r==null?void 0:r.id)?t.jsxs(m,{className:"text-destructive focus:text-destructive",onSelect:()=>void B(e.projectId),"data-testid":`archived-project-delete-${e.projectId}`,children:[t.jsx(T,{className:"h-4 w-4 mr-2 text-destructive"}),"Delete"]}):t.jsxs(m,{className:"text-destructive focus:text-destructive",onSelect:()=>void H(e.projectId),"data-testid":`archived-project-leave-${e.projectId}`,children:[t.jsx(T,{className:"h-4 w-4 mr-2 text-destructive"}),"Leave"]})]})]}),t.jsxs("div",{className:"relative z-10 pointer-events-none flex items-center gap-1.5 pr-8",children:[t.jsx(J,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground",strokeWidth:1.5,"aria-label":"Archived"}),t.jsx("h3",{className:`min-w-0 truncate text-sm font-medium ${(o=e.title)!=null&&o.trim()?"":"text-muted-foreground/40"}`,children:((d=e.title)==null?void 0:d.trim())||"Untitled project"})]}),t.jsx("p",{className:"relative z-10 pointer-events-none text-xs text-muted-foreground line-clamp-3 break-words mt-1.5",children:((P=e.description)==null?void 0:P.trim())||""}),t.jsx("p",{className:"relative z-10 pointer-events-none text-[11px] text-muted-foreground/50 mt-auto",children:ie(e.archivedAt??e.lastUpdated)})]},e.projectId)})})]})]}),t.jsx("div",{className:"fixed bottom-6 left-1/2 z-30 flex -translate-x-1/2 items-center gap-3 md:hidden",children:t.jsxs(f,{onClick:R,size:"sm",className:"h-9 gap-1.5 rounded-full px-5 text-[13px] font-medium shadow-lg","data-testid":"button-new-project-mobile",children:[t.jsx(ue,{className:"h-3.5 w-3.5"}),"New Project"]})})]}),t.jsx(le,{open:!!u,onOpenChange:e=>{!e&&!ee&&W(null)},title:"Delete project?",itemName:u==null?void 0:u.title,description:"This will delete {name}. You'll no longer see the project history, and this action cannot be undone.",onConfirm:De,isConfirming:ee,error:C.error,testId:"dialog-delete-project"}),t.jsx(le,{open:!!j,onOpenChange:e=>{!e&&!te&&O(null)},title:"Leave project?",itemName:j==null?void 0:j.title,description:"You'll leave {name}. You can rejoin later with an invite link.",confirmLabel:"Leave",onConfirm:Ue,isConfirming:te,error:S.error,testId:"dialog-leave-project"}),Le]}):(h("/login"),null)}export{er 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.