1import{j as e,r as o,b as ki,c as Xa}from"./vendor-react-7kK5Bxv7.js";import{n as A,aU as An,k as On,W as gt,R as Lt,ab as Bn,t as P,ae as Ja,g as at,au as xe,a8 as Mt,c as be,$ as Si,dx as Ua,T as oe,ah as Jr,p as bt,bK as Ci,f as _i,bc as Ve,an as Un,C as cn,a1 as it,i as Di,A as ft,aV as Qa,a4 as De,a0 as Fe,dd as es,E as Qr,ak as ye,a3 as ts,z as lt,ai as he,bb as ea,am as ta,u as ra,J as lr,aZ as qa,bn as Fi,ba as qn,a6 as Wn,be as Wa,a$ as Kn,K as Vr,aP as zi,d3 as $i,a as Ei,d as Li,U as Et,V as Ka,Y as Mi,Z as Ri,dy as Hr,c6 as dn,af as Ti,at as rs,as,o as ss,c0 as Pi}from"./realtime-mux-D9UASGOE.js";import{u as ct,e as Rt,b9 as aa,J as de,g6 as Ii,B as G,I as st,y as Se,z as Ce,F as _e,G as z,aF as Vn,D as ze,r as $e,t as Ee,v as Le,w as Re,bv as sa,x as He,g7 as Ai,aP as Oi,L as pt,a5 as Me,cc as Bi,o as Hn,dj as Ui,C as Ke,aQ as qi,T as Gn,ah as un,H as ie,a6 as ns,cv as Yn,bn as Wi,bo as mn,bu as Ki,cw as na,g8 as je,b as ir,g9 as Vi,b5 as Hi,_ as Gi,ga as Yi,n as Fa,p as Zi,el as Xi,ez as Ji,gb as Qi,gc as za,$ as el,cC as tl,E as Zn,S as xn}from"./index-CY_U-MX5.js";import{u as os}from"./useIsTouch-BRK2o5i0.js";import{u as is}from"./useLongPress-BcUKze09.js";import{u as rl}from"./useGlobalNewShortcut-ijAYZlxm.js";import{u as al}from"./useCoarsePointer-C3km7-d8.js";import{P as sl}from"./PullToRefresh-Drf94SsU.js";import{u as nl,Z as ol,a as il}from"./useZoomPan-Cdw7pkyo.js";import{B as ls}from"./Breadcrumbs-DsHUJt8e.js";import{I as oa}from"./InlineRename-CDAm23Lb.js";import{M as Xn}from"./ModuleColorChip-D0XN56w9.js";import{h as Jn}from"./option-colors-jUdPirh-.js";import{T as ll}from"./TypedConfirmDialog-DrDCWZab.js";import{g as nt}from"./driveFileIcon-KPBAZHUw.js";import{u as V,a as Qn,b as cl,d as $a,c as Ea,p as dl,i as ul,g as ml}from"./driveStore-C4pYjnKE.js";import{v as cr,m as xl,b as cs,c as hl,a as vl,o as pl}from"./fileKind-B45DSKk8.js";import{c as La}from"./camera-BK_01vqn.js";import{S as fl}from"./ShareDialog-Bv_zWSIU.js";import{u as gl}from"./upload-fm3Txge8.js";import{D as bl}from"./DetailPanelHeader-BxoemHK8.js";import{A as yl}from"./ActionButton-D2iBheZp.js";import{C as jl}from"./action-costs-BP0gjEio.js";import{D as wl,u as Nl}from"./DrivePreviewModal-B-X_j41v.js";import{U as kl}from"./UserPicker-Bik8_Gvy.js";import{V as Sl}from"./VersionHistoryDialog-CfbWyfI1.js";import{d as Cl}from"./download-CoxLfzn7.js";import"./vendor-radix-B-GS9lOI.js";import"./vendor-sentry-5pfF84Kg.js";import"./vendor-zustand-CrGSlGru.js";import"./vendor-tiptap-D5DGAmLD.js";import"./vendor-prosemirror-C2SEAMxP.js";import"./vendor-yjs-B8tolAur.js";import"./usePinchZoom-DsqZKHKA.js";import"./tree-BP2orYm_.js";import"./documentPages-CL7etf5-.js";import"./exportDocument-C33Wzvg1.js";import"./RequestAccessButton-WQF5jSEq.js";import"./shareLink-CV50lg5m.js";import"./accessRequests-D8Jdggkv.js";import"./CommentsPanel-BhkgtllM.js";import"./CommentThread-CaVD3swm.js";import"./CommentTiptapInput-DI50RisW.js";import"./MentionSuggestion-BBKS5RXF.js";import"./tokenGrammar-CzEQ10R3.js";import"./useSmartChipSync-Dp-CIe_9.js";import"./useProseMirrorReconcileGuard-D3puOMT0.js";import"./markdownListRun-B3uaTs5-.js";import"./MentionContent-Dxre6Jsl.js";import"./sanitize-DFtTX6mG.js";import"./EmojiPicker-viehkrU_.js";import"./ReactionChips-DFRqcH4W.js";import"./normalizedGeometry-BckzUVXA.js";import"./DriveFilePreviewBody-XOXgqZhe.js";import"./line-BXI_jX-L.js";import"./base-Bv2RN8kc.js";import"./versionSessions-BBzPF23y.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};t.SENTRY_RELEASE={id:"266446510ecd5dbce76808c272265ca5e766a576"};var r=new t.Error().stack;r&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[r]="8b9c83d8-c28e-4c1c-aa4a-9b7576ca3fca",t._sentryDebugIdIdentifier="sentry-dbid-8b9c83d8-c28e-4c1c-aa4a-9b7576ca3fca")}catch{}})();const qr=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),Mr=qr?"â":"Ctrl+",_l=[{id:"drive:back-folder",module:"drive",combo:"Backspace",description:"Go to parent folder",category:"navigation",when:"list"},{id:"drive:close-preview",module:"drive",combo:"Escape",description:"Close preview / dialog",category:"navigation",when:"always"},{id:"drive:upload",module:"drive",combo:`${Mr}U`,description:"Upload file",category:"creation",when:"always"},{id:"drive:new-folder",module:"drive",combo:`${qr?"â§":"Shift+"}N`,description:"Create new folder",category:"creation",when:"list"},{id:"drive:view-grid",module:"drive",combo:`${Mr}${qr?"â§":"Shift+"}G`,description:"Switch to grid view",category:"view",when:"always"}
1,{id:"drive:view-list",module:"drive",combo:`${Mr}${qr?"â§":"Shift+"}L`,description:"Switch to list view",category:"view",when:"always"},{id:"drive:delete",module:"drive",combo:"Delete",description:"Move selected item(s) to trash",category:"editing",when:"list"},{id:"drive:search",module:"drive",combo:`${Mr}F`,description:"Focus Drive search",category:"general",when:"always"},{id:"drive:search-slash",module:"drive",combo:"/",description:"Open Drive search",category:"general",when:"list"}];function Dl({searchResults:t,files:r,trashedFiles:a,virtualDocuments:n,currentFolderId:i,activeSection:l,currentUserId:c}){if(t!==null)return t;if(l==="trash"){if(i)return a.filter(x=>x.parent_folder_id===i);const u=new Set(a.map(x=>x.id));return a.filter(x=>!x.parent_folder_id||!u.has(x.parent_folder_id))}if(l==="my-drive"&&n.length>0){const u=new Set(r.map(m=>m.id)),x=n.filter(m=>!u.has(m.id)&&m.owner_id===c&&(m.parent_folder_id??null)===i);return[...r,...x]}return r}function Fl(t,r){const a=t.on_behalf_of?t.on_behalf_of.id===r?"you":t.on_behalf_of.display_name:null,n=[a?`added for ${a}`:"added"];return t.source==="mail"&&n.push("from Mail"),n.join(" · ")}function zl(t,r){const a=t.on_behalf_of?t.on_behalf_of.id===r?"you":t.on_behalf_of.display_name:null;return`Added by agent ${t.agent.display_name}${a?` for ${a}`:""}${t.source==="mail"?", from Mail":""}`}function $l({name:t,className:r}){return e.jsxs(aa,{variant:"accent",className:A("rounded-full gap-1 px-2 py-0 max-w-[160px]",r),title:`${t} is an agent`,"data-agent-pill":"true",children:[e.jsx(An,{size:12,"aria-hidden":"true"}),e.jsx("span",{className:"truncate",children:t})]})}function ds({addedBy:t,className:r,compact:a}){const n=ct(i=>{var l;return((l=i.user)==null?void 0:l.id)??null});return e.jsx("span",{className:A("flex flex-wrap items-center gap-x-1.5 gap-y-0.5 min-w-0 text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)]",r),"data-testid":"drive-agent-attribution","aria-label":zl(t,n),role:"note",children:e.jsxs("span",{"aria-hidden":"true",className:"contents",children:[e.jsx(Rt,{name:t.agent.display_name,src:t.agent.avatar_url,size:"xxs",shape:"square",decorative:!0}),e.jsx($l,{name:t.agent.display_name}),!a&&e.jsx("span",{className:"min-w-0",children:Fl(t,n)})]})})}const eo={type:"all",people:"any",modified:"any",location:"anywhere",addedByAgents:!1},to=[{key:"all",label:"Any type"},{key:"folders",label:"Folders"},{key:"documents",label:"Documents"},{key:"spreadsheets",label:"Spreadsheets"},{key:"presentations",label:"Presentations"},{key:"forms",label:"Forms"},{key:"images",label:"Images"},{key:"pdf",label:"PDFs"}],ro=[{key:"any",label:"Anyone"},{key:"me",label:"Owned by me"}],ao=[{key:"any",label:"Any time"},{key:"today",label:"Today"},{key:"last_week",label:"Last 7 days"},{key:"last_month",label:"Last 30 days"},{key:"last_year",label:"Last year"}];function so(t){return[{key:"anywhere",label:"Anywhere in Drive"},...t?[{key:"this_folder",label:`In ${t}`}]:[],{key:"my_drive",label:"My Drive"},{key:"shared_with_me",label:"Shared with me"},{key:"shared_drives",label:"Shared drives"}]}function Rr(t,r){var a;return((a=t.find(n=>n.key===r))==null?void 0:a.label)??r}function nr(t,r,a){switch(t){case"type":return r.type==="all"?"Type":`Type: ${Rr(to,r.type)}`;case"people":return r.people==="any"?"People":`People: ${Rr(ro,r.people)}`;case"modified":return r.modified==="any"?"Modified":`Modified: ${Rr(ao,r.modified)}`;case"location":return r.location==="anywhere"?"Location":`Location: ${Rr(so(a),r.location)}`}}function or(t,r){return r[t]!==eo[t]}function no(t,r=new Date){if(t==="any")return null;if(t==="today"){const n=new Date(r);return n.setHours(0,0,0,0),n}const a=t==="last_week"?7:t==="last_month"?30:365;return new Date(r.getTime()-a*24*60*60*1e3)}function El(t,r){const a={};t.type!=="all"&&(a.kind=t.type),t.people==="me"&&r.currentUserId&&(a.owner_id=r.currentUserId);const n=no(t.modified,r.now);return n&&(a.modified_after=n.toISOString()),t.addedByAgents&&(a.added_by="agents"),t.location==="this_folder"?r.currentFolderId&&(a.in_folder=r.currentFolderId):t.location!=="anywhere"&&(a.location=t.location),r.sort==="modified"&&(a.sort="modified"),a}function Ll(t,r){const a=[];for(const n of["type","people","modified"])or(n,t)&&a.push({label:`Remove "${nr(n,t,r)}
1"`,next:{...t,[n]:eo[n]}});return t.addedByAgents&&a.push({label:'Remove "Added by agents"',next:{...t,addedByAgents:!1}}),t.location!=="anywhere"&&a.push({label:"Search all of Drive",next:{...t,location:"anywhere"}}),a}function hn(t,r){if(!r||r.length===0)return[{text:t,match:!1}];const a=[...r].sort((l,c)=>l.start-c.start),n=[];let i=0;for(const l of a){const c=Math.max(l.start,i),u=Math.min(l.start+l.length,t.length);u<=c||(c>i&&n.push({text:t.slice(i,c),match:!1}),n.push({text:t.slice(c,u),match:!0}),i=u)}return i<t.length&&n.push({text:t.slice(i),match:!1}),n}function vn(t,r){return r?`${t}+ results`:`${t} ${t===1?"result":"results"}`}function Ml(t){var n;const r=de(t.updated_at);return[t.added_by?null:((n=t.owner)==null?void 0:n.display_name)??null,r].filter(Boolean).join(" · ")}function Rl(t){const r=[t.name];return t.location&&r.push(`in ${t.location.label}`),t.updated_at&&r.push(`modified ${de(t.updated_at)}`),t.added_by?r.push(`added by agent ${t.added_by.agent.display_name}`):t.owner&&r.push(`owned by ${t.owner.dis
1play_name}`),r.join(", ")}const oo=A("inline-flex items-center gap-1 h-8 pointer-coarse:min-h-11 px-3 rounded-full border whitespace-nowrap shrink-0","text-[length:var(--text-label-m)] leading-[var(--lh-label-m)] font-medium","transition-colors duration-[var(--duration-micro)]","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)] focus-visible:ring-offset-1 focus-visible:ring-offset-[var(--color-bg-primary)]"),io="border-[var(--color-border-control)] text-[var(--color-text-secondary)] hover:bg-[var(--color-bg-secondary)]",lo="bg-[var(--color-accent-subtle)] border-[var(--color-accent)] text-[var(--color-accent-text)]",Tl=o.forwardRef(function({value:r,onChange:a,onClear:n,onArrowDown:i,autoFocus:l,placeholder:c="Search in Drive"},u){return e.jsxs("div",{className:"relative w-full","data-testid":"drive-search-field",children:[e.jsx(On,{size:16,"aria-hidden":"true",className:"absolute left-3 top-1/2 -translate-y-1/2 text-[var(--color-text-tertiary)] pointer-events-none"}),e.jsx("input",{ref:u,type:"search",value:r,onChange:x=>a(x.target.value),placeholder:c,"aria-label":c,"data-testid":"drive-search-input",autoFocus:l,enterKeyHint:"search",onKeyDown:x=>{x.key==="Escape"?(x.preventDefault(),n()):x.key==="ArrowDown"&&(x.preventDefault(),i())},className:A("h-10 pointer-coarse:h-11 w-full pl-9 pr-16 rounded-[var(--radius-lg)] border","border-[var(--color-border-control)] bg-[var(--color-bg-primary)]","text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] pointer-coarse:text-[length:var(--text-body-l)] text-[var(--color-text-primary)]","placeholder:text-[var(--color-text-tertiary)]","focus:outline-none focus:border-[var(--color-accent)] focus:ring-2 focus:ring-[var(--color-accent-subtle)]","[&::-webkit-search-cancel-button]:appearance-none")}),e.jsx("span",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-1",children:r?e.jsx("button",{type:"button",onClick:n,"aria-label":"Clear search","data-testid":"drive-search-clear",className:"h-8 w-8 pointer-coarse:h-11 pointer-coarse:w-11 flex items-center justify-center rounded-full text-[var(--color-text-tertiary)] hover:bg-[var(--color-bg-secondary)] hover:text-[var(--color-text-secondary)]",children:e.jsx(gt,{size:14,"aria-hidden":"true"})}):e.jsx("span",{className:"hidden md:inline-flex","aria-hidden":"true",children:e.jsx(Ii,{children:"/"})})})]})});function Tr({chipKey:t,label:r,title:a,changed:n,options:i,value:l,onSelect:c}
1){const u=Vn(),[x,m]=o.useState(!1),v=e.jsxs("button",{type:"button",className:A(oo,n?lo:io),"data-testid":`drive-search-chip-${t}`,"data-changed":n?"true":void 0,"aria-haspopup":u?"dialog":"menu",onClick:u?()=>m(!0):void 0,children:[e.jsx("span",{children:r}),e.jsx(Lt,{size:14,"aria-hidden":"true"})]}),p=y=>e.jsxs("span",{className:"flex w-full items-center justify-between gap-3",children:[e.jsx("span",{children:y.label}),l===y.key&&e.jsx(Bn,{size:14,"aria-hidden":"true",className:"text-[var(--color-accent-text)]"})]});return u?e.jsxs(e.Fragment,{children:[v,e.jsx(ze,{open:x,onOpenChange:m,children:e.jsxs($e,{"data-testid":`drive-search-sheet-${t}`,children:[e.jsxs(Ee,{children:[e.jsx(Le,{children:a}),e.jsx(Re,{className:"sr-only",children:"Choose one"})]}),e.jsx("div",{role:"radiogroup","aria-label":a,className:"flex flex-col pb-2",children:i.map(y=>e.jsx("button",{type:"button",role:"radio","aria-checked":l===y.key,"data-testid":`drive-search-chip-${t}-option-${y.key}`,onClick:()=>{c(y.key),m(!1)},className:"min-h-11 px-3 rounded-[var(--radius-md)] text-left text-[length:var(--text-body-l)] leading-[var(--lh-body-l)] text-[var(--color-text-primary)] hover:bg-[var(--color-bg-secondary)]",children:p(y)},y.key))})]})})]}):e.jsxs(Se,{children:[e.jsx(Ce,{asChild:!0,children:v}),e.jsx(_e,{align:"start",sideOffset:4,className:"w-56","aria-label":a,children:i.map(y=>e.jsx(z,{"data-testid":`drive-search-chip-${t}-option-${y.key}`,onSelect:()=>c(y.key),"aria-checked":l===y.key,role:"menuitemradio",children:p(y)},y.key))})]})}function co({pressed:t,onToggle:r}){return e.jsxs("button",{type:"button","aria-pressed":t,onClick:r,"data-testid":"drive-search-chip-agents",className:A(oo,t?lo:io),children:[e.jsx(An,{size:14,"aria-hidden":"true"}),e.jsx("span",{children:"Added by agents"})]})}function Pl({filters:t,onChange:r,folderName:a,showLocation:n}){return e.jsxs("div",{role:"group","aria-label":"Search filters","data-testid":"drive-search-chips",className:"flex flex-nowrap items-center gap-2 overflow-x-auto max-md:-mx-4 max-md:pl-4 max-md:pr-12 pb-1 [scrollbar-width:none] max-md:[mask-image:linear-gradient(to_right,#000_0,#000_calc(100%-40px),transparent_100%)]",children:[e.jsx(Tr,{chipKey:"type",label:nr("type",t,a),title:"Type",changed:or("type",t),options:to,value:t.type,onSelect:i=>r({...t,type:i})}),e.jsx(Tr,{chipKey:"people",label:nr("people",t,a),title:"People",changed:or("people",t),options:ro,value:t.people,onSelect:i=>r({...t,people:i})}),e.jsx(Tr,{chipKey:"modified",label:nr("modified",t,a),title:"Modified",changed:or("modified",t),options:ao,value:t.modified,onSelect:i=>r({...t,modified:i})}),n&&e.jsx(Tr,{chipKey:"location",label:nr("location",t,a),title:"Location",changed:or("location",t),options:so(a),value:t.location,onSelect:i=>r({...t,location:i})}),e.jsx(co,{pressed:t.addedByAgents,onToggle:()=>r({...t,addedByAgents:!t.addedByAgents})})]})}function pn({segments:t}){return e.jsx(e.Fragment,{children:t.map((r,a)=>r.match?e.jsx("mark",{className:"rounded-[2px] bg-[var(--color-accent-subtle)] text-[var(--color-text-primary)] px-[1px]",children:r.text},a):e.jsx("span",{children:r.text},a))})}function Il({file:t,onOpen:r,onKeyNav:a}){const n=t.search_match,i=hn(t.name,n==null?void 0:n.name_highlights),l=(n==null?void 0:n.snippet)??null,c=Ml(t);return e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>r(t),onKeyDown:a,"aria-label":Rl(t),"data-testid":`drive-search-result-${t.id}`,"data-search-result":"true",className:A("w-full flex items-start gap-3 px-3 py-2.5 text-left rounded-[var(--radius-md)]","hover:bg-[var(--color-bg-secondary)] focus-visible:outline-none focus-visible:bg-[var(--color-accent-subtle)] focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]","transition-colors duration-[var(--duration-micro)]"),children:[e.jsx("span",{className:"mt-0.5 shrink-0 text-[var(--color-text-tertiary)]","aria-hidden":"true",children:nt(t,18)}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block line-clamp-2 break-words [word-break:break-word] text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] font-medium text-[var(--color-text-primary)]",title:t.name,children:e.jsx(pn,{segments:i})}),e.jsxs("span",{className:"block line-clamp-2 text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-secondary)] break-words",children:[(n==null?void 0:n.field)==="scanned_text"&&l&&e.jsx("span",{className:"text-[var(--color-text-tertiary)]",children:"In scanned text: "}),l&&e.jsxs(e.Fragment,{children:['"',e.jsx(pn,{segments:hn(l,n==null?void 0:n.snippet_highlights)}),'"'," "]}),t.location&&e.jsxs("span",{className:"hidden md:inline text-[var(--color-text-tertiary)]","data-testid":`drive-search-result-location-${t.id}`,children:["in ",t.location.label]})]}),t.location&&e.jsxs("span",{className:"md:hidden block truncate text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)]",children:["in ",t.location.label]}),t.added_by&&e.jsx(ds,{addedBy:t.added_by,className:"mt-1"})]}),c&&e.jsxs("span",{className:"shrink-0 mt-0.5 text-[length:var(--text-label-s)] leading-[var(--lh-label-s)] text-[var(--color-text-tertiary)] tabular-nums",children:[e.jsx("span",{className:"hidden md:inline",children:c}),e.jsx("span",{className:"md:hidden",children:de(t.updated_at)})]})]})})}const Ma={relevance:"Most relevant",modified:"Last modified"};function Al({query:t,status:r,results:a,hasMore:n,filters:i,folderName:l,sort:c,onSortChange:u,onFiltersChange:x,onOpen:m,onRetry:v,onLoadMore:p,onFocusField:y}
1){const R=o.useRef(null),k=o.useCallback(T=>{var N,f,w;if(T.key!=="ArrowDown"&&T.key!=="ArrowUp"&&T.key!=="Escape")return;if(T.preventDefault(),T.key==="Escape"){y();return}const L=Array.from(((N=R.current)==null?void 0:N.querySelectorAll("[data-search-result]"))??[]),h=L.indexOf(T.currentTarget);T.key==="ArrowDown"?(f=L[Math.min(h+1,L.length-1)])==null||f.focus():h<=0?y():(w=L[h-1])==null||w.focus()},[y]),F=r==="loading"&&(!a||a.length===0),U=(a==null?void 0:a.length)??0,W=r==="loading"?"Searching":r==="error"?"Couldn't search Drive":r==="done"?vn(U,n):"";return e.jsxs("section",{"aria-label":"Search results","data-testid":"drive-search-results",className:"flex flex-col",children:[e.jsx("p",{className:"sr-only",role:"status","aria-live":"polite","data-testid":"drive-search-announce",children:W}),r==="error"?e.jsxs("div",{className:"flex flex-col items-center text-center gap-2 py-12 px-4","data-testid":"drive-search-error",children:[e.jsx("h2",{className:"text-[length:var(--text-title-s)] leading-[var(--lh-title-s)] font-semibold text-[var(--color-text-primary)]",children:"Couldn't search Drive"}),e.jsx("p",{className:"text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] text-[var(--color-text-secondary)]",children:"Check your connection and try again."}),e.jsx(G,{variant:"secondary",size:"compact",className:"mt-2 pointer-coarse:min-h-11 border border-[var(--color-border-control)]",onClick:v,children:"Try again"})]}):F?e.jsx("div",{"data-testid":"drive-search-loading","aria-hidden":"true",children:[0,1,2,3].map(T=>e.jsx(st,{className:"border-b border-[var(--color-bg-tertiary)] last:border-b-0"},T))}):r==="done"&&U===0?e.jsxs("div",{className:"flex flex-col items-center text-center gap-2 py-12 px-4","data-testid":"drive-search-empty",children:[e.jsxs("h2",{className:"text-[length:var(--text-title-s)] leading-[var(--lh-title-s)] font-semibold text-[var(--color-text-primary)] break-words max-w-full",children:['No files match "',t,'"']}),e.jsx("p",{className:"text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] text-[var(--color-text-secondary)]",children:"Try fewer words, or remove a filter."}),(()=>{const T=Ll(i,l);return T.length===0?null:e.jsx("div",{className:"flex flex-wrap justify-center gap-2 mt-2",children:T.map(L=>e.jsx(G,{variant:"secondary",size:"compact",className:"pointer-coarse:min-h-11",onClick:()=>x(L.next),children:L.label},L.label))})})()]}):a?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 pb-1",children:[e.jsx("span",{className:"text-[length:var(--text-label-m)] leading-[var(--lh-label-m)] text-[var(--color-text-secondary)] tabular-nums","data-testid":"drive-search-count",children:vn(U,n)}),e.jsxs(Se,{children:[e.jsx(Ce,{asChild:!0,children:e.jsxs("button",{type:"button","data-testid":"drive-search-sort","aria-label":`Sort: ${Ma[c]}`,className:"inline-flex items-center gap-1 h-8 pointer-coarse:min-h-11 px-2 rounded-[var(--radius-md)] text-[length:var(--text-label-m)] leading-[var(--lh-label-m)] text-[var(--color-text-secondary)] hover:bg-[var(--color-bg-secondary)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]",children:[Ma[c],e.jsx(Lt,{size:12,"aria-hidden":"true"})]})}),e.jsx(_e,{align:"end",sideOffset:4,className:"w-44",children:["relevance","modified"].map(T=>e.jsx(z,{"data-testid":`drive-search-sort-${T}`,onSelect:()=>u(T),role:"menuitemradio","aria-checked":c===T,children:e.jsxs("span",{className:"flex w-full items-center justify-between",children:[Ma[T],c===T&&e.jsx(Bn,{size:14,"aria-hidden":"true",className:"text-[var(--color-accent-text)]"})]})},T))})]})]}),e.jsx("ul",{ref:R,className:"flex flex-col divide-y divide-[var(--color-bg-tertiary)]","data-testid":"drive-search-list",children:a.map(T=>e.jsx(Il,{file:T,onOpen:m,onKeyNav:k},T.id))}),n&&e.jsx("div",{className:"flex justify-center pt-3",children:e.jsx(G,{variant:"secondary",size:"compact",className:"pointer-coarse:min-h-11",onClick:p,"data-testid":"drive-search-more",children:"Show more results"})}),e.jsx("p",{className:"px-3 pt-3 pb-2 text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)]","data-testid":"drive-search-scope-note",children:"Results include only files you can open."})]}):null]})}function Ol(t=document){const r=t.querySelector("[data-search-result]");return r?(r.focus(),!0):!1}function uo(t,r){return new URL(Ja(r,"folder"),t).toString()}async function us(t){const r=uo(window.location.origin,t);await sa(r)?P.success("Folder link copied"):P.error("Couldn't copy link",r)}function Bl(t,r,a="file"){return new URL(Ja(r,a),t).toString()}async function Ul(t,r="file"){const a=Bl(window.location.origin,t,r);await sa(a)?P.success("Link copied"):P.error("Couldn't copy link",a)}async function ql(t){const r=cr(t);if(!r)return Ul(t.id,t.is_folder?"folder":"file");const a=new URL(r,window.location.origin).toString();await sa(a)?P.success("Link copied"):P.error("Couldn't copy link",a)}const dr="application/x-drive-file-id",mo="application/x-drive-file-ids",Va="data-drop-target-id",xo="root";function Wl(t){if(!t)return null;try{const r=JSON.parse(t);return Array.isArray(r)&&r.length>0&&r.every(a=>
1typeof a=="string")?r:null}catch{return null}}function ho(t){const r=Wl(t.getData(mo));if(r)return r;const a=t.getData(dr);return a?[a]:[]}function Kl(t){const r=t instanceof Element?t.closest(`[${Va}]`):null,a=r==null?void 0:r.getAttribute(Va);if(a!=null)return a===xo?null:a}function Gr(t){const r=t.lastIndexOf("/");return r===-1?"":t.slice(0,r)}function Vl(t){return t.slice(t.lastIndexOf("/")+1)}function fn(t){return at(t,"Upload failed")}function Hl(t){return/quota|too large|maximum allowed size/i.test(t)}function Gl(t){return{files:t.map(r=>({file:r,relativePath:r.name})),folders:[]}}function Yl(t){const r=t.map(n=>({file:n,relativePath:n.webkitRelativePath||n.name})),a=new Set;for(const{relativePath:n}of r){let i=Gr(n);for(;i;)a.add(i),i=Gr(i)}return{files:r,folders:[...a]}}function Zl(...t){return{files:t.flatMap(r=>r.files),folders:[...new Set(t.flatMap(r=>r.folders))]}}function Xl(t){return new Promise((r,a)=>t.readEntries(r,a))}function Jl(t){return new Promise((r,a)=>t.file(r,a))}async function vo(t,r=""){const a=r?`${r}/${t.name}`:t.name,n={files:[],folders:[a]},i=t.createReader();for(;;){const l=await Xl(i);if(l.length===0)break;for(const c of l)if(c.isDirectory){const u=await vo(c,a);n.files.push(...u.files),n.folders.push(...u.folders)}else if(c.isFile){const u=await Jl(c);n.files.push({file:u,relativePath:`${a}/${c.name}`})}}return n}async function Ql(t,r,a){var x;const n={uploaded:0,foldersCreated:0,failures:[],stoppedOnLimit:!1},i=new Map([["",r]]),l=new Map,c=[...new Set(t.folders)].sort((m,v)=>m.split("/").length-v.split("/").length||m.localeCompare(v));for(const m of c){const v=Gr(m),p=l.get(v);if(p){l.set(m,p);continue}try{const y=await a.createFolder(Vl(m),i.get(v)??null);i.set(m,y.id),n.foldersCreated++}catch(y){const R=fn(y);l.set(m,R),n.failures.push({path:m,reason:R})}}const u=t.files.length;for(let m=0;m<u;m++){const{file:v,relativePath:p}=t.files[m],y=Gr(p);if(l.has(y)){n.failures.push({path:p,reason:l.get(y)});continue}(x=a.onProgress)==null||x.call(a,{current:m+1,total:u,filename:v.name,pct:0});try{await a.uploadFile(v,i.get(y)??null,R=>{var k;return(k=a.onProgress)==null?void 0:k.call(a,{current:m+1,total:u,filename:v.name,pct:R})}),n.uploaded++}catch(R){const k=fn(R);if(n.failures.push({path:p,reason:k}),Hl(k)){n.stoppedOnLimit=!0;break}}}return n}function gn(t,r){return`${t} ${r}${t===1?"":"s"}`}function ec(t,r,a){const n=new Set(r.failures.map(u=>u.path)),i=[...new Set(t.folders)].filter(u=>!u.includes("/")&&!n.has(u)),l={};if(i.length>0)l.success={title:i.length===1?`Folder "${i[0]}" uploaded`:`${i.length} folders uploaded`,description:gn(r.uploaded,"file")};else if(r.uploaded===1){const u=t.files.find(x=>!n.has(x.relativePath));l.success={title:"File uploaded",description:u==null?void 0:u.file.name}}else r.uploaded>1&&(l.success={title:`${r.uploaded} files uploaded`});l.success&&a&&(l.success.description=[l.success.description,`in "${a}"`].filter(Boolean).join(" "));const[c]=r.failures;if(!c)return l;if(r.stoppedOnLimit){const u=r.failures[r.failures.length-1];l.error={title:u.reason,description:"Free up space by emptying Trash or deleting files."}}else r.failures.length===1?l.error={title:"Upload failed",description:c.path.includes("/")?`${c.path}: ${c.reason}`:c.reason}:l.error={title:`${gn(r.failures.length,"item")} couldn't be uploaded`,description:`${c.path}: ${c.reason}`};return l}function tc(t){const r=t;if(!r||r===document.body||typeof r.closest!="function"||r.closest('[role="dialog"]'))return null;const a=r.closest('[role="menu"]');return a?a.id?document.querySelector(`[aria-controls="${CSS.escape(a.id)}"]`):null:r}const rc=[{root:"my_drive",name:"My Drive"},{root:"shared_drives",name:"Shared drives"},{root:"shared_with_me",name:"Shared with me"}],ac=["my_drive","shared_drives","shared_with_me"],bn="All locations",sc=[0,1,2,3],yn="w-full flex items-center gap-3 px-3 py-2 min-h-9 pointer-coarse:min-h-11 transition-colors text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--color-accent)]",jn="h-9 pointer-coarse:h-11 px-3 rounded-[var(--radius-md)] border border-[var(--color-bg-tertiary)] bg-[var(--color-bg-primary)] text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] text-[var(--color-text-primary)] placeholder:text-[var(--color-text-tertiary)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]";function Ra({open:t,onOpenChange:r,title:a,actionLabel:n,onConfirm:i,loading:l,roots:c=ac}){const u=rc.filter(({root:C})=>c.includes(C)),x=u.length===1?u[0].root:null,[m,v]=o.useState(null),[p,y]=o.useState(null),[R,k]=o.useState([]),[F,U]=o.useState(!1),[W,T]=o.useState(!1),[L,h]=o.use
1State([{id:null,name:bn,root:null}]),[N,f]=o.useState(""),w=N.trim().length>0,[b,j]=o.useState(null),[E,q]=o.useState(null),D=o.useRef(null);o.useEffect(()=>{const C=H=>{const $=tc(H.target);$&&(D.current=$)};return document.addEventListener("focusin",C,!0),()=>document.removeEventListener("focusin",C,!0)},[]);const O=o.useCallback(async(C,H,$)=>{U(!0),T(!1);try{const ue=await V.getState().loadFolders(C,H,$);k(ue)}catch{k([]),T(!0)}U(!1)},[]);o.useEffect(()=>{t&&(v(null),y(null),k([]),T(!1),f(""),j(null),q(null),h([{id:null,name:bn,root:null}]))},[t]),o.useEffect(()=>{if(!t)return;const C=N.trim();C&&v(null);const H=setTimeout(()=>{if(C)O(null,x,C);else{const $=L[L.length-1];v($.id),$.root?O($.id,$.root):k([])}},C?150:0);return()=>clearTimeout(H)},[N,t]);const K=()=>w?(f(""),!0):!1,X=(C,H)=>{y(C),v(null),h($=>[...$,{id:null,name:H,root:C}]),!K()&&O(null,C)},S=(C,H)=>{p&&(v(C),h($=>[...$,{id:C,name:H,root:p}]),!K()&&O(C,p))},I=C=>{const H=L[C];v(H.id),y(H.root),h($=>$.slice(0,C+1)),!K()&&(H.root?O(H.id,H.root):k([]))},Z=()=>{const C=N.trim();C?O(null,x,C):p&&O(m,p)},ae=!W&&(w?m!==null:p!==null&&(p==="my_drive"||m!==null)),M=async()=>{const C=(b??"").trim();if(C){q(null);try{const H=await V.getState().createFolder(C,m);j(null),S(H.id,H.name)}catch(H){q(H instanceof Error?H.message:"Couldn't create a folder here.")}}};return e.jsx(ze,{open:t,onOpenChange:r,children:e.jsxs($e,{className:"sm:max-w-[480px]",onEscapeKeyDown:C=>{b!==null&&(C.preventDefault(),j(null))},onCloseAutoFocus:C=>{const H=D.current;H!=null&&H.isConnected&&(C.preventDefault(),H.focus())},children:[e.jsxs(Ee,{children:[e.jsx(Le,{children:a}),e.jsx(Re,{children:"Choose a destination folder"})]}),e.jsx(ls,{ariaLabel:"Folder path",size:"s",className:"pb-1",items:L.map((C,H)=>{const $=H===L.length-1;return{key:C.id??C.root??"chooser",label:C.name,onClick:$?void 0:()=>I(H),dataTestId:`dialog-breadcrumb-${H}`}})}),e.jsx("input",{type:"search","data-testid":"picker-search","aria-label":"Search folders",placeholder:"Search folders",value:N,onChange:C=>f(C.target.value),className:`w-full mb-2 ${jn}`}),e.jsx("div",{className:"border border-[var(--color-bg-tertiary)] rounded-[var(--radius-md)] max-h-[280px] min-h-[160px] overflow-y-auto",children:p===null&&!w?e.jsx("div",{className:"py-1",children:u.map(({root:C,name:H})=>e.jsxs("button",{"data-testid":`picker-root-${C}`,className:`${yn} hover:bg-[var(--color-bg-secondary)]`,onClick:()=>X(C,H),children:[e.jsx(xe,{size:18,className:"text-[var(--color-text-tertiary)] shrink-0"}),e.jsx("span",{className:"text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] text-[var(--color-text-primary)] truncate",children:H}),e.jsx(Mt,{size:14,className:"text-[var(--color-text-quaternary)] ml-auto shrink-0"})]},C))}):F?e.jsx("div",{className:"py-1","data-testid":"picker-loading",children:sc.map(C=>e.jsx(st,{className:"py-2 min-h-9 pointer-coarse:min-h-11"},C))}):W?e.jsxs("div",{role:"alert","data-testid":"picker-load-error",className:"flex flex-col items-center justify-center gap-2 py-8 px-3 text-center",children:[e.jsx("span",{className:"text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] text-[var(--color-text-secondary)]",children:"Couldnât load folders."}),e.jsx(G,{variant:"secondary",size:"compact","data-testid":"picker-load-retry",onClick:Z,children:"Try again"})]}):R.length===0?e.jsx("div",{className:"flex items-center justify-center py-8 text-[var(--color-text-tertiary)]",children:e.jsx("span",{className:"text-[length:var(--text-body-m)] leading-[var(--lh-body-m)]",children:w?"No matching folders":"No folders here"})}):e.jsx("div",{className:"py-1",children:R.map(C=>{const H=C.destination_denied,$=`picker-denied-${C.id}`,ue=w&&C.id===m;return e.jsxs("button",{"data-testid":`picker-folder-${C.id}`,"aria-disabled":H?!0:void 0,"aria-describedby":H?$:void 0,"aria-current":ue?"true":void 0,className:`${yn} ${H?"cursor-not-allowed opacity-60":ue?"bg-[var(--color-accent-subtle)]":"hover:bg-[var(--color-bg-secondary)]"}`,onClick:H?void 0:w?()=>v(C.id):()=>S(C.id,C.name),children:[e.jsx(xe,{size:18,className:"text-[var(--color-text-tertiary)] shrink-0"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] text-[var(--color-text-primary)] truncate",children:C.name}),H?e.jsx("span",{id:$,className:"block text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)]",children:H.reason}):null]}),H||w?null:e.jsx(Mt,{size:14,className:"text-[var(--color-text-quaternary)] shrink-0"})]},C.id)})})}),!w&&ae?e.jsxs("div",{className:"mt-2",children:[b===null?e.jsx(G,{variant:"secondary",size:"compact","data-testid":"picker-new-folder",onClick:()=>j(""),children:"New folder"}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{autoFocus:!0,"data-testid":"picker-new-folder-name","aria-label":"New folder name",placeholder:"Folder name",value:b,onChange:C=>j(C.target.value),onKeyDown:C=>{C.key==="Enter"&&M(),C.key==="Escape"&&j(null)},className:`flex-1 min-w-0 ${jn}`}),e.jsx(G,{size:"compact","data-testid":"picker-new-folder-create",disabled:!b.trim(),onClick:()=>void M(),children:"Create"})]}),E?e.jsx("p",{className:"mt-1 text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-error)]",children:E}):null]}):null,e.jsxs(He,{children:[e.jsx(G,{variant:"secondary",onClick:()=>r(!1),children:"Cancel"}),e.jsx(G,{onClick:()=>i(m),disabled:l||!ae,children:l?`${n}...`:n})]})]})})}function nc(t){const r={};return t.sortBy!=="shared"&&(t.sortBy!=="modified"||t.sortDirection!=="desc")&&(r.sort=t.sortBy,r.order=t.sortDirection),t.filterType!=="all"&&(r.kind=t.filterType),t.ownerId&&(r.owner_id=t.ownerId),t.modifiedAfter&&(r.modified_after=t.modifiedAfter.toISOString()),t.foldersFirst===!1&&(r.folders_first="false"),t.addedByAgents&&(r.added_by="agents"),r}function wn(t,r){let a=t;if(r.filterType!=="all"){const n=r.filterType;a=a.filter(i=>xl(n,i))}if(r.ownerId){const n=r.ownerId;a=a.filter(i=>i.owner_id===n)}if(r.modifiedAfter){const n=r.modifiedAfter.getTime();a=a.filter(i=>!!i.updated_at&&new Date(i.updated_at).getTime()>=n)}return r.addedByAgents&&(a=a.filter(n=>!!n.added_by)),a}const ge=t=>t?new Date(t).getTime():0;function po(t){switch(t){case"shared":return(r,a)=>ge(r.shared_at)-ge(a.shared_at);case"name":return(r,a)=>r.name.localeCompare(a.name);case"owner":return(r,a)=>{var n,i;return(((n=r.owner)==null?void 0:n.display_name)||"").localeCompare(((i=a.owner)==null?void 0:i.display_name)||"")};case"modified":return(r,a)=>ge(r.updated_at)-ge(a.updated_at);case"last_opened":return(r,a)=>(ge(r.last_viewed_at)||ge(r.updated_at)||ge(r.created_at))-(ge(a.last_viewed_at)||ge(a.updated_at)||ge(a.created_at));case"created":return(r,a)=>ge(r.created_at)-ge(a.created_at);case"size":return(r,a)=>(r.size_bytes||0)-(a.size_bytes||0)}}function Nn(t,r,a){const n=[...t].sort(po(r));return a==="desc"&&n.reverse(),n}function oc(t,r,a,n,i,l=!0){if(r.length===0)return t;const c=po(a),u=(v,p)=>n==="asc"?c(v,p)<0:c(v,p)>0,x=[];let m=0;for(const v of t){if(!l||!v.is_folder)for(;m<r.length&&u(r[m],v);)x.push(r[m++]);x.push(v)}return i||x.push(...r.slice(m)),x}function ic(t,r){if(!r)return{folders:[],files:[],mixed:t};const a=[],n=[];for(const i of t)(i.is_folder?a:n).push(i);return{folders:a,files:n,mixed:null}}function Pr(t){return t.toLocaleDateString("en-CA",{timeZone:Ai()})}function lc(t,r){const a=new Date(t);if(Pr(a)===Pr(r))return"today";const n=new Date(r.getTime()-1440*60*1e3);return Pr(a)===Pr(n)?"yesterday":de(t)}function cc(t,r=new Date){switch(t.reason){case"opened":return`You opened ${lc(t.at,r)}`;case"shared":return t.actor?`${t.actor.display_name}
1 shared · ${de(t.at)}`:`Shared with you · ${de(t.at)}`;case"added":return t.actor?t.actor.is_agent?`${t.actor.display_name} added for you · ${de(t.at)}`:`${t.actor.display_name} added · ${de(t.at)}`:`Added · ${de(t.at)}`}}const fo="text-[length:var(--text-label-s)] leading-[var(--lh-label-s)] font-semibold uppercase tracking-[0.05em] text-[var(--color-text-tertiary)]",go="rounded-[var(--radius-lg)] border border-[var(--color-border-control)] bg-[var(--color-bg-primary)] text-left hover:bg-[var(--color-bg-secondary)] transition-colors duration-[var(--duration-micro)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)] focus-visible:ring-offset-1 focus-visible:ring-offset-[var(--color-bg-primary)]";function dc({files:t,onOpen:r,onContextMenu:a}){return t.length===0?null:e.jsxs("section",{"aria-labelledby":"drive-suggested-heading",className:"mb-6","data-testid":"drive-suggested-section",children:[e.jsx("h2",{id:"drive-suggested-heading",className:A(fo,"mb-3"),children:"Suggested"}),e.jsx("ul",{className:"grid grid-cols-3 gap-3",children:t.slice(0,3).map(n=>e.jsx("li",{className:"min-w-0",children:e.jsxs("button",{type:"button",onClick:()=>r(n),onContextMenu:a?i=>{i.preventDefault(),a(n,i)}:void 0,className:A(go,"w-full h-full min-h-[72px] flex items-start gap-3 px-4 py-3"),"data-testid":`drive-suggested-card-${n.id}`,children:[e.jsx("span",{className:"mt-0.5 shrink-0","aria-hidden":"true",children:nt(n,20)}),e.jsxs("span",{className:"min-w-0 flex flex-col gap-1",children:[e.jsx("span",{className:"text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] font-medium text-[var(--color-text-primary)] line-clamp-2 break-words",children:n.name}),e.jsx("span",{className:"text-[length:var(--text-label-s)] leading-[var(--lh-label-s)] text-[var(--color-text-tertiary)]","data-testid":`drive-suggested-reason-${n.id}`,children:cc(n.suggestion)})]})]})},n.id))})]})}function uc(t,r){const a=[...new Set(t.map(l=>l.parent_folder_id).filter(l=>!!l))].sort().join(","),[n,i]=o.useState(new Map);return o.useEffect(()=>{if(!a)return;let l=!1;return Promise.all(a.split(",").map(async c=>{var u;try{const x=await be.drive.folders.ancestors({params:{id:c}});return[c,((u=x.data.at(-1))==null?void 0:u.name)??null]}catch{return[c,null]}})).then(c=>{l||i(new Map(c))}),()=>{l=!0}},[a]),o.useMemo(()=>{const l=new Map,c=u=>u.owner_id===r?"My Drive":"Shared with me";for(const u of t){if(!u.parent_folder_id){l.set(u.id,c(u));continue}n.has(u.parent_folder_id)&&l.set(u.id,n.get(u.parent_folder_id)??c(u))}return l},[t,n,r])}function mc({files:t,currentUserId:r,onOpen:a,onSeeAll:n}){const i=t.slice(0,3),l=uc(i,r);return t.length===0?null:e.jsxs("section",{"aria-labelledby":"drive-recent-strip-heading",className:"mb-2","data-testid":"drive-recent-strip",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[e.jsx("h2",{id:"drive-recent-strip-heading",className:fo,children:"Recent"}),e.jsx("button",{type:"button",onClick:n,className:"-mr-2 h-11 px-2 rounded-[var(--radius-md)] text-[length:var(--text-label-m)] leading-[var(--lh-label-m)] font-medium text-[var(--color-accent-text)] hover:bg-[var(--color-bg-secondary)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]","data-testid":"drive-recent-see-all",children:"See all"})]}),e.jsx("ul",{className:"flex gap-2 overflow-x-auto [overscroll-behavior-x:contain] snap-x scroll-px-4 -mx-4 px-4 pb-1",children:i.map(c=>{const u=de(c.last_viewed_at??c.updated_at??c.created_at),x=l.get(c.id);return e.jsx("li",{className:"snap-start shrink-0",children:e.jsxs("button",{type:"button",onClick:()=>a(c),className:A(go,"w-[168px] h-full min-h-[88px] flex flex-col items-start gap-1 p-3"),"data-testid":`drive-recent-strip-item-${c.id}`,children:[e.jsx("span",{"aria-hidden":"true",children:nt(c,16)}),e.jsx("span",{className:"text-[length:var(--text-label-m)] leading-[var(--lh-label-m)] font-medium text-[var(--color-text-primary)] line-clamp-2 break-words",children:c.name}),e.jsxs("span",{className:"block max-w-full truncate whitespace-nowrap text-[length:var(--text-label-s)] leading-[var(--lh-label-s)] text-[var(--color-text-tertiary)] tabular-nums","data-testid":`drive-recent-strip-meta-${c.id}`,children:[u,x?` · in ${x.replace(/^\/\s*/,"")}`:""]})]})},c.id)})})]})}const xc={letter:{width:612,height:792}};function hc(t,r,a,n){if(t<=0||r<=0||a<=0||n<=0)return{w:0,h:0,x:0,y:0};const i=Math.min(a/t,n/r),l=t*i,c=r*i;return{w:l,h:c,x:(a-l)/2,y:(n-c)/2}}function vc(t){return new Promise((r,a)=>{const n=new Image;n.onload=()=>r(n),n.onerror=()=>a(new Error("Image failed to load")),n.decoding="async",n.src=t})}async function pc(t,r,a){const n=await vc(t);
1let i=n.naturalWidth,l=n.naturalHeight;if(i===0||l===0)throw new Error("Image has zero dimensions");const c=Math.max(i,l);if(c>a){const p=a/c;i=Math.round(i*p),l=Math.round(l*p)}const u=document.createElement("canvas");u.width=i,u.height=l;const x=u.getContext("2d");if(!x)throw new Error("Canvas 2D context unavailable");x.fillStyle="#ffffff",x.fillRect(0,0,i,l),x.drawImage(n,0,0,i,l);const m=await new Promise(p=>{u.toBlob(y=>p(y),"image/jpeg",r)});if(!m)throw new Error("Canvas toBlob returned null");const v=await m.arrayBuffer();return{jpegBytes:new Uint8Array(v),width:i,height:l}}function fc(t,r){if(t.length===0)throw new Error("At least one image is required to build a PDF");const{pageSize:a,margin:n,title:i}=r,l=Math.max(0,a.width-n*2),c=Math.max(0,a.height-n*2),u=t.length,x=Array.from({length:u},(w,b)=>4+b),m=Array.from({length:u},(w,b)=>4+u+b),v=Array.from({length:u},(w,b)=>4+2*u+b),p=[],y=3+3*u,R=new Array(y+1).fill(0);let k=0;const F=w=>{const b=typeof w=="string"?kn(w):w;p.push(b),k+=b.byteLength},U=w=>{R[w]=k};F(`%PDF-1.4 2`),F(new Uint8Array([37,226,227,207,211,10])),U(1),F(`1 0 obj 3<< /Type /Catalog /Pages 2 0 R >> 4endobj 5`),U(2);const W=x.map(w=>`${w} 0 R`).join(" ");F(`2 0 obj 6<< /Type /Pages /Count ${u} /Kids [${W}] >> 7endobj 8`),U(3);const T=yc(new Date);F(`3 0 obj 9<< /Title (${bc(i)}) /Producer (Ambiguous Document Scanner) /CreationDate (${T}) >> 10endobj 11`);for(let w=0;w<u;w++)U(x[w]),F(`${x[w]} 0 obj 12<< /Type /Page /Parent 2 0 R /MediaBox [0 0 ${a.width} ${a.height}] /Resources << /XObject << /Im${w} ${v[w]} 0 R >> /ProcSet [/PDF /ImageC] >> /Contents ${m[w]} 0 R >> 13endobj 14`);for(let w=0;w<u;w++){const b=t[w],j=hc(b.width,b.height,l,c),E=n+j.x,q=n+j.y,D=`q 15${Ir(j.w)} 0 0 ${Ir(j.h)} ${Ir(E)} ${Ir(q)} cm 16/Im${w} Do 17Q 18`,O=kn(D);U(m[w]),F(`${m[w]} 0 obj 19<< /Length ${O.byteLength} >> 20stream 21`),F(O),F(` 22endstream 23endobj 24`)}for(let w=0;w<u;w++){const b=t[w];U(v[w]),F(`${v[w]} 0 obj 25<< /Type /XObject /Subtype /Image /Width ${b.width} /Height ${b.height} /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length ${b.jpegBytes.byteLength} >> 26stream 27`),F(b.jpegBytes),F(` 28endstream 29endobj 30`)}const L=k;F(`xref 310 ${y+1} 32`),F(`0000000000 65535 f 33`);for(let w=1;w<=y;w++)F(`${R[w].toString().padStart(10,"0")} 00000 n 34`);F(`trailer 35<< /Size ${y+1} /Root 1 0 R /Info 3 0 R >> 36startxref 37${L} 38%%EOF 39`);let h=0;for(const w of p)h+=w.byteLength;const N=new Uint8Array(h);let f=0;for(const w of p)N.set(w,f),f+=w.byteLength;return N}async function gc(t,r={}){if(t.length===0)throw new Error("pdfFromImages: at least one image required");const a=r.pageSize??xc.letter,n=r.margin??36,i=r.jpegQuality??.85,l=r.maxPixelDimension??2200,c=r.title??"Scanned Document",u=[];for(const v of t)u.push(await pc(v,i,l));const x=fc(u,{pageSize:a,margin:n,title:c}),m=new ArrayBuffer(x.byteLength);return new Uint8Array(m).set(x),new Blob([m],{type:"application/pdf"})}function Ir(t){if(!Number.isFinite(t))return"0";const r=Math.round(t*1e3)/1e3;return Number.isInteger(r)?r.toString():r.toFixed(3).replace(/0+$/,"").replace(/\.$/,"")}function bc(t){return t.replace(/[\\()]/g,r=>"\\"+r)}function yc(t){const r=n=>n.toString().padStart(2,"0");return`D:${t.getUTCFullYear()}${r(t.getUTCMonth()+1)}${r(t.getUTCDate())}${r(t.getUTCHours())}${r(t.getUTCMinutes())}${r(t.getUTCSeconds())}Z`}function kn(t){const r=new Uint8Array(t.length);for(let a=0;a<t.length;a++)r[a]=t.charCodeAt(a)&255;return r}function bo(t=new Date){const r=t.getFullYear(),a=(t.getMonth()+1).toString().padStart(2,"0"),n=t.getDate().toString().padStart(2,"0"),i=t.getHours().toString().padStart(2,"0"),l=t.getMinutes().toString().padStart(2,"0");return`Scan ${r}-${a}-${n} ${i}.${l}.pdf`}function jc(t){const r=t.trim();return r?/\.pdf$/i.test(r)?r:`${r}.pdf`:null}function wc({open:t,onClose:r,currentFolderId:a,onUploaded:n}){const[i,l]=o.useState("capture"),[c,u]=o.useState([]),[x,m]=o.useState(""),[v,p]=o.useState(null),y=o.useRef(1),R=o.useCallback(()=>{l("capture"),u([]),m(""),p(null),y.current=1},[]);o.useEffect(()=>{t||R()},[t,R]);const k=o.useCallback(h=>{u(N=>[...N,{id:y.current++,dataUrl:h}]),l("review")},[]),F=o.useCallback(h=>{const N=h.target.files;if(!N||N.length===0)return;const f=Array.from(N);h.target.value="";const w=b=>{if(b>=f.length)return;const j=new FileReader;j.onload=()=>{const E=typeof j.result=="string"?j.result:"";E&&k(E),w(b+1)},j.onerror=()=>w(b+1),j.readAsDataURL(f[b])};w(0)},[k]),U=o.useCallback(h=>{u(N=>{const f=N.filter(w=>w.id!==h);return f.length===0&&l("capture"),f})},[]),W=o.useCallback((h,N)=>{u(f=>{if(N<0||N>=f.length||h===N)return f;const w=f.slice(),[b]=w.splice(h,1);return w.splice(N,0,b),w})},[]),T=o.useCallback(async()=>
39{if(c.length!==0){l("saving"),p(null);try{const h=jc(x)??bo(),N=await gc(c.map(b=>b.dataUrl),{title:h.replace(/\.pdf$/i,"")}),f=new File([N],h,{type:"application/pdf"}),w=await gl(f,{parentFolderId:a});P.success("Scan saved",h),n&&n(w),r()}catch(h){p(h instanceof Error?h.message:"Could not save scan"),l("error")}}},[c,x,a,n,r]),L=Oi();return e.jsx(ze,{open:t,onOpenChange:h=>{h||r()},children:e.jsxs($e,{className:"max-w-[560px]",children:[e.jsxs(Ee,{children:[e.jsx(Le,{children:"Scan document"}),e.jsx(Re,{children:c.length===0?"Capture pages. Saves as a PDF to your Drive.":`${c.length} ${c.length===1?"page":"pages"} captured. Add more, reorder, or save as PDF.`})]}),i==="capture"&&e.jsx(Nc,{touchFallback:L,onFileInput:F}),i==="review"&&e.jsx(kc,{pages:c,filename:x,onFilenameChange:m,onRemovePage:U,onReorder:W,onAddFromFiles:F,touchFallback:L,onSave:T}),i==="saving"&&e.jsxs("div",{className:"flex flex-col items-center gap-3 py-10",children:[e.jsx(Si,{size:20,className:"animate-spin text-[var(--color-accent)]","aria-hidden":!0}),e.jsx("p",{className:"text-[length:var(--text-body-m)] text-[var(--color-text-secondary)]",children:"Building PDF and saving to Driveâ¦"})]}),i==="error"&&e.jsxs("div",{className:"flex flex-col gap-4 py-4",children:[e.jsx("p",{role:"alert",className:"text-[length:var(--text-body-m)] text-[var(--color-error)]",children:v||"Something went wrong. Try again."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(G,{variant:"secondary",onClick:()=>l(c.length>0?"review":"capture"),className:"flex-1",children:"Back"}),e.jsx(G,{variant:"primary",onClick:T,disabled:c.length===0,className:"flex-1",children:"Try again"})]})]})]})})}function Nc({touchFallback:t,onFileInput:r}){return e.jsxs("div",{className:"flex flex-col gap-4 py-2",children:[e.jsxs("div",{className:"flex flex-col items-center gap-3 rounded-[var(--radius-md)] bg-[var(--color-bg-secondary)] p-6 text-center",children:[e.jsx("div",{className:"flex h-16 w-16 items-center justify-center rounded-full",style:{backgroundColor:"color-mix(in srgb, var(--color-module-drive, var(--color-accent)) 14%, transparent)",color:"var(--color-module-drive, var(--color-accent))"},children:e.jsx(Ua,{size:32,"aria-hidden":!0})}),e.jsx("p",{className:"text-[length:var(--text-body-m)] text-[var(--color-text-secondary)]",children:"Place a document on a flat surface and capture each page."})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"sr-only",children:"Document image"}),e.jsx("input",{type:"file",accept:"image/*",multiple:!0,...t?{capture:"environment"}:{},onChange:r,className:"block w-full cursor-pointer rounded-[var(--radius-md)] border border-dashed border-[var(--color-bg-tertiary)] bg-[var(--color-bg-secondary)] p-6 text-center text-[var(--color-text-secondary)] hover:border-[var(--color-accent)]","data-testid":"document-scanner-file-input"}),e.jsx("span",{className:"mt-2 block text-center text-[length:var(--text-body-s)] text-[var(--color-text-tertiary)]",children:"Choose one or more page images"})]})]})}function kc({pages:t,filename:r,onFilenameChange:a,onRemovePage:n,onReorder:i,onAddFromFiles:l,touchFallback:c,onSave:u}){const x=o.useRef(null);return e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-3 sm:grid-cols-4",role:"list",children:[t.map((m,v)=>e.jsx(Sc,{page:m,index:v,total:t.length,onRemove:()=>n(m.id),onMoveLeft:()=>i(v,v-1),onMoveRight:()=>i(v,v+1)},m.id)),e.jsx(Cc,{onFilesClick:()=>{var m;return(m=x.current)==null?void 0:m.click()}})]}),e.jsx("input",{ref:x,type:"file",accept:"image/*",multiple:!0,...c?{capture:"environment"}:{},onChange:l,className:"hidden"}),e.jsxs("label",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-[length:var(--text-label-s)] font-medium text-[var(--color-text-secondary)]",children:"File name"}),e.jsx(pt,{type:"text",value:r,onChange:m=>a(m.target.value),placeholder:bo(),"aria-label":"PDF file name"})]}),e.jsx("div",{className:"flex gap-2",children:e.jsx(G,{variant:"primary",size:"large",onClick:u,disabled:t.length===0,className:"flex-1",children:"Save as PDF"})})]})}function Sc({page:t,index:r,total:a,onRemove:n,onMoveLeft:i,onMoveRight:l}){return e.jsxs("div",{role:"listitem",className:"group relative aspect-[3/4] overflow-hidden rounded-[var(--radius-md)] border border-[var(--color-bg-tertiary)] bg-[var(--color-bg-secondary)]",children:[e.jsx("img",{src:t.dataUrl,alt:`Page ${r+1}`,className:"h-full w-full object-cover"}),e.jsx("span",{className:"absolute left-2 top-2 rounded-full bg-[color-mix(in_srgb,var(--color-text-primary)_85%,transparent)] px-2 py-0.5 text-[length:var(--text-label-s)] font-medium text-[var(--color-bg-primary)]",children:r+1}),e.jsx("button",{type:"button",onClick:n,"aria-label":`Remove page ${r+1}`,className:"absolute right-2 top-2 flex h-7 w-7 items-center justify-center rounded-full bg-[color-mix(in_srgb,var(--color-error)_85%,transparent)] text-[var(--color-text-on-accent)] shadow-sm transition-opacity hover:bg-[var(--color-error)]",children:e.jsx(oe,{size:14,"aria-hidden":!0})}),e.jsxs("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 flex items-center justify-between bg-gradient-to-t from-black/60 to-transparent px-1 py-1 opacity-0 transition-opacity group-hover:opacity-100",children:[e.jsx("button",{type:"button",onClick:i,disabled:r===0,"aria-label":`Move page ${r+1} left`,className:"pointer-events-auto flex h-7 w-7 items-center justify-center rounded-full bg-black/50 text-white hover:bg-black/70 disabled:opacity-30",children:e.jsx(Jr,{size:14,"aria-hidden":!0})}),e.jsx("button",{type:"button",onClick:l,disabled:r===a-1,"aria-label":`Move page ${r+1} right`,className:"pointer-events-auto flex h-7 w-7 items-center justify-center rounded-full bg-black/50 text-white hover:bg-black/70 disabled:opacity-30",children:e.jsx(Mt,{size:14,"aria-hidden":!0})})]})]})}function Cc({onFilesClick:t}){return e.jsxs("button",{type:"button",onClick:t,"aria-label":"Add another page",className:"flex aspect-[3/4] flex-col items-center justify-center gap-1 rounded-[var(--radius-md)] border-2 border-dashed border-[var(--color-bg-tertiary)] bg-[var(--color-bg-secondary)] text-[var(--color-text-secondary)] transition-colors hover:border-[var(--color-accent)] hover:text-[var(--color-accent)]",children:[e.jsx(bt,{size:20,"aria-hidden":!0}),e.jsx("span",{className:"text-[length:var(--text-label-s)]",children:"Add page"})]})}function yo(t){return!t.is_folder&&!t.document_type&&!t.is_legal_record}function _c({file:t,size:r="compact"}){const a=o.useRef(null),n=V(c=>c.uploadFileVersion),[i,l]=o.useState(!1);return yo(t)?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:a,type:"file",className:"hidden","data-testid":"upload-new-version-input",onChange:async c=>{var x;const u=(x=c.target.files)==null?void 0:x[0];if(c.target.value="",!!u){l(!0);try{await n(t.id,u)}catch(m){P.error("Couldn't upload new version",at(m,"Upload failed"))}finally{l(!1)}}}}),e.jsx(G,{type:"button",variant:"secondary",size:r,disabled:i,onClick:()=>{var c;return(c=a.current)==null?void 0:c.click()},"data-testid":"upload-new-version",children:i?"Uploadingâ¦":"Upload new version"})]}):null}const Ha="current";async function Dc(t,r,a){const n=_i(),i={};n&&(i.Authorization=`Bearer ${n}`);const l=r===Ha?`/api/drive/${t}/content?download=true`:`/api/drive/${t}/versions/${r}`,c=await fetch(l,{headers:i});if(!c.ok)throw new Error("Failed to download version");Cl(await c.blob(),a)}function Fc({open:t,onOpenChange:r,file:a,onRestored:n}){var m,v;const i=o.useRef(new Map),l=o.useRef(null);o.useLayoutEffect(()=>{t&&(l.current=document.activeElement)},[t]);const c=o.useCallback(p=>{if(r(p),p)return;const y=l.current;y!=null&&y.isConnected&&requestAnimationFrame(()=>y.focus())},[r]),u=o.useMemo(()=>
39({newestIsCurrent:!0,currentLabel:"Current",list:async()=>{var F,U,W,T;const y=(await be.drive.versions.list({params:{id:a.id},query:{}})).data||[],k=[{id:Ha,size_bytes:a.size_bytes??0,mime_type:a.mime_type,uploaded_by_id:((F=y[0])==null?void 0:F.uploaded_by_id)??((U=a.owner)==null?void 0:U.id)??null,uploaded_by_name:((W=y[0])==null?void 0:W.uploaded_by_name)??((T=a.owner)==null?void 0:T.display_name)??"",created_at:a.updated_at??null},...y];return i.current=new Map(k.map(L=>[L.id,L])),k.map(L=>({id:L.id,title:"",user_id:L.uploaded_by_id,user_name:L.uploaded_by_name,created_at:L.created_at}))},restore:async p=>(await be.drive.versions.restore({params:{id:a.id,versionId:p}}),{}),remove:async p=>{await be.drive.versions.delete({params:{id:a.id,versionId:p}})}}),[a.id,a.size_bytes,a.mime_type,(m=a.owner)==null?void 0:m.id,(v=a.owner)==null?void 0:v.display_name,a.updated_at]),x=o.useCallback(p=>{const y=i.current.get(p.id);return e.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 py-10 text-center","data-testid":"drive-version-preview",children:[e.jsx("div",{className:"text-[length:var(--text-body-m)] text-[var(--color-text-primary)] font-medium break-all",children:a.name}),e.jsx("div",{className:"text-[length:var(--text-body-s)] text-[var(--color-text-tertiary)]",children:y?`${Me(y.size_bytes)} · ${cs({name:a.name,mime_type:y.mime_type})}`:"Unknown size"}),e.jsx(G,{type:"button",variant:"secondary",onClick:()=>{const R=()=>Dc(a.id,p.id,a.name).catch(()=>P({title:"Couldn't download this version",variant:"error",action:e.jsx(Ci,{altText:"Retry download",onClick:R,children:"Retry"})}));R()},"data-testid":"drive-version-download",children:p.id===Ha?"Download":"Download this version"})]})},[a.id,a.name]);return e.jsx(Sl,{open:t,onOpenChange:c,documentId:a.id,onReverted:n,source:u,renderPreview:x})}function ur(t){switch(t){case"public":case"link":case"anyone-with-link":return"Anyone with the link";case"workspace":return"Workspace";case"restricted":case"private":return"Private";default:return"Private"}}function Sn(t){if(!t)return"â";try{return new Date(t).toLocaleString(void 0,{year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}catch{return"â"}}function zc({file:t,onExtractText:r}){const a=jl.drive_extract_text.vendor_cost,n=Hn(p=>p.view),i=n?Ui(n):void 0,[l,c]=o.useState(!1),[u,x]=o.useState(null),[m,v]=o.useState(null);return e.jsxs("section",{"data-testid":"file-info-extract-text","aria-label":"Text extraction",children:[e.jsx("h3",{className:"text-[length:var(--text-title-s)] font-semibold text-[var(--color-text-primary)] mb-2",children:"Text"}),e.jsx(yl,{cost:a,remaining:i,disabled:l?"loading":void 0,testId:"file-info-extract-text-button",onClick:async()=>{c(!0),v(null);try{x(await r(t))}catch(p){x(null),v(at(p,"Couldn't extract text. Try again."))}finally{c(!1)}},children:"Extract text"}),e.jsx("p",{className:"mt-2 text-[length:var(--text-body-s)] text-[var(--color-text-tertiary)]","aria-live":"polite","data-testid":"file-info-extract-text-result",children:u===null?"":u.status==="empty"?"No text found.":"Text extracted â this file is now findable by its contents."}),m!==null&&e.jsx("p",{className:"mt-2 text-[length:var(--text-body-s)] text-[var(--color-error)]",role:"alert","aria-live":"assertive","data-testid":"file-info-extract-text-error",children:m})]})}function $c({open:t,onClose:r,file:a,onManageTags:n,onRename:i,onExtractText:l}){const[c,u]=o.useState(!1);if(!a)return null;const x=!a.is_folder&&a.size_bytes!=null?Me(a.size_bytes):"â",m=[{label:"Type",value:cs(a)},...a.is_folder?[]:[{label:"Size",value:x}],{label:"Created",value:Sn(a.created_at)},{label:"Modified",value:Sn(a.updated_at)},{label:"Owner",value:a.owner?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Rt,{name:a.owner.display_name,src:a.owner.avatar_url,size:"xs"}),e.jsx("span",{children:a.owner.display_name})]}):"â"},{label:"Sharing",value:ur(a.visibility)},{label:"ID",value:e.jsx("button",{type:"button",className:"text-left font-medium text-[var(--color-accent-text)] hover:underline focus-visible:outline-2 focus-visible:outline-[var(--color-accent)] rounded-[var(--radius-sm)] pointer-coarse:min-h-11",onClick:async()=>{await sa(a.id)?P.success("File ID copied"):P.error("Couldn't copy the ID",a.id
39)},"data-testid":"file-info-copy-id",children:"Copy ID"})}];return e.jsx(Bi,{open:t,onClose:r,size:"md",mobileMode:"overlay",testId:"file-info-panel",headerSlot:e.jsx(bl,{title:e.jsxs("span",{className:"flex items-center gap-2 min-w-0 w-full",children:[a.is_folder?e.jsx(xe,{size:18,className:"text-[var(--color-text-tertiary)] shrink-0"}):e.jsx(Un,{size:18,className:"text-[var(--color-text-tertiary)] shrink-0"}),i?e.jsx(oa,{value:a.name,onCommit:async v=>{await i(a,v)},clickToEdit:!0,displayAsButton:!1,testId:"file-info-panel-rename",className:"text-[length:var(--text-title-s)] font-semibold text-[var(--color-text-primary)] truncate"}):e.jsx("span",{className:"truncate",children:a.name})]}),onClose:r,testId:"file-info-panel-header"}),hideCloseButton:!0,children:e.jsxs("div",{className:"px-4 py-4 flex flex-col gap-4",children:[e.jsx("dl",{className:"grid grid-cols-[96px_1fr] gap-x-4 gap-y-2","data-testid":"file-info-grid",children:m.map(v=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-[length:var(--text-body-s)] text-[var(--color-text-tertiary)]",children:v.label}),e.jsx("dd",{className:"text-[length:var(--text-body-s)] text-[var(--color-text-primary)] min-w-0 break-words",children:v.value})]},v.label))}),yo(a)&&e.jsxs("section",{"data-testid":"file-info-versions","aria-label":"Versions",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-[length:var(--text-title-s)] font-semibold text-[var(--color-text-primary)]",children:"Versions"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(G,{type:"button",variant:"secondary",size:"compact",onClick:()=>u(!0),"data-testid":"open-version-history",children:"Version history"}),e.jsx(_c,{file:a})]})]}),e.jsx(Fc,{open:c,onOpenChange:u,file:a,onRestored:()=>{}})]}),l&&hl(a)&&e.jsx(zc,{file:a,onExtractText:l}),!a.is_folder&&e.jsxs("section",{"data-testid":"file-info-tags","aria-label":"Tags",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("h3",{className:"text-[length:var(--text-title-s)] font-semibold text-[var(--color-text-primary)] flex items-center gap-1.5",children:[e.jsx(Ve,{size:14,className:"text-[var(--color-text-tertiary)]"}),"Tags"]}),n&&e.jsx(G,{variant:"ghost",size:"compact",onClick:()=>n(a),"aria-label":"Manage tags",children:"Manage"})]}),a.tags&&a.tags.length>0?e.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.tags.map(v=>e.jsx(aa,{variant:"default",className:"rounded-full font-medium",style:zo(v.color),children:v.name},v.id))}):n?e.jsx("button",{type:"button",className:"text-left text-[length:var(--text-body-s)] font-medium text-[var(--color-accent-text)] hover:underline focus-visible:outline-2 focus-visible:outline-[var(--color-accent)] rounded-[var(--radius-sm)] pointer-coarse:min-h-11",onClick:()=>n(a),"data-testid":"file-info-add-tag",children:"Add a tag"}):e.jsx("p",{className:"text-[length:var(--text-body-s)] text-[var(--color-text-tertiary)]",children:"No tags"})]})]})})}const Ec=[{value:"gray",label:"Gray"},{value:"red",label:"Red"},{value:"orange",label:"Orange"},{value:"yellow",label:"Yellow"},{value:"green",label:"Green"},{value:"blue",label:"Blue"},{value:"purple",label:"Purple"},{value:"pink",label:"Pink"},{value:"cyan",label:"Cyan"}],Wr={gray:{bg:"var(--color-bg-tertiary)",fg:"var(--color-text-secondary)"},red:{bg:"var(--color-error-subtle)",fg:"var(--color-error-text)"},orange:{bg:"var(--color-orange-subtle)",fg:"var(--color-orange)"},yellow:{bg:"var(--color-warning-subtle)",fg:"var(--color-warning-text)"},green:{bg:"var(--color-success-subtle)",fg:"var(--color-success-text)"},blue:{bg:"var(--color-accent-subtle)",fg:"var(--color-accent-text)"},purple:{bg:"var(--color-purple-subtle)",fg:"var(--color-purple)"},pink:{bg:"var(--color-pink-subtle)",fg:"var(--color-pink)"},cyan:{bg:"var(--color-cyan-subtle)",fg:"var(--color-cyan)"}};function Lc(t){const r=Wr[t];if(r)return{backgroundColor:r.bg,color:r.fg};const a=Object.keys(Wr).filter(c=>c!=="gray"),n=Jn(t),i=a[n%a.length],l=Wr[i];return{backgroundColor:l.bg,color:l.fg}}function Mc({open:t,onOpenChange:r,file:a}){const{tags:n,loadTags:i,createTag:l,deleteTag:c,addTagToFile:u,removeTagFromFile:x}=V(),[m,v]=o.useState(""),[p,y]=o.useState("gray"),[R,k]=o.useState(!1),[F,U]=o.useState(null);if(o.useEffect(()=>{t&&i()},[t,i]),!a)return null;const W=new Set((a.tags??[]).map(f=>f.id)),T=async f=>{f==null||f.preventDefault();const w=m.trim();if(w){k(!0);try{const b=await l(w,p);v(""),y("gray"),await u(a.id,b.id)}catch(b){const j=b instanceof Error?b.message:"Failed to create tag";P({title:j,variant:"error"})}finally{k(!1)}}},L=async f=>{try{W.has(f.id)?await x(a.id,f.id):await u(a.id,f.id)}catch(w){const b=w instanceof Error?w.message:"Failed to update tag";P({title:b,variant:"error"})}},h=f=>{U(f)},N=async()=>
39{if(F)try{await c(F.id)}catch(f){const w=f instanceof Error?f.message:"Failed to delete tag";P({title:w,variant:"error"})}finally{U(null)}};return e.jsxs(e.Fragment,{children:[e.jsx(Ke,{open:F!==null,onOpenChange:f=>{f||U(null)},title:"Delete tag?",description:F?`"${F.name}" will be removed from all files. This cannot be undone.`:"",confirmLabel:"Delete tag",variant:"destructive",onConfirm:N}),e.jsx(ze,{open:t,onOpenChange:r,children:e.jsxs($e,{className:"max-w-[480px]","data-testid":"tag-manager-dialog",children:[e.jsxs(Ee,{children:[e.jsxs(Le,{className:"flex items-center gap-2",children:[e.jsx(Ve,{size:18}),"Manage tags"]}),e.jsx(Re,{className:"truncate",children:a.name})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{className:"text-[length:var(--text-label-s)] leading-[var(--lh-label-s)] font-medium text-[var(--color-text-secondary)]",children:"Your tags"}),n.length===0?e.jsx("p",{"data-testid":"tag-manager-empty",className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)] py-2",children:"No tags yet. Create one below to start organizing your files."}):e.jsx("ul",{className:"flex flex-col gap-1 max-h-[280px] overflow-y-auto",children:n.map(f=>{const w=W.has(f.id);return e.jsxs("li",{"data-testid":`tag-manager-row-${f.id}`,className:"flex items-center gap-2 rounded-[var(--radius-sm)] px-2 py-2 hover:bg-[var(--color-bg-secondary)]",children:[e.jsxs("button",{type:"button",onClick:()=>L(f),"data-testid":`tag-manager-toggle-${f.id}`,"aria-pressed":w,className:A("flex-1 flex items-center gap-2 text-left rounded-[var(--radius-sm)]","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]"),children:[e.jsx(aa,{variant:"default",className:"rounded-full gap-1",style:Lc(f.color),children:f.name}),e.jsx("span",{className:"text-[length:var(--text-label-s)] leading-[var(--lh-label-s)] text-[var(--color-text-tertiary)]",children:w?"Attached":"Click to attach"})]}),e.jsx("button",{type:"button",onClick:()=>h(f),"aria-label":`Delete tag ${f.name}`,"data-testid":`tag-manager-delete-${f.id}`,className:"shrink-0 p-1 rounded-[var(--radius-sm)] text-[var(--color-text-tertiary)] hover:text-[var(--color-error)] hover:bg-[var(--color-bg-tertiary)]",children:e.jsx(oe,{size:14})})]},f.id)})})]}),e.jsxs("form",{onSubmit:T,className:"flex flex-col gap-2 pt-2 border-t border-[var(--color-bg-tertiary)]",children:[e.jsx("label",{className:"text-[length:var(--text-label-s)] leading-[var(--lh-label-s)] font-medium text-[var(--color-text-secondary)]",children:"Create new tag"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(pt,{type:"text",value:m,onChange:f=>v(f.target.value),placeholder:"Tag name","data-testid":"tag-manager-new-name",maxLength:50,className:"flex-1"}),e.jsxs(G,{type:"submit",size:"compact",variant:"primary",disabled:!m.trim()||R,"data-testid":"tag-manager-create",children:[e.jsx(bt,{size:14}),"Add"]})]}),e.jsx("div",{className:"flex items-center gap-1 flex-wrap",children:Ec.map(({value:f,label:w})=>e.jsx("button",{type:"button",onClick:()=>y(f),"aria-label":`Color: ${w}`,"aria-pressed":p===f,"data-testid":`tag-manager-color-${f}`,className:A("w-6 h-6 rounded-full border-2 transition-colors",p===f?"border-[var(--color-text-primary)]":"border-transparent hover:border-[var(--color-text-quaternary)]"),style:{backgroundColor:Wr[f].fg}},f))})]}),e.jsx(He,{children:e.jsx(G,{variant:"primary",onClick:()=>r(!1),children:"Done"})})]})})]})}const Cn=20,_n=200,Dn=14,Rc=1024*1024;function Fn(t){return`${window.location.origin}/file-request/${t}`}function Tc(t){return new Date(Date.now()+t*24*60*60*1e3).toISOString()}function Pc(t){try{return new Date(t).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}catch{return t}}function Ic(t){return!t.revoked_at&&new Date(t.expires_at).getTime()>Date.now()}function Ft(){return"text-[length:var(--text-label-m)] leading-[var(--lh-label-m)] font-medium text-[var(--color-text-secondary)]"}function Ta(t,r){return t instanceof ft&&t.status===403?"Only the folder owner can manage file requests.":t instanceof ft&&t.status===404?"File requests aren't available for this folder.":t instanceof ft&&t.status===409?"This file request changed. Refresh and try again.":`${r} Try again.`}function Ac({folder:t,open:r,onClose:a}){const n=V(B=>B.fileRequests),i=V(B=>B.loadFileRequests),l=V(B=>B.createFileRequest),c=V(B=>B.remintFileRequest),u=V(B=>
39B.revokeFileRequest),[x,m]=o.useState(!1),[v,p]=o.useState(""),[y,R]=o.useState(""),[k,F]=o.useState(String(Cn)),[U,W]=o.useState(String(_n)),[T,L]=o.useState(String(Dn)),[h,N]=o.useState(!1),[f,w]=o.useState(null),[b,j]=o.useState(null),[E,q]=o.useState(null),D=o.useRef(null),[O,K]=o.useState(null),{copied:X,copy:S,reset:I}=qi(),Z=(t==null?void 0:t.id)??null;o.useEffect(()=>{!r||!Z||(K(null),w(null),j(null),q(null),I(),p(""),R(""),F(String(Cn)),W(String(_n)),L(String(Dn)),m(!0),i(Z).catch(B=>P.error(Ta(B,"Couldn't load file requests."))).finally(()=>m(!1)))},[r,Z,i,I]);const ae=parseInt(k,10),M=parseInt(U,10),C=parseInt(T,10),H=!!Z&&v.trim().length>0&&ae>0&&M>0&&C>0,$=o.useCallback(()=>{const B=D.current;w(null),window.setTimeout(()=>{B!=null&&B.isConnected&&B.focus()},0)},[]),ue=o.useCallback(async()=>{if(!(!Z||!H)){N(!0);try{const{token:B}=await l(Z,{title:v.trim(),instructions:y.trim()||null,max_files:ae,max_total_bytes:M*Rc,expires_at:Tc(C)});I(),K({token:B,title:"Link created"}),p(""),R("")}catch(B){P.error(Ta(B,"Couldn't create the request."))}finally{N(!1)}}},[Z,H,l,v,y,ae,M,C,I]),la=o.useCallback(async()=>{if(!(!Z||!f||b)){j(f.id);try{const{token:B}=await c(Z,f.id,f.updated_at);I(),K({token:B,title:"Link re-minted"}),$()}catch(B){P.error(Ta(B,"Couldn't re-mint the link."))}finally{j(null)}}},[Z,c,f,b,I,$]),mr=o.useCallback(async()=>{if(!(!Z||!E))try{await u(Z,E.id),P.success("Request revoked")}catch{P.error("Couldn't revoke the request. Try again.")}finally{q(null)}},[Z,E,u]);return e.jsxs(e.Fragment,{children:[e.jsx(ze,{open:r,onOpenChange:B=>!B&&a(),children:e.jsxs($e,{className:"flex max-h-[90dvh] max-w-lg flex-col overflow-hidden!","data-testid":"file-requests-dialog",children:[e.jsxs(Ee,{className:"shrink-0",children:[e.jsx(Le,{children:"Request files"}),e.jsx(Re,{children:t?`Anyone with the link can upload into ${t.name}. They see nothing else.`:"Anyone with the link can upload. They see nothing else."})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain pr-1","data-testid":"file-requests-scroll-region",children:[O?e.jsxs("div",{className:"flex flex-col gap-2 rounded-[var(--radius-lg)] border border-[var(--color-success)] bg-[var(--color-success-subtle)] p-4","data-testid":"file-request-token-reveal",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(cn,{size:16,className:"text-[var(--color-success)]"}),e.jsx("span",{className:"text-[length:var(--text-label-l)] font-medium text-[var(--color-text-primary)]",children:O.title})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 select-all break-all rounded-[var(--radius-md)] bg-[var(--color-bg-primary)] px-3 py-2 font-mono text-[length:var(--text-body-s)]","data-testid":"file-request-link",children:Fn(O.token)}),e.jsx(G,{variant:"ghost",size:"icon-sm",onClick:()=>void S(Fn(O.token)),"aria-label":X?"Link copied":"Copy link","data-testid":"file-request-copy-link",children:X?e.jsx(cn,{size:16,className:"text-[var(--color-success)]"}):e.jsx(it,{size:16})})]}),e.jsxs("div",{className:"flex items-start gap-2 rounded-[var(--radius-md)] border border-[var(--color-warning)] bg-[var(--color-warning-subtle)] px-3 py-2 text-[var(--color-warning-text)]",role:"status","aria-live":"polite","aria-atomic":"true","data-testid":"file-request-one-time-notice",children:[e.jsx(Di,{size:16,className:"mt-0.5 shrink-0"}),e.jsx("p",{className:"text-[length:var(--text-label-m)] font-medium",children:"This link is displayed once for security. Copy it now."})]}),e.jsx("div",{children:e.jsx(G,{variant:"ghost",size:"compact",onClick:()=>{K(null),I()},"data-testid":"file-request-dismiss-reveal",children:"Done"})})]}):e.jsxs("div",{className:"flex flex-col gap-4 py-2",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"file-request-title",className:Ft(),children:"Title"}),e.jsx(pt,{id:"file-request-title",value:v,onChange:B=>p(B.target.value),placeholder:"Q1 receipts",autoFocus:!0,"data-testid":"file-request-title-input"})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"file-request-instructions",className:Ft(),children:"Instructions"}),e.jsx(Gn,{id:"file-request-instructions",value:y,onChange:B=>R(B.target.value),placeholder:"One PDF per receipt.",rows:2,"data-testid":"file-request-instructions-input"})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"file-request-max-files",className:Ft(),children:"Max files"}),e.jsx(pt,{id:"file-request-max-files",type:"number",min:1,value:k,onChange:B=>F(B.target.value),"data-testid":"file-request-max-files-input"})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"file-request-max-mb",className:Ft(),children:"Max total (MB)"}),e.jsx(pt,{id:"file-request-max-mb",type:"number",min:1,value:U,onChange:B=>W(B.target.value),"data-testid":"file-request-max-bytes-input"})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"file-request-expiry",className:Ft(),children:"Expires (days)"}),e.jsx(pt,{id:"file-request-expiry",type:"number",min:1,value:T,onChange:B=>L(B.target.value),"data-testid":"file-request-expiry-input"})]})]})]}),e.jsxs("div",{className:"mt-4 flex flex-col gap-2",children:[e.jsx("span",{className:Ft(),children:"Active links"}),x?e.jsx(st,{}):n.length===0?e.jsx("p",{className:"text-[length:var(--text-body-s)] text-[var(--color-text-tertiary)]","data-testid":"file-requests-empty",children:"No file requests yet."}):e.jsx("ul",{className:"flex flex-col gap-2",children:n.map(B=>e.jsxs("li",{className:"flex flex-col items-stretch gap-1 sm:flex-row sm:items-center sm:justify-between sm:gap-3 rounded-[var(--radius-md)] border border-[var(--color-bg-tertiary)] px-3 py-2","data-testid":`file-request-row-${B.id}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-[length:var(--text-body-m)] text-[var(--color-text-primary)]",children:B.title}),e.jsxs("p",{className:"text-[length:var(--text-label-s)] text-[var(--color-text-tertiary)]",children:[B.uploaded_file_count,"/",B.max_files," ","files · ",Me(B.uploaded_total_bytes)," ","of ",Me(B.max_total_bytes)," ·"," ",e.jsx("span",{className:"whitespace-nowrap",children:B.revoked_at?"Revoked":`Expires ${Pc(B.expires_at)}`})]})]}),Ic(B)&&e.jsxs("div",{className:"flex shrink-0 items-center gap-1 -ml-2 sm:ml-0",children:[e.jsx(G,{variant:"ghost",size:"compact",onClick:ca=>{D.current=ca.currentTarget,w(B)},disabled:b===B.id,"data-testid":`file-request-remint-${B.id}`,children:b===B.id?"Making a new linkâ¦":"New link"}),e.jsx(G,{variant:"ghost",size:"compact",className:"text-[var(--color-error)] hover:text-[var(--color-error)]",onClick:()=>q(B),"data-testid":`file-request-revoke-${B.id}`,children:"Revoke"})]})]},B.id))})]})]}),e.jsxs(He,{className:"shrink-0","data-testid":"file-requests-footer",children:[!O&&!H&&!h&&e.jsx("p",{className:"mr-auto self-center text-[length:var(--text-body-s)] text-[var(--color-text-tertiary)]","data-testid":"file-request-create-hint",children:v.trim().length===0?"Add a title to create a link.":"Set limits above zero to create a link."}),!O&&e.jsx(G,{variant:"ghost",onClick:a,children:"Close"}),!O&&e.jsx(G,{onClick:()=>void ue(),disabled:!H||h,"data-testid":"file-request-create",children:h?"Creatingâ¦":"Create link"})]})]})}),e.jsx(Ke,{open:f!==null,onOpenChange:B=>!B&&$(),title:"Make a new link",description:"The current link will stop working immediately. Request limits, uploads, and expiry stay the same.",confirmLabel:"Make new link",cancelLabel:"Cancel",variant:"primary",onConfirm:la}),e.jsx(Ke,{open:E!==null,onOpenChange:B=>!B&&q(null),title:"Revoke link",description:E?`Revoke ${E.title} â anyone holding the link can no longer upload.`:"",confirmLabel:"Revoke link",cancelLabel:"Cancel",variant:"destructive",onConfirm:mr})]})}const Ga=[{value:"manager",label:"Manager"},{value:"contributor",label:"Contributor"},{value:"viewer",label:"Viewer"}];function zt(t){var r;return((r=Ga.find(a=>a.value===t))==null?void 0:r.label)??t}function Oc({driveId:t,driveName:r,open:a,onClose:n,canManage:i}){const l=V(b=>b.sharedDriveMembers),c=V(b=>b.loadSharedDriveMembers),u=V(b=>b.addSharedDriveMember),x=V(b=>b.updateSharedDriveMember),m=V(b=>
39b.removeSharedDriveMember),[v,p]=o.useState(!1),[y,R]=o.useState(null),[k,F]=o.useState("contributor"),[U,W]=o.useState(!1),[T,L]=o.useState(null);o.useEffect(()=>{if(!a||!t)return;let b=!1;return p(!0),c(t).catch(()=>{b||P.error("Couldn't load members. Try again.")}).finally(()=>{b||p(!1)}),()=>{b=!0}},[a,t,c]);const h=o.useCallback(async()=>{if(!(!t||!y)){W(!0);try{await u(t,y,k),R(null),F("contributor"),P.success("Member added")}catch{P.error("Couldn't add member. Try again.")}finally{W(!1)}}},[t,y,k,u]),N=o.useCallback(async(b,j)=>{var E,q,D;if(!(!t||b.role===j))try{await x(t,b.user_id,j),P.success(`${b.display_name} is now a ${zt(j).toLowerCase()}`)}catch(O){const K=((q=(E=O==null?void 0:O.response)==null?void 0:E.data)==null?void 0:q.error)||((D=O==null?void 0:O.body)==null?void 0:D.error)||(O==null?void 0:O.error)||"Couldn't change role. Try again.";P.error(K)}},[t,x]),f=o.useCallback(async()=>{var b,j,E;if(!(!t||!T))try{await m(t,T.user_id),P.success(`${T.display_name} removed`),L(null)}catch(q){const D=((j=(b=q==null?void 0:q.response)==null?void 0:b.data)==null?void 0:j.error)||((E=q==null?void 0:q.body)==null?void 0:E.error)||(q==null?void 0:q.error)||"Couldn't remove member. Try again.";P.error(D)}},[t,T,m]),w=l.map(b=>b.user_id);return e.jsxs(e.Fragment,{children:[e.jsx(ze,{open:a,onOpenChange:b=>!b&&n(),children:e.jsxs($e,{className:"max-w-lg","data-testid":"shared-drive-members-dialog",children:[e.jsxs(Ee,{children:[e.jsxs(Le,{children:["Members of ",r??"shared drive"]}),e.jsx(Re,{children:i?"Add teammates and set their role.":"View who has access to this drive."})]}),i&&e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center gap-2 mb-3","data-testid":"shared-drive-add-member-row",children:[e.jsx("div",{className:"flex-1",children:e.jsx(kl,{value:y,onChange:R,placeholder:"Add a teammate",excludeUserIds:w,allowClear:!0,showAssignToMe:!1,testId:"shared-drive-add-member-picker"})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(Se,{children:[e.jsx(Ce,{asChild:!0,children:e.jsxs("button",{type:"button",className:"h-9 max-md:flex-1 pointer-coarse:min-h-[44px] px-3 rounded-md border border-[var(--color-bg-tertiary)] text-[length:var(--text-label-m)] leading-[var(--lh-label-m)] font-medium text-[var(--color-text-secondary)] hover:bg-[var(--color-bg-secondary)] flex items-center justify-center gap-1.5","aria-label":`Role: ${zt(k)}`,"data-testid":"shared-drive-add-member-role-trigger",children:[zt(k),e.jsx(Lt,{size:12,"aria-hidden":"true"})]})}),e.jsx(_e,{align:"end",children:Ga.map(b=>e.jsx(z,{onSelect:()=>F(b.value),"data-testid":`shared-drive-add-member-role-${b.value}`,children:b.label},b.value))})]}),e.jsx(G,{size:"compact",className:"max-md:flex-1 pointer-coarse:min-h-[44px]",onClick:h,disabled:!y||U,"data-testid":"shared-drive-add-member-submit",children:U?"Addingâ¦":"Add"})]})]}),e.jsx("div",{className:"flex flex-col gap-1 max-h-80 overflow-y-auto",role:"list","aria-label":"Drive members","data-testid":"shared-drive-members-list",children:v?e.jsxs(e.Fragment,{children:[e.jsx(st,{}),e.jsx(st,{}),e.jsx(st,{})]}):l.length===0?e.jsx("p",{className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)] px-2 py-3",children:"No members yet."}):l.map(b=>e.jsxs("div",{className:"flex items-center gap-3 px-2 py-2 rounded-md hover:bg-[var(--color-bg-secondary)]",role:"listitem","data-testid":`shared-drive-member-row-${b.user_id}`,children:[e.jsx(Rt,{name:b.display_name,src:b.avatar_url,size:"sm"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] text-[var(--color-text-primary)] truncate",children:b.display_name}),un(b)&&e.jsx("div",{className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)] truncate",children:un(b)})]}),i?e.jsxs(Se,{children:[e.jsx(Ce,{asChild:!0,children:e.jsxs("button",{type:"button",className:"h-8 px-2.5 rounded-md text-[length:var(--text-label-m)] leading-[var(--lh-label-m)] font-medium text-[var(--color-text-secondary)] hover:bg-[var(--color-bg-tertiary)] flex items-center gap-1","aria-label":`Change role for ${b.display_name}, currently ${zt(b.role)}
39`,"data-testid":`shared-drive-member-role-trigger-${b.user_id}`,children:[zt(b.role),e.jsx(Lt,{size:12,"aria-hidden":"true"})]})}),e.jsx(_e,{align:"end",children:Ga.map(j=>e.jsx(z,{onSelect:()=>N(b,j.value),"data-testid":`shared-drive-member-role-option-${b.user_id}-${j.value}`,children:j.label},j.value))})]}):e.jsx("span",{className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)] px-2",children:zt(b.role)}),i&&e.jsx("button",{type:"button",onClick:()=>L(b),className:"h-8 w-8 flex items-center justify-center rounded-md text-[var(--color-text-tertiary)] hover:text-[var(--color-error)] hover:bg-[var(--color-bg-tertiary)]","aria-label":`Remove ${b.display_name}`,"data-testid":`shared-drive-member-remove-${b.user_id}`,children:e.jsx(oe,{size:16})})]},b.user_id))}),e.jsx(He,{children:e.jsx(G,{variant:"secondary",onClick:n,children:"Done"})})]})}),e.jsx(Ke,{open:!!T,onOpenChange:b=>!b&&L(null),title:"Remove member",description:T?`Remove ${T.display_name} â they lose access to this drive.`:"",confirmLabel:"Remove",cancelLabel:"Cancel",variant:"destructive",onConfirm:f})]})}const Ar=["#3B7AEB","#16A34A","#D97706","#7C5FC7","#DC2626","#0891B2","#E06B5E","#EA580C","#9333EA","#4285F4","#78716C","#0F766E","#0D9488"];function Bc(t){if(!t)return"â";try{return new Date(t).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}catch{return"â"}}function jo({mode:t,drive:r,open:a,onClose:n}){const i=V(N=>N.updateSharedDrive),[l,c]=o.useState((r==null?void 0:r.name)??""),[u,x]=o.useState((r==null?void 0:r.description)??""),[m,v]=o.useState((r==null?void 0:r.color)??Ar[0]),[p,y]=o.useState(!1);o.useEffect(()=>{a&&(c((r==null?void 0:r.name)??""),x((r==null?void 0:r.description)??""),v((r==null?void 0:r.color)??Ar[0]))},[a,r==null?void 0:r.id,r==null?void 0:r.name,r==null?void 0:r.description,r==null?void 0:r.color]);const R=l.trim(),k=R.length>0&&R!==((r==null?void 0:r.name)??""),F=(u??"")!==((r==null?void 0:r.description)??""),U=m!==((r==null?void 0:r.color)??Ar[0]),W=!!r&&R.length>0&&(t==="rename"?k:k||F||U),T=o.useCallback(async()=>{if(!(!r||!W)){y(!0);try{const N={};k&&(N.name=R),t==="settings"&&(F&&(N.description=u),U&&(N.color=m)),await i(r.id,N),P.success(t==="rename"?"Drive renamed":"Settings saved"),n()}catch{P.error(t==="rename"?"Couldn't rename drive. Try again.":"Couldn't save settings. Try again.")}finally{y(!1)}}},[r,W,k,R,t,F,u,i,n]),L=t==="rename"?"Rename drive":"Drive settings",h=t==="rename"?"Rename this shared drive.":"Edit drive name and description.";return e.jsx(ze,{open:a,onOpenChange:N=>!N&&n(),children:e.jsxs($e,{className:"max-w-md","data-testid":`shared-drive-settings-dialog-${t}`,children:[e.jsxs(Ee,{children:[e.jsx(Le,{children:L}),e.jsx(Re,{children:h})]}),e.jsxs("div",{className:"flex flex-col gap-4 py-2",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"shared-drive-name-input",className:"text-[length:var(--text-label-m)] leading-[var(--lh-label-m)] font-medium text-[var(--color-text-secondary)]",children:"Name"}),e.jsx(pt,{id:"shared-drive-name-input",value:l,onChange:N=>c(N.target.value),placeholder:"Drive name",autoFocus:!0,"data-testid":"shared-drive-settings-name-input"})]}),t==="settings"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"shared-drive-description-input",className:"text-[length:var(--text-label-m)] leading-[var(--lh-label-m)] font-medium text-[var(--color-text-secondary)]",children:"Description"}),e.jsx(Gn,{id:"shared-drive-description-input",value:u??"",onChange:N=>x(N.target.value),placeholder:"What this drive is for",rows:3,"data-testid":"shared-drive-settings-description-input"})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-[length:var(--text-label-m)] leading-[var(--lh-label-m)] font-medium text-[var(--color-text-secondary)]",children:"Color"}),e.jsx("div",{className:"flex items-center gap-2 flex-wrap","data-testid":"shared-drive-settings-color-picker",children:Ar.map(N=>e.jsx("button",{type:"button",onClick:()=>v(N),className:A("w-7 h-7 rounded-full transition-all duration-[var(--duration-micro)]",m===N?"ring-2 ring-offset-2 ring-[var(--color-accent)] ring-offset-[var(--color-bg-primary)]":"hover:scale-110"),style:{backgroundColor:N},"aria-label":`Color ${N}`,"data-testid":`shared-drive-settings-color-${N}`},N))})]}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-4 gap-y-2 pt-2 border-t border-[var(--color-bg-tertiary)]","data-testid":"shared-drive-settings-metadata",children:[e.jsx("dt",{className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)]",children:"Created"}),e.jsx("dd",{className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-secondary)]",children:Bc(r==null?void 0:r.created_at)}),e.jsx("dt",{className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)]",children:"Members"}),e.jsx("dd",{className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-secondary)]",children:(r==null?void 0:r.member_count)??0})]})]})]}),e.jsxs(He,{children:[e.jsx(G,{variant:"secondary",onClick:n,disabled:p,children:"Cancel"}),e.jsx(G,{onClick:T,disabled:!W||p,"data-testid":"shared-drive-settings-save",children:p?"Savingâ¦":"Save"})]})]})})}const Uc={docs:{id:"docs",label:"Docs",icon:e.jsx(rs,{size:16,className:"text-[var(--color-module-docs)]"}),route:t=>`/docs/import?driveFileId=${t}`},sheets:{id:"sheets",label:"Sheets",icon:e.jsx(as,{size:16,className:"text-[var(--color-module-sheets)]"}),route:t=>`/sheets/import?driveFileId=${t}`},slides:{id:"slides",label:"Slides",icon:e.jsx(ss,{size:16,className:"text-[var(--color-module-slides)]"}),route:t=>`/slides/import?driveFileId=${t}`}};function qc(t){return pl(t).map(r=>Uc[r])}const wo=A("fixed z-[9999] py-2 min-w-[200px] max-w-[280px]","bg-[var(--color-surface-2)] border border-[var(--color-border-control)]","rounded-[var(--radius-lg)] shadow-[var(--shadow-lg)]","animate-in fade-in-0 zoom-in-95 duration-100"),vt=A("relative flex items-center gap-[var(--spacing-2)] rounded-[var(--radius-sm)] px-[var(--spacing-2)] py-[6px]","pointer-coarse:min-h-11 text-[length:var(--text-body-m)] font-normal cursor-pointer select-none outline-none","transition-colors duration-[var(--duration-micro)] hover:bg-[var(--color-bg-tertiary)] text-[var(--color-text-primary)]"),No="my-[var(--spacing-1)] h-px bg-[var(--color-bg-tertiary)] mx-2";function ko(t,r){o.useEffect(()=>{const a=i=>{t.current&&!t.current.contains(i.target)&&r()},n=i=>{i.key==="Escape"&&r()};return document.addEventListener("pointerdown",a,!0),document.addEventListener("keydown",n),()=>{document.removeEventListener("pointerdown",a,!0),document.removeEventListener("keydown",n)}},[t,r])}function ot(t,r){return!t.document_type||r!==null&&t.owner_id===r}function ia(t,r){return r!==null&&t.is_folder===!0&&t.owner_id===r}function Wc({state:t,onClose:r,onOpen:a,onPreview:n,onRename:i,onDelete:l,onShare:c,onDownload:u,onDuplicate:x,onCopy:m,onMoveTo:v,onShowInfo:p,onToggleStar:y,onManageTags:R,onRequestFiles:k,onCopyLink:F,onRestore:U,onPermanentDelete:W,isTrash:T,onNavigate:L}){const{file:h}=t,N=o.useRef(null),f=ct(I=>{var Z;return((Z=I.user)==null?void 0:Z.id)??null}),b=h.owner_id===f||h.role==="editor"||h.role==="owner",j=o.useMemo(()=>qc(h),[h]),[E,q]=o.useState(!1);ko(N,r);const D=I=>{I(),r()},O=wo,K=vt,X=No,S=A(K,"text-[var(--color-error-text)] hover:bg-[var(--color-error-subtle)] hover:text-[var(--color-error-text)]");return Xa.createPortal(e.jsx("div",{ref:N,className:O,style:{left:t.x,top:t.y},role:"menu","aria-label":"File context menu",children:T?e.jsxs(e.Fragment,{children:[U&&e.jsxs("div",{className:K,role:"menuitem",onClick:()=>D(()=>U(h)),"data-testid":"file-context-restore",children:[e.jsx(Qr,{size:16}),"Restore"]}),!h.is_folder&&!h.document_type&&e.jsxs("div",{className:K,role:"menuitem",onClick:()=>D(()=>u(h)),"data-testid":"file-context-download",children:[e.jsx(De,{size:16}),"Download"]}),e.jsx("div",{className:X,role:"separator"}),W&&e.jsxs("div",{className:S,role:"menuitem",onClick:()=>D(()=>W(h)),"data-testid":"file-context-delete-permanent",children:[e.jsx(oe,{size:16}),"Delete forever"]})]}):h.document_type?e.jsxs(e.Fragment,{children:[x&&e.jsxs("div",{className:K,role:"menuitem",onClick:()=>D(()=>x(h)),"data-testid":"file-context-duplicate",children:[e.jsx(it,{size:16}),"Make a copy"]}),e.jsxs("div",{className:K,role:"menuitem",onClick:()=>{const I=cr(h);I&&window.open(I,"_blank"),r()},"data-testid":"file-context-open-new-tab",children:[e.jsx(ts,{size:16}),"Open in new tab"]}),e.jsx("div",{className:X,role:"separator"}),b&&e.jsxs("div",{className:K,role:"menuitem",onClick:()=>D(()=>i(h)),"data-testid":"file-context-rename",children:[e.jsx(lt,{size:16}),"Rename"]}),c&&h.document_type!=="form"&&e.jsxs("div",{className:K,role:"menuitem",onClick:()=>D(()=>setTimeout(()=>c(h),0)),"data-testid":"file-context-share",children:[e.jsx(he,{size:16}),"Share"]}),e.jsx("div",{className:X,role:"separator"}),y&&e.jsxs("div",{className:K,role:"menuitem",onClick:()=>D(()=>y(h)),"data-testid":"file-context-star",children:[e.jsx(Fe,{size:16,className:h.starred?"text-[var(--color-warning)]":"",fill:h.starred?"currentColor":"none"}),h.starred?"Remove from starred":"Add to starred"]}),R&&ot(h,f)&&e.jsxs("div",{className:K,role:"menuitem",onClick:()=>D(()=>R(h)),"data-testid":"file-context-manage-tags",children:[e.jsx(Ve,{size:16}),"Manage tagsâ¦"]}),p&&e.jsxs("div",{className:K,role:"menuitem",onClick:()=>D(()=>p(h)),"data-testid":"file-context-info",children:[e.jsx(ye,{size:16}),"File info"]}),b&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:X,role:"separator"}),e.jsxs("div",{className:S,role:"menuitem",onClick:()=>D(()=>l(h)),"data-testid":"file-context-delete",children:[e.jsx(oe,{size:16}),"Move to trash"]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:K,role:"menuitem",onClick:()=>D(()=>!h.is_folder&&n?n(h):a(h)),"data-testid":"file-context-open",children:[h.is_folder?e.jsx(xe,{size:16}):e.jsx(ye,{size:16}),h.is_folder?"Open":"Preview"]}),!h.is_folder&&j.length>0&&e.jsxs("div",{className:"relative",onMouseEnter:()=>q(!0),onMouseLeave:()=>q(!1),children:[e.jsxs("div",{className:A(K,"justify-between"),role:"menuitem","aria-haspopup":"true","data-testid":"file-context-open-with-trigger",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Pi,{size:16}),"Open with"]}),e.jsx(Mt,{size:14,className:"text-[var(--color-text-quaternary)]"})]}),E&&e.jsx("div",{className:"absolute left-full top-0 ml-1 py-2 min-w-[160px] bg-[var(--color-surface-2)] border border-[var(--color-bg-tertiary)] rounded-[var(--radius-lg)] shadow-[var(--shadow-lg)] z-[10000]",role:"menu","aria-label":"Open with app",children:j.map(I=>e.jsxs("div",{className:K,role:"menuitem",onClick:()=>D(()=>L(I.route(h.id))),"data-testid":`file-context-open-with-${I.label.toLowerCase()}`,children:[I.icon,I.label]},I.label))})]}),!h.is_folder&&e.jsx("div",{className:X,role:"separator"}),!h.is_folder&&e.jsxs("div",{className:K,role:"menuitem",onClick:()=>D(()=>u(h)),"data-testid":"file-context-download",children:[e.jsx(De,{size:16}),"Download"]}),!h.is_folder&&m&&e.jsxs("div",{className:K,role:"menuitem",onClick:()=>D(()=>m(h)),"data-testid":"file-context-copy",children:[e.jsx(it,{size:16}),"Make a copy"]}),v&&e.jsxs("div",{className:K,role:"menuitem",onClick:()=>D(()=>v(h)),"data-testid":"file-context-move",children:[e.jsx(xe,{size:16}),"Move toâ¦"]}),b&&e.jsxs("div",{className:K,role:"menuitem",onClick:()=>D(()=>i(h)),"data-testid":"file-context-rename",children:[e.jsx(lt,{size:16}),"Rename"]}),c&&e.jsxs("div",{className:K,role:"menuitem",onClick:()=>D(()=>setTimeout(()=>c(h),0)),"data-testid":"file-context-share",children:[e.jsx(he,{size:16}),"Share"]}),F&&e.jsxs("div",{className:K,role:"menuitem",onClick:()=>D(()=>F(h)),"data-testid":"file-context-copy-link",children:[e.jsx(ta,{size:16}),"Copy link"]}),R&&e.jsxs("div",{className:K,role:"menuitem",onClick:()=>D(()=>R(h)),"data-testid":"file-context-manage-tags",children:[e.jsx(Ve,{size:16}),"Manage tagsâ¦"]}),ia(h,f)&&k&&e.jsxs("div",{className:K,role:"menuitem",onClick:()=>D(()=>k(h)),"data-testid":"file-context-request-files",children:[e.jsx(ea,{size:16}),"Request filesâ¦"]}),e.jsx("div",{className:X,role:"separator"}),y&&e.jsxs("div",{className:K,role:"menuitem",onClick:()=>D(()=>y(h)),"data-testid":"file-context-star",children:[e.jsx(Fe,{size:16,className:h.starred?"text-[var(--color-warning)]":"",fill:h.starred?"currentColor":"none"}),h.starred?"Remove from starred":"Add to starred"]}),p&&e.jsxs("div",{className:K,role:"menuitem",onClick:()=>D(()=>p(h)),"data-testid":"file-context-info",children:[e.jsx(ye,{size:16}),"File info"]}),b&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:X,role:"separator"}),e.jsxs("div",{className:S,role:"menuitem",onClick:()=>D(()=>l(h)),"data-testid":"file-context-delete",children:[e.jsx(oe,{size:16}),"Move to trash"]})]})]})}),document.body)}function Kc({state:t,onClose:r,onNewFolder:a,onUploadFile:n,onUploadFolder:i,onCreateDocument:l,creatingDoc:c}){const u=o.useRef(null),[x,m]=o.useState(t);ko(u,r),o.useLayoutEffect(()=>{const p=u.current;p&&m({x:Math.max(8,Math.min(t.x,window.innerWidth-p.offsetWidth-8)),y:Math.max(8,Math.min(t.y,window.innerHeight-p.offsetHeight-8))})},[t]);const v=p=>{p(),r()};return Xa.createPortal(e.jsxs("div",{ref:u,className:wo,style:{left:x.x,top:x.y},role:"menu","aria-label":"Drive actions","data-testid":"drive-blank-context-menu",children:[e.jsxs("div",{className:vt,role:"menuitem",onClick:()=>v(a),"data-testid":"drive-blank-context-new-folder",children:[e.jsx(Hr,{size:16}),"New folder"]}),e.jsxs("div",{className:vt,role:"menuitem",onClick:()=>v(n),"data-testid":"drive-blank-context-upload-file",children:[e.jsx(Et,{size:16}),"Upload file"]}),e.jsxs("div",{className:vt,role:"menuitem",onClick:()=>v(i),"data-testid":"drive-blank-context-upload-folder",children:[e.jsx(xe,{size:16}),"Upload folder"]}),e.jsx("div",{className:No,role:"separator"}),e.jsxs("div",{className:A(vt,c&&"opacity-50 pointer-events-none"),role:"menuitem","aria-disabled":!!c,onClick:()=>v(()=>l("doc")),"data-testid":"drive-blank-context-new-doc",children:[e.jsx(rs,{size:16,className:"text-[var(--color-module-docs)]"}),"New document"]}),e.jsxs("div",{className:A(vt,c&&"opacity-50 pointer-events-none"),role:"menuitem","aria-disabled":!!c,onClick:()=>v(()=>l("sheet")),"data-testid":"drive-blank-context-new-sheet",children:[e.jsx(as,{size:16,className:"text-[var(--color-module-sheets)]"}),"New spreadsheet"]}),e.jsxs("div",{className:A(vt,c&&"opacity-50 pointer-events-none"),role:"menuitem","aria-disabled":!!c,onClick:()=>v(()=>l("slide")),"data-testid":"drive-blank-context-new-slide",children:[e.jsx(ss,{size:16,className:"text-[var(--color-module-slides)]"}),"New presentation"]})]}),document.body)}const Vc=["my_drive"];function ms(t,r){const{selectedFiles:a}=V.getState(),n=a.size>1&&a.has(r.id)?[...a]:[r.id];t.dataTransfer.setData(dr,r.id),t.dataTransfer.setData(mo,JSON.stringify(n)),t.dataTransfer.setData("text/plain",r.name),t.dataTransfer.effectAllowed="move"}function Yr(t){return t.dataTransfer.types.includes(dr)}function So(t){return Vi(t.dataTransfer.types,[dr])}function xs(t,{dragOverId:r,onDragOverChange:a,onDrop:n,isTrash:i}){const l=t.is_folder&&!i;return{...l?{[Va]:t.id}:{},onDragOver:c=>{if(!l)return;const u=Yr(c);!u&&!So(c)||(c.preventDefault(),c.dataTransfer.dropEffect=u?"move":"copy",a==null||a(t.id))},onDragLeave:()=>{r===t.id&&(a==null||a(null))},onDrop:c=>{if(a==null||a(null),!l||!Yr(c))return;c.preventDefault();const u=ho(c.dataTransfer).filter(x=>x!==t.id);u.length>0&&(n==null||n(u,t.id))}}}function hs(t){return vl(t.document_type)}function Zr(t){switch(t.document_type){case"doc":return"docs";case"sheet":return"sheets";case"slide":return"slides";case"form":return"forms";default:return null}}function Hc(t,r){const[a,n]=o.useState(null),[i,l]=o.useState(!1),c=ns();return o.useEffect(()=>{if(!r||c)return;let u=!1;return Qn(t).then(x=>{u||n(x)}).catch(()=>{u||l(!0)}),()=>{u=!0}},[t,r,c]),{url:a,error:i}}function Gc(t,r,a){const[n,i]=o.useState(null),[l,c]=o.useState(!1);return o.useEffect
39(()=>{if(!a)return;let u=!1;return c(!1),cl(t,r).then(x=>{u||i(x)}).catch(()=>{u||c(!0)}),()=>{u=!0}},[t,r,a]),{url:n,error:l}}const Yc=4;function Co({file:t,className:r,fallback:a,enableDocumentThumbnail:n=!1}){const i=!t.is_folder&&(t.mime_type||"").startsWith("image/"),l=!t.is_folder&&(t.mime_type||"").startsWith("video/"),{url:c,error:u}=Hc(t.id,i||l),x=i?c:null,[m,v]=o.useState(!1),p=n&&!!t.document_type&&["doc","sheet","slide"].includes(t.document_type),{url:y,error:R}=Gc(t.id,t.updated_at,p);return i&&x&&!u&&!m?e.jsx("img",{src:x,alt:t.name,className:r,onError:()=>v(!0),onLoad:k=>{k.currentTarget.naturalWidth<Yc&&v(!0)},loading:"lazy"}):l&&c&&!u?e.jsxs("div",{className:A("relative",r),children:[e.jsx("video",{src:c,preload:"metadata",muted:!0,playsInline:!0,className:"w-full h-full object-cover"}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/20",children:e.jsx(Fi,{size:32,className:"text-white drop-shadow-md"})})]}):p&&y&&!R&&!m?e.jsx("img",{src:y,alt:t.name,className:r,"data-testid":`file-card-doc-thumb-${t.id}`,onError:()=>v(!0),loading:"lazy"}):e.jsx(e.Fragment,{children:a})}function _o(t){var a;const r=(a=t.shared_by)==null?void 0:a.display_name;return r?`Shared by ${r}`:"Shared"}function Zc(t){return`${_o(t)} · ${de(t.shared_at??null)}`}function Do(t){return!t.is_folder&&(t.mime_type||"").startsWith("image/")}function Ya(t){return t.is_folder?!1:(t.mime_type||"")==="application/pdf"||t.name.toLowerCase().endsWith(".pdf")}function Fo(t){return!t.is_folder&&(t.mime_type||"").startsWith("video/")}function Pa(t){return Do(t)||Ya(t)||Fo(t)}function Xc({size:t=18}){return e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}function zn(t){if(!t)return"â";try{return new Date(t).toLocaleString(void 0,{year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}catch{return"â"}}const Jc='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [contenteditable="true"], [tabindex]:not([tabindex="-1"])';function $n(t){return Array.from(t.querySelectorAll(Jc)).filter(r=>r.offsetParent!==null||r===document.activeElement)}function Qc({file:t,files:r,breadcrumbs:a,onClose:n,onDownload:i,onNavigate:l,onShare:c,onNavigateFolder:u}
39){const[x,m]=o.useState(null),[v,p]=o.useState(!0),[y,R]=o.useState(!1),k=o.useRef(null),F=nl({resetKey:t.id}),{commentsOpen:U,setCommentsOpen:W,mediaRef:T,regionLayer:L,fileLevelNotice:h,panel:N}=Nl({file:t,mediaReady:!v&&!y&&!!x,transform:F.contentProps.style.transform}),[f,w]=o.useState(()=>{const S=lr("drive.preview.showInfo");return S===null?!0:S==="1"}),b=o.useCallback(()=>{w(S=>{const I=!S;return Vr("drive.preview.showInfo",I?"1":"0"),I})},[]),j=r.findIndex(S=>S.id===t.id),E=j>0,q=j<r.length-1;o.useEffect(()=>{p(!0),R(!1);let S=!1;return(Ya(t)?ml:Qn)(t.id).then(Z=>{S||(m(Z),p(!1))}).catch(()=>{S||(R(!0),p(!1))}),()=>{S=!0}},[t.id]),o.useEffect(()=>{const S=I=>{if(I.key==="Escape"){n();return}if(I.key==="ArrowLeft"&&E){l(r[j-1]);return}if(I.key==="ArrowRight"&&q){l(r[j+1]);return}if(I.key==="i"&&!I.metaKey&&!I.ctrlKey&&!I.altKey){const Z=I.target;if(Z&&(Z.tagName==="INPUT"||Z.tagName==="TEXTAREA"||Z.isContentEditable))return;I.preventDefault(),b()}};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[n,E,q,r,j,l,b]),o.useEffect(()=>{const S=k.current;!S||S.contains(document.activeElement)||($n(S)[0]??S).focus()},[t.id]);const D=o.useCallback(S=>{if(S.key!=="Tab")return;const I=k.current;if(!I)return;const Z=$n(I);if(Z.length===0)return;const ae=Z[0],M=Z[Z.length-1],C=document.activeElement;S.shiftKey&&(C===ae||!C||!I.contains(C))?(S.preventDefault(),M.focus()):!S.shiftKey&&(C===M||!C||!I.contains(C))&&(S.preventDefault(),ae.focus())},[]),O=Do(t),K=Ya(t),X=Fo(t);return Xa.createPortal(e.jsxs("div",{ref:k,role:"dialog","aria-modal":"true","aria-label":t.name,tabIndex:-1,onKeyDown:D,className:"fixed inset-0 z-50 flex flex-col bg-black/80 backdrop-blur-sm","data-testid":"file-preview-overlay",children:[e.jsxs("div",{className:"flex flex-wrap md:flex-nowrap items-center justify-between gap-x-3 gap-y-2 px-4 py-3 bg-[var(--color-bg-primary)]/95 backdrop-blur border-b border-[var(--color-bg-tertiary)]",children:[e.jsxs("div",{className:"flex flex-col min-w-0 gap-0.5 basis-full md:basis-auto md:flex-1","data-testid":"preview-title-block",children:[a&&a.length>0&&e.jsx(ls,{ariaLabel:"File location",size:"s",items:a.map((S,I)=>{const Z=I===a.length-1;return{key:`${S.id??"root"}-${I}`,label:S.name,onClick:Z||!u?void 0:()=>{u(S.id),n()},dataTestId:`preview-breadcrumb-${I}`}})}),e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("span",{className:"shrink-0",children:nt(t,20)}),e.jsx("span",{className:"min-w-0 text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] font-medium text-[var(--color-text-primary)] truncate",title:t.name,"data-testid":"preview-file-name",children:t.name}),t.size_bytes!=null&&e.jsx("span",{className:"text-[length:var(--text-label-s)] leading-[var(--lh-label-s)] text-[var(--color-text-tertiary)] shrink-0 tabular-nums",children:Me(t.size_bytes)})]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0 ml-auto","data-testid":"preview-actions",children:[O&&e.jsx(ol,{tone:"light",zoom:F.zoom,zoomIn:F.zoomIn,zoomOut:F.zoomOut,reset:F.reset,canZoomIn:F.canZoomIn,canZoomOut:F.canZoomOut}),e.jsx("button",{onClick:()=>i(t),className:"pointer-coarse:min-h-11 pointer-coarse:min-w-11 p-2 flex items-center justify-center rounded-[var(--radius-md)] text-[var(--color-text-secondary)] hover:bg-[var(--color-bg-secondary)] transition-colors",title:"Download","aria-label":"Download",children:e.jsx(De,{size:18})}),c&&e.jsx("button",{onClick:()=>c(t),className:"pointer-coarse:min-h-11 pointer-coarse:min-w-11 p-2 flex items-center justify-center rounded-[var(--radius-md)] text-[var(--color-text-secondary)] hover:bg-[var(--color-bg-secondary)] transition-colors",title:"Share","aria-label":"Share","data-testid":"preview-share-button",children:e.jsx(he,{size:18})}),e.jsx("button",{onClick:()=>W(S=>!S),className:A("pointer-coarse:min-h-11 pointer-coarse:min-w-11 p-2 flex items-center justify-center rounded-[var(--radius-md)] transition-colors",U?"bg-[var(--color-accent-subtle)] text-[var(--color-accent)]":"text-[var(--color-text-secondary)] hover:bg-[var(--color-bg-secondary)]"),title:"Comments","aria-label":"Comments","aria-expanded":U,"data-testid":"preview-comments-toggle",children:e.jsx(Ti,{size:18})}),e.jsx("button",{onClick:b,className:A("hidden md:flex items-center justify-center p-2 rounded-[var(--radius-md)] transition-colors",f?"bg-[var(--color-accent-subtle)] text-[var(--color-accent)]":"text-[var(--color-text-secondary)] hover:bg-[var(--color-bg-secondary)]"),title:f?"Hide details":"Show details","aria-label":f?"Hide details":"Show details","aria-pressed":f,"data-testid":"preview-info-toggle",children:e.jsx(Xc,{size:18})}),e.jsx("button",{onClick:n,className:"pointer-coarse:min-h-11 pointer-coarse:min-w-11 p-2 flex items-center justify-center rounded-[var(--radius-md)] text-[var(--color-text-secondary)] hover:bg-[var(--color-bg-secondary)] transition-colors",title:"Close (Esc)","aria-label":"Close",children:e.jsx(gt,{size:18})})]})]}),e.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[e.jsxs("div",{className:"flex-1 relative flex items-center justify-center overflow-hidden",onClick:n,children:[E&&e.jsx("button",{onClick:S=>{S.stopPropagation(),l(r[j-1])},className:"absolute left-3 z-10 pointer-coarse:min-h-11 pointer-coarse:min-w-11 p-2 flex items-center justify-center rounded-full bg-[var(--color-bg-primary)]/90 text-[var(--color-text-secondary)] hover:bg-[var(--color-bg-primary)] shadow-lg transition-colors",title:"Previous (â)","aria-label":"Previous",children:e.jsx(Jr,{size:24})}),q&&e.jsx("button",{onClick:S=>{S.stopPropagation(),l(r[j+1])},className:"absolute right-3 z-10 pointer-coarse:min-h-11 pointer-coarse:min-w-11 p-2 flex items-center justify-center rounded-full bg-[var(--color-bg-primary)]/90 text-[var(--color-text-secondary)] hover:bg-[var(--color-bg-primary)] shadow-lg transition-colors",title:"Next (â)","aria-label":"Next",children:e.jsx(Mt,{size:24})}),v&&e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx(xn,{className:"w-48 h-36 rounded-[var(--radius-lg)]"}),e.jsx(xn,{className:"w-32 h-3"})]}),y&&e.jsxs("div",{className:"flex flex-col items-center gap-3",onClick:S=>S.stopPropagation(),children:[e.jsx("div",{className:"w-14 h-14 roun
39ded-2xl bg-[var(--color-bg-secondary)] flex items-center justify-center",children:nt(t,28)}),e.jsx("p",{className:"text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] text-[var(--color-text-secondary)]",children:"Unable to preview this file"}),e.jsxs(G,{variant:"secondary",size:"compact",onClick:()=>i(t),children:[e.jsx(De,{size:16}),"Download instead"]})]}),!v&&!y&&O&&x&&e.jsxs("div",{ref:T,className:"absolute inset-0 p-4 overflow-hidden",onClick:S=>{U&&S.stopPropagation()},children:[e.jsx(il,{src:x,alt:t.name,zoomPan:F,className:"absolute inset-0"}),L]}),!v&&!y&&X&&x&&e.jsx("div",{className:"w-full h-full flex items-center justify-center p-4",onClick:S=>S.stopPropagation(),children:e.jsx("video",{"data-testid":"file-preview-video",src:x,controls:!0,autoPlay:!0,playsInline:!0,title:t.name,className:"max-w-full max-h-full rounded-[var(--radius-lg)] bg-black"})}),!v&&!y&&K&&x&&e.jsxs("div",{className:"w-full h-full max-w-[900px] mx-auto p-4 flex flex-col gap-2",onClick:S=>S.stopPropagation(),children:[h,e.jsxs("div",{ref:T,className:"relative flex-1 min-h-0 overflow-hidden",children:[e.jsx("iframe",{src:x,title:t.name,"data-pinch-zoom":"true",className:"w-full h-full rounded-[var(--radius-lg)] bg-[var(--color-bg-primary)] border-0"}),L]})]})]}),N,f&&e.jsxs("aside",{className:"hidden md:block w-[280px] shrink-0 border-l border-[var(--color-bg-tertiary)] bg-[var(--color-bg-primary)] overflow-y-auto","data-testid":"preview-info-panel","aria-label":"File details",children:[e.jsx("div",{className:"px-4 py-3 border-b border-[var(--color-bg-tertiary)]",children:e.jsx("div",{className:"text-[length:var(--text-title-s)] leading-[var(--lh-title-s)] font-[600] text-[var(--color-text-primary)]",children:"Details"})}),e.jsxs("div",{className:"p-4 flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"shrink-0 mt-0.5",children:nt(t,24)}),e.jsx("div",{className:"min-w-0 text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] font-[500] text-[var(--color-text-primary)] break-words","data-testid":"preview-info-name",children:t.name})]}),e.jsxs("dl",{className:"grid grid-cols-[80px_1fr] gap-x-3 gap-y-3",children:[e.jsx("dt",{className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)]",children:"Type"}),e.jsx("dd",{className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-primary)] min-w-0 break-words",children:cs(t)}),!t.is_folder&&t.size_bytes!=null&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)]",children:"Size"}),e.jsx("dd",{className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-primary)] tabular-nums","data-testid":"preview-info-size",children:Me(t.size_bytes)})]}),e.jsx("dt",{className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)]",children:"Owner"}),e.jsx("dd",{className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-primary)] min-w-0","data-testid":"preview-info-owner",children:t.owner?e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(Rt,{name:t.owner.display_name,src:t.owner.avatar_url,size:"xs"}),e.jsx("span",{className:"truncate",children:t.owner.display_name})]}):"â"}),e.jsx("dt",{className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)]",children:"Created"}),e.jsx("dd",{className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-primary)] tabular-nums",children:zn(t.created_at)}),e.jsx("dt",{className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)]",children:"Modified"}),e.jsx("dd",{className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-primary)] tabular-nums",children:zn(t.updated_at)}),e.jsx("dt",{className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)]",children:"Sharing"}),e.jsx("dd",{className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-primary)]","data-testid":"preview-info-visibility",children:ur(t.visibility)})]}),c&&e.jsxs(G,{variant:"secondary",size:"compact",onClick:()=>
39c(t),"data-testid":"preview-info-share-button",children:[e.jsx(he,{size:16}),"Share"]})]})]})]}),e.jsxs("div",{className:"shrink-0 hidden md:flex items-center justify-center gap-5 px-4 py-2 bg-[var(--color-bg-primary)]/95 backdrop-blur border-t border-[var(--color-bg-tertiary)] text-[length:var(--text-label-s)] leading-[var(--lh-label-s)] text-[var(--color-text-tertiary)] overflow-x-auto [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden","data-testid":"preview-shortcut-hints",children:[e.jsx(sr,{keys:["Esc"],label:"Close"}),(E||q)&&e.jsx(sr,{keys:["â","â"],label:"Navigate"}),O&&e.jsxs(e.Fragment,{children:[e.jsx(sr,{keys:["â","+"],label:"Zoom in"}),e.jsx(sr,{keys:["â","0"],label:"Fit"})]}),e.jsx(sr,{keys:["i"],label:f?"Hide details":"Show details"})]})]}),document.body)}function sr({keys:t,label:r}){return e.jsxs("span",{className:"flex items-center gap-2 whitespace-nowrap shrink-0",children:[e.jsx("span",{className:"flex items-center gap-0.5",children:t.map((a,n)=>e.jsx("kbd",{className:"inline-flex items-center justify-center min-w-[20px] h-5 px-2 rounded-[var(--radius-sm)] bg-[var(--color-bg-secondary)] border border-[var(--color-bg-tertiary)] text-[var(--color-text-secondary)] font-medium tabular-nums",children:a},n))}),e.jsx("span",{children:r})]})}const Kr={gray:{bg:"var(--color-bg-tertiary)",fg:"var(--color-text-secondary)"},red:{bg:"var(--color-error-subtle)",fg:"var(--color-error-text)"},orange:{bg:"var(--color-orange-subtle)",fg:"var(--color-orange)"},yellow:{bg:"var(--color-warning-subtle)",fg:"var(--color-warning-text)"},green:{bg:"var(--color-success-subtle)",fg:"var(--color-success-text)"},blue:{bg:"var(--color-accent-subtle)",fg:"var(--color-accent-text)"},purple:{bg:"var(--color-purple-subtle)",fg:"var(--color-purple)"},pink:{bg:"var(--color-pink-subtle)",fg:"var(--color-pink)"},cyan:{bg:"var(--color-cyan-subtle)",fg:"var(--color-cyan)"}},zu=Object.keys(Kr);function zo(t){const r=Kr[t];if(r)return{backgroundColor:r.bg,color:r.fg};const a=Object.keys(Kr).filter(c=>c!=="gray"),n=Jn(t),i=a[n%a.length],l=Kr[i];return{backgroundColor:l.bg,color:l.fg}}function ed({tag:t,onRemove:r,className:a,testId:n}){return e.jsxs(aa,{variant:"default","data-testid":n,"data-tag-color":t.color,className:A("rounded-full gap-1 max-w-[140px]",a),style:zo(t.color),title:t.name,children:[e.jsx("span",{className:"truncate",children:t.name}),r&&e.jsx("button",{type:"button",onClick:i=>{i.stopPropagation(),r()},onPointerDown:i=>i.stopPropagation(),"aria-label":`Remove tag ${t.name}`,"data-testid":n?`${n}-remove`:void 0,className:"relative shrink-0 inline-flex items-center justify-center rounded-full hover:opacity-80 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-current before:absolute before:-inset-[7px] before:content-['']",children:e.jsx(gt,{size:10})})]})}
39function vs({file:t,removable:r,className:a,testId:n}){const i=V(c=>c.removeTagFromFile),l=t.tags??[];return l.length===0?null:e.jsx("div",{"data-testid":n,className:A("flex items-center gap-1 flex-wrap",a),children:l.map(c=>e.jsx(ed,{tag:c,testId:`${n??"file-tag"}-${c.id}`,onRemove:r?()=>{i(t.id,c.id).catch(()=>{P.error("Couldn't remove the tag. Try again.")})}:void 0},c.id))})}const Ia="text-[length:var(--text-label-s)] leading-[var(--lh-label-s)] text-[var(--color-text-tertiary)] tabular-nums";function td({file:t}){const r=de(t.updated_at);if(t.is_folder){if(t.child_count==null)return r?e.jsx("p",{className:A(Ia,"@[440px]/drivelist:hidden"),children:r}):null;const i=`${t.child_count} ${t.child_count===1?"item":"items"}`;return e.jsxs("p",{className:Ia,"data-testid":`file-row-meta-${t.id}`,children:[i,r&&e.jsx("span",{className:"@[440px]/drivelist:hidden",children:` · ${r}`})]})}const n=[t.document_type?hs(t):Me(t.size_bytes),r].filter(Boolean).join(" · ");return n?e.jsx("p",{className:A(Ia,"@[440px]/drivelist:hidden"),"data-testid":`file-row-meta-${t.id}`,children:n}):null}function En({children:t,testId:r}){return e.jsx("h2",{className:"px-3 max-md:px-0 pt-4 pb-1 text-[length:var(--text-label-s)] leading-[var(--lh-label-s)] font-semibold uppercase tracking-[0.05em] text-[var(--color-text-tertiary)]","data-testid":r,children:t})}function Or({file:t,onOpen:r,onPreview:a,onRename:n,onDelete:i,onShare:l,onDownload:c,onDuplicate:u,onCopy:x,onMoveTo:m,onShowInfo:v,onToggleStar:p,onManageTags:y,onRequestFiles:R,onDrop:k,dragOverId:F,onDragOverChange:U,isTrash:W,onRestore:T,onPermanentDelete:L,isSelected:h,onToggleSelect:N,selectionActive:f,onContextMenu:w,renameTarget:b,onRenameCommit:j,onRenameCancel:E}){var H;const q=ct($=>{var ue;return((ue=$.user)==null?void 0:ue.id)??null}),D=ct($=>{var ue;return((ue=$.user)==null?void 0:ue.display_name)??null}),O=t.owner_id===q,K=t.added_by?null:((H=t.owner)==null?void 0:H.display_name)??(O?D:null),X=O||t.role==="editor"||t.role==="owner",S=t.is_folder&&F===t.id,I=os(),Z=is({onLongPress:$=>{w&&w(t,$)},onTap:$=>C($)}),ae=$=>ms($,t),M=xs(t,{dragOverId:F,onDragOverChange:U,onDrop:k,isTrash:W}),C=$=>{f?($.preventDefault(),N==null||N(t,$)):r(t)};return e.jsxs("div",{draggable:!t.document_type,onDragStart:t.document_type?void 0:ae,...M,tabIndex:0,role:"row","aria-selected":h,"aria-label":t.name,className:A("flex items-center gap-3 px-3 py-3 rounded-[var(--radius-md)]","hover:bg-[var(--color-bg-secondary)] transition-colors duration-[var(--duration-micro)]","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)] focus-visible:ring-offset-1 focus-visible:ring-offset-[var(--color-bg-primary)]","group cursor-pointer",S&&"ring-2 ring-[var(--color-accent)] bg-[var(--color-accent-subtle)]",h&&"bg-[var(--color-accent-subtle)]"),...I?Z:{onClick:C,onContextMenu:$=>{w&&($.preventDefault(),w(t,$))}},onKeyDown:$=>{($.key==="Enter"||$.key===" ")&&($.preventDefault(),C($))},"data-testid":`file-row-${t.id}`,children:[e.jsx("div",{tabIndex:0,className:A("relative w-5 h-5 shrink-0 flex items-center justify-center rounded-[var(--radius-sm)] border transition-colors duration-[var(--duration-micro)]","pointer-coarse:before:content-[''] pointer-coarse:before:absolute pointer-coarse:before:-inset-3","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]",!f&&"max-md:hidden",h?"bg-[var(--color-accent)] border-[var(--color-accent)]":"border-[var(--color-border-control)] hover:border-[var(--color-text-tertiary)]"),onPointerDown:$=>$.stopPropagation(),onPointerUp:$=>$.stopPropagation(),onClick:$=>{$.stopPropagation(),N==null||N(t,$)},onKeyDown:$=>{($.key===" "||$.key==="Enter")&&($.preventDefault(),$.stopPropagation(),N==null||N(t,$))},role:"checkbox","aria-checked":h,"aria-label":`Select ${t.name}`,children:h&&e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:e.jsx("path",{d:"M2.5 6L5 8.5L9.5 3.5",stroke:"white",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),e.jsx("div",{className:"w-8 h-8 rounded-[var(--radius-md)] bg-[var(--color-bg-secondary)] group-hover:bg-[var(--color-accent-subtle)] flex items-center justify-center shrink-0 transition-colors duration-[var(--duration-micro)] overflow-hidden",children:e.jsx(Co,{file:t,className:"w-full h-full object-cover",fallback:nt(t)})}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col justify-center",children:[e.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[j?e.jsx(oa,{value:t.name,onCommit:async $=>{await j(t,$)},editing:(b==null?void 0:b.id)===t.id,onEditingChange:$=>{!$&&(b==null?void 0:b.id)===t.id&&(E==null||E())},readOnly:W,displayAsButton:!1,clickToEdit:!1,testId:`file-row-name-${t.id}`,lines:2,className:"w-auto min-w-0 text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] font-medium text-[var(--color-text-primary)] break-words"}):e.jsx("p",{className:"text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] font-medium text-[var(--color-text-primary)] line-clamp-2 break-words",children:t.name}),Zr(t)&&e.jsx(Xn,{label:hs(t),color:Zr(t),size:"sm",className:"shrink-0 hidden @[560px]/drivelist:inline-flex",testId:`file-row-module-badge-${t.id}`}),t.visibility&&t.visibility!=="restricted"&&e.jsx("span",{className:"shrink-0 flex items-center gap-1 text-[length:var(--text-label-s)] leading-[var(--lh-label-s)] text-[var(--color-text-tertiary)]",title:ur(t.visibility),"data-testid":`file-row-visibility-${t.id}`,children:e.jsx(Qa,{size:12})}),t.tags&&t.tags.length>0&&e.jsx(vs,{file:t,removable:O&&!W,testId:`file-row-tags-${t.id}`,className:"hidden md:flex shrink"})]}),t.shared_at&&e.jsxs("p",{className:"flex min-w-0 text-[length:var(--text-label-s)] leading-[var(--lh-label-s)] text-[var(--color-text-tertiary)]","data-testid":`file-row-shared-by-${t.id}`,children:[e.jsx("span",{className:"truncate",children:_o(t)}),e.jsx("span",{className:"shrink-0 whitespace-pre",children:` · ${de(t.shared_at)}`})]}),t.added_by?e.jsx(ds,{addedBy:t.added_by,className:"mt-0.5"}):e.jsx(td,{file:t})]}),e.jsx("span",{className:"text-[length:var(--text-label-s)] leading-[var(--lh-label-s)] text-[var(--color-text-tertiary)] shrink-0 hidden @[680px]/drivelist:inline w-[120px] truncate",children:K??"â"}),e.jsx("span",{className:"text-[length:var(--text-label-s)] leading-[var(--lh-label-s)] text-[var(--color-text-tertiary)] shrink-0 tabular-nums w-24 text-right hidden @[560px]/drivelist:inline",children:t.is_folder||t.document_type||t.size_bytes==null?"â":Me(t.size_bytes)}),e.jsx("span",{className:"hidden @[440px]/drivelist:inline text-[length:var(--text-label-s)] leading-[var(--lh-label-s)] text-[var(--color-text-tertiary)] shrink-0 tabular-nums w-[88px] text-right",children:de(t.updated_at)}),e.jsxs("div",{className:"flex items-center justify-end gap-0.5 shrink-0 @[440px]/drivelist:w-[72px]",children:[!t.is_folder&&!t.document_type&&e.jsx("button",{type:"button","data-testid":`file-row-download-${t.id}`,"aria-label":`Download ${t.name}`,onClick:$=>{$.stopPropagation(),c(t)},className:A("shrink-0 p-1 rounded-[var(--radius-sm)] transition-all duration-[var(--duration-micro)]","hover:bg-[var(--color-bg-tertiary)]","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]","text-[var(--color-text-tertiary)]","hidden @[560px]/drivelist:inline-flex opacity-0 group-hover:opacity-100 focus-visible:opacity-100"),title:"Download",children:e.jsx(De,{size:14})}),p&&e.jsx("button",{type:"button","data-testid":`file-row-star-${t.id}`,"aria-label":t.starred?`Unstar ${t.name}`:`Star ${t.name}`,"aria-pressed":!!t.starred,onClick:$=>{$.stopPropagation(),p(t)},className:A("shrink-0 p-1 rounded-[var(--radius-sm)] transition-all duration-[var(--duration-micro)]","hover:bg-[var(--color-bg-tertiary)]","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]","pointer-coarse:w-11 pointer-coarse:h-11 pointer-coarse:flex pointer-coarse:items-center pointer-coarse:justify-center",t.starred?"opacity-100 text-[var(--color-warning)]":"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 max-md:hidden text-[var(--color-text-tertiary)]"),title:t.starred?"Unstar":"Add to starred",children:e.jsx(Fe,{size:14,fill:t.
39starred?"currentColor":"none"})}),e.jsx("div",{className:A("shrink-0",f&&"max-md:hidden"),onClick:$=>$.stopPropagation(),onPointerDown:$=>$.stopPropagation(),onMouseDown:$=>$.stopPropagation(),onContextMenu:$=>{$.preventDefault(),$.stopPropagation()},children:e.jsxs(Se,{children:[e.jsx(Ce,{asChild:!0,children:e.jsx("button",{className:A("p-1 rounded-[var(--radius-sm)] text-[var(--color-text-tertiary)]","hover:bg-[var(--color-bg-tertiary)] transition-colors icon-interactive","pointer-coarse:min-w-11 pointer-coarse:min-h-11 pointer-coarse:flex pointer-coarse:items-center pointer-coarse:justify-center","opacity-0 group-hover:opacity-100 focus:opacity-100 pointer-coarse:opacity-100 max-md:opacity-100"),"data-testid":`file-menu-${t.id}`,"aria-label":`File actions for ${t.name}`,children:e.jsx(es,{size:16})})}),e.jsx(_e,{align:"end",children:W?e.jsxs(e.Fragment,{children:[T&&e.jsxs(z,{onSelect:()=>T(t),children:[e.jsx(Qr,{size:16}),"Restore"]}),!t.is_folder&&!t.document_type&&e.jsxs(z,{onSelect:()=>c(t),children:[e.jsx(De,{size:16}),"Download"]}),e.jsx(ie,{}),L&&e.jsxs(z,{onSelect:()=>L(t),className:"text-[var(--color-error-text)] focus:text-[var(--color-error-text)]",children:[e.jsx(oe,{size:16}),"Delete forever"]})]}):t.document_type?e.jsxs(e.Fragment,{children:[a&&t.document_type!=="form"&&e.jsxs(e.Fragment,{children:[e.jsxs(z,{onSelect:()=>a(t),children:[e.jsx(ye,{size:16}),"Preview"]}),e.jsx(ie,{})]}),u&&e.jsxs(z,{onSelect:()=>u(t),children:[e.jsx(it,{size:16}),"Make a copy"]}),e.jsxs(z,{onSelect:()=>{const $=cr(t);$&&window.open($,"_blank")},children:[e.jsx(ts,{size:16}),"Open in new tab"]}),e.jsx(ie,{}),X&&e.jsxs(z,{onSelect:()=>n(t),children:[e.jsx(lt,{size:16}),"Rename"]}),l&&t.document_type!=="form"&&e.jsxs(z,{onSelect:()=>setTimeout(()=>l(t),0),children:[e.jsx(he,{size:16}),"Share"]}),e.jsx(ie,{}),p&&e.jsxs(z,{onSelect:()=>p(t),children:[e.jsx(Fe,{size:16,className:t.starred?"text-[var(--color-warning)]":"",fill:t.starred?"currentColor":"none"}),t.starred?"Remove from starred":"Add to starred"]}),y&&ot(t,q)&&e.jsxs(z,{onSelect:()=>y(t),children:[e.jsx(Ve,{size:16}),"Manage tagsâ¦"]}),v&&e.jsxs(z,{onSelect:()=>v(t),children:[e.jsx(ye,{size:16}),"File info"]}),X&&e.jsxs(e.Fragment,{children:[e.jsx(ie,{}),e.jsxs(z,{onSelect:()=>i(t),className:"text-[var(--color-error-text)] focus:text-[var(--color-error-text)]",children:[e.jsx(oe,{size:16}),"Move to trash"]})]})]}):e.jsxs(e.Fragment,{children:[!t.is_folder&&a&&e.jsxs(z,{onSelect:()=>a(t),children:[e.jsx(ye,{size:16}),"Preview"]}),!t.is_folder&&e.jsxs(z,{onSelect:()=>c(t),children:[e.jsx(De,{size:16}),"Download"]}),!t.is_folder&&x&&e.jsxs(z,{onSelect:()=>x(t),children:[e.jsx(it,{size:16}),"Make a copy"]}),X&&m&&e.jsxs(z,{onSelect:()=>m(t),children:[e.jsx(xe,{size:16}),"Move toâ¦"]}),X&&e.jsxs(z,{onSelect:()=>n(t),children:[e.jsx(lt,{size:16}),"Rename"]}),l&&e.jsxs(z,{onSelect:()=>setTimeout(()=>l(t),0),children:[e.jsx(he,{size:16}),"Share"]}),e.jsx(ie,{}),p&&e.jsxs(z,{onSelect:()=>p(t),children:[e.jsx(Fe,{size:16,className:t.starred?"text-[var(--color-warning)]":"",fill:t.starred?"currentColor":"none"}),t.starred?"Remove from starred":"Add to starred"]}),y&&ot(t,q)&&e.jsxs(z,{onSelect:()=>y(t),children:[e.jsx(Ve,{size:16}),"Manage tagsâ¦"]}),ia(t,q)&&R&&e.jsxs(z,{onSelect:()=>R(t),children:[e.jsx(ea,{size:16}),"Request filesâ¦"]}),t.is_folder&&!W&&e.jsxs(z,{onSelect:()=>void us(t.id),"data-testid":"folder-menu-copy-link",children:[e.jsx(ta,{size:16}),"Copy link"]}),v&&e.jsxs(z,{onSelect:()=>v(t),children:[e.jsx(ye,{size:16}),"File info"]}),X&&e.jsxs(e.Fragment,{children:[e.jsx(ie,{}),e.jsxs(z,{onSelect:()=>i(t),className:"text-[var(--color-error-text)] focus:text-[var(--color-error-text)]",children:[e.jsx(oe,{size:16}),"Move to trash"]})]})]})})]})})]})]})}function Ln({file:t,onOpen:r,onRename:a,onDelete:n,onShare:i,onRequestFiles:l,onMoveTo:c,onShowInfo:u,onToggleStar:x,onManageTags:m,onDrop:v,dragOverId:p,onDragOverChange:y,isTrash:R,onRestore:k,onPermanentDelete:F,isSelected:U,onToggleSelect:W,selectionActive:T,onContextMenu:L,renameTarget:h,onRenameCommit:N,onRenameCancel:f}){const w=ct(S=>{var I;return((I=S.user)==null?void 0:I.id)??null}),b=t.owner_id===w,j=b||t.role==="editor"||t.role==="owner",E=p===t.id,q=os(),D=is({onLongPress:S=>{L&&L(t,S)},onTap:S=>X(S)}),O=S=>ms(S,t),K=xs(t,{dragOverId:p,onDragOverChange:y,onDrop:v,isTrash:R}),X=S=>{T?(S.preventDefault(),W==null||W(t,S)):r(t)};return e.jsxs("div",{draggable:!0,onDragStart:O,...K,className:A("flex flex-col rounded-[var(--radius-lg)] border relative",E?"border-[var(--color-accent)] ring-2 ring-[var(--color-accent)] bg-[var(--color-accent-subtle)]":U?"border-[var(--color-accent)] ring-2 ring-[var(--color-accent)]":"border-[var(--color-border-control)] hover:border-[var(--color-accent)]/50 hover:shadow-md hover:bg-[var(--color-accent-subtle)]","transition-all duration-[var(--duration-micro)]","overflow-hidden group cursor-pointer"),...q?D:{onClick:X,onContextMenu:S=>{L&&(S.preventDefault(),L(t,S))}},"data-testid":`folder-chip-${t.id}`,children:[e.jsx("div",{"data-testid":`folder-chip-thumb-${t.id}`,className:"h-[48px] flex items-center justify-center overflow-hidden bg-[var(--color-bg-tertiary)]",children:e.jsx(xe,{size:28,className:"text-[var(--color-text-secondary)]"})}),e.jsxs("div",{className:"h-[106px] overflow-hidden px-3 py-2 flex items-start gap-1 border-t border-[var(--color-border-control)] bg-[var(--color-bg-primary)]",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[N?e.jsx(oa,{value:t.name,onCommit:async S=>{await N(t,S)},editing:(h==null?void 0:h.id)===t.id,onEditingChange:S=>{!S&&(h==null?void 0:h.id)===t.id&&(f==null||f())},readOnly:R,displayAsButton:!1,clickToEdit:!1,testId:`folder-chip-name-${t.id}`,lines:2,className:"min-h-[calc(var(--lh-body-m)*2)] text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] font-semibold text-[var(--color-text-primary)] break-words"}):e.jsx("p",{className:"min-h-[calc(var(--lh-body-m)*2)] text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] font-semibold text-[var(--color-text-primary)] line-clamp-2 break-words",title:t.name,"data-testid":`folder-chip-name-${t.id}`,children:t.name}),e.jsxs("div",{className:"mt-1 flex items-center gap-2 text-[length:var(--text-label-s)] leading-[var(--lh-label-s)] text-[var(--color-text-tertiary)] tabular-nums",children:[t.visibility&&t.visibility!=="restricted"&&e.jsx("span",{title:ur(t.visibility),"data-testid":`folder-chip-visibility-${t.id}`,children:e.jsx(Qa,{size:12})}),e.jsx("span",{className:"truncate","data-testid":`folder-chip-meta-${t.id}`,children:(()=>{const S=de(t.updated_at),I=t.child_count,Z=I===void 0?null:I===1?"1 item":`${I} items`;return Z&&S?`${Z} · ${S}`:Z||(S??" ")})()})]}),t.tags&&t.tags.length>0&&e.jsx(vs,{file:t,removable:b&&!R,testId:`folder-chip-tags-${t.id}`,className:"mt-2"})]}),e.jsx("div",{className:"shrink-0",onClick:S=>S.stopPropagation(),onPointerDown:S=>S.stopPropagation(),onMouseDown:S=>S.stopPropagation(),onContextMenu:S=>{S.preventDefault(),S.stopPropagation()},children:e.jsxs(Se,{children:[e.jsx(Ce,{asChild:!0,children:e.jsx("button",{className:A("p-0.5 rounded-[var(--radius-sm)] text-[var(--color-text-tertiary)]","hover:bg-[var(--color-bg-tertiary)] transition-colors icon-interactive","pointer-coarse:min-w-11 pointer-coarse:min-h-11 pointer-coarse:flex pointer-coarse:items-center pointer-coarse:justify-center","opacity-0 group-hover:opacity-100 focus:opacity-100 pointer-coarse:opacity-100 max-md:opacity-100"),"aria-label":`Folder actions for ${t.name}`,"data-testid":`folder-menu-${t.id}`,children:e.jsx(es,{size:14})})}),e.jsx(_e,{align:"end",children:R?e.jsxs(e.Fragment,{children:[k&&e.jsxs(z,{onSelect:()=>k(t),children:[e.jsx(Qr,{size:16}),"Restore"]}),F&&e.jsxs(z,{onSelect:()=>
39F(t),className:"text-[var(--color-error-text)] focus:text-[var(--color-error-text)]",children:[e.jsx(oe,{size:16}),"Delete permanently"]})]}):e.jsxs(e.Fragment,{children:[j&&c&&e.jsxs(z,{onSelect:()=>c(t),children:[e.jsx(xe,{size:16}),"Move toâ¦"]}),j&&e.jsxs(z,{onSelect:()=>a(t),children:[e.jsx(lt,{size:16}),"Rename"]}),i&&e.jsxs(z,{onSelect:()=>i(t),children:[e.jsx(he,{size:16}),"Share"]}),e.jsx(ie,{}),x&&e.jsxs(z,{onSelect:()=>x(t),children:[e.jsx(Fe,{size:16,className:t.starred?"text-[var(--color-warning)]":"",fill:t.starred?"currentColor":"none"}),t.starred?"Remove from starred":"Add to starred"]}),m&&e.jsxs(z,{onSelect:()=>m(t),children:[e.jsx(Ve,{size:16}),"Manage tagsâ¦"]}),ia(t,w)&&l&&e.jsxs(z,{onSelect:()=>l(t),children:[e.jsx(ea,{size:16}),"Request filesâ¦"]}),t.is_folder&&!R&&e.jsxs(z,{onSelect:()=>void us(t.id),"data-testid":"folder-menu-copy-link",children:[e.jsx(ta,{size:16}),"Copy link"]}),u&&e.jsxs(z,{onSelect:()=>u(t),children:[e.jsx(ye,{size:16}),"File info"]}),j&&e.jsxs(e.Fragment,{children:[e.jsx(ie,{}),e.jsxs(z,{onSelect:()=>n(t),className:"text-[var(--color-error-text)] focus:text-[var(--color-error-text)]",children:[e.jsx(oe,{size:16}),"Move to trash"]})]})]})})]})})]})]})}function Mn({file:t,onOpen:r,onPreview:a,onRename:n,onDelete:i,onShare:l,onDownload:c,onDuplicate:u,onCopy:x,onMoveTo:m,onShowInfo:v,onToggleStar:p,onManageTags:y,onRequestFiles:R,onDrop:k,dragOverId:F,onDragOverChange:U,isTrash:W,onRestore:T,onPermanentDelete:L,isSelected:h,onToggleSelect:N,selectionActive:f,onContextMenu:w,renameTarget:b,onRenameCommit:j,onRenameCancel:E}){const q=ct(M=>{var C;return((C=M.user)==null?void 0:C.id)??null}),D=t.owner_id===q,O=D||t.role==="editor"||t.role==="owner",K=t.is_folder&&F===t.id,X=os(),S=is({onLongPress:M=>{w&&w(t,M)},onTap:M=>ae(M)}),I=M=>ms(M,t),Z=xs(t,{dragOverId:F,onDragOverChange:U,onDrop:k,isTrash:W}),ae=M=>{f?(M.preventDefault(),N==null||N(t,M)):r(t)};return e.jsxs("div",{draggable:!t.document_type,onDragStart:t.document_type?void 0:I,...Z,tabIndex:0,role:"gridcell","aria-selected":h,"aria-label":t.name,className:A("flex flex-col rounded-[var(--radius-lg)] border relative",K?"border-[var(--color-accent)] ring-2 ring-[var(--color-accent)] bg-[var(--color-accent-subtle)]":h?"border-[var(--color-accent)] ring-2 ring-[var(--color-accent)]":"border-[var(--color-border-control)] hover:border-[var(--color-accent)]/50 hover:shadow-md hover:bg-[var(--color-accent-subtle)]","transition-all duration-[var(--duration-micro)]","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)] focus-visible:ring-offset-1 focus-visible:ring-offset-[var(--color-bg-primary)]","overflow-hidden group cursor-pointer"),...X?S:{onClick:ae,onContextMenu:M=>{w&&(M.preventDefault(),w(t,M))}},onKeyDown:M=>{(M.key==="Enter"||M.key===" ")&&(M.preventDefault(),ae(M))},"data-testid":`file-card-${t.id}`,children:[e.jsx("div",{"data-testid":`file-card-select-${t.id}`,tabIndex:0,className:A("absolute top-2 left-2 z-10 w-5 h-5 flex items-center justify-center rounded-[var(--radius-sm)] border transition-all duration-[var(--duration-micro)]","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)] focus-visible:opacity-100",h?"bg-[var(--color-accent)] border-[var(--color-accent)]":A("border-[var(--color-border-control)] bg-[var(--color-bg-primary)]/90 group-hover:opacity-100",f?"opacity-100":"opacity-0")),onPointerDown:M=>M.stopPropagation(),onPointerUp:M=>M.stopPropagation(),onClick:M=>{M.stopPropagation(),N==null||N(t,M)},onKeyDown:M=>{(M.key===" "||M.key==="Enter")&&(M.preventDefault(),M.stopPropagation(),N==null||N(t,M))},role:"checkbox","aria-checked":h,"aria-label":`Select ${t.name}`,children:h&&e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:e.jsx("path",{d:"M2.5 6L5 8.5L9.5 3.5",stroke:"white",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),p&&e.jsx("button",{type:"button","data-testid":`file-card-star-${t.id}`,"aria-label":t.starred?`Unstar ${t.name}`:`Star ${t.name}`,"aria-pressed":!!t.starred,onClick:M=>{M.stopPropagation(),p(t)},className:A("absolute top-2 right-2 z-10 w-7 h-7 pointer-coarse:w-11 pointer-coarse:h-11 flex items-center justify-center rounded-[var(--radius-sm)]","bg-[var(--color-bg-primary)]/90 border border-[var(--color-border-control)]","hover:bg-[var(--color-bg-primary)] hover:border-[var(--color-text-quaternary)]","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]","transition-all duration-[var(--duration-micro)]",t.starred?"opacity-100 text-[var(--color-warning)]":"opacity-0 group-hover:opacity-100 pointer-coarse:opacity-100 focus-visible:opacity-100 text-[var(--color-text-tertiary)]"),title:t.starred?"Unstar":"Add to starred",children:e.jsx(Fe,{size:16,fill:t.starred?"currentColor":"none"})}),!t.is_folder&&!t.document_type&&e.jsx("button",{type:"button","data-testid":`file-card-download-${t.id}`,"aria-label":`Download ${t.name}`,onClick:M=>{M.stopPropagation(),c(t)},className:A("absolute top-2 right-11 pointer-coarse:right-16 z-10 w-7 h-7 pointer-coarse:w-11 pointer-coarse:h-11 flex items-center justify-center rounded-[var(--radius-sm)]","bg-[var(--color-bg-primary)]/90 border border-[var(--color-border-control)]","hover:bg-[var(--color-bg-primary)] hover:border-[var(--color-text-quaternary)]","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]","transition-all duration-[var(--duration-micro)]","text-[var(--color-text-tertiary)]","opacity-0 group-hover:opacity-100 focus-visible:opacity-100 pointer-coarse:hidden"),title:"Download",children:e.jsx(De,{size:16})}),e.jsxs("div",{"data-testid":`file-card-thumb-${t.id}`,className:"relative h-[96px] flex items-center justify-center overflow-hidden bg-[var(--color-bg-tertiary)]",children:[e.jsx(Co,{file:t,className:"w-full h-full object-cover",fallback:nt(t,32),enableDocumentThumbn
39ail:!0}),Zr(t)&&e.jsx("div",{className:"absolute bottom-1.5 left-1.5 z-10 pointer-events-none",children:e.jsx(Xn,{label:hs(t),color:Zr(t),size:"sm",onImage:!0,testId:`file-card-module-badge-${t.id}`,className:"shadow-sm"})})]}),e.jsxs("div",{className:"h-[106px] overflow-hidden px-3 py-2 flex items-start gap-1 border-t border-[var(--color-border-control)] bg-[var(--color-bg-primary)]",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[j?e.jsx(oa,{value:t.name,onCommit:async M=>{await j(t,M)},editing:(b==null?void 0:b.id)===t.id,onEditingChange:M=>{!M&&(b==null?void 0:b.id)===t.id&&(E==null||E())},readOnly:W,displayAsButton:!1,clickToEdit:!1,testId:`file-card-name-${t.id}`,lines:2,className:"min-h-[calc(var(--lh-body-m)*2)] text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] font-semibold text-[var(--color-text-primary)] break-words"}):e.jsx("p",{className:"min-h-[calc(var(--lh-body-m)*2)] text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] font-semibold text-[var(--color-text-primary)] line-clamp-2 break-words [word-break:break-word]",title:t.name,"data-testid":`file-card-name-${t.id}`,children:t.name}),e.jsxs("div",{className:"mt-1 flex min-w-0 items-center gap-2 text-[length:var(--text-label-s)] leading-[var(--lh-label-s)] text-[var(--color-text-tertiary)] tabular-nums",children:[t.owner&&!t.shared_at&&!t.added_by&&e.jsx(Rt,{name:t.owner.display_name,src:t.owner.avatar_url,size:"xxs"}),t.visibility&&t.visibility!=="restricted"&&e.jsx("span",{title:ur(t.visibility),"data-testid":`file-card-visibility-${t.id}`,children:e.jsx(Qa,{size:12})}),(()=>{if(t.shared_at)return e.jsx("span",{className:"truncate","data-testid":`file-card-shared-by-${t.id}`,children:Zc(t)});const M=de(t.updated_at),C=!t.is_folder&&!t.document_type&&t.size_bytes!=null?Me(t.size_bytes):null;return!M&&!C?e.jsx("span",{children:" "}):e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-x-1 overflow-hidden","data-testid":`file-card-meta-${t.id}`,children:[M&&e.jsx("span",{className:"min-w-0 truncate","data-testid":`file-card-meta-date-${t.id}`,children:M}),M&&C&&e.jsx("span",{className:"shrink-0","aria-hidden":"true",children:"·"}),C&&e.jsx("span",{className:"shrink-0 whitespace-nowrap",children:C})]})})()]}),t.added_by&&e.jsx(ds,{addedBy:t.added_by,className:"mt-1 max-w-full",compact:!0}),t.tags&&t.tags.length>0&&e.jsx(vs,{file:t,removable:D&&!W,testId:`file-card-tags-${t.id}`,className:"mt-2"})]}),e.jsx("div",{className:"shrink-0",onClick:M=>M.stopPropagation(),onPointerDown:M=>M.stopPropagation(),onMouseDown:M=>M.stopPropagation(),onContextMenu:M=>{M.preventDefault(),M.stopPropagation()},children:e.jsxs(Se,{children:[e.jsx(Ce,{asChild:!0,children:e.jsx("button",{className:A("p-0.5 rounded-[var(--radius-sm)] text-[var(--color-text-tertiary)]","hover:bg-[var(--color-bg-tertiary)] transition-colors icon-interactive","pointer-coarse:min-w-11 pointer-coarse:min-h-11 pointer-coarse:flex pointer-coarse:items-center pointer-coarse:justify-center","opacity-0 group-hover:opacity-100 focus:opacity-100 pointer-coarse:opacity-100 max-md:opacity-100"),"aria-label":`File actions for ${t.name}`,children:e.jsx(es,{size:14})})}),e.jsx(_e,{align:"end",children:W?e.jsxs(e.Fragment,{children:[T&&e.jsxs(z,{onSelect:()=>T(t),children:[e.jsx(Qr,{size:16}),"Restore"]}),!t.is_folder&&!t.document_type&&e.jsxs(z,{onSelect:()=>c(t),children:[e.jsx(De,{size:16}),"Download"]}),e.jsx(ie,{}),L&&e.jsxs(z,{onSelect:()=>L(t),className:"text-[var(--color-error-text)] focus:text-[var(--color-error-text)]",children:[e.jsx(oe,{size:16}),"Delete forever"]})]}):t.document_type?e.jsxs(e.Fragment,{children:[a&&t.document_type!=="form"&&e.jsxs(e.Fragment,{children:[e.jsxs(z,{onSelect:()=>a(t),children:[e.jsx(ye,{size:16}),"Preview"]}),e.jsx(ie,{})]}),u&&e.jsxs(z,{onSelect:()=>u(t),children:[e.jsx(it,{size:16}),"Make a copy"]}),e.jsxs(z,{onSelect:()=>{const M=cr(t);M&&window.open(M,"_blank")},children:[e.jsx(ts,{size:16}),"Open in new tab"]}),e.jsx(ie,{}),O&&e.jsxs(z,{onSelect:()=>n(t),children:[e.jsx(lt,{size:16}),"Rename"]}),l&&t.document_type!=="form"&&e.jsxs(z,{onSelect:()=>l(t),children:[e.jsx(he,{size:16}),"Share"]}),e.jsx(ie,{}),p&&e.jsxs(z,{onSelect:()=>
39p(t),children:[e.jsx(Fe,{size:16,className:t.starred?"text-[var(--color-warning)]":"",fill:t.starred?"currentColor":"none"}),t.starred?"Remove from starred":"Add to starred"]}),y&&ot(t,q)&&e.jsxs(z,{onSelect:()=>y(t),children:[e.jsx(Ve,{size:16}),"Manage tagsâ¦"]}),v&&e.jsxs(z,{onSelect:()=>v(t),children:[e.jsx(ye,{size:16}),"File info"]}),O&&e.jsxs(e.Fragment,{children:[e.jsx(ie,{}),e.jsxs(z,{onSelect:()=>i(t),className:"text-[var(--color-error-text)] focus:text-[var(--color-error-text)]",children:[e.jsx(oe,{size:16}),"Move to trash"]})]})]}):e.jsxs(e.Fragment,{children:[!t.is_folder&&a&&e.jsxs(z,{onSelect:()=>a(t),children:[e.jsx(ye,{size:16}),"Preview"]}),!t.is_folder&&e.jsxs(z,{onSelect:()=>c(t),children:[e.jsx(De,{size:16}),"Download"]}),!t.is_folder&&x&&e.jsxs(z,{onSelect:()=>x(t),children:[e.jsx(it,{size:16}),"Make a copy"]}),O&&m&&e.jsxs(z,{onSelect:()=>m(t),children:[e.jsx(xe,{size:16}),"Move toâ¦"]}),O&&e.jsxs(z,{onSelect:()=>n(t),children:[e.jsx(lt,{size:16}),"Rename"]}),l&&e.jsxs(z,{onSelect:()=>l(t),children:[e.jsx(he,{size:16}),"Share"]}),e.jsx(ie,{}),p&&e.jsxs(z,{onSelect:()=>p(t),children:[e.jsx(Fe,{size:16,className:t.starred?"text-[var(--color-warning)]":"",fill:t.starred?"currentColor":"none"}),t.starred?"Remove from starred":"Add to starred"]}),y&&ot(t,q)&&e.jsxs(z,{onSelect:()=>y(t),children:[e.jsx(Ve,{size:16}),"Manage tagsâ¦"]}),ia(t,q)&&R&&e.jsxs(z,{onSelect:()=>R(t),children:[e.jsx(ea,{size:16}),"Request filesâ¦"]}),t.is_folder&&!W&&e.jsxs(z,{onSelect:()=>void us(t.id),"data-testid":"folder-menu-copy-link",children:[e.jsx(ta,{size:16}),"Copy link"]}),v&&e.jsxs(z,{onSelect:()=>v(t),children:[e.jsx(ye,{size:16}),"File info"]}),O&&e.jsxs(e.Fragment,{children:[e.jsx(ie,{}),e.jsxs(z,{onSelect:()=>i(t),className:"text-[var(--color-error-text)] focus:text-[var(--color-error-text)]",children:[e.jsx(oe,{size:16}),"Move to trash"]})]})]})})]})})]})]})}function rd({open:t,onOpenChange:r,onCreate:a}){const[n,i]=o.useState(""),[l,c]=o.useState(!1),[u,x]=o.useState(null),m=async v=>{v.preventDefault();const p=n.trim();if(!p){x("Folder name is required");return}c(!0),x(null);try{await a(p),i(""),r(!1)}catch(y){x(y instanceof Error?y.message:"Failed to create folder")}finally{c(!1)}};return e.jsx(ze,{open:t,onOpenChange:r,children:e.jsxs($e,{children:[e.jsx(Ee,{children:e.jsx(Le,{children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Hr,{size:20,className:"text-[var(--color-accent)]"}),"New folder"]})})}),e.jsxs("form",{onSubmit:m,children:[e.jsx("input",{type:"text",value:n,onChange:v=>i(v.target.value),placeholder:"Folder name",autoFocus:!0,className:"w-full h-9 px-3 rounded-[var(--radius-md)] border border-[var(--color-bg-tertiary)] bg-[var(--color-bg-primary)] text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] text-[var(--color-text-primary)] placeholder:text-[var(--color-text-quaternary)] focus:outline-none focus:border-[var(--color-accent)] transition-colors mb-4"}),u&&e.jsx("p",{className:"mb-3 text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-error)]",children:u}),e.jsxs(He,{children:[e.jsx(G,{type:"button",variant:"ghost",onClick:()=>r(!1),children:"Cancel"}),e.jsx(G,{type:"submit",disabled:l||!n.trim(),children:l?"Creating...":"Create"})]})]})]})})}function ad({open:t,onOpenChange:r,fileName:a,isFolder:n,isTrash:i,onConfirm:l}){const c=i?`Permanently delete ${n?"folder":"file"}?`:`Move ${n?"folder":"file"} to trash?`,u=i?n?" and all its contents will be permanently deleted. This cannot be undone.":" will be permanently deleted. This cannot be undone.":n?" and all its contents will be moved to trash. Items stay in trash until you empty it.":" will be moved to trash. Items stay in trash until you empty it.";return i?e.jsx(ll,{open:t,onOpenChange:r,entityName:a,title:c,description:e.jsxs("span",{className:"break-words",children:[e.jsx("span",{className:"font-medium text-[var(--color-text-primary)]",children:a}),u]}),confirmLabel:"Permanently delete",onConfirm:l,testId:"delete-forever-confirm-dialog"}):e.jsx(Ke,{open:t,onOpenChange:r,title:c,description:e.jsxs("span",{className:"break-words",children:[e.jsx("span",{className:"font-medium text-[var(--color-text-primary)]",children:a}),u]}),confirmLabel:"Move to trash",onConfirm:async()=>{await l(),r(!1)}})}function sd(){const{storageUsage:t}
39=V(),[r,a]=o.useState(!1),[n,i]=o.useState(!1);if(!t||r)return null;const l=t.usedBytes/t.totalBytes;if(l<.8)return null;const c=l>=.95,u=l>=1,x=u||c?"var(--color-error-subtle)":"var(--color-warning-subtle)",m=u||c?"var(--color-error)":"var(--color-warning)",v=u||c?"var(--color-error-text)":"var(--color-warning-text)",p=u||c?"var(--color-error)":"var(--color-warning)",y=u?"Your storage is full. You won't be able to upload new files.":c?`Storage almost full â ${je(t.usedBytes)} of ${je(t.totalBytes)} used.`:`Running low on storage â ${je(t.usedBytes)} of ${je(t.totalBytes)} used.`;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 rounded-[var(--radius-md)] mb-4",style:{backgroundColor:x,border:`1px solid ${m}`},role:"alert","data-testid":"drive-storage-warning-banner",children:[e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:p,flexShrink:0},"aria-hidden":"true",children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),e.jsx("p",{className:"flex-1 text-[length:var(--text-body-m)] leading-[var(--lh-body-m)]",style:{color:v},children:y}),e.jsx("button",{onClick:()=>i(!0),className:"text-[length:var(--text-label-m)] leading-[var(--lh-label-m)] font-medium px-3 py-1 pointer-coarse:min-h-11 pointer-coarse:px-4 roun
39ded-[var(--radius-sm)] transition-colors duration-[var(--duration-micro)] hover:bg-[var(--color-bg-tertiary)]",style:{color:v},children:"Manage storage"}),e.jsx("button",{onClick:()=>a(!0),className:"p-1 pointer-coarse:min-h-11 pointer-coarse:min-w-11 pointer-coarse:flex pointer-coarse:items-center pointer-coarse:justify-center rounded-[var(--radius-sm)] hover:bg-[var(--color-bg-tertiary)] transition-colors duration-[var(--duration-micro)]",style:{color:v},"aria-label":"Dismiss warning",children:e.jsx(gt,{size:14})})]}),e.jsx(nd,{open:n,onOpenChange:i})]})}const Xr={Documents:"var(--color-accent)",Images:"var(--color-success)",Videos:"var(--color-purple)",Audio:"var(--color-pink)",Archives:"var(--color-orange)",Other:"var(--color-text-tertiary)"};function nd({open:t,onOpenChange:r}){const{storageUsage:a,storageBreakdown:n,loadStorageBreakdown:i}=V();o.useEffect(()=>{t&&!n&&i()},[t,n,i]);const l=a?a.usedBytes/a.totalBytes:0;return e.jsx(ze,{open:t,onOpenChange:r,children:e.jsxs($e,{className:"max-w-[480px]",children:[e.jsxs(Ee,{children:[e.jsx(Le,{children:"Storage"}),e.jsx(Re,{children:"See what's using your storage space."})]}),a&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-[length:var(--text-headline-s)] leading-[var(--lh-headline-s)] font-medium text-[var(--color-text-primary)] tabular-nums",children:je(a.usedBytes)}),e.jsxs("span",{className:"text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] text-[var(--color-text-tertiary)] tabular-nums",children:["of ",je(a.totalBytes)]})]}),e.jsx(na,{value:Math.max(1,Math.min(100,l*100)),size:"lg",className:A(l>=.9?"[&>div]:bg-[var(--color-error)]":l>=.75?"[&>div]:bg-[var(--color-warning)]":"[&>div]:bg-[var(--color-accent)]")}),e.jsxs("p",{className:"mt-2 text-[length:var(--text-label-s)] leading-[var(--lh-label-s)] text-[var(--color-text-tertiary)] tabular-nums",children:[a.fileCount," ",a.fileCount===1?"file":"files"," · ",Math.round(l*100),"% used"]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-[length:var(--text-title-s)] leading-[var(--lh-title-s)] font-semibold text-[var(--color-text-primary)] mb-3",children:"Storage breakdown"}),n?n.length>0?e.jsx("div",{className:"space-y-3",children:n.map(c=>{const u=a.totalBytes>0?c.usedBytes/a.totalBytes:0,x=Xr[c.category]||Xr.Other;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-3 h-3 rounded-full shrink-0",style:{backgroundColor:x}}),e.jsx("span",{className:"text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] text-[var(--color-text-primary)]",children:c.category})]}),e.jsxs("span",{className:"text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] text-[var(--color-text-secondary)] tabular-nums",children:[je(c.usedBytes),e.jsxs("span",{className:"text-[var(--color-text-tertiary)] ml-2",children:["(",c.fileCount," ",c.fileCount===1?"file":"files",")"]})]})]}),e.jsx("div",{className:"h-1 rounded-full bg-[var(--color-bg-tertiary)] overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${Math.max(.5,u*100)}%`,backgroundColor:x}})})]},c.category)})}):e.jsx("p",{className:"text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] text-[var(--color-text-tertiary)]",children:"No files yet."}):e.jsx("div",{className:"space-y-3",children:[1,2,3].map(c=>e.jsx(ir,{className:"h-8"},c))})]}),l>=.8&&e.jsx("p",{className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)] border-t border-[var(--color-bg-tertiary)] pt-4",children:"To free up space, empty your Trash or delete files you no longer need."})]}),e.jsxs(He,{children:[e.jsx(G,{variant:"ghost",onClick:()=>r(!1),children:"Close"}),e.jsx(G,{variant:"secondary",onClick:()=>{r(!1),V.getState().setActiveSection("trash")},children:"Go to Trash"})]})]})})}const Br=["#405EF2","#22C55E","#F59E0B","#EF4444","#8B5CF6","#EC4899","#06B6D4","#F97316","#8979CB","#10B981"];function $o({open:t,onOpenChange:r}){const[a,n]=o.useState(""),[i,l]=o.useState(""),[c,u]=o.useState(Br[0]),[x,m]=o.useState(!1),{createSharedDrive:v,openSharedDrive:p}=V(),y=o.useRef(null);o.useEffect(()=>{t&&(n(""),l(""),u(Br[Math.floor(Math.random()*Br.length)]),setTimeout(()=>{var k;return(k=y.current)==null?void 0:k.focus()},100))},[t]);const R=async()=>
39{if(!(!a.trim()||x)){m(!0);try{const k=await v(a.trim(),i.trim()||void 0,c);r(!1),p(k.id,k.name),P.success(`Created team drive "${k.name}"`)}catch{P.error("Failed to create team drive")}finally{m(!1)}}};return e.jsx(ze,{open:t,onOpenChange:r,children:e.jsxs($e,{className:"max-w-[420px]",children:[e.jsxs(Ee,{children:[e.jsx(Le,{children:"New team drive"}),e.jsx(Re,{children:"Where your team organizes shared files."})]}),e.jsxs("div",{className:"flex flex-col gap-4 py-2",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-[length:var(--text-label-m)] leading-[var(--lh-label-m)] font-medium text-[var(--color-text-secondary)]",children:"Name"}),e.jsx("input",{ref:y,type:"text",value:a,onChange:k=>n(k.target.value),onKeyDown:k=>k.key==="Enter"&&R(),placeholder:"e.g. Marketing, Engineering",className:"w-full px-3 py-2 rounded-[var(--radius-md)] border border-[var(--color-bg-tertiary)] bg-[var(--color-bg-primary)] text-[var(--color-text-primary)] text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] placeholder:text-[var(--color-text-quaternary)] focus:outline-none focus:ring-2 focus:ring-[var(--color-accent)] focus:border-transparent [@media(pointer:coarse)]:text-base"})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("label",{className:"text-[length:var(--text-label-m)] leading-[var(--lh-label-m)] font-medium text-[var(--color-text-secondary)]",children:["Description ",e.jsx("span",{className:"font-normal text-[var(--color-text-tertiary)]",children:"(optional)"})]}),e.jsx("input",{type:"text",value:i,onChange:k=>l(k.target.value),placeholder:"What is this drive for?",className:"w-full px-3 py-2 rounded-[var(--radius-md)] border border-[var(--color-bg-tertiary)] bg-[var(--color-bg-primary)] text-[var(--color-text-primary)] text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] placeholder:text-[var(--color-text-quaternary)] focus:outline-none focus:ring-2 focus:ring-[var(--color-accent)] focus:border-transparent [@media(pointer:coarse)]:text-base"})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-[length:var(--text-label-m)] leading-[var(--lh-label-m)] font-medium text-[var(--color-text-secondary)]",children:"Color"}),e.jsx("div",{className:"flex items-center gap-2",children:Br.map(k=>e.jsx("button",{onClick:()=>u(k),className:A("w-7 h-7 rounded-full transition-all duration-[var(--duration-micro)]",c===k?"ring-2 ring-offset-2 ring-[var(--color-accent)] ring-offset-[var(--color-bg-primary)]":"hover:scale-110"),style:{backgroundColor:k},"aria-label":`Color ${k}`},k))})]})]}),e.jsxs(He,{children:[e.jsx(G,{variant:"ghost",onClick:()=>r(!1),children:"Cancel"}),e.jsx(G,{onClick:R,disabled:!a.trim()||x,children:x?"Creating...":"Create"})]})]})})}function od(t){const r=t.user_name||"Someone",a=t.metadata||{},n=a.name||a.title||a.filename||"a file";switch(t.action){case"file.uploaded":return`${r} uploaded "${n}"`;case"file.deleted":return`${r} deleted "${n}"`;case"file.shared":return`${r} shared "${n}"`;case"file.renamed":return`${r} renamed "${n}"`;case"file.restored":return`${r} restored "${n}"`;case"file.starred":return`${r} starred "${n}"`;case"file.unstarred":return`${r} unstarred "${n}"`;case"folder.created":return`${r} created folder "${n}"`;case"folder.deleted":return`${r} deleted folder "${n}"`;default:return`${r} · ${t.action.replace(/^file\.|^folder\./,"")} "${n}"`}}function id(){const t=ra(),[r,a]=o.useState([]),[n,i]=o.useState(!0),[l,c]=o.useState(null),u=o.useCallback(async()=>{i(!0),c(null);try{const m=await be.activity.list({query:{resource_type:"file",limit:"50"}});a(m.data)}catch(m){c(m instanceof Error?m.message:"Couldnât load activity")}finally{i(!1)}},[]);o.useEffect(()=>{u()},[u]);const x=m=>{m.resource_type!=="file"||!m.resource_id||t(Ja(m.resource_id))};return e.jsxs("section",{"data-testid":"drive-activity-view","aria-labelledby":"drive-activity-heading",className:"rounded-[var(--radius-lg)] border border-[var(--color-bg-tertiary)] bg-[var(--color-surface-0)] overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-[var(--color-bg-tertiary)] flex items-center gap-2",children:[e.jsx(Wa,{size:16,className:"text-[var(--color-text-tertiary)]","aria-hidden":"true"}),e.jsx("h2",{id:"drive-activity-heading",className:"text-[length:var(--text-title-s)] leading-[var(--lh-title-s)] font-semibold text-[var(--color-text-primary)]",children:"Recent file activity"})]}),e.jsx("div",{"aria-live":"polite",children:n?e.jsx("div",{className:"py-1",children:[1,2,3,4,5].map(m=>e.jsx(st,{},m))}):l?e.jsxs("div",{className:"px-4 py-8 flex flex-col items-center gap-2 text-center","data-testid":"drive-activity-error",children:[e.jsx("p",{className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)]",children:"Couldnât load activity"}),e.jsx("button",{onClick:u,className:"text-[length:var(--text-label-m)
39] leading-[var(--lh-label-m)] font-medium text-[var(--color-accent-text)] hover:underline","data-testid":"drive-activity-retry",children:"Retry"})]}):r.length===0?e.jsxs("div",{className:"px-4 py-12 flex flex-col items-center gap-2 text-center","data-testid":"drive-activity-empty",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl bg-[var(--color-bg-secondary)] flex items-center justify-center mb-2",children:e.jsx(Wa,{size:28,className:"text-[var(--color-text-quaternary)]"})}),e.jsx("p",{className:"text-[length:var(--text-body-l)] leading-[var(--lh-body-l)] font-medium text-[var(--color-text-secondary)]",children:"No recent file activity"}),e.jsx("p",{className:"text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] text-[var(--color-text-tertiary)] max-w-[320px]",children:"When files are uploaded, edited, or shared, events will appear here."})]}):e.jsx("ul",{className:"divide-y divide-[var(--color-bg-tertiary)]",children:r.map(m=>e.jsxs("li",{className:"flex items-center gap-3 px-4 py-3 hover:bg-[var(--color-bg-secondary)] transition-colors duration-[var(--duration-micro)] cursor-pointer","data-testid":`drive-activity-row-${m.id}`,onClick:()=>x(m),role:"button",tabIndex:0,onKeyDown:v=>{(v.key==="Enter"||v.key===" ")&&(v.preventDefault(),x(m))},children:[e.jsx(Rt,{name:m.user_name||"Someone",src:m.user_avatar??void 0,size:"sm"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] text-[var(--color-text-primary)] truncate",children:od(m)}),e.jsx("p",{className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)] tabular-nums",children:de(m.created_at)})]})]},m.id))})})]})}function ld(){const{storageUsage:t,storageBreakdown:r,loadStorageUsage:a,loadStorageBreakdown:n}=V();o.useEffect(()=>{a(),n()},[a,n]);const i=t?t.usedBytes/t.totalBytes:0;return e.jsxs("section",{"data-testid":"drive-storage-view","aria-labelledby":"drive-storage-heading",className:"rounded-[var(--radius-lg)] border border-[var(--color-bg-tertiary)] bg-[var(--color-surface-0)] overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-[var(--color-bg-tertiary)] flex items-center gap-2",children:[e.jsx(Kn,{size:16,className:"text-[var(--color-text-tertiary)]","aria-hidden":"true"}),e.jsx("h2",{id:"drive-storage-heading",className:"text-[length:var(--text-title-s)] leading-[var(--lh-title-s)] font-semibold text-[var(--color-text-primary)]",children:"Storage"})]}),e.jsx("div",{className:"p-4",children:t?e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{"data-testid":"drive-storage-used",className:"text-[length:var(--text-headline-s)] leading-[var(--lh-headline-s)] font-medium text-[var(--color-text-primary)] tabular-nums",children:je(t.usedBytes)}),e.jsxs("span",{className:"text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] text-[var(--color-text-tertiary)] tabular-nums",children:["of ",je(t.totalBytes)]})]}),e.jsx(na,{value:Math.max(1,Math.min(100,i*100)),size:"lg","data-testid":"drive-storage-bar",className:A(i>=.9?"[&>div]:bg-[var(--color-error)]":i>=.75?"[&>div]:bg-[var(--color-warning)]":"[&>div]:bg-[var(--color-accent)]")}),e.jsxs("p",{className:"mt-2 text-[length:var(--text-label-s)] leading-[var(--lh-label-s)] text-[var(--color-text-tertiary)] tabular-nums",children:[t.fileCount," ",t.fileCount===1?"file":"files"," · ",Math.round(i*100),"% used"]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-[length:var(--text-title-s)] leading-[var(--lh-title-s)] font-semibold text-[var(--color-text-primary)] mb-3",children:"Storage breakdown"}),r?r.length>0?e.jsx("div",{className:"space-y-3","data-testid":"drive-storage-breakdown",children:r.map(l=>{const c=t.totalBytes>0?l.usedBytes/t.totalBytes:0,u=Xr[l.category]||Xr.Other;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-3 h-3 rounded-full shrink-0",style:{backgroundColor:u}}),e.jsx("span",{className:"text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] text-[var(--color-text-primary)]",children:l.category})]}),e.jsxs("span",{className:"text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] text-[var(--color-text-secondary)] tabular-nums",children:[je(l.usedBytes),e.jsxs("span",{className:"text-[var(--color-text-tertiary)] ml-2",children:["(",l.fileCount," ",l.fileCount===1?"file":"files",")"]})]})]}),e.jsx("div",{className:"h-1 rounded-full bg-[var(--color-bg-tertiary)] overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${Math.max(1,Math.min(100,c*100))}%`,backgroundColor:u}})})]},l.category)})}):e.jsx("p",{className:"text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] text-[var(--color-text-tertiary)]",children:"No files yet."}):e.jsx("div",{className:"space-y-3",children:[1,2,3].map(l=>e.jsx(ir,{className:"h-8"},l))})]}),i>=.8&&e.jsx("p",{className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)] border-t border-[var(--color-bg-tertiary)] pt-4",children:"To free up space, empty your Trash or delete files you no longer need."}),e.jsx("div",{className:"flex justify-end gap-2 border-t border-[var(--color-bg-tertiary)] pt-4",children:e.jsx(G,{variant:"secondary",size:"compact",onClick:()=>
39V.getState().setActiveSection("trash"),children:"Go to Trash"})})]}):e.jsxs("div",{className:"space-y-3","data-testid":"drive-storage-loading",children:[e.jsx(ir,{className:"h-5 w-40"}),e.jsx("div",{className:"h-3 rounded-full bg-[var(--color-bg-tertiary)]"}),e.jsx(ir,{className:"h-3 w-32"})]})})]})}const cd=6,Eo="drive.sidebar.folderTree.expanded";function dd(){return new Set(zi(Eo,[],{area:"session",shape:$i}))}function Aa(t){if(!(typeof window>"u"))try{window.sessionStorage.setItem(Eo,JSON.stringify([...t]))}catch{}}function Lo({folder:t,depth:r,childrenByParent:a,expanded:n,loadingParents:i,currentFolderId:l,onToggle:c,onNavigate:u}){const x=n.has(t.id),m=l===t.id,v=i.has(t.id),p=a.get(t.id)??[],y=r<cd,k=a.has(t.id)?p.length>0:t.child_count!==void 0?t.child_count>0:!0,F=8+r*12;return e.jsxs("div",{role:"treeitem","aria-expanded":k?x:void 0,"aria-level":r+1,children:[e.jsxs("div",{className:A("group relative flex items-center rounded-full transition-colors duration-[var(--duration-micro)]","text-[length:var(--text-body-m)] leading-[var(--lh-body-m)]",m?"bg-[var(--color-accent-subtle)] text-[var(--color-accent-text)] font-medium":"text-[var(--color-text-secondary)] hover:bg-[var(--color-bg-tertiary)]"),children:[k?e.jsx("button",{type:"button",onClick:U=>{U.stopPropagation(),c(t.id)},"aria-label":x?`Collapse ${t.name}`:`Expand ${t.name}`,className:"flex items-center justify-center w-5 h-5 shrink-0 rounded hover:bg-[var(--color-bg-tertiary)] text-[var(--color-text-tertiary)]",style:{marginLeft:`${F}px`},"data-testid":`drive-folder-tree-toggle-${t.id}`,children:e.jsx(Mt,{size:12,className:A("transition-transform duration-[var(--duration-micro)]",x&&"rotate-90")})}):e.jsx("span",{className:"w-5 h-5 shrink-0",style:{marginLeft:`${F}px`}}),e.jsxs("button",{type:"button",onClick:()=>u(t.id,t.name),className:"flex-1 flex items-center gap-2 pl-1 pr-3 py-2 text-left min-w-0","data-testid":`drive-folder-tree-node-${t.id}`,children:[e.jsx(xe,{size:16,className:A("shrink-0",m?"text-[var(--color-accent)]":"text-[var(--color-text-tertiary)]")}),e.jsx("span",{className:"truncate",children:t.name})]})]}),x&&k&&y&&e.jsxs("div",{role:"group",children:[v&&p.length===0&&e.jsx("div",{className:"flex items-center gap-2 py-2 text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)]",style:{paddingLeft:`${F+28}px`},"data-testid":`drive-folder-tree-loading-${t.id}`,children:"Loadingâ¦"}),p.map(U=>e.jsx(Lo,{folder:U,depth:r+1,childrenByParent:a,expanded:n,loadingParents:i,currentFolderId:l,onToggle:c,onNavigate:u},U.id))]}),x&&!y&&e.jsx("div",{className:"py-1 text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)]",style:{paddingLeft:`${F+28}px`},children:"Open folder to continueâ¦"})]})}function ud({isActive:t}){const{currentFolderId:r,navigateToFolder:a,loadFolders:n,files:i}=V(),l=ns(),c=Yn(),[u,x]=o.useState([]),[m,v]=o.useState(new Map),[p,y]=o.useState(()=>dd()),[R,k]=o.useState(new Set),[F,U]=o.useState(!1),[W,T]=o.useState(!1),[L,h]=o.useState(0),[N,f]=o.useState(!1);o.useEffect(()=>{l||!t||F||W||N||(T(!0),n(null).then(E=>{x(E),U(!0)}).catch(E=>{const q=E==null?void 0:E.status;!(q===void 0||q>=500)||L>=2?f(!0):h(O=>O+1)}).finally(()=>{T(!1)}))},[t,F,W,N,L,n,l]),o.useEffect(()=>{if(!t)return;const E=i.filter(q=>q.is_folder);r===null?x(E):v(q=>{const D=new Map(q);return D.set(r,E),D})},[t,i,r]);const w=o.useCallback(E=>{y(q=>{const D=new Set(q);return D.has(E)?(D.delete(E),Aa(D),D):(D.add(E),Aa(D),!m.has(E)&&!R.has(E)&&(k(O=>{const K=new Set(O);return K.add(E),K}),n(E).then(O=>{v(K=>{const X=new Map(K);return X.set(E,O),X}),O.length===0&&y(K=>{const X=new Set(K);return X.delete(E),Aa(X),X})}).catch(()=>{}).finally(()=>{k(O=>{const K=new Set(O);return K.delete(E),K})})),D)})},[m,R,n]),b=o.useCallback((E,q)=>{a(E,q),c==null||c()},[c,a]);if(!t)return null;const j=u.length>0;return e.jsxs("div",{role:"tree","aria-label":"Folder tree",className:"mt-1","data-testid":"drive-folder-tree",children:[W&&!F&&e.jsx("div",{className:"pl-8 py-1 text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)]","data-testid":"drive-folder-tree-root-loading",children:"Loadingâ¦"}),F&&!j&&e.jsx("div",{className:"pl-8 py-1 text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)]","data-testid":"drive-folder-tree-empty",children:"No folders yet"}),j&&u.map(E=>e.jsx(Lo,{folder:E,depth:0,childrenByParent:m,expanded:p,loadingParents:R,currentFolderId:r,onToggle:w,onNavigate:b},E.id))]})}function md(){const{sharedDrives:t,loadSharedDrives:r,openSharedDrive:a}=V(),[n,i]=o.useState(!1);return o.useEffect(()=>{r()},[r]),e.jsxs("div",{"data-testid":"drive-team-drives-picker",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h2",{className:"text-[length:var(--text-title-m)] leading-[var(--lh-title-m)] font-semibold text-[var(--color-text-primary)]",children:"Team drives"}),e.jsxs(G,{variant:"ghost",size:"compact",onClick:()=>i(!0),children:[e.jsx(bt,{size:16}),e.jsx("span",{className:"ml-1",children:"New"})]})]}),t.length===0?e.jsx(Zn,{variant:"page",icon:e.jsx(he,{size:28,className:"text-[var(--color-text-quaternary)]"}),title:"No team drives yet",description:"Create a team drive to share files with your team.",actions:[e.jsxs(G,{variant:"secondary",size:"compact",onClick:()=>i(!0),children:[e.jsx(bt,{size:16}),"New team drive"]},"new-team-drive")]}):e.jsx("div",{className:"grid gap-2",children:t.map(l=>e.jsxs("button",{type:"button",onClick:()=>a(l.id,l.name),className:"flex items-center gap-3 px-4 py-3 rounded-lg border border-[var(--color-border-control)] hover:bg-[var(--color-bg-secondary)] transition-colors duration-[var(--duration-micro)] text-left","data-testid":`team-drive-picker-${l.id}`,children:[e.jsx("span",{className:"w-8 h-8 rounded-md flex items-center justify-center shrink-0 text-[var(--color-text-on-accent)] text-[length:var(--text-label-m)
39] leading-[var(--lh-label-m)] font-bold",style:{backgroundColor:l.color||"var(--color-accent)"},children:l.name.charAt(0).toUpperCase()}),e.jsx("span",{className:"text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] text-[var(--color-text-primary)] font-medium truncate",children:l.name})]},l.id))}),e.jsx($o,{open:n,onOpenChange:i})]})}const xd=[{key:"my-drive",label:"My Drive",icon:e.jsx(qn,{size:18})},{key:"shared",label:"Shared with me",icon:e.jsx(he,{size:18})},{key:"recent",label:"Recent",icon:e.jsx(Wn,{size:18})},{key:"starred",label:"Starred",icon:e.jsx(Fe,{size:18})},{key:"activity",label:"Activity",icon:e.jsx(Wa,{size:18})},{key:"storage",label:"Storage",icon:e.jsx(Kn,{size:18})},{key:"trash",label:"Trash",icon:e.jsx(oe,{size:18})}];function hd(){const t=ra(),[r,a]=o.useState(null),n=o.useCallback(async i=>{if(!r){a(i);try{const l={doc:"Untitled document",sheet:"Untitled spreadsheet",slide:"Untitled presentation"},c={doc:"/docs",sheet:"/sheets",slide:"/slides"},u=await be.documents.create({body:{type:i,title:l[i]}});t(`${c[i]}/${u.id}`)}catch(l){l instanceof ft&&l.status===401?t("/login"):P.error("Couldn't create",l instanceof Error?l.message:void 0)}finally{a(null)}}},[r,t]);return{creatingDoc:r,createDocument:n}}function vd(){const{activeSection:t,setActiveSection:r,storageUsage:a,loadStorageUsage:n,sharedDrives:i,loadSharedDrives:l,openSharedDrive:c,activeSharedDriveId:u,sharedWithMeCount:x,loadSharedWithMeCount:m}=V(),v=ra(),[p,y]=o.useState(!1),[R,k]=o.useState(null),[F,U]=o.useState(()=>{const f=lr("drive.sidebar.sharedDrivesExpanded");return f===null?!1:f==="1"}),W=ns(),T=Yn(),L=()=>T==null?void 0:T(),h=()=>{U(f=>{const w=!f;return Vr("drive.sidebar.sharedDrivesExpanded",w?"1":"0"),w})};o.useEffect(()=>{W||(n(),l(),m())},[n,l,m,W]);const N=o.useRef(!1);return o.useEffect(()=>{N.current||i.length!==0&&(N.current=!0,lr("drive.sidebar.sharedDrivesExpanded")===null&&U(!0))},[i.length]),e.jsxs(Wi,{label:"Drive navigation","data-testid":"drive-sidebar",bodyClassName:"p-0 space-y-0 overflow-hidden",children:[e.jsxs("div",{className:"flex-1 overflow-y-auto px-2 py-2",children:[xd.map(f=>e.jsxs(ki.Fragment,{children:[e.jsx(mn,{label:f.label,icon:f.icon,active:t===f.key&&!u,onClick:()=>{r(f.key),L()},"data-testid":`drive-sidebar-nav-${f.key}`,badge:f.key==="shared"&&x>0?e.jsx("span",{children:x>99?"99+":x}):void 0}),f.key==="my-drive"&&e.jsx(ud,{isActive:t==="my-drive"&&!u})]},f.key)),e.jsx(Ki,{title:"Team drives",collapsible:!0,collapsed:!F,onCollapsedChange:f=>{f===F&&h()},count:!F&&i.length>0?i.length:void 0,"data-testid":"drive-sidebar-shared-drives-toggle",children:F&&e.jsxs("div",{id:"drive-sidebar-shared-drives-list",className:"mt-1",children:[e.jsx(mn,{label:"Browse team drives",icon:e.jsx(he,{size:16}),active:t==="shared-drive"&&!u,onClick:()=>{r("shared-drive"),L()},"data-testid":"drive-sidebar-nav-team-drives"}),i.map(f=>e.jsxs("div",{className:A("group/sd w-full flex items-center gap-3 px-3 py-2 rounded-full","text-left transition-colors duration-[var(--duration-micro)]","text-[length:var(--text-body-m)] leading-[var(--lh-body-m)]",u===f.id?"bg-[var(--color-accent-subtle)] text-[var(--color-accent-text)] font-medium":"text-[var(--color-text-secondary)] hover:bg-[var(--color-bg-tertiary)]"),children:[e.jsxs("button",{type:"button",onClick:()=>{c(f.id,f.name),L()},className:"flex items-center gap-3 min-w-0 flex-1",children:[e.jsx("span",{className:"w-5 h-5 rounded flex items-center justify-center shrink-0 text-[var(--color-text-on-accent)] text-[10px] font-bold",style:{backgroundColor:f.color||"var(--color-accent)"},children:f.name.charAt(0).toUpperCase()}),e.jsx("span",{className:"truncate",title:f.name,children:f.name})]}),f.my_role==="manager"&&e.jsx("button",{type:"button",onClick:w=>{w.stopPropagation(),k(f)},className:"shrink-0 w-6 h-6 flex items-center justify-center rounded-full opacity-0 group-hover/sd:opacity-100 focus-visible:opacity-100 pointer-coarse:opacity-100 text-[var(--color-text-tertiary)] hover:text-[var(--color-text-primary)] hover:bg-[var(--color-bg-tertiary)] transition-opacity duration-[var(--duration-micro)]","aria-label":`Settings for ${f.name}`,"data-testid":`shared-drive-sidebar-settings-${f.id}`,children:e.jsx(qa,{size:14})})]},f.id)),i.length===0?e.jsxs("div",{"data-testid":"drive-sidebar-shared-drives-empty",className:"px-3 py-2 text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)]",children:["No team drives yet."," ",e.jsx("button",{type:"button","data-testid":"drive-sidebar-create-shared-drive-link",onClick:()=>y(!0),className:"text-[var(--color-accent-text)] hover:underline font-medium focus-visible:outline-2 focus-visible:outline-[var(--color-accent)] focu
39s-visible:outline-offset-2 rounded-sm",children:"Create one"})]}):e.jsxs("button",{"data-testid":"drive-sidebar-new-shared-drive",onClick:()=>y(!0),className:"mt-1 w-full flex items-center gap-2 px-3 py-2 rounded-full text-left text-[length:var(--text-label-m)] leading-[var(--lh-label-m)] font-medium text-[var(--color-text-secondary)] border border-[var(--color-border-control)] bg-transparent hover:bg-[var(--color-bg-tertiary)] transition-colors duration-[var(--duration-micro)]",children:[e.jsx(bt,{size:14,className:"shrink-0 text-[var(--color-text-tertiary)]"}),e.jsx("span",{className:"truncate",children:"New team drive"})]})]})})]}),e.jsx("div",{className:"px-3 py-3 border-t border-[var(--color-bg-tertiary)] shrink-0",children:a?e.jsxs(e.Fragment,{children:[e.jsx(na,{value:Math.max(1,Math.min(100,a.usedBytes/a.totalBytes*100)),size:"md","data-testid":"drive-sidebar-storage-bar",className:A(a.usedBytes/a.totalBytes>.9?"[&>div]:bg-[var(--color-error)]":a.usedBytes/a.totalBytes>.75?"[&>div]:bg-[var(--color-warning)]":"[&>div]:bg-[var(--color-accent)]")}),e.jsxs("div",{className:"mt-2 flex flex-col items-start gap-0.5 text-[length:var(--text-body-m)] leading-[var(--lh-body-m)]",children:[e.jsxs("span",{className:"text-[var(--color-text-secondary)] tabular-nums whitespace-nowrap","data-testid":"drive-sidebar-storage-usage",children:[je(a.usedBytes)," of ",je(a.totalBytes)]}),e.jsx("button",{onClick:()=>v("/admin"),className:"text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] font-medium text-[var(--color-accent-text)] hover:underline shrink-0","data-testid":"drive-sidebar-upgrade",children:"Upgrade"})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-2 rounded-full bg-[var(--color-bg-tertiary)]"}),e.jsx(ir,{className:"mt-2 h-4 w-32"})]})}),e.jsx($o,{open:p,onOpenChange:y}),e.jsx(jo,{mode:"settings",drive:R,open:R!==null,onClose:()=>k(null)})]})}function pd({onGoBack:t}){return e.jsx("div",{className:"flex-1 flex items-center justify-center min-h-[400px]",children:e.jsxs("div",{className:"flex flex-col items-center text-center max-w-[400px] px-6",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-[var(--color-error-subtle)] flex items-center justify-center mb-5",children:e.jsxs("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-[var(--color-error)]","aria-hidden":"true",children:[e.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),e.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}),e.jsx("h2",{className:"text-[length:var(--text-headline-s)] leading-[var(--lh-headline-s)] font-medium text-[var(--color-text-primary)] mb-2",children:"Access denied"}),e.jsx("p",{className:"text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] text-[var(--color-text-secondary)] mb-6",children:"You don't have permission to access this file or folder. Ask the owner to share it with you."}),e.jsxs(G,{onClick:t,children:[e.jsx(Jr,{size:16}),"Back to Drive"]})]})})}function Rn({onGoBack:t,title:r,description:a}){return e.jsx("div",{className:"flex-1 flex items-center justify-center min-h-[400px]",children:e.jsxs("div",{className:"flex flex-col items-center text-center max-w-[400px] px-6",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-[var(--color-bg-secondary)] flex items-center justify-center mb-5",children:e.jsx(Un,{size:32,className:"text-[var(--color-text-quaternary)]"})}),e.jsx("h2",{className:"text-[length:var(--text-headline-s)] leading-[var(--lh-headline-s)] font-medium text-[var(--color-text-primary)] mb-2",children:r??"File not found"}),e.jsx("p",{className:"text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] text-[var(--color-text-secondary)] mb-6",children:a??"This file was deleted, moved, or never existed."}),e.jsxs(G,{onClick:t,children:[e.jsx(Jr,{size:16}),"Back to Drive"]})]})})}function Tn(t){return Me(t).replace(/\.0 /," ")}function fd(t){return`This selection is ${t.total_bytes>t.max_bytes||t.entry_count<=t.max_entries?Tn(t.total_bytes):`${t.entry_count.toLocaleStr
39ing("en-US")}${t.entry_count_is_lower_bound?"+":""} files`}. One .zip can be up to ${Tn(t.max_bytes)} or ${t.max_entries.toLocaleString("en-US")} files.`}const gd="Share one item at a time for now.",$t="max-sm:h-auto max-sm:min-h-11 max-sm:px-1 max-sm:flex-col max-sm:gap-0.5 max-sm:justify-center max-sm:text-[length:var(--text-label-s)]";function bd({selectedCount:t,selecting:r=!1,onShare:a,onDownload:n,onMove:i,onCopy:l,onDelete:c,onClearSelection:u,onSelectAll:x,totalCount:m}){if(t===0&&!r)return null;const v=t>1,p=t===0;return e.jsxs("div",{"data-testid":"drive-selection-toolbar",className:"flex flex-wrap items-center gap-x-2 gap-y-1 px-3 py-2 mb-3 rounded-[var(--radius-md)] border border-[var(--color-accent)]/20 max-md:sticky max-md:top-0 max-md:z-20",style:{backgroundColor:"color-mix(in srgb, var(--color-accent) 10%, var(--color-bg-primary))"},children:[e.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[e.jsx("button",{onClick:t===m?u:x,className:A("relative w-5 h-5 flex items-center justify-center rounded-[var(--radius-sm)] border transition-colors","pointer-coarse:before:content-[''] pointer-coarse:before:absolute pointer-coarse:before:-inset-3",t===m||t>0?"bg-[var(--color-accent)] border-[var(--color-accent)]":"border-[var(--color-border-control)]"),"aria-label":t===m?"Deselect all":"Select all",children:t===m?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:e.jsx("path",{d:"M2.5 6L5 8.5L9.5 3.5",stroke:"white",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}):t>0?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:e.jsx("path",{d:"M3 6H9",stroke:"white",strokeWidth:"1.5",strokeLinecap:"round"})}):null}),e.jsxs("span",{className:"whitespace-nowrap text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] font-medium text-[var(--color-accent-text)]",children:[t," selected"]}),e.jsx("button",{type:"button",onClick:t===m?u:x,className:"md:hidden ml-auto h-11 px-2 rounded-[var(--radius-md)] text-[length:var(--text-label-m)] leading-[var(--lh-label-m)] font-medium text-[var(--color-accent-text)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]","data-testid":"drive-selection-select-all",children:t===m?"Deselect all":"Select all"})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0 max-sm:grid max-sm:grid-cols-5 max-sm:w-full",role:"group","aria-label":"Selection actions",children:[e.jsxs(G,{variant:"ghost",size:"compact",onClick:a,disabled:v||p,"aria-label":"Share","aria-describedby":v?"drive-selection-share-reason":void 0,className:$t,children:[e.jsx(he,{size:16}),e.jsx("span",{className:"sm:ml-1",children:"Share"})]}),e.jsxs(G,{variant:"ghost",size:"compact",onClick:n,disabled:p,"aria-label":"Download",className:$t,children:[e.jsx(De,{size:16}),e.jsx("span",{className:"sm:ml-1",children:"Download"})]}),e.jsxs(G,{variant:"ghost",size:"compact",onClick:i,disabled:p,"aria-label":"Move",className:$t,children:[e.jsx(xe,{size:16}),e.jsx("span",{className:"sm:ml-1",children:"Move"})]}),e.jsxs(G,{variant:"ghost",size:"compact",onClick:l,disabled:p,"aria-label":"Copy",className:$t,children:[e.jsx(it,{size:16}),e.jsx("span",{className:"sm:ml-1",children:"Copy"})]}),e.jsx("div",{"data-testid":"drive-selection-divider","aria-hidden":"true",className:"w-px h-5 bg-[var(--color-border-control)] mx-1 max-sm:hidden"}),e.jsxs(G,{variant:"ghost",size:"compact",onClick:c,disabled:p,"aria-label":"Delete selected",className:A("text-[var(--color-error-text)] hover:text-[var(--color-error-text)]",$t),children:[e.jsx(oe,{size:16}),e.jsx("span",{className:"sm:ml-1",children:"Delete"})]}),e.jsx("div",{"aria-hidden":"true",className:"w-px h-5 bg-[var(--color-bg-tertiary)] mx-1 max-md:hidden"}),e.jsx(G,{variant:"ghost",size:"compact",onClick:u,"aria-label":"Clear selection",className:A($t,"max-md:hidden"),children:e.jsx(gt,{size:16})})]}),v&&e.jsx("p",{id:"drive-selection-share-reason",className:"basis-full text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-secondary)]",children:gd})]})}function $u(){return e.jsx(Hi,{navigationLabel:"Drive navigation",className:"h-full",sidebar:e.jsx(vd,{}),children:t=>e.jsx(kd,{navigationTrigger:t})})}const Mo=[{key:"name",label:"Name"},{key:"modified",label:"Modified"},{key:"size",label:"Size"},{key:"owner",label:"Owner"},{key:"last_opened",label:"Last opened"}],Pn="drive_folders_on_top",yd=[{key:"shared",label:"Date shared"},...Mo.map(t=>t.key==="modified"?{...t,label:"Last modified"}:t)],Za={name:"asc",owner:"asc",modified:"desc",last_opened:"desc",created:"desc",size:"desc",shared:"desc"};function In({checked:t}){return e.jsx("span",{className:"w-4 shrink-0 flex items-center justify-center text-[var(--color-text-primary)]","aria-hidden":"true",children:t&&e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",children:e.jsx("path",{d:"M3 8.5L6.5 12L13 5",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round"})})})}function Ur({sortKey:t,label:r,activeKey:a,activeDirection:n,onSort:i,className:l,alignEnd:c=!1}){const u=a===t,x=u?n:Za[t],m=x==="asc"?Ka:Lt;return e.jsxs("button",{type:"button",onClick:()=>i(t),className:A("group inline-flex items-center gap-1 transition-colors",c?"flex-row-reverse text-right":"text-left","text-[length:var(--text-label-s)] leading-[var(--lh-label-s)] font-medium","text-[var(--color-text-tertiary)] hover:text-[var(--color-text-secondary)]",l),"aria-label":`Sort by ${r}`,"aria-sort":u?x==="asc"?"ascending":"descending":"none","data-testid":`drive-list-sort-${t}`,"data-active":u?"true":void 0,"data-direction":u?x:void 0,children:[e.jsx("span",{children:r}),e.jsx(m,{size:12,className:A("shrink-0 transition-opacity duration-[var(--duration-micro)]",u?"text-[var(--color-accent)] opacity-100":"text-[var(--color-text-quaternary)] opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100 pointer-coarse:opacity-100"),"aria-hidden":"true"})]})}const Oa=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,jd="Folder not found or you don't have access";function Ba(t){const r=t.replace(/^\/drive\/?/,"").split("/").filter(
39Boolean),[a,n]=r,i=a?wd[a]:void 0,l=a==="folders"&&n&&Oa.test(n)?n:null,c=a==="file"&&n&&Oa.test(n)?n:null,u=a&&!i&&a!=="folders"&&a!=="file"&&Oa.test(a)?a:null;return{urlSection:i,aliasFolderId:l,aliasFileId:c,bareEntityId:u,unrecognizedPath:!!a&&!i&&!l&&!c&&!u}}const wd={starred:"starred",trash:"trash",shared:"shared",recent:"recent",activity:"activity",storage:"storage","shared-drives":"shared-drive"},Nd={starred:"starred",trash:"trash",shared:"shared",recent:"recent",activity:"activity",storage:"storage","shared-drive":"shared-drives"};function kd({navigationTrigger:t}={}){var tn,rn,an,sn,nn,on;Gi(_l);const r=al(),{denyAccess:a}=Yi(),n=ra(),i=Ei(),[l]=Li(),c=o.useRef(null),u=o.useRef(null),x=o.useRef(null),[m,v]=o.useState(!1),p=o.useMemo(()=>Ba(i.pathname).unrecognizedPath,[i.pathname]);o.useEffect(()=>{const s=x.current;if(!s)return;const d=()=>v(s.scrollTop>200);return s.addEventListener("scroll",d,{passive:!0}),()=>s.removeEventListener("scroll",d)},[]),o.useEffect(()=>{let s=null;Fa.retain(["files"]);const d=Fa.onFrame(g=>{g.table==="files"&&(typeof document<"u"&&document.hidden||(s&&clearTimeout(s),s=setTimeout(()=>{V.getState().refreshActiveView()},400)))});return()=>{d(),Fa.release(["files"]),s&&clearTimeout(s)}},[]);const y=Hn(s=>s.view),R=o.useMemo(()=>Zi(y,"drive-empty"),[y]),{files:k,trashedFiles:F,virtualDocuments:U,loading:W,uploading:T,error:L,currentFolderId:h,breadcrumbs:N,searchResults:f,searchStatus:w,searchHasMore:b,activeSection:j,activeSharedDriveId:E,sharedDrives:q,selectedFiles:D,loadFiles:O,loadMoreFiles:K,listing:X,loadVirtualDocuments:S,navigateToFolder:I,navigateToBreadcrumb:Z,createFolder:ae,uploadFile:M,renameFile:C,moveFile:H,moveFiles:$,copyFile:ue,deleteFile:la,restoreFile:mr,permanentlyDeleteFile:B,emptyTrash:ca,downloadFile:Tt,recordFileView:ps,toggleFileStarred:fs,extractFileText:Ro,clearError:xr,loadStorageUsage:me,storageUsage:Sd,loadSharedDriveFiles:gs,createSharedDriveFolder:da,uploadSharedDriveFile:bs,toggleSelectFile:ys,selectAllFiles:js,clearSelection:Pt,bulkMove:ws,bulkCopy:Ns,bulkDelete:ks,downloadSelection:Ss,downloadZipInParts:To}=V(),It=j==="shared-drive"&&!!E,re=o.useMemo(()=>q.find(s=>s.id===E)??null,[q,E]),Cs=It&&(re==null?void 0:re.my_role)==="manager",[Po,_s]=o.useState(!1),[Ds,ua]=o.use
39State(null),[Io,ma]=o.useState(!1),[Ao,Fs]=o.useState(!1),zs=V(s=>s.deleteSharedDrive),Oo=o.useCallback(async()=>{if(!(!E||!re)){Fs(!0);try{await zs(E),P.success(`${re.name} deleted`),ma(!1),n("/drive")}catch{P.error("Couldn't delete drive. Try again.")}finally{Fs(!1)}}},[E,re,zs,n]),[At,dt]=o.useState(!1),[Ot,Bt]=o.useState(!1),[yt,xa]=o.useState(!1);rl("drive",()=>dt(!0));const[Ge,Ye]=o.useState(null),[le,ut]=o.useState(null),[ee,ve]=o.useState(null),Bo=()=>{const s=lr("viewMode_drive");return s==="list"||s==="grid"?s:"grid"},[$s,Uo]=o.useState(Bo),qo=s=>{Uo(s),Vr("viewMode_drive",s)},[se,hr]=o.useState("modified"),[Te,Wo]=o.useState(()=>lr(Pn)!=="false"),Ko=o.useCallback(s=>{Wo(s),Vr(Pn,s?"true":"false")},[]),[pe,Ut]=o.useState(Za.modified),qt=o.useCallback(s=>{hr(d=>d===s?(Ut(g=>g==="asc"?"desc":"asc"),d):(Ut(Za[s]),s))},[]),ha=j==="shared"?yd:Mo,[we,Es]=o.useState("all"),[jt,Vo]=o.useState("any"),[wt,Ho]=o.useState("any"),[Ls,Go]=o.useState("anywhere"),[Ze,va]=o.useState(!1),[pa,Yo]=o.useState("relevance"),Ne=ct(s=>{var d;return((d=s.user)==null?void 0:d.id)??null}),[fe,fa]=o.useState(""),ga=o.useRef(null),[Xe,Pe]=o.useState(null),mt=Vn(),[Wt,Je]=o.useState([]);o.useEffect(()=>{if(j!=="my-drive"||h){Je([]);return}let s=!1;return(async()=>{try{if(!mt){const g=await be.drive.suggested({query:{limit:"3"}});s||Je(g.data.map($a));return}const d=await be.drive.recent({query:{limit:"3"}});if(!s){const g=Q=>{const te=Q.last_viewed_at||Q.updated_at||Q.created_at;return te?new Date(te).getTime():0},_=new Map;for(const Q of d.data){const te=$a(Q),ne=_.get(te.id);(!ne||g(te)>g(ne))&&_.set(te.id,te)}const Y=[..._.values()].sort((Q,te)=>g(te)-g(Q)).slice(0,3);Je(Y)}}catch{}})(),()=>{s=!0}},[j,h,mt]);const Ms=V(s=>s.files),Rs=V(s=>s.virtualDocuments);o.useEffect(()=>{Wt.length!==0&&Je(s=>s.map(d=>{const g=Ms.find(_=>_.id===d.id)??Rs.find(_=>_.id===d.id);return g&&(g.name!==d.name||g.starred!==d.starred||JSON.stringify(g.tags)!==JSON.stringify(d.tags))?{...d,name:g.name,starred:g.starred,tags:g.tags}:d}))},[Ms,Rs,Wt.length]);const[ba,ya]=o.useState(!1),[ja,wa]=o.useState(!1),[Ts,vr]=o.useState(!1),[Zo,pr]=o.useState(!1),[Qe,Na]=o.useState(null),Ps=Ea(s=>
39s.skipped),[Xo,ka]=o.useState(!1),[Is,Jo]=o.useState(0),[As,Qo]=o.useState(0),[Kt,Nt]=o.useState(null),[fr,Vt]=o.useState(null),[Os,xt]=o.useState(null),[gr,kt]=o.useState(null),[Ie,br]=o.useState(null),Ht=o.useCallback((s,d)=>{d.preventDefault(),jr(null),br({x:d.clientX,y:d.clientY,file:s})},[]),[yr,jr]=o.useState(null),{creatingDoc:wr,createDocument:Nr}=hd(),[Gt,Sa]=o.useState(!1);o.useEffect(()=>{Sa(!1)},[h,j]);const St=D.size>0,Yt=St||Gt,kr=o.useCallback((s,d)=>{d.stopPropagation(),ys(s.id)},[ys]),ei=o.useCallback(async s=>{vr(!0);try{const d=await ws(s);d.moved>0&&P.success(`Moved ${d.moved} item${d.moved>1?"s":""}`),d.errors.length>0&&P.error(`Failed to move ${d.errors.length} item${d.errors.length>1?"s":""}`,d.errors[0].error),ya(!1),me()}catch{P.error("Failed to move files")}vr(!1)},[ws,me]),ti=o.useCallback(async s=>{vr(!0);try{const d=await Ns(s);d.copied>0&&P.success(`Copied ${d.copied} item${d.copied>1?"s":""}`),d.errors.length>0&&P.error(`Failed to copy ${d.errors.length} item${d.errors.length>1?"s":""}`),wa(!1),me(),j==="shared-drive"&&E?gs(E,h):O(h)}catch{P.error("Failed to copy files")}vr(!1)},[Ns,me,O,gs,j,E,h]),ri=o.useCallback(()=>{pr(!0)},[]),ai=o.useCallback(async()=>{const s=new Set(D),d=s.size;try{await ks(),Je(g=>g.filter(_=>!s.has(_.id))),P.success(`Deleted ${d} item${d>1?"s":""}`),me()}catch{P.error("Failed to delete files")}},[D,ks,me]);o.useEffect(()=>{const s=d=>{if(d.key!=="Delete"&&d.key!=="Backspace"||d.key==="Backspace"&&!d.metaKey)return;const g=d.target;g&&(g.tagName==="INPUT"||g.tagName==="TEXTAREA"||g.isContentEditable)||j!=="trash"&&D.size!==0&&(d.preventDefault(),pr(!0))};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[D.size,j]),o.useEffect(()=>{const s=d=>{if(d.key!=="t"&&d.key!=="T"||d.metaKey||d.ctrlKey||d.altKey)return;const g=d.target;if(g&&(g.tagName==="INPUT"||g.tagName==="TEXTAREA"||g.isContentEditable)||j==="trash"||D.size!==1)return;const _=[...D][0],Y=k.find(Q=>Q.id===_);!Y||Y.is_folder||Y.document_type||(d.preventDefault(),xt(Y))};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[D,j,k]),o.useEffect(()=>{const s=d=>{if(d.key.toLowerCase()!=="n"||!d.shiftKey||d.metaKey||d.ctrlKey||d.altKey)return;const g=d.target;g&&(g.tagName==="INPUT"||g.tagName==="TEXTAREA"||g.isContentEditable)||j!=="trash"&&(d.preventDefault(),window.dispatchEvent(new CustomEvent("drive:new-folder")))};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[j]);const Ae=o.useRef(null),Sr=o.useMemo(()=>({type:we,people:jt,modified:wt,location:Ls,addedByAgents:Ze}),[we,jt,wt,Ls,Ze]),Bs=o.useCallback(s=>{Es(s.type),Vo(s.people),Ho(s.modified),Go(s.location),va(s.addedByAgents)},[]),Ct=o.useMemo(()=>El(Sr,{currentUserId:Ne,currentFolderId:h,sort:pa}),[Sr,Ne,h,pa]),Us=o.useCallback(s=>{if(fa(s),Ae.current&&clearTimeout(Ae.current),!s.trim()){V.getState().clearSearch();return}Ae.current=setTimeout(()=>{V.getState().search(s,Ct)},300)},[Ct]),si=o.useCallback(()=>{Ae.current&&clearTimeout(Ae.current),fa(""),V.getState().clearSearch()},[]),ni=o.useCallback(()=>{fe.trim()&&V.getState().search(fe,Ct)},[Ct,fe]);o.useEffect(()=>{fe.trim()&&(Ae.current&&clearTimeout(Ae.current),V.getState().search(fe,Ct))},[Ct]),o.useEffect(()=>{const s=d=>{if(d.key!=="/"||d.metaKey||d.ctrlKey||d.altKey)return;const g=d.target;g&&(g.tagName==="INPUT"||g.tagName==="TEXTAREA"||g.isContentEditable)||(d.preventDefault(),xa(!0),requestAnimationFrame(()=>{var _;return(_=ga.current)==null?void 0:_.focus()}))};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[]),o.useEffect(()=>{const s=()=>{document.visibilityState==="visible"&&V.getState().refreshActiveSection()};return document.addEventListener("visibilitychange",s),()=>document.removeEventListener("visibilitychange",s)},[]),o.useEffect(()=>{ba&&D.size>0&&Jo(D.size)},[ba,D.size]),o.useEffect(()=>{ja&&D.size>0&&Qo(D.size)},[ja,D.size]);const[Cr,_r]=o.useState(null),[oi,Dr]=o.useState(null),[et,qs]=o.useState(null);o.useEffect(()=>{const s=()=>{var Q;return(Q=c.current)==null?void 0:Q.click()},d=()=>{var Q;return(Q=u.current)==null?void 0:Q.click()},g=()=>dt(!0),_=()=>Bt(!0),Y=async()=>{const Q=await La({});if(Q)try{await M(Q),P.success("Photo uploaded",Q.name),me()}catch(te){P.error("Photo upload failed",at(te,"Upload failed"))}};return window.addEventListener("drive:new-upload",s),window.addEventListener("drive:new-upload-folder",d),window.addEventListener("drive:new-folder",g),window.addEventListener("drive:new-scan",_),window.addEventListener("drive:new-take-photo",Y),()=>{window.removeEventListener("drive:new-upload",s),window.removeEventListener("drive:new-upload-folder",d),window.removeEventListener("drive:new-folder",g),window.removeEventListener("drive:new-scan",_),window.removeEventListener("drive:new-take-photo",Y)}},[M,me]),Xi({onEscape:o.useCallback(()=>{yr?jr(null):Ie?br(null):Xe?Pe(null):Ot?Bt(!1):At?dt(!1):Ge?Ye(null):le?ut(null):ee?ve(null):gr?kt(null):St&&Pt()},[yr,Ie,Xe,Ot,At,Ge,le,ee,gr,St,Pt]),onDelete:o.useCallback(()=>{},[Xe,Ot,At,Ge,le,ee])});const _t=o.useCallback(async(s,d)=>{var qe;const g=new Set(V.getState().virtualDocuments.map(ce=>ce.id)),_=s.filter(ce=>ce!==d&&!g.has(ce)),Y=s.filter(ce=>g.has(ce)).length;let Q=[],te=0;
39if(_.length>0)try{const ce=await $(_,d);te=ce.moved,Q=ce.errors}catch(ce){Q=_.map(We=>({fileId:We,error:at(ce,"Failed to move")}))}te>1&&P.success(`Moved ${te} items`);const ne=Q.length+Y;ne>0&&P.error(ne===1?"Couldn't move 1 item":`Couldn't move ${ne} items`,((qe=Q[0])==null?void 0:qe.error)??"Docs, sheets and slides can't be moved by dragging yet.")},[$]),ii=o.useCallback((s,d)=>{const g=Yr(s);!g&&!So(s)||(s.preventDefault(),s.dataTransfer.dropEffect=g?"move":"copy",Dr(d))},[]),li=o.useCallback(()=>{Dr(null)},[]),ci=o.useCallback((s,d)=>{if(Dr(null),!Yr(s))return;s.preventDefault();const g=N[d];g.id!==V.getState().currentFolderId&&_t(ho(s.dataTransfer),g.id)},[N,_t]),di=o.useCallback(()=>{_r(null),Dr(null)},[]),Fr=o.useCallback(async(s,d)=>{var ce;if(s.files.length===0&&s.folders.length===0)return;const g=It?E:null,_=await Ql(s,d,{createFolder:(We,ar)=>g?da(g,We,ar):ae(We,ar),uploadFile:(We,ar,ln)=>g?bs(g,We,ln,ar):M(We,ln,ar),onProgress:qs});qs(null);const{currentFolderId:Y,files:Q}=V.getState(),te=d!==Y?(ce=Q.find(We=>We.id===d))==null?void 0:ce.name:void 0,{success:ne,error:qe}=ec(s,_,te);ne&&P.success(ne.title,ne.description),qe&&P.error(qe.title,qe.description),_.uploaded>0&&me()},[ae,da,M,bs,It,E,me]),ui=o.useCallback(async(s,d,g)=>{const _=[];for(const Y of d)try{_.push(await vo(Y))}catch(Q){P.error(`Couldn't read folder "${Y.name}"`,at(Q,"The browser refused access to it."))}await Fr(Zl(Gl(s),..._),g)},[Fr]),{isDragOver:mi,dropzoneProps:xi}=Ji({onFiles:(s,d,g)=>{const _=Kl(g);return ui(s,d,_!==void 0?_:V.getState().currentFolderId)},acceptDirectories:!0,internalMimes:[dr]}),hi=o.useCallback(async s=>{var Y;const d=V.getState(),g=s.parent_folder_id??null,_=s.owner_id!==null&&s.owner_id===((Y=ct.getState().user)==null?void 0:Y.id);if(g){if(await d.hydrateFromFolderId(g),!V.getState().error)return;if(d.clearError(),_){await d.hydrateFromFolderId(null);return}}else if(_){await d.loadFiles(null);return}d.setActiveSection("shared")},[]),Ws=o.useCallback(async s=>{const d=V.getState();let g;try{g=$a(await be.drive.get({params:{id:s}}))}catch(_){if(_ instanceof ft&&_.status===401){n("/login");return}}if(!g){a(s),await d.loadFiles(null);return}if(g.is_folder){await d.hydrateFromFolderId(g.id,{name:g.name});return}await hi(g),V.getState().toggleSelectFile(g.id),Pe(g)},[]);o.useEffect(()=>{const{urlSection:s,aliasFolderId:d,aliasFileId:g,bareEntityId:_,unrecognizedPath:Y}=Ba(i.pathname),Q=l.get("q"),te=d??g??l.get("preview")??l.get("file")??l.get("item")??_??l.get("folder"),ne=V.getState(),qe=ce=>{ce instanceof ft&&ce.status===401&&n("/login")};Y||(s?ne.activeSection!==s&&ne.setActiveSection(s):te?Ws(te).catch(qe):ne.loadFiles(ne.currentFolderId).catch(qe),Q&&Us(Q),ne.loadVirtualDocuments())},[]);const Ks=o.useRef(i.key);o.useEffect(()=>{if(Ks.current===i.key||(Ks.current=i.key,Qi(i.state)))return;const{urlSection:s,aliasFolderId:d,aliasFileId:g,bareEntityId:_}=Ba(i.pathname);if(s)return;const Y=d??g??l.get("preview")??l.get("file")??l.get("item")??_;Y&&Ws(Y).catch(Q=>{Q instanceof ft&&Q.status===401&&n("/login")})},[i.key]);const zr=o.useRef(null);o.useEffect(()=>{const s=`${j}\0${h??""}`;if(zr.current===null||zr.current===s){zr.current=s;return}if(zr.current=s,p)return;const d=Nd[j];d?n(`/drive/${d}`,{replace:!0,state:za()}):h?n(`/drive?folder=${h}`,{replace:!0,state:za()}):n("/drive",{replace:!0,state:za()})},[j,h,n,p]);const Vs=o.useRef(null);o.useEffect(()=>{const s=`${j}\0${h??""}`,d=Vs.current;Vs.current=s,!(d===null||d===s)&&(fa(""),V.getState().clearSearch(),Ae.current&&clearTimeout(Ae.current))},[j,h]),o.useEffect(()=>{j==="recent"?(hr("last_opened"),Ut("desc")):j==="shared"?(hr("shared"),Ut("desc")):(hr("modified"),Ut("desc"))},[j]);const tt=o.useCallback(async s=>{if(s.is_folder){I(s.id,s.name);return}ps(s.id);const d=cr(s);if(d){n(d);return}Pe(s)},[I,ps,n]),Hs=o.useCallback(async s=>{const d=Array.from(s.target.files??[]);s.target.value="",d.length!==0&&await Fr(Yl(d),V.getState().currentFolderId)},[Fr]),Ca=o.useCallback(async s=>{if(!(s.is_folder||s.document_type))try{await ue(s.id,s.parent_folder_id??null),P.success(`Copy of "${s.name}" created`)}catch(d){P.error(d instanceof Error?d.message:"Failed to copy file")}},[ue]),vi=o.useCallback(async(s,d)=>{await H(s,d),P.success("Moved")},[H]),Zt=o.useCallback(async s=>{const d=!s.starred;try{await fs(s.id,d),P.success(d?"Starred":"Removed from starred")}catch{P.error("Failed to update starred status")}},[fs]),_a=o.useCallback(async s=>{if(s.document_type)try{const d=s.document_type;if(d==="form")await be.forms.create({body:{title:`${s.name} (copy)`}});else{const g=await be.documents.get({params:{id:s.id}});await be.documents.create({body:{type:d,title:`${s.name} (copy)`,content:g.content||""}})}P.success(`Copy of "${s.name}" created`),await S()}catch{P.error("Failed to duplicate")}},[S]),ke=o.useMemo(()=>Dl({searchResults:f,files:k,trashedFiles:F,virtualDocuments:U,currentFolderId:h,activeSection:j,currentUserId:Ne}),[f,k,F,U,h,j,Ne]),$r=o.useCallback(()=>ke.filter(s=>D.has(s.id)),[ke,D]),pi=o.useCallback(()=>{const s=$r();s.length===1&&ve(s[0])},[$r,ve]),fi=o.useCallback(async()=>{const s=await Ss($r());s.kind==="over_limit"&&Na({manifest:s.manifest,rootIds:s.rootIds})},[Ss,$r]),gi=o.useMemo(()=>Qe?dl(Qe.manifest,Qe.rootIds):[],[Qe]),Gs=o.useMemo(()=>no(wt),[wt]),Xt=o.useMemo(()=>({sortBy:se,sortDirection:pe,filterType:we,ownerId:jt==="me"&&Ne?Ne:null,modifiedAfter:Gs,foldersFirst:Te,addedByAgents:Ze}),[se,pe,we,jt,Ne,Gs,Te,Ze]);o.useEffect(()=>{V.getState().setListParams(nc(Xt))},[Xt]),o.useEffect(()=>()=>V.setState({listParams:{}}),[]),o.useEffect(()=>{j==="shared"&&V.getState().setSharedWithMeSort(se==="modified"?"modified":"shared")},[j,se]);const Jt=ul({activeSection:j,currentFolderId:h,searchResults:f}),Er=o.useMemo(()=>
39{if(!Jt)return Nn(wn(ke,Xt),se,pe);const s=new Set(k.map(g=>g.id)),d=ke.filter(g=>!s.has(g.id));return oc(k,Nn(wn(d,Xt),se,pe),se,pe,X.hasMore,Te)},[Jt,ke,k,Xt,se,pe,X.hasMore,Te]),{folders:Oe,files:rt,mixed:Be}=o.useMemo(()=>ic(Er,Te&&j!=="shared"),[Er,Te,j]),Lr=o.useMemo(()=>{if(se!=="name"||Oe.length<=20)return null;const s=[];let d=null;for(const g of Oe){const _=g.name.trim().charAt(0).toUpperCase(),Y=/^[A-Z]$/.test(_)?_:"#";(!d||d.letter!==Y)&&(d={letter:Y,items:[]},s.push(d)),d.items.push(g)}return s},[Oe,se]);o.useMemo(()=>rt.filter(Pa),[rt]),ke.length;const Qt=f!==null||fe.trim().length>0||we!=="all"||jt!=="any"||wt!=="any"||Ze,ht=fe.trim().length>0,bi=X.unseenAgentAdditions>0||k.some(s=>!!s.added_by),Ys=yt||ht||jt!=="any"||wt!=="any",Zs=!h&&j==="my-drive"&&Wt.length>0&&!fe.trim(),J=j==="trash",er=o.useCallback(async s=>{try{await mr(s.id),P.success("File restored",s.name)}catch(d){P.error(at(d,"Failed to restore file"))}},[mr]),tr=o.useCallback(s=>{ut(s)},[]),Dt=o.useCallback(s=>({file:s,onOpen:tt,onPreview:Pe,onRename:Ye,onDelete:ut,onShare:ve,onDownload:d=>Tt(d.id),onDuplicate:s.document_type?_a:void 0,onCopy:!J&&!s.document_type&&!s.is_folder?Ca:void 0,onMoveTo:!J&&!s.document_type?Nt:void 0,onShowInfo:J?void 0:Vt,onToggleStar:J?void 0:Zt,onManageTags:!J&&ot(s,Ne)?xt:void 0,onRequestFiles:J?void 0:kt,onDrop:J?void 0:_t,dragOverId:Cr,onDragOverChange:_r,isTrash:J,onRestore:J?er:void 0,onPermanentDelete:J?tr:void 0,isSelected:D.has(s.id),onToggleSelect:kr,selectionActive:Yt,onContextMenu:Ht,renameTarget:Ge,onRenameCommit:async(d,g)=>{await C(d.id,g),Je(_=>_.map(Y=>Y.id===d.id?{...Y,name:g}:Y))},onRenameCancel:()=>Ye(null)}),[tt,Tt,_a,Ca,Zt,_t,Cr,J,er,tr,D,kr,Yt,Ht,Ge,C]),rr=N.length>1?N[N.length-1].name:((tn=N[0])==null?void 0:tn.name)||"My Drive",Xs=[{key:"all",label:"All"},{key:"folders",label:"Folders"},{key:"documents",label:"Documents"},{key:"spreadsheets",label:"Spreadsheets"},{key:"presentations",label:"Presentations"},{key:"forms",label:"Forms"},{key:"images",label:"Images"},{key:"pdf",label:"PDFs"}],Da=o.useMemo(()=>{const s={all:ke.length,folders:0,documents:0,spreadsheets:0,presentations:0,forms:0,images:0,pdf:0};for(const d of ke){const g=d.mime_type||"",_=d.name.toLowerCase();if(d.is_folder){s.folders++;continue}d.document_type==="doc"||!d.document_type&&(g.includes("document")||g.includes("msword")||_.endsWith(".md")||_.endsWith(".txt")||_.endsWith(".doc")||_.endsWith(".docx"))?s.documents++:d.document_type==="sheet"||!d.document_type&&(g.includes("spreadsheet")||g.includes("excel")||_.endsWith(".csv")||_.endsWith(".xls")||_.endsWith(".xlsx"))?s.spreadsheets++:d.document_type==="slide"||!d.document_type&&(g.includes("presentation")||g.includes("powerpoint")||_.endsWith(".ppt")||_.endsWith(".pptx"))?s.presentations++:d.document_type==="form"?s.forms++:!d.document_type&&g.startsWith("image/")?s.images++:!d.document_type&&(g==="application/pdf"||_.endsWith(".pdf"))&&s.pdf++}return s},[ke]),Js=o.useRef(Da);we==="all"&&(Js.current=Da);const Qs=Jt&&we!=="all"?Js.current:Da,en=o.useMemo(()=>Xs.filter(s=>s.key==="all"||s.key===we?!0:Qs[s.key]>0),[Xs,Qs,we]),yi=ke.length>0&&en.length>1,Ue=j==="my-drive"||It&&((re==null?void 0:re.my_role)==="manager"||(re==null?void 0:re.my_role)==="content_manager"||(re==null?void 0:re.my_role)==="contributor"),ji=s=>{!Ue||s.defaultPrevented||s.target.closest("input, textarea, select, [contenteditable='true']")||(s.preventDefault(),br(null),jr({x:s.clientX,y:s.clientY}))},wi=e.jsxs(e.Fragment,{children:[e.jsxs(z,{onSelect:()=>dt(!0),"data-testid":"drive-title-menu-new-folder",children:[e.jsx(Hr,{size:16,className:"mr-2 text-[var(--color-text-tertiary)]"}),"New folder"]}),e.jsxs(z,{onSelect:()=>{var s;return(s=c.current)==null?void 0:s.click()},"data-testid":"drive-title-menu-upload-file",children:[e.jsx(Et,{size:16,className:"mr-2 text-[var(--color-text-tertiary)]"}),"File upload"]}),e.jsxs(z,{onSelect:()=>{var s;return(s=u.current)==null?void 0:s.click()},"data-testid":"drive-title-menu-upload-folder",children:[e.jsx(xe,{size:16,className:"mr-2 text-[var(--color-text-tertiary)]"}),"Folder upload"]}),r&&e.jsxs(e.Fragment,{children:[e.jsxs(z,{onSelect:async()=>{const s=await La({});if(s)try{await M(s),P.success("Photo uploaded",s.name),me()}catch(d){P.error("Photo upload failed",d instanceof Error?d.message:void 0)}},"data-testid":"drive-title-menu-take-photo",children:[e.jsx(dn,{size:16,className:"mr-2 text-[var(--color-text-tertiary)]"}),"Take photo"]}),e.jsxs(z,{onSelect:()=>Bt(!0),"data-testid":"drive-title-menu-scan",children:[e.jsx(Ua,{size:16,className:"mr-2 text-[var(--color-text-tertiary)]"}),"Scan document"]})]}),e.jsx(ie,{}),e.jsxs(z,{onSelect:()=>Nr("doc"),disabled:!!wr,"data-testid":"drive-title-menu-new-doc",children:[e.jsx(rs,{size:16,className:"mr-2 text-[var(--color-module-docs)]"}),"New document"]}),e.jsxs(z,{onSelect:()=>Nr("sheet"),disabled:!!wr,"data-testid":"drive-title-menu-new-sheet",children:[e.jsx(as,{size:16,className:"mr-2 text-[var(--color-module-sheets)]"}),"New spreadsheet"]}),e.jsxs(z,{onSelect:()=>Nr("slide"),disabled:!!wr,"data-testid":"drive-title-menu-new-slide",children:[e.jsx(ss,{size:16,className:"mr-2 text-[var(--color-module-slides)]"}),"New presentation"]})]}),Ni=(s,d,g="end")=>e.jsxs(Se,{children:[e.jsx(Ce,{asChild:!0,children:s}),e.jsx(_e,{align:g,sideOffset:6,className:"w-56","data-testid":d,children:wi})]});return W&&k.length===0&&!f?e.jsx("div",{className:"flex-1 min-w-0 overflow-y-auto overflow-x-clip [overscroll-behavior-y:none]",children:e.jsxs("div",{className:"max-w-[1080px] mx-auto px-6 py-6 max-md:px-4 max-md:py-4",children:[e.jsx(el,{}),e.jsx("div",{className:"flex flex-col gap-1 mt-4",children:[1,2,3,4,5,6].map(s=>e.jsx(st,{},s))})]})}):e.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1",children:[e.jsx(sl,{onRefresh:O,scrollRef:x,children:e.jsxs("div",{ref:x,className:"flex-1 min-w-0 overflow-y-auto overflow-x-clip [overscroll-behavior-y:none]",children:[e.jsxs("div",{className:"max-w-[1080px] mx-auto px-6 py-6 max-md:px-4 max-md:py-4 relative","data-testid":"drive-content-container",onDragEnd:di,...xi,onContextMenu:ji,children:[mi&&e.jsx("div",{className:"absolute inset-0 z-40 flex items-center justify-center bg-[var(--color-bg-primary)]/80 backdrop-blur-sm rounded-[var(--radius-lg)] border-2 border-dashed border-[var(--color-accent)] pointer-events-none",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-[var(--color-accent-subtle)] flex items-center justify-center",children:e.jsx(Et,{size:32,className:"text-[var(--color-accent)]"})}),e.jsx("p",{className:"text-[length:var(--text-body-l)] leading-[var(--lh-body-l)] font-medium text-[var(--color-accent-text)]",children:"Drop files to upload"}),e.jsxs("p",{className:"text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] text-[var(--color-text-tertiary)]",children:["Files will be uploaded to ",rr]})]})}),et&&e.jsx("div",{"data-testid":"drive-upload-progress",role:"status","aria-live":"polite",className:"fixed bottom-6 right-6 z-50 w-80 rounded-[var(--radius-lg)] border border-[var(--color-bg-tertiary)] bg-[var(--color-bg-primary)] shadow-lg p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-8 h-8 shrink-0 rounded-xl bg-[var(--color-accent-subtle)] flex items-center justify-center",children:e.jsx(Et,{size:16,className:"text-[var(--color-accent)]"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] font-medium text-[var(--color-text-primary)]",children:et.total===1?"Uploading file":`Uploading ${et.current} of ${et.total}`}),e.jsx("p",{"data-testid":"drive-upload-progress-filename",className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)] truncate",title:et.filename,children:et.filename}),e.jsx(na,{value:et.pct,size:"sm",className:"mt-2","data-testid":"drive-upload-progress-bar","aria-valuenow":et.pct,"aria-valuemin":0,"aria-valuemax":100,role:"progressbar"})]})]})}),e.jsx(sd,{}),e.jsxs("div",{className:"flex items-center justify-between mb-4 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0 overflow-hidden",children:[t,e.jsxs("div",{className:"min-w-0 flex flex-col gap-0.5",children:[!f&&N.length>1&&e.jsx(ls,{ariaLabel:"Drive navigation",size:"s",className:"-ml-2",collapseAt:4,endsAtCurrentPage:!mt,copyLinkUrl:h?uo(window.location.origin,h):void 0,copyLinkLabel:"Copy link to folder",onCopyLink:()=>P.success("Folder link copied"),items:(mt?N.slice(0,-1):N).map((s,d)=>{const g=d===N.length-1;return{key:s.id??"root",label:s.name,onClick:g?void 0:()=>Z(d),onDragOver:g?void 0:_=>ii(_,d),onDragLeave:g?void 0:li,onDrop:g?void 0:_=>ci(_,d),dropTargetId:g?void 0:s.id??xo,isDragOver:oi===d,dataTestId:`drive-breadcrumb-${d}`}})}),e.jsx("h1",{className:"text-[length:var(--text-headline-s)] leading-[var(--lh-headline-s)] font-medium text-[var(--color-text-primary)] line-clamp-2 break-words","data-testid":"drive-page-title",children:rr})]})]}),e.jsx("div",{className:"flex items-center gap-2","data-testid":"drive-view-controls",children:e.jsxs("div",{className:A("flex items-center gap-1",ht&&"hidden"),children:[e.jsxs(Se,{children:[e.jsx(Ce,{asChild:!0,children:e.jsxs("button",{type:"button",className:A("flex items-center gap-2 h-11 sm:h-8 px-3 rounded-full border border-[var(--color-border-control)]","text-[length:var(--text-label-m)
39] leading-[var(--lh-label-m)] font-medium text-[var(--color-text-secondary)]","hover:bg-[var(--color-bg-secondary)] transition-colors duration-[var(--duration-micro)]","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)] focus-visible:ring-offset-1 focus-visible:ring-offset-[var(--color-bg-primary)]"),"aria-label":`Sort by ${((rn=ha.find(s=>s.key===se))==null?void 0:rn.label)??se}, ${pe==="asc"?"ascending":"descending"}`,"data-testid":"drive-sort-trigger","data-sort-direction":pe,children:[e.jsx("span",{className:"text-[var(--color-text-tertiary)] max-sm:sr-only",children:"Sort:"}),e.jsx("span",{className:"max-sm:sr-only",children:((an=ha.find(s=>s.key===se))==null?void 0:an.label)??se}),pe==="asc"?e.jsx(Ka,{size:14,className:"text-[var(--color-accent)]","aria-hidden":"true","data-testid":"drive-sort-trigger-direction-asc"}):e.jsx(Lt,{size:14,className:"text-[var(--color-accent)]","aria-hidden":"true","data-testid":"drive-sort-trigger-direction-desc"})]})}),e.jsxs(_e,{align:"end",className:"min-w-[200px]",children:[ha.map(({key:s,label:d})=>{const g=se===s;return e.jsxs(z,{onSelect:()=>qt(s),role:"menuitemradio","aria-checked":g,"data-testid":`drive-sort-option-${s}`,"data-active":g?"true":void 0,children:[e.jsx(In,{checked:g}),e.jsx("span",{className:"flex-1",children:d})]},s)}),e.jsx(ie,{}),e.jsxs(z,{role:"menuitemcheckbox","aria-checked":Te,onSelect:s=>{s==null||s.preventDefault(),Ko(!Te)},"data-testid":"drive-sort-folders-on-top",children:[e.jsx(In,{checked:Te}),e.jsx("span",{className:"flex-1",children:"Folders on top"})]})]})]}),e.jsx(tl,{variant:"segmented",className:A("hidden",!ht&&"md:flex"),items:[{id:"list",label:"List view",icon:Mi},{id:"grid",label:"Grid view",icon:Ri}],value:$s,onChange:s=>qo(s),"aria-label":"File layout","data-testid":"drive-view-toggle"}),Ue&&Ni(e.jsxs(G,{size:"compact",className:"max-md:hidden","data-testid":"drive-new-menu-trigger","aria-label":`New in ${rr}`,children:[e.jsx(bt,{size:16}),"New"]}),"drive-new-menu"),!J&&Er.length>0&&e.jsx("button",{type:"button",onClick:()=>Gt||St?(Pt(),Sa(!1)):Sa(!0),className:"md:hidden h-11 px-3 rounded-full text-[length:var(--text-label-m)] leading-[var(--lh-label-m)] font-medium text-[var(--color-accent-text)] hover:bg-[var(--color-bg-secondary)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]","aria-pressed":Gt||St,"data-testid":"drive-phone-select-toggle",children:Gt||St?"Done":"Select"}),e.jsx("button",{type:"button",onClick:()=>xa(s=>!s),className:A("h-11 w-11 md:h-9 md:w-9 flex items-center justify-center rounded-full text-[var(--color-text-secondary)] hover:bg-[var(--color-bg-secondary)] transition-colors duration-[var(--duration-micro)]"),"aria-label":yt?"Hide search":"Search files","aria-expanded":yt,"data-testid":"drive-search-toggle",children:yt?e.jsx(gt,{size:18}):e.jsx(On,{size:18})}),Cs&&e.jsxs(Se,{children:[e.jsx(Ce,{asChild:!0,children:e.jsx("button",{type:"button",className:A("h-11 w-11 md:h-9 md:w-9 flex items-center justify-center rounded-full","text-[var(--color-text-secondary)] hover:bg-[var(--color-bg-secondary)]","transition-colors duration-[var(--duration-micro)]"),"aria-label":"Drive settings","data-testid":"shared-drive-settings-trigger",children:e.jsx(qa,{size:18})})}),e.jsxs(_e,{align:"end",children:[e.jsxs(z,{onSelect:()=>_s(!0),"data-testid":"shared-drive-settings-manage-members",children:[e.jsx(he,{size:14}),"Manage members"]}),e.jsxs(z,{onSelect:()=>ua("rename"),"data-testid":"shared-drive-settings-rename",children:[e.jsx(lt,{size:14}),"Rename drive"]}),e.jsxs(z,{onSelect:()=>ua("settings"),"data-testid":"shared-drive-settings-edit",children:[e.jsx(qa,{size:14}),"Drive settings"]}),e.jsxs(z,{onSelect:()=>ma(!0),"data-testid":"shared-drive-settings-delete",children:[e.jsx(oe,{size:14}),"Delete drive"]})]})]})]})})]}),(yt||ht)&&e.jsx("div",{className:"mb-3","data-testid":"drive-search-bar-row",children:e.jsx(Tl,{ref:ga,value:fe,onChange:Us,onClear:()=>{si(),xa(!1)},onArrowDown:()=>{Ol()},autoFocus:yt&&!fe,placeholder:`Search in ${h?((sn=N[N.length-1])==null?void 0:sn.name)??rr:"Drive"}`})}),Ys?e.jsx("div",{className:"mb-4",children:e.jsx(Pl,{filters:Sr,onChange:Bs,folderName:h?((nn=N[N.length-1])==null?void 0:nn.name)??null:null,showLocation:ht})}):(bi||Ze)&&!J?e.jsx("div",{className:"mb-4 flex",children:e.jsx(co,{pressed:Ze,onToggle:()=>va(s=>!s)})}):null,e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-4",children:[J&&F.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs(G,{variant:"destructive",size:"compact",onClick:()=>ka(!0),"data-testid":"drive-empty-trash",children:[e.jsx(oe,{size:16}),"Empty trash"]}),e.jsx("p",{className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-text-tertiary)]","data-testid":"drive-trash-retention-hint",children:"Items stay in trash until you empty it."})]}),e.jsx("input",{ref:c,type:"file",multiple:!0,className:"hidden",onChange:Hs,"data-testid":"file-upload-input"}),e.jsx("input",{ref:u,type:"file",multiple:!0,className:"hidden",onChange:Hs,"data-testid":"folder-upload-input",webkitdirectory:"",directory:""})]}),yi&&!Ys&&e.jsx("div",{"data-testid":"drive-type-filter-row",className:A("flex flex-nowrap items-center gap-2 mb-5 pb-1 overflow-x-auto [scrollbar-width:none] md:flex-wrap"),children:en.map(s=>e.jsx("button",{"data-testid":`drive-type-filter-chip-${s.key}`,onClick:()=>Es(s.key===we?"all":s.key),className:A("px-3 py-2 max-md:py-3 rounded-full text-[length:var(--text-label-m)
39] leading-[var(--lh-label-m)] font-medium border transition-colors duration-[var(--duration-micro)] whitespace-nowrap shrink-0",we===s.key?"bg-[var(--color-accent-subtle)] border-[var(--color-accent)] text-[var(--color-accent-text)]":"border-[var(--color-border-control)] text-[var(--color-text-secondary)] hover:bg-[var(--color-bg-secondary)]"),children:s.label},s.key))}),!ht&&Jt&&X.unseenAgentAdditions>0&&!Ze&&e.jsxs("div",{className:"mb-4 flex items-center gap-3 px-3 py-2 rounded-[var(--radius-md)] bg-[var(--color-accent-subtle)]",role:"status","data-testid":"drive-agent-additions-banner",children:[e.jsx("span",{className:"flex-1 min-w-0 text-[length:var(--text-body-m)] leading-[var(--lh-body-m)] font-medium text-[var(--color-text-primary)]",children:X.unseenAgentAdditions===1?"1 new file from agents since you were last here":`${X.unseenAgentAdditions} new files from agents since you were last here`}),e.jsx(G,{variant:"secondary",size:"compact",className:"shrink-0 pointer-coarse:min-h-11 bg-[var(--color-bg-primary)] border border-[var(--color-border-control)] text-[var(--color-text-primary)] hover:bg-[var(--color-bg-secondary)]",onClick:()=>va(!0),"data-testid":"drive-agent-additions-review",children:"Review"})]}),(L==null?void 0:L.status)===403&&e.jsx(pd,{onGoBack:()=>{xr(),I(null)}}),p?e.jsx(Rn,{onGoBack:()=>{xr(),n("/drive"),I(null)},title:"Folder not found",description:jd}):(L==null?void 0:L.status)===404&&e.jsx(Rn,{onGoBack:()=>{xr(),I(null)}}),L&&L.status!==403&&L.status!==404&&e.jsxs("div",{className:"mb-4 px-3 py-2 rounded-[var(--radius-md)] bg-[var(--color-error)]/10 border border-[var(--color-error)]/20 flex items-center justify-between",children:[e.jsx("p",{className:"text-[length:var(--text-body-s)] leading-[var(--lh-body-s)] text-[var(--color-error)]",children:L.message}),e.jsx("button",{onClick:xr,className:"text-[var(--color-error)] ml-2",children:e.jsx(gt,{size:14})})]}),p||L&&(L.status===403||L.status===404)?null:ht?e.jsx(Al,{query:fe.trim(),status:w,results:f,hasMore:b,filters:Sr,folderName:h?((on=N[N.length-1])==null?void 0:on.name)??null:null,sort:pa,onSortChange:Yo,onFiltersChange:Bs,onOpen:tt,onRetry:ni,onLoadMore:()=>void V.getState().loadMoreSearch(),onFocusField:()=>{var s;return(s=ga.current)==null?void 0:s.focus()}}):j==="activity"?e.jsx(id,{}):j==="storage"?e.jsx(ld,{}):j==="shared-drive"&&!E?e.jsx(md,{}):Er.length===0&&!Zs?(()=>{const s=(Ue||j==="trash")&&!Qt,d=s?j==="trash"?"trash":"writable":"dashboard",g=j==="shared"?e.jsx(he,{size:28,className:"text-[var(--color-text-quaternary)]"}):j==="recent"?e.jsx(Wn,{size:28,className:"text-[var(--color-text-quaternary)]"}):j==="starred"?e.jsx(Fe,{size:28,className:"text-[var(--color-text-quaternary)]"}):j==="trash"?e.jsx(oe,{size:28,className:"text-[var(--color-text-quaternary)]"}):Ue?e.jsx(xe,{size:28,className:"text-[var(--color-text-quaternary)]"}):e.jsx(qn,{size:28,className:"text-[var(--color-text-quaternary)]"}),_=Qt?"No results found":Ue?`Nothing in ${rr} yet`:j==="shared"?"Nothing shared with you yet":j==="recent"?"No recent files":j==="starred"?"No starred files":j==="trash"?"Trash is empty":"No files yet",Y=Qt?fe?"Try a different search term.":"Try changing your filters.":j==="shared"?"Files shared with you will appear here.":j==="recent"?"Files you've opened recently will appear here.":j==="starred"?"Star files to find them quickly.":j==="trash"?"Files you delete appear here and stay until you empty the trash.":Ue?mt?"Upload files or create a document here.":"Upload files or create a document here. You can also drop files anywhere on this page.":void 0,Q=Ue&&!Qt,te=Ue&&!Qt&&N.length<=1;return e.jsx("div",{className:A(s&&"px-6 max-md:px-0"),"data-testid":"drive-empty-state","data-empty-variant":d,children:e.jsx(Zn,{variant:"page",icon:g,title:_,description:Y,descriptionClassName:"[text-wrap:balance]",ladderHint:te?R:void 0,actions:Q?[e.jsx("div",{className:"flex gap-2",children:e.jsxs(G,{variant:"secondary",size:"compact",className:"pointer-coarse:min-h-11 max-md:px-5 border border-[var(--color-border-control)]",onClick:()=>{var ne;return(ne=c.current)==null?void 0:ne.click()},"data-testid":"drive-empty-upload",children:[e.jsx(Et,{size:16}),"Upload"]})},"drive-empty-actions")]:void 0})})})():e.jsxs("div",{"data-testid":"file-list",className:"max-md:pb-[calc(var(--mobile-tab-bar-clearance,0px)+56px+32px)]",children:[!J&&e.jsx(bd,{selectedCount:D.size,selecting:mt&&Gt,totalCount:ke.length,onShare:pi,onDownload:fi,onMove:()=>ya(!0),onCopy:()=>wa(!0),onDelete:ri,onClearSelection:Pt,onSelectAll:js}),Zs&&(mt?e.jsx(mc,{files:Wt,currentUserId:Ne,onOpen:tt,onSeeAll:()=>
39V.getState().setActiveSection("recent")}):e.jsx(dc,{files:Wt.filter(s=>!!s.suggestion),onOpen:tt,onContextMenu:Ht})),$s==="list"?(Oe.length>0||rt.length>0||((Be==null?void 0:Be.length)??0)>0)&&e.jsxs("div",{className:"@container/drivelist flex flex-col","data-testid":"drive-list-table",children:[e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 text-[length:var(--text-label-s)] leading-[var(--lh-label-s)] font-medium text-[var(--color-text-tertiary)] border-b border-[var(--color-bg-tertiary)] max-md:hidden",children:[(()=>{const s=Be??[...Oe,...rt],d=s.length>0&&s.every(_=>D.has(_.id)),g=!d&&s.some(_=>D.has(_.id));return e.jsx("div",{className:A("w-5 h-5 shrink-0 flex items-center justify-center rounded-[var(--radius-sm)] border transition-colors duration-[var(--duration-micro)] cursor-pointer",d||g?"bg-[var(--color-accent)] border-[var(--color-accent)]":"border-[var(--color-border-control)] hover:border-[var(--color-text-tertiary)]"),onClick:_=>{_.stopPropagation(),d||g?Pt():js()},role:"checkbox","aria-checked":d?!0:g?"mixed":!1,"aria-label":d?"Deselect all files":"Select all files","data-testid":"list-select-all",children:d?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:e.jsx("path",{d:"M2.5 6L5 8.5L9.5 3.5",stroke:"white",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}):g?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",children:e.jsx("path",{d:"M2.5 6h7",stroke:"white",strokeWidth:"2",strokeLinecap:"round"})}):null})})(),e.jsx("div",{className:"w-8 shrink-0"}),e.jsx(Ur,{sortKey:"name",label:"Name",activeKey:se,activeDirection:pe,onSort:qt,className:"flex-1 min-w-0"}),e.jsx(Ur,{sortKey:"owner",label:"Owner",activeKey:se,activeDirection:pe,onSort:qt,className:"shrink-0 hidden @[680px]/drivelist:flex w-[120px]"}),e.jsx(Ur,{sortKey:"size",label:"Size",activeKey:se,activeDirection:pe,onSort:qt,alignEnd:!0,className:"shrink-0 tabular-nums w-24 hidden @[560px]/drivelist:flex justify-start"}),e.jsx(Ur,{sortKey:"modified",label:"Modified",activeKey:se,activeDirection:pe,onSort:qt,alignEnd:!0,className:"hidden @[440px]/drivelist:flex shrink-0 tabular-nums w-[88px] justify-start"}),e.jsx("div",{className:"w-[72px] shrink-0 hidden @[440px]/drivelist:block"})]}),Be?Be.map(s=>e.jsx(Or,{...Dt(s)},s.id)):null,Oe.length>0&&e.jsx(En,{testId:"drive-list-group-folders",children:"Folders"}),Lr?Lr.map(s=>e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center gap-3 px-3 pt-3 pb-1 text-[length:var(--text-label-s)] leading-[var(--lh-label-s)] font-semibold uppercase tracking-[0.05em] text-[var(--color-text-tertiary)]","data-testid":`drive-folder-letter-divider-${s.letter}`,children:s.letter}),s.items.map(d=>e.jsx(Or,{...Dt(d)},d.id))]},`letter-${s.letter}`)):Oe.map(s=>e.jsx(Or,{...Dt(s)},s.id)),rt.length>0&&e.jsx(En,{testId:"drive-list-group-files",children:"Files"}),rt.map(s=>e.jsx(Or,{...Dt(s)},s.id))]}):e.jsxs(e.Fragment,{children:[Be&&Be.length>0&&e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(160px,1fr))] gap-3 mb-6","data-testid":"drive-grid-mixed",children:Be.map(s=>e.jsx(Mn,{...Dt(s)},s.id))}),Oe.length>0&&e.jsxs("div",{className:"mb-6",children:[e.jsx("div",{className:"flex items-center gap-2 mb-3",children:e.jsx("h2",{className:"text-[length:var(--text-label-s)] leading-[var(--lh-label-s)] font-semibold uppercase tracking-[0.05em] text-[var(--color-text-tertiary)]",children:"Folders"})}),Lr?Lr.map(s=>e.jsxs("div",{className:"mb-4 last:mb-0",children:[e.jsx("div",{className:"text-[length:var(--text-label-s)] leading-[var(--lh-label-s)] font-semibold uppercase tracking-[0.05em] text-[var(--color-text-tertiary)] mb-2","data-testid":`drive-folder-letter-divider-${s.letter}`,children:s.letter}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(160px,1fr))] gap-3",children:s.items.map(d=>e.jsx(Ln,{file:d,onOpen:tt,onRename:Ye,onDelete:ut,onShare:ve,onMoveTo:Nt,onShowInfo:Vt,onToggleStar:Zt,onManageTags:J?void 0:xt,onRequestFiles:J?void 0:kt,onDrop:_t,dragOverId:Cr,onDragOverChange:_r,isTrash:J,onRestore:J?er:void 0,onPermanentDelete:J?tr:void 0,isSelected:D.has(d.id),onToggleSelect:kr,selectionActive:Yt,onContextMenu:Ht,renameTarget:Ge,onRenameCommit:async(g,_)=>{await C(g.id,_)},onRenameCancel:()=>Ye(null)},d.id))})]},`letter-${s.letter}`)):e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(160px,1fr))] gap-3",children:Oe.map(s=>e.jsx(Ln,{file:s,onOpen:tt,onRename:Ye,onDelete:ut,onShare:ve,onMoveTo:Nt,onShowInfo:Vt,onToggleStar:Zt,onManageTags:J?void 0:xt,onRequestFiles:J?void 0:kt,onDrop:_t,dragOverId:Cr,onDragOverChange:_r,isTrash:J,onRestore:J?er:void 0,onPermanentDelete:J?tr:void 0,isSelected:D.has(s.id),onToggleSelect:kr,selectionActive:Yt,onContextMenu:Ht,renameTarget:Ge,onRenameCommit:async(d,g)=>{await C(d.id,g)},onRenameCancel:()=>Ye(null)},s.id))})]}),rt.length>0&&e.jsxs("div",{className:"mb-6",children:[j!=="shared"&&e.jsx("div",{className:"flex items-center mb-3",children:e.jsx("h2",{className:"text-[length:var(--text-label-s)] leading-[var(--lh-label-s)] font-semibold uppercase tracking-[0.05em] text-[var(--color-text-tertiary)]",children:"Files"})}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(160px,1fr))] gap-3",children:rt.map(s=>e.jsx(Mn,{...Dt(s)},s.id))})]})]}),Jt&&X.hasMore&&X.folderId===h&&e.jsx("div",{className:"flex justify-center py-4","data-testid":"drive-load-more-row",children:e.jsx(G,{variant:"secondary",onClick:()=>void K(),disabled:X.loadingMore,"data-testid":"drive-load-more",children:X.loadingMore?"Loadingâ¦":"Show more"})})]}),Ue&&!Yt&&e.jsx("div",{className:"md:hidden fixed bottom-[calc(var(--mobile-tab-bar-clearance,0px)+16px)] right-4 z-40","data-testid":"drive-mobile-fab",children:e.jsxs(Se,{children:[e.jsx(Ce,{asChild:!0,children:e.jsx("button",{type:"button",className:"h-14 w-14 roun
39ded-full bg-[var(--color-accent)] text-[var(--color-text-on-accent)] shadow-lg flex items-center justify-center hover:bg-[var(--color-accent-hover)] transition-colors duration-[var(--duration-micro)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)] focus-visible:ring-offset-2 focus-visible:ring-offset-[var(--color-bg-primary)]","aria-label":"Create new","data-testid":"drive-mobile-fab-trigger",disabled:T,children:e.jsx(bt,{size:24})})}),e.jsxs(_e,{align:"end",side:"top",sideOffset:8,className:"w-56",children:[e.jsxs(z,{onSelect:()=>{var s;return(s=c.current)==null?void 0:s.click()},"data-testid":"drive-mobile-fab-upload",children:[e.jsx(Et,{size:16,className:"mr-2 text-[var(--color-text-tertiary)]"}),"Upload file"]}),e.jsxs(z,{onSelect:()=>{var s;return(s=u.current)==null?void 0:s.click()},"data-testid":"drive-mobile-fab-upload-folder",children:[e.jsx(xe,{size:16,className:"mr-2 text-[var(--color-text-tertiary)]"}),"Upload folder"]}),e.jsxs(z,{onSelect:()=>dt(!0),"data-testid":"drive-mobile-fab-new-folder",children:[e.jsx(Hr,{size:16,className:"mr-2 text-[var(--color-text-tertiary)]"}),"New folder"]}),e.jsxs(z,{onSelect:async()=>{const s=await La({});if(s)try{await M(s),P.success("Photo uploaded",s.name),me()}catch(d){P.error("Photo upload failed",at(d,"Upload failed"))}},"data-testid":"drive-mobile-fab-take-photo",children:[e.jsx(dn,{size:16,className:"mr-2 text-[var(--color-text-tertiary)]"}),"Take photo"]}),e.jsxs(z,{onSelect:()=>Bt(!0),"data-testid":"drive-mobile-fab-scan",children:[e.jsx(Ua,{size:16,className:"mr-2 text-[var(--color-text-tertiary)]"}),"Scan document"]})]})]})}),e.jsx(rd,{open:At,onOpenChange:dt,onCreate:It?s=>da(E,s):ae}),e.jsx(ad,{open:le!==null,onOpenChange:s=>{s||ut(null)},fileName:(le==null?void 0:le.name)||"",isFolder:!!(le!=null&&le.is_folder),isTrash:J,onConfirm:async()=>{le&&(J?(await B(le.id),P.success("Permanently deleted",le.name)):(await la(le.id),Je(s=>s.filter(d=>d.id!==le.id)),P.success("Moved to trash",le.name)),me())}}),Xe&&Pa(Xe)?e.jsx(Qc,{file:Xe,files:k.filter(Pa),breadcrumbs:N,onClose:()=>Pe(null),onDownload:s=>Tt(s.id),onNavigate:s=>Pe(s),onShare:ee?void 0:s=>ve(s),onNavigateFolder:s=>{if(Pe(null),s){const d=N.find(g=>g.id===s);I(s,(d==null?void 0:d.name)??"")}else Z(0)}}):e.jsx(wl,{file:Xe,onClose:()=>Pe(null),onDownload:s=>Tt(s.id)}),e.jsx(wc,{open:Ot,onClose:()=>Bt(!1),currentFolderId:h,onUploaded:()=>{me(),O(h)}}),ee&&(()=>{const s=!!ee.document_type&&ee.document_type!=="form",d=s?"/api/documents":"/api/drive",g=s?ee.document_type:"drive";return e.jsx(fl,{open:ee!==null,onOpenChange:_=>{_||ve(null)},documentId:ee.id,documentTitle:ee.name,owner:ee.owner?{id:ee.owner.id,display_name:ee.owner.display_name,primary_email:ee.owner.primary_email,workspace_email:ee.owner.workspace_email}:void 0,apiBasePath:d,visibility:ee.visibility,onVisibilityChange:_=>ve(Y=>Y&&{...Y,visibility:_}),resourceType:g,isFolder:ee.is_folder??!1,linkExpiresAt:ee.link_expires_at,onLinkExpiresAtChange:_=>ve(Y=>Y&&{...Y,link_expires_at:_}),hasPassword:ee.has_password,onPasswordChange:_=>ve(Y=>Y&&{...Y,has_password:_}),linkPermission:ee.link_permission??"viewer",onLinkPermissionChange:_=>ve(Y=>Y&&{...Y,link_permission:_})})})(),e.jsx(Ra,{open:ba,onOpenChange:ya,title:`Move ${Is} item${Is>1?"s":""}`,actionLabel:"Move here",onConfirm:ei,loading:Ts}),e.jsx(Ra,{open:ja,onOpenChange:wa,title:`Copy ${As} item${As>1?"s":""}`,actionLabel:"Copy here",onConfirm:ti,loading:Ts,roots:Vc}),yr&&e.jsx(Kc,{state:yr,onClose:()=>jr(null),onNewFolder:()=>dt(!0),onUploadFile:()=>{var s;return(s=c.current)==null?void 0:s.click()},onUploadFolder:()=>{var s;return(s=u.current)==null?void 0:s.click()},onCreateDocument:Nr,creatingDoc:wr}),Ie&&e.jsx(Wc,{state:Ie,onClose:()=>br(null),onOpen:tt,onPreview:Pe,onRename:Ye,onDelete:ut,onShare:ve,onDownload:s=>Tt(s.id),onDuplicate:Ie.file.document_type?_a:void 0,onCopy:!J&&!Ie.file.document_type&&!Ie.file.is_folder?Ca:void 0,onMoveTo:!J&&!Ie.file.document_type?Nt:void 0,onShowInfo:J?void 0:Vt,onToggleStar:J?void 0:Zt,onManageTags:!J&&ot(Ie.file,Ne)?xt:void 0,onRequestFiles:J?void 0:kt,onCopyLink:J?void 0:s=>void ql(s),onRestore:J?er:void 0,onPermanentDelete:J?tr:void 0,isTrash:J,onNavigate:n}),e.jsx(Ra,{open:Kt!==null,onOpenChange:s=>
39{s||Nt(null)},title:Kt?`Move "${Kt.name}"`:"Move",actionLabel:"Move here",onConfirm:async s=>{if(Kt)try{await vi(Kt.id,s)}catch(d){P.error(d instanceof Error?d.message:"Failed to move file")}finally{Nt(null)}}}),e.jsx(Ac,{folder:gr,open:gr!==null,onClose:()=>kt(null)}),e.jsx(Mc,{open:Os!==null,onOpenChange:s=>{s||xt(null)},file:Os}),e.jsx(Oc,{open:Po,onClose:()=>_s(!1),driveId:E,driveName:(re==null?void 0:re.name)??null,canManage:!!Cs}),e.jsx(jo,{mode:Ds??"settings",drive:re,open:Ds!==null,onClose:()=>ua(null)}),e.jsx(Ke,{open:Io,onOpenChange:s=>!s&&ma(!1),title:"Delete drive",description:re?`Permanently delete ${re.name} â all members lose access.`:"",confirmLabel:Ao?"Deletingâ¦":"Delete drive",cancelLabel:"Cancel",variant:"destructive",onConfirm:Oo})]}),m&&e.jsx("button",{type:"button","aria-label":"Scroll to top",onClick:()=>{var s;return(s=x.current)==null?void 0:s.scrollTo({top:0,behavior:"smooth"})},className:"md:hidden fixed right-4 bottom-20 z-30 w-11 h-11 rounded-full bg-[var(--color-bg-primary)] border border-[var(--color-border-control)] shadow-lg flex items-center justify-center text-[var(--color-text-secondary)] active:bg-[var(--color-bg-secondary)] transition-colors",children:e.jsx(Ka,{size:20})})]})}),e.jsx($c,{open:fr!==null,onClose:()=>Vt(null),file:fr,onManageTags:!J&&fr&&ot(fr,Ne)?xt:void 0,onExtractText:J?void 0:s=>Ro(s.id),onRename:async(s,d)=>{await C(s.id,d),Je(g=>g.map(_=>_.id===s.id?{..._,name:d}:_))}}),e.jsx(Ke,{open:Qe!==null,onOpenChange:s=>{s||Na(null)},title:"Too large to download as one .zip",description:Qe?fd(Qe.manifest):"",confirmLabel:`Download in ${gi.length} parts`,cancelLabel:"Cancel",variant:"primary",onConfirm:async()=>{const s=Qe;Na(null),s&&await To(s.manifest,s.rootIds)}}),e.jsx(ze,{open:Ps!==null,onOpenChange:s=>{s||Ea.setState({skipped:null})},children:e.jsxs($e,{className:"max-w-md",children:[e.jsxs(Ee,{children:[e.jsx(Le,{children:"Files not in the .zip"}),e.jsx(Re,{children:"These couldn't be added to your download."})]}),e.jsx("ul",{className:"flex flex-col gap-[var(--spacing-2)] max-h-80 overflow-y-auto","data-testid":"drive-zip-skipped-list",children:(Ps??[]).map(s=>e.jsxs("li",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[length:var(--text-body-m)] text-[var(--color-text-primary)] truncate",children:s.name}),e.jsx("span",{className:"text-[length:var(--text-body-s)] text-[var(--color-text-secondary)]",children:s.reason})]},s.id))}),e.jsx(He,{children:e.jsx(G,{variant:"primary",onClick:()=>Ea.setState({skipped:null}),children:"Done"})})]})}),e.jsx(Ke,{open:Zo,onOpenChange:s=>{s||pr(!1)},title:`Delete ${D.size} item${D.size>1?"s":""}?`,description:"They will be moved to trash.",confirmLabel:"Delete",variant:"destructive",onConfirm:async()=>{pr(!1),await ai()}}),e.jsx(Ke,{open:Xo,onOpenChange:s=>{s||ka(!1)},title:"Empty trash?",description:"Permanently delete all items in trash? This cannot be undone.",confirmLabel:"Empty trash",variant:"destructive",onConfirm:async()=>{ka(!1);try{await ca(),P.success("Trash emptied"),me()}catch{P.error("Failed to empty trash")}}})]})}export{$u as DrivePage,vd as DriveSidebar,Mn as FileCard,Or as FileRow,zu as TAG_COLORS,zo as tagStyle};
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.