@rubytech/create-maxy-code 0.1.433 → 0.1.434

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/package.json +1 -1
  2. package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +2 -2
  3. package/payload/platform/plugins/docs/references/admin-ui.md +1 -1
  4. package/payload/server/public/assets/{AdminLoginScreens-CH-kznsr.js → AdminLoginScreens-CMh1pdOp.js} +1 -1
  5. package/payload/server/public/assets/{AdminShell-DzgrZYpX.js → AdminShell-X9Bg3AKc.js} +1 -1
  6. package/payload/server/public/assets/{Checkbox-ChPx3-af.js → Checkbox-OCfZCTCO.js} +1 -1
  7. package/payload/server/public/assets/{admin-VHYR1DAp.js → admin-Bi2uYnAg.js} +1 -1
  8. package/payload/server/public/assets/{browser-DkTz3Atj.js → browser-B0ieZy-b.js} +1 -1
  9. package/payload/server/public/assets/{calendar-DlQUywFC.js → calendar-CRL2_9Fl.js} +1 -1
  10. package/payload/server/public/assets/chat-C56bmC6C.js +1 -0
  11. package/payload/server/public/assets/chevron-left-B2DKUxLk.js +1 -0
  12. package/payload/server/public/assets/data-C1ftMulP.js +1 -0
  13. package/payload/server/public/assets/{file-download-CX16TB7C.js → file-download-CHTyUQqS.js} +1 -1
  14. package/payload/server/public/assets/{graph-DPqvHCZ4.js → graph-CrJ-itbq.js} +1 -1
  15. package/payload/server/public/assets/{graph-labels-D_0uou0Z.js → graph-labels-CmCWaKJT.js} +1 -1
  16. package/payload/server/public/assets/{maximize-2-BTHbMSfz.js → maximize-2-_cJWIgx2.js} +1 -1
  17. package/payload/server/public/assets/{operator-BCZ7UoWU.js → operator-B4wN2c53.js} +1 -1
  18. package/payload/server/public/assets/page-BIfOKi9I.js +32 -0
  19. package/payload/server/public/assets/{page-CqN6MkYM.js → page-C1G57kPZ.js} +1 -1
  20. package/payload/server/public/assets/{public-DI5OCw9V.js → public-DmBKnBkr.js} +1 -1
  21. package/payload/server/public/assets/tasks-0OcRiBdQ.js +1 -0
  22. package/payload/server/public/assets/time-entry-format-D477WAes.js +1 -0
  23. package/payload/server/public/assets/{useCopyFeedback-8b1gtbRz.js → useCopyFeedback-CpfVOO26.js} +1 -1
  24. package/payload/server/public/assets/{useSubAccountSwitcher-DRRuGtGS.css → useSubAccountSwitcher-BKCWKo97.css} +1 -1
  25. package/payload/server/public/assets/useVoiceRecorder-CZPtVpM-.js +2 -0
  26. package/payload/server/public/browser.html +5 -5
  27. package/payload/server/public/calendar.html +6 -6
  28. package/payload/server/public/chat.html +11 -11
  29. package/payload/server/public/data.html +10 -9
  30. package/payload/server/public/graph.html +10 -10
  31. package/payload/server/public/index.html +13 -12
  32. package/payload/server/public/operator.html +13 -13
  33. package/payload/server/public/public.html +11 -11
  34. package/payload/server/public/tasks.html +4 -4
  35. package/payload/server/public/assets/chat-CPOGOzmQ.js +0 -1
  36. package/payload/server/public/assets/chevron-left-Ch2-JhmS.js +0 -1
  37. package/payload/server/public/assets/data-Ppxc3gvy.js +0 -1
  38. package/payload/server/public/assets/page-BObPPwJr.js +0 -32
  39. package/payload/server/public/assets/play-Bw1WkeRC.js +0 -1
  40. package/payload/server/public/assets/tasks-Bj03-1M6.js +0 -1
  41. package/payload/server/public/assets/useVoiceRecorder-D9Qa7Eua.js +0 -2
  42. /package/payload/server/public/assets/{useSubAccountSwitcher-Cmbcd72K.js → useSubAccountSwitcher-Bo7bnFtC.js} +0 -0
@@ -1 +1 @@
1
- import{o as e}from"./chunk-Ck5AOu5v.js";import{S as t,T as n,a as r,b as i,c as a,h as o,n as s,o as c,r as l,s as u,t as d,u as f}from"./useSubAccountSwitcher-Cmbcd72K.js";import{C as p,b as m,n as h,r as g,s as _,w as ee,x as v}from"./useVoiceRecorder-D9Qa7Eua.js";import{t as y}from"./chevron-left-Ch2-JhmS.js";import{a as b,c as x,d as te,f as ne,h as S,i as C,m as w,n as re,p as ie,r as ae,s as T,t as E,u as D}from"./file-download-CX16TB7C.js";import{i as oe,t as O}from"./graph-labels-D_0uou0Z.js";var se=o(`arrow-left`,[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]),ce=o(`ellipsis`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]]),le=o(`folder-plus`,[[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`M9 13h6`,key:`1uhe8q`}],[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),ue=o(`folder`,[[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),k=o(`image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),de=o(`layout-grid`,[[`rect`,{width:`7`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`1g98yp`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`3`,rx:`1`,key:`6d4xhi`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`14`,rx:`1`,key:`nxv5o0`}],[`rect`,{width:`7`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`1bb6yr`}]]),fe=o(`list`,[[`path`,{d:`M3 5h.01`,key:`18ugdj`}],[`path`,{d:`M3 12h.01`,key:`nlz23k`}],[`path`,{d:`M3 19h.01`,key:`noohij`}],[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M8 12h13`,key:`1za7za`}],[`path`,{d:`M8 19h13`,key:`m83p4d`}]]),pe=o(`mouse-pointer-click`,[[`path`,{d:`M14 4.1 12 6`,key:`ita8i4`}],[`path`,{d:`m5.1 8-2.9-.8`,key:`1go3kf`}],[`path`,{d:`m6 12-1.9 2`,key:`mnht97`}],[`path`,{d:`M7.2 2.2 8 5.1`,key:`1cfko1`}],[`path`,{d:`M9.037 9.69a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z`,key:`s0h3yz`}]]),me=o(`send-horizontal`,[[`path`,{d:`M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z`,key:`117uat`}],[`path`,{d:`M6 12h16`,key:`s4cdu5`}]]),A=o(`smile`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M8 14s1.5 2 4 2 4-2 4-2`,key:`1y1vjs`}],[`line`,{x1:`9`,x2:`9.01`,y1:`9`,y2:`9`,key:`yxxnd0`}],[`line`,{x1:`15`,x2:`15.01`,y1:`9`,y2:`9`,key:`1p4y9e`}]]),he=o(`triangle-alert`,[[`path`,{d:`m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3`,key:`wmoenq`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),ge=o(`upload`,[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]),j=o(`user`,[[`path`,{d:`M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2`,key:`975kel`}],[`circle`,{cx:`12`,cy:`7`,r:`4`,key:`17ys0d`}]]),M=e(n(),1);function _e(){let[e,t]=(0,M.useState)([]),[n,r]=(0,M.useState)(!1),[i,a]=(0,M.useState)(null),o=(0,M.useRef)(null),s=(0,M.useCallback)(e=>{a(null);let n=e.find(e=>!g(e.type,ee));if(n){a(`Unsupported file type: "${n.type}". Supported: images, PDF, plain text, markdown, CSV, calendar, zip, voice notes.`);return}let r=e.find(e=>e.size>p);if(r){a(`"${r.name}" exceeds the 50 MB limit.`);return}t(t=>[...t,...e].slice(0,5))},[]);return{pendingFiles:e,setPendingFiles:t,isDragOver:n,attachError:i,setAttachError:a,fileInputRef:o,addFiles:s,clearFiles:(0,M.useCallback)(()=>{t([]),a(null)},[]),removeFile:(0,M.useCallback)(e=>{t(t=>t.filter((t,n)=>n!==e))},[]),onDragOver:(0,M.useCallback)(e=>{e.preventDefault(),r(!0)},[]),onDragLeave:(0,M.useCallback)(()=>{r(!1)},[]),onDrop:(0,M.useCallback)(e=>{e.preventDefault(),r(!1),s([...e.dataTransfer.files])},[s])}}var N=[[128512],[128515],[128516],[128513],[128518],[128517],[128514],[129315],[128578],[128579],[128521],[128522],[128519],[128525],[128536],[128535],[128540],[128541],[129303],[129300],[128528],[128566],[128564],[128526],[129395],[128546],[128557],[128548],[128544],[128533],[128556],[129393],[128077],[128078],[128076],[128591],[128079],[128588],[128170],[128075],[129309],[10084,65039],[128293],[11088],[127881],[10024],[128175],[128064]].map(e=>String.fromCodePoint(...e));function ve(e,t,n,r){let i=e.length,a=Math.max(0,Math.min(n??i,i)),o=Math.max(a,Math.min(r??a,i));return{value:e.slice(0,a)+t+e.slice(o),caret:a+t.length}}var P=i();function F({onSelect:e}){return(0,P.jsx)(`div`,{className:`wa-emoji-popover`,role:`menu`,"aria-label":`Emoji picker`,children:N.map((t,n)=>(0,P.jsx)(`button`,{type:`button`,role:`menuitem`,className:`wa-emoji-item`,onClick:()=>e(t),children:t},n))})}function ye({sessionKey:e,onPick:t,onClose:n}){let[i,a]=(0,M.useState)(``),[o,s]=(0,M.useState)(null),[c,l]=(0,M.useState)(null),[u,d]=(0,M.useState)(!1),f=(0,M.useCallback)(t=>{d(!0),l(null),fetch(`/api/admin/files?path=${encodeURIComponent(t)}&session_key=${encodeURIComponent(e)}`).then(async e=>{let t=await e.json().catch(()=>({}));if(!e.ok)throw Error(t.error??`Could not list files`);return t}).then(e=>{s(e),a(e.path===`.`?``:e.path)}).catch(e=>l(e instanceof Error?e.message:String(e))).finally(()=>d(!1))},[e]);(0,M.useEffect)(()=>{f(``)},[f]);let p=e=>f(i?`${i}/${e}`:e),m=()=>{let e=i.split(`/`).filter(Boolean);e.pop(),f(e.join(`/`))},h=e=>t({path:i?`${i}/${e.name}`:e.name,name:e.displayName??e.name});return(0,P.jsx)(`div`,{className:`wa-picker-backdrop`,role:`dialog`,"aria-label":`Choose a device file`,onClick:n,children:(0,P.jsxs)(`div`,{className:`wa-picker`,onClick:e=>e.stopPropagation(),children:[(0,P.jsxs)(`div`,{className:`wa-picker-head`,children:[i&&(0,P.jsx)(`button`,{type:`button`,className:`wa-picker-icon-btn`,onClick:m,"aria-label":`Up one folder`,children:(0,P.jsx)(y,{size:18})}),(0,P.jsx)(`span`,{className:`wa-picker-title`,children:i||`Device storage`}),(0,P.jsx)(`button`,{type:`button`,className:`wa-picker-icon-btn`,onClick:n,"aria-label":`Close file picker`,children:(0,P.jsx)(r,{size:18})})]}),c&&(0,P.jsx)(`p`,{className:`wa-picker-error`,role:`alert`,children:c}),u&&(0,P.jsx)(`p`,{className:`wa-picker-empty`,children:`Loading…`}),o&&!u&&(0,P.jsxs)(`ul`,{className:`wa-picker-list`,children:[o.entries.length===0&&(0,P.jsx)(`li`,{className:`wa-picker-empty`,children:`This folder is empty.`}),o.entries.map(e=>(0,P.jsx)(`li`,{children:e.kind===`directory`?(0,P.jsxs)(`button`,{type:`button`,className:`wa-picker-row`,onClick:()=>p(e.name),children:[(0,P.jsx)(ue,{size:16,"aria-hidden":!0}),(0,P.jsx)(`span`,{className:`wa-picker-name`,children:e.displayName??e.name})]}):e.kind===`file`?(0,P.jsxs)(`button`,{type:`button`,className:`wa-picker-row`,onClick:()=>h(e),children:[(0,P.jsx)(w,{size:16,"aria-hidden":!0}),(0,P.jsx)(`span`,{className:`wa-picker-name`,children:e.displayName??e.name})]}):null},e.name))]})]})})}function be(e){return`${Math.floor(e/60)}:${String(e%60).padStart(2,`0`)}`}function xe({accountId:e,remoteJid:t,sessionKey:n,replyTo:i,onClearReply:a}){let[o,s]=(0,M.useState)(``),[l,d]=(0,M.useState)(!1),[f,p]=(0,M.useState)(null),[g,_]=(0,M.useState)(!1),[ee,y]=(0,M.useState)(!1),[b,x]=(0,M.useState)([]),te=(0,M.useRef)(null),{pendingFiles:S,attachError:C,addFiles:re,removeFile:ie,clearFiles:ae}=_e(),{state:T,elapsedSeconds:E,errorMessage:D,start:oe,send:O,discard:se}=h(),ce=T===`recording`||T===`paused`,le=(0,M.useCallback)(()=>{console.info(`[operator-ui] op=voice-record state=start ms=0`),oe()},[oe]),ue=(0,M.useCallback)(async()=>{let e=E*1e3,t=await O();if(console.info(`[operator-ui] op=voice-record state=stop ms=${e}`),t){let e=t.type===`audio/ogg`?`.ogg`:t.type===`audio/mp4`?`.m4a`:`.webm`;re([new File([t],`voice-note${e}`,{type:t.type})])}},[E,O,re]),de=(0,M.useCallback)(()=>{console.info(`[operator-ui] op=voice-record state=cancel ms=${E*1e3}`),se()},[E,se]),fe=(0,M.useRef)(!1),pe=(o.trim().length>0||S.length>0||b.length>0)&&!l,he=(0,M.useCallback)(async()=>{if(!fe.current&&!(o.trim().length===0&&S.length===0&&b.length===0)){fe.current=!0,d(!0),p(null);try{let r=`/api/whatsapp-reader/reply?session_key=${encodeURIComponent(n)}`,c;if(S.length>0||b.length>0){let n=new FormData;n.append(`accountId`,e),n.append(`remoteJid`,t),o.trim()&&n.append(`text`,o);for(let e of S)n.append(`files`,e);for(let e of b)n.append(`fileRefs`,e.path);i&&n.append(`quotedId`,i.msgKeyId),c=await fetch(r,{method:`POST`,body:n})}else c=await fetch(r,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({accountId:e,remoteJid:t,text:o,...i?{quotedId:i.msgKeyId}:{}})});let l=await c.json().catch(()=>({}));if(!c.ok){p(l.error??`Send failed.`),console.info(`[operator-ui] op=reply-fail remoteJid=${t} error=${l.error??`unknown`}`);return}s(``),ae(),x([]),a?.(),console.info(`[operator-ui] op=reply-sent remoteJid=${t} sent=${l.sent??0}`)}catch(e){p(`Could not reach the server. Try again.`),console.info(`[operator-ui] op=reply-fail remoteJid=${t} error=${String(e)}`)}finally{fe.current=!1,d(!1)}}},[o,S,b,i,a,e,t,n,ae]),ge=(0,M.useCallback)(e=>{let t=te.current,{value:n,caret:r}=ve(o,e,t?t.selectionStart:null,t?t.selectionEnd:null);s(n),_(!1),requestAnimationFrame(()=>{let e=te.current;e&&(e.focus(),e.setSelectionRange(r,r))})},[o]),j=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),pe&&he())},N=e=>e.startsWith(`image/`)?(0,P.jsx)(k,{size:14}):e===`application/pdf`?(0,P.jsx)(w,{size:14}):(0,P.jsx)(v,{size:14});return(0,P.jsxs)(`div`,{className:`wa-reply`,children:[ee&&(0,P.jsx)(ye,{sessionKey:n,onPick:e=>{x(t=>[...t,e].slice(0,5)),y(!1)},onClose:()=>y(!1)}),g&&(0,P.jsx)(F,{onSelect:ge}),f&&(0,P.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:f}),C&&(0,P.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:C}),T===`error`&&D&&(0,P.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:D}),(S.length>0||b.length>0)&&(0,P.jsxs)(`div`,{className:`wa-reply-attachments`,children:[S.map((e,t)=>(0,P.jsxs)(`div`,{className:`wa-reply-chip`,children:[N(e.type),(0,P.jsx)(`span`,{className:`wa-reply-chip-name`,children:e.name}),(0,P.jsx)(`button`,{type:`button`,onClick:()=>ie(t),"aria-label":`Remove ${e.name}`,children:(0,P.jsx)(r,{size:12})})]},`f-${t}`)),b.map((e,t)=>(0,P.jsxs)(`div`,{className:`wa-reply-chip wa-reply-chip-ref`,children:[(0,P.jsx)(w,{size:14}),(0,P.jsx)(`span`,{className:`wa-reply-chip-name`,children:e.name}),(0,P.jsx)(`button`,{type:`button`,onClick:()=>x(e=>e.filter((e,n)=>n!==t)),"aria-label":`Remove ${e.name}`,children:(0,P.jsx)(r,{size:12})})]},`r-${t}`))]}),i&&(0,P.jsxs)(`div`,{className:`wa-reply-quote`,children:[(0,P.jsxs)(`div`,{className:`wa-reply-quote-body`,children:[(0,P.jsx)(`span`,{className:`wa-reply-quote-who`,children:i.fromMe?`You`:i.senderName??`Contact`}),(0,P.jsx)(`span`,{className:`wa-reply-quote-text`,children:i.body||`Message`})]}),(0,P.jsx)(`button`,{type:`button`,className:`wa-reply-quote-cancel`,onClick:()=>a?.(),"aria-label":`Cancel reply`,children:(0,P.jsx)(r,{size:14})})]}),(0,P.jsx)(`div`,{className:`wa-reply-row`,children:ce?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`button`,{type:`button`,className:`wa-reply-attach`,onClick:de,"aria-label":`Cancel recording`,children:(0,P.jsx)(c,{size:20})}),(0,P.jsxs)(`span`,{className:`wa-rec-live`,role:`status`,children:[(0,P.jsx)(`span`,{className:`wa-rec-dot`,"aria-hidden":!0}),be(E)]}),(0,P.jsx)(`button`,{type:`button`,className:`wa-reply-send`,onClick:()=>void ue(),"aria-label":`Stop recording`,children:(0,P.jsx)(u,{size:20})})]}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`button`,{type:`button`,className:`wa-reply-emoji`,onClick:()=>_(e=>!e),disabled:l,"aria-label":`Emoji`,"aria-expanded":g,children:(0,P.jsx)(A,{size:22})}),(0,P.jsx)(`button`,{type:`button`,className:`wa-reply-attach`,onClick:()=>y(!0),disabled:l,"aria-label":`Attach files`,children:(0,P.jsx)(ne,{size:22})}),(0,P.jsx)(`textarea`,{ref:te,className:`wa-reply-input`,value:o,rows:1,placeholder:`Type a message`,disabled:l,onChange:e=>s(e.target.value),onKeyDown:j}),(0,P.jsx)(`button`,{type:`button`,className:`wa-reply-mic`,onClick:()=>void le(),disabled:l,"aria-label":`Record voice note`,children:(0,P.jsx)(m,{size:22})}),(0,P.jsx)(`button`,{type:`button`,className:`wa-reply-send`,onClick:()=>void he(),disabled:!pe,"aria-label":`Send`,children:(0,P.jsx)(me,{size:20})})]})})]})}function Se({accountId:e,remoteJid:t,contactName:n,sessionKey:i,onBack:a}){let o=x(t),s=t.split(`@`)[0],c=o?`Group`:n===`+${s}`?void 0:`+${s}`,[l,u]=(0,M.useState)(!1),[d,f]=(0,M.useState)(``),p=()=>{u(!1),f(``)},[m,h]=(0,M.useState)(null);return(0,P.jsxs)(`div`,{className:`wa-web`,children:[(0,P.jsxs)(`header`,{className:`wa-web-header`,children:[a&&(0,P.jsx)(`button`,{type:`button`,className:`wa-web-back`,onClick:a,"aria-label":`Back`,children:(0,P.jsx)(y,{size:20})}),(0,P.jsx)(`span`,{className:`wa-web-avatar`,"aria-hidden":!0,children:(0,P.jsx)(j,{size:20})}),l?(0,P.jsxs)(`div`,{className:`wa-web-search`,children:[(0,P.jsx)(oe,{size:18,"aria-hidden":!0}),(0,P.jsx)(`input`,{className:`wa-web-search-input`,type:`text`,autoFocus:!0,placeholder:`Search messages`,"aria-label":`Search messages`,value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Escape`&&p()}}),(0,P.jsx)(`button`,{type:`button`,className:`wa-web-search-close`,onClick:p,"aria-label":`Close search`,children:(0,P.jsx)(r,{size:18})})]}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`div`,{className:`wa-web-titles`,children:[(0,P.jsx)(`span`,{className:`wa-web-name`,children:n}),c&&(0,P.jsx)(`span`,{className:`wa-web-subtitle`,children:c})]}),(0,P.jsx)(`button`,{type:`button`,className:`wa-web-search-toggle`,onClick:()=>u(!0),"aria-label":`Search messages`,children:(0,P.jsx)(oe,{size:20})})]})]}),(0,P.jsx)(`div`,{className:`wa-web-body`,children:(0,P.jsx)(_,{sessionId:``,projectDir:``,sessionKey:i,forceDeliveredOnly:!0,suppressDirectives:!0,store:{accountId:e,remoteJid:t},search:l?d:void 0,onReplyTo:o?void 0:h})}),o?(0,P.jsx)(`p`,{className:`wa-reply wa-reply-readonly`,children:`Group messages are read-only.`}):(0,P.jsx)(xe,{accountId:e,remoteJid:t,sessionKey:i,replyTo:m,onClearReply:()=>h(null)})]})}function Ce(e){let t=new Set,n=[];for(let r of e)for(let e of r.labels)e&&(t.has(e)||O.has(e)&&(t.add(e),n.push(e)));return n}function I(e){if(!e)return``;let t=new Date(e).getTime();return Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``}function L({conversations:e,sessionKey:t,onBack:n}){let[r,i]=(0,M.useState)(null),a=C(e);return r?r.source===`store`&&r.accountId&&r.remoteJid?(0,P.jsx)(Se,{accountId:r.accountId,remoteJid:r.remoteJid,contactName:b(r),sessionKey:t,onBack:()=>i(null)},T(r)):(0,P.jsxs)(`div`,{className:`op-conv op-conv-reader`,children:[(0,P.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,P.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:()=>i(null),"aria-label":`Back to conversations`,children:[(0,P.jsx)(y,{size:16}),` Back`]}),(0,P.jsx)(`span`,{className:`op-conv-title`,children:b(r)})]}),(0,P.jsx)(_,{sessionId:r.sessionId,projectDir:r.projectDir,sessionKey:t,forceDeliveredOnly:!0,suppressDirectives:r.source===`store`,store:r.source===`store`?{accountId:r.accountId,remoteJid:r.remoteJid}:void 0},T(r))]}):(0,P.jsxs)(`div`,{className:`op-conv op-conv-list`,children:[(0,P.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,P.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:n,"aria-label":`Back to chat`,children:[(0,P.jsx)(y,{size:16}),` Chat`]}),(0,P.jsx)(`span`,{className:`op-conv-title`,children:`Conversations`})]}),a.map(e=>(0,P.jsxs)(`div`,{className:`op-conv-group`,children:[(0,P.jsxs)(`div`,{className:`op-conv-group-head`,children:[(0,P.jsx)(D,{channel:e.channel,size:14}),e.label]}),e.rows.map(e=>(0,P.jsxs)(`button`,{type:`button`,className:`op-conv-row`,onClick:()=>{console.info(`[operator-ui] op=reader-open channel=${e.channel} key=${T(e)} readonly=true source=${e.source}`),i(e)},children:[(0,P.jsx)(`span`,{className:`op-conv-name`,children:b(e)}),e.modelGated&&(0,P.jsx)(`span`,{className:`op-conv-gated`,role:`img`,"aria-label":`Model unavailable`,children:(0,P.jsx)(he,{size:13})}),(0,P.jsx)(`span`,{className:`op-conv-when`,children:I(e.lastMessageAt)})]},T(e)))]},e.channel))]})}var R=/\.(png|jpe?g|gif|webp|svg)$/i;function we(e){return R.test(e)}var Te=`maxy-data-view`,Ee=95*1024*1024,De=48*1024*1024;function Oe(){return typeof window>`u`?`list`:window.localStorage.getItem(Te)===`grid`?`grid`:`list`}function ke(){let[e,t]=(0,M.useState)(null),[n,r]=(0,M.useState)(!1);return(0,M.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!n){t(null),r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]),n?e?(0,P.jsx)(l,{cacheKey:e,surface:`data`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=data`);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},children:(0,P.jsx)(`div`,{className:`data-page data-page-full`,children:(0,P.jsx)(z,{cacheKey:e})})}):(0,P.jsx)(`div`,{className:`data-page`,children:(0,P.jsxs)(`div`,{className:`data-empty`,children:[(0,P.jsx)(`p`,{children:`You are not signed in.`}),(0,P.jsxs)(`p`,{children:[`Open the `,(0,P.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,P.jsx)(`div`,{className:`data-page`,children:(0,P.jsxs)(`div`,{className:`data-loading`,children:[(0,P.jsx)(f,{size:18,className:`spin`}),` Loading…`]})})}function z({cacheKey:e}){let{adminFetch:n,cacheKey:r,sessionRefetchNonce:i}=t({initialCacheKey:e,surface:`data`});return(0,P.jsx)(Le,{adminFetch:n,cacheKey:r,sessionRefetchNonce:i})}function Ae(){if(typeof window>`u`)return`.`;let e=new URLSearchParams(window.location.hash.replace(/^#/,``)).get(`path`);return e&&e.length>0?e:`.`}function je(e){if(typeof window>`u`)return;let t=new URL(window.location.href);t.hash=e===`.`?``:`path=${encodeURIComponent(e)}`,window.history.replaceState(window.history.state,``,t.toString())}function Me(e){return new Promise((t,n)=>{let r=[],i=()=>e.readEntries(e=>{e.length===0?t(r):(r.push(...e),i())},n);i()})}function Ne(e){return new Promise((t,n)=>e.file(t,n))}async function Pe(e,t=``){let n=[];for(let r of e){if(!r)continue;let e=t?`${t}/${r.name}`:r.name;if(r.isFile)n.push({file:await Ne(r),relpath:e});else if(r.isDirectory){let t=await Me(r.createReader());n.push(...await Pe(t,e))}}return n}function Fe(e,t){if(e===422&&typeof t==`string`){if(/exceeds the .* limit/i.test(t))return`size`;if(/unsupported file type/i.test(t))return`mime`}return`http=${e}`}function Ie({adminFetch:e,cacheKey:t,sessionRefetchNonce:n}){let[i,o]=(0,M.useState)(``),s=(0,M.useRef)(null),[l,u]=(0,M.useState)(``),[d,p]=(0,M.useState)(null),[m,h]=(0,M.useState)(`hybrid`),[g,_]=(0,M.useState)(!1),[ee,v]=(0,M.useState)(null),[y,b]=(0,M.useState)(null),[x,ne]=(0,M.useState)(0),[C,T]=(0,M.useState)(!1),[D,O]=(0,M.useState)(()=>Ae()),[k,me]=(0,M.useState)(null),[A,he]=(0,M.useState)(()=>Oe()),[j,_e]=(0,M.useState)(null),[N,ve]=(0,M.useState)([]),[F,ye]=(0,M.useState)(!1),[be,xe]=(0,M.useState)(null),[Se,I]=(0,M.useState)(!1),[L,R]=(0,M.useState)(null),[ke,z]=(0,M.useState)(null),[Me,Ne]=(0,M.useState)(null),[Ie,Le]=(0,M.useState)(!1),[Re,Ve]=(0,M.useState)(null),B=(0,M.useRef)(null),[He,V]=(0,M.useState)(0),[Ge,Ke]=(0,M.useState)(!1),[qe,Je]=(0,M.useState)(``),[H,Ye]=(0,M.useState)(null),[Xe,Ze]=(0,M.useState)(``),[Qe,U]=(0,M.useState)(null),W=(()=>{let e=D===`.`?[]:D.split(`/`).filter(Boolean);return e.length>=2&&e[0]===`accounts`})(),[$e,et]=(0,M.useState)(!1),tt=(0,M.useRef)(null),[nt,G]=(0,M.useState)(!1),rt=(0,M.useRef)(null);(0,M.useEffect)(()=>{let e=i.trim();if(!e){u(``),p(null),v(null);return}T(!1);let t=setTimeout(()=>u(e),300);return()=>clearTimeout(t)},[i]),(0,M.useEffect)(()=>{if(!l){_(!1);return}let t=!1;return _(!0),v(null),e(`/api/admin/graph-search?q=${encodeURIComponent(l)}&labels=FileArtifact&limit=20${C?`&threshold=0`:``}`).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(e=>{t||(p(e.results),h(e.mode??`hybrid`),ne(typeof e.suppressed==`number`?e.suppressed:0))}).catch(e=>{t||v(e instanceof Error?e.message:String(e))}).finally(()=>{t||_(!1)}),()=>{t=!0}},[l,e,n,C]);let it=(0,M.useMemo)(()=>d?Ce(d):[],[d]),K=y&&it.includes(y)?y:null,at=(0,M.useMemo)(()=>d?K?d.filter(e=>e.labels.includes(K)):d:null,[d,K]),ot=(0,M.useCallback)(e=>{let n=e.properties.relativePath;if(typeof n!=`string`||n.length===0)return;let r=`/api/admin/files/download?session_key=${encodeURIComponent(t)}&path=${encodeURIComponent(n)}`,i=document.createElement(`a`);i.href=r,i.rel=`noopener noreferrer`,document.body.appendChild(i),i.click(),i.remove()},[t]);(0,M.useEffect)(()=>{if(!d)return;let e=d.filter(e=>{let t=e.properties.relativePath;return typeof t!=`string`||t.length===0});e.length>0&&console.warn(`[data-search] op=locate-link-missing nodeId=${e.map(e=>e.nodeId).join(`,`)}`)},[d]),(0,M.useEffect)(()=>{let t=!1;return ye(!0),xe(null),e(`/api/admin/files?path=${encodeURIComponent(D===`.`?``:D)}`).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(e=>{t||(me(e.entries),ve(e.displayPath??[]))}).catch(e=>{t||(me([]),ve([]),xe(e instanceof Error?e.message:String(e)))}).finally(()=>{t||ye(!1)}),()=>{t=!0}},[e,D,He,n]),(0,M.useEffect)(()=>{je(D)},[D]);let st=(0,M.useCallback)(()=>{V(e=>e+1)},[]),q=(0,M.useCallback)(e=>{et(!1),O(e)},[]),ct=(0,M.useCallback)(e=>{let t=e.properties.relativePath;if(typeof t!=`string`||t.length===0)return;let n=t.lastIndexOf(`/`),r=n===-1?`.`:t.slice(0,n);console.log(`[data-search] op=locate nodeId=${e.nodeId} folder=${r}`),o(``),v(null),b(null),q(r)},[q]),lt=(0,M.useCallback)(()=>{if(D===`.`||D===``)return;let e=D.split(`/`).filter(Boolean);e.pop(),O(e.length===0?`.`:e.join(`/`))},[D]),ut=(0,M.useCallback)(e=>{re(t,D===`.`?e.name:`${D}/${e.name}`)},[D,t]),[J,dt]=(0,M.useState)(!1),[Y,ft]=(0,M.useState)(new Set),pt=(0,M.useRef)(null),X=(0,M.useRef)(!1),mt=typeof navigator<`u`&&typeof navigator.share==`function`&&typeof navigator.canShare==`function`,ht=(0,M.useCallback)(e=>{dt(!0),ft(new Set([e])),console.info(`[data-ui] op=select-enter count=1`)},[]),Z=(0,M.useCallback)(e=>{dt(!1),ft(new Set),console.info(`[data-ui] op=select-exit reason=${e}`)},[]),Q=(0,M.useCallback)(e=>{ft(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),gt=(0,M.useCallback)(e=>{X.current=!1,pt.current=setTimeout(()=>{X.current=!0,ht(e)},500)},[ht]),$=(0,M.useCallback)(()=>{pt.current&&=(clearTimeout(pt.current),null)},[]),_t=(0,M.useCallback)(e=>{if(X.current){X.current=!1;return}if(J){Q(e.name);return}ut(e)},[J,Q,ut]),vt=(0,M.useCallback)(e=>{he(e),typeof window<`u`&&window.localStorage.setItem(Te,e),console.info(`[data] op=view-mode mode=${e}`)},[]),yt=(0,M.useCallback)(e=>{if(X.current){X.current=!1;return}if(J){Q(e.name);return}_e({src:E(t,D===`.`?e.name:`${D}/${e.name}`),alt:e.displayName??e.name})},[J,Q,D,t]),bt=(0,M.useCallback)(()=>(k??[]).filter(e=>e.kind===`file`&&Y.has(e.name)),[k,Y]),xt=(0,M.useCallback)(()=>(k??[]).filter(e=>(e.kind===`file`||e.kind===`directory`)&&Y.has(e.name)),[k,Y]),St=(0,M.useCallback)(()=>{let e=xt(),n=e.some(e=>e.kind===`directory`);e.length===1&&!n?ut(e[0]):e.length>=1&&ae(t,e.map(e=>D===`.`?e.name:`${D}/${e.name}`)),Z(`action`)},[xt,ut,D,t,Z]),Ct=(0,M.useCallback)(async()=>{let t=bt(),n=t.filter(e=>!e.protected),r=t.length-n.length;Ve(r>0?`${r} protected file(s) kept`:null);for(let t of n){let n=D===`.`?t.name:`${D}/${t.name}`;try{let t=await e(`/api/admin/files?path=${encodeURIComponent(n)}`,{method:`DELETE`}),r=await t.json().catch(()=>({error:`HTTP ${t.status}`}));if(!t.ok)throw Error(r.error??`HTTP ${t.status}`)}catch(e){Ve(e instanceof Error?e.message:String(e))}}V(e=>e+1),Z(`action`)},[bt,D,e,Z]),wt=(0,M.useCallback)(async()=>{let e=bt();if(console.info(`[data-ui] op=share supported=${mt} count=${e.length}`),mt)try{let n=await Promise.all(e.map(async e=>{let n=D===`.`?e.name:`${D}/${e.name}`,r=`/api/admin/files/download?session_key=${encodeURIComponent(t)}&path=${encodeURIComponent(n)}`,i=await(await fetch(r)).blob();return new File([i],e.name,{type:i.type||`application/octet-stream`})}));navigator.canShare({files:n})&&await navigator.share({files:n})}catch(e){console.warn(`[data-ui] op=share-failed err=${e instanceof Error?e.message:String(e)}`)}},[bt,mt,D,t]),Tt=(0,M.useCallback)(()=>{B.current?.click()},[]),Et=(0,M.useCallback)((e,n={})=>{let r=(r,i,a)=>{let o=new URLSearchParams({session_key:t,path:D===`.`?``:D,filename:e.name});n.relpath&&o.set(`relpath`,n.relpath),n.token&&o.set(`token`,n.token);for(let[e,t]of Object.entries(i))o.set(e,t);return new Promise(t=>{let n=new XMLHttpRequest;n.open(`POST`,`/api/admin/files/upload?${o.toString()}`),n.setRequestHeader(`Content-Type`,e.type||`application/octet-stream`),a&&(n.upload.onprogress=e=>{e.lengthComputable&&a(e.loaded)}),n.onload=()=>{let e={};try{e=JSON.parse(n.responseText)}catch{}t({status:n.status,data:e})},n.onerror=()=>t({status:0,data:{}}),n.onabort=()=>t({status:0,data:{error:`aborted`}}),n.send(r)})};if(e.size<=Ee)return r(e,{},t=>n.onProgress?.(t,e.size));let i=`${Date.now().toString(36)}-${Math.random().toString(16).slice(2,10)}`,a=Math.ceil(e.size/De);return(async()=>{let t={status:0,data:{}};for(let o=0;o<a;o++){let s=o*De;if(t=await r(e.slice(s,Math.min(s+De,e.size)),{uploadId:i,seq:String(o),total:String(a)},t=>n.onProgress?.(s+t,e.size)),!(t.status>=200&&t.status<300))return t}return t})()},[t,D]),Dt=(0,M.useCallback)(async e=>{z(null),I(!0),R({loaded:0,total:e.size});try{let{status:t,data:n}=await Et(e,{onProgress:(e,t)=>R({loaded:e,total:t})});t>=200&&t<300&&n.path?(O(n.path.split(`/`).slice(0,-1).join(`/`)||`.`),V(e=>e+1)):z(t===0?`Network error during upload — the connection failed before the server responded.`:n.error??`Upload failed (HTTP ${t}).`)}finally{I(!1),R(null),B.current&&(B.current.value=``)}},[Et]),Ot=(0,M.useCallback)(e=>{W&&Array.from(e.dataTransfer.types).includes(`Files`)&&(e.preventDefault(),Le(!0))},[W]),kt=(0,M.useCallback)(e=>{e.currentTarget.contains(e.relatedTarget)||Le(!1)},[]),At=(0,M.useCallback)(async e=>{e.preventDefault(),Le(!1);let t=Math.random().toString(16).slice(2,10),n=Array.from(e.dataTransfer.items);if(console.info(`[data-ui] op=drop-received token=${t} items=${n.length}`),n.length===0)return;if(!W){console.info(`[data-ui] op=drop-rejected token=${t} reason=no-write`),z(`Open a folder inside your account to upload`);return}let r=n.map(e=>e.webkitGetAsEntry?.()).filter(e=>!!e);I(!0),z(null),Ne(null);let i=performance.now();try{let e=await Pe(r),n=e.reduce((e,t)=>e+t.file.size,0),a=new Set(e.map(e=>e.relpath.split(`/`).slice(0,-1).join(`/`)).filter(Boolean)).size;console.info(`[data-ui] op=drop-walk token=${t} files=${e.length} dirs=${a} bytes=${n}`);let o=0,s=[];for(let n=0;n<e.length;n++){let{file:r,relpath:i}=e[n];console.info(`[data-ui] op=drop-file token=${t} rel="${i}" i=${n+1}/${e.length}`),R({loaded:0,total:r.size});let{status:a,data:c}=await Et(r,{relpath:i,token:t,onProgress:(e,t)=>R({loaded:e,total:t})});if(a>=200&&a<300)o++,console.info(`[data-ui] op=drop-file-ok token=${t} rel="${i}"`);else{let e=a===0?`http=0`:Fe(a,c.error);s.push(`${i} (${e})`),console.info(`[data-ui] op=drop-file-skip token=${t} rel="${i}" reason=${e}`)}}let c=Math.round(performance.now()-i);console.info(`[data-ui] op=drop-done token=${t} uploaded=${o} skipped=${s.length} ms=${c}`),Ne(`Uploaded ${o}, skipped ${s.length}${s.length?`: ${s.join(`, `)}`:``}`),V(e=>e+1)}catch(e){z(e instanceof Error?e.message:String(e))}finally{I(!1),R(null)}},[W,Et]),jt=(0,M.useCallback)(async()=>{let t=qe.trim();if(t){U(null);try{let n=await e(`/api/admin/files/folder`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:D===`.`?``:D,name:t})}),r=await n.json().catch(()=>({error:`HTTP ${n.status}`}));if(!n.ok)throw Error(r.error??`HTTP ${n.status}`);Ke(!1),Je(``),V(e=>e+1)}catch(e){U(e instanceof Error?e.message:String(e))}}},[e,qe,D]),Mt=(0,M.useCallback)(async()=>{if(!H)return;let t=Xe.trim();if(!t)return;U(null);let n=D===`.`?H:`${D}/${H}`;try{let r=await e(`/api/admin/files/rename`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:n,newName:t})}),i=await r.json().catch(()=>({error:`HTTP ${r.status}`}));if(!r.ok)throw Error(i.error??`HTTP ${r.status}`);Ye(null),Ze(``),Z(`action`),V(e=>e+1)}catch(e){U(e instanceof Error?e.message:String(e))}},[e,Xe,H,D,Z]);(0,M.useEffect)(()=>{if(!$e)return;let e=e=>{tt.current&&!tt.current.contains(e.target)&&et(!1)},t=e=>{e.key===`Escape`&&et(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[$e]),(0,M.useEffect)(()=>{if(!nt)return;let e=e=>{rt.current&&!rt.current.contains(e.target)&&G(!1)},t=e=>{e.key===`Escape`&&G(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[nt]);let Nt=(0,M.useCallback)(e=>N.slice(0,e+1).map(e=>e.name).join(`/`),[N]),Pt=N.length>=2,Ft=Pt?[{name:`.`,label:`data`},...N.slice(0,N.length-2).map((e,t)=>({name:Nt(t),label:e.displayName??e.name}))]:[];return(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`div`,{className:`data-toolbar`,children:[J?(0,P.jsxs)(`button`,{type:`button`,className:`data-select-cancel`,onClick:()=>Z(`cancel`),"aria-label":`Cancel selection`,children:[(0,P.jsx)(r,{size:14}),` Cancel`]}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`div`,{className:`data-search-input`,children:[i===``&&(0,P.jsx)(oe,{size:14}),(0,P.jsx)(`input`,{ref:s,type:`text`,value:i,onChange:e=>o(e.target.value),autoFocus:!0,autoComplete:`off`,spellCheck:!1}),g&&(0,P.jsx)(f,{size:14,className:`spin`}),i!==``&&(0,P.jsx)(`button`,{type:`button`,className:`data-search-inline-btn`,onClick:()=>{o(``),s.current?.focus()},title:`Clear search`,"aria-label":`Clear search`,children:(0,P.jsx)(r,{size:14})})]}),(0,P.jsxs)(`div`,{className:`data-toolbar-actions`,ref:rt,children:[(0,P.jsx)(`button`,{type:`button`,className:`data-action-overflow`,onClick:()=>G(e=>!e),"aria-haspopup":`menu`,"aria-expanded":nt,"aria-label":`File actions`,title:`File actions`,children:(0,P.jsx)(ce,{size:16})}),(0,P.jsxs)(`div`,{className:`data-action-group`,role:`group`,"aria-label":`File actions`,"data-open":nt?`true`:void 0,children:[(0,P.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{st(),G(!1)},disabled:F,title:`Refresh this folder`,"aria-label":`Refresh this folder`,children:[F?(0,P.jsx)(f,{size:16,className:`spin`}):(0,P.jsx)(te,{size:16}),(0,P.jsx)(`span`,{className:`data-action-label`,children:`Refresh`})]}),(0,P.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{Tt(),G(!1)},disabled:Se||!W,title:W?`Upload a file`:`Open a folder inside your account to upload`,"aria-label":`Upload a file`,children:[Se?L&&L.total>0?(0,P.jsxs)(`span`,{className:`data-upload-pct`,children:[Math.round(L.loaded/L.total*100),`%`]}):(0,P.jsx)(f,{size:16,className:`spin`}):(0,P.jsx)(ge,{size:16}),(0,P.jsx)(`span`,{className:`data-action-label`,children:`Upload`})]}),(0,P.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{Ke(e=>!e),Je(``),U(null),G(!1)},disabled:Se||!W,title:W?`New folder`:`Open a folder inside your account to create one`,"aria-label":`New folder`,children:[(0,P.jsx)(le,{size:16}),(0,P.jsx)(`span`,{className:`data-action-label`,children:`New folder`})]}),(0,P.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{vt(A===`grid`?`list`:`grid`),G(!1)},title:A===`grid`?`List view`:`Grid view`,"aria-label":A===`grid`?`Switch to list view`:`Switch to grid view`,"aria-pressed":A===`grid`,children:[A===`grid`?(0,P.jsx)(fe,{size:16}):(0,P.jsx)(de,{size:16}),(0,P.jsx)(`span`,{className:`data-action-label`,children:A===`grid`?`List view`:`Grid view`})]})]})]})]}),(0,P.jsxs)(`div`,{className:`data-breadcrumbs`,children:[D!==`.`&&(0,P.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost data-back-btn`,onClick:lt,title:`Up one level`,"aria-label":`Up one level`,children:(0,P.jsx)(se,{size:14})}),Pt?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`span`,{className:`data-crumb-wrap`,ref:tt,children:[(0,P.jsx)(`button`,{type:`button`,className:`data-crumb data-crumb-ellipsis`,onClick:()=>et(e=>!e),"aria-haspopup":`menu`,"aria-expanded":$e,"aria-label":`Show parent folders`,title:`Show parent folders`,children:`…`}),$e&&(0,P.jsx)(`div`,{className:`data-crumb-menu`,role:`menu`,children:Ft.map(e=>(0,P.jsx)(`button`,{type:`button`,role:`menuitem`,className:`data-crumb-menu-item`,onClick:()=>q(e.name),title:e.label,children:e.label},e.name))})]}),[N.length-2,N.length-1].map(e=>{let t=N[e];return(0,P.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,P.jsx)(`span`,{className:`data-crumb-sep`,children:`/`}),(0,P.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>q(Nt(e)),title:t.name,children:t.displayName??t.name})]},Nt(e))})]}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>q(`.`),children:`data`}),N.map((e,t)=>(0,P.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,P.jsx)(`span`,{className:`data-crumb-sep`,children:`/`}),(0,P.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>q(Nt(t)),title:e.name,children:e.displayName??e.name})]},Nt(t)))]})]}),Ge&&(0,P.jsxs)(`div`,{className:`data-inline-form`,children:[(0,P.jsx)(`input`,{type:`text`,className:`data-inline-input`,placeholder:`Folder name`,value:qe,autoFocus:!0,onChange:e=>Je(e.target.value),onKeyDown:e=>{e.key===`Enter`&&jt(),e.key===`Escape`&&Ke(!1)}}),(0,P.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:jt,children:`Create`}),(0,P.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost`,onClick:()=>Ke(!1),children:`Cancel`})]}),H&&(0,P.jsxs)(`div`,{className:`data-inline-form`,children:[(0,P.jsx)(`input`,{type:`text`,className:`data-inline-input`,placeholder:`New name`,value:Xe,autoFocus:!0,onChange:e=>Ze(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Mt(),e.key===`Escape`&&Ye(null)}}),(0,P.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:Mt,children:`Rename`}),(0,P.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost`,onClick:()=>Ye(null),children:`Cancel`})]}),Qe&&(0,P.jsx)(`div`,{className:`data-error`,children:Qe}),(0,P.jsx)(`input`,{type:`file`,ref:B,hidden:!0,onChange:e=>{let t=e.target.files?.[0];t&&Dt(t)}})]}),(0,P.jsxs)(`div`,{className:`data-body`,"data-drag-active":Ie?`true`:void 0,onDragEnter:Ot,onDragOver:Ot,onDragLeave:kt,onDrop:At,children:[(ee!==null||d!==null)&&(0,P.jsxs)(`section`,{className:`data-panel`,children:[ee&&(0,P.jsxs)(`div`,{className:`data-error`,children:[`Search failed: `,ee]}),it.length>0&&(0,P.jsx)(`div`,{className:`data-chip-row`,role:`group`,"aria-label":`Filter by type`,children:it.map(e=>{let t=e===K;return(0,P.jsx)(`button`,{type:`button`,className:`data-chip`,"data-active":t,onClick:()=>b(t?null:e),children:Be([e])??e},e)})}),d&&!g&&(0,P.jsxs)(`div`,{className:`data-results-meta`,children:[at.length,` of `,d.length,` result`,d.length===1?``:`s`]}),d&&!g&&!K&&x>0&&!C&&(0,P.jsxs)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>T(!0),children:[x,` low-confidence result`,x===1?``:`s`,` hidden — show all`]}),d&&!g&&!K&&C&&(0,P.jsx)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>T(!1),children:`Showing all results — hide low-confidence`}),d&&d.length===0&&!g&&(0,P.jsx)(`div`,{className:`data-empty-results`,children:`No matches. Try a different keyword.`}),at&&at.length>0&&(0,P.jsx)(`ul`,{className:`data-results`,children:at.map(e=>(0,P.jsx)(ze,{hit:e,mode:m,onDownload:ot,onLocate:ct},e.nodeId))})]}),(0,P.jsxs)(`section`,{className:`data-panel`,children:[L&&(0,P.jsxs)(`div`,{className:`data-upload-progress`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":L.total>0?Math.round(L.loaded/L.total*100):void 0,children:[(0,P.jsx)(`div`,{className:`data-upload-progress-track`,children:(0,P.jsx)(`div`,{className:`data-upload-progress-fill`,style:{width:`${L.total>0?Math.round(L.loaded/L.total*100):0}%`}})}),(0,P.jsxs)(`span`,{className:`data-upload-progress-label`,children:[`Uploading… `,L.total>0?`${Math.round(L.loaded/L.total*100)}%`:``]})]}),ke&&(0,P.jsxs)(`div`,{className:`data-error`,children:[`Upload failed: `,ke]}),Me&&(0,P.jsx)(`div`,{className:`data-status`,children:Me}),Re&&(0,P.jsxs)(`div`,{className:`data-error`,children:[`Delete failed: `,Re]}),be&&(0,P.jsx)(`div`,{className:`data-error`,children:be}),F&&(0,P.jsxs)(`div`,{className:`data-loading`,children:[(0,P.jsx)(f,{size:14,className:`spin`}),` Loading…`]}),!J&&!F&&k&&k.length>0&&(0,P.jsxs)(`div`,{className:`data-select-hint`,children:[(0,P.jsx)(pe,{size:13}),(0,P.jsx)(`span`,{children:`Press and hold a file to select, rename, or delete it.`})]}),!F&&k&&k.length===0&&!be&&(0,P.jsx)(`div`,{className:`data-empty-results`,children:`Empty directory.`}),!F&&k&&k.length>0&&A===`grid`&&(0,P.jsx)(`ul`,{className:`data-grid`,children:k.map(e=>{let n=e.displayName??e.name,r=J&&Y.has(e.name);if(e.kind===`directory`)return(0,P.jsx)(`li`,{className:`data-grid-cell`,"data-selected":r?`true`:void 0,children:(0,P.jsxs)(`button`,{type:`button`,className:`data-grid-tile`,onPointerDown:()=>gt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>{if(X.current){X.current=!1;return}if(J){Q(e.name);return}q(D===`.`?e.name:`${D}/${e.name}`)},children:[J&&(0,P.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,P.jsx)(ue,{size:28,className:`data-grid-glyph`}),(0,P.jsx)(`span`,{className:`data-grid-label`,title:e.name,children:n})]})},e.name);if(e.kind===`file`){let i=we(e.name),a=D===`.`?e.name:`${D}/${e.name}`;return(0,P.jsx)(`li`,{className:`data-grid-cell`,"data-selected":r?`true`:void 0,children:(0,P.jsxs)(`button`,{type:`button`,className:`data-grid-tile${i?` data-grid-tile-image`:``}`,onPointerDown:()=>gt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>i?yt(e):_t(e),title:J?void 0:i?`Preview ${n}`:`Download ${n}`,children:[J&&(0,P.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),i?(0,P.jsx)(`img`,{className:`data-grid-thumb`,src:E(t,a),alt:n,loading:`lazy`,onError:()=>console.warn(`[data] op=thumb-error path=${a}`)}):(0,P.jsx)(w,{size:28,className:`data-grid-glyph`}),(0,P.jsx)(`span`,{className:`data-grid-label`,title:e.name,children:n}),!i&&(0,P.jsx)(`span`,{className:`data-grid-sub`,children:Ue(e.sizeBytes)})]})},e.name)}return(0,P.jsx)(`li`,{className:`data-grid-cell`,children:(0,P.jsxs)(`div`,{className:`data-grid-tile data-entry-disabled`,children:[(0,P.jsx)(w,{size:28,className:`data-grid-glyph`}),(0,P.jsx)(`span`,{className:`data-grid-label`,children:n}),(0,P.jsx)(`span`,{className:`data-grid-sub`,children:`special`})]})},e.name)})}),!F&&k&&k.length>0&&A===`list`&&(0,P.jsx)(`ul`,{className:`data-entries`,children:k.map(e=>{let t=e.displayName??e.name;if(e.kind===`directory`){let n=J&&Y.has(e.name);return(0,P.jsx)(`li`,{className:`data-entry`,"data-selected":n?`true`:void 0,children:(0,P.jsxs)(`button`,{type:`button`,className:`data-entry-btn`,onPointerDown:()=>gt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>{if(X.current){X.current=!1;return}if(J){Q(e.name);return}q(D===`.`?e.name:`${D}/${e.name}`)},children:[J&&(0,P.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,P.jsx)(ue,{size:14}),(0,P.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t})]})},e.name)}if(e.kind===`file`){let n=J&&Y.has(e.name);return(0,P.jsx)(`li`,{className:`data-entry`,"data-selected":n?`true`:void 0,children:(0,P.jsxs)(`button`,{type:`button`,className:`data-entry-btn data-entry-file`,onPointerDown:()=>gt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>_t(e),title:J?void 0:`Download ${t}`,children:[J&&(0,P.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,P.jsxs)(`span`,{className:`data-entry-text`,children:[(0,P.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t}),(0,P.jsxs)(`span`,{className:`data-entry-meta`,title:`Modified ${We(e.modifiedAt)}`,children:[Ue(e.sizeBytes),` · `,We(e.modifiedAt)]})]})]})},e.name)}return(0,P.jsx)(`li`,{className:`data-entry`,children:(0,P.jsx)(`div`,{className:`data-entry-btn data-entry-file data-entry-disabled`,children:(0,P.jsxs)(`span`,{className:`data-entry-text`,children:[(0,P.jsx)(`span`,{className:`data-entry-name`,children:t}),(0,P.jsx)(`span`,{className:`data-entry-meta`,children:`special`})]})})},e.name)})})]})]}),J&&(0,P.jsx)(`div`,{className:`data-select-bar`,role:`toolbar`,"aria-label":`Selection actions`,children:(0,P.jsxs)(`div`,{className:`data-select-bar-inner`,children:[(0,P.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:wt,disabled:!mt||Y.size===0,title:mt?`Share selected files`:`Sharing is not supported on this device`,children:[(0,P.jsx)(a,{size:16}),` Share`]}),(0,P.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:St,disabled:Y.size===0,children:[(0,P.jsx)(S,{size:16}),` Download`]}),(0,P.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:()=>{let e=[...Y][0];e&&(Ye(e),Ze(e))},disabled:Y.size!==1,children:[(0,P.jsx)(ie,{size:16}),` Rename`]}),(0,P.jsxs)(`button`,{type:`button`,className:`data-select-action data-select-delete`,onClick:Ct,disabled:Y.size===0,children:[(0,P.jsx)(c,{size:16}),` Delete`]})]})}),j&&(0,P.jsx)(`div`,{className:`chat-attachment-overlay`,role:`dialog`,"aria-label":j.alt,onClick:()=>_e(null),children:(0,P.jsx)(`img`,{className:`chat-attachment-overlay-image`,src:j.src,alt:j.alt})})]})}function Le({adminFetch:e,cacheKey:t,sessionRefetchNonce:n}){(0,M.useEffect)(()=>{console.info(`[data-ui] op=mount header=operator home=absent`)},[]);let r=(0,M.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]),i=(0,M.useCallback)(e=>{e===`chat`&&(window.location.href=`/`)},[]),[a,o]=(0,M.useState)([]),[c,l]=(0,M.useState)(`files`),{subAccounts:u,activeAccountId:f,switching:p,switchAccount:m}=d(t);return(0,M.useEffect)(()=>{if(!t)return;let e=!1;return fetch(`/api/whatsapp-reader/conversations?session_key=${encodeURIComponent(t)}`).then(e=>e.ok?e.json():{conversations:[]}).then(t=>{e||o(t.conversations??[])}).catch(()=>{}),()=>{e=!0}},[t]),(0,P.jsxs)(`main`,{className:`data-main`,children:[(0,P.jsx)(s,{variant:`operator`,onNavigate:i,onOpenConversations:a.length>0?()=>l(`conversations`):void 0,onToggleSidebar:()=>{},sidebarOpen:!1,onLogout:r,onDisconnect:async()=>!0,disconnecting:!1,subAccounts:u,activeAccountId:f,switchingAccount:p,onSwitchAccount:m}),c===`conversations`?(0,P.jsx)(L,{conversations:a,sessionKey:t,onBack:()=>l(`files`)}):(0,P.jsx)(Ie,{adminFetch:e,cacheKey:t,sessionRefetchNonce:n})]})}function Re({cacheKey:e}){let{adminFetch:n,cacheKey:r,sessionRefetchNonce:i}=t({initialCacheKey:e,surface:`data`});return(0,P.jsx)(`div`,{className:`data-page`,children:(0,P.jsx)(`main`,{className:`data-main`,children:(0,P.jsx)(Ie,{adminFetch:n,cacheKey:r,sessionRefetchNonce:i})})})}function ze({hit:e,mode:t,onDownload:n,onLocate:r}){let i=Ve(e.properties),a=B(e.properties),o=Be(e.labels),s=He(e.properties),[c,l]=(0,M.useState)(!1),u=a&&a.length>280,d=c||!u?a:a?.slice(0,280)+`…`,f=t===`bm25`?`bm25 ${e.bm25Score.toFixed(2)}`:`vector ${e.vectorScore.toFixed(2)} · bm25 ${e.bm25Score.toFixed(2)} · combined ${e.score.toFixed(2)}`,p=e.properties.relativePath,m=typeof p==`string`&&p.length>0,h=m?p.lastIndexOf(`/`):-1,g=m?h===-1?`data`:p.slice(0,h):null;return(0,P.jsxs)(`li`,{className:`data-result`,children:[(0,P.jsxs)(`div`,{role:`button`,tabIndex:0,className:`data-result-open`,onClick:()=>n(e),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),n(e))},"aria-label":`Download ${i??o??`file`}`,children:[o&&(0,P.jsx)(`div`,{className:`data-result-header`,children:(0,P.jsx)(`span`,{className:`data-result-labels`,children:o})}),i&&(0,P.jsx)(`div`,{className:`data-result-title`,children:i}),a&&(0,P.jsx)(`pre`,{className:`data-result-body`,children:d}),(0,P.jsxs)(`div`,{className:`data-result-scores`,children:[s&&(0,P.jsxs)(`span`,{className:`data-result-updated`,children:[`Updated `,We(s),` · `]}),f]})]}),m&&(0,P.jsxs)(`button`,{type:`button`,className:`data-result-locate`,onClick:()=>r(e),title:`Locate in ${g}`,"aria-label":`Locate in ${g}`,children:[(0,P.jsx)(ue,{size:12}),g]}),u&&(0,P.jsx)(`button`,{type:`button`,className:`data-result-toggle`,onClick:()=>l(e=>!e),children:c?`Show less`:`Show more`})]})}function Be(e){if(e.length===0)return null;let t=e[0].replace(/([a-z])([A-Z])/g,`$1 $2`);return t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()}function Ve(e){for(let t of[`title`,`name`,`summary`,`headline`]){let n=e[t];if(typeof n==`string`&&n.length>0)return n.length>140?n.slice(0,140)+`…`:n}return null}function B(e){for(let t of[`content`,`summary`,`body`,`description`,`text`]){let n=e[t];if(typeof n==`string`&&n.length>0)return n}return null}function He(e){for(let t of[`updatedAt`,`modifiedAt`,`fetchedAt`,`createdAt`,`lastModified`]){let n=e[t];if(typeof n==`string`&&n.length>0)return n}return null}function Ue(e){return e==null?``:e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)} MB`:`${(e/1024/1024/1024).toFixed(1)} GB`}function We(e){try{let t=new Date(e);if(isNaN(t.getTime()))return`—`;let n=typeof navigator<`u`?navigator.languages&&navigator.languages.length>0?[...navigator.languages]:[navigator.language]:void 0;return t.toLocaleString(n,{dateStyle:`medium`,timeStyle:`short`})}catch{return`—`}}export{Re as n,Se as r,ke as t};
1
+ import{o as e}from"./chunk-Ck5AOu5v.js";import{S as t,T as n,a as r,b as i,c as a,h as o,n as s,o as c,r as l,s as u,t as d,u as f}from"./useSubAccountSwitcher-Bo7bnFtC.js";import{S as p,T as m,n as h,r as g,s as _,w as ee,x as v}from"./useVoiceRecorder-CZPtVpM-.js";import{t as y}from"./chevron-left-B2DKUxLk.js";import{a as b,c as x,d as te,f as ne,h as S,i as C,m as w,n as re,p as ie,r as ae,s as T,t as E,u as D}from"./file-download-CHTyUQqS.js";import{i as oe,t as O}from"./graph-labels-CmCWaKJT.js";var se=o(`arrow-left`,[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]),ce=o(`ellipsis`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]]),le=o(`folder-plus`,[[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`M9 13h6`,key:`1uhe8q`}],[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),ue=o(`folder`,[[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),k=o(`image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),de=o(`layout-grid`,[[`rect`,{width:`7`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`1g98yp`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`3`,rx:`1`,key:`6d4xhi`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`14`,rx:`1`,key:`nxv5o0`}],[`rect`,{width:`7`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`1bb6yr`}]]),fe=o(`list`,[[`path`,{d:`M3 5h.01`,key:`18ugdj`}],[`path`,{d:`M3 12h.01`,key:`nlz23k`}],[`path`,{d:`M3 19h.01`,key:`noohij`}],[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M8 12h13`,key:`1za7za`}],[`path`,{d:`M8 19h13`,key:`m83p4d`}]]),pe=o(`mouse-pointer-click`,[[`path`,{d:`M14 4.1 12 6`,key:`ita8i4`}],[`path`,{d:`m5.1 8-2.9-.8`,key:`1go3kf`}],[`path`,{d:`m6 12-1.9 2`,key:`mnht97`}],[`path`,{d:`M7.2 2.2 8 5.1`,key:`1cfko1`}],[`path`,{d:`M9.037 9.69a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z`,key:`s0h3yz`}]]),me=o(`send-horizontal`,[[`path`,{d:`M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z`,key:`117uat`}],[`path`,{d:`M6 12h16`,key:`s4cdu5`}]]),A=o(`smile`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M8 14s1.5 2 4 2 4-2 4-2`,key:`1y1vjs`}],[`line`,{x1:`9`,x2:`9.01`,y1:`9`,y2:`9`,key:`yxxnd0`}],[`line`,{x1:`15`,x2:`15.01`,y1:`9`,y2:`9`,key:`1p4y9e`}]]),he=o(`triangle-alert`,[[`path`,{d:`m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3`,key:`wmoenq`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),ge=o(`upload`,[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]),j=o(`user`,[[`path`,{d:`M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2`,key:`975kel`}],[`circle`,{cx:`12`,cy:`7`,r:`4`,key:`17ys0d`}]]),M=e(n(),1);function _e(){let[e,t]=(0,M.useState)([]),[n,r]=(0,M.useState)(!1),[i,a]=(0,M.useState)(null),o=(0,M.useRef)(null),s=(0,M.useCallback)(e=>{a(null);let n=e.find(e=>!g(e.type,m));if(n){a(`Unsupported file type: "${n.type}". Supported: images, PDF, plain text, markdown, CSV, calendar, zip, voice notes.`);return}let r=e.find(e=>e.size>ee);if(r){a(`"${r.name}" exceeds the 50 MB limit.`);return}t(t=>[...t,...e].slice(0,5))},[]);return{pendingFiles:e,setPendingFiles:t,isDragOver:n,attachError:i,setAttachError:a,fileInputRef:o,addFiles:s,clearFiles:(0,M.useCallback)(()=>{t([]),a(null)},[]),removeFile:(0,M.useCallback)(e=>{t(t=>t.filter((t,n)=>n!==e))},[]),onDragOver:(0,M.useCallback)(e=>{e.preventDefault(),r(!0)},[]),onDragLeave:(0,M.useCallback)(()=>{r(!1)},[]),onDrop:(0,M.useCallback)(e=>{e.preventDefault(),r(!1),s([...e.dataTransfer.files])},[s])}}var N=[[128512],[128515],[128516],[128513],[128518],[128517],[128514],[129315],[128578],[128579],[128521],[128522],[128519],[128525],[128536],[128535],[128540],[128541],[129303],[129300],[128528],[128566],[128564],[128526],[129395],[128546],[128557],[128548],[128544],[128533],[128556],[129393],[128077],[128078],[128076],[128591],[128079],[128588],[128170],[128075],[129309],[10084,65039],[128293],[11088],[127881],[10024],[128175],[128064]].map(e=>String.fromCodePoint(...e));function ve(e,t,n,r){let i=e.length,a=Math.max(0,Math.min(n??i,i)),o=Math.max(a,Math.min(r??a,i));return{value:e.slice(0,a)+t+e.slice(o),caret:a+t.length}}var P=i();function F({onSelect:e}){return(0,P.jsx)(`div`,{className:`wa-emoji-popover`,role:`menu`,"aria-label":`Emoji picker`,children:N.map((t,n)=>(0,P.jsx)(`button`,{type:`button`,role:`menuitem`,className:`wa-emoji-item`,onClick:()=>e(t),children:t},n))})}function ye({sessionKey:e,onPick:t,onClose:n}){let[i,a]=(0,M.useState)(``),[o,s]=(0,M.useState)(null),[c,l]=(0,M.useState)(null),[u,d]=(0,M.useState)(!1),f=(0,M.useCallback)(t=>{d(!0),l(null),fetch(`/api/admin/files?path=${encodeURIComponent(t)}&session_key=${encodeURIComponent(e)}`).then(async e=>{let t=await e.json().catch(()=>({}));if(!e.ok)throw Error(t.error??`Could not list files`);return t}).then(e=>{s(e),a(e.path===`.`?``:e.path)}).catch(e=>l(e instanceof Error?e.message:String(e))).finally(()=>d(!1))},[e]);(0,M.useEffect)(()=>{f(``)},[f]);let p=e=>f(i?`${i}/${e}`:e),m=()=>{let e=i.split(`/`).filter(Boolean);e.pop(),f(e.join(`/`))},h=e=>t({path:i?`${i}/${e.name}`:e.name,name:e.displayName??e.name});return(0,P.jsx)(`div`,{className:`wa-picker-backdrop`,role:`dialog`,"aria-label":`Choose a device file`,onClick:n,children:(0,P.jsxs)(`div`,{className:`wa-picker`,onClick:e=>e.stopPropagation(),children:[(0,P.jsxs)(`div`,{className:`wa-picker-head`,children:[i&&(0,P.jsx)(`button`,{type:`button`,className:`wa-picker-icon-btn`,onClick:m,"aria-label":`Up one folder`,children:(0,P.jsx)(y,{size:18})}),(0,P.jsx)(`span`,{className:`wa-picker-title`,children:i||`Device storage`}),(0,P.jsx)(`button`,{type:`button`,className:`wa-picker-icon-btn`,onClick:n,"aria-label":`Close file picker`,children:(0,P.jsx)(r,{size:18})})]}),c&&(0,P.jsx)(`p`,{className:`wa-picker-error`,role:`alert`,children:c}),u&&(0,P.jsx)(`p`,{className:`wa-picker-empty`,children:`Loading…`}),o&&!u&&(0,P.jsxs)(`ul`,{className:`wa-picker-list`,children:[o.entries.length===0&&(0,P.jsx)(`li`,{className:`wa-picker-empty`,children:`This folder is empty.`}),o.entries.map(e=>(0,P.jsx)(`li`,{children:e.kind===`directory`?(0,P.jsxs)(`button`,{type:`button`,className:`wa-picker-row`,onClick:()=>p(e.name),children:[(0,P.jsx)(ue,{size:16,"aria-hidden":!0}),(0,P.jsx)(`span`,{className:`wa-picker-name`,children:e.displayName??e.name})]}):e.kind===`file`?(0,P.jsxs)(`button`,{type:`button`,className:`wa-picker-row`,onClick:()=>h(e),children:[(0,P.jsx)(w,{size:16,"aria-hidden":!0}),(0,P.jsx)(`span`,{className:`wa-picker-name`,children:e.displayName??e.name})]}):null},e.name))]})]})})}function be(e){return`${Math.floor(e/60)}:${String(e%60).padStart(2,`0`)}`}function xe({accountId:e,remoteJid:t,sessionKey:n,replyTo:i,onClearReply:a}){let[o,s]=(0,M.useState)(``),[l,d]=(0,M.useState)(!1),[f,m]=(0,M.useState)(null),[g,_]=(0,M.useState)(!1),[ee,y]=(0,M.useState)(!1),[b,x]=(0,M.useState)([]),te=(0,M.useRef)(null),{pendingFiles:S,attachError:C,addFiles:re,removeFile:ie,clearFiles:ae}=_e(),{state:T,elapsedSeconds:E,errorMessage:D,start:oe,send:O,discard:se}=h(),ce=T===`recording`||T===`paused`,le=(0,M.useCallback)(()=>{console.info(`[operator-ui] op=voice-record state=start ms=0`),oe()},[oe]),ue=(0,M.useCallback)(async()=>{let e=E*1e3,t=await O();if(console.info(`[operator-ui] op=voice-record state=stop ms=${e}`),t){let e=t.type===`audio/ogg`?`.ogg`:t.type===`audio/mp4`?`.m4a`:`.webm`;re([new File([t],`voice-note${e}`,{type:t.type})])}},[E,O,re]),de=(0,M.useCallback)(()=>{console.info(`[operator-ui] op=voice-record state=cancel ms=${E*1e3}`),se()},[E,se]),fe=(0,M.useRef)(!1),pe=(o.trim().length>0||S.length>0||b.length>0)&&!l,he=(0,M.useCallback)(async()=>{if(!fe.current&&!(o.trim().length===0&&S.length===0&&b.length===0)){fe.current=!0,d(!0),m(null);try{let r=`/api/whatsapp-reader/reply?session_key=${encodeURIComponent(n)}`,c;if(S.length>0||b.length>0){let n=new FormData;n.append(`accountId`,e),n.append(`remoteJid`,t),o.trim()&&n.append(`text`,o);for(let e of S)n.append(`files`,e);for(let e of b)n.append(`fileRefs`,e.path);i&&n.append(`quotedId`,i.msgKeyId),c=await fetch(r,{method:`POST`,body:n})}else c=await fetch(r,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({accountId:e,remoteJid:t,text:o,...i?{quotedId:i.msgKeyId}:{}})});let l=await c.json().catch(()=>({}));if(!c.ok){m(l.error??`Send failed.`),console.info(`[operator-ui] op=reply-fail remoteJid=${t} error=${l.error??`unknown`}`);return}s(``),ae(),x([]),a?.(),console.info(`[operator-ui] op=reply-sent remoteJid=${t} sent=${l.sent??0}`)}catch(e){m(`Could not reach the server. Try again.`),console.info(`[operator-ui] op=reply-fail remoteJid=${t} error=${String(e)}`)}finally{fe.current=!1,d(!1)}}},[o,S,b,i,a,e,t,n,ae]),ge=(0,M.useCallback)(e=>{let t=te.current,{value:n,caret:r}=ve(o,e,t?t.selectionStart:null,t?t.selectionEnd:null);s(n),_(!1),requestAnimationFrame(()=>{let e=te.current;e&&(e.focus(),e.setSelectionRange(r,r))})},[o]),j=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),pe&&he())},N=e=>e.startsWith(`image/`)?(0,P.jsx)(k,{size:14}):e===`application/pdf`?(0,P.jsx)(w,{size:14}):(0,P.jsx)(p,{size:14});return(0,P.jsxs)(`div`,{className:`wa-reply`,children:[ee&&(0,P.jsx)(ye,{sessionKey:n,onPick:e=>{x(t=>[...t,e].slice(0,5)),y(!1)},onClose:()=>y(!1)}),g&&(0,P.jsx)(F,{onSelect:ge}),f&&(0,P.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:f}),C&&(0,P.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:C}),T===`error`&&D&&(0,P.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:D}),(S.length>0||b.length>0)&&(0,P.jsxs)(`div`,{className:`wa-reply-attachments`,children:[S.map((e,t)=>(0,P.jsxs)(`div`,{className:`wa-reply-chip`,children:[N(e.type),(0,P.jsx)(`span`,{className:`wa-reply-chip-name`,children:e.name}),(0,P.jsx)(`button`,{type:`button`,onClick:()=>ie(t),"aria-label":`Remove ${e.name}`,children:(0,P.jsx)(r,{size:12})})]},`f-${t}`)),b.map((e,t)=>(0,P.jsxs)(`div`,{className:`wa-reply-chip wa-reply-chip-ref`,children:[(0,P.jsx)(w,{size:14}),(0,P.jsx)(`span`,{className:`wa-reply-chip-name`,children:e.name}),(0,P.jsx)(`button`,{type:`button`,onClick:()=>x(e=>e.filter((e,n)=>n!==t)),"aria-label":`Remove ${e.name}`,children:(0,P.jsx)(r,{size:12})})]},`r-${t}`))]}),i&&(0,P.jsxs)(`div`,{className:`wa-reply-quote`,children:[(0,P.jsxs)(`div`,{className:`wa-reply-quote-body`,children:[(0,P.jsx)(`span`,{className:`wa-reply-quote-who`,children:i.fromMe?`You`:i.senderName??`Contact`}),(0,P.jsx)(`span`,{className:`wa-reply-quote-text`,children:i.body||`Message`})]}),(0,P.jsx)(`button`,{type:`button`,className:`wa-reply-quote-cancel`,onClick:()=>a?.(),"aria-label":`Cancel reply`,children:(0,P.jsx)(r,{size:14})})]}),(0,P.jsx)(`div`,{className:`wa-reply-row`,children:ce?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`button`,{type:`button`,className:`wa-reply-attach`,onClick:de,"aria-label":`Cancel recording`,children:(0,P.jsx)(c,{size:20})}),(0,P.jsxs)(`span`,{className:`wa-rec-live`,role:`status`,children:[(0,P.jsx)(`span`,{className:`wa-rec-dot`,"aria-hidden":!0}),be(E)]}),(0,P.jsx)(`button`,{type:`button`,className:`wa-reply-send`,onClick:()=>void ue(),"aria-label":`Stop recording`,children:(0,P.jsx)(u,{size:20})})]}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`button`,{type:`button`,className:`wa-reply-emoji`,onClick:()=>_(e=>!e),disabled:l,"aria-label":`Emoji`,"aria-expanded":g,children:(0,P.jsx)(A,{size:22})}),(0,P.jsx)(`button`,{type:`button`,className:`wa-reply-attach`,onClick:()=>y(!0),disabled:l,"aria-label":`Attach files`,children:(0,P.jsx)(ne,{size:22})}),(0,P.jsx)(`textarea`,{ref:te,className:`wa-reply-input`,value:o,rows:1,placeholder:`Type a message`,disabled:l,onChange:e=>s(e.target.value),onKeyDown:j}),(0,P.jsx)(`button`,{type:`button`,className:`wa-reply-mic`,onClick:()=>void le(),disabled:l,"aria-label":`Record voice note`,children:(0,P.jsx)(v,{size:22})}),(0,P.jsx)(`button`,{type:`button`,className:`wa-reply-send`,onClick:()=>void he(),disabled:!pe,"aria-label":`Send`,children:(0,P.jsx)(me,{size:20})})]})})]})}function Se({accountId:e,remoteJid:t,contactName:n,sessionKey:i,onBack:a}){let o=x(t),s=t.split(`@`)[0],c=o?`Group`:n===`+${s}`?void 0:`+${s}`,[l,u]=(0,M.useState)(!1),[d,f]=(0,M.useState)(``),p=()=>{u(!1),f(``)},[m,h]=(0,M.useState)(null);return(0,P.jsxs)(`div`,{className:`wa-web`,children:[(0,P.jsxs)(`header`,{className:`wa-web-header`,children:[a&&(0,P.jsx)(`button`,{type:`button`,className:`wa-web-back`,onClick:a,"aria-label":`Back`,children:(0,P.jsx)(y,{size:20})}),(0,P.jsx)(`span`,{className:`wa-web-avatar`,"aria-hidden":!0,children:(0,P.jsx)(j,{size:20})}),l?(0,P.jsxs)(`div`,{className:`wa-web-search`,children:[(0,P.jsx)(oe,{size:18,"aria-hidden":!0}),(0,P.jsx)(`input`,{className:`wa-web-search-input`,type:`text`,autoFocus:!0,placeholder:`Search messages`,"aria-label":`Search messages`,value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Escape`&&p()}}),(0,P.jsx)(`button`,{type:`button`,className:`wa-web-search-close`,onClick:p,"aria-label":`Close search`,children:(0,P.jsx)(r,{size:18})})]}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`div`,{className:`wa-web-titles`,children:[(0,P.jsx)(`span`,{className:`wa-web-name`,children:n}),c&&(0,P.jsx)(`span`,{className:`wa-web-subtitle`,children:c})]}),(0,P.jsx)(`button`,{type:`button`,className:`wa-web-search-toggle`,onClick:()=>u(!0),"aria-label":`Search messages`,children:(0,P.jsx)(oe,{size:20})})]})]}),(0,P.jsx)(`div`,{className:`wa-web-body`,children:(0,P.jsx)(_,{sessionId:``,projectDir:``,sessionKey:i,forceDeliveredOnly:!0,suppressDirectives:!0,store:{accountId:e,remoteJid:t},search:l?d:void 0,onReplyTo:o?void 0:h})}),o?(0,P.jsx)(`p`,{className:`wa-reply wa-reply-readonly`,children:`Group messages are read-only.`}):(0,P.jsx)(xe,{accountId:e,remoteJid:t,sessionKey:i,replyTo:m,onClearReply:()=>h(null)})]})}function Ce(e){let t=new Set,n=[];for(let r of e)for(let e of r.labels)e&&(t.has(e)||O.has(e)&&(t.add(e),n.push(e)));return n}function I(e){if(!e)return``;let t=new Date(e).getTime();return Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``}function L({conversations:e,sessionKey:t,onBack:n}){let[r,i]=(0,M.useState)(null),a=C(e);return r?r.source===`store`&&r.accountId&&r.remoteJid?(0,P.jsx)(Se,{accountId:r.accountId,remoteJid:r.remoteJid,contactName:b(r),sessionKey:t,onBack:()=>i(null)},T(r)):(0,P.jsxs)(`div`,{className:`op-conv op-conv-reader`,children:[(0,P.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,P.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:()=>i(null),"aria-label":`Back to conversations`,children:[(0,P.jsx)(y,{size:16}),` Back`]}),(0,P.jsx)(`span`,{className:`op-conv-title`,children:b(r)})]}),(0,P.jsx)(_,{sessionId:r.sessionId,projectDir:r.projectDir,sessionKey:t,forceDeliveredOnly:!0,suppressDirectives:r.source===`store`,store:r.source===`store`?{accountId:r.accountId,remoteJid:r.remoteJid}:void 0},T(r))]}):(0,P.jsxs)(`div`,{className:`op-conv op-conv-list`,children:[(0,P.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,P.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:n,"aria-label":`Back to chat`,children:[(0,P.jsx)(y,{size:16}),` Chat`]}),(0,P.jsx)(`span`,{className:`op-conv-title`,children:`Conversations`})]}),a.map(e=>(0,P.jsxs)(`div`,{className:`op-conv-group`,children:[(0,P.jsxs)(`div`,{className:`op-conv-group-head`,children:[(0,P.jsx)(D,{channel:e.channel,size:14}),e.label]}),e.rows.map(e=>(0,P.jsxs)(`button`,{type:`button`,className:`op-conv-row`,onClick:()=>{console.info(`[operator-ui] op=reader-open channel=${e.channel} key=${T(e)} readonly=true source=${e.source}`),i(e)},children:[(0,P.jsx)(`span`,{className:`op-conv-name`,children:b(e)}),e.modelGated&&(0,P.jsx)(`span`,{className:`op-conv-gated`,role:`img`,"aria-label":`Model unavailable`,children:(0,P.jsx)(he,{size:13})}),(0,P.jsx)(`span`,{className:`op-conv-when`,children:I(e.lastMessageAt)})]},T(e)))]},e.channel))]})}var R=/\.(png|jpe?g|gif|webp|svg)$/i;function we(e){return R.test(e)}var Te=`maxy-data-view`,Ee=95*1024*1024,De=48*1024*1024;function Oe(){return typeof window>`u`?`list`:window.localStorage.getItem(Te)===`grid`?`grid`:`list`}function ke(){let[e,t]=(0,M.useState)(null),[n,r]=(0,M.useState)(!1);return(0,M.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!n){t(null),r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]),n?e?(0,P.jsx)(l,{cacheKey:e,surface:`data`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=data`);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},children:(0,P.jsx)(`div`,{className:`data-page data-page-full`,children:(0,P.jsx)(z,{cacheKey:e})})}):(0,P.jsx)(`div`,{className:`data-page`,children:(0,P.jsxs)(`div`,{className:`data-empty`,children:[(0,P.jsx)(`p`,{children:`You are not signed in.`}),(0,P.jsxs)(`p`,{children:[`Open the `,(0,P.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,P.jsx)(`div`,{className:`data-page`,children:(0,P.jsxs)(`div`,{className:`data-loading`,children:[(0,P.jsx)(f,{size:18,className:`spin`}),` Loading…`]})})}function z({cacheKey:e}){let{adminFetch:n,cacheKey:r,sessionRefetchNonce:i}=t({initialCacheKey:e,surface:`data`});return(0,P.jsx)(Le,{adminFetch:n,cacheKey:r,sessionRefetchNonce:i})}function Ae(){if(typeof window>`u`)return`.`;let e=new URLSearchParams(window.location.hash.replace(/^#/,``)).get(`path`);return e&&e.length>0?e:`.`}function je(e){if(typeof window>`u`)return;let t=new URL(window.location.href);t.hash=e===`.`?``:`path=${encodeURIComponent(e)}`,window.history.replaceState(window.history.state,``,t.toString())}function Me(e){return new Promise((t,n)=>{let r=[],i=()=>e.readEntries(e=>{e.length===0?t(r):(r.push(...e),i())},n);i()})}function Ne(e){return new Promise((t,n)=>e.file(t,n))}async function Pe(e,t=``){let n=[];for(let r of e){if(!r)continue;let e=t?`${t}/${r.name}`:r.name;if(r.isFile)n.push({file:await Ne(r),relpath:e});else if(r.isDirectory){let t=await Me(r.createReader());n.push(...await Pe(t,e))}}return n}function Fe(e,t){if(e===422&&typeof t==`string`){if(/exceeds the .* limit/i.test(t))return`size`;if(/unsupported file type/i.test(t))return`mime`}return`http=${e}`}function Ie({adminFetch:e,cacheKey:t,sessionRefetchNonce:n}){let[i,o]=(0,M.useState)(``),s=(0,M.useRef)(null),[l,u]=(0,M.useState)(``),[d,p]=(0,M.useState)(null),[m,h]=(0,M.useState)(`hybrid`),[g,_]=(0,M.useState)(!1),[ee,v]=(0,M.useState)(null),[y,b]=(0,M.useState)(null),[x,ne]=(0,M.useState)(0),[C,T]=(0,M.useState)(!1),[D,O]=(0,M.useState)(()=>Ae()),[k,me]=(0,M.useState)(null),[A,he]=(0,M.useState)(()=>Oe()),[j,_e]=(0,M.useState)(null),[N,ve]=(0,M.useState)([]),[F,ye]=(0,M.useState)(!1),[be,xe]=(0,M.useState)(null),[Se,I]=(0,M.useState)(!1),[L,R]=(0,M.useState)(null),[ke,z]=(0,M.useState)(null),[Me,Ne]=(0,M.useState)(null),[Ie,Le]=(0,M.useState)(!1),[Re,Ve]=(0,M.useState)(null),B=(0,M.useRef)(null),[He,V]=(0,M.useState)(0),[Ge,Ke]=(0,M.useState)(!1),[qe,Je]=(0,M.useState)(``),[H,Ye]=(0,M.useState)(null),[Xe,Ze]=(0,M.useState)(``),[Qe,U]=(0,M.useState)(null),W=(()=>{let e=D===`.`?[]:D.split(`/`).filter(Boolean);return e.length>=2&&e[0]===`accounts`})(),[$e,et]=(0,M.useState)(!1),tt=(0,M.useRef)(null),[nt,G]=(0,M.useState)(!1),rt=(0,M.useRef)(null);(0,M.useEffect)(()=>{let e=i.trim();if(!e){u(``),p(null),v(null);return}T(!1);let t=setTimeout(()=>u(e),300);return()=>clearTimeout(t)},[i]),(0,M.useEffect)(()=>{if(!l){_(!1);return}let t=!1;return _(!0),v(null),e(`/api/admin/graph-search?q=${encodeURIComponent(l)}&labels=FileArtifact&limit=20${C?`&threshold=0`:``}`).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(e=>{t||(p(e.results),h(e.mode??`hybrid`),ne(typeof e.suppressed==`number`?e.suppressed:0))}).catch(e=>{t||v(e instanceof Error?e.message:String(e))}).finally(()=>{t||_(!1)}),()=>{t=!0}},[l,e,n,C]);let it=(0,M.useMemo)(()=>d?Ce(d):[],[d]),K=y&&it.includes(y)?y:null,at=(0,M.useMemo)(()=>d?K?d.filter(e=>e.labels.includes(K)):d:null,[d,K]),ot=(0,M.useCallback)(e=>{let n=e.properties.relativePath;if(typeof n!=`string`||n.length===0)return;let r=`/api/admin/files/download?session_key=${encodeURIComponent(t)}&path=${encodeURIComponent(n)}`,i=document.createElement(`a`);i.href=r,i.rel=`noopener noreferrer`,document.body.appendChild(i),i.click(),i.remove()},[t]);(0,M.useEffect)(()=>{if(!d)return;let e=d.filter(e=>{let t=e.properties.relativePath;return typeof t!=`string`||t.length===0});e.length>0&&console.warn(`[data-search] op=locate-link-missing nodeId=${e.map(e=>e.nodeId).join(`,`)}`)},[d]),(0,M.useEffect)(()=>{let t=!1;return ye(!0),xe(null),e(`/api/admin/files?path=${encodeURIComponent(D===`.`?``:D)}`).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(e=>{t||(me(e.entries),ve(e.displayPath??[]))}).catch(e=>{t||(me([]),ve([]),xe(e instanceof Error?e.message:String(e)))}).finally(()=>{t||ye(!1)}),()=>{t=!0}},[e,D,He,n]),(0,M.useEffect)(()=>{je(D)},[D]);let st=(0,M.useCallback)(()=>{V(e=>e+1)},[]),q=(0,M.useCallback)(e=>{et(!1),O(e)},[]),ct=(0,M.useCallback)(e=>{let t=e.properties.relativePath;if(typeof t!=`string`||t.length===0)return;let n=t.lastIndexOf(`/`),r=n===-1?`.`:t.slice(0,n);console.log(`[data-search] op=locate nodeId=${e.nodeId} folder=${r}`),o(``),v(null),b(null),q(r)},[q]),lt=(0,M.useCallback)(()=>{if(D===`.`||D===``)return;let e=D.split(`/`).filter(Boolean);e.pop(),O(e.length===0?`.`:e.join(`/`))},[D]),ut=(0,M.useCallback)(e=>{re(t,D===`.`?e.name:`${D}/${e.name}`)},[D,t]),[J,dt]=(0,M.useState)(!1),[Y,ft]=(0,M.useState)(new Set),pt=(0,M.useRef)(null),X=(0,M.useRef)(!1),mt=typeof navigator<`u`&&typeof navigator.share==`function`&&typeof navigator.canShare==`function`,ht=(0,M.useCallback)(e=>{dt(!0),ft(new Set([e])),console.info(`[data-ui] op=select-enter count=1`)},[]),Z=(0,M.useCallback)(e=>{dt(!1),ft(new Set),console.info(`[data-ui] op=select-exit reason=${e}`)},[]),Q=(0,M.useCallback)(e=>{ft(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),gt=(0,M.useCallback)(e=>{X.current=!1,pt.current=setTimeout(()=>{X.current=!0,ht(e)},500)},[ht]),$=(0,M.useCallback)(()=>{pt.current&&=(clearTimeout(pt.current),null)},[]),_t=(0,M.useCallback)(e=>{if(X.current){X.current=!1;return}if(J){Q(e.name);return}ut(e)},[J,Q,ut]),vt=(0,M.useCallback)(e=>{he(e),typeof window<`u`&&window.localStorage.setItem(Te,e),console.info(`[data] op=view-mode mode=${e}`)},[]),yt=(0,M.useCallback)(e=>{if(X.current){X.current=!1;return}if(J){Q(e.name);return}_e({src:E(t,D===`.`?e.name:`${D}/${e.name}`),alt:e.displayName??e.name})},[J,Q,D,t]),bt=(0,M.useCallback)(()=>(k??[]).filter(e=>e.kind===`file`&&Y.has(e.name)),[k,Y]),xt=(0,M.useCallback)(()=>(k??[]).filter(e=>(e.kind===`file`||e.kind===`directory`)&&Y.has(e.name)),[k,Y]),St=(0,M.useCallback)(()=>{let e=xt(),n=e.some(e=>e.kind===`directory`);e.length===1&&!n?ut(e[0]):e.length>=1&&ae(t,e.map(e=>D===`.`?e.name:`${D}/${e.name}`)),Z(`action`)},[xt,ut,D,t,Z]),Ct=(0,M.useCallback)(async()=>{let t=bt(),n=t.filter(e=>!e.protected),r=t.length-n.length;Ve(r>0?`${r} protected file(s) kept`:null);for(let t of n){let n=D===`.`?t.name:`${D}/${t.name}`;try{let t=await e(`/api/admin/files?path=${encodeURIComponent(n)}`,{method:`DELETE`}),r=await t.json().catch(()=>({error:`HTTP ${t.status}`}));if(!t.ok)throw Error(r.error??`HTTP ${t.status}`)}catch(e){Ve(e instanceof Error?e.message:String(e))}}V(e=>e+1),Z(`action`)},[bt,D,e,Z]),wt=(0,M.useCallback)(async()=>{let e=bt();if(console.info(`[data-ui] op=share supported=${mt} count=${e.length}`),mt)try{let n=await Promise.all(e.map(async e=>{let n=D===`.`?e.name:`${D}/${e.name}`,r=`/api/admin/files/download?session_key=${encodeURIComponent(t)}&path=${encodeURIComponent(n)}`,i=await(await fetch(r)).blob();return new File([i],e.name,{type:i.type||`application/octet-stream`})}));navigator.canShare({files:n})&&await navigator.share({files:n})}catch(e){console.warn(`[data-ui] op=share-failed err=${e instanceof Error?e.message:String(e)}`)}},[bt,mt,D,t]),Tt=(0,M.useCallback)(()=>{B.current?.click()},[]),Et=(0,M.useCallback)((e,n={})=>{let r=(r,i,a)=>{let o=new URLSearchParams({session_key:t,path:D===`.`?``:D,filename:e.name});n.relpath&&o.set(`relpath`,n.relpath),n.token&&o.set(`token`,n.token);for(let[e,t]of Object.entries(i))o.set(e,t);return new Promise(t=>{let n=new XMLHttpRequest;n.open(`POST`,`/api/admin/files/upload?${o.toString()}`),n.setRequestHeader(`Content-Type`,e.type||`application/octet-stream`),a&&(n.upload.onprogress=e=>{e.lengthComputable&&a(e.loaded)}),n.onload=()=>{let e={};try{e=JSON.parse(n.responseText)}catch{}t({status:n.status,data:e})},n.onerror=()=>t({status:0,data:{}}),n.onabort=()=>t({status:0,data:{error:`aborted`}}),n.send(r)})};if(e.size<=Ee)return r(e,{},t=>n.onProgress?.(t,e.size));let i=`${Date.now().toString(36)}-${Math.random().toString(16).slice(2,10)}`,a=Math.ceil(e.size/De);return(async()=>{let t={status:0,data:{}};for(let o=0;o<a;o++){let s=o*De;if(t=await r(e.slice(s,Math.min(s+De,e.size)),{uploadId:i,seq:String(o),total:String(a)},t=>n.onProgress?.(s+t,e.size)),!(t.status>=200&&t.status<300))return t}return t})()},[t,D]),Dt=(0,M.useCallback)(async e=>{z(null),I(!0),R({loaded:0,total:e.size});try{let{status:t,data:n}=await Et(e,{onProgress:(e,t)=>R({loaded:e,total:t})});t>=200&&t<300&&n.path?(O(n.path.split(`/`).slice(0,-1).join(`/`)||`.`),V(e=>e+1)):z(t===0?`Network error during upload — the connection failed before the server responded.`:n.error??`Upload failed (HTTP ${t}).`)}finally{I(!1),R(null),B.current&&(B.current.value=``)}},[Et]),Ot=(0,M.useCallback)(e=>{W&&Array.from(e.dataTransfer.types).includes(`Files`)&&(e.preventDefault(),Le(!0))},[W]),kt=(0,M.useCallback)(e=>{e.currentTarget.contains(e.relatedTarget)||Le(!1)},[]),At=(0,M.useCallback)(async e=>{e.preventDefault(),Le(!1);let t=Math.random().toString(16).slice(2,10),n=Array.from(e.dataTransfer.items);if(console.info(`[data-ui] op=drop-received token=${t} items=${n.length}`),n.length===0)return;if(!W){console.info(`[data-ui] op=drop-rejected token=${t} reason=no-write`),z(`Open a folder inside your account to upload`);return}let r=n.map(e=>e.webkitGetAsEntry?.()).filter(e=>!!e);I(!0),z(null),Ne(null);let i=performance.now();try{let e=await Pe(r),n=e.reduce((e,t)=>e+t.file.size,0),a=new Set(e.map(e=>e.relpath.split(`/`).slice(0,-1).join(`/`)).filter(Boolean)).size;console.info(`[data-ui] op=drop-walk token=${t} files=${e.length} dirs=${a} bytes=${n}`);let o=0,s=[];for(let n=0;n<e.length;n++){let{file:r,relpath:i}=e[n];console.info(`[data-ui] op=drop-file token=${t} rel="${i}" i=${n+1}/${e.length}`),R({loaded:0,total:r.size});let{status:a,data:c}=await Et(r,{relpath:i,token:t,onProgress:(e,t)=>R({loaded:e,total:t})});if(a>=200&&a<300)o++,console.info(`[data-ui] op=drop-file-ok token=${t} rel="${i}"`);else{let e=a===0?`http=0`:Fe(a,c.error);s.push(`${i} (${e})`),console.info(`[data-ui] op=drop-file-skip token=${t} rel="${i}" reason=${e}`)}}let c=Math.round(performance.now()-i);console.info(`[data-ui] op=drop-done token=${t} uploaded=${o} skipped=${s.length} ms=${c}`),Ne(`Uploaded ${o}, skipped ${s.length}${s.length?`: ${s.join(`, `)}`:``}`),V(e=>e+1)}catch(e){z(e instanceof Error?e.message:String(e))}finally{I(!1),R(null)}},[W,Et]),jt=(0,M.useCallback)(async()=>{let t=qe.trim();if(t){U(null);try{let n=await e(`/api/admin/files/folder`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:D===`.`?``:D,name:t})}),r=await n.json().catch(()=>({error:`HTTP ${n.status}`}));if(!n.ok)throw Error(r.error??`HTTP ${n.status}`);Ke(!1),Je(``),V(e=>e+1)}catch(e){U(e instanceof Error?e.message:String(e))}}},[e,qe,D]),Mt=(0,M.useCallback)(async()=>{if(!H)return;let t=Xe.trim();if(!t)return;U(null);let n=D===`.`?H:`${D}/${H}`;try{let r=await e(`/api/admin/files/rename`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:n,newName:t})}),i=await r.json().catch(()=>({error:`HTTP ${r.status}`}));if(!r.ok)throw Error(i.error??`HTTP ${r.status}`);Ye(null),Ze(``),Z(`action`),V(e=>e+1)}catch(e){U(e instanceof Error?e.message:String(e))}},[e,Xe,H,D,Z]);(0,M.useEffect)(()=>{if(!$e)return;let e=e=>{tt.current&&!tt.current.contains(e.target)&&et(!1)},t=e=>{e.key===`Escape`&&et(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[$e]),(0,M.useEffect)(()=>{if(!nt)return;let e=e=>{rt.current&&!rt.current.contains(e.target)&&G(!1)},t=e=>{e.key===`Escape`&&G(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[nt]);let Nt=(0,M.useCallback)(e=>N.slice(0,e+1).map(e=>e.name).join(`/`),[N]),Pt=N.length>=2,Ft=Pt?[{name:`.`,label:`data`},...N.slice(0,N.length-2).map((e,t)=>({name:Nt(t),label:e.displayName??e.name}))]:[];return(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`div`,{className:`data-toolbar`,children:[J?(0,P.jsxs)(`button`,{type:`button`,className:`data-select-cancel`,onClick:()=>Z(`cancel`),"aria-label":`Cancel selection`,children:[(0,P.jsx)(r,{size:14}),` Cancel`]}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`div`,{className:`data-search-input`,children:[i===``&&(0,P.jsx)(oe,{size:14}),(0,P.jsx)(`input`,{ref:s,type:`text`,value:i,onChange:e=>o(e.target.value),autoFocus:!0,autoComplete:`off`,spellCheck:!1}),g&&(0,P.jsx)(f,{size:14,className:`spin`}),i!==``&&(0,P.jsx)(`button`,{type:`button`,className:`data-search-inline-btn`,onClick:()=>{o(``),s.current?.focus()},title:`Clear search`,"aria-label":`Clear search`,children:(0,P.jsx)(r,{size:14})})]}),(0,P.jsxs)(`div`,{className:`data-toolbar-actions`,ref:rt,children:[(0,P.jsx)(`button`,{type:`button`,className:`data-action-overflow`,onClick:()=>G(e=>!e),"aria-haspopup":`menu`,"aria-expanded":nt,"aria-label":`File actions`,title:`File actions`,children:(0,P.jsx)(ce,{size:16})}),(0,P.jsxs)(`div`,{className:`data-action-group`,role:`group`,"aria-label":`File actions`,"data-open":nt?`true`:void 0,children:[(0,P.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{st(),G(!1)},disabled:F,title:`Refresh this folder`,"aria-label":`Refresh this folder`,children:[F?(0,P.jsx)(f,{size:16,className:`spin`}):(0,P.jsx)(te,{size:16}),(0,P.jsx)(`span`,{className:`data-action-label`,children:`Refresh`})]}),(0,P.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{Tt(),G(!1)},disabled:Se||!W,title:W?`Upload a file`:`Open a folder inside your account to upload`,"aria-label":`Upload a file`,children:[Se?L&&L.total>0?(0,P.jsxs)(`span`,{className:`data-upload-pct`,children:[Math.round(L.loaded/L.total*100),`%`]}):(0,P.jsx)(f,{size:16,className:`spin`}):(0,P.jsx)(ge,{size:16}),(0,P.jsx)(`span`,{className:`data-action-label`,children:`Upload`})]}),(0,P.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{Ke(e=>!e),Je(``),U(null),G(!1)},disabled:Se||!W,title:W?`New folder`:`Open a folder inside your account to create one`,"aria-label":`New folder`,children:[(0,P.jsx)(le,{size:16}),(0,P.jsx)(`span`,{className:`data-action-label`,children:`New folder`})]}),(0,P.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{vt(A===`grid`?`list`:`grid`),G(!1)},title:A===`grid`?`List view`:`Grid view`,"aria-label":A===`grid`?`Switch to list view`:`Switch to grid view`,"aria-pressed":A===`grid`,children:[A===`grid`?(0,P.jsx)(fe,{size:16}):(0,P.jsx)(de,{size:16}),(0,P.jsx)(`span`,{className:`data-action-label`,children:A===`grid`?`List view`:`Grid view`})]})]})]})]}),(0,P.jsxs)(`div`,{className:`data-breadcrumbs`,children:[D!==`.`&&(0,P.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost data-back-btn`,onClick:lt,title:`Up one level`,"aria-label":`Up one level`,children:(0,P.jsx)(se,{size:14})}),Pt?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`span`,{className:`data-crumb-wrap`,ref:tt,children:[(0,P.jsx)(`button`,{type:`button`,className:`data-crumb data-crumb-ellipsis`,onClick:()=>et(e=>!e),"aria-haspopup":`menu`,"aria-expanded":$e,"aria-label":`Show parent folders`,title:`Show parent folders`,children:`…`}),$e&&(0,P.jsx)(`div`,{className:`data-crumb-menu`,role:`menu`,children:Ft.map(e=>(0,P.jsx)(`button`,{type:`button`,role:`menuitem`,className:`data-crumb-menu-item`,onClick:()=>q(e.name),title:e.label,children:e.label},e.name))})]}),[N.length-2,N.length-1].map(e=>{let t=N[e];return(0,P.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,P.jsx)(`span`,{className:`data-crumb-sep`,children:`/`}),(0,P.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>q(Nt(e)),title:t.name,children:t.displayName??t.name})]},Nt(e))})]}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>q(`.`),children:`data`}),N.map((e,t)=>(0,P.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,P.jsx)(`span`,{className:`data-crumb-sep`,children:`/`}),(0,P.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>q(Nt(t)),title:e.name,children:e.displayName??e.name})]},Nt(t)))]})]}),Ge&&(0,P.jsxs)(`div`,{className:`data-inline-form`,children:[(0,P.jsx)(`input`,{type:`text`,className:`data-inline-input`,placeholder:`Folder name`,value:qe,autoFocus:!0,onChange:e=>Je(e.target.value),onKeyDown:e=>{e.key===`Enter`&&jt(),e.key===`Escape`&&Ke(!1)}}),(0,P.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:jt,children:`Create`}),(0,P.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost`,onClick:()=>Ke(!1),children:`Cancel`})]}),H&&(0,P.jsxs)(`div`,{className:`data-inline-form`,children:[(0,P.jsx)(`input`,{type:`text`,className:`data-inline-input`,placeholder:`New name`,value:Xe,autoFocus:!0,onChange:e=>Ze(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Mt(),e.key===`Escape`&&Ye(null)}}),(0,P.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:Mt,children:`Rename`}),(0,P.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost`,onClick:()=>Ye(null),children:`Cancel`})]}),Qe&&(0,P.jsx)(`div`,{className:`data-error`,children:Qe}),(0,P.jsx)(`input`,{type:`file`,ref:B,hidden:!0,onChange:e=>{let t=e.target.files?.[0];t&&Dt(t)}})]}),(0,P.jsxs)(`div`,{className:`data-body`,"data-drag-active":Ie?`true`:void 0,onDragEnter:Ot,onDragOver:Ot,onDragLeave:kt,onDrop:At,children:[(ee!==null||d!==null)&&(0,P.jsxs)(`section`,{className:`data-panel`,children:[ee&&(0,P.jsxs)(`div`,{className:`data-error`,children:[`Search failed: `,ee]}),it.length>0&&(0,P.jsx)(`div`,{className:`data-chip-row`,role:`group`,"aria-label":`Filter by type`,children:it.map(e=>{let t=e===K;return(0,P.jsx)(`button`,{type:`button`,className:`data-chip`,"data-active":t,onClick:()=>b(t?null:e),children:Be([e])??e},e)})}),d&&!g&&(0,P.jsxs)(`div`,{className:`data-results-meta`,children:[at.length,` of `,d.length,` result`,d.length===1?``:`s`]}),d&&!g&&!K&&x>0&&!C&&(0,P.jsxs)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>T(!0),children:[x,` low-confidence result`,x===1?``:`s`,` hidden — show all`]}),d&&!g&&!K&&C&&(0,P.jsx)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>T(!1),children:`Showing all results — hide low-confidence`}),d&&d.length===0&&!g&&(0,P.jsx)(`div`,{className:`data-empty-results`,children:`No matches. Try a different keyword.`}),at&&at.length>0&&(0,P.jsx)(`ul`,{className:`data-results`,children:at.map(e=>(0,P.jsx)(ze,{hit:e,mode:m,onDownload:ot,onLocate:ct},e.nodeId))})]}),(0,P.jsxs)(`section`,{className:`data-panel`,children:[L&&(0,P.jsxs)(`div`,{className:`data-upload-progress`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":L.total>0?Math.round(L.loaded/L.total*100):void 0,children:[(0,P.jsx)(`div`,{className:`data-upload-progress-track`,children:(0,P.jsx)(`div`,{className:`data-upload-progress-fill`,style:{width:`${L.total>0?Math.round(L.loaded/L.total*100):0}%`}})}),(0,P.jsxs)(`span`,{className:`data-upload-progress-label`,children:[`Uploading… `,L.total>0?`${Math.round(L.loaded/L.total*100)}%`:``]})]}),ke&&(0,P.jsxs)(`div`,{className:`data-error`,children:[`Upload failed: `,ke]}),Me&&(0,P.jsx)(`div`,{className:`data-status`,children:Me}),Re&&(0,P.jsxs)(`div`,{className:`data-error`,children:[`Delete failed: `,Re]}),be&&(0,P.jsx)(`div`,{className:`data-error`,children:be}),F&&(0,P.jsxs)(`div`,{className:`data-loading`,children:[(0,P.jsx)(f,{size:14,className:`spin`}),` Loading…`]}),!J&&!F&&k&&k.length>0&&(0,P.jsxs)(`div`,{className:`data-select-hint`,children:[(0,P.jsx)(pe,{size:13}),(0,P.jsx)(`span`,{children:`Press and hold a file to select, rename, or delete it.`})]}),!F&&k&&k.length===0&&!be&&(0,P.jsx)(`div`,{className:`data-empty-results`,children:`Empty directory.`}),!F&&k&&k.length>0&&A===`grid`&&(0,P.jsx)(`ul`,{className:`data-grid`,children:k.map(e=>{let n=e.displayName??e.name,r=J&&Y.has(e.name);if(e.kind===`directory`)return(0,P.jsx)(`li`,{className:`data-grid-cell`,"data-selected":r?`true`:void 0,children:(0,P.jsxs)(`button`,{type:`button`,className:`data-grid-tile`,onPointerDown:()=>gt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>{if(X.current){X.current=!1;return}if(J){Q(e.name);return}q(D===`.`?e.name:`${D}/${e.name}`)},children:[J&&(0,P.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,P.jsx)(ue,{size:28,className:`data-grid-glyph`}),(0,P.jsx)(`span`,{className:`data-grid-label`,title:e.name,children:n})]})},e.name);if(e.kind===`file`){let i=we(e.name),a=D===`.`?e.name:`${D}/${e.name}`;return(0,P.jsx)(`li`,{className:`data-grid-cell`,"data-selected":r?`true`:void 0,children:(0,P.jsxs)(`button`,{type:`button`,className:`data-grid-tile${i?` data-grid-tile-image`:``}`,onPointerDown:()=>gt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>i?yt(e):_t(e),title:J?void 0:i?`Preview ${n}`:`Download ${n}`,children:[J&&(0,P.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),i?(0,P.jsx)(`img`,{className:`data-grid-thumb`,src:E(t,a),alt:n,loading:`lazy`,onError:()=>console.warn(`[data] op=thumb-error path=${a}`)}):(0,P.jsx)(w,{size:28,className:`data-grid-glyph`}),(0,P.jsx)(`span`,{className:`data-grid-label`,title:e.name,children:n}),!i&&(0,P.jsx)(`span`,{className:`data-grid-sub`,children:Ue(e.sizeBytes)})]})},e.name)}return(0,P.jsx)(`li`,{className:`data-grid-cell`,children:(0,P.jsxs)(`div`,{className:`data-grid-tile data-entry-disabled`,children:[(0,P.jsx)(w,{size:28,className:`data-grid-glyph`}),(0,P.jsx)(`span`,{className:`data-grid-label`,children:n}),(0,P.jsx)(`span`,{className:`data-grid-sub`,children:`special`})]})},e.name)})}),!F&&k&&k.length>0&&A===`list`&&(0,P.jsx)(`ul`,{className:`data-entries`,children:k.map(e=>{let t=e.displayName??e.name;if(e.kind===`directory`){let n=J&&Y.has(e.name);return(0,P.jsx)(`li`,{className:`data-entry`,"data-selected":n?`true`:void 0,children:(0,P.jsxs)(`button`,{type:`button`,className:`data-entry-btn`,onPointerDown:()=>gt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>{if(X.current){X.current=!1;return}if(J){Q(e.name);return}q(D===`.`?e.name:`${D}/${e.name}`)},children:[J&&(0,P.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,P.jsx)(ue,{size:14}),(0,P.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t})]})},e.name)}if(e.kind===`file`){let n=J&&Y.has(e.name);return(0,P.jsx)(`li`,{className:`data-entry`,"data-selected":n?`true`:void 0,children:(0,P.jsxs)(`button`,{type:`button`,className:`data-entry-btn data-entry-file`,onPointerDown:()=>gt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>_t(e),title:J?void 0:`Download ${t}`,children:[J&&(0,P.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,P.jsxs)(`span`,{className:`data-entry-text`,children:[(0,P.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t}),(0,P.jsxs)(`span`,{className:`data-entry-meta`,title:`Modified ${We(e.modifiedAt)}`,children:[Ue(e.sizeBytes),` · `,We(e.modifiedAt)]})]})]})},e.name)}return(0,P.jsx)(`li`,{className:`data-entry`,children:(0,P.jsx)(`div`,{className:`data-entry-btn data-entry-file data-entry-disabled`,children:(0,P.jsxs)(`span`,{className:`data-entry-text`,children:[(0,P.jsx)(`span`,{className:`data-entry-name`,children:t}),(0,P.jsx)(`span`,{className:`data-entry-meta`,children:`special`})]})})},e.name)})})]})]}),J&&(0,P.jsx)(`div`,{className:`data-select-bar`,role:`toolbar`,"aria-label":`Selection actions`,children:(0,P.jsxs)(`div`,{className:`data-select-bar-inner`,children:[(0,P.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:wt,disabled:!mt||Y.size===0,title:mt?`Share selected files`:`Sharing is not supported on this device`,children:[(0,P.jsx)(a,{size:16}),` Share`]}),(0,P.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:St,disabled:Y.size===0,children:[(0,P.jsx)(S,{size:16}),` Download`]}),(0,P.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:()=>{let e=[...Y][0];e&&(Ye(e),Ze(e))},disabled:Y.size!==1,children:[(0,P.jsx)(ie,{size:16}),` Rename`]}),(0,P.jsxs)(`button`,{type:`button`,className:`data-select-action data-select-delete`,onClick:Ct,disabled:Y.size===0,children:[(0,P.jsx)(c,{size:16}),` Delete`]})]})}),j&&(0,P.jsx)(`div`,{className:`chat-attachment-overlay`,role:`dialog`,"aria-label":j.alt,onClick:()=>_e(null),children:(0,P.jsx)(`img`,{className:`chat-attachment-overlay-image`,src:j.src,alt:j.alt})})]})}function Le({adminFetch:e,cacheKey:t,sessionRefetchNonce:n}){(0,M.useEffect)(()=>{console.info(`[data-ui] op=mount header=operator home=absent`)},[]);let r=(0,M.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]),i=(0,M.useCallback)(e=>{e===`chat`&&(window.location.href=`/`)},[]),[a,o]=(0,M.useState)([]),[c,l]=(0,M.useState)(`files`),{subAccounts:u,activeAccountId:f,switching:p,switchAccount:m}=d(t);return(0,M.useEffect)(()=>{if(!t)return;let e=!1;return fetch(`/api/whatsapp-reader/conversations?session_key=${encodeURIComponent(t)}`).then(e=>e.ok?e.json():{conversations:[]}).then(t=>{e||o(t.conversations??[])}).catch(()=>{}),()=>{e=!0}},[t]),(0,P.jsxs)(`main`,{className:`data-main`,children:[(0,P.jsx)(s,{variant:`operator`,onNavigate:i,onOpenConversations:a.length>0?()=>l(`conversations`):void 0,onToggleSidebar:()=>{},sidebarOpen:!1,onLogout:r,onDisconnect:async()=>!0,disconnecting:!1,subAccounts:u,activeAccountId:f,switchingAccount:p,onSwitchAccount:m}),c===`conversations`?(0,P.jsx)(L,{conversations:a,sessionKey:t,onBack:()=>l(`files`)}):(0,P.jsx)(Ie,{adminFetch:e,cacheKey:t,sessionRefetchNonce:n})]})}function Re({cacheKey:e}){let{adminFetch:n,cacheKey:r,sessionRefetchNonce:i}=t({initialCacheKey:e,surface:`data`});return(0,P.jsx)(`div`,{className:`data-page`,children:(0,P.jsx)(`main`,{className:`data-main`,children:(0,P.jsx)(Ie,{adminFetch:n,cacheKey:r,sessionRefetchNonce:i})})})}function ze({hit:e,mode:t,onDownload:n,onLocate:r}){let i=Ve(e.properties),a=B(e.properties),o=Be(e.labels),s=He(e.properties),[c,l]=(0,M.useState)(!1),u=a&&a.length>280,d=c||!u?a:a?.slice(0,280)+`…`,f=t===`bm25`?`bm25 ${e.bm25Score.toFixed(2)}`:`vector ${e.vectorScore.toFixed(2)} · bm25 ${e.bm25Score.toFixed(2)} · combined ${e.score.toFixed(2)}`,p=e.properties.relativePath,m=typeof p==`string`&&p.length>0,h=m?p.lastIndexOf(`/`):-1,g=m?h===-1?`data`:p.slice(0,h):null;return(0,P.jsxs)(`li`,{className:`data-result`,children:[(0,P.jsxs)(`div`,{role:`button`,tabIndex:0,className:`data-result-open`,onClick:()=>n(e),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),n(e))},"aria-label":`Download ${i??o??`file`}`,children:[o&&(0,P.jsx)(`div`,{className:`data-result-header`,children:(0,P.jsx)(`span`,{className:`data-result-labels`,children:o})}),i&&(0,P.jsx)(`div`,{className:`data-result-title`,children:i}),a&&(0,P.jsx)(`pre`,{className:`data-result-body`,children:d}),(0,P.jsxs)(`div`,{className:`data-result-scores`,children:[s&&(0,P.jsxs)(`span`,{className:`data-result-updated`,children:[`Updated `,We(s),` · `]}),f]})]}),m&&(0,P.jsxs)(`button`,{type:`button`,className:`data-result-locate`,onClick:()=>r(e),title:`Locate in ${g}`,"aria-label":`Locate in ${g}`,children:[(0,P.jsx)(ue,{size:12}),g]}),u&&(0,P.jsx)(`button`,{type:`button`,className:`data-result-toggle`,onClick:()=>l(e=>!e),children:c?`Show less`:`Show more`})]})}function Be(e){if(e.length===0)return null;let t=e[0].replace(/([a-z])([A-Z])/g,`$1 $2`);return t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()}function Ve(e){for(let t of[`title`,`name`,`summary`,`headline`]){let n=e[t];if(typeof n==`string`&&n.length>0)return n.length>140?n.slice(0,140)+`…`:n}return null}function B(e){for(let t of[`content`,`summary`,`body`,`description`,`text`]){let n=e[t];if(typeof n==`string`&&n.length>0)return n}return null}function He(e){for(let t of[`updatedAt`,`modifiedAt`,`fetchedAt`,`createdAt`,`lastModified`]){let n=e[t];if(typeof n==`string`&&n.length>0)return n}return null}function Ue(e){return e==null?``:e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)} MB`:`${(e/1024/1024/1024).toFixed(1)} GB`}function We(e){try{let t=new Date(e);if(isNaN(t.getTime()))return`—`;let n=typeof navigator<`u`?navigator.languages&&navigator.languages.length>0?[...navigator.languages]:[navigator.language]:void 0;return t.toLocaleString(n,{dateStyle:`medium`,timeStyle:`short`})}catch{return`—`}}export{Re as n,Se as r,ke as t};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-Ck5AOu5v.js";import{C as t,T as n,b as r}from"./useSubAccountSwitcher-Cmbcd72K.js";import"./useVoiceRecorder-D9Qa7Eua.js";import{y as i}from"./AdminShell-DzgrZYpX.js";import{a,c as o,i as s,o as c,r as l,s as u}from"./page-BObPPwJr.js";import"./useCopyFeedback-8b1gtbRz.js";import"./file-download-CX16TB7C.js";var d=t(),f=e(n(),1),p=r();function m({gateState:e,setGateState:t,grantInfo:n,resolvedSlugRef:r}){let[a,o]=(0,f.useState)(``),[s,c]=(0,f.useState)(!1),[l,u]=(0,f.useState)(null);async function d(e){e.preventDefault();let n=a.trim().toLowerCase();if(!n){u(`Enter the email you were invited on.`);return}c(!0),u(null);try{let e=await fetch(`/api/access/request-magic-link`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({contactValue:n,agentSlug:r.current})});if(e.status===429){u((await e.json().catch(()=>({})))?.error||`Too many requests. Try again later.`);return}t(`request-sent`)}catch{u(`Could not reach the server. Check your connection and try again.`)}finally{c(!1)}}return(0,p.jsxs)(`div`,{className:`access-gate`,children:[e===`verifying`&&(0,p.jsxs)(`div`,{className:`access-gate-message`,children:[(0,p.jsx)(`h2`,{children:`Verifying your link…`}),(0,p.jsx)(`p`,{children:`This takes a moment.`})]}),e===`verify-failed`&&(0,p.jsxs)(`div`,{className:`access-gate-message`,children:[(0,p.jsx)(`h2`,{children:`That link did not work`}),(0,p.jsx)(`p`,{children:`It may have expired, already been used, or been for a different agent. You can request a fresh one below.`}),(0,p.jsx)(i,{onClick:()=>{t(`request-link`),u(null)},children:`Request a new link`})]}),e===`request-link`&&(0,p.jsxs)(`form`,{className:`access-gate-form`,onSubmit:d,children:[(0,p.jsx)(`h2`,{children:n?.displayName?`Welcome back, ${n.displayName}`:`Sign in`}),(0,p.jsx)(`p`,{children:`Enter the email you were invited on and we will send you a fresh link.`}),(0,p.jsx)(`label`,{htmlFor:`access-email`,children:`Email`}),(0,p.jsx)(`input`,{id:`access-email`,type:`email`,inputMode:`email`,autoComplete:`email`,value:a,onChange:e=>o(e.target.value),disabled:s}),l&&(0,p.jsx)(`p`,{className:`access-gate-error`,children:l}),(0,p.jsx)(i,{type:`submit`,disabled:s||!a.trim(),children:s?`Sending…`:`Send me a link`})]}),e===`request-sent`&&(0,p.jsxs)(`div`,{className:`access-gate-message`,children:[(0,p.jsx)(`h2`,{children:`Check your email`}),(0,p.jsx)(`p`,{children:`If that address is on the invite list, a fresh link is on the way. It expires in 15 minutes.`}),(0,p.jsx)(i,{onClick:()=>{t(`request-link`),o(``),u(null)},children:`Try a different email`})]})]})}function h(){let[e,t]=(0,f.useState)(null),[n,r]=(0,f.useState)(null),[i,l]=(0,f.useState)(`loading`),[d,p]=(0,f.useState)(``),[m,h]=(0,f.useState)(null),[g,_]=(0,f.useState)(null),[v,y]=(0,f.useState)(!1),[b,x]=(0,f.useState)(null),S=(0,f.useMemo)(()=>a(),[]),C=(0,f.useRef)(S||``),w=(0,f.useRef)(null),T=(0,f.useRef)(null),E=(0,f.useRef)(!1),D=(0,f.useRef)(null),[O,k]=(0,f.useState)(`request-link`),[A,j]=(0,f.useState)(null),M=(0,f.useRef)(null),N=(0,f.useRef)(null);(0,f.useEffect)(()=>{try{let e=sessionStorage.getItem(`maxy_session`);e&&(N.current=e)}catch{}},[]),(0,f.useEffect)(()=>{try{let e=c();e&&(sessionStorage.setItem(s,e),o&&console.info(`[public-webchat] op=seed-persisted len=${e.length} head=${e.slice(0,40)}`))}catch{}},[]);let P=(0,f.useCallback)(e=>{w.current=e,t(e);try{sessionStorage.setItem(`maxy_session`,e)}catch{}l(`chat`)},[]),F=(0,f.useCallback)(()=>{w.current=null;try{sessionStorage.removeItem(`maxy_session`)}catch{}t(null),l(`auth-required`),k(`request-link`)},[]),I=(0,f.useCallback)(async e=>{k(`verifying`);try{let t=C.current,n=await fetch(`/api/access/verify-token`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({token:e,agentSlug:t})});if(window.history.replaceState({},``,window.location.pathname),n.ok){let e=await n.json().catch(()=>({}));return e?.displayName&&j({displayName:e.displayName,contactValue:``,expiresAt:null,status:`active`}),!0}return k(`verify-failed`),!1}catch{return k(`verify-failed`),!1}},[]),L=(0,f.useCallback)(async()=>{if(w.current)return w.current;if(T.current)return T.current;let e=(async()=>{try{let e=N.current,n=await fetch(`/api/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({session_id:u(),...S?{agent:S}:{},...e?{session_key:e}:{}})});if(!n.ok){let e=await n.json().catch(()=>({error:``}));return o&&console.error(`[session] POST /api/session failed: ${n.status} ${n.statusText}`,e),n.status===404?r(e.error||`Agent not found`):n.status===503&&r(e.error||`Service unavailable`),null}let i=await n.json();if(i.auth_required){i.agent_id&&(C.current=i.agent_id),p(i.displayName||``),i.agentImage&&h(i.agentImage),i.agentImageShape&&_(i.agentImageShape),i.showAgentName&&y(i.showAgentName),i.branding&&x(i.branding),l(`auth-required`);let e=new URLSearchParams(window.location.search).get(`token`);return e?await I(e)&&window.location.reload():k(`request-link`),null}w.current=i.session_key,t(i.session_key),i.displayName&&p(i.displayName),i.agentImage&&h(i.agentImage),i.agentImageShape&&_(i.agentImageShape),i.showAgentName&&y(i.showAgentName),i.branding&&x(i.branding),l(`chat`),i.resumed&&i.messages&&(E.current=!0,D.current=i.messages);try{sessionStorage.setItem(`maxy_session`,i.session_key)}catch{}return i.session_key}catch(e){return o&&console.error(`[session] fetch /api/session threw:`,e),r(`Unable to connect. Please check your connection and try again.`),null}finally{T.current=null}})();return T.current=e,e},[S,I]);return{sessionId:e,cacheKeyRef:w,sessionError:n,pageState:i,setPageState:l,agentDisplayName:d,agentImage:m,agentImageShape:g,showAgentName:v,agentSlug:S,branding:b,resolvedSlugRef:C,ensureSession:L,startNewSession:(0,f.useCallback)(async()=>{w.current=null,T.current=null,N.current=null,E.current=!1,D.current=null,t(null),r(null);try{sessionStorage.removeItem(`maxy_session`)}catch{}await L()},[L]),enterChat:P,enterGate:F,resumedRef:E,resumeMessagesRef:D,gateState:O,setGateState:k,grantInfo:A,setGrantInfo:j,gateCacheKeyRef:M}}function g(){let{ensureSession:e,pageState:t,gateState:n,setGateState:r,grantInfo:i,resolvedSlugRef:a}=h();return(0,f.useEffect)(()=>{e()},[e]),t===`loading`?(0,p.jsx)(`div`,{className:`public-loading`,children:`Loading…`}):t===`auth-required`?(0,p.jsx)(m,{gateState:n,setGateState:r,grantInfo:i,resolvedSlugRef:a}):(0,p.jsx)(`div`,{className:`public-shell`,children:(0,p.jsx)(l,{cacheKey:``,variant:`public`})})}(0,d.createRoot)(document.getElementById(`root`)).render((0,p.jsx)(g,{}));
1
+ import{o as e}from"./chunk-Ck5AOu5v.js";import{C as t,T as n,b as r}from"./useSubAccountSwitcher-Bo7bnFtC.js";import"./useVoiceRecorder-CZPtVpM-.js";import{y as i}from"./AdminShell-X9Bg3AKc.js";import{a,c as o,i as s,o as c,r as l,s as u}from"./page-BIfOKi9I.js";import"./useCopyFeedback-CpfVOO26.js";import"./file-download-CHTyUQqS.js";var d=t(),f=e(n(),1),p=r();function m({gateState:e,setGateState:t,grantInfo:n,resolvedSlugRef:r}){let[a,o]=(0,f.useState)(``),[s,c]=(0,f.useState)(!1),[l,u]=(0,f.useState)(null);async function d(e){e.preventDefault();let n=a.trim().toLowerCase();if(!n){u(`Enter the email you were invited on.`);return}c(!0),u(null);try{let e=await fetch(`/api/access/request-magic-link`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({contactValue:n,agentSlug:r.current})});if(e.status===429){u((await e.json().catch(()=>({})))?.error||`Too many requests. Try again later.`);return}t(`request-sent`)}catch{u(`Could not reach the server. Check your connection and try again.`)}finally{c(!1)}}return(0,p.jsxs)(`div`,{className:`access-gate`,children:[e===`verifying`&&(0,p.jsxs)(`div`,{className:`access-gate-message`,children:[(0,p.jsx)(`h2`,{children:`Verifying your link…`}),(0,p.jsx)(`p`,{children:`This takes a moment.`})]}),e===`verify-failed`&&(0,p.jsxs)(`div`,{className:`access-gate-message`,children:[(0,p.jsx)(`h2`,{children:`That link did not work`}),(0,p.jsx)(`p`,{children:`It may have expired, already been used, or been for a different agent. You can request a fresh one below.`}),(0,p.jsx)(i,{onClick:()=>{t(`request-link`),u(null)},children:`Request a new link`})]}),e===`request-link`&&(0,p.jsxs)(`form`,{className:`access-gate-form`,onSubmit:d,children:[(0,p.jsx)(`h2`,{children:n?.displayName?`Welcome back, ${n.displayName}`:`Sign in`}),(0,p.jsx)(`p`,{children:`Enter the email you were invited on and we will send you a fresh link.`}),(0,p.jsx)(`label`,{htmlFor:`access-email`,children:`Email`}),(0,p.jsx)(`input`,{id:`access-email`,type:`email`,inputMode:`email`,autoComplete:`email`,value:a,onChange:e=>o(e.target.value),disabled:s}),l&&(0,p.jsx)(`p`,{className:`access-gate-error`,children:l}),(0,p.jsx)(i,{type:`submit`,disabled:s||!a.trim(),children:s?`Sending…`:`Send me a link`})]}),e===`request-sent`&&(0,p.jsxs)(`div`,{className:`access-gate-message`,children:[(0,p.jsx)(`h2`,{children:`Check your email`}),(0,p.jsx)(`p`,{children:`If that address is on the invite list, a fresh link is on the way. It expires in 15 minutes.`}),(0,p.jsx)(i,{onClick:()=>{t(`request-link`),o(``),u(null)},children:`Try a different email`})]})]})}function h(){let[e,t]=(0,f.useState)(null),[n,r]=(0,f.useState)(null),[i,l]=(0,f.useState)(`loading`),[d,p]=(0,f.useState)(``),[m,h]=(0,f.useState)(null),[g,_]=(0,f.useState)(null),[v,y]=(0,f.useState)(!1),[b,x]=(0,f.useState)(null),S=(0,f.useMemo)(()=>a(),[]),C=(0,f.useRef)(S||``),w=(0,f.useRef)(null),T=(0,f.useRef)(null),E=(0,f.useRef)(!1),D=(0,f.useRef)(null),[O,k]=(0,f.useState)(`request-link`),[A,j]=(0,f.useState)(null),M=(0,f.useRef)(null),N=(0,f.useRef)(null);(0,f.useEffect)(()=>{try{let e=sessionStorage.getItem(`maxy_session`);e&&(N.current=e)}catch{}},[]),(0,f.useEffect)(()=>{try{let e=c();e&&(sessionStorage.setItem(s,e),o&&console.info(`[public-webchat] op=seed-persisted len=${e.length} head=${e.slice(0,40)}`))}catch{}},[]);let P=(0,f.useCallback)(e=>{w.current=e,t(e);try{sessionStorage.setItem(`maxy_session`,e)}catch{}l(`chat`)},[]),F=(0,f.useCallback)(()=>{w.current=null;try{sessionStorage.removeItem(`maxy_session`)}catch{}t(null),l(`auth-required`),k(`request-link`)},[]),I=(0,f.useCallback)(async e=>{k(`verifying`);try{let t=C.current,n=await fetch(`/api/access/verify-token`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({token:e,agentSlug:t})});if(window.history.replaceState({},``,window.location.pathname),n.ok){let e=await n.json().catch(()=>({}));return e?.displayName&&j({displayName:e.displayName,contactValue:``,expiresAt:null,status:`active`}),!0}return k(`verify-failed`),!1}catch{return k(`verify-failed`),!1}},[]),L=(0,f.useCallback)(async()=>{if(w.current)return w.current;if(T.current)return T.current;let e=(async()=>{try{let e=N.current,n=await fetch(`/api/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({session_id:u(),...S?{agent:S}:{},...e?{session_key:e}:{}})});if(!n.ok){let e=await n.json().catch(()=>({error:``}));return o&&console.error(`[session] POST /api/session failed: ${n.status} ${n.statusText}`,e),n.status===404?r(e.error||`Agent not found`):n.status===503&&r(e.error||`Service unavailable`),null}let i=await n.json();if(i.auth_required){i.agent_id&&(C.current=i.agent_id),p(i.displayName||``),i.agentImage&&h(i.agentImage),i.agentImageShape&&_(i.agentImageShape),i.showAgentName&&y(i.showAgentName),i.branding&&x(i.branding),l(`auth-required`);let e=new URLSearchParams(window.location.search).get(`token`);return e?await I(e)&&window.location.reload():k(`request-link`),null}w.current=i.session_key,t(i.session_key),i.displayName&&p(i.displayName),i.agentImage&&h(i.agentImage),i.agentImageShape&&_(i.agentImageShape),i.showAgentName&&y(i.showAgentName),i.branding&&x(i.branding),l(`chat`),i.resumed&&i.messages&&(E.current=!0,D.current=i.messages);try{sessionStorage.setItem(`maxy_session`,i.session_key)}catch{}return i.session_key}catch(e){return o&&console.error(`[session] fetch /api/session threw:`,e),r(`Unable to connect. Please check your connection and try again.`),null}finally{T.current=null}})();return T.current=e,e},[S,I]);return{sessionId:e,cacheKeyRef:w,sessionError:n,pageState:i,setPageState:l,agentDisplayName:d,agentImage:m,agentImageShape:g,showAgentName:v,agentSlug:S,branding:b,resolvedSlugRef:C,ensureSession:L,startNewSession:(0,f.useCallback)(async()=>{w.current=null,T.current=null,N.current=null,E.current=!1,D.current=null,t(null),r(null);try{sessionStorage.removeItem(`maxy_session`)}catch{}await L()},[L]),enterChat:P,enterGate:F,resumedRef:E,resumeMessagesRef:D,gateState:O,setGateState:k,grantInfo:A,setGrantInfo:j,gateCacheKeyRef:M}}function g(){let{ensureSession:e,pageState:t,gateState:n,setGateState:r,grantInfo:i,resolvedSlugRef:a}=h();return(0,f.useEffect)(()=>{e()},[e]),t===`loading`?(0,p.jsx)(`div`,{className:`public-loading`,children:`Loading…`}):t===`auth-required`?(0,p.jsx)(m,{gateState:n,setGateState:r,grantInfo:i,resolvedSlugRef:a}):(0,p.jsx)(`div`,{className:`public-shell`,children:(0,p.jsx)(l,{cacheKey:``,variant:`public`})})}(0,d.createRoot)(document.getElementById(`root`)).render((0,p.jsx)(g,{}));
@@ -0,0 +1 @@
1
+ import{o as e}from"./chunk-Ck5AOu5v.js";import{C as t,S as n,T as r,b as i,h as a,n as o,r as s,s as c,t as l,u}from"./useSubAccountSwitcher-Bo7bnFtC.js";import{n as d,t as f}from"./time-entry-format-D477WAes.js";var p=a(`circle-check`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]),m=a(`circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),h=t(),g=e(r(),1);function _(e=3e4){let[t,n]=(0,g.useState)(()=>Date.now());return(0,g.useEffect)(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}function v(e,t){let n=new Map,r=(e,t,r)=>{let i=n.get(e)??{openCount:0,totalSeconds:0};i.totalSeconds+=t,r&&(i.openCount+=1),n.set(e,i)};for(let t of e)t.clientName&&r(t.clientName,t.secondsLogged,!0);for(let e of t)e.clientName&&r(e.clientName,e.secondsLogged,!1);let i=[...n.entries()].map(([e,t])=>({name:e,openCount:t.openCount,totalSeconds:t.totalSeconds}));return i.sort((e,t)=>t.openCount-e.openCount||e.name.localeCompare(t.name)),y(e,i),i}function y(e,t){let n=t.reduce((e,t)=>e+t.openCount,0),r=e.filter(e=>!e.clientName).length,i=n+r===e.length;return i||console.warn(`[tasks-clients] reconcile-mismatch assigned=${n} unassigned=${r} openTotal=${e.length}`),i}var b=i();function x(e){let t=[];return e.clientName&&t.push(e.clientName),e.propertyAddress&&t.push(e.propertyAddress),e.fee!=null&&t.push(`£${e.fee}`),t.join(` · `)}function S(e){return[e.clientName,e.propertyAddress].filter(Boolean).join(` · `)}function C(e,t){if(e.running&&e.runningStartedAt){let n=Date.parse(e.runningStartedAt);if(Number.isFinite(n))return e.secondsLogged+Math.max(0,(t-n)/1e3)}return e.secondsLogged}function w({clients:e,onSelect:t}){return(0,b.jsxs)(`section`,{className:`tasks-card`,children:[(0,b.jsxs)(`div`,{className:`tasks-card-head`,children:[(0,b.jsx)(`span`,{className:`tasks-card-title`,children:`Clients`}),(0,b.jsxs)(`span`,{className:`tasks-card-count`,children:[e.length,` total`]})]}),e.length===0&&(0,b.jsx)(`div`,{className:`tasks-empty`,children:`No clients yet.`}),e.map(e=>(0,b.jsx)(`button`,{className:`tasks-row tasks-client-row`,onClick:()=>t(e.name),children:(0,b.jsxs)(`div`,{className:`tasks-row-main`,children:[(0,b.jsx)(`div`,{className:`tasks-row-name`,children:e.name}),(0,b.jsxs)(`div`,{className:`tasks-row-sub`,children:[e.openCount,` open · `,f(e.totalSeconds),` logged`]})]})},e.name))]})}function T({adminFetch:e}){let[t,n]=(0,g.useState)({open:[],completed:[]}),[r,i]=(0,g.useState)(!1),[a,o]=(0,g.useState)(!1),s=(0,g.useRef)(!1),l=_(1e3),[h,y]=(0,g.useState)(`tasks`),[T,E]=(0,g.useState)(null),D=(0,g.useMemo)(()=>v(t.open,t.completed),[t]),O=(0,g.useCallback)(e=>{E(e),y(`tasks`)},[]);(0,g.useEffect)(()=>{T&&!D.some(e=>e.name===T)&&E(null)},[D,T]);let k=T?t.open.filter(e=>e.clientName===T||e.running):t.open,A=T?t.completed.filter(e=>e.clientName===T):t.completed,j=(0,g.useCallback)(async()=>{let t=await e(`/api/admin/tasks-list`);t.ok&&n(await t.json()),i(!0)},[e]);(0,g.useEffect)(()=>{j()},[j]);let M=(0,g.useMemo)(()=>t.open.some(e=>e.running),[t.open]),N=(0,g.useCallback)(async(t,n)=>{if(!s.current){s.current=!0,o(!0);try{await e(t,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({taskId:n})}),await j()}finally{s.current=!1,o(!1)}}},[e,j]);return r?(0,b.jsxs)(`div`,{className:`tasks-body`,children:[(0,b.jsxs)(`div`,{className:`tasks-tabs`,children:[(0,b.jsxs)(`button`,{className:`tasks-tab ${h===`tasks`?`tasks-tab-active`:``}`,onClick:()=>y(`tasks`),children:[`Task list `,(0,b.jsx)(`span`,{className:`tasks-tab-badge`,children:t.open.length})]}),(0,b.jsxs)(`button`,{className:`tasks-tab ${h===`clients`?`tasks-tab-active`:``}`,onClick:()=>y(`clients`),children:[`Clients `,(0,b.jsx)(`span`,{className:`tasks-tab-badge`,children:D.length})]})]}),h===`clients`?(0,b.jsx)(w,{clients:D,onSelect:O}):(0,b.jsxs)(b.Fragment,{children:[T&&(0,b.jsxs)(`div`,{className:`tasks-filter-banner`,children:[(0,b.jsxs)(`span`,{children:[`Showing `,T]}),(0,b.jsx)(`button`,{className:`tasks-filter-clear`,onClick:()=>E(null),children:`Clear`})]}),(0,b.jsxs)(`section`,{className:`tasks-card`,children:[(0,b.jsxs)(`div`,{className:`tasks-card-head`,children:[(0,b.jsx)(`span`,{className:`tasks-card-title`,children:`Open tasks`}),(0,b.jsxs)(`span`,{className:`tasks-card-count`,children:[k.length,` to do`]})]}),k.length===0&&(0,b.jsx)(`div`,{className:`tasks-empty`,children:`No open tasks.`}),k.map(e=>(0,b.jsxs)(`div`,{className:`tasks-row`,children:[(0,b.jsx)(`button`,{className:`tasks-check`,"aria-label":`Mark complete`,disabled:a||e.running,title:e.running?`Stop the timer before completing`:void 0,onClick:()=>void N(`/api/admin/task-complete`,e.taskId),children:(0,b.jsx)(m,{size:18})}),(0,b.jsxs)(`div`,{className:`tasks-row-main`,children:[(0,b.jsx)(`div`,{className:`tasks-row-name`,children:e.name}),x(e)&&(0,b.jsx)(`div`,{className:`tasks-row-sub`,children:x(e)})]}),(0,b.jsx)(`div`,{className:`tasks-row-elapsed`,children:f(C(e,l))}),e.running?(0,b.jsxs)(`button`,{className:`tasks-btn tasks-btn-stop`,disabled:a,onClick:()=>void N(`/api/admin/task-timer-stop`,e.taskId),children:[(0,b.jsx)(c,{size:14}),` Stop`]}):(0,b.jsxs)(`button`,{className:`tasks-btn tasks-btn-start`,disabled:a||M,onClick:()=>void N(`/api/admin/task-timer-start`,e.taskId),children:[(0,b.jsx)(d,{size:14}),` Start`]})]},e.taskId))]}),(0,b.jsxs)(`section`,{className:`tasks-card`,children:[(0,b.jsxs)(`div`,{className:`tasks-card-head`,children:[(0,b.jsx)(`span`,{className:`tasks-card-title`,children:`Completed`}),(0,b.jsxs)(`span`,{className:`tasks-card-count`,children:[A.length,` done`]})]}),A.length===0&&(0,b.jsx)(`div`,{className:`tasks-empty`,children:`Nothing completed yet.`}),A.map(e=>(0,b.jsxs)(`div`,{className:`tasks-row tasks-row-done`,children:[(0,b.jsx)(`span`,{className:`tasks-check tasks-check-done`,children:(0,b.jsx)(p,{size:18})}),(0,b.jsxs)(`div`,{className:`tasks-row-main`,children:[(0,b.jsx)(`div`,{className:`tasks-row-name`,children:e.name}),S(e)&&(0,b.jsx)(`div`,{className:`tasks-row-sub`,children:S(e)})]}),(0,b.jsxs)(`div`,{className:`tasks-row-elapsed`,children:[f(e.secondsLogged),e.fee==null?``:` · £${e.fee}`]})]},e.taskId))]})]})]}):(0,b.jsxs)(`div`,{className:`tasks-loading`,children:[(0,b.jsx)(u,{size:18,className:`spin`}),` Loading…`]})}function E({cacheKey:e}){let{adminFetch:t,cacheKey:r}=n({initialCacheKey:e,surface:`tasks`}),{subAccounts:i,activeAccountId:a,switching:s,switchAccount:c}=l(r),u=(0,g.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]);return(0,b.jsxs)(`main`,{className:`tasks-main`,children:[(0,b.jsx)(o,{variant:`operator`,onNavigate:(0,g.useCallback)(e=>{e===`chat`&&(window.location.href=`/`)},[]),onToggleSidebar:()=>{},sidebarOpen:!1,onLogout:u,onDisconnect:async()=>!0,disconnecting:!1,cacheKey:r,subAccounts:i,activeAccountId:a,switchingAccount:s,onSwitchAccount:c}),(0,b.jsx)(T,{adminFetch:t})]})}function D(){let[e,t]=(0,g.useState)(null),[n,r]=(0,g.useState)(!1);return(0,g.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!n){t(null),r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]),n?e?(0,b.jsx)(s,{cacheKey:e,surface:`tasks`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=tasks`);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},children:(0,b.jsx)(`div`,{className:`tasks-page tasks-page-full`,children:(0,b.jsx)(E,{cacheKey:e})})}):(0,b.jsx)(`div`,{className:`tasks-page`,children:(0,b.jsxs)(`div`,{className:`tasks-empty`,children:[(0,b.jsx)(`p`,{children:`You are not signed in.`}),(0,b.jsxs)(`p`,{children:[`Open the `,(0,b.jsx)(`a`,{href:`/`,className:`tasks-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,b.jsx)(`div`,{className:`tasks-page`,children:(0,b.jsxs)(`div`,{className:`tasks-loading`,children:[(0,b.jsx)(u,{size:18,className:`spin`}),` Loading…`]})})}(0,h.createRoot)(document.getElementById(`root`)).render((0,b.jsx)(D,{}));
@@ -0,0 +1 @@
1
+ import{h as e}from"./useSubAccountSwitcher-Bo7bnFtC.js";var t=e(`play`,[[`path`,{d:`M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z`,key:`10ikf1`}]]);function n(e){let t=Math.max(0,Math.floor(e)),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60;return n>0?`${n}:${String(r).padStart(2,`0`)}`:`${r}:${String(i).padStart(2,`0`)}`}export{t as n,n as t};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-Ck5AOu5v.js";import{T as t,h as n}from"./useSubAccountSwitcher-Cmbcd72K.js";import{o as r}from"./AdminShell-DzgrZYpX.js";var i=n(`copy`,[[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),a=n(`rotate-ccw`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}]]),o=e(t(),1);function s(e){let[t,n]=(0,o.useState)(`idle`),i=(0,o.useRef)(null),a=(0,o.useRef)(e?.onResult);return a.current=e?.onResult,(0,o.useEffect)(()=>()=>{i.current&&clearTimeout(i.current)},[]),{status:t,copy:(0,o.useCallback)(async e=>{let t=await r(e);n(t?`ok`:`fail`),a.current?.(t),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>n(`idle`),1500)},[])}}export{a as n,i as r,s as t};
1
+ import{o as e}from"./chunk-Ck5AOu5v.js";import{T as t,h as n}from"./useSubAccountSwitcher-Bo7bnFtC.js";import{o as r}from"./AdminShell-X9Bg3AKc.js";var i=n(`copy`,[[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),a=n(`rotate-ccw`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}]]),o=e(t(),1);function s(e){let[t,n]=(0,o.useState)(`idle`),i=(0,o.useRef)(null),a=(0,o.useRef)(e?.onResult);return a.current=e?.onResult,(0,o.useEffect)(()=>()=>{i.current&&clearTimeout(i.current)},[]),{status:t,copy:(0,o.useCallback)(async e=>{let t=await r(e);n(t?`ok`:`fail`),a.current?.(t),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>n(`idle`),1500)},[])}}export{a as n,i as r,s as t};