@rubytech/create-sitedesk-code 0.1.513 → 0.1.514

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 (178) hide show
  1. package/package.json +1 -1
  2. package/payload/platform/docs/superpowers/plans/2026-07-27-task-2052-account-machinery-write-fence.md +250 -0
  3. package/payload/platform/docs/superpowers/specs/2026-07-27-task-2028-declared-file-write-deny-design.md +2 -1
  4. package/payload/platform/docs/superpowers/specs/2026-07-27-task-2052-account-machinery-write-fence-design.md +150 -0
  5. package/payload/platform/plugins/admin/hooks/__tests__/fs-schema-guard.test.sh +41 -0
  6. package/payload/platform/plugins/admin/hooks/fs-schema-guard-bash-post.sh +8 -0
  7. package/payload/platform/plugins/admin/hooks/fs-schema-guard.sh +40 -1
  8. package/payload/platform/plugins/admin/skills/whats-new/SKILL.md +6 -0
  9. package/payload/platform/plugins/cloudflare/bin/schema-exposed-dirs.mjs +1 -1
  10. package/payload/platform/plugins/whatsapp/references/channels-whatsapp.md +1 -1
  11. package/payload/platform/templates/account-schema/SCHEMA.md +17 -0
  12. package/payload/server/public/activity.html +5 -5
  13. package/payload/server/public/agents.html +4 -4
  14. package/payload/server/public/assets/{AdminLoginScreens-bksN0XPe.js → AdminLoginScreens-Cs1jSnOF.js} +1 -1
  15. package/payload/server/public/assets/AdminLoginScreens-Cs1jSnOF.js.br +0 -0
  16. package/payload/server/public/assets/AdminLoginScreens-Cs1jSnOF.js.gz +0 -0
  17. package/payload/server/public/assets/{AdminShell-BMPEWNZk.js → AdminShell-DkrURZnF.js} +1 -1
  18. package/payload/server/public/assets/AdminShell-DkrURZnF.js.br +0 -0
  19. package/payload/server/public/assets/AdminShell-DkrURZnF.js.gz +0 -0
  20. package/payload/server/public/assets/{activity-ByWYF5dC.js → activity-BgZISMuE.js} +1 -1
  21. package/payload/server/public/assets/activity-BgZISMuE.js.br +0 -0
  22. package/payload/server/public/assets/activity-BgZISMuE.js.gz +0 -0
  23. package/payload/server/public/assets/{admin-6QN-k3zQ.js → admin-DjFysc3-.js} +1 -1
  24. package/payload/server/public/assets/admin-DjFysc3-.js.br +0 -0
  25. package/payload/server/public/assets/admin-DjFysc3-.js.gz +0 -0
  26. package/payload/server/public/assets/{agents-C0rTfrYd.js → agents-Bx-MSZW6.js} +1 -1
  27. package/payload/server/public/assets/agents-Bx-MSZW6.js.br +0 -0
  28. package/payload/server/public/assets/agents-Bx-MSZW6.js.gz +0 -0
  29. package/payload/server/public/assets/{browser-4tTaem8N.js → browser-1I7syhHu.js} +1 -1
  30. package/payload/server/public/assets/browser-1I7syhHu.js.br +0 -0
  31. package/payload/server/public/assets/browser-1I7syhHu.js.gz +0 -0
  32. package/payload/server/public/assets/{calendar-BEjnkKG1.js → calendar-D_04JIo1.js} +1 -1
  33. package/payload/server/public/assets/calendar-D_04JIo1.js.br +0 -0
  34. package/payload/server/public/assets/calendar-D_04JIo1.js.gz +0 -0
  35. package/payload/server/public/assets/chat-BFH3FM5a.js +1 -0
  36. package/payload/server/public/assets/chat-BFH3FM5a.js.br +0 -0
  37. package/payload/server/public/assets/chat-BFH3FM5a.js.gz +0 -0
  38. package/payload/server/public/assets/chevron-left-Ux9-qLkk.js +1 -0
  39. package/payload/server/public/assets/chevron-right-BwIuCfyG.js +1 -0
  40. package/payload/server/public/assets/chevron-right-BwIuCfyG.js.br +0 -0
  41. package/payload/server/public/assets/clock-DhJdZRhC.js +1 -0
  42. package/payload/server/public/assets/clock-DhJdZRhC.js.br +0 -0
  43. package/payload/server/public/assets/data-ChY_uSIk.js +1 -0
  44. package/payload/server/public/assets/data-ChY_uSIk.js.br +0 -0
  45. package/payload/server/public/assets/data-ChY_uSIk.js.gz +0 -0
  46. package/payload/server/public/assets/{file-text-DMKw3nIk.js → file-text-DkvKqHMx.js} +1 -1
  47. package/payload/server/public/assets/file-text-DkvKqHMx.js.br +0 -0
  48. package/payload/server/public/assets/file-text-DkvKqHMx.js.gz +0 -0
  49. package/payload/server/public/assets/{graph-C3vW8lvw.js → graph-CCZhrwZX.js} +1 -1
  50. package/payload/server/public/assets/graph-CCZhrwZX.js.br +0 -0
  51. package/payload/server/public/assets/graph-CCZhrwZX.js.gz +0 -0
  52. package/payload/server/public/assets/{graph-labels-BZgd0L6n.js → graph-labels-BJ7puQkX.js} +1 -1
  53. package/payload/server/public/assets/graph-labels-BJ7puQkX.js.br +0 -0
  54. package/payload/server/public/assets/graph-labels-BJ7puQkX.js.gz +0 -0
  55. package/payload/server/public/assets/{maximize-2-la3IBA3M.js → maximize-2-Xdj804U1.js} +1 -1
  56. package/payload/server/public/assets/maximize-2-Xdj804U1.js.br +0 -0
  57. package/payload/server/public/assets/maximize-2-Xdj804U1.js.gz +0 -0
  58. package/payload/server/public/assets/{operator-D9NgVL9_.js → operator-BkfNpBs7.js} +1 -1
  59. package/payload/server/public/assets/operator-BkfNpBs7.js.br +0 -0
  60. package/payload/server/public/assets/operator-BkfNpBs7.js.gz +0 -0
  61. package/payload/server/public/assets/{page-DC11gesX.js → page-BoYc9c4a.js} +1 -1
  62. package/payload/server/public/assets/page-BoYc9c4a.js.br +0 -0
  63. package/payload/server/public/assets/page-BoYc9c4a.js.gz +0 -0
  64. package/payload/server/public/assets/{page-BWFHRIAH.js → page-D5n8ShE7.js} +1 -1
  65. package/payload/server/public/assets/page-D5n8ShE7.js.br +0 -0
  66. package/payload/server/public/assets/page-D5n8ShE7.js.gz +0 -0
  67. package/payload/server/public/assets/{public-DQbbLHQN.js → public-CX5XSrxD.js} +1 -1
  68. package/payload/server/public/assets/public-CX5XSrxD.js.br +0 -0
  69. package/payload/server/public/assets/public-CX5XSrxD.js.gz +0 -0
  70. package/payload/server/public/assets/{rotate-ccw-OQD5si8N.js → rotate-ccw-dh_OhL23.js} +1 -1
  71. package/payload/server/public/assets/rotate-ccw-dh_OhL23.js.br +0 -0
  72. package/payload/server/public/assets/rotate-ccw-dh_OhL23.js.gz +0 -0
  73. package/payload/server/public/assets/{routines-asrBGZUR.js → routines-bb7dxcrr.js} +1 -1
  74. package/payload/server/public/assets/routines-bb7dxcrr.js.br +0 -0
  75. package/payload/server/public/assets/routines-bb7dxcrr.js.gz +0 -0
  76. package/payload/server/public/assets/{skills-D4ECwoxa.js → skills-TeMwxXmJ.js} +1 -1
  77. package/payload/server/public/assets/skills-TeMwxXmJ.js.br +0 -0
  78. package/payload/server/public/assets/skills-TeMwxXmJ.js.gz +0 -0
  79. package/payload/server/public/assets/{tasks-U3QdbUsO.js → tasks-BqBBJlkg.js} +1 -1
  80. package/payload/server/public/assets/tasks-BqBBJlkg.js.br +0 -0
  81. package/payload/server/public/assets/tasks-BqBBJlkg.js.gz +0 -0
  82. package/payload/server/public/assets/{time-entry-format-BgdTKgYr.js → time-entry-format-Cy_T-wiD.js} +1 -1
  83. package/payload/server/public/assets/time-entry-format-Cy_T-wiD.js.br +3 -0
  84. package/payload/server/public/assets/time-entry-format-Cy_T-wiD.js.gz +0 -0
  85. package/payload/server/public/assets/{triangle-alert-Ck_3VhT9.js → triangle-alert-D-bSbPnX.js} +1 -1
  86. package/payload/server/public/assets/triangle-alert-D-bSbPnX.js.br +1 -0
  87. package/payload/server/public/assets/triangle-alert-D-bSbPnX.js.gz +0 -0
  88. package/payload/server/public/assets/{useCopyFeedback-BdUwyNpa.js → useCopyFeedback-L7L55nFl.js} +1 -1
  89. package/payload/server/public/assets/useCopyFeedback-L7L55nFl.js.br +0 -0
  90. package/payload/server/public/assets/useCopyFeedback-L7L55nFl.js.gz +0 -0
  91. package/payload/server/public/assets/useSubAccountSwitcher-BYl2c7xA.css +1 -0
  92. package/payload/server/public/assets/useSubAccountSwitcher-BYl2c7xA.css.br +0 -0
  93. package/payload/server/public/assets/useSubAccountSwitcher-BYl2c7xA.css.gz +0 -0
  94. package/payload/server/public/assets/{useVoiceRecorder-ChnBrzbZ.js → useVoiceRecorder-MuZ7lpet.js} +1 -1
  95. package/payload/server/public/assets/useVoiceRecorder-MuZ7lpet.js.br +0 -0
  96. package/payload/server/public/assets/useVoiceRecorder-MuZ7lpet.js.gz +0 -0
  97. package/payload/server/public/assets/{wrench-Cpee3C3J.js → wrench-DUG1SZQB.js} +1 -1
  98. package/payload/server/public/assets/wrench-DUG1SZQB.js.br +0 -0
  99. package/payload/server/public/assets/wrench-DUG1SZQB.js.gz +0 -0
  100. package/payload/server/public/brand-defaults.css +2 -0
  101. package/payload/server/public/browser.html +4 -4
  102. package/payload/server/public/calendar.html +7 -7
  103. package/payload/server/public/chat.html +13 -13
  104. package/payload/server/public/data.html +11 -11
  105. package/payload/server/public/graph.html +9 -9
  106. package/payload/server/public/index.html +14 -14
  107. package/payload/server/public/operator.html +14 -14
  108. package/payload/server/public/public.html +13 -13
  109. package/payload/server/public/routines.html +6 -6
  110. package/payload/server/public/skills.html +5 -5
  111. package/payload/server/public/tasks.html +6 -6
  112. package/payload/server/server.js +37 -6
  113. package/payload/server/public/assets/AdminLoginScreens-bksN0XPe.js.br +0 -0
  114. package/payload/server/public/assets/AdminLoginScreens-bksN0XPe.js.gz +0 -0
  115. package/payload/server/public/assets/AdminShell-BMPEWNZk.js.br +0 -0
  116. package/payload/server/public/assets/AdminShell-BMPEWNZk.js.gz +0 -0
  117. package/payload/server/public/assets/activity-ByWYF5dC.js.br +0 -0
  118. package/payload/server/public/assets/activity-ByWYF5dC.js.gz +0 -0
  119. package/payload/server/public/assets/admin-6QN-k3zQ.js.br +0 -0
  120. package/payload/server/public/assets/admin-6QN-k3zQ.js.gz +0 -0
  121. package/payload/server/public/assets/agents-C0rTfrYd.js.br +0 -0
  122. package/payload/server/public/assets/agents-C0rTfrYd.js.gz +0 -0
  123. package/payload/server/public/assets/browser-4tTaem8N.js.br +0 -0
  124. package/payload/server/public/assets/browser-4tTaem8N.js.gz +0 -0
  125. package/payload/server/public/assets/calendar-BEjnkKG1.js.br +0 -0
  126. package/payload/server/public/assets/calendar-BEjnkKG1.js.gz +0 -0
  127. package/payload/server/public/assets/chat-DBgzjDIE.js +0 -1
  128. package/payload/server/public/assets/chat-DBgzjDIE.js.br +0 -0
  129. package/payload/server/public/assets/chat-DBgzjDIE.js.gz +0 -0
  130. package/payload/server/public/assets/chevron-left-DqYv3oFh.js +0 -1
  131. package/payload/server/public/assets/chevron-right-CQfPGsFb.js +0 -1
  132. package/payload/server/public/assets/chevron-right-CQfPGsFb.js.br +0 -0
  133. package/payload/server/public/assets/clock-Dn6FHB51.js +0 -1
  134. package/payload/server/public/assets/clock-Dn6FHB51.js.br +0 -0
  135. package/payload/server/public/assets/clock-Dn6FHB51.js.gz +0 -0
  136. package/payload/server/public/assets/data-D_e6Vdfd.js +0 -1
  137. package/payload/server/public/assets/data-D_e6Vdfd.js.br +0 -0
  138. package/payload/server/public/assets/data-D_e6Vdfd.js.gz +0 -0
  139. package/payload/server/public/assets/file-text-DMKw3nIk.js.br +0 -0
  140. package/payload/server/public/assets/file-text-DMKw3nIk.js.gz +0 -0
  141. package/payload/server/public/assets/graph-C3vW8lvw.js.br +0 -0
  142. package/payload/server/public/assets/graph-C3vW8lvw.js.gz +0 -0
  143. package/payload/server/public/assets/graph-labels-BZgd0L6n.js.br +0 -0
  144. package/payload/server/public/assets/graph-labels-BZgd0L6n.js.gz +0 -0
  145. package/payload/server/public/assets/maximize-2-la3IBA3M.js.br +0 -0
  146. package/payload/server/public/assets/maximize-2-la3IBA3M.js.gz +0 -0
  147. package/payload/server/public/assets/operator-D9NgVL9_.js.br +0 -0
  148. package/payload/server/public/assets/operator-D9NgVL9_.js.gz +0 -0
  149. package/payload/server/public/assets/page-BWFHRIAH.js.br +0 -0
  150. package/payload/server/public/assets/page-BWFHRIAH.js.gz +0 -0
  151. package/payload/server/public/assets/page-DC11gesX.js.br +0 -0
  152. package/payload/server/public/assets/page-DC11gesX.js.gz +0 -0
  153. package/payload/server/public/assets/public-DQbbLHQN.js.br +0 -0
  154. package/payload/server/public/assets/public-DQbbLHQN.js.gz +0 -0
  155. package/payload/server/public/assets/rotate-ccw-OQD5si8N.js.br +0 -0
  156. package/payload/server/public/assets/rotate-ccw-OQD5si8N.js.gz +0 -0
  157. package/payload/server/public/assets/routines-asrBGZUR.js.br +0 -0
  158. package/payload/server/public/assets/routines-asrBGZUR.js.gz +0 -0
  159. package/payload/server/public/assets/skills-D4ECwoxa.js.br +0 -0
  160. package/payload/server/public/assets/skills-D4ECwoxa.js.gz +0 -0
  161. package/payload/server/public/assets/tasks-U3QdbUsO.js.br +0 -0
  162. package/payload/server/public/assets/tasks-U3QdbUsO.js.gz +0 -0
  163. package/payload/server/public/assets/time-entry-format-BgdTKgYr.js.br +0 -0
  164. package/payload/server/public/assets/time-entry-format-BgdTKgYr.js.gz +0 -0
  165. package/payload/server/public/assets/triangle-alert-Ck_3VhT9.js.br +0 -0
  166. package/payload/server/public/assets/triangle-alert-Ck_3VhT9.js.gz +0 -0
  167. package/payload/server/public/assets/useCopyFeedback-BdUwyNpa.js.br +0 -0
  168. package/payload/server/public/assets/useCopyFeedback-BdUwyNpa.js.gz +0 -0
  169. package/payload/server/public/assets/useSubAccountSwitcher-DOWQXDT8.css +0 -1
  170. package/payload/server/public/assets/useSubAccountSwitcher-DOWQXDT8.css.br +0 -0
  171. package/payload/server/public/assets/useSubAccountSwitcher-DOWQXDT8.css.gz +0 -0
  172. package/payload/server/public/assets/useVoiceRecorder-ChnBrzbZ.js.br +0 -0
  173. package/payload/server/public/assets/useVoiceRecorder-ChnBrzbZ.js.gz +0 -0
  174. package/payload/server/public/assets/wrench-Cpee3C3J.js.br +0 -2
  175. package/payload/server/public/assets/wrench-Cpee3C3J.js.gz +0 -0
  176. /package/payload/server/public/assets/{useSubAccountSwitcher-CJKjEPNN.js → useSubAccountSwitcher-DH0P6QMV.js} +0 -0
  177. /package/payload/server/public/assets/{useSubAccountSwitcher-CJKjEPNN.js.br → useSubAccountSwitcher-DH0P6QMV.js.br} +0 -0
  178. /package/payload/server/public/assets/{useSubAccountSwitcher-CJKjEPNN.js.gz → useSubAccountSwitcher-DH0P6QMV.js.gz} +0 -0
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,F as n,K as r,O as i,P as a,S as o,T as s,U as c,_ as l,a as u,b as d,c as f,d as p,g as m,i as h,k as g,p as _,s as v,t as y,u as b,v as ee,x as te,y as x}from"./useSubAccountSwitcher-CJKjEPNN.js";import{C as ne,E as S,S as re,T as ie,n as ae,r as C,s as oe}from"./useVoiceRecorder-ChnBrzbZ.js";import{t as w}from"./chevron-left-DqYv3oFh.js";import{t as T}from"./file-text-DMKw3nIk.js";import{i as E,t as D}from"./graph-labels-BZgd0L6n.js";import{t as O}from"./triangle-alert-Ck_3VhT9.js";var se=a(`arrow-left`,[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]),ce=a(`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=a(`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=a(`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=a(`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=a(`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=a(`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`}]]),k=a(`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`}]]),me=a(`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=a(`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`}]]),A=a(`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`}]]),j=e(r(),1);function ge(){let[e,t]=(0,j.useState)([]),[n,r]=(0,j.useState)(!1),[i,a]=(0,j.useState)(null),o=(0,j.useRef)(null),s=(0,j.useCallback)(e=>{a(null);let n=e.find(e=>!C(e.type,S));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>ie);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,j.useCallback)(()=>{t([]),a(null)},[]),removeFile:(0,j.useCallback)(e=>{t(t=>t.filter((t,n)=>n!==e))},[]),onDragOver:(0,j.useCallback)(e=>{e.preventDefault(),r(!0)},[]),onDragLeave:(0,j.useCallback)(()=>{r(!1)},[]),onDrop:(0,j.useCallback)(e=>{e.preventDefault(),r(!1),s([...e.dataTransfer.files])},[s])}}var M=[[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 _e(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 N=t();function P({onSelect:e}){return(0,N.jsx)(`div`,{className:`wa-emoji-popover`,role:`menu`,"aria-label":`Emoji picker`,children:M.map((t,n)=>(0,N.jsx)(`button`,{type:`button`,role:`menuitem`,className:`wa-emoji-item`,onClick:()=>e(t),children:t},n))})}function ve({sessionKey:e,onPick:t,onClose:n}){let[r,a]=(0,j.useState)(``),[o,s]=(0,j.useState)(null),[c,l]=(0,j.useState)(null),[u,d]=(0,j.useState)(!1),f=(0,j.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,j.useEffect)(()=>{f(``)},[f]);let p=e=>f(r?`${r}/${e}`:e),h=()=>{let e=r.split(`/`).filter(Boolean);e.pop(),f(e.join(`/`))},g=e=>{let n=e.entryPath??e.name;t({path:r?`${r}/${n}`:n,name:e.displayName??e.name})};return(0,N.jsx)(`div`,{className:`wa-picker-backdrop`,role:`dialog`,"aria-label":`Choose a device file`,onClick:n,children:(0,N.jsxs)(`div`,{className:`wa-picker`,onClick:e=>e.stopPropagation(),children:[(0,N.jsxs)(`div`,{className:`wa-picker-head`,children:[r&&(0,N.jsx)(`button`,{type:`button`,className:`wa-picker-icon-btn`,onClick:h,"aria-label":`Up one folder`,children:(0,N.jsx)(w,{size:18})}),(0,N.jsx)(`span`,{className:`wa-picker-title`,children:r||`Device storage`}),(0,N.jsx)(`button`,{type:`button`,className:`wa-picker-icon-btn`,onClick:n,"aria-label":`Close file picker`,children:(0,N.jsx)(m,{size:18})})]}),c&&(0,N.jsx)(`p`,{className:`wa-picker-error`,role:`alert`,children:c}),u&&(0,N.jsx)(`p`,{className:`wa-picker-empty`,children:`Loading…`}),o&&!u&&(0,N.jsxs)(`ul`,{className:`wa-picker-list`,children:[o.entries.length===0&&(0,N.jsx)(`li`,{className:`wa-picker-empty`,children:`This folder is empty.`}),o.entries.map(e=>(0,N.jsx)(`li`,{children:e.kind===`directory`?(0,N.jsxs)(`button`,{type:`button`,className:`wa-picker-row`,onClick:()=>p(e.name),children:[(0,N.jsx)(i,{size:16,"aria-hidden":!0}),(0,N.jsx)(`span`,{className:`wa-picker-name`,children:e.displayName??e.name})]}):e.kind===`file`?(0,N.jsxs)(`button`,{type:`button`,className:`wa-picker-row`,onClick:()=>g(e),children:[(0,N.jsx)(T,{size:16,"aria-hidden":!0}),(0,N.jsx)(`span`,{className:`wa-picker-name`,children:e.displayName??e.name})]}):null},e.name))]})]})})}function ye(e){return`${Math.floor(e/60)}:${String(e%60).padStart(2,`0`)}`}function F({accountId:e,remoteJid:t,sessionKey:n,replyTo:r,onClearReply:i}){let[a,o]=(0,j.useState)(``),[s,c]=(0,j.useState)(!1),[u,d]=(0,j.useState)(null),[f,p]=(0,j.useState)(!1),[h,g]=(0,j.useState)(!1),[_,v]=(0,j.useState)(!1),[y,b]=(0,j.useState)([]),x=(0,j.useRef)(null),{pendingFiles:S,attachError:ie,addFiles:C,removeFile:oe,clearFiles:w}=ge(),{state:E,elapsedSeconds:D,errorMessage:O,start:se,send:ce,discard:le}=ae(),de=E===`recording`||E===`paused`,fe=(0,j.useCallback)(()=>{console.info(`[operator-ui] op=voice-record state=start ms=0`),se()},[se]),pe=(0,j.useCallback)(async()=>{let e=D*1e3,t=await ce();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`;C([new File([t],`voice-note${e}`,{type:t.type})])}},[D,ce,C]),he=(0,j.useCallback)(()=>{console.info(`[operator-ui] op=voice-record state=cancel ms=${D*1e3}`),le()},[D,le]),A=(0,j.useRef)(!1),M=()=>Math.round((typeof window>`u`?900:window.innerHeight)/3),[F,I]=(0,j.useState)(null),[be,xe]=(0,j.useState)(null),Se=(0,j.useRef)(null),Ce=(0,j.useRef)(44),L=(0,j.useCallback)(e=>{let t=Se.current;if(!t)return;t.moved=!0;let n=Math.min(M(),Math.max(44,t.startH+(t.startY-e.clientY)));Ce.current=n,I(n)},[]),R=(0,j.useCallback)(()=>{let e=Se.current?.moved??!1;Se.current=null,window.removeEventListener(`pointermove`,L),window.removeEventListener(`pointerup`,R),e&&console.info(`[operator-ui] op=wa-composer-resize mode=drag h=${Ce.current}`)},[L]),we=(0,j.useCallback)(e=>{Se.current={startY:e.clientY,startH:x.current?.offsetHeight??44,moved:!1},window.addEventListener(`pointermove`,L),window.addEventListener(`pointerup`,R),e.preventDefault()},[L,R]),Te=(0,j.useCallback)(e=>{let t=F??x.current?.offsetHeight??44,n=null;e.key===`ArrowUp`?(e.preventDefault(),n=Math.min(M(),t+24)):e.key===`ArrowDown`&&(e.preventDefault(),n=Math.max(44,t-24)),n!==null&&(I(n),console.info(`[operator-ui] op=wa-composer-resize mode=key h=${n}`))},[F]),z=(0,j.useRef)(``);(0,j.useEffect)(()=>{let e=x.current;if(!e)return;let t=z.current!==``&&a===``;if(z.current=a,F!==null){t&&I(null);return}let n=e.style.height;e.style.height=`auto`;let r=Math.min(M(),Math.max(44,e.scrollHeight));e.style.height=n,xe(r)},[a,F]);let Ee=(a.trim().length>0||S.length>0||y.length>0)&&!s,De=(0,j.useCallback)(async()=>{if(!A.current&&!(a.trim().length===0&&S.length===0&&y.length===0)){A.current=!0,c(!0),d(null);try{let s=`/api/whatsapp-reader/reply?session_key=${encodeURIComponent(n)}`,c;if(S.length>0||y.length>0){let n=new FormData;n.append(`accountId`,e),n.append(`remoteJid`,t),a.trim()&&n.append(`text`,a);for(let e of S)n.append(`files`,e);for(let e of y)n.append(`fileRefs`,e.path);r&&n.append(`quotedId`,r.msgKeyId),c=await fetch(s,{method:`POST`,body:n})}else c=await fetch(s,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({accountId:e,remoteJid:t,text:a,...r?{quotedId:r.msgKeyId}:{}})});let l=await c.json().catch(()=>({}));if(!c.ok){d(l.error??`Send failed.`),console.info(`[operator-ui] op=reply-fail remoteJid=${t} error=${l.error??`unknown`}`);return}o(``),w(),b([]),i?.(),console.info(`[operator-ui] op=reply-sent remoteJid=${t} sent=${l.sent??0}`)}catch(e){d(`Could not reach the server. Try again.`),console.info(`[operator-ui] op=reply-fail remoteJid=${t} error=${String(e)}`)}finally{A.current=!1,c(!1)}}},[a,S,y,r,i,e,t,n,w]),Oe=(0,j.useCallback)(e=>{let t=x.current,{value:n,caret:r}=_e(a,e,t?t.selectionStart:null,t?t.selectionEnd:null);o(n),p(!1),requestAnimationFrame(()=>{let e=x.current;e&&(e.focus(),e.setSelectionRange(r,r))})},[a]),ke=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Ee&&De())},B=e=>e.dataTransfer.types.includes(`Files`),V=(0,j.useCallback)(e=>{B(e)&&(e.preventDefault(),v(!0))},[]),Ae=(0,j.useCallback)(()=>v(!1),[]),je=(0,j.useCallback)(e=>{if(!B(e))return;e.preventDefault(),v(!1);let t=[...e.dataTransfer.files];if(t.length===0)return;let n=Math.max(0,S.length+t.length-5);console.info(`[operator-ui] op=composer-drop count=${t.length} rejected=${n}`),C(t)},[S.length,C]),H=e=>e.startsWith(`image/`)?(0,N.jsx)(ue,{size:14}):e===`application/pdf`?(0,N.jsx)(T,{size:14}):(0,N.jsx)(ne,{size:14});return(0,N.jsxs)(`div`,{className:`wa-reply${_?` wa-reply-drag-over`:``}`,onDragOver:V,onDragLeave:Ae,onDrop:je,children:[h&&(0,N.jsx)(ve,{sessionKey:n,onPick:e=>{b(t=>[...t,e].slice(0,5)),g(!1)},onClose:()=>g(!1)}),f&&(0,N.jsx)(P,{onSelect:Oe}),u&&(0,N.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:u}),ie&&(0,N.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:ie}),E===`error`&&O&&(0,N.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:O}),(S.length>0||y.length>0)&&(0,N.jsxs)(`div`,{className:`wa-reply-attachments`,children:[S.map((e,t)=>(0,N.jsxs)(`div`,{className:`wa-reply-chip`,children:[H(e.type),(0,N.jsx)(`span`,{className:`wa-reply-chip-name`,children:e.name}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>oe(t),"aria-label":`Remove ${e.name}`,children:(0,N.jsx)(m,{size:12})})]},`f-${t}`)),y.map((e,t)=>(0,N.jsxs)(`div`,{className:`wa-reply-chip wa-reply-chip-ref`,children:[(0,N.jsx)(T,{size:14}),(0,N.jsx)(`span`,{className:`wa-reply-chip-name`,children:e.name}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>b(e=>e.filter((e,n)=>n!==t)),"aria-label":`Remove ${e.name}`,children:(0,N.jsx)(m,{size:12})})]},`r-${t}`))]}),r&&(0,N.jsxs)(`div`,{className:`wa-reply-quote`,children:[(0,N.jsxs)(`div`,{className:`wa-reply-quote-body`,children:[(0,N.jsx)(`span`,{className:`wa-reply-quote-who`,children:r.fromMe?`You`:r.senderName??`Contact`}),(0,N.jsx)(`span`,{className:`wa-reply-quote-text`,children:r.body||`Message`})]}),(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-quote-cancel`,onClick:()=>i?.(),"aria-label":`Cancel reply`,children:(0,N.jsx)(m,{size:14})})]}),!de&&(0,N.jsx)(`div`,{className:`wa-reply-resize-handle`,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Resize input — drag up to enlarge`,tabIndex:0,onPointerDown:we,onKeyDown:Te}),(0,N.jsx)(`div`,{className:`wa-reply-row`,children:de?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-attach`,onClick:he,"aria-label":`Cancel recording`,children:(0,N.jsx)(l,{size:20})}),(0,N.jsxs)(`span`,{className:`wa-rec-live`,role:`status`,children:[(0,N.jsx)(`span`,{className:`wa-rec-dot`,"aria-hidden":!0}),ye(D)]}),(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-send`,onClick:()=>void pe(),"aria-label":`Stop recording`,children:(0,N.jsx)(ee,{size:20})})]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-emoji`,onClick:()=>p(e=>!e),disabled:s,"aria-label":`Emoji`,"aria-expanded":f,children:(0,N.jsx)(me,{size:22})}),(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-attach`,onClick:()=>g(!0),disabled:s,"aria-label":`Attach files`,children:(0,N.jsx)(te,{size:22})}),(0,N.jsx)(`textarea`,{ref:x,className:`wa-reply-input`,value:a,rows:1,style:{height:`${F??be??44}px`},placeholder:`Type a message`,disabled:s,onChange:e=>o(e.target.value),onKeyDown:ke}),(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-mic`,onClick:()=>void fe(),disabled:s,"aria-label":`Record voice note`,children:(0,N.jsx)(re,{size:22})}),(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-send`,onClick:()=>void De(),disabled:!Ee,"aria-label":`Send`,children:(0,N.jsx)(k,{size:20})})]})})]})}function I({accountId:e,remoteJid:t,contactName:n,sessionKey:r,onBack:i}){let a=f(t),o=t.split(`@`)[0],s=a?`Group`:n===`+${o}`?void 0:`+${o}`,[c,l]=(0,j.useState)(!1),[u,d]=(0,j.useState)(``),p=()=>{l(!1),d(``)},[h,g]=(0,j.useState)(null);return(0,N.jsxs)(`div`,{className:`wa-web`,children:[(0,N.jsxs)(`header`,{className:`wa-web-header`,children:[i&&(0,N.jsx)(`button`,{type:`button`,className:`wa-web-back`,onClick:i,"aria-label":`Back`,children:(0,N.jsx)(w,{size:20})}),(0,N.jsx)(`span`,{className:`wa-web-avatar`,"aria-hidden":!0,children:(0,N.jsx)(A,{size:20})}),c?(0,N.jsxs)(`div`,{className:`wa-web-search`,children:[(0,N.jsx)(E,{size:18,"aria-hidden":!0}),(0,N.jsx)(`input`,{className:`wa-web-search-input`,type:`text`,autoFocus:!0,placeholder:`Search messages`,"aria-label":`Search messages`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Escape`&&p()}}),(0,N.jsx)(`button`,{type:`button`,className:`wa-web-search-close`,onClick:p,"aria-label":`Close search`,children:(0,N.jsx)(m,{size:18})})]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`wa-web-titles`,children:[(0,N.jsx)(`span`,{className:`wa-web-name`,children:n}),s&&(0,N.jsx)(`span`,{className:`wa-web-subtitle`,children:s})]}),(0,N.jsx)(`button`,{type:`button`,className:`wa-web-search-toggle`,onClick:()=>l(!0),"aria-label":`Search messages`,children:(0,N.jsx)(E,{size:20})})]})]}),(0,N.jsx)(`div`,{className:`wa-web-body`,children:(0,N.jsx)(oe,{sessionId:``,projectDir:``,sessionKey:r,forceDeliveredOnly:!0,suppressDirectives:!0,store:{accountId:e,remoteJid:t},search:c?u:void 0,onReplyTo:a?void 0:g})}),a?(0,N.jsx)(`p`,{className:`wa-reply wa-reply-readonly`,children:`Group messages are read-only.`}):(0,N.jsx)(F,{accountId:e,remoteJid:t,sessionKey:r,replyTo:h,onClearReply:()=>g(null)})]})}function be(e){let t=new Set,n=[];for(let r of e)for(let e of r.labels)e&&(t.has(e)||D.has(e)&&(t.add(e),n.push(e)));return n}function xe(e,t,n=`data`){let r=`/api/admin/files/download?session_key=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`+(n===`data`?``:`&root=${encodeURIComponent(n)}`),i=document.createElement(`a`);i.href=r,i.rel=`noopener noreferrer`,document.body.appendChild(i),i.click(),i.remove()}function Se(e,t){let n=new URLSearchParams;n.set(`session_key`,e);for(let e of t)n.append(`path`,e);let r=document.createElement(`a`);r.href=`/api/admin/files/download-zip?${n.toString()}`,r.rel=`noopener noreferrer`,document.body.appendChild(r),r.click(),r.remove()}function Ce(e,t,n=`data`){return`/api/admin/files/download?session_key=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}&disposition=inline`+(n===`data`?``:`&root=${encodeURIComponent(n)}`)}function L(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 R({conversations:e,sessionKey:t,onBack:n}){let[r,i]=(0,j.useState)(null),a=h(e);return r?r.source===`store`&&r.accountId&&r.remoteJid?(0,N.jsx)(I,{accountId:r.accountId,remoteJid:r.remoteJid,contactName:u(r),sessionKey:t,onBack:()=>i(null)},v(r)):(0,N.jsxs)(`div`,{className:`op-conv op-conv-reader`,children:[(0,N.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,N.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:()=>i(null),"aria-label":`Back to conversations`,children:[(0,N.jsx)(w,{size:16}),` Back`]}),(0,N.jsx)(`span`,{className:`op-conv-title`,children:u(r)})]}),(0,N.jsx)(oe,{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},v(r))]}):(0,N.jsxs)(`div`,{className:`op-conv op-conv-list`,children:[(0,N.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,N.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:n,"aria-label":`Back to chat`,children:[(0,N.jsx)(w,{size:16}),` Chat`]}),(0,N.jsx)(`span`,{className:`op-conv-title`,children:`Conversations`})]}),a.map(e=>(0,N.jsxs)(`div`,{className:`op-conv-group`,children:[(0,N.jsxs)(`div`,{className:`op-conv-group-head`,children:[(0,N.jsx)(b,{channel:e.channel,size:14}),e.label]}),e.rows.map(e=>(0,N.jsxs)(`button`,{type:`button`,className:`op-conv-row`,onClick:()=>{console.info(`[operator-ui] op=reader-open channel=${e.channel} key=${v(e)} readonly=true source=${e.source}`),i(e)},children:[(0,N.jsx)(`span`,{className:`op-conv-name`,children:u(e)}),e.modelGated&&(0,N.jsx)(`span`,{className:`op-conv-gated`,role:`img`,"aria-label":`Model unavailable`,children:(0,N.jsx)(O,{size:13})}),(0,N.jsx)(`span`,{className:`op-conv-when`,children:L(e.lastMessageAt)})]},v(e)))]},e.channel))]})}var we=/\.(png|jpe?g|gif|webp|svg)$/i;function Te(e){return we.test(e)}function z(e){return e.entryPath??e.name}var Ee=`maxy-data-view`,De=95*1024*1024,Oe=48*1024*1024;function ke(){return typeof window>`u`?`list`:window.localStorage.getItem(Ee)===`grid`?`grid`:`list`}function B(){let[e,t]=(0,j.useState)(null),[r,i]=(0,j.useState)(!1);return(0,j.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!n){t(null),i(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!0))}),()=>{e=!0}},[]),r?e?(0,N.jsx)(_,{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,N.jsx)(`div`,{className:`data-page data-page-full`,children:(0,N.jsx)(V,{cacheKey:e})})}):(0,N.jsx)(`div`,{className:`data-page`,children:(0,N.jsxs)(`div`,{className:`data-empty`,children:[(0,N.jsx)(`p`,{children:`You are not signed in.`}),(0,N.jsxs)(`p`,{children:[`Open the `,(0,N.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,N.jsx)(n,{surface:`gate`})}function V({cacheKey:e}){let{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}=c({initialCacheKey:e,surface:`data`});return(0,N.jsx)(Fe,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r})}function Ae(){if(typeof window>`u`)return`@home`;let e=new URLSearchParams(window.location.hash.replace(/^#/,``)).get(`path`);return e&&e.length>0?e:`@home`}function je(e){if(typeof window>`u`)return;let t=new URL(window.location.href);t.hash=e===`.`||e===`@home`?``:`path=${encodeURIComponent(e)}`,window.history.replaceState(window.history.state,``,t.toString())}function H(e){return new Promise((t,n)=>{let r=[],i=()=>e.readEntries(e=>{e.length===0?t(r):(r.push(...e),i())},n);i()})}function U(e){return new Promise((t,n)=>e.file(t,n))}async function Me(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 U(r),relpath:e});else if(r.isDirectory){let t=await H(r.createReader());n.push(...await Me(t,e))}}return n}function Ne(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 Pe({adminFetch:e,cacheKey:t,sessionRefetchNonce:r}){let[a,c]=(0,j.useState)(``),u=(0,j.useRef)(null),[f,p]=(0,j.useState)(``),[h,_]=(0,j.useState)(null),[v,y]=(0,j.useState)(`hybrid`),[b,ee]=(0,j.useState)(!1),[te,ne]=(0,j.useState)(null),[S,re]=(0,j.useState)(null),[ie,ae]=(0,j.useState)(0),[C,oe]=(0,j.useState)(!1),[w,D]=(0,j.useState)(()=>Ae()),[O,ue]=(0,j.useState)(null),[k,me]=(0,j.useState)(()=>ke()),[A,ge]=(0,j.useState)(null),[M,_e]=(0,j.useState)([]),[P,ve]=(0,j.useState)(null),[ye,F]=(0,j.useState)(0),[I,L]=(0,j.useState)(null),R=(0,j.useRef)(null),we=M.slice(0,-1).map(e=>e.name).join(`/`),B=(()=>{let e=M.map(e=>e.name);return e.length>=2&&e[0]===`accounts`?`${e[0]}/${e[1]}`:null})(),V=P?we:w,H=(0,j.useCallback)(e=>V===`.`||V===``?e:`${V}/${e}`,[V]),[U,Pe]=(0,j.useState)(!1),[Fe,Ie]=(0,j.useState)(!1),[ze,Be]=(0,j.useState)(null),[Ve,We]=(0,j.useState)(!1),[W,G]=(0,j.useState)(null),[Ge,Ke]=(0,j.useState)(null),[qe,Je]=(0,j.useState)(null),[Ye,Xe]=(0,j.useState)(!1),[Ze,Qe]=(0,j.useState)(null),$e=(0,j.useRef)(null),[et,tt]=(0,j.useState)(0),[nt,rt]=(0,j.useState)(!1),[it,at]=(0,j.useState)(``),[ot,st]=(0,j.useState)(null),[ct,lt]=(0,j.useState)(``),[ut,dt]=(0,j.useState)(null),K=(()=>{let e=w===`.`?[]:w.split(`/`).filter(Boolean);return e.some(e=>e.startsWith(`@`))?!1:e.length>=2&&e[0]===`accounts`})(),[ft,pt]=(0,j.useState)(!1),mt=(0,j.useRef)(null),[ht,q]=(0,j.useState)(!1),gt=(0,j.useRef)(null);(0,j.useEffect)(()=>{let e=a.trim();if(!e){p(``),_(null),ne(null);return}oe(!1);let t=setTimeout(()=>p(e),300);return()=>clearTimeout(t)},[a]),(0,j.useEffect)(()=>{if(!f){ee(!1);return}let t=!1;return ee(!0),ne(null),e(`/api/admin/graph-search?q=${encodeURIComponent(f)}&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||(_(e.results),y(e.mode??`hybrid`),ae(typeof e.suppressed==`number`?e.suppressed:0))}).catch(e=>{t||ne(e instanceof Error?e.message:String(e))}).finally(()=>{t||ee(!1)}),()=>{t=!0}},[f,e,r,C]);let _t=(0,j.useMemo)(()=>h?be(h):[],[h]),vt=S&&_t.includes(S)?S:null,yt=(0,j.useMemo)(()=>h?vt?h.filter(e=>e.labels.includes(vt)):h:null,[h,vt]),bt=(0,j.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,j.useEffect)(()=>{if(!h)return;let e=h.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(`,`)}`)},[h]),(0,j.useEffect)(()=>{let t=!1;return Pe(!0),Be(null),e(`/api/admin/files?path=${encodeURIComponent(w===`.`?``:w)}`).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||(ue(e.entries),_e(e.displayPath??[]),ve(e.view??null),F(typeof e.systemCount==`number`?e.systemCount:0))}).catch(e=>{t||(ue([]),_e([]),ve(null),F(0),Be(e instanceof Error?e.message:String(e)))}).finally(()=>{t||(Pe(!1),Ie(!0))}),()=>{t=!0}},[e,w,et,r]),(0,j.useEffect)(()=>{if(P!==null||!B||R.current===B)return;R.current=B;let t=!1;return e(`/api/admin/files?path=${encodeURIComponent(`${B}/@home`)}`).then(e=>e.ok?e.json():null).then(e=>{t||!e||L((e.entries??[]).map(e=>e.name))}).catch(e=>{console.warn(`[data-ui] op=rail-buckets status=error reason="${e instanceof Error?e.message:String(e)}"`)}),()=>{t=!0}},[e,P,B]),(0,j.useEffect)(()=>{je(w)},[w]);let xt=(0,j.useCallback)(()=>{tt(e=>e+1)},[]),J=(0,j.useCallback)(e=>{pt(!1),D(e)},[]),St=(0,j.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}`),c(``),ne(null),re(null),J(r)},[J]),Ct=(0,j.useCallback)(()=>{if(!w.split(`/`).some(e=>e.startsWith(`@`))){if(w===`.`||w===``)return;let e=w.split(`/`).filter(Boolean);e.pop(),D(e.length===0?`.`:e.join(`/`));return}M.length!==0&&D(M.length>=2?M.slice(0,M.length-1).map(e=>e.name).join(`/`):`.`)},[w,M]),wt=(0,j.useCallback)(e=>{xe(t,H(z(e)))},[H,t]),[Y,Tt]=(0,j.useState)(!1),[X,Et]=(0,j.useState)(new Set),Dt=(0,j.useRef)(null),Z=(0,j.useRef)(!1),Ot=typeof navigator<`u`&&typeof navigator.share==`function`&&typeof navigator.canShare==`function`,kt=(0,j.useCallback)(e=>{Tt(!0),Et(new Set([e])),console.info(`[data-ui] op=select-enter count=1`)},[]),Q=(0,j.useCallback)(e=>{Tt(!1),Et(new Set),console.info(`[data-ui] op=select-exit reason=${e}`)},[]),At=(0,j.useCallback)(e=>{Et(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),jt=(0,j.useCallback)(e=>{Z.current=!1,Dt.current=setTimeout(()=>{Z.current=!0,kt(e)},500)},[kt]),$=(0,j.useCallback)(()=>{Dt.current&&=(clearTimeout(Dt.current),null)},[]),Mt=(0,j.useCallback)(e=>{if(Z.current){Z.current=!1;return}if(Y){At(e.name);return}wt(e)},[Y,At,wt]),Nt=(0,j.useCallback)(e=>{me(e),typeof window<`u`&&window.localStorage.setItem(Ee,e),console.info(`[data] op=view-mode mode=${e}`)},[]),Pt=(0,j.useCallback)(e=>{if(Z.current){Z.current=!1;return}if(Y){At(e.name);return}ge({src:Ce(t,H(z(e))),alt:e.displayName??e.name})},[Y,At,H,t]),Ft=(0,j.useCallback)(()=>(O??[]).filter(e=>e.kind===`file`&&X.has(e.name)),[O,X]),It=(0,j.useCallback)(()=>{if(X.size!==1)return null;let e=(O??[]).find(e=>X.has(e.name));return e&&!e.entryPath?e:null},[O,X]),Lt=(0,j.useCallback)(()=>(O??[]).filter(e=>(e.kind===`file`||e.kind===`directory`)&&X.has(e.name)),[O,X]),Rt=(0,j.useCallback)(()=>{let e=Lt(),n=e.some(e=>e.kind===`directory`);e.length===1&&!n?wt(e[0]):e.length>=1&&Se(t,e.map(e=>H(z(e)))),Q(`action`)},[Lt,wt,H,t,Q]),zt=(0,j.useCallback)(async()=>{let t=Ft(),n=t.filter(e=>!e.protected),r=t.length-n.length;Qe(r>0?`${r} protected file(s) kept`:null);for(let t of n){let n=H(z(t));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){Qe(e instanceof Error?e.message:String(e))}}tt(e=>e+1),Q(`action`)},[Ft,H,e,Q]),Bt=(0,j.useCallback)(async()=>{let e=Ft();if(console.info(`[data-ui] op=share supported=${Ot} count=${e.length}`),Ot)try{let n=await Promise.all(e.map(async e=>{let n=H(z(e)),r=`/api/admin/files/download?session_key=${encodeURIComponent(t)}&path=${encodeURIComponent(n)}`,i=await(await fetch(r)).blob();return new File([i],e.displayName??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)}`)}},[Ft,Ot,H,t]),Vt=(0,j.useCallback)(()=>{$e.current?.click()},[]),Ht=(0,j.useCallback)((e,n={})=>{let r=(r,i,a)=>{let o=new URLSearchParams({session_key:t,path:w===`.`?``:w,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<=De)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/Oe);return(async()=>{let t={status:0,data:{}};for(let o=0;o<a;o++){let s=o*Oe;if(t=await r(e.slice(s,Math.min(s+Oe,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,w]),Ut=(0,j.useCallback)(async e=>{Ke(null),We(!0),G({loaded:0,total:e.size});try{let{status:t,data:n}=await Ht(e,{onProgress:(e,t)=>G({loaded:e,total:t})});t>=200&&t<300&&n.path?(D(n.path.split(`/`).slice(0,-1).join(`/`)||`.`),tt(e=>e+1)):Ke(t===0?`Network error during upload — the connection failed before the server responded.`:n.error??`Upload failed (HTTP ${t}).`)}finally{We(!1),G(null),$e.current&&($e.current.value=``)}},[Ht]),Wt=(0,j.useCallback)(e=>{K&&Array.from(e.dataTransfer.types).includes(`Files`)&&(e.preventDefault(),Xe(!0))},[K]),Gt=(0,j.useCallback)(e=>{e.currentTarget.contains(e.relatedTarget)||Xe(!1)},[]),Kt=(0,j.useCallback)(async e=>{e.preventDefault(),Xe(!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(!K){console.info(`[data-ui] op=drop-rejected token=${t} reason=no-write`),Ke(`Open a folder inside your account to upload`);return}let r=n.map(e=>e.webkitGetAsEntry?.()).filter(e=>!!e);We(!0),Ke(null),Je(null);let i=performance.now();try{let e=await Me(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}`),G({loaded:0,total:r.size});let{status:a,data:c}=await Ht(r,{relpath:i,token:t,onProgress:(e,t)=>G({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`:Ne(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}`),Je(`Uploaded ${o}, skipped ${s.length}${s.length?`: ${s.join(`, `)}`:``}`),tt(e=>e+1)}catch(e){Ke(e instanceof Error?e.message:String(e))}finally{We(!1),G(null)}},[K,Ht]),qt=(0,j.useCallback)(async()=>{let t=it.trim();if(t){dt(null);try{let n=await e(`/api/admin/files/folder`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:w===`.`?``:w,name:t})}),r=await n.json().catch(()=>({error:`HTTP ${n.status}`}));if(!n.ok)throw Error(r.error??`HTTP ${n.status}`);rt(!1),at(``),tt(e=>e+1)}catch(e){dt(e instanceof Error?e.message:String(e))}}},[e,it,w]),Jt=(0,j.useCallback)(async()=>{if(!ot)return;let t=ct.trim();if(!t)return;dt(null);let n=H(ot);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}`);st(null),lt(``),Q(`action`),tt(e=>e+1)}catch(e){dt(e instanceof Error?e.message:String(e))}},[e,ct,ot,H,Q]);(0,j.useEffect)(()=>{if(!ft)return;let e=e=>{mt.current&&!mt.current.contains(e.target)&&pt(!1)},t=e=>{e.key===`Escape`&&pt(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[ft]),(0,j.useEffect)(()=>{if(!ht)return;let e=e=>{gt.current&&!gt.current.contains(e.target)&&q(!1)},t=e=>{e.key===`Escape`&&q(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[ht]);let Yt=(0,j.useCallback)(e=>M.slice(0,e+1).map(e=>e.name).join(`/`),[M]),Xt=M.length>=2,Zt=Xt?[{name:`.`,label:`data`},...M.slice(0,M.length-2).map((e,t)=>({name:Yt(t),label:e.displayName??e.name}))]:[];return Fe?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`data-toolbar`,children:[Y?(0,N.jsxs)(`button`,{type:`button`,className:`data-select-cancel`,onClick:()=>Q(`cancel`),"aria-label":`Cancel selection`,children:[(0,N.jsx)(m,{size:14}),` Cancel`]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`data-search-input`,children:[a===``&&(0,N.jsx)(E,{size:14}),(0,N.jsx)(`input`,{ref:u,type:`text`,value:a,onChange:e=>c(e.target.value),autoFocus:!0,autoComplete:`off`,spellCheck:!1}),b&&(0,N.jsx)(s,{size:14,className:`spin`}),a!==``&&(0,N.jsx)(`button`,{type:`button`,className:`data-search-inline-btn`,onClick:()=>{c(``),u.current?.focus()},title:`Clear search`,"aria-label":`Clear search`,children:(0,N.jsx)(m,{size:14})})]}),(0,N.jsxs)(`div`,{className:`data-toolbar-actions`,ref:gt,children:[(0,N.jsx)(`button`,{type:`button`,className:`data-action-overflow`,onClick:()=>q(e=>!e),"aria-haspopup":`menu`,"aria-expanded":ht,"aria-label":`File actions`,title:`File actions`,children:(0,N.jsx)(ce,{size:16})}),(0,N.jsxs)(`div`,{className:`data-action-group`,role:`group`,"aria-label":`File actions`,"data-open":ht?`true`:void 0,children:[(0,N.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{xt(),q(!1)},disabled:U,title:`Refresh this folder`,"aria-label":`Refresh this folder`,children:[U?(0,N.jsx)(s,{size:16,className:`spin`}):(0,N.jsx)(d,{size:16}),(0,N.jsx)(`span`,{className:`data-action-label`,children:`Refresh`})]}),(0,N.jsxs)(`button`,{type:`button`,className:`data-action-btn admin-btn-cta`,onClick:()=>{Vt(),q(!1)},disabled:Ve||!K,title:K?`Upload a file`:`Open a folder inside your account to upload`,"aria-label":`Upload a file`,children:[Ve?W&&W.total>0?(0,N.jsxs)(`span`,{className:`data-upload-pct`,children:[Math.round(W.loaded/W.total*100),`%`]}):(0,N.jsx)(s,{size:16,className:`spin`}):(0,N.jsx)(he,{size:16}),(0,N.jsx)(`span`,{className:`data-action-label`,children:`Upload`})]}),(0,N.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{rt(e=>!e),at(``),dt(null),q(!1)},disabled:Ve||!K,title:K?`New folder`:`Open a folder inside your account to create one`,"aria-label":`New folder`,children:[(0,N.jsx)(le,{size:16}),(0,N.jsx)(`span`,{className:`data-action-label`,children:`New folder`})]}),(0,N.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{Nt(k===`grid`?`list`:`grid`),q(!1)},title:k===`grid`?`List view`:`Grid view`,"aria-label":k===`grid`?`Switch to list view`:`Switch to grid view`,"aria-pressed":k===`grid`,children:[k===`grid`?(0,N.jsx)(fe,{size:16}):(0,N.jsx)(de,{size:16}),(0,N.jsx)(`span`,{className:`data-action-label`,children:k===`grid`?`List view`:`Grid view`})]})]})]})]}),(0,N.jsxs)(`div`,{className:`data-breadcrumbs`,children:[w!==`.`&&(0,N.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost data-back-btn`,onClick:Ct,title:`Up one level`,"aria-label":`Up one level`,children:(0,N.jsx)(se,{size:14})}),Xt?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`span`,{className:`data-crumb-wrap`,ref:mt,children:[(0,N.jsx)(`button`,{type:`button`,className:`data-crumb data-crumb-ellipsis`,onClick:()=>pt(e=>!e),"aria-haspopup":`menu`,"aria-expanded":ft,"aria-label":`Show parent folders`,title:`Show parent folders`,children:`…`}),ft&&(0,N.jsx)(`div`,{className:`data-crumb-menu`,role:`menu`,children:Zt.map(e=>(0,N.jsx)(`button`,{type:`button`,role:`menuitem`,className:`data-crumb-menu-item`,onClick:()=>J(e.name),title:e.label,children:e.label},e.name))})]}),[M.length-2,M.length-1].map(e=>{let t=M[e];return(0,N.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,N.jsx)(`span`,{className:`data-crumb-sep`,children:`›`}),(0,N.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>J(Yt(e)),title:t.name,children:t.displayName??t.name})]},Yt(e))})]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>J(`.`),children:`data`}),M.map((e,t)=>(0,N.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,N.jsx)(`span`,{className:`data-crumb-sep`,children:`›`}),(0,N.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>J(Yt(t)),title:e.name,children:e.displayName??e.name})]},Yt(t)))]})]}),nt&&(0,N.jsxs)(`div`,{className:`data-inline-form`,children:[(0,N.jsx)(`input`,{type:`text`,className:`data-inline-input`,placeholder:`Folder name`,value:it,autoFocus:!0,onChange:e=>at(e.target.value),onKeyDown:e=>{e.key===`Enter`&&qt(),e.key===`Escape`&&rt(!1)}}),(0,N.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:qt,children:`Create`}),(0,N.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost`,onClick:()=>rt(!1),children:`Cancel`})]}),ot&&(0,N.jsxs)(`div`,{className:`data-inline-form`,children:[(0,N.jsx)(`input`,{type:`text`,className:`data-inline-input`,placeholder:`New name`,value:ct,autoFocus:!0,onChange:e=>lt(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Jt(),e.key===`Escape`&&st(null)}}),(0,N.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:Jt,children:`Rename`}),(0,N.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost`,onClick:()=>st(null),children:`Cancel`})]}),ut&&(0,N.jsx)(`div`,{className:`data-error`,children:ut}),(0,N.jsx)(`input`,{type:`file`,ref:$e,hidden:!0,onChange:e=>{let t=e.target.files?.[0];t&&Ut(t)}})]}),(0,N.jsxs)(`div`,{className:`data-body`,"data-drag-active":Ye?`true`:void 0,onDragEnter:Wt,onDragOver:Wt,onDragLeave:Gt,onDrop:Kt,children:[P===null&&B&&I&&I.length>0&&(0,N.jsxs)(`aside`,{className:`data-rail`,"aria-label":`Folders`,children:[(0,N.jsx)(`span`,{className:`data-rail-label`,children:`Folders`}),(0,N.jsx)(`ul`,{className:`data-rail-list`,children:I.map(e=>{let t=`${B}/${e}`,n=w===t||w.startsWith(`${t}/`);return(0,N.jsx)(`li`,{children:(0,N.jsxs)(`button`,{type:`button`,className:`data-rail-item`,"aria-current":n?`true`:void 0,onClick:()=>J(t),children:[(0,N.jsx)(i,{size:13}),(0,N.jsx)(`span`,{className:`data-rail-item-name`,children:e})]})},e)})})]}),(0,N.jsxs)(`div`,{className:`data-content`,children:[(te!==null||h!==null)&&(0,N.jsxs)(`section`,{className:`data-panel admin-card`,children:[te&&(0,N.jsxs)(`div`,{className:`data-error`,children:[`Search failed: `,te]}),_t.length>0&&(0,N.jsx)(`div`,{className:`data-chip-row`,role:`group`,"aria-label":`Filter by type`,children:_t.map(e=>{let t=e===vt;return(0,N.jsx)(`button`,{type:`button`,className:`data-chip`,"data-active":t,onClick:()=>re(t?null:e),children:Re([e])??e},e)})}),h&&!b&&(0,N.jsxs)(`div`,{className:`data-results-meta`,children:[yt.length,` of `,h.length,` result`,h.length===1?``:`s`]}),h&&!b&&!vt&&ie>0&&!C&&(0,N.jsxs)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>oe(!0),children:[ie,` low-confidence result`,ie===1?``:`s`,` hidden — show all`]}),h&&!b&&!vt&&C&&(0,N.jsx)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>oe(!1),children:`Showing all results — hide low-confidence`}),h&&h.length===0&&!b&&(0,N.jsx)(`div`,{className:`data-empty-results`,children:`No matches. Try a different keyword.`}),yt&&yt.length>0&&(0,N.jsx)(`ul`,{className:`data-results`,children:yt.map(e=>(0,N.jsx)(Le,{hit:e,mode:v,onDownload:bt,onLocate:St},e.nodeId))})]}),(0,N.jsxs)(`section`,{className:`data-panel data-panel--wide admin-card`,children:[W&&(0,N.jsxs)(`div`,{className:`data-upload-progress`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":W.total>0?Math.round(W.loaded/W.total*100):void 0,children:[(0,N.jsx)(`div`,{className:`data-upload-progress-track`,children:(0,N.jsx)(`div`,{className:`data-upload-progress-fill`,style:{width:`${W.total>0?Math.round(W.loaded/W.total*100):0}%`}})}),(0,N.jsxs)(`span`,{className:`data-upload-progress-label`,children:[`Uploading… `,W.total>0?`${Math.round(W.loaded/W.total*100)}%`:``]})]}),Ge&&(0,N.jsxs)(`div`,{className:`data-error`,children:[`Upload failed: `,Ge]}),qe&&(0,N.jsx)(`div`,{className:`data-status`,children:qe}),Ze&&(0,N.jsxs)(`div`,{className:`data-error`,children:[`Delete failed: `,Ze]}),ze&&(0,N.jsx)(`div`,{className:`data-error`,children:ze}),U&&(0,N.jsxs)(`div`,{className:`data-loading`,children:[(0,N.jsx)(s,{size:14,className:`spin`}),` Loading…`]}),!Y&&!U&&P!==`home`&&O&&O.length>0&&(0,N.jsxs)(`div`,{className:`data-select-hint`,children:[(0,N.jsx)(pe,{size:13}),(0,N.jsx)(`span`,{children:`Press and hold a file to select, rename, or delete it.`})]}),!U&&P!==`home`&&O&&O.length===0&&!ze&&(0,N.jsx)(`div`,{className:`data-empty-results`,children:`Empty directory.`}),!U&&P===`home`&&O&&(0,N.jsxs)(`ul`,{className:`routine-list data-home-list`,children:[O.map(e=>(0,N.jsxs)(`li`,{className:`data-home-card`,children:[(0,N.jsxs)(`button`,{type:`button`,className:`data-home-card-head`,onClick:()=>J(H(e.name)),children:[(0,N.jsx)(`span`,{className:`data-home-card-title`,children:e.name}),(0,N.jsx)(`span`,{className:`data-home-card-count`,children:e.childCount===null||e.childCount===void 0?`—`:`${e.childCount} ${e.childCount===1?`item`:`items`}`})]}),(0,N.jsxs)(`ul`,{className:`data-home-card-children`,children:[e.childCount===null&&(0,N.jsx)(`li`,{className:`data-home-card-error`,children:`Could not read this folder.`}),e.childCount===0&&(0,N.jsx)(`li`,{className:`data-home-card-empty`,children:`Empty.`}),(e.children??[]).map(e=>(0,N.jsxs)(`li`,{className:`data-home-card-child`,children:[e.kind===`directory`?(0,N.jsx)(i,{size:12}):(0,N.jsx)(T,{size:12}),(0,N.jsx)(`span`,{className:`data-home-card-child-name`,children:e.name})]},e.name)),typeof e.childCount==`number`&&e.childCount>(e.children?.length??0)&&(0,N.jsxs)(`li`,{className:`data-home-card-more`,children:[`+`,e.childCount-(e.children?.length??0),` more`]})]})]},e.name)),(0,N.jsxs)(`li`,{className:`data-home-card`,children:[(0,N.jsxs)(`button`,{type:`button`,className:`data-home-card-head`,onClick:()=>J(H(`@system`)),children:[(0,N.jsx)(`span`,{className:`data-home-card-title`,children:`system`}),(0,N.jsxs)(`span`,{className:`data-home-card-count`,children:[ye,` `,ye===1?`item`:`items`]})]}),(0,N.jsx)(`ul`,{className:`data-home-card-children`,children:(0,N.jsx)(`li`,{className:`data-home-card-empty`,children:`Platform and plugin folders.`})})]})]}),!U&&P!==`home`&&O&&O.length>0&&k===`grid`&&(0,N.jsx)(`ul`,{className:`data-grid`,children:O.map(e=>{let n=e.displayName??e.name,r=Y&&X.has(e.name);if(e.kind===`directory`)return(0,N.jsx)(`li`,{className:`data-grid-cell`,"data-selected":r?`true`:void 0,children:(0,N.jsxs)(`button`,{type:`button`,className:`data-grid-tile`,onPointerDown:()=>jt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>{if(Z.current){Z.current=!1;return}if(Y){At(e.name);return}J(H(e.name))},children:[Y&&(0,N.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,N.jsx)(i,{size:28,className:`data-grid-glyph`}),(0,N.jsx)(`span`,{className:`data-grid-label`,title:e.name,children:n})]})},e.name);if(e.kind===`file`){let i=Te(z(e)),a=H(z(e));return(0,N.jsx)(`li`,{className:`data-grid-cell`,"data-selected":r?`true`:void 0,children:(0,N.jsxs)(`button`,{type:`button`,className:`data-grid-tile${i?` data-grid-tile-image`:``}`,onPointerDown:()=>jt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>i?Pt(e):Mt(e),title:Y?void 0:i?`Preview ${n}`:`Download ${n}`,children:[Y&&(0,N.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),i?(0,N.jsx)(`img`,{className:`data-grid-thumb`,src:Ce(t,a),alt:n,loading:`lazy`,onError:()=>console.warn(`[data] op=thumb-error path=${a}`)}):(0,N.jsx)(T,{size:28,className:`data-grid-glyph`}),(0,N.jsx)(`span`,{className:`data-grid-label`,title:e.name,children:n}),!i&&(0,N.jsx)(`span`,{className:`data-grid-sub`,children:He(e.sizeBytes)})]})},e.name)}return(0,N.jsx)(`li`,{className:`data-grid-cell`,children:(0,N.jsxs)(`div`,{className:`data-grid-tile data-entry-disabled`,children:[(0,N.jsx)(T,{size:28,className:`data-grid-glyph`}),(0,N.jsx)(`span`,{className:`data-grid-label`,children:n}),(0,N.jsx)(`span`,{className:`data-grid-sub`,children:`special`})]})},e.name)})}),!U&&P!==`home`&&O&&O.length>0&&k===`list`&&(0,N.jsx)(`ul`,{className:`data-entries`,children:O.map(e=>{let t=e.displayName??e.name;if(e.kind===`directory`){let n=Y&&X.has(e.name);return(0,N.jsx)(`li`,{className:`data-entry`,"data-selected":n?`true`:void 0,children:(0,N.jsxs)(`button`,{type:`button`,className:`data-entry-btn`,onPointerDown:()=>jt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>{if(Z.current){Z.current=!1;return}if(Y){At(e.name);return}J(H(e.name))},children:[Y&&(0,N.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,N.jsx)(i,{size:14}),(0,N.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t})]})},e.name)}if(e.kind===`file`){let n=Y&&X.has(e.name);return(0,N.jsx)(`li`,{className:`data-entry`,"data-selected":n?`true`:void 0,children:(0,N.jsxs)(`button`,{type:`button`,className:`data-entry-btn data-entry-file`,onPointerDown:()=>jt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>Mt(e),title:Y?void 0:`Download ${t}`,children:[Y&&(0,N.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,N.jsxs)(`span`,{className:`data-entry-text`,children:[(0,N.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t}),(0,N.jsxs)(`span`,{className:`data-entry-meta`,title:`Modified ${Ue(e.modifiedAt)}`,children:[He(e.sizeBytes),` · `,Ue(e.modifiedAt)]})]})]})},e.name)}return(0,N.jsx)(`li`,{className:`data-entry`,children:(0,N.jsx)(`div`,{className:`data-entry-btn data-entry-file data-entry-disabled`,children:(0,N.jsxs)(`span`,{className:`data-entry-text`,children:[(0,N.jsx)(`span`,{className:`data-entry-name`,children:t}),(0,N.jsx)(`span`,{className:`data-entry-meta`,children:`special`})]})})},e.name)})})]})]})]}),Y&&(0,N.jsx)(`div`,{className:`data-select-bar`,role:`toolbar`,"aria-label":`Selection actions`,children:(0,N.jsxs)(`div`,{className:`data-select-bar-inner`,children:[(0,N.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:Bt,disabled:!Ot||X.size===0,title:Ot?`Share selected files`:`Sharing is not supported on this device`,children:[(0,N.jsx)(x,{size:16}),` Share`]}),(0,N.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:Rt,disabled:X.size===0,children:[(0,N.jsx)(g,{size:16}),` Download`]}),(0,N.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:()=>{let e=It();e&&(st(e.name),lt(e.name))},disabled:!It(),children:[(0,N.jsx)(o,{size:16}),` Rename`]}),(0,N.jsxs)(`button`,{type:`button`,className:`data-select-action data-select-delete`,onClick:zt,disabled:X.size===0,children:[(0,N.jsx)(l,{size:16}),` Delete`]})]})}),A&&(0,N.jsx)(`div`,{className:`chat-attachment-overlay`,role:`dialog`,"aria-label":A.alt,onClick:()=>ge(null),children:(0,N.jsx)(`img`,{className:`chat-attachment-overlay-image`,src:A.src,alt:A.alt})})]}):(0,N.jsx)(n,{surface:`gate`})}function Fe({adminFetch:e,cacheKey:t,sessionRefetchNonce:n}){(0,j.useEffect)(()=>{console.info(`[data-ui] op=mount header=operator home=absent`)},[]);let r=(0,j.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]),i=(0,j.useCallback)(e=>{e===`chat`&&(window.location.href=`/`)},[]),[a,o]=(0,j.useState)([]),[s,c]=(0,j.useState)(`files`),{subAccounts:l,activeAccountId:u,switching:d,switchAccount:f}=y(t);return(0,j.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,N.jsxs)(`main`,{className:`data-main`,children:[(0,N.jsx)(p,{variant:`operator`,onNavigate:i,onOpenConversations:a.length>0?()=>c(`conversations`):void 0,onToggleSidebar:()=>{},sidebarOpen:!1,onLogout:r,onDisconnect:async()=>!0,disconnecting:!1,subAccounts:l,activeAccountId:u,switchingAccount:d,onSwitchAccount:f}),s===`conversations`?(0,N.jsx)(R,{conversations:a,sessionKey:t,onBack:()=>c(`files`)}):(0,N.jsx)(Pe,{adminFetch:e,cacheKey:t,sessionRefetchNonce:n})]})}function Ie({cacheKey:e}){let{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}=c({initialCacheKey:e,surface:`data`});return(0,N.jsx)(`div`,{className:`data-page`,children:(0,N.jsx)(`main`,{className:`data-main`,children:(0,N.jsx)(Pe,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r})})})}function Le({hit:e,mode:t,onDownload:n,onLocate:r}){let a=ze(e.properties),o=Be(e.properties),s=Re(e.labels),c=Ve(e.properties),[l,u]=(0,j.useState)(!1),d=o&&o.length>280,f=l||!d?o:o?.slice(0,280)+`…`,p=t===`bm25`?`bm25 ${e.bm25Score.toFixed(2)}`:`vector ${e.vectorScore.toFixed(2)} · bm25 ${e.bm25Score.toFixed(2)} · combined ${e.score.toFixed(2)}`,m=e.properties.relativePath,h=typeof m==`string`&&m.length>0,g=h?m.lastIndexOf(`/`):-1,_=h?g===-1?`data`:m.slice(0,g):null;return(0,N.jsxs)(`li`,{className:`data-result`,children:[(0,N.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 ${a??s??`file`}`,children:[s&&(0,N.jsx)(`div`,{className:`data-result-header`,children:(0,N.jsx)(`span`,{className:`data-result-labels`,children:s})}),a&&(0,N.jsx)(`div`,{className:`data-result-title`,children:a}),o&&(0,N.jsx)(`pre`,{className:`data-result-body`,children:f}),(0,N.jsxs)(`div`,{className:`data-result-scores`,children:[c&&(0,N.jsxs)(`span`,{className:`data-result-updated`,children:[`Updated `,Ue(c),` · `]}),p]})]}),h&&(0,N.jsxs)(`button`,{type:`button`,className:`data-result-locate`,onClick:()=>r(e),title:`Locate in ${_}`,"aria-label":`Locate in ${_}`,children:[(0,N.jsx)(i,{size:12}),_]}),d&&(0,N.jsx)(`button`,{type:`button`,className:`data-result-toggle`,onClick:()=>u(e=>!e),children:l?`Show less`:`Show more`})]})}function Re(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 ze(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 Be(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 Ve(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 He(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 Ue(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{A as a,I as i,Ie as n,xe as r,B as t};
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,F as n,K as r,O as i,P as a,S as o,T as s,U as c,_ as l,a as u,b as d,c as f,d as p,g as m,i as h,k as g,p as _,s as v,t as y,u as b,v as ee,x as te,y as x}from"./useSubAccountSwitcher-DH0P6QMV.js";import{C as ne,E as S,S as re,T as ie,n as ae,r as C,s as oe}from"./useVoiceRecorder-MuZ7lpet.js";import{t as w}from"./chevron-left-Ux9-qLkk.js";import{t as T}from"./file-text-DkvKqHMx.js";import{i as E,t as D}from"./graph-labels-BJ7puQkX.js";import{t as O}from"./triangle-alert-D-bSbPnX.js";var se=a(`arrow-left`,[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]),ce=a(`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=a(`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=a(`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=a(`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=a(`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=a(`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`}]]),k=a(`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`}]]),me=a(`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=a(`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`}]]),A=a(`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`}]]),j=e(r(),1);function ge(){let[e,t]=(0,j.useState)([]),[n,r]=(0,j.useState)(!1),[i,a]=(0,j.useState)(null),o=(0,j.useRef)(null),s=(0,j.useCallback)(e=>{a(null);let n=e.find(e=>!C(e.type,S));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>ie);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,j.useCallback)(()=>{t([]),a(null)},[]),removeFile:(0,j.useCallback)(e=>{t(t=>t.filter((t,n)=>n!==e))},[]),onDragOver:(0,j.useCallback)(e=>{e.preventDefault(),r(!0)},[]),onDragLeave:(0,j.useCallback)(()=>{r(!1)},[]),onDrop:(0,j.useCallback)(e=>{e.preventDefault(),r(!1),s([...e.dataTransfer.files])},[s])}}var M=[[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 _e(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 N=t();function P({onSelect:e}){return(0,N.jsx)(`div`,{className:`wa-emoji-popover`,role:`menu`,"aria-label":`Emoji picker`,children:M.map((t,n)=>(0,N.jsx)(`button`,{type:`button`,role:`menuitem`,className:`wa-emoji-item`,onClick:()=>e(t),children:t},n))})}function ve({sessionKey:e,onPick:t,onClose:n}){let[r,a]=(0,j.useState)(``),[o,s]=(0,j.useState)(null),[c,l]=(0,j.useState)(null),[u,d]=(0,j.useState)(!1),f=(0,j.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,j.useEffect)(()=>{f(``)},[f]);let p=e=>f(r?`${r}/${e}`:e),h=()=>{let e=r.split(`/`).filter(Boolean);e.pop(),f(e.join(`/`))},g=e=>{let n=e.entryPath??e.name;t({path:r?`${r}/${n}`:n,name:e.displayName??e.name})};return(0,N.jsx)(`div`,{className:`wa-picker-backdrop`,role:`dialog`,"aria-label":`Choose a device file`,onClick:n,children:(0,N.jsxs)(`div`,{className:`wa-picker`,onClick:e=>e.stopPropagation(),children:[(0,N.jsxs)(`div`,{className:`wa-picker-head`,children:[r&&(0,N.jsx)(`button`,{type:`button`,className:`wa-picker-icon-btn`,onClick:h,"aria-label":`Up one folder`,children:(0,N.jsx)(w,{size:18})}),(0,N.jsx)(`span`,{className:`wa-picker-title`,children:r||`Device storage`}),(0,N.jsx)(`button`,{type:`button`,className:`wa-picker-icon-btn`,onClick:n,"aria-label":`Close file picker`,children:(0,N.jsx)(m,{size:18})})]}),c&&(0,N.jsx)(`p`,{className:`wa-picker-error`,role:`alert`,children:c}),u&&(0,N.jsx)(`p`,{className:`wa-picker-empty`,children:`Loading…`}),o&&!u&&(0,N.jsxs)(`ul`,{className:`wa-picker-list`,children:[o.entries.length===0&&(0,N.jsx)(`li`,{className:`wa-picker-empty`,children:`This folder is empty.`}),o.entries.map(e=>(0,N.jsx)(`li`,{children:e.kind===`directory`?(0,N.jsxs)(`button`,{type:`button`,className:`wa-picker-row`,onClick:()=>p(e.name),children:[(0,N.jsx)(i,{size:16,"aria-hidden":!0}),(0,N.jsx)(`span`,{className:`wa-picker-name`,children:e.displayName??e.name})]}):e.kind===`file`?(0,N.jsxs)(`button`,{type:`button`,className:`wa-picker-row`,onClick:()=>g(e),children:[(0,N.jsx)(T,{size:16,"aria-hidden":!0}),(0,N.jsx)(`span`,{className:`wa-picker-name`,children:e.displayName??e.name})]}):null},e.name))]})]})})}function ye(e){return`${Math.floor(e/60)}:${String(e%60).padStart(2,`0`)}`}function F({accountId:e,remoteJid:t,sessionKey:n,replyTo:r,onClearReply:i}){let[a,o]=(0,j.useState)(``),[s,c]=(0,j.useState)(!1),[u,d]=(0,j.useState)(null),[f,p]=(0,j.useState)(!1),[h,g]=(0,j.useState)(!1),[_,v]=(0,j.useState)(!1),[y,b]=(0,j.useState)([]),x=(0,j.useRef)(null),{pendingFiles:S,attachError:ie,addFiles:C,removeFile:oe,clearFiles:w}=ge(),{state:E,elapsedSeconds:D,errorMessage:O,start:se,send:ce,discard:le}=ae(),de=E===`recording`||E===`paused`,fe=(0,j.useCallback)(()=>{console.info(`[operator-ui] op=voice-record state=start ms=0`),se()},[se]),pe=(0,j.useCallback)(async()=>{let e=D*1e3,t=await ce();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`;C([new File([t],`voice-note${e}`,{type:t.type})])}},[D,ce,C]),he=(0,j.useCallback)(()=>{console.info(`[operator-ui] op=voice-record state=cancel ms=${D*1e3}`),le()},[D,le]),A=(0,j.useRef)(!1),M=()=>Math.round((typeof window>`u`?900:window.innerHeight)/3),[F,I]=(0,j.useState)(null),[be,xe]=(0,j.useState)(null),Se=(0,j.useRef)(null),Ce=(0,j.useRef)(44),L=(0,j.useCallback)(e=>{let t=Se.current;if(!t)return;t.moved=!0;let n=Math.min(M(),Math.max(44,t.startH+(t.startY-e.clientY)));Ce.current=n,I(n)},[]),R=(0,j.useCallback)(()=>{let e=Se.current?.moved??!1;Se.current=null,window.removeEventListener(`pointermove`,L),window.removeEventListener(`pointerup`,R),e&&console.info(`[operator-ui] op=wa-composer-resize mode=drag h=${Ce.current}`)},[L]),we=(0,j.useCallback)(e=>{Se.current={startY:e.clientY,startH:x.current?.offsetHeight??44,moved:!1},window.addEventListener(`pointermove`,L),window.addEventListener(`pointerup`,R),e.preventDefault()},[L,R]),Te=(0,j.useCallback)(e=>{let t=F??x.current?.offsetHeight??44,n=null;e.key===`ArrowUp`?(e.preventDefault(),n=Math.min(M(),t+24)):e.key===`ArrowDown`&&(e.preventDefault(),n=Math.max(44,t-24)),n!==null&&(I(n),console.info(`[operator-ui] op=wa-composer-resize mode=key h=${n}`))},[F]),z=(0,j.useRef)(``);(0,j.useEffect)(()=>{let e=x.current;if(!e)return;let t=z.current!==``&&a===``;if(z.current=a,F!==null){t&&I(null);return}let n=e.style.height;e.style.height=`auto`;let r=Math.min(M(),Math.max(44,e.scrollHeight));e.style.height=n,xe(r)},[a,F]);let Ee=(a.trim().length>0||S.length>0||y.length>0)&&!s,De=(0,j.useCallback)(async()=>{if(!A.current&&!(a.trim().length===0&&S.length===0&&y.length===0)){A.current=!0,c(!0),d(null);try{let s=`/api/whatsapp-reader/reply?session_key=${encodeURIComponent(n)}`,c;if(S.length>0||y.length>0){let n=new FormData;n.append(`accountId`,e),n.append(`remoteJid`,t),a.trim()&&n.append(`text`,a);for(let e of S)n.append(`files`,e);for(let e of y)n.append(`fileRefs`,e.path);r&&n.append(`quotedId`,r.msgKeyId),c=await fetch(s,{method:`POST`,body:n})}else c=await fetch(s,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({accountId:e,remoteJid:t,text:a,...r?{quotedId:r.msgKeyId}:{}})});let l=await c.json().catch(()=>({}));if(!c.ok){d(l.error??`Send failed.`),console.info(`[operator-ui] op=reply-fail remoteJid=${t} error=${l.error??`unknown`}`);return}o(``),w(),b([]),i?.(),console.info(`[operator-ui] op=reply-sent remoteJid=${t} sent=${l.sent??0}`)}catch(e){d(`Could not reach the server. Try again.`),console.info(`[operator-ui] op=reply-fail remoteJid=${t} error=${String(e)}`)}finally{A.current=!1,c(!1)}}},[a,S,y,r,i,e,t,n,w]),Oe=(0,j.useCallback)(e=>{let t=x.current,{value:n,caret:r}=_e(a,e,t?t.selectionStart:null,t?t.selectionEnd:null);o(n),p(!1),requestAnimationFrame(()=>{let e=x.current;e&&(e.focus(),e.setSelectionRange(r,r))})},[a]),ke=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Ee&&De())},B=e=>e.dataTransfer.types.includes(`Files`),V=(0,j.useCallback)(e=>{B(e)&&(e.preventDefault(),v(!0))},[]),Ae=(0,j.useCallback)(()=>v(!1),[]),je=(0,j.useCallback)(e=>{if(!B(e))return;e.preventDefault(),v(!1);let t=[...e.dataTransfer.files];if(t.length===0)return;let n=Math.max(0,S.length+t.length-5);console.info(`[operator-ui] op=composer-drop count=${t.length} rejected=${n}`),C(t)},[S.length,C]),H=e=>e.startsWith(`image/`)?(0,N.jsx)(ue,{size:14}):e===`application/pdf`?(0,N.jsx)(T,{size:14}):(0,N.jsx)(ne,{size:14});return(0,N.jsxs)(`div`,{className:`wa-reply${_?` wa-reply-drag-over`:``}`,onDragOver:V,onDragLeave:Ae,onDrop:je,children:[h&&(0,N.jsx)(ve,{sessionKey:n,onPick:e=>{b(t=>[...t,e].slice(0,5)),g(!1)},onClose:()=>g(!1)}),f&&(0,N.jsx)(P,{onSelect:Oe}),u&&(0,N.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:u}),ie&&(0,N.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:ie}),E===`error`&&O&&(0,N.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:O}),(S.length>0||y.length>0)&&(0,N.jsxs)(`div`,{className:`wa-reply-attachments`,children:[S.map((e,t)=>(0,N.jsxs)(`div`,{className:`wa-reply-chip`,children:[H(e.type),(0,N.jsx)(`span`,{className:`wa-reply-chip-name`,children:e.name}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>oe(t),"aria-label":`Remove ${e.name}`,children:(0,N.jsx)(m,{size:12})})]},`f-${t}`)),y.map((e,t)=>(0,N.jsxs)(`div`,{className:`wa-reply-chip wa-reply-chip-ref`,children:[(0,N.jsx)(T,{size:14}),(0,N.jsx)(`span`,{className:`wa-reply-chip-name`,children:e.name}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>b(e=>e.filter((e,n)=>n!==t)),"aria-label":`Remove ${e.name}`,children:(0,N.jsx)(m,{size:12})})]},`r-${t}`))]}),r&&(0,N.jsxs)(`div`,{className:`wa-reply-quote`,children:[(0,N.jsxs)(`div`,{className:`wa-reply-quote-body`,children:[(0,N.jsx)(`span`,{className:`wa-reply-quote-who`,children:r.fromMe?`You`:r.senderName??`Contact`}),(0,N.jsx)(`span`,{className:`wa-reply-quote-text`,children:r.body||`Message`})]}),(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-quote-cancel`,onClick:()=>i?.(),"aria-label":`Cancel reply`,children:(0,N.jsx)(m,{size:14})})]}),!de&&(0,N.jsx)(`div`,{className:`wa-reply-resize-handle`,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Resize input — drag up to enlarge`,tabIndex:0,onPointerDown:we,onKeyDown:Te}),(0,N.jsx)(`div`,{className:`wa-reply-row`,children:de?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-attach`,onClick:he,"aria-label":`Cancel recording`,children:(0,N.jsx)(l,{size:20})}),(0,N.jsxs)(`span`,{className:`wa-rec-live`,role:`status`,children:[(0,N.jsx)(`span`,{className:`wa-rec-dot`,"aria-hidden":!0}),ye(D)]}),(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-send`,onClick:()=>void pe(),"aria-label":`Stop recording`,children:(0,N.jsx)(ee,{size:20})})]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-emoji`,onClick:()=>p(e=>!e),disabled:s,"aria-label":`Emoji`,"aria-expanded":f,children:(0,N.jsx)(me,{size:22})}),(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-attach`,onClick:()=>g(!0),disabled:s,"aria-label":`Attach files`,children:(0,N.jsx)(te,{size:22})}),(0,N.jsx)(`textarea`,{ref:x,className:`wa-reply-input`,value:a,rows:1,style:{height:`${F??be??44}px`},placeholder:`Type a message`,disabled:s,onChange:e=>o(e.target.value),onKeyDown:ke}),(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-mic`,onClick:()=>void fe(),disabled:s,"aria-label":`Record voice note`,children:(0,N.jsx)(re,{size:22})}),(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-send`,onClick:()=>void De(),disabled:!Ee,"aria-label":`Send`,children:(0,N.jsx)(k,{size:20})})]})})]})}function I({accountId:e,remoteJid:t,contactName:n,sessionKey:r,onBack:i}){let a=f(t),o=t.split(`@`)[0],s=a?`Group`:n===`+${o}`?void 0:`+${o}`,[c,l]=(0,j.useState)(!1),[u,d]=(0,j.useState)(``),p=()=>{l(!1),d(``)},[h,g]=(0,j.useState)(null);return(0,N.jsxs)(`div`,{className:`wa-web`,children:[(0,N.jsxs)(`header`,{className:`wa-web-header`,children:[i&&(0,N.jsx)(`button`,{type:`button`,className:`wa-web-back`,onClick:i,"aria-label":`Back`,children:(0,N.jsx)(w,{size:20})}),(0,N.jsx)(`span`,{className:`wa-web-avatar`,"aria-hidden":!0,children:(0,N.jsx)(A,{size:20})}),c?(0,N.jsxs)(`div`,{className:`wa-web-search`,children:[(0,N.jsx)(E,{size:18,"aria-hidden":!0}),(0,N.jsx)(`input`,{className:`wa-web-search-input`,type:`text`,autoFocus:!0,placeholder:`Search messages`,"aria-label":`Search messages`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Escape`&&p()}}),(0,N.jsx)(`button`,{type:`button`,className:`wa-web-search-close`,onClick:p,"aria-label":`Close search`,children:(0,N.jsx)(m,{size:18})})]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`wa-web-titles`,children:[(0,N.jsx)(`span`,{className:`wa-web-name`,children:n}),s&&(0,N.jsx)(`span`,{className:`wa-web-subtitle`,children:s})]}),(0,N.jsx)(`button`,{type:`button`,className:`wa-web-search-toggle`,onClick:()=>l(!0),"aria-label":`Search messages`,children:(0,N.jsx)(E,{size:20})})]})]}),(0,N.jsx)(`div`,{className:`wa-web-body`,children:(0,N.jsx)(oe,{sessionId:``,projectDir:``,sessionKey:r,forceDeliveredOnly:!0,suppressDirectives:!0,store:{accountId:e,remoteJid:t},search:c?u:void 0,onReplyTo:a?void 0:g})}),a?(0,N.jsx)(`p`,{className:`wa-reply wa-reply-readonly`,children:`Group messages are read-only.`}):(0,N.jsx)(F,{accountId:e,remoteJid:t,sessionKey:r,replyTo:h,onClearReply:()=>g(null)})]})}function be(e){let t=new Set,n=[];for(let r of e)for(let e of r.labels)e&&(t.has(e)||D.has(e)&&(t.add(e),n.push(e)));return n}function xe(e,t,n=`data`){let r=`/api/admin/files/download?session_key=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`+(n===`data`?``:`&root=${encodeURIComponent(n)}`),i=document.createElement(`a`);i.href=r,i.rel=`noopener noreferrer`,document.body.appendChild(i),i.click(),i.remove()}function Se(e,t){let n=new URLSearchParams;n.set(`session_key`,e);for(let e of t)n.append(`path`,e);let r=document.createElement(`a`);r.href=`/api/admin/files/download-zip?${n.toString()}`,r.rel=`noopener noreferrer`,document.body.appendChild(r),r.click(),r.remove()}function Ce(e,t,n=`data`){return`/api/admin/files/download?session_key=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}&disposition=inline`+(n===`data`?``:`&root=${encodeURIComponent(n)}`)}function L(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 R({conversations:e,sessionKey:t,onBack:n}){let[r,i]=(0,j.useState)(null),a=h(e);return r?r.source===`store`&&r.accountId&&r.remoteJid?(0,N.jsx)(I,{accountId:r.accountId,remoteJid:r.remoteJid,contactName:u(r),sessionKey:t,onBack:()=>i(null)},v(r)):(0,N.jsxs)(`div`,{className:`op-conv op-conv-reader`,children:[(0,N.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,N.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:()=>i(null),"aria-label":`Back to conversations`,children:[(0,N.jsx)(w,{size:16}),` Back`]}),(0,N.jsx)(`span`,{className:`op-conv-title`,children:u(r)})]}),(0,N.jsx)(oe,{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},v(r))]}):(0,N.jsxs)(`div`,{className:`op-conv op-conv-list`,children:[(0,N.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,N.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:n,"aria-label":`Back to chat`,children:[(0,N.jsx)(w,{size:16}),` Chat`]}),(0,N.jsx)(`span`,{className:`op-conv-title`,children:`Conversations`})]}),a.map(e=>(0,N.jsxs)(`div`,{className:`op-conv-group`,children:[(0,N.jsxs)(`div`,{className:`op-conv-group-head`,children:[(0,N.jsx)(b,{channel:e.channel,size:14}),e.label]}),e.rows.map(e=>(0,N.jsxs)(`button`,{type:`button`,className:`op-conv-row`,onClick:()=>{console.info(`[operator-ui] op=reader-open channel=${e.channel} key=${v(e)} readonly=true source=${e.source}`),i(e)},children:[(0,N.jsx)(`span`,{className:`op-conv-name`,children:u(e)}),e.modelGated&&(0,N.jsx)(`span`,{className:`op-conv-gated`,role:`img`,"aria-label":`Model unavailable`,children:(0,N.jsx)(O,{size:13})}),(0,N.jsx)(`span`,{className:`op-conv-when`,children:L(e.lastMessageAt)})]},v(e)))]},e.channel))]})}var we=/\.(png|jpe?g|gif|webp|svg)$/i;function Te(e){return we.test(e)}function z(e){return e.entryPath??e.name}var Ee=`maxy-data-view`,De=95*1024*1024,Oe=48*1024*1024;function ke(){return typeof window>`u`?`list`:window.localStorage.getItem(Ee)===`grid`?`grid`:`list`}function B(){let[e,t]=(0,j.useState)(null),[r,i]=(0,j.useState)(!1);return(0,j.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!n){t(null),i(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!0))}),()=>{e=!0}},[]),r?e?(0,N.jsx)(_,{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,N.jsx)(`div`,{className:`data-page data-page-full`,children:(0,N.jsx)(V,{cacheKey:e})})}):(0,N.jsx)(`div`,{className:`data-page`,children:(0,N.jsxs)(`div`,{className:`data-empty`,children:[(0,N.jsx)(`p`,{children:`You are not signed in.`}),(0,N.jsxs)(`p`,{children:[`Open the `,(0,N.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,N.jsx)(n,{surface:`gate`})}function V({cacheKey:e}){let{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}=c({initialCacheKey:e,surface:`data`});return(0,N.jsx)(Fe,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r})}function Ae(){if(typeof window>`u`)return`@home`;let e=new URLSearchParams(window.location.hash.replace(/^#/,``)).get(`path`);return e&&e.length>0?e:`@home`}function je(e){if(typeof window>`u`)return;let t=new URL(window.location.href);t.hash=e===`.`||e===`@home`?``:`path=${encodeURIComponent(e)}`,window.history.replaceState(window.history.state,``,t.toString())}function H(e){return new Promise((t,n)=>{let r=[],i=()=>e.readEntries(e=>{e.length===0?t(r):(r.push(...e),i())},n);i()})}function U(e){return new Promise((t,n)=>e.file(t,n))}async function Me(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 U(r),relpath:e});else if(r.isDirectory){let t=await H(r.createReader());n.push(...await Me(t,e))}}return n}function Ne(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 Pe({adminFetch:e,cacheKey:t,sessionRefetchNonce:r}){let[a,c]=(0,j.useState)(``),u=(0,j.useRef)(null),[f,p]=(0,j.useState)(``),[h,_]=(0,j.useState)(null),[v,y]=(0,j.useState)(`hybrid`),[b,ee]=(0,j.useState)(!1),[te,ne]=(0,j.useState)(null),[S,re]=(0,j.useState)(null),[ie,ae]=(0,j.useState)(0),[C,oe]=(0,j.useState)(!1),[w,D]=(0,j.useState)(()=>Ae()),[O,ue]=(0,j.useState)(null),[k,me]=(0,j.useState)(()=>ke()),[A,ge]=(0,j.useState)(null),[M,_e]=(0,j.useState)([]),[P,ve]=(0,j.useState)(null),[ye,F]=(0,j.useState)(0),[I,L]=(0,j.useState)(null),R=(0,j.useRef)(null),we=M.slice(0,-1).map(e=>e.name).join(`/`),B=(()=>{let e=M.map(e=>e.name);return e.length>=2&&e[0]===`accounts`?`${e[0]}/${e[1]}`:null})(),V=P?we:w,H=(0,j.useCallback)(e=>V===`.`||V===``?e:`${V}/${e}`,[V]),[U,Pe]=(0,j.useState)(!1),[Fe,Ie]=(0,j.useState)(!1),[ze,Be]=(0,j.useState)(null),[Ve,We]=(0,j.useState)(!1),[W,G]=(0,j.useState)(null),[Ge,Ke]=(0,j.useState)(null),[qe,Je]=(0,j.useState)(null),[Ye,Xe]=(0,j.useState)(!1),[Ze,Qe]=(0,j.useState)(null),$e=(0,j.useRef)(null),[et,tt]=(0,j.useState)(0),[nt,rt]=(0,j.useState)(!1),[it,at]=(0,j.useState)(``),[ot,st]=(0,j.useState)(null),[ct,lt]=(0,j.useState)(``),[ut,dt]=(0,j.useState)(null),K=(()=>{let e=w===`.`?[]:w.split(`/`).filter(Boolean);return e.some(e=>e.startsWith(`@`))?!1:e.length>=2&&e[0]===`accounts`})(),[ft,pt]=(0,j.useState)(!1),mt=(0,j.useRef)(null),[ht,q]=(0,j.useState)(!1),gt=(0,j.useRef)(null);(0,j.useEffect)(()=>{let e=a.trim();if(!e){p(``),_(null),ne(null);return}oe(!1);let t=setTimeout(()=>p(e),300);return()=>clearTimeout(t)},[a]),(0,j.useEffect)(()=>{if(!f){ee(!1);return}let t=!1;return ee(!0),ne(null),e(`/api/admin/graph-search?q=${encodeURIComponent(f)}&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||(_(e.results),y(e.mode??`hybrid`),ae(typeof e.suppressed==`number`?e.suppressed:0))}).catch(e=>{t||ne(e instanceof Error?e.message:String(e))}).finally(()=>{t||ee(!1)}),()=>{t=!0}},[f,e,r,C]);let _t=(0,j.useMemo)(()=>h?be(h):[],[h]),vt=S&&_t.includes(S)?S:null,yt=(0,j.useMemo)(()=>h?vt?h.filter(e=>e.labels.includes(vt)):h:null,[h,vt]),bt=(0,j.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,j.useEffect)(()=>{if(!h)return;let e=h.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(`,`)}`)},[h]),(0,j.useEffect)(()=>{let t=!1;return Pe(!0),Be(null),e(`/api/admin/files?path=${encodeURIComponent(w===`.`?``:w)}`).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||(ue(e.entries),_e(e.displayPath??[]),ve(e.view??null),F(typeof e.systemCount==`number`?e.systemCount:0))}).catch(e=>{t||(ue([]),_e([]),ve(null),F(0),Be(e instanceof Error?e.message:String(e)))}).finally(()=>{t||(Pe(!1),Ie(!0))}),()=>{t=!0}},[e,w,et,r]),(0,j.useEffect)(()=>{if(P!==null||!B||R.current===B)return;R.current=B;let t=!1;return e(`/api/admin/files?path=${encodeURIComponent(`${B}/@home`)}`).then(e=>e.ok?e.json():null).then(e=>{t||!e||L((e.entries??[]).map(e=>e.name))}).catch(e=>{console.warn(`[data-ui] op=rail-buckets status=error reason="${e instanceof Error?e.message:String(e)}"`)}),()=>{t=!0}},[e,P,B]),(0,j.useEffect)(()=>{je(w)},[w]);let xt=(0,j.useCallback)(()=>{tt(e=>e+1)},[]),J=(0,j.useCallback)(e=>{pt(!1),D(e)},[]),St=(0,j.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}`),c(``),ne(null),re(null),J(r)},[J]),Ct=(0,j.useCallback)(()=>{if(!w.split(`/`).some(e=>e.startsWith(`@`))){if(w===`.`||w===``)return;let e=w.split(`/`).filter(Boolean);e.pop(),D(e.length===0?`.`:e.join(`/`));return}M.length!==0&&D(M.length>=2?M.slice(0,M.length-1).map(e=>e.name).join(`/`):`.`)},[w,M]),wt=(0,j.useCallback)(e=>{xe(t,H(z(e)))},[H,t]),[Y,Tt]=(0,j.useState)(!1),[X,Et]=(0,j.useState)(new Set),Dt=(0,j.useRef)(null),Z=(0,j.useRef)(!1),Ot=typeof navigator<`u`&&typeof navigator.share==`function`&&typeof navigator.canShare==`function`,kt=(0,j.useCallback)(e=>{Tt(!0),Et(new Set([e])),console.info(`[data-ui] op=select-enter count=1`)},[]),Q=(0,j.useCallback)(e=>{Tt(!1),Et(new Set),console.info(`[data-ui] op=select-exit reason=${e}`)},[]),At=(0,j.useCallback)(e=>{Et(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),jt=(0,j.useCallback)(e=>{Z.current=!1,Dt.current=setTimeout(()=>{Z.current=!0,kt(e)},500)},[kt]),$=(0,j.useCallback)(()=>{Dt.current&&=(clearTimeout(Dt.current),null)},[]),Mt=(0,j.useCallback)(e=>{if(Z.current){Z.current=!1;return}if(Y){At(e.name);return}wt(e)},[Y,At,wt]),Nt=(0,j.useCallback)(e=>{me(e),typeof window<`u`&&window.localStorage.setItem(Ee,e),console.info(`[data] op=view-mode mode=${e}`)},[]),Pt=(0,j.useCallback)(e=>{if(Z.current){Z.current=!1;return}if(Y){At(e.name);return}ge({src:Ce(t,H(z(e))),alt:e.displayName??e.name})},[Y,At,H,t]),Ft=(0,j.useCallback)(()=>(O??[]).filter(e=>e.kind===`file`&&X.has(e.name)),[O,X]),It=(0,j.useCallback)(()=>{if(X.size!==1)return null;let e=(O??[]).find(e=>X.has(e.name));return e&&!e.entryPath?e:null},[O,X]),Lt=(0,j.useCallback)(()=>(O??[]).filter(e=>(e.kind===`file`||e.kind===`directory`)&&X.has(e.name)),[O,X]),Rt=(0,j.useCallback)(()=>{let e=Lt(),n=e.some(e=>e.kind===`directory`);e.length===1&&!n?wt(e[0]):e.length>=1&&Se(t,e.map(e=>H(z(e)))),Q(`action`)},[Lt,wt,H,t,Q]),zt=(0,j.useCallback)(async()=>{let t=Ft(),n=t.filter(e=>!e.protected),r=t.length-n.length;Qe(r>0?`${r} protected file(s) kept`:null);for(let t of n){let n=H(z(t));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){Qe(e instanceof Error?e.message:String(e))}}tt(e=>e+1),Q(`action`)},[Ft,H,e,Q]),Bt=(0,j.useCallback)(async()=>{let e=Ft();if(console.info(`[data-ui] op=share supported=${Ot} count=${e.length}`),Ot)try{let n=await Promise.all(e.map(async e=>{let n=H(z(e)),r=`/api/admin/files/download?session_key=${encodeURIComponent(t)}&path=${encodeURIComponent(n)}`,i=await(await fetch(r)).blob();return new File([i],e.displayName??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)}`)}},[Ft,Ot,H,t]),Vt=(0,j.useCallback)(()=>{$e.current?.click()},[]),Ht=(0,j.useCallback)((e,n={})=>{let r=(r,i,a)=>{let o=new URLSearchParams({session_key:t,path:w===`.`?``:w,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<=De)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/Oe);return(async()=>{let t={status:0,data:{}};for(let o=0;o<a;o++){let s=o*Oe;if(t=await r(e.slice(s,Math.min(s+Oe,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,w]),Ut=(0,j.useCallback)(async e=>{Ke(null),We(!0),G({loaded:0,total:e.size});try{let{status:t,data:n}=await Ht(e,{onProgress:(e,t)=>G({loaded:e,total:t})});t>=200&&t<300&&n.path?(D(n.path.split(`/`).slice(0,-1).join(`/`)||`.`),tt(e=>e+1)):Ke(t===0?`Network error during upload — the connection failed before the server responded.`:n.error??`Upload failed (HTTP ${t}).`)}finally{We(!1),G(null),$e.current&&($e.current.value=``)}},[Ht]),Wt=(0,j.useCallback)(e=>{K&&Array.from(e.dataTransfer.types).includes(`Files`)&&(e.preventDefault(),Xe(!0))},[K]),Gt=(0,j.useCallback)(e=>{e.currentTarget.contains(e.relatedTarget)||Xe(!1)},[]),Kt=(0,j.useCallback)(async e=>{e.preventDefault(),Xe(!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(!K){console.info(`[data-ui] op=drop-rejected token=${t} reason=no-write`),Ke(`Open a folder inside your account to upload`);return}let r=n.map(e=>e.webkitGetAsEntry?.()).filter(e=>!!e);We(!0),Ke(null),Je(null);let i=performance.now();try{let e=await Me(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}`),G({loaded:0,total:r.size});let{status:a,data:c}=await Ht(r,{relpath:i,token:t,onProgress:(e,t)=>G({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`:Ne(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}`),Je(`Uploaded ${o}, skipped ${s.length}${s.length?`: ${s.join(`, `)}`:``}`),tt(e=>e+1)}catch(e){Ke(e instanceof Error?e.message:String(e))}finally{We(!1),G(null)}},[K,Ht]),qt=(0,j.useCallback)(async()=>{let t=it.trim();if(t){dt(null);try{let n=await e(`/api/admin/files/folder`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:w===`.`?``:w,name:t})}),r=await n.json().catch(()=>({error:`HTTP ${n.status}`}));if(!n.ok)throw Error(r.error??`HTTP ${n.status}`);rt(!1),at(``),tt(e=>e+1)}catch(e){dt(e instanceof Error?e.message:String(e))}}},[e,it,w]),Jt=(0,j.useCallback)(async()=>{if(!ot)return;let t=ct.trim();if(!t)return;dt(null);let n=H(ot);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}`);st(null),lt(``),Q(`action`),tt(e=>e+1)}catch(e){dt(e instanceof Error?e.message:String(e))}},[e,ct,ot,H,Q]);(0,j.useEffect)(()=>{if(!ft)return;let e=e=>{mt.current&&!mt.current.contains(e.target)&&pt(!1)},t=e=>{e.key===`Escape`&&pt(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[ft]),(0,j.useEffect)(()=>{if(!ht)return;let e=e=>{gt.current&&!gt.current.contains(e.target)&&q(!1)},t=e=>{e.key===`Escape`&&q(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[ht]);let Yt=(0,j.useCallback)(e=>M.slice(0,e+1).map(e=>e.name).join(`/`),[M]),Xt=M.length>=2,Zt=Xt?[{name:`.`,label:`data`},...M.slice(0,M.length-2).map((e,t)=>({name:Yt(t),label:e.displayName??e.name}))]:[];return Fe?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`data-toolbar`,children:[Y?(0,N.jsxs)(`button`,{type:`button`,className:`data-select-cancel`,onClick:()=>Q(`cancel`),"aria-label":`Cancel selection`,children:[(0,N.jsx)(m,{size:14}),` Cancel`]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`data-search-input`,children:[a===``&&(0,N.jsx)(E,{size:14}),(0,N.jsx)(`input`,{ref:u,type:`text`,value:a,onChange:e=>c(e.target.value),autoFocus:!0,autoComplete:`off`,spellCheck:!1}),b&&(0,N.jsx)(s,{size:14,className:`spin`}),a!==``&&(0,N.jsx)(`button`,{type:`button`,className:`data-search-inline-btn`,onClick:()=>{c(``),u.current?.focus()},title:`Clear search`,"aria-label":`Clear search`,children:(0,N.jsx)(m,{size:14})})]}),(0,N.jsxs)(`div`,{className:`data-toolbar-actions`,ref:gt,children:[(0,N.jsx)(`button`,{type:`button`,className:`data-action-overflow`,onClick:()=>q(e=>!e),"aria-haspopup":`menu`,"aria-expanded":ht,"aria-label":`File actions`,title:`File actions`,children:(0,N.jsx)(ce,{size:16})}),(0,N.jsxs)(`div`,{className:`data-action-group`,role:`group`,"aria-label":`File actions`,"data-open":ht?`true`:void 0,children:[(0,N.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{xt(),q(!1)},disabled:U,title:`Refresh this folder`,"aria-label":`Refresh this folder`,children:[U?(0,N.jsx)(s,{size:16,className:`spin`}):(0,N.jsx)(d,{size:16}),(0,N.jsx)(`span`,{className:`data-action-label`,children:`Refresh`})]}),(0,N.jsxs)(`button`,{type:`button`,className:`data-action-btn admin-btn-cta`,onClick:()=>{Vt(),q(!1)},disabled:Ve||!K,title:K?`Upload a file`:`Open a folder inside your account to upload`,"aria-label":`Upload a file`,children:[Ve?W&&W.total>0?(0,N.jsxs)(`span`,{className:`data-upload-pct`,children:[Math.round(W.loaded/W.total*100),`%`]}):(0,N.jsx)(s,{size:16,className:`spin`}):(0,N.jsx)(he,{size:16}),(0,N.jsx)(`span`,{className:`data-action-label`,children:`Upload`})]}),(0,N.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{rt(e=>!e),at(``),dt(null),q(!1)},disabled:Ve||!K,title:K?`New folder`:`Open a folder inside your account to create one`,"aria-label":`New folder`,children:[(0,N.jsx)(le,{size:16}),(0,N.jsx)(`span`,{className:`data-action-label`,children:`New folder`})]}),(0,N.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{Nt(k===`grid`?`list`:`grid`),q(!1)},title:k===`grid`?`List view`:`Grid view`,"aria-label":k===`grid`?`Switch to list view`:`Switch to grid view`,"aria-pressed":k===`grid`,children:[k===`grid`?(0,N.jsx)(fe,{size:16}):(0,N.jsx)(de,{size:16}),(0,N.jsx)(`span`,{className:`data-action-label`,children:k===`grid`?`List view`:`Grid view`})]})]})]})]}),(0,N.jsxs)(`div`,{className:`data-breadcrumbs`,children:[w!==`.`&&(0,N.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost data-back-btn`,onClick:Ct,title:`Up one level`,"aria-label":`Up one level`,children:(0,N.jsx)(se,{size:14})}),Xt?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`span`,{className:`data-crumb-wrap`,ref:mt,children:[(0,N.jsx)(`button`,{type:`button`,className:`data-crumb data-crumb-ellipsis`,onClick:()=>pt(e=>!e),"aria-haspopup":`menu`,"aria-expanded":ft,"aria-label":`Show parent folders`,title:`Show parent folders`,children:`…`}),ft&&(0,N.jsx)(`div`,{className:`data-crumb-menu`,role:`menu`,children:Zt.map(e=>(0,N.jsx)(`button`,{type:`button`,role:`menuitem`,className:`data-crumb-menu-item`,onClick:()=>J(e.name),title:e.label,children:e.label},e.name))})]}),[M.length-2,M.length-1].map(e=>{let t=M[e];return(0,N.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,N.jsx)(`span`,{className:`data-crumb-sep`,children:`›`}),(0,N.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>J(Yt(e)),title:t.name,children:t.displayName??t.name})]},Yt(e))})]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>J(`.`),children:`data`}),M.map((e,t)=>(0,N.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,N.jsx)(`span`,{className:`data-crumb-sep`,children:`›`}),(0,N.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>J(Yt(t)),title:e.name,children:e.displayName??e.name})]},Yt(t)))]})]}),nt&&(0,N.jsxs)(`div`,{className:`data-inline-form`,children:[(0,N.jsx)(`input`,{type:`text`,className:`data-inline-input`,placeholder:`Folder name`,value:it,autoFocus:!0,onChange:e=>at(e.target.value),onKeyDown:e=>{e.key===`Enter`&&qt(),e.key===`Escape`&&rt(!1)}}),(0,N.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:qt,children:`Create`}),(0,N.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost`,onClick:()=>rt(!1),children:`Cancel`})]}),ot&&(0,N.jsxs)(`div`,{className:`data-inline-form`,children:[(0,N.jsx)(`input`,{type:`text`,className:`data-inline-input`,placeholder:`New name`,value:ct,autoFocus:!0,onChange:e=>lt(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Jt(),e.key===`Escape`&&st(null)}}),(0,N.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:Jt,children:`Rename`}),(0,N.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost`,onClick:()=>st(null),children:`Cancel`})]}),ut&&(0,N.jsx)(`div`,{className:`data-error`,children:ut}),(0,N.jsx)(`input`,{type:`file`,ref:$e,hidden:!0,onChange:e=>{let t=e.target.files?.[0];t&&Ut(t)}})]}),(0,N.jsxs)(`div`,{className:`data-body`,"data-drag-active":Ye?`true`:void 0,onDragEnter:Wt,onDragOver:Wt,onDragLeave:Gt,onDrop:Kt,children:[P===null&&B&&I&&I.length>0&&(0,N.jsxs)(`aside`,{className:`data-rail`,"aria-label":`Folders`,children:[(0,N.jsx)(`span`,{className:`data-rail-label`,children:`Folders`}),(0,N.jsx)(`ul`,{className:`data-rail-list`,children:I.map(e=>{let t=`${B}/${e}`,n=w===t||w.startsWith(`${t}/`);return(0,N.jsx)(`li`,{children:(0,N.jsxs)(`button`,{type:`button`,className:`data-rail-item`,"aria-current":n?`true`:void 0,onClick:()=>J(t),children:[(0,N.jsx)(i,{size:13}),(0,N.jsx)(`span`,{className:`data-rail-item-name`,children:e})]})},e)})})]}),(0,N.jsxs)(`div`,{className:`data-content`,children:[(te!==null||h!==null)&&(0,N.jsxs)(`section`,{className:`data-panel admin-card`,children:[te&&(0,N.jsxs)(`div`,{className:`data-error`,children:[`Search failed: `,te]}),_t.length>0&&(0,N.jsx)(`div`,{className:`data-chip-row`,role:`group`,"aria-label":`Filter by type`,children:_t.map(e=>{let t=e===vt;return(0,N.jsx)(`button`,{type:`button`,className:`data-chip`,"data-active":t,onClick:()=>re(t?null:e),children:Re([e])??e},e)})}),h&&!b&&(0,N.jsxs)(`div`,{className:`data-results-meta`,children:[yt.length,` of `,h.length,` result`,h.length===1?``:`s`]}),h&&!b&&!vt&&ie>0&&!C&&(0,N.jsxs)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>oe(!0),children:[ie,` low-confidence result`,ie===1?``:`s`,` hidden — show all`]}),h&&!b&&!vt&&C&&(0,N.jsx)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>oe(!1),children:`Showing all results — hide low-confidence`}),h&&h.length===0&&!b&&(0,N.jsx)(`div`,{className:`data-empty-results`,children:`No matches. Try a different keyword.`}),yt&&yt.length>0&&(0,N.jsx)(`ul`,{className:`data-results`,children:yt.map(e=>(0,N.jsx)(Le,{hit:e,mode:v,onDownload:bt,onLocate:St},e.nodeId))})]}),(0,N.jsxs)(`section`,{className:`data-panel data-panel--wide admin-card`,children:[W&&(0,N.jsxs)(`div`,{className:`data-upload-progress`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":W.total>0?Math.round(W.loaded/W.total*100):void 0,children:[(0,N.jsx)(`div`,{className:`data-upload-progress-track`,children:(0,N.jsx)(`div`,{className:`data-upload-progress-fill`,style:{width:`${W.total>0?Math.round(W.loaded/W.total*100):0}%`}})}),(0,N.jsxs)(`span`,{className:`data-upload-progress-label`,children:[`Uploading… `,W.total>0?`${Math.round(W.loaded/W.total*100)}%`:``]})]}),Ge&&(0,N.jsxs)(`div`,{className:`data-error`,children:[`Upload failed: `,Ge]}),qe&&(0,N.jsx)(`div`,{className:`data-status`,children:qe}),Ze&&(0,N.jsxs)(`div`,{className:`data-error`,children:[`Delete failed: `,Ze]}),ze&&(0,N.jsx)(`div`,{className:`data-error`,children:ze}),U&&(0,N.jsxs)(`div`,{className:`data-loading`,children:[(0,N.jsx)(s,{size:14,className:`spin`}),` Loading…`]}),!Y&&!U&&P!==`home`&&O&&O.length>0&&(0,N.jsxs)(`div`,{className:`data-select-hint`,children:[(0,N.jsx)(pe,{size:13}),(0,N.jsx)(`span`,{children:`Press and hold a file to select, rename, or delete it.`})]}),!U&&P!==`home`&&O&&O.length===0&&!ze&&(0,N.jsx)(`div`,{className:`data-empty-results`,children:`Empty directory.`}),!U&&P===`home`&&O&&(0,N.jsxs)(`ul`,{className:`routine-list data-home-list`,children:[O.map(e=>(0,N.jsxs)(`li`,{className:`data-home-card`,children:[(0,N.jsxs)(`button`,{type:`button`,className:`data-home-card-head`,onClick:()=>J(H(e.name)),children:[(0,N.jsx)(`span`,{className:`data-home-card-title`,children:e.name}),(0,N.jsx)(`span`,{className:`data-home-card-count`,children:e.childCount===null||e.childCount===void 0?`—`:`${e.childCount} ${e.childCount===1?`item`:`items`}`})]}),(0,N.jsxs)(`ul`,{className:`data-home-card-children`,children:[e.childCount===null&&(0,N.jsx)(`li`,{className:`data-home-card-error`,children:`Could not read this folder.`}),e.childCount===0&&(0,N.jsx)(`li`,{className:`data-home-card-empty`,children:`Empty.`}),(e.children??[]).map(e=>(0,N.jsxs)(`li`,{className:`data-home-card-child`,children:[e.kind===`directory`?(0,N.jsx)(i,{size:12}):(0,N.jsx)(T,{size:12}),(0,N.jsx)(`span`,{className:`data-home-card-child-name`,children:e.name})]},e.name)),typeof e.childCount==`number`&&e.childCount>(e.children?.length??0)&&(0,N.jsxs)(`li`,{className:`data-home-card-more`,children:[`+`,e.childCount-(e.children?.length??0),` more`]})]})]},e.name)),(0,N.jsxs)(`li`,{className:`data-home-card`,children:[(0,N.jsxs)(`button`,{type:`button`,className:`data-home-card-head`,onClick:()=>J(H(`@system`)),children:[(0,N.jsx)(`span`,{className:`data-home-card-title`,children:`system`}),(0,N.jsxs)(`span`,{className:`data-home-card-count`,children:[ye,` `,ye===1?`item`:`items`]})]}),(0,N.jsx)(`ul`,{className:`data-home-card-children`,children:(0,N.jsx)(`li`,{className:`data-home-card-empty`,children:`Platform and plugin folders.`})})]})]}),!U&&P!==`home`&&O&&O.length>0&&k===`grid`&&(0,N.jsx)(`ul`,{className:`data-grid`,children:O.map(e=>{let n=e.displayName??e.name,r=Y&&X.has(e.name);if(e.kind===`directory`)return(0,N.jsx)(`li`,{className:`data-grid-cell`,"data-selected":r?`true`:void 0,children:(0,N.jsxs)(`button`,{type:`button`,className:`data-grid-tile`,onPointerDown:()=>jt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>{if(Z.current){Z.current=!1;return}if(Y){At(e.name);return}J(H(e.name))},children:[Y&&(0,N.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,N.jsx)(i,{size:28,className:`data-grid-glyph`}),(0,N.jsx)(`span`,{className:`data-grid-label`,title:e.name,children:n})]})},e.name);if(e.kind===`file`){let i=Te(z(e)),a=H(z(e));return(0,N.jsx)(`li`,{className:`data-grid-cell`,"data-selected":r?`true`:void 0,children:(0,N.jsxs)(`button`,{type:`button`,className:`data-grid-tile${i?` data-grid-tile-image`:``}`,onPointerDown:()=>jt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>i?Pt(e):Mt(e),title:Y?void 0:i?`Preview ${n}`:`Download ${n}`,children:[Y&&(0,N.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),i?(0,N.jsx)(`img`,{className:`data-grid-thumb`,src:Ce(t,a),alt:n,loading:`lazy`,onError:()=>console.warn(`[data] op=thumb-error path=${a}`)}):(0,N.jsx)(T,{size:28,className:`data-grid-glyph`}),(0,N.jsx)(`span`,{className:`data-grid-label`,title:e.name,children:n}),!i&&(0,N.jsx)(`span`,{className:`data-grid-sub`,children:He(e.sizeBytes)})]})},e.name)}return(0,N.jsx)(`li`,{className:`data-grid-cell`,children:(0,N.jsxs)(`div`,{className:`data-grid-tile data-entry-disabled`,children:[(0,N.jsx)(T,{size:28,className:`data-grid-glyph`}),(0,N.jsx)(`span`,{className:`data-grid-label`,children:n}),(0,N.jsx)(`span`,{className:`data-grid-sub`,children:`special`})]})},e.name)})}),!U&&P!==`home`&&O&&O.length>0&&k===`list`&&(0,N.jsx)(`ul`,{className:`data-entries`,children:O.map(e=>{let t=e.displayName??e.name;if(e.kind===`directory`){let n=Y&&X.has(e.name);return(0,N.jsx)(`li`,{className:`data-entry`,"data-selected":n?`true`:void 0,children:(0,N.jsxs)(`button`,{type:`button`,className:`data-entry-btn`,onPointerDown:()=>jt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>{if(Z.current){Z.current=!1;return}if(Y){At(e.name);return}J(H(e.name))},children:[Y&&(0,N.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,N.jsx)(i,{size:14}),(0,N.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t})]})},e.name)}if(e.kind===`file`){let n=Y&&X.has(e.name);return(0,N.jsx)(`li`,{className:`data-entry`,"data-selected":n?`true`:void 0,children:(0,N.jsxs)(`button`,{type:`button`,className:`data-entry-btn data-entry-file`,onPointerDown:()=>jt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>Mt(e),title:Y?void 0:`Download ${t}`,children:[Y&&(0,N.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,N.jsxs)(`span`,{className:`data-entry-text`,children:[(0,N.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t}),(0,N.jsxs)(`span`,{className:`data-entry-meta`,title:`Modified ${Ue(e.modifiedAt)}`,children:[He(e.sizeBytes),` · `,Ue(e.modifiedAt)]})]})]})},e.name)}return(0,N.jsx)(`li`,{className:`data-entry`,children:(0,N.jsx)(`div`,{className:`data-entry-btn data-entry-file data-entry-disabled`,children:(0,N.jsxs)(`span`,{className:`data-entry-text`,children:[(0,N.jsx)(`span`,{className:`data-entry-name`,children:t}),(0,N.jsx)(`span`,{className:`data-entry-meta`,children:`special`})]})})},e.name)})})]})]})]}),Y&&(0,N.jsx)(`div`,{className:`data-select-bar`,role:`toolbar`,"aria-label":`Selection actions`,children:(0,N.jsxs)(`div`,{className:`data-select-bar-inner`,children:[(0,N.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:Bt,disabled:!Ot||X.size===0,title:Ot?`Share selected files`:`Sharing is not supported on this device`,children:[(0,N.jsx)(x,{size:16}),` Share`]}),(0,N.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:Rt,disabled:X.size===0,children:[(0,N.jsx)(g,{size:16}),` Download`]}),(0,N.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:()=>{let e=It();e&&(st(e.name),lt(e.name))},disabled:!It(),children:[(0,N.jsx)(o,{size:16}),` Rename`]}),(0,N.jsxs)(`button`,{type:`button`,className:`data-select-action data-select-delete`,onClick:zt,disabled:X.size===0,children:[(0,N.jsx)(l,{size:16}),` Delete`]})]})}),A&&(0,N.jsx)(`div`,{className:`chat-attachment-overlay`,role:`dialog`,"aria-label":A.alt,onClick:()=>ge(null),children:(0,N.jsx)(`img`,{className:`chat-attachment-overlay-image`,src:A.src,alt:A.alt})})]}):(0,N.jsx)(n,{surface:`gate`})}function Fe({adminFetch:e,cacheKey:t,sessionRefetchNonce:n}){(0,j.useEffect)(()=>{console.info(`[data-ui] op=mount header=operator home=absent`)},[]);let r=(0,j.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]),i=(0,j.useCallback)(e=>{e===`chat`&&(window.location.href=`/`)},[]),[a,o]=(0,j.useState)([]),[s,c]=(0,j.useState)(`files`),{subAccounts:l,activeAccountId:u,switching:d,switchAccount:f}=y(t);return(0,j.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,N.jsxs)(`main`,{className:`data-main`,children:[(0,N.jsx)(p,{variant:`operator`,onNavigate:i,onOpenConversations:a.length>0?()=>c(`conversations`):void 0,onToggleSidebar:()=>{},sidebarOpen:!1,onLogout:r,onDisconnect:async()=>!0,disconnecting:!1,subAccounts:l,activeAccountId:u,switchingAccount:d,onSwitchAccount:f}),s===`conversations`?(0,N.jsx)(R,{conversations:a,sessionKey:t,onBack:()=>c(`files`)}):(0,N.jsx)(Pe,{adminFetch:e,cacheKey:t,sessionRefetchNonce:n})]})}function Ie({cacheKey:e}){let{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}=c({initialCacheKey:e,surface:`data`});return(0,N.jsx)(`div`,{className:`data-page`,children:(0,N.jsx)(`main`,{className:`data-main`,children:(0,N.jsx)(Pe,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r})})})}function Le({hit:e,mode:t,onDownload:n,onLocate:r}){let a=ze(e.properties),o=Be(e.properties),s=Re(e.labels),c=Ve(e.properties),[l,u]=(0,j.useState)(!1),d=o&&o.length>280,f=l||!d?o:o?.slice(0,280)+`…`,p=t===`bm25`?`bm25 ${e.bm25Score.toFixed(2)}`:`vector ${e.vectorScore.toFixed(2)} · bm25 ${e.bm25Score.toFixed(2)} · combined ${e.score.toFixed(2)}`,m=e.properties.relativePath,h=typeof m==`string`&&m.length>0,g=h?m.lastIndexOf(`/`):-1,_=h?g===-1?`data`:m.slice(0,g):null;return(0,N.jsxs)(`li`,{className:`data-result`,children:[(0,N.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 ${a??s??`file`}`,children:[s&&(0,N.jsx)(`div`,{className:`data-result-header`,children:(0,N.jsx)(`span`,{className:`data-result-labels`,children:s})}),a&&(0,N.jsx)(`div`,{className:`data-result-title`,children:a}),o&&(0,N.jsx)(`pre`,{className:`data-result-body`,children:f}),(0,N.jsxs)(`div`,{className:`data-result-scores`,children:[c&&(0,N.jsxs)(`span`,{className:`data-result-updated`,children:[`Updated `,Ue(c),` · `]}),p]})]}),h&&(0,N.jsxs)(`button`,{type:`button`,className:`data-result-locate`,onClick:()=>r(e),title:`Locate in ${_}`,"aria-label":`Locate in ${_}`,children:[(0,N.jsx)(i,{size:12}),_]}),d&&(0,N.jsx)(`button`,{type:`button`,className:`data-result-toggle`,onClick:()=>u(e=>!e),children:l?`Show less`:`Show more`})]})}function Re(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 ze(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 Be(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 Ve(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 He(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 Ue(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{A as a,I as i,Ie as n,xe as r,B as t};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,K as n,W as r}from"./useSubAccountSwitcher-CJKjEPNN.js";import"./useVoiceRecorder-ChnBrzbZ.js";import{C as i}from"./AdminShell-BMPEWNZk.js";import{a,c as o,i as s,o as c,r as l,s as u}from"./page-DC11gesX.js";import"./useCopyFeedback-BdUwyNpa.js";var d=r(),f=e(n(),1),p=t();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-CltuBf4Z.js";import{B as t,K as n,W as r}from"./useSubAccountSwitcher-DH0P6QMV.js";import"./useVoiceRecorder-MuZ7lpet.js";import{C as i}from"./AdminShell-DkrURZnF.js";import{a,c as o,i as s,o as c,r as l,s as u}from"./page-BoYc9c4a.js";import"./useCopyFeedback-L7L55nFl.js";var d=r(),f=e(n(),1),p=t();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 +1 @@
1
- import{P as e}from"./useSubAccountSwitcher-CJKjEPNN.js";var t=e(`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`}]]);export{t};
1
+ import{P as e}from"./useSubAccountSwitcher-DH0P6QMV.js";var t=e(`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`}]]);export{t};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,F as n,K as r,P as i,S as a,T as o,U as s,W as c,_ as l,g as u,p as d}from"./useSubAccountSwitcher-CJKjEPNN.js";import{T as f,d as p,m,t as h}from"./AdminShell-BMPEWNZk.js";import{t as g}from"./clock-Dn6FHB51.js";import{t as _}from"./wrench-Cpee3C3J.js";var v=i(`history`,[[`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`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),y=c(),b=e(r(),1);function x(e){return/^\d+$/.test(e)?Number(e):null}function S(e){let t=e.trim().split(/\s+/);if(t.length!==5)return null;let[n,r,i,a,o]=t,s=x(n),c=x(r);if(s===null||c===null||s>59||c>23||a!==`*`)return null;if(i===`*`&&o===`*`)return{frequency:`daily`,minute:s,hour:c,weekdays:[],dayOfMonth:1};if(i===`*`&&o!==`*`){let e=o.split(`,`).map(x);return e.some(e=>e===null||e>6)?null:{frequency:`weekly`,minute:s,hour:c,weekdays:e,dayOfMonth:1}}if(o===`*`&&i!==`*`){let e=x(i);return e===null||e<1||e>31?null:{frequency:`monthly`,minute:s,hour:c,weekdays:[],dayOfMonth:e}}return null}function C(e){let t=String(e.minute),n=String(e.hour);return e.frequency===`daily`?`${t} ${n} * * *`:e.frequency===`weekly`?`${t} ${n} * * ${e.weekdays.length?[...e.weekdays].sort((e,t)=>e-t).join(`,`):`*`}`:`${t} ${n} ${e.dayOfMonth} * *`}var w=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function T(e,t){if(e===`*`)return{kind:`any`,value:0,rangeStart:null,rangeEnd:null,step:1};let n=e.match(/^(\*|\d+-\d+)\/(\d+)$/);if(n){let e=Number(n[2]);if(e<1)return null;if(n[1]===`*`)return{kind:`step`,value:0,rangeStart:null,rangeEnd:null,step:e};let[r,i]=n[1].split(`-`).map(Number);return r>t||i>t||r>i?null:{kind:`step`,value:0,rangeStart:r,rangeEnd:i,step:e}}let r=e.match(/^(\d+)-(\d+)$/);if(r){let e=Number(r[1]),n=Number(r[2]);return e>t||n>t||e>n?null:{kind:`step`,value:0,rangeStart:e,rangeEnd:n,step:1}}if(/^\d+$/.test(e)){let n=Number(e);return n>t?null:{kind:`fixed`,value:n,rangeStart:null,rangeEnd:null,step:1}}return null}function E(e){return String(e).padStart(2,`0`)}function D(e){if(e===`*`)return null;let t=e.match(/^(\d+)-(\d+)$/);if(t){let e=Number(t[1]),n=Number(t[2]);return e>7||n>7||e>n?`invalid`:`${w[e%7]} to ${w[n%7]}`}let n=e.split(`,`);return n.length>0&&n.every(e=>/^\d+$/.test(e)&&Number(e)<=7)?n.map(e=>w[Number(e)%7]).join(`, `):`invalid`}function O(e){let t=e.trim().split(/\s+/);if(t.length!==5)return e;let[n,r,i,a,o]=t;if(a!==`*`||i!==`*`&&!/^\d+$/.test(i))return e;let s=T(n,59),c=T(r,23);if(!s||!c)return e;let l=D(o);if(l===`invalid`||s.kind===`step`&&s.rangeStart!==null||(s.kind===`any`&&(s={kind:`step`,value:0,rangeStart:null,rangeEnd:null,step:1}),c.kind===`step`&&c.step===1&&c.rangeStart===null&&(c={kind:`any`,value:0,rangeStart:null,rangeEnd:null,step:1}),i!==`*`&&!(s.kind===`fixed`&&c.kind===`fixed`&&o===`*`))||s.kind===`step`&&c.kind===`step`&&c.step>1)return e;let u=l?`, ${l}`:``,d=e=>e.rangeStart+Math.floor((e.rangeEnd-e.rangeStart)/e.step)*e.step;if(s.kind===`step`){let e=s.step===1?`Every minute`:`Every ${s.step} minutes`;return c.kind===`any`?`${e}${u}`:c.kind===`fixed`?`${e}, ${E(c.value)}:00 to ${E(c.value)}:59${u}`:`${e}, ${E(c.rangeStart)}:00 to ${E(d(c))}:00${u}`}if(c.kind===`step`){let e=E(s.value),t=s.value===0?``:` at :${e}`;return c.rangeStart===null?`Every ${c.step} hours${t}${u}`:c.step===1?`Hourly, ${E(c.rangeStart)}:${e} to ${E(c.rangeEnd)}:${e}${u}`:`Every ${c.step} hours, ${E(c.rangeStart)}:${e} to ${E(d(c))}:${e}${u}`}if(c.kind===`any`)return`${s.value===0?`Every hour`:`Every hour at :${E(s.value)}`}${u}`;let f=`${E(c.value)}:${E(s.value)}`;return i===`*`?l?`${l} at ${f}`:`Daily at ${f}`:`Monthly on day ${Number(i)} at ${f}`}var k=t(),A=[{value:1,label:`Mon`},{value:2,label:`Tue`},{value:3,label:`Wed`},{value:4,label:`Thu`},{value:5,label:`Fri`},{value:6,label:`Sat`},{value:0,label:`Sun`}];function j(e){return`${String(e.hour).padStart(2,`0`)}:${String(e.minute).padStart(2,`0`)}`}var M={frequency:`daily`,minute:0,hour:9,weekdays:[1],dayOfMonth:1};function N({recurrence:e,onChange:t,disabled:n}){let r=e?S(e):M,[i,a]=(0,b.useState)(r??M),[o]=(0,b.useState)(e!=null&&r==null),[s,c]=(0,b.useState)(e??``);if(o)return(0,k.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,k.jsx)(`span`,{children:`Schedule (advanced)`}),(0,k.jsx)(`input`,{type:`text`,className:`routine-raw-cron`,value:s,disabled:n,onChange:e=>{c(e.target.value),t(e.target.value)},"aria-label":`Cron expression`}),(0,k.jsx)(`span`,{className:`routine-raw-note`,children:`This routine uses an advanced schedule, edited as a raw cron expression.`})]});let l=e=>{a(e),t(C(e))},u=e=>{let t=e===`weekly`&&i.weekdays.length===0?[1]:i.weekdays;l({...i,frequency:e,weekdays:t})},d=e=>{let[t,n]=e.split(`:`);l({...i,hour:Number(t)||0,minute:Number(n)||0})},f=e=>{let t=i.weekdays.includes(e);if(t&&i.weekdays.length===1)return;let n=t?i.weekdays.filter(t=>t!==e):[...i.weekdays,e];l({...i,weekdays:n})},p=e=>l({...i,dayOfMonth:Number(e)||1});return(0,k.jsxs)(`div`,{className:`routine-sched`,children:[(0,k.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,k.jsx)(`span`,{children:`Frequency`}),(0,k.jsxs)(`select`,{value:i.frequency,disabled:n,onChange:e=>u(e.target.value),children:[(0,k.jsx)(`option`,{value:`daily`,children:`Daily`}),(0,k.jsx)(`option`,{value:`weekly`,children:`Weekly`}),(0,k.jsx)(`option`,{value:`monthly`,children:`Monthly`})]})]}),(0,k.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,k.jsx)(`span`,{children:`Time of day`}),(0,k.jsx)(`input`,{type:`time`,value:j(i),disabled:n,onChange:e=>d(e.target.value)})]}),i.frequency===`weekly`&&(0,k.jsxs)(`div`,{className:`cal-modal-field`,children:[(0,k.jsx)(`span`,{children:`Days`}),(0,k.jsx)(`div`,{className:`routine-weekdays`,children:A.map(e=>(0,k.jsx)(`button`,{type:`button`,className:`routine-weekday${i.weekdays.includes(e.value)?` routine-weekday-on`:``}`,"aria-pressed":i.weekdays.includes(e.value),disabled:n,onClick:()=>f(e.value),children:e.label},e.value))})]}),i.frequency===`monthly`&&(0,k.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,k.jsx)(`span`,{children:`Day of month`}),(0,k.jsx)(`select`,{value:i.dayOfMonth,disabled:n,onChange:e=>p(e.target.value),children:Array.from({length:31},(e,t)=>t+1).map(e=>(0,k.jsx)(`option`,{value:e,children:e},e))})]})]})}function P(e){if(!e)return`—`;let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString():e}function F({routine:e,adminFetch:t,onClose:n,onSaved:r,onDeleted:i}){let[s,c]=(0,b.useState)(!1),[d,f]=(0,b.useState)(!1),[h,y]=(0,b.useState)(null),[x,S]=(0,b.useState)(e),[C,w]=(0,b.useState)(!1),T=x.agentChannel!=null,[E,D]=(0,b.useState)(e.agentPrompt??``),[A,j]=(0,b.useState)(e.recurrence);(0,b.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!d&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[d,n]);let M=(0,b.useCallback)(()=>{let e={};return T&&E!==(x.agentPrompt??``)&&(e.agentPrompt=E),A!=null&&A!==(x.recurrence??null)&&(e.recurrence=A),e},[T,E,A,x]),F=(0,b.useCallback)(async()=>{let n=M();if(Object.keys(n).length===0){c(!1);return}f(!0),y(null);try{let i=await t(`/api/admin/routines/${encodeURIComponent(e.eventId)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(n)});if(!i.ok){let e=await i.json().catch(()=>({}));throw Error(e.error??`HTTP ${i.status}`)}let a=await i.json();S(a.routine),D(a.routine.agentPrompt??``),j(a.routine.recurrence),r(a.routine),c(!1)}catch(e){y(e instanceof Error?e.message:`Save failed`)}finally{f(!1)}},[t,M,e.eventId,r]),I=(0,b.useCallback)(async()=>{if(!d){if(!C){w(!0);return}f(!0),y(null);try{let n=await t(`/api/admin/routines/${encodeURIComponent(e.eventId)}`,{method:`DELETE`});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`HTTP ${n.status}`)}i(e.eventId)}catch(e){y(e instanceof Error?e.message:`Delete failed`),w(!1)}finally{f(!1)}}},[t,d,C,e.eventId,i]);return(0,k.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{d||n()},children:(0,k.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":s?`Edit routine`:`Routine detail`,onClick:e=>e.stopPropagation(),children:[(0,k.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,k.jsxs)(`span`,{className:`cal-modal-kind`,children:[(0,k.jsx)(p,{size:13}),` Routine`]}),(0,k.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:n,"aria-label":`Close`,autoFocus:!0,disabled:d,children:(0,k.jsx)(u,{size:16})})]}),!s&&(0,k.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,k.jsx)(`div`,{className:`cal-modal-title`,children:x.name??`Untitled routine`}),(0,k.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,k.jsx)(g,{size:14}),(0,k.jsx)(`span`,{children:x.recurrence?O(x.recurrence):`One-time`})]}),(0,k.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,k.jsxs)(`span`,{children:[`Status: `,x.eventStatus??`unknown`]})}),(0,k.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,k.jsxs)(`span`,{children:[`Next run: `,P(x.nextRun)]})}),(0,k.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,k.jsx)(v,{size:14}),(0,k.jsxs)(`span`,{children:[`Last run: `,P(x.lastTriggered),x.lastDispatchResult?` (${x.lastDispatchResult})`:``]})]}),T?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,k.jsx)(m,{size:14}),(0,k.jsxs)(`span`,{children:[x.agentChannel,` to `,x.agentDestination??`—`]})]}),(0,k.jsx)(`div`,{className:`cal-modal-row cal-modal-row-top routine-prose`,children:(0,k.jsx)(`span`,{children:x.agentPrompt??`No instruction set.`})})]}):x.actionPlugin?(0,k.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,k.jsx)(_,{size:14}),(0,k.jsxs)(`span`,{children:[x.actionPlugin,`.`,x.actionTool,x.actionArgs?` ${x.actionArgs}`:``]})]}):(0,k.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,k.jsx)(g,{size:14}),(0,k.jsx)(`span`,{children:`Scheduled trigger (no dispatch)`})]})]}),s&&(0,k.jsxs)(`div`,{className:`cal-modal-body`,children:[T&&(0,k.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,k.jsx)(`span`,{children:`Instruction`}),(0,k.jsx)(`textarea`,{className:`cal-modal-textarea`,value:E,onChange:e=>D(e.target.value),disabled:d,rows:16,placeholder:`What should the agent do when this routine fires?`})]}),(0,k.jsx)(N,{recurrence:x.recurrence,onChange:j,disabled:d})]}),h&&(0,k.jsx)(`div`,{className:`cal-modal-error`,children:h}),(0,k.jsxs)(`div`,{className:`cal-modal-actions`,children:[!s&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>{w(!1),c(!0)},disabled:d,children:[(0,k.jsx)(a,{size:14}),` Edit`]}),(0,k.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:I,disabled:d,children:[d&&C?(0,k.jsx)(o,{size:14,className:`spin`}):(0,k.jsx)(l,{size:14}),C?`Confirm delete`:`Delete`]})]}),s&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:F,disabled:d,children:[d?(0,k.jsx)(o,{size:14,className:`spin`}):null,` Save`]}),(0,k.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>{c(!1),y(null)},disabled:d,children:`Cancel`})]})]})]})})}var I=`maxy-admin-session-key`;function L(e){return e?O(e):`One-time`}function R(e){if(!e)return`—`;let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString():e}function z(){let[e,t]=(0,b.useState)(null),[r,i]=(0,b.useState)(!1),[a,o]=(0,b.useState)(void 0),[s,c]=(0,b.useState)(null),[l,u]=(0,b.useState)(void 0),[p,m]=(0,b.useState)(null),[g,_]=(0,b.useState)(null);(0,b.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(I)}catch{}if(!n){i(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem(I)}catch{}window.location.href=`/`;return}if(r.ok)try{let e=await r.json();typeof e.businessName==`string`&&o(e.businessName),e.sessionId!==void 0&&c(e.sessionId??null),_(e.role??null),u(e.userName===void 0?null:e.userName),m(e.avatar??null)}catch{}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!0))}),()=>{e=!0}},[]);let v=(0,b.useCallback)(()=>{try{sessionStorage.removeItem(I)}catch{}window.location.href=`/`},[]),[y,x]=(0,b.useState)(!1),S=(0,b.useCallback)(async()=>{x(!0);try{let e=await f();if(e){try{sessionStorage.removeItem(I)}catch{}window.location.href=`/`}return e}finally{x(!1)}},[]);return r?e?(0,k.jsx)(d,{cacheKey:e,surface:`routines`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=routines`);try{sessionStorage.removeItem(I)}catch{}window.location.href=`/`},children:(0,k.jsx)(h,{cacheKey:e,businessName:a,sessionId:s,onLogout:v,onDisconnect:S,disconnecting:y,userName:l,userAvatar:p,role:g,children:(0,k.jsx)(B,{cacheKey:e})})}):(0,k.jsx)(`div`,{className:`cal-page`,children:(0,k.jsxs)(`div`,{className:`cal-empty`,children:[(0,k.jsx)(`p`,{children:`You are not signed in.`}),(0,k.jsxs)(`p`,{children:[`Open the `,(0,k.jsx)(`a`,{href:`/`,className:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,k.jsx)(n,{surface:`gate`})}function B({cacheKey:e}){let{adminFetch:t,sessionRefetchNonce:r}=s({initialCacheKey:e,surface:`routines`}),[i,a]=(0,b.useState)([]),[c,l]=(0,b.useState)(!1),[u,d]=(0,b.useState)(!1),[f,h]=(0,b.useState)(null),[v,y]=(0,b.useState)(null),x=(0,b.useCallback)(()=>{let e=!1;return l(!0),h(null),t(`/api/admin/routines`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();a(Array.isArray(n.routines)?n.routines:[])}).catch(t=>{e||(h(t instanceof Error?t.message:`Failed to load`),a([]))}).finally(()=>{e||(l(!1),d(!0))}),()=>{e=!0}},[t]);(0,b.useEffect)(()=>x(),[x,r]);let S=(0,b.useCallback)(e=>{a(t=>t.map(t=>t.eventId===e.eventId?e:t)),y(e)},[]),C=(0,b.useCallback)(e=>{a(t=>t.filter(t=>t.eventId!==e)),y(null)},[]);return u?(0,k.jsxs)(`div`,{className:`cal-page`,children:[(0,k.jsx)(`header`,{className:`cal-header`,children:(0,k.jsxs)(`div`,{className:`cal-nav`,children:[(0,k.jsxs)(`span`,{className:`cal-range-label`,children:[(0,k.jsx)(p,{size:16}),` Routines`]}),c&&(0,k.jsx)(o,{size:16,className:`spin`})]})}),(0,k.jsxs)(`div`,{className:`cal-body`,children:[f&&(0,k.jsxs)(`div`,{className:`cal-error`,children:[`Could not load routines: `,f]}),!f&&!c&&i.length===0&&(0,k.jsx)(`div`,{className:`cal-empty`,children:(0,k.jsx)(`p`,{children:`No routines yet.`})}),(0,k.jsx)(`div`,{className:`routine-list`,children:i.map(e=>(0,k.jsxs)(`button`,{type:`button`,className:`routine-card`,onClick:()=>y(e),children:[(0,k.jsx)(`span`,{className:`routine-card-title`,children:e.name??`Untitled routine`}),(0,k.jsxs)(`span`,{className:`routine-card-sched`,children:[(0,k.jsx)(g,{size:13}),` `,L(e.recurrence)]}),(0,k.jsx)(`span`,{className:`routine-card-target`,children:e.agentChannel?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(m,{size:13}),` `,e.agentChannel,` to `,e.agentDestination??`—`]}):e.actionPlugin?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(_,{size:13}),` `,e.actionPlugin,`.`,e.actionTool]}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(g,{size:13}),` Scheduled trigger`]})}),(0,k.jsxs)(`span`,{className:`routine-card-meta`,children:[`Next: `,R(e.nextRun),` · `,e.eventStatus??`unknown`]})]},e.eventId))})]}),v&&(0,k.jsx)(F,{routine:v,adminFetch:t,onClose:()=>y(null),onSaved:S,onDeleted:C})]}):(0,k.jsx)(n,{surface:`gate`})}(0,y.createRoot)(document.getElementById(`root`)).render((0,k.jsx)(z,{}));
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,F as n,K as r,P as i,S as a,T as o,U as s,W as c,_ as l,g as u,p as d}from"./useSubAccountSwitcher-DH0P6QMV.js";import{T as f,d as p,m,t as h}from"./AdminShell-DkrURZnF.js";import{t as g}from"./clock-DhJdZRhC.js";import{t as _}from"./wrench-DUG1SZQB.js";var v=i(`history`,[[`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`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),y=c(),b=e(r(),1);function x(e){return/^\d+$/.test(e)?Number(e):null}function S(e){let t=e.trim().split(/\s+/);if(t.length!==5)return null;let[n,r,i,a,o]=t,s=x(n),c=x(r);if(s===null||c===null||s>59||c>23||a!==`*`)return null;if(i===`*`&&o===`*`)return{frequency:`daily`,minute:s,hour:c,weekdays:[],dayOfMonth:1};if(i===`*`&&o!==`*`){let e=o.split(`,`).map(x);return e.some(e=>e===null||e>6)?null:{frequency:`weekly`,minute:s,hour:c,weekdays:e,dayOfMonth:1}}if(o===`*`&&i!==`*`){let e=x(i);return e===null||e<1||e>31?null:{frequency:`monthly`,minute:s,hour:c,weekdays:[],dayOfMonth:e}}return null}function C(e){let t=String(e.minute),n=String(e.hour);return e.frequency===`daily`?`${t} ${n} * * *`:e.frequency===`weekly`?`${t} ${n} * * ${e.weekdays.length?[...e.weekdays].sort((e,t)=>e-t).join(`,`):`*`}`:`${t} ${n} ${e.dayOfMonth} * *`}var w=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function T(e,t){if(e===`*`)return{kind:`any`,value:0,rangeStart:null,rangeEnd:null,step:1};let n=e.match(/^(\*|\d+-\d+)\/(\d+)$/);if(n){let e=Number(n[2]);if(e<1)return null;if(n[1]===`*`)return{kind:`step`,value:0,rangeStart:null,rangeEnd:null,step:e};let[r,i]=n[1].split(`-`).map(Number);return r>t||i>t||r>i?null:{kind:`step`,value:0,rangeStart:r,rangeEnd:i,step:e}}let r=e.match(/^(\d+)-(\d+)$/);if(r){let e=Number(r[1]),n=Number(r[2]);return e>t||n>t||e>n?null:{kind:`step`,value:0,rangeStart:e,rangeEnd:n,step:1}}if(/^\d+$/.test(e)){let n=Number(e);return n>t?null:{kind:`fixed`,value:n,rangeStart:null,rangeEnd:null,step:1}}return null}function E(e){return String(e).padStart(2,`0`)}function D(e){if(e===`*`)return null;let t=e.match(/^(\d+)-(\d+)$/);if(t){let e=Number(t[1]),n=Number(t[2]);return e>7||n>7||e>n?`invalid`:`${w[e%7]} to ${w[n%7]}`}let n=e.split(`,`);return n.length>0&&n.every(e=>/^\d+$/.test(e)&&Number(e)<=7)?n.map(e=>w[Number(e)%7]).join(`, `):`invalid`}function O(e){let t=e.trim().split(/\s+/);if(t.length!==5)return e;let[n,r,i,a,o]=t;if(a!==`*`||i!==`*`&&!/^\d+$/.test(i))return e;let s=T(n,59),c=T(r,23);if(!s||!c)return e;let l=D(o);if(l===`invalid`||s.kind===`step`&&s.rangeStart!==null||(s.kind===`any`&&(s={kind:`step`,value:0,rangeStart:null,rangeEnd:null,step:1}),c.kind===`step`&&c.step===1&&c.rangeStart===null&&(c={kind:`any`,value:0,rangeStart:null,rangeEnd:null,step:1}),i!==`*`&&!(s.kind===`fixed`&&c.kind===`fixed`&&o===`*`))||s.kind===`step`&&c.kind===`step`&&c.step>1)return e;let u=l?`, ${l}`:``,d=e=>e.rangeStart+Math.floor((e.rangeEnd-e.rangeStart)/e.step)*e.step;if(s.kind===`step`){let e=s.step===1?`Every minute`:`Every ${s.step} minutes`;return c.kind===`any`?`${e}${u}`:c.kind===`fixed`?`${e}, ${E(c.value)}:00 to ${E(c.value)}:59${u}`:`${e}, ${E(c.rangeStart)}:00 to ${E(d(c))}:00${u}`}if(c.kind===`step`){let e=E(s.value),t=s.value===0?``:` at :${e}`;return c.rangeStart===null?`Every ${c.step} hours${t}${u}`:c.step===1?`Hourly, ${E(c.rangeStart)}:${e} to ${E(c.rangeEnd)}:${e}${u}`:`Every ${c.step} hours, ${E(c.rangeStart)}:${e} to ${E(d(c))}:${e}${u}`}if(c.kind===`any`)return`${s.value===0?`Every hour`:`Every hour at :${E(s.value)}`}${u}`;let f=`${E(c.value)}:${E(s.value)}`;return i===`*`?l?`${l} at ${f}`:`Daily at ${f}`:`Monthly on day ${Number(i)} at ${f}`}var k=t(),A=[{value:1,label:`Mon`},{value:2,label:`Tue`},{value:3,label:`Wed`},{value:4,label:`Thu`},{value:5,label:`Fri`},{value:6,label:`Sat`},{value:0,label:`Sun`}];function j(e){return`${String(e.hour).padStart(2,`0`)}:${String(e.minute).padStart(2,`0`)}`}var M={frequency:`daily`,minute:0,hour:9,weekdays:[1],dayOfMonth:1};function N({recurrence:e,onChange:t,disabled:n}){let r=e?S(e):M,[i,a]=(0,b.useState)(r??M),[o]=(0,b.useState)(e!=null&&r==null),[s,c]=(0,b.useState)(e??``);if(o)return(0,k.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,k.jsx)(`span`,{children:`Schedule (advanced)`}),(0,k.jsx)(`input`,{type:`text`,className:`routine-raw-cron`,value:s,disabled:n,onChange:e=>{c(e.target.value),t(e.target.value)},"aria-label":`Cron expression`}),(0,k.jsx)(`span`,{className:`routine-raw-note`,children:`This routine uses an advanced schedule, edited as a raw cron expression.`})]});let l=e=>{a(e),t(C(e))},u=e=>{let t=e===`weekly`&&i.weekdays.length===0?[1]:i.weekdays;l({...i,frequency:e,weekdays:t})},d=e=>{let[t,n]=e.split(`:`);l({...i,hour:Number(t)||0,minute:Number(n)||0})},f=e=>{let t=i.weekdays.includes(e);if(t&&i.weekdays.length===1)return;let n=t?i.weekdays.filter(t=>t!==e):[...i.weekdays,e];l({...i,weekdays:n})},p=e=>l({...i,dayOfMonth:Number(e)||1});return(0,k.jsxs)(`div`,{className:`routine-sched`,children:[(0,k.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,k.jsx)(`span`,{children:`Frequency`}),(0,k.jsxs)(`select`,{value:i.frequency,disabled:n,onChange:e=>u(e.target.value),children:[(0,k.jsx)(`option`,{value:`daily`,children:`Daily`}),(0,k.jsx)(`option`,{value:`weekly`,children:`Weekly`}),(0,k.jsx)(`option`,{value:`monthly`,children:`Monthly`})]})]}),(0,k.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,k.jsx)(`span`,{children:`Time of day`}),(0,k.jsx)(`input`,{type:`time`,value:j(i),disabled:n,onChange:e=>d(e.target.value)})]}),i.frequency===`weekly`&&(0,k.jsxs)(`div`,{className:`cal-modal-field`,children:[(0,k.jsx)(`span`,{children:`Days`}),(0,k.jsx)(`div`,{className:`routine-weekdays`,children:A.map(e=>(0,k.jsx)(`button`,{type:`button`,className:`routine-weekday${i.weekdays.includes(e.value)?` routine-weekday-on`:``}`,"aria-pressed":i.weekdays.includes(e.value),disabled:n,onClick:()=>f(e.value),children:e.label},e.value))})]}),i.frequency===`monthly`&&(0,k.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,k.jsx)(`span`,{children:`Day of month`}),(0,k.jsx)(`select`,{value:i.dayOfMonth,disabled:n,onChange:e=>p(e.target.value),children:Array.from({length:31},(e,t)=>t+1).map(e=>(0,k.jsx)(`option`,{value:e,children:e},e))})]})]})}function P(e){if(!e)return`—`;let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString():e}function F({routine:e,adminFetch:t,onClose:n,onSaved:r,onDeleted:i}){let[s,c]=(0,b.useState)(!1),[d,f]=(0,b.useState)(!1),[h,y]=(0,b.useState)(null),[x,S]=(0,b.useState)(e),[C,w]=(0,b.useState)(!1),T=x.agentChannel!=null,[E,D]=(0,b.useState)(e.agentPrompt??``),[A,j]=(0,b.useState)(e.recurrence);(0,b.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!d&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[d,n]);let M=(0,b.useCallback)(()=>{let e={};return T&&E!==(x.agentPrompt??``)&&(e.agentPrompt=E),A!=null&&A!==(x.recurrence??null)&&(e.recurrence=A),e},[T,E,A,x]),F=(0,b.useCallback)(async()=>{let n=M();if(Object.keys(n).length===0){c(!1);return}f(!0),y(null);try{let i=await t(`/api/admin/routines/${encodeURIComponent(e.eventId)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(n)});if(!i.ok){let e=await i.json().catch(()=>({}));throw Error(e.error??`HTTP ${i.status}`)}let a=await i.json();S(a.routine),D(a.routine.agentPrompt??``),j(a.routine.recurrence),r(a.routine),c(!1)}catch(e){y(e instanceof Error?e.message:`Save failed`)}finally{f(!1)}},[t,M,e.eventId,r]),I=(0,b.useCallback)(async()=>{if(!d){if(!C){w(!0);return}f(!0),y(null);try{let n=await t(`/api/admin/routines/${encodeURIComponent(e.eventId)}`,{method:`DELETE`});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`HTTP ${n.status}`)}i(e.eventId)}catch(e){y(e instanceof Error?e.message:`Delete failed`),w(!1)}finally{f(!1)}}},[t,d,C,e.eventId,i]);return(0,k.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{d||n()},children:(0,k.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":s?`Edit routine`:`Routine detail`,onClick:e=>e.stopPropagation(),children:[(0,k.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,k.jsxs)(`span`,{className:`cal-modal-kind`,children:[(0,k.jsx)(p,{size:13}),` Routine`]}),(0,k.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:n,"aria-label":`Close`,autoFocus:!0,disabled:d,children:(0,k.jsx)(u,{size:16})})]}),!s&&(0,k.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,k.jsx)(`div`,{className:`cal-modal-title`,children:x.name??`Untitled routine`}),(0,k.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,k.jsx)(g,{size:14}),(0,k.jsx)(`span`,{children:x.recurrence?O(x.recurrence):`One-time`})]}),(0,k.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,k.jsxs)(`span`,{children:[`Status: `,x.eventStatus??`unknown`]})}),(0,k.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,k.jsxs)(`span`,{children:[`Next run: `,P(x.nextRun)]})}),(0,k.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,k.jsx)(v,{size:14}),(0,k.jsxs)(`span`,{children:[`Last run: `,P(x.lastTriggered),x.lastDispatchResult?` (${x.lastDispatchResult})`:``]})]}),T?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,k.jsx)(m,{size:14}),(0,k.jsxs)(`span`,{children:[x.agentChannel,` to `,x.agentDestination??`—`]})]}),(0,k.jsx)(`div`,{className:`cal-modal-row cal-modal-row-top routine-prose`,children:(0,k.jsx)(`span`,{children:x.agentPrompt??`No instruction set.`})})]}):x.actionPlugin?(0,k.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,k.jsx)(_,{size:14}),(0,k.jsxs)(`span`,{children:[x.actionPlugin,`.`,x.actionTool,x.actionArgs?` ${x.actionArgs}`:``]})]}):(0,k.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,k.jsx)(g,{size:14}),(0,k.jsx)(`span`,{children:`Scheduled trigger (no dispatch)`})]})]}),s&&(0,k.jsxs)(`div`,{className:`cal-modal-body`,children:[T&&(0,k.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,k.jsx)(`span`,{children:`Instruction`}),(0,k.jsx)(`textarea`,{className:`cal-modal-textarea`,value:E,onChange:e=>D(e.target.value),disabled:d,rows:16,placeholder:`What should the agent do when this routine fires?`})]}),(0,k.jsx)(N,{recurrence:x.recurrence,onChange:j,disabled:d})]}),h&&(0,k.jsx)(`div`,{className:`cal-modal-error`,children:h}),(0,k.jsxs)(`div`,{className:`cal-modal-actions`,children:[!s&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>{w(!1),c(!0)},disabled:d,children:[(0,k.jsx)(a,{size:14}),` Edit`]}),(0,k.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:I,disabled:d,children:[d&&C?(0,k.jsx)(o,{size:14,className:`spin`}):(0,k.jsx)(l,{size:14}),C?`Confirm delete`:`Delete`]})]}),s&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:F,disabled:d,children:[d?(0,k.jsx)(o,{size:14,className:`spin`}):null,` Save`]}),(0,k.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>{c(!1),y(null)},disabled:d,children:`Cancel`})]})]})]})})}var I=`maxy-admin-session-key`;function L(e){return e?O(e):`One-time`}function R(e){if(!e)return`—`;let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString():e}function z(){let[e,t]=(0,b.useState)(null),[r,i]=(0,b.useState)(!1),[a,o]=(0,b.useState)(void 0),[s,c]=(0,b.useState)(null),[l,u]=(0,b.useState)(void 0),[p,m]=(0,b.useState)(null),[g,_]=(0,b.useState)(null);(0,b.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(I)}catch{}if(!n){i(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem(I)}catch{}window.location.href=`/`;return}if(r.ok)try{let e=await r.json();typeof e.businessName==`string`&&o(e.businessName),e.sessionId!==void 0&&c(e.sessionId??null),_(e.role??null),u(e.userName===void 0?null:e.userName),m(e.avatar??null)}catch{}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!0))}),()=>{e=!0}},[]);let v=(0,b.useCallback)(()=>{try{sessionStorage.removeItem(I)}catch{}window.location.href=`/`},[]),[y,x]=(0,b.useState)(!1),S=(0,b.useCallback)(async()=>{x(!0);try{let e=await f();if(e){try{sessionStorage.removeItem(I)}catch{}window.location.href=`/`}return e}finally{x(!1)}},[]);return r?e?(0,k.jsx)(d,{cacheKey:e,surface:`routines`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=routines`);try{sessionStorage.removeItem(I)}catch{}window.location.href=`/`},children:(0,k.jsx)(h,{cacheKey:e,businessName:a,sessionId:s,onLogout:v,onDisconnect:S,disconnecting:y,userName:l,userAvatar:p,role:g,children:(0,k.jsx)(B,{cacheKey:e})})}):(0,k.jsx)(`div`,{className:`cal-page`,children:(0,k.jsxs)(`div`,{className:`cal-empty`,children:[(0,k.jsx)(`p`,{children:`You are not signed in.`}),(0,k.jsxs)(`p`,{children:[`Open the `,(0,k.jsx)(`a`,{href:`/`,className:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,k.jsx)(n,{surface:`gate`})}function B({cacheKey:e}){let{adminFetch:t,sessionRefetchNonce:r}=s({initialCacheKey:e,surface:`routines`}),[i,a]=(0,b.useState)([]),[c,l]=(0,b.useState)(!1),[u,d]=(0,b.useState)(!1),[f,h]=(0,b.useState)(null),[v,y]=(0,b.useState)(null),x=(0,b.useCallback)(()=>{let e=!1;return l(!0),h(null),t(`/api/admin/routines`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();a(Array.isArray(n.routines)?n.routines:[])}).catch(t=>{e||(h(t instanceof Error?t.message:`Failed to load`),a([]))}).finally(()=>{e||(l(!1),d(!0))}),()=>{e=!0}},[t]);(0,b.useEffect)(()=>x(),[x,r]);let S=(0,b.useCallback)(e=>{a(t=>t.map(t=>t.eventId===e.eventId?e:t)),y(e)},[]),C=(0,b.useCallback)(e=>{a(t=>t.filter(t=>t.eventId!==e)),y(null)},[]);return u?(0,k.jsxs)(`div`,{className:`cal-page`,children:[(0,k.jsx)(`header`,{className:`cal-header`,children:(0,k.jsxs)(`div`,{className:`cal-nav`,children:[(0,k.jsxs)(`span`,{className:`cal-range-label`,children:[(0,k.jsx)(p,{size:16}),` Routines`]}),c&&(0,k.jsx)(o,{size:16,className:`spin`})]})}),(0,k.jsxs)(`div`,{className:`cal-body`,children:[f&&(0,k.jsxs)(`div`,{className:`cal-error`,children:[`Could not load routines: `,f]}),!f&&!c&&i.length===0&&(0,k.jsx)(`div`,{className:`cal-empty`,children:(0,k.jsx)(`p`,{children:`No routines yet.`})}),(0,k.jsx)(`div`,{className:`routine-list`,children:i.map(e=>(0,k.jsxs)(`button`,{type:`button`,className:`routine-card`,onClick:()=>y(e),children:[(0,k.jsx)(`span`,{className:`routine-card-title`,children:e.name??`Untitled routine`}),(0,k.jsxs)(`span`,{className:`routine-card-sched`,children:[(0,k.jsx)(g,{size:13}),` `,L(e.recurrence)]}),(0,k.jsx)(`span`,{className:`routine-card-target`,children:e.agentChannel?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(m,{size:13}),` `,e.agentChannel,` to `,e.agentDestination??`—`]}):e.actionPlugin?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(_,{size:13}),` `,e.actionPlugin,`.`,e.actionTool]}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(g,{size:13}),` Scheduled trigger`]})}),(0,k.jsxs)(`span`,{className:`routine-card-meta`,children:[`Next: `,R(e.nextRun),` · `,e.eventStatus??`unknown`]})]},e.eventId))})]}),v&&(0,k.jsx)(F,{routine:v,adminFetch:t,onClose:()=>y(null),onSaved:S,onDeleted:C})]}):(0,k.jsx)(n,{surface:`gate`})}(0,y.createRoot)(document.getElementById(`root`)).render((0,k.jsx)(z,{}));
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,D as n,F as r,K as i,T as a,U as o,W as s,_ as c,g as l,p as u}from"./useSubAccountSwitcher-CJKjEPNN.js";import{T as d,f,t as p}from"./AdminShell-BMPEWNZk.js";import{t as m}from"./file-text-DMKw3nIk.js";var h=s(),g=e(i(),1),_=t();function v({summary:e,adminFetch:t,onClose:r,onDeleted:i}){let[o,s]=(0,g.useState)(null),[u,d]=(0,g.useState)(!0),[p,h]=(0,g.useState)(null),[v,y]=(0,g.useState)(!1),[b,x]=(0,g.useState)(!1);(0,g.useEffect)(()=>{let n=!1;return d(!0),h(null),t(`/api/admin/skills/${encodeURIComponent(e.plugin)}/${encodeURIComponent(e.skill)}`).then(async e=>{if(!n){if(!e.ok)throw Error(`HTTP ${e.status}`);s((await e.json()).skill)}}).catch(e=>{n||h(e instanceof Error?e.message:`Failed to load`)}).finally(()=>{n||d(!1)}),()=>{n=!0}},[t,e.plugin,e.skill]),(0,g.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!b&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[b,r]);let S=(0,g.useCallback)(async()=>{x(!0),h(null);try{let n=await t(`/api/admin/skills/${encodeURIComponent(e.plugin)}/${encodeURIComponent(e.skill)}`,{method:`DELETE`,headers:{"content-type":`application/json`}});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`HTTP ${n.status}`)}i(e)}catch(e){h(e instanceof Error?e.message:`Delete failed`),x(!1),y(!1)}},[t,e,i]);return(0,_.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{b||r()},children:(0,_.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":`Skill detail`,onClick:e=>e.stopPropagation(),children:[(0,_.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,_.jsxs)(`span`,{className:`cal-modal-kind`,children:[(0,_.jsx)(f,{size:13}),` Skill`]}),(0,_.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:r,"aria-label":`Close`,autoFocus:!0,disabled:b,children:(0,_.jsx)(l,{size:16})})]}),(0,_.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,_.jsx)(`div`,{className:`cal-modal-title`,children:e.skill}),(0,_.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,_.jsx)(m,{size:14}),(0,_.jsx)(`span`,{children:e.plugin})]}),u&&(0,_.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,_.jsx)(a,{size:14,className:`spin`}),(0,_.jsx)(`span`,{children:`Loading…`})]}),o&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,_.jsx)(`span`,{children:o.frontmatter.description||`No description.`})}),o.frontmatter.publicEmbed&&(0,_.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,_.jsx)(n,{size:14}),(0,_.jsx)(`span`,{children:`Public embed`})]}),(0,_.jsx)(`pre`,{className:`skill-body`,children:o.body.trim()||`No body content.`}),o.references.length>0&&(0,_.jsxs)(`div`,{className:`skill-refs`,children:[(0,_.jsx)(`span`,{className:`skill-refs-label`,children:`References`}),o.references.map(e=>(0,_.jsxs)(`span`,{className:`skill-ref`,children:[(0,_.jsx)(m,{size:13}),` `,e]},e))]})]})]}),p&&(0,_.jsx)(`div`,{className:`cal-modal-error`,children:p}),(0,_.jsxs)(`div`,{className:`cal-modal-actions`,children:[!v&&(0,_.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:()=>y(!0),disabled:b||u,children:[(0,_.jsx)(c,{size:14}),` Delete`]}),v&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Delete this skill?`}),(0,_.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:S,disabled:b,children:[b?(0,_.jsx)(a,{size:14,className:`spin`}):(0,_.jsx)(c,{size:14}),` Delete`]}),(0,_.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>y(!1),disabled:b,children:`Cancel`})]})]})]})})}var y=`maxy-admin-session-key`;function b(){let[e,t]=(0,g.useState)(null),[n,i]=(0,g.useState)(!1),[a,o]=(0,g.useState)(void 0),[s,c]=(0,g.useState)(null),[l,f]=(0,g.useState)(void 0),[m,h]=(0,g.useState)(null),[v,b]=(0,g.useState)(null);(0,g.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(y)}catch{}if(!n){i(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem(y)}catch{}window.location.href=`/`;return}if(r.ok)try{let e=await r.json();typeof e.businessName==`string`&&o(e.businessName),e.sessionId!==void 0&&c(e.sessionId??null),b(e.role??null),f(e.userName===void 0?null:e.userName),h(e.avatar??null)}catch{}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!0))}),()=>{e=!0}},[]);let S=(0,g.useCallback)(()=>{try{sessionStorage.removeItem(y)}catch{}window.location.href=`/`},[]),[C,w]=(0,g.useState)(!1),T=(0,g.useCallback)(async()=>{w(!0);try{let e=await d();if(e){try{sessionStorage.removeItem(y)}catch{}window.location.href=`/`}return e}finally{w(!1)}},[]);return n?e?(0,_.jsx)(u,{cacheKey:e,surface:`skills`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=skills`);try{sessionStorage.removeItem(y)}catch{}window.location.href=`/`},children:(0,_.jsx)(p,{cacheKey:e,businessName:a,sessionId:s,onLogout:S,onDisconnect:T,disconnecting:C,userName:l,userAvatar:m,role:v,children:(0,_.jsx)(x,{cacheKey:e})})}):(0,_.jsx)(`div`,{className:`cal-page`,children:(0,_.jsxs)(`div`,{className:`cal-empty`,children:[(0,_.jsx)(`p`,{children:`You are not signed in.`}),(0,_.jsxs)(`p`,{children:[`Open the `,(0,_.jsx)(`a`,{href:`/`,className:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,_.jsx)(r,{surface:`gate`})}function x({cacheKey:e}){let{adminFetch:t,sessionRefetchNonce:n}=o({initialCacheKey:e,surface:`skills`}),[i,s]=(0,g.useState)([]),[c,l]=(0,g.useState)(!1),[u,d]=(0,g.useState)(!1),[p,h]=(0,g.useState)(null),[y,b]=(0,g.useState)(null),x=(0,g.useCallback)(()=>{let e=!1;return l(!0),h(null),t(`/api/admin/skills`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();s(Array.isArray(n.skills)?n.skills:[])}).catch(t=>{e||(h(t instanceof Error?t.message:`Failed to load`),s([]))}).finally(()=>{e||(l(!1),d(!0))}),()=>{e=!0}},[t]);(0,g.useEffect)(()=>x(),[x,n]);let S=(0,g.useCallback)(e=>{s(t=>t.filter(t=>!(t.plugin===e.plugin&&t.skill===e.skill))),b(null),x()},[x]);return u?(0,_.jsxs)(`div`,{className:`cal-page`,children:[(0,_.jsx)(`header`,{className:`cal-header`,children:(0,_.jsxs)(`div`,{className:`cal-nav`,children:[(0,_.jsxs)(`span`,{className:`cal-range-label`,children:[(0,_.jsx)(f,{size:16}),` Skills`]}),c&&(0,_.jsx)(a,{size:16,className:`spin`})]})}),(0,_.jsxs)(`div`,{className:`cal-body`,children:[p&&(0,_.jsxs)(`div`,{className:`cal-error`,children:[`Could not load skills: `,p]}),!p&&!c&&i.length===0&&(0,_.jsx)(`div`,{className:`cal-empty`,children:(0,_.jsx)(`p`,{children:`No skills yet. Ask in chat to create one.`})}),i.length>0&&(0,_.jsx)(`div`,{className:`routine-list`,children:i.map(e=>(0,_.jsxs)(`button`,{type:`button`,className:`routine-card`,onClick:()=>b(e),children:[(0,_.jsx)(`span`,{className:`routine-card-title`,children:e.skill}),(0,_.jsxs)(`span`,{className:`routine-card-sched`,children:[(0,_.jsx)(m,{size:13}),` `,e.plugin]}),(0,_.jsx)(`span`,{className:`skill-card-desc`,children:e.description||`No description.`}),(0,_.jsx)(`span`,{className:`routine-card-meta`,children:e.refCount===0?`No references`:`${e.refCount} reference${e.refCount===1?``:`s`}`})]},`${e.plugin}/${e.skill}`))})]}),y&&(0,_.jsx)(v,{summary:y,adminFetch:t,onClose:()=>b(null),onDeleted:S})]}):(0,_.jsx)(r,{surface:`gate`})}(0,h.createRoot)(document.getElementById(`root`)).render((0,_.jsx)(b,{}));
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,D as n,F as r,K as i,T as a,U as o,W as s,_ as c,g as l,p as u}from"./useSubAccountSwitcher-DH0P6QMV.js";import{T as d,f,t as p}from"./AdminShell-DkrURZnF.js";import{t as m}from"./file-text-DkvKqHMx.js";var h=s(),g=e(i(),1),_=t();function v({summary:e,adminFetch:t,onClose:r,onDeleted:i}){let[o,s]=(0,g.useState)(null),[u,d]=(0,g.useState)(!0),[p,h]=(0,g.useState)(null),[v,y]=(0,g.useState)(!1),[b,x]=(0,g.useState)(!1);(0,g.useEffect)(()=>{let n=!1;return d(!0),h(null),t(`/api/admin/skills/${encodeURIComponent(e.plugin)}/${encodeURIComponent(e.skill)}`).then(async e=>{if(!n){if(!e.ok)throw Error(`HTTP ${e.status}`);s((await e.json()).skill)}}).catch(e=>{n||h(e instanceof Error?e.message:`Failed to load`)}).finally(()=>{n||d(!1)}),()=>{n=!0}},[t,e.plugin,e.skill]),(0,g.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!b&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[b,r]);let S=(0,g.useCallback)(async()=>{x(!0),h(null);try{let n=await t(`/api/admin/skills/${encodeURIComponent(e.plugin)}/${encodeURIComponent(e.skill)}`,{method:`DELETE`,headers:{"content-type":`application/json`}});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`HTTP ${n.status}`)}i(e)}catch(e){h(e instanceof Error?e.message:`Delete failed`),x(!1),y(!1)}},[t,e,i]);return(0,_.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{b||r()},children:(0,_.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":`Skill detail`,onClick:e=>e.stopPropagation(),children:[(0,_.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,_.jsxs)(`span`,{className:`cal-modal-kind`,children:[(0,_.jsx)(f,{size:13}),` Skill`]}),(0,_.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:r,"aria-label":`Close`,autoFocus:!0,disabled:b,children:(0,_.jsx)(l,{size:16})})]}),(0,_.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,_.jsx)(`div`,{className:`cal-modal-title`,children:e.skill}),(0,_.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,_.jsx)(m,{size:14}),(0,_.jsx)(`span`,{children:e.plugin})]}),u&&(0,_.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,_.jsx)(a,{size:14,className:`spin`}),(0,_.jsx)(`span`,{children:`Loading…`})]}),o&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,_.jsx)(`span`,{children:o.frontmatter.description||`No description.`})}),o.frontmatter.publicEmbed&&(0,_.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,_.jsx)(n,{size:14}),(0,_.jsx)(`span`,{children:`Public embed`})]}),(0,_.jsx)(`pre`,{className:`skill-body`,children:o.body.trim()||`No body content.`}),o.references.length>0&&(0,_.jsxs)(`div`,{className:`skill-refs`,children:[(0,_.jsx)(`span`,{className:`skill-refs-label`,children:`References`}),o.references.map(e=>(0,_.jsxs)(`span`,{className:`skill-ref`,children:[(0,_.jsx)(m,{size:13}),` `,e]},e))]})]})]}),p&&(0,_.jsx)(`div`,{className:`cal-modal-error`,children:p}),(0,_.jsxs)(`div`,{className:`cal-modal-actions`,children:[!v&&(0,_.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:()=>y(!0),disabled:b||u,children:[(0,_.jsx)(c,{size:14}),` Delete`]}),v&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Delete this skill?`}),(0,_.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:S,disabled:b,children:[b?(0,_.jsx)(a,{size:14,className:`spin`}):(0,_.jsx)(c,{size:14}),` Delete`]}),(0,_.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>y(!1),disabled:b,children:`Cancel`})]})]})]})})}var y=`maxy-admin-session-key`;function b(){let[e,t]=(0,g.useState)(null),[n,i]=(0,g.useState)(!1),[a,o]=(0,g.useState)(void 0),[s,c]=(0,g.useState)(null),[l,f]=(0,g.useState)(void 0),[m,h]=(0,g.useState)(null),[v,b]=(0,g.useState)(null);(0,g.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(y)}catch{}if(!n){i(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem(y)}catch{}window.location.href=`/`;return}if(r.ok)try{let e=await r.json();typeof e.businessName==`string`&&o(e.businessName),e.sessionId!==void 0&&c(e.sessionId??null),b(e.role??null),f(e.userName===void 0?null:e.userName),h(e.avatar??null)}catch{}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!0))}),()=>{e=!0}},[]);let S=(0,g.useCallback)(()=>{try{sessionStorage.removeItem(y)}catch{}window.location.href=`/`},[]),[C,w]=(0,g.useState)(!1),T=(0,g.useCallback)(async()=>{w(!0);try{let e=await d();if(e){try{sessionStorage.removeItem(y)}catch{}window.location.href=`/`}return e}finally{w(!1)}},[]);return n?e?(0,_.jsx)(u,{cacheKey:e,surface:`skills`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=skills`);try{sessionStorage.removeItem(y)}catch{}window.location.href=`/`},children:(0,_.jsx)(p,{cacheKey:e,businessName:a,sessionId:s,onLogout:S,onDisconnect:T,disconnecting:C,userName:l,userAvatar:m,role:v,children:(0,_.jsx)(x,{cacheKey:e})})}):(0,_.jsx)(`div`,{className:`cal-page`,children:(0,_.jsxs)(`div`,{className:`cal-empty`,children:[(0,_.jsx)(`p`,{children:`You are not signed in.`}),(0,_.jsxs)(`p`,{children:[`Open the `,(0,_.jsx)(`a`,{href:`/`,className:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,_.jsx)(r,{surface:`gate`})}function x({cacheKey:e}){let{adminFetch:t,sessionRefetchNonce:n}=o({initialCacheKey:e,surface:`skills`}),[i,s]=(0,g.useState)([]),[c,l]=(0,g.useState)(!1),[u,d]=(0,g.useState)(!1),[p,h]=(0,g.useState)(null),[y,b]=(0,g.useState)(null),x=(0,g.useCallback)(()=>{let e=!1;return l(!0),h(null),t(`/api/admin/skills`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();s(Array.isArray(n.skills)?n.skills:[])}).catch(t=>{e||(h(t instanceof Error?t.message:`Failed to load`),s([]))}).finally(()=>{e||(l(!1),d(!0))}),()=>{e=!0}},[t]);(0,g.useEffect)(()=>x(),[x,n]);let S=(0,g.useCallback)(e=>{s(t=>t.filter(t=>!(t.plugin===e.plugin&&t.skill===e.skill))),b(null),x()},[x]);return u?(0,_.jsxs)(`div`,{className:`cal-page`,children:[(0,_.jsx)(`header`,{className:`cal-header`,children:(0,_.jsxs)(`div`,{className:`cal-nav`,children:[(0,_.jsxs)(`span`,{className:`cal-range-label`,children:[(0,_.jsx)(f,{size:16}),` Skills`]}),c&&(0,_.jsx)(a,{size:16,className:`spin`})]})}),(0,_.jsxs)(`div`,{className:`cal-body`,children:[p&&(0,_.jsxs)(`div`,{className:`cal-error`,children:[`Could not load skills: `,p]}),!p&&!c&&i.length===0&&(0,_.jsx)(`div`,{className:`cal-empty`,children:(0,_.jsx)(`p`,{children:`No skills yet. Ask in chat to create one.`})}),i.length>0&&(0,_.jsx)(`div`,{className:`routine-list`,children:i.map(e=>(0,_.jsxs)(`button`,{type:`button`,className:`routine-card`,onClick:()=>b(e),children:[(0,_.jsx)(`span`,{className:`routine-card-title`,children:e.skill}),(0,_.jsxs)(`span`,{className:`routine-card-sched`,children:[(0,_.jsx)(m,{size:13}),` `,e.plugin]}),(0,_.jsx)(`span`,{className:`skill-card-desc`,children:e.description||`No description.`}),(0,_.jsx)(`span`,{className:`routine-card-meta`,children:e.refCount===0?`No references`:`${e.refCount} reference${e.refCount===1?``:`s`}`})]},`${e.plugin}/${e.skill}`))})]}),y&&(0,_.jsx)(v,{summary:y,adminFetch:t,onClose:()=>b(null),onDeleted:S})]}):(0,_.jsx)(r,{surface:`gate`})}(0,h.createRoot)(document.getElementById(`root`)).render((0,_.jsx)(b,{}));
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,F as n,K as r,S as i,U as a,W as o,g as s,j as c,p as l,v as u}from"./useSubAccountSwitcher-CJKjEPNN.js";import{T as d,t as f}from"./AdminShell-BMPEWNZk.js";import{n as p,t as m}from"./time-entry-format-BgdTKgYr.js";import{t as h}from"./rotate-ccw-OQD5si8N.js";var g=o(),_=e(r(),1);function v(e=3e4){let[t,n]=(0,_.useState)(()=>Date.now());return(0,_.useEffect)(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}function y(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)),b(e,i),i}function b(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 x=`__unassigned__`;function S(e,t){return e===`__unassigned__`?`Unassigned`:t||e.slice(0,8)}function C(e){return e===null||e===``?x:e}function w(e,t){let n=new Map,r=(e,t)=>{let r=C(e.assigneeUserId),i=n.get(r)??{name:null,openCount:0,totalCount:0};i.name===null&&e.assigneeName&&(i.name=e.assigneeName),i.totalCount+=1,t&&(i.openCount+=1),n.set(r,i)};for(let t of e)r(t,!0);for(let e of t)r(e,!1);let i=[...n.entries()].map(([e,t])=>({userId:e,label:S(e,t.name),openCount:t.openCount,totalCount:t.totalCount}));return i.sort((e,t)=>t.openCount-e.openCount||e.label.localeCompare(t.label)),i}function T(e,t){return t===null?!0:C(e.assigneeUserId)===t}var E=t();function D(e){let t=e.name??e.userId.slice(0,8);return e.kind===`owner`?`${t} (owner)`:t}var O=`maxy-admin-session-key`;function k(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 A(e){if(!e)return``;let t=Date.parse(e);if(!Number.isFinite(t))return``;let n=new Date(t);return`${n.getUTCDate()} ${[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`][n.getUTCMonth()]} ${n.getUTCFullYear()}`}function j(e){return e.assigneeName?e.assigneeName:e.assigneeUserId?e.assigneeUserId.slice(0,8):`Unassigned`}function M(e,t){return[t,A(e.createdAt),j(e)].filter(Boolean).join(` · `)}function N(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 P({clients:e,onSelect:t}){return(0,E.jsxs)(`section`,{className:`admin-card tasks-card`,children:[(0,E.jsxs)(`div`,{className:`tasks-card-head`,children:[(0,E.jsx)(`span`,{className:`tasks-card-title`,children:`Clients`}),(0,E.jsxs)(`span`,{className:`tasks-card-count`,children:[e.length,` total`]})]}),e.length===0&&(0,E.jsx)(`div`,{className:`tasks-empty`,children:`No clients yet.`}),e.map(e=>(0,E.jsx)(`button`,{className:`tasks-row tasks-client-row`,onClick:()=>t(e.name),children:(0,E.jsxs)(`div`,{className:`tasks-row-main`,children:[(0,E.jsx)(`div`,{className:`tasks-row-name`,children:e.name}),(0,E.jsxs)(`div`,{className:`tasks-row-sub`,children:[e.openCount,` open · `,m(e.totalSeconds),` logged`]})]})},e.name))]})}function ee({task:e,roster:t,busy:n,onAssign:r,onClose:i}){return(0,_.useEffect)(()=>{let e=e=>{e.key===`Escape`&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i]),(0,E.jsx)(`div`,{className:`tasks-detail-backdrop`,onClick:i,children:(0,E.jsxs)(`div`,{className:`tasks-detail`,role:`dialog`,"aria-modal":`true`,"aria-label":`Task detail`,onClick:e=>e.stopPropagation(),children:[(0,E.jsxs)(`div`,{className:`tasks-detail-head`,children:[(0,E.jsx)(`h2`,{className:`tasks-detail-title`,children:e?e.name:`Task no longer available`}),(0,E.jsx)(`button`,{className:`tasks-detail-close`,"aria-label":`Close`,onClick:i,children:(0,E.jsx)(s,{size:16})})]}),e===null?(0,E.jsx)(`p`,{className:`tasks-detail-gone`,children:`This task is no longer in the list. It may have been completed, cancelled or removed. Close this and reload to see the current list.`}):(0,E.jsxs)(`dl`,{className:`tasks-detail-fields`,children:[(0,E.jsx)(`dt`,{children:`Status`}),(0,E.jsx)(`dd`,{children:e.status}),(0,E.jsx)(`dt`,{children:`Logged`}),(0,E.jsx)(`dd`,{children:m(e.secondsLogged)}),(0,E.jsx)(`dt`,{children:`Created`}),(0,E.jsx)(`dd`,{children:A(e.createdAt)||`Not recorded`}),(0,E.jsx)(`dt`,{children:`Assignee`}),(0,E.jsx)(`dd`,{children:e.taskId===null?j(e):(0,E.jsxs)(`select`,{className:`tasks-assign-select`,"aria-label":`Assignee`,disabled:n,value:e.assigneeUserId??``,onChange:t=>r(e.taskId,t.target.value===``?null:t.target.value),children:[(0,E.jsx)(`option`,{value:``,children:`Unassigned`}),e.assigneeUserId&&!t.some(t=>t.userId===e.assigneeUserId)&&(0,E.jsxs)(`option`,{value:e.assigneeUserId,children:[j(e),` (not in roster)`]}),t.map(e=>(0,E.jsx)(`option`,{value:e.userId,children:D(e)},e.userId))]})}),e.clientName&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`dt`,{children:`Client`}),(0,E.jsx)(`dd`,{children:e.clientName})]}),e.propertyAddress&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`dt`,{children:`Property`}),(0,E.jsx)(`dd`,{children:e.propertyAddress})]}),e.fee!=null&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`dt`,{children:`Fee`}),(0,E.jsxs)(`dd`,{children:[`£`,e.fee]})]})]})]})})}function F({adminFetch:e}){let[t,r]=(0,_.useState)({open:[],completed:[]}),[a,o]=(0,_.useState)(!1),[l,d]=(0,_.useState)(!1),f=(0,_.useRef)(!1),g=(0,_.useRef)(``),b=v(1e3),[x,S]=(0,_.useState)(`open`),[C,D]=(0,_.useState)(null),[O,A]=(0,_.useState)(null),[j,F]=(0,_.useState)(null),[I,L]=(0,_.useState)(``),[R,z]=(0,_.useState)(null),[B,V]=(0,_.useState)(null),H=(0,_.useMemo)(()=>{if(R!==null)return[...t.open,...t.completed].find(e=>e.rowKey===R)??null},[t,R]);(0,_.useEffect)(()=>{R!==null&&H===null&&console.error(`[tasks-ui] op=detail-failed rowKey=${R} reason=not-in-list`)},[R,H]);let U=(0,_.useMemo)(()=>y(t.open,t.completed),[t]),W=(0,_.useMemo)(()=>C===null?{open:t.open,completed:t.completed}:{open:t.open.filter(e=>e.clientName===C),completed:t.completed.filter(e=>e.clientName===C)},[t,C]),G=(0,_.useMemo)(()=>w(W.open,W.completed),[W]),K=(0,_.useCallback)(e=>{D(e),S(`open`)},[]);(0,_.useEffect)(()=>{C&&!U.some(e=>e.name===C)&&D(null)},[U,C]),(0,_.useEffect)(()=>{O&&!G.some(e=>e.userId===O)&&A(null)},[G,O]),(0,_.useEffect)(()=>{V(null)},[x,C,O]);let q=t.open.filter(e=>e.running||(C===null||e.clientName===C)&&T(e,O)),J=(C?t.completed.filter(e=>e.clientName===C):t.completed).filter(e=>T(e,O)),[te,ne]=(0,_.useState)([]),Y=(0,_.useCallback)(async()=>{let t=await e(`/api/admin/tasks-list`);t.ok&&r(await t.json()),o(!0)},[e]);(0,_.useEffect)(()=>{Y()},[Y]),(0,_.useEffect)(()=>{(async()=>{let t=await e(`/api/admin/admin-users-list`);if(t.ok){let e=await t.json();e.ok&&Array.isArray(e.users)&&ne(e.users)}})()},[e]);let X=(0,_.useCallback)(async(t,n,r)=>{if(f.current)return!1;f.current=!0,d(!0);try{return await e(t,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({taskId:n,...r})}),await Y(),!0}finally{f.current=!1,d(!1)}},[e,Y]),re=(0,_.useCallback)(async e=>{await X(`/api/admin/task-complete`,e)&&console.log(`[tasks-ui] op=complete taskId=${e.slice(0,8)} confirmed=true`)},[X]),ie=(0,_.useCallback)((e,t)=>{let n=String(Math.round(e.secondsLogged/60));g.current=n,F(t),L(n)},[]),Z=(0,_.useCallback)(()=>{F(null),L(``)},[]),ae=(0,_.useCallback)(async e=>{let t=I.trim(),n=Number(t);if(!(t===``||!Number.isInteger(n)||n<0)){if(t===g.current){Z();return}F(null),L(``),await X(`/api/admin/task-time-adjust`,e,{newSeconds:n*60})}},[I,X,Z]),oe=(0,_.useCallback)(e=>{X(`/api/admin/task-time-adjust`,e,{newSeconds:0})},[X]),se=(0,_.useCallback)((e,t)=>{X(`/api/admin/task-assign`,e,{assigneeUserId:t})},[X]);if(!a)return(0,E.jsx)(n,{surface:`gate`});let Q=e=>e.taskId!==null&&j===e.taskId,$=(e,t)=>Q(e)?(0,E.jsxs)(`div`,{className:`tasks-edit`,children:[(0,E.jsx)(`input`,{className:`tasks-edit-input`,type:`number`,min:0,step:1,"aria-label":`Logged minutes`,value:I,onChange:e=>L(e.target.value)}),(0,E.jsx)(`span`,{className:`tasks-edit-unit`,children:`min`}),(0,E.jsxs)(`button`,{className:`admin-btn-cta tasks-btn-action`,disabled:l,onClick:()=>void ae(t),children:[(0,E.jsx)(c,{size:14}),` Save`]}),(0,E.jsxs)(`button`,{className:`tasks-btn-secondary tasks-btn-action`,onClick:Z,children:[(0,E.jsx)(s,{size:14}),` Cancel`]})]}):(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`button`,{className:`tasks-time-btn`,"aria-label":`Edit time`,disabled:l||e.running,title:e.running?`Stop the timer before editing time`:void 0,onClick:()=>ie(e,t),children:(0,E.jsx)(i,{size:14})}),(0,E.jsx)(`button`,{className:`tasks-time-btn`,"aria-label":`Reset time`,disabled:l||e.running,title:e.running?`Stop the timer before resetting time`:void 0,onClick:()=>oe(t),children:(0,E.jsx)(h,{size:14})})]});return(0,E.jsxs)(`div`,{className:`tasks-body`,children:[R!==null&&(0,E.jsx)(ee,{task:H??null,roster:te,busy:l,onAssign:se,onClose:()=>z(null)}),(0,E.jsxs)(`div`,{className:`tasks-tabs`,children:[(0,E.jsxs)(`button`,{className:`admin-chip ${x===`open`?`is-active`:``}`,onClick:()=>S(`open`),children:[`Open `,(0,E.jsx)(`span`,{className:`tasks-tab-badge`,children:t.open.length})]}),(0,E.jsxs)(`button`,{className:`admin-chip ${x===`completed`?`is-active`:``}`,onClick:()=>S(`completed`),children:[`Completed `,(0,E.jsx)(`span`,{className:`tasks-tab-badge`,children:t.completed.length})]}),(0,E.jsxs)(`button`,{className:`admin-chip ${x===`clients`?`is-active`:``}`,onClick:()=>S(`clients`),children:[`Clients `,(0,E.jsx)(`span`,{className:`tasks-tab-badge`,children:U.length})]})]}),x===`clients`?(0,E.jsx)(P,{clients:U,onSelect:K}):(0,E.jsxs)(E.Fragment,{children:[C&&(0,E.jsxs)(`div`,{className:`tasks-filter-banner`,children:[(0,E.jsxs)(`span`,{children:[`Showing `,C]}),(0,E.jsx)(`button`,{className:`tasks-filter-clear`,onClick:()=>D(null),children:`Clear`})]}),G.length>0&&(0,E.jsxs)(`div`,{className:`tasks-assignee-bar`,children:[(0,E.jsxs)(`button`,{className:`admin-chip ${O===null?`is-active`:``}`,"aria-pressed":O===null,onClick:()=>A(null),children:[`All `,(0,E.jsx)(`span`,{className:`tasks-assignee-count`,children:W.open.length})]}),G.map(e=>(0,E.jsxs)(`button`,{className:`admin-chip ${O===e.userId?`is-active`:``}`,"aria-pressed":O===e.userId,"aria-label":`Assignee ${e.label}`,title:e.userId===`__unassigned__`?`Tasks with no assigned admin`:`AdminUser ${e.userId}`,onClick:()=>A(O===e.userId?null:e.userId),children:[e.label,` `,(0,E.jsx)(`span`,{className:`tasks-assignee-count`,children:e.openCount})]},e.userId))]}),x===`open`?(0,E.jsxs)(`section`,{className:`admin-card tasks-card`,children:[(0,E.jsxs)(`div`,{className:`tasks-card-head`,children:[(0,E.jsx)(`span`,{className:`tasks-card-title`,children:`Open tasks`}),(0,E.jsxs)(`span`,{className:`tasks-card-count`,children:[q.length,` to do`]})]}),q.length===0&&(0,E.jsx)(`div`,{className:`tasks-empty`,children:`No open tasks.`}),q.map(e=>(0,E.jsxs)(`div`,{className:`tasks-row`,children:[(0,E.jsx)(`button`,{className:`tasks-row-open`,"aria-label":`Open task detail: ${e.name}`,onClick:()=>z(e.rowKey),children:(0,E.jsxs)(`div`,{className:`tasks-row-main`,children:[(0,E.jsx)(`div`,{className:`tasks-row-name`,children:e.name}),(0,E.jsx)(`div`,{className:`tasks-row-sub`,children:M(e,k(e))})]})}),(0,E.jsx)(`div`,{className:`tasks-row-elapsed ${e.running?`tasks-row-elapsed-running`:``}`,children:m(N(e,b))}),(0,E.jsx)(`div`,{className:`tasks-row-controls ${e.taskId!==null&&B===e.taskId?`is-confirming`:``}`,children:e.taskId!==null&&B===e.taskId?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`span`,{className:`tasks-confirm-label`,children:`Complete?`}),(0,E.jsxs)(`button`,{className:`admin-btn-cta tasks-btn-action`,disabled:l,onClick:()=>{V(null),re(e.taskId)},children:[(0,E.jsx)(c,{size:14}),` Confirm complete`]}),(0,E.jsxs)(`button`,{className:`tasks-btn-secondary tasks-btn-action`,onClick:()=>V(null),children:[(0,E.jsx)(s,{size:14}),` Keep open`]})]}):e.taskId===null?(0,E.jsx)(`span`,{className:`tasks-row-broken`,title:`This task has no id, so it cannot be started, edited or completed. Repair it by running platform/scripts/backfill-task-ids.sh on this install.`,children:`Needs repair`}):(0,E.jsxs)(E.Fragment,{children:[$(e,e.taskId),Q(e)?null:(0,E.jsxs)(`button`,{className:`tasks-btn-secondary tasks-btn-action`,"aria-label":`Complete task: ${e.name}`,disabled:l||e.running,title:e.running?`Stop the timer before completing`:void 0,onClick:()=>V(e.taskId),children:[(0,E.jsx)(c,{size:14}),` Complete`]}),Q(e)?null:e.running?(0,E.jsxs)(`button`,{className:`admin-btn-danger tasks-btn-action`,disabled:l,onClick:()=>void X(`/api/admin/task-timer-stop`,e.taskId),children:[(0,E.jsx)(u,{size:14}),` Stop`]}):(0,E.jsxs)(`button`,{className:`admin-btn-cta tasks-btn-action`,disabled:l,onClick:()=>void X(`/api/admin/task-timer-start`,e.taskId),children:[(0,E.jsx)(p,{size:14}),` Start`]})]})})]},e.rowKey))]}):(0,E.jsxs)(`section`,{className:`admin-card tasks-card`,children:[(0,E.jsxs)(`div`,{className:`tasks-card-head`,children:[(0,E.jsx)(`span`,{className:`tasks-card-title`,children:`Completed`}),(0,E.jsxs)(`span`,{className:`tasks-card-count`,children:[J.length,` done`]})]}),J.length===0&&(0,E.jsx)(`div`,{className:`tasks-empty`,children:`Nothing completed yet.`}),J.map(e=>(0,E.jsxs)(`div`,{className:`tasks-row tasks-row-done`,children:[(0,E.jsx)(`button`,{className:`tasks-row-open`,"aria-label":`Open task detail: ${e.name}`,onClick:()=>z(e.rowKey),children:(0,E.jsxs)(`div`,{className:`tasks-row-main`,children:[(0,E.jsx)(`div`,{className:`tasks-row-name`,children:e.name}),(0,E.jsx)(`div`,{className:`tasks-row-sub`,children:M(e,k(e))})]})}),(0,E.jsx)(`div`,{className:`tasks-row-elapsed`,children:m(e.secondsLogged)}),(0,E.jsx)(`div`,{className:`tasks-row-controls`,children:e.taskId===null?(0,E.jsx)(`span`,{className:`tasks-row-broken`,title:`This task has no id, so its logged time cannot be edited. Repair it by running platform/scripts/backfill-task-ids.sh on this install.`,children:`Needs repair`}):$(e,e.taskId)})]},e.rowKey))]})]})]})}function I({cacheKey:e}){let{adminFetch:t}=a({initialCacheKey:e,surface:`tasks`});return(0,E.jsx)(F,{adminFetch:t})}function L(){let[e,t]=(0,_.useState)(null),[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(void 0),[s,c]=(0,_.useState)(null),[u,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(null),[g,v]=(0,_.useState)(null);(0,_.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(O)}catch{}if(!n){t(null),i(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem(O)}catch{}window.location.href=`/`;return}if(r.ok)try{let e=await r.json();typeof e.businessName==`string`&&o(e.businessName),e.sessionId!==void 0&&c(e.sessionId??null),p(e.role??null),h(e.userName===void 0?null:e.userName),v(e.avatar??null)}catch{}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!0))}),()=>{e=!0}},[]);let y=(0,_.useCallback)(()=>{try{sessionStorage.removeItem(O)}catch{}window.location.href=`/`},[]),[b,x]=(0,_.useState)(!1),S=(0,_.useCallback)(async()=>{x(!0);try{let e=await d();if(e){try{sessionStorage.removeItem(O)}catch{}window.location.href=`/`}return e}finally{x(!1)}},[]);return r?e?(0,E.jsx)(l,{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(O)}catch{}window.location.href=`/`},children:(0,E.jsx)(f,{cacheKey:e,businessName:a,sessionId:s,onLogout:y,onDisconnect:S,disconnecting:b,userName:m,userAvatar:g,role:u,children:(0,E.jsx)(I,{cacheKey:e})})}):(0,E.jsx)(`div`,{className:`tasks-page`,children:(0,E.jsxs)(`div`,{className:`tasks-empty`,children:[(0,E.jsx)(`p`,{children:`You are not signed in.`}),(0,E.jsxs)(`p`,{children:[`Open the `,(0,E.jsx)(`a`,{href:`/`,className:`tasks-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,E.jsx)(n,{surface:`gate`})}(0,g.createRoot)(document.getElementById(`root`)).render((0,E.jsx)(L,{}));
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,F as n,K as r,S as i,U as a,W as o,g as s,j as c,p as l,v as u}from"./useSubAccountSwitcher-DH0P6QMV.js";import{T as d,t as f}from"./AdminShell-DkrURZnF.js";import{n as p,t as m}from"./time-entry-format-Cy_T-wiD.js";import{t as h}from"./rotate-ccw-dh_OhL23.js";var g=o(),_=e(r(),1);function v(e=3e4){let[t,n]=(0,_.useState)(()=>Date.now());return(0,_.useEffect)(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}function y(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)),b(e,i),i}function b(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 x=`__unassigned__`;function S(e,t){return e===`__unassigned__`?`Unassigned`:t||e.slice(0,8)}function C(e){return e===null||e===``?x:e}function w(e,t){let n=new Map,r=(e,t)=>{let r=C(e.assigneeUserId),i=n.get(r)??{name:null,openCount:0,totalCount:0};i.name===null&&e.assigneeName&&(i.name=e.assigneeName),i.totalCount+=1,t&&(i.openCount+=1),n.set(r,i)};for(let t of e)r(t,!0);for(let e of t)r(e,!1);let i=[...n.entries()].map(([e,t])=>({userId:e,label:S(e,t.name),openCount:t.openCount,totalCount:t.totalCount}));return i.sort((e,t)=>t.openCount-e.openCount||e.label.localeCompare(t.label)),i}function T(e,t){return t===null?!0:C(e.assigneeUserId)===t}var E=t();function D(e){let t=e.name??e.userId.slice(0,8);return e.kind===`owner`?`${t} (owner)`:t}var O=`maxy-admin-session-key`;function k(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 A(e){if(!e)return``;let t=Date.parse(e);if(!Number.isFinite(t))return``;let n=new Date(t);return`${n.getUTCDate()} ${[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`][n.getUTCMonth()]} ${n.getUTCFullYear()}`}function j(e){return e.assigneeName?e.assigneeName:e.assigneeUserId?e.assigneeUserId.slice(0,8):`Unassigned`}function M(e,t){return[t,A(e.createdAt),j(e)].filter(Boolean).join(` · `)}function N(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 P({clients:e,onSelect:t}){return(0,E.jsxs)(`section`,{className:`admin-card tasks-card`,children:[(0,E.jsxs)(`div`,{className:`tasks-card-head`,children:[(0,E.jsx)(`span`,{className:`tasks-card-title`,children:`Clients`}),(0,E.jsxs)(`span`,{className:`tasks-card-count`,children:[e.length,` total`]})]}),e.length===0&&(0,E.jsx)(`div`,{className:`tasks-empty`,children:`No clients yet.`}),e.map(e=>(0,E.jsx)(`button`,{className:`tasks-row tasks-client-row`,onClick:()=>t(e.name),children:(0,E.jsxs)(`div`,{className:`tasks-row-main`,children:[(0,E.jsx)(`div`,{className:`tasks-row-name`,children:e.name}),(0,E.jsxs)(`div`,{className:`tasks-row-sub`,children:[e.openCount,` open · `,m(e.totalSeconds),` logged`]})]})},e.name))]})}function ee({task:e,roster:t,busy:n,onAssign:r,onClose:i}){return(0,_.useEffect)(()=>{let e=e=>{e.key===`Escape`&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i]),(0,E.jsx)(`div`,{className:`tasks-detail-backdrop`,onClick:i,children:(0,E.jsxs)(`div`,{className:`tasks-detail`,role:`dialog`,"aria-modal":`true`,"aria-label":`Task detail`,onClick:e=>e.stopPropagation(),children:[(0,E.jsxs)(`div`,{className:`tasks-detail-head`,children:[(0,E.jsx)(`h2`,{className:`tasks-detail-title`,children:e?e.name:`Task no longer available`}),(0,E.jsx)(`button`,{className:`tasks-detail-close`,"aria-label":`Close`,onClick:i,children:(0,E.jsx)(s,{size:16})})]}),e===null?(0,E.jsx)(`p`,{className:`tasks-detail-gone`,children:`This task is no longer in the list. It may have been completed, cancelled or removed. Close this and reload to see the current list.`}):(0,E.jsxs)(`dl`,{className:`tasks-detail-fields`,children:[(0,E.jsx)(`dt`,{children:`Status`}),(0,E.jsx)(`dd`,{children:e.status}),(0,E.jsx)(`dt`,{children:`Logged`}),(0,E.jsx)(`dd`,{children:m(e.secondsLogged)}),(0,E.jsx)(`dt`,{children:`Created`}),(0,E.jsx)(`dd`,{children:A(e.createdAt)||`Not recorded`}),(0,E.jsx)(`dt`,{children:`Assignee`}),(0,E.jsx)(`dd`,{children:e.taskId===null?j(e):(0,E.jsxs)(`select`,{className:`tasks-assign-select`,"aria-label":`Assignee`,disabled:n,value:e.assigneeUserId??``,onChange:t=>r(e.taskId,t.target.value===``?null:t.target.value),children:[(0,E.jsx)(`option`,{value:``,children:`Unassigned`}),e.assigneeUserId&&!t.some(t=>t.userId===e.assigneeUserId)&&(0,E.jsxs)(`option`,{value:e.assigneeUserId,children:[j(e),` (not in roster)`]}),t.map(e=>(0,E.jsx)(`option`,{value:e.userId,children:D(e)},e.userId))]})}),e.clientName&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`dt`,{children:`Client`}),(0,E.jsx)(`dd`,{children:e.clientName})]}),e.propertyAddress&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`dt`,{children:`Property`}),(0,E.jsx)(`dd`,{children:e.propertyAddress})]}),e.fee!=null&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`dt`,{children:`Fee`}),(0,E.jsxs)(`dd`,{children:[`£`,e.fee]})]})]})]})})}function F({adminFetch:e}){let[t,r]=(0,_.useState)({open:[],completed:[]}),[a,o]=(0,_.useState)(!1),[l,d]=(0,_.useState)(!1),f=(0,_.useRef)(!1),g=(0,_.useRef)(``),b=v(1e3),[x,S]=(0,_.useState)(`open`),[C,D]=(0,_.useState)(null),[O,A]=(0,_.useState)(null),[j,F]=(0,_.useState)(null),[I,L]=(0,_.useState)(``),[R,z]=(0,_.useState)(null),[B,V]=(0,_.useState)(null),H=(0,_.useMemo)(()=>{if(R!==null)return[...t.open,...t.completed].find(e=>e.rowKey===R)??null},[t,R]);(0,_.useEffect)(()=>{R!==null&&H===null&&console.error(`[tasks-ui] op=detail-failed rowKey=${R} reason=not-in-list`)},[R,H]);let U=(0,_.useMemo)(()=>y(t.open,t.completed),[t]),W=(0,_.useMemo)(()=>C===null?{open:t.open,completed:t.completed}:{open:t.open.filter(e=>e.clientName===C),completed:t.completed.filter(e=>e.clientName===C)},[t,C]),G=(0,_.useMemo)(()=>w(W.open,W.completed),[W]),K=(0,_.useCallback)(e=>{D(e),S(`open`)},[]);(0,_.useEffect)(()=>{C&&!U.some(e=>e.name===C)&&D(null)},[U,C]),(0,_.useEffect)(()=>{O&&!G.some(e=>e.userId===O)&&A(null)},[G,O]),(0,_.useEffect)(()=>{V(null)},[x,C,O]);let q=t.open.filter(e=>e.running||(C===null||e.clientName===C)&&T(e,O)),J=(C?t.completed.filter(e=>e.clientName===C):t.completed).filter(e=>T(e,O)),[te,ne]=(0,_.useState)([]),Y=(0,_.useCallback)(async()=>{let t=await e(`/api/admin/tasks-list`);t.ok&&r(await t.json()),o(!0)},[e]);(0,_.useEffect)(()=>{Y()},[Y]),(0,_.useEffect)(()=>{(async()=>{let t=await e(`/api/admin/admin-users-list`);if(t.ok){let e=await t.json();e.ok&&Array.isArray(e.users)&&ne(e.users)}})()},[e]);let X=(0,_.useCallback)(async(t,n,r)=>{if(f.current)return!1;f.current=!0,d(!0);try{return await e(t,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({taskId:n,...r})}),await Y(),!0}finally{f.current=!1,d(!1)}},[e,Y]),re=(0,_.useCallback)(async e=>{await X(`/api/admin/task-complete`,e)&&console.log(`[tasks-ui] op=complete taskId=${e.slice(0,8)} confirmed=true`)},[X]),ie=(0,_.useCallback)((e,t)=>{let n=String(Math.round(e.secondsLogged/60));g.current=n,F(t),L(n)},[]),Z=(0,_.useCallback)(()=>{F(null),L(``)},[]),ae=(0,_.useCallback)(async e=>{let t=I.trim(),n=Number(t);if(!(t===``||!Number.isInteger(n)||n<0)){if(t===g.current){Z();return}F(null),L(``),await X(`/api/admin/task-time-adjust`,e,{newSeconds:n*60})}},[I,X,Z]),oe=(0,_.useCallback)(e=>{X(`/api/admin/task-time-adjust`,e,{newSeconds:0})},[X]),se=(0,_.useCallback)((e,t)=>{X(`/api/admin/task-assign`,e,{assigneeUserId:t})},[X]);if(!a)return(0,E.jsx)(n,{surface:`gate`});let Q=e=>e.taskId!==null&&j===e.taskId,$=(e,t)=>Q(e)?(0,E.jsxs)(`div`,{className:`tasks-edit`,children:[(0,E.jsx)(`input`,{className:`tasks-edit-input`,type:`number`,min:0,step:1,"aria-label":`Logged minutes`,value:I,onChange:e=>L(e.target.value)}),(0,E.jsx)(`span`,{className:`tasks-edit-unit`,children:`min`}),(0,E.jsxs)(`button`,{className:`admin-btn-cta tasks-btn-action`,disabled:l,onClick:()=>void ae(t),children:[(0,E.jsx)(c,{size:14}),` Save`]}),(0,E.jsxs)(`button`,{className:`tasks-btn-secondary tasks-btn-action`,onClick:Z,children:[(0,E.jsx)(s,{size:14}),` Cancel`]})]}):(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`button`,{className:`tasks-time-btn`,"aria-label":`Edit time`,disabled:l||e.running,title:e.running?`Stop the timer before editing time`:void 0,onClick:()=>ie(e,t),children:(0,E.jsx)(i,{size:14})}),(0,E.jsx)(`button`,{className:`tasks-time-btn`,"aria-label":`Reset time`,disabled:l||e.running,title:e.running?`Stop the timer before resetting time`:void 0,onClick:()=>oe(t),children:(0,E.jsx)(h,{size:14})})]});return(0,E.jsxs)(`div`,{className:`tasks-body`,children:[R!==null&&(0,E.jsx)(ee,{task:H??null,roster:te,busy:l,onAssign:se,onClose:()=>z(null)}),(0,E.jsxs)(`div`,{className:`tasks-tabs`,children:[(0,E.jsxs)(`button`,{className:`admin-chip ${x===`open`?`is-active`:``}`,onClick:()=>S(`open`),children:[`Open `,(0,E.jsx)(`span`,{className:`tasks-tab-badge`,children:t.open.length})]}),(0,E.jsxs)(`button`,{className:`admin-chip ${x===`completed`?`is-active`:``}`,onClick:()=>S(`completed`),children:[`Completed `,(0,E.jsx)(`span`,{className:`tasks-tab-badge`,children:t.completed.length})]}),(0,E.jsxs)(`button`,{className:`admin-chip ${x===`clients`?`is-active`:``}`,onClick:()=>S(`clients`),children:[`Clients `,(0,E.jsx)(`span`,{className:`tasks-tab-badge`,children:U.length})]})]}),x===`clients`?(0,E.jsx)(P,{clients:U,onSelect:K}):(0,E.jsxs)(E.Fragment,{children:[C&&(0,E.jsxs)(`div`,{className:`tasks-filter-banner`,children:[(0,E.jsxs)(`span`,{children:[`Showing `,C]}),(0,E.jsx)(`button`,{className:`tasks-filter-clear`,onClick:()=>D(null),children:`Clear`})]}),G.length>0&&(0,E.jsxs)(`div`,{className:`tasks-assignee-bar`,children:[(0,E.jsxs)(`button`,{className:`admin-chip ${O===null?`is-active`:``}`,"aria-pressed":O===null,onClick:()=>A(null),children:[`All `,(0,E.jsx)(`span`,{className:`tasks-assignee-count`,children:W.open.length})]}),G.map(e=>(0,E.jsxs)(`button`,{className:`admin-chip ${O===e.userId?`is-active`:``}`,"aria-pressed":O===e.userId,"aria-label":`Assignee ${e.label}`,title:e.userId===`__unassigned__`?`Tasks with no assigned admin`:`AdminUser ${e.userId}`,onClick:()=>A(O===e.userId?null:e.userId),children:[e.label,` `,(0,E.jsx)(`span`,{className:`tasks-assignee-count`,children:e.openCount})]},e.userId))]}),x===`open`?(0,E.jsxs)(`section`,{className:`admin-card tasks-card`,children:[(0,E.jsxs)(`div`,{className:`tasks-card-head`,children:[(0,E.jsx)(`span`,{className:`tasks-card-title`,children:`Open tasks`}),(0,E.jsxs)(`span`,{className:`tasks-card-count`,children:[q.length,` to do`]})]}),q.length===0&&(0,E.jsx)(`div`,{className:`tasks-empty`,children:`No open tasks.`}),q.map(e=>(0,E.jsxs)(`div`,{className:`tasks-row`,children:[(0,E.jsx)(`button`,{className:`tasks-row-open`,"aria-label":`Open task detail: ${e.name}`,onClick:()=>z(e.rowKey),children:(0,E.jsxs)(`div`,{className:`tasks-row-main`,children:[(0,E.jsx)(`div`,{className:`tasks-row-name`,children:e.name}),(0,E.jsx)(`div`,{className:`tasks-row-sub`,children:M(e,k(e))})]})}),(0,E.jsx)(`div`,{className:`tasks-row-elapsed ${e.running?`tasks-row-elapsed-running`:``}`,children:m(N(e,b))}),(0,E.jsx)(`div`,{className:`tasks-row-controls ${e.taskId!==null&&B===e.taskId?`is-confirming`:``}`,children:e.taskId!==null&&B===e.taskId?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`span`,{className:`tasks-confirm-label`,children:`Complete?`}),(0,E.jsxs)(`button`,{className:`admin-btn-cta tasks-btn-action`,disabled:l,onClick:()=>{V(null),re(e.taskId)},children:[(0,E.jsx)(c,{size:14}),` Confirm complete`]}),(0,E.jsxs)(`button`,{className:`tasks-btn-secondary tasks-btn-action`,onClick:()=>V(null),children:[(0,E.jsx)(s,{size:14}),` Keep open`]})]}):e.taskId===null?(0,E.jsx)(`span`,{className:`tasks-row-broken`,title:`This task has no id, so it cannot be started, edited or completed. Repair it by running platform/scripts/backfill-task-ids.sh on this install.`,children:`Needs repair`}):(0,E.jsxs)(E.Fragment,{children:[$(e,e.taskId),Q(e)?null:(0,E.jsxs)(`button`,{className:`tasks-btn-secondary tasks-btn-action`,"aria-label":`Complete task: ${e.name}`,disabled:l||e.running,title:e.running?`Stop the timer before completing`:void 0,onClick:()=>V(e.taskId),children:[(0,E.jsx)(c,{size:14}),` Complete`]}),Q(e)?null:e.running?(0,E.jsxs)(`button`,{className:`admin-btn-danger tasks-btn-action`,disabled:l,onClick:()=>void X(`/api/admin/task-timer-stop`,e.taskId),children:[(0,E.jsx)(u,{size:14}),` Stop`]}):(0,E.jsxs)(`button`,{className:`admin-btn-cta tasks-btn-action`,disabled:l,onClick:()=>void X(`/api/admin/task-timer-start`,e.taskId),children:[(0,E.jsx)(p,{size:14}),` Start`]})]})})]},e.rowKey))]}):(0,E.jsxs)(`section`,{className:`admin-card tasks-card`,children:[(0,E.jsxs)(`div`,{className:`tasks-card-head`,children:[(0,E.jsx)(`span`,{className:`tasks-card-title`,children:`Completed`}),(0,E.jsxs)(`span`,{className:`tasks-card-count`,children:[J.length,` done`]})]}),J.length===0&&(0,E.jsx)(`div`,{className:`tasks-empty`,children:`Nothing completed yet.`}),J.map(e=>(0,E.jsxs)(`div`,{className:`tasks-row tasks-row-done`,children:[(0,E.jsx)(`button`,{className:`tasks-row-open`,"aria-label":`Open task detail: ${e.name}`,onClick:()=>z(e.rowKey),children:(0,E.jsxs)(`div`,{className:`tasks-row-main`,children:[(0,E.jsx)(`div`,{className:`tasks-row-name`,children:e.name}),(0,E.jsx)(`div`,{className:`tasks-row-sub`,children:M(e,k(e))})]})}),(0,E.jsx)(`div`,{className:`tasks-row-elapsed`,children:m(e.secondsLogged)}),(0,E.jsx)(`div`,{className:`tasks-row-controls`,children:e.taskId===null?(0,E.jsx)(`span`,{className:`tasks-row-broken`,title:`This task has no id, so its logged time cannot be edited. Repair it by running platform/scripts/backfill-task-ids.sh on this install.`,children:`Needs repair`}):$(e,e.taskId)})]},e.rowKey))]})]})]})}function I({cacheKey:e}){let{adminFetch:t}=a({initialCacheKey:e,surface:`tasks`});return(0,E.jsx)(F,{adminFetch:t})}function L(){let[e,t]=(0,_.useState)(null),[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(void 0),[s,c]=(0,_.useState)(null),[u,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(null),[g,v]=(0,_.useState)(null);(0,_.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(O)}catch{}if(!n){t(null),i(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem(O)}catch{}window.location.href=`/`;return}if(r.ok)try{let e=await r.json();typeof e.businessName==`string`&&o(e.businessName),e.sessionId!==void 0&&c(e.sessionId??null),p(e.role??null),h(e.userName===void 0?null:e.userName),v(e.avatar??null)}catch{}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!0))}),()=>{e=!0}},[]);let y=(0,_.useCallback)(()=>{try{sessionStorage.removeItem(O)}catch{}window.location.href=`/`},[]),[b,x]=(0,_.useState)(!1),S=(0,_.useCallback)(async()=>{x(!0);try{let e=await d();if(e){try{sessionStorage.removeItem(O)}catch{}window.location.href=`/`}return e}finally{x(!1)}},[]);return r?e?(0,E.jsx)(l,{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(O)}catch{}window.location.href=`/`},children:(0,E.jsx)(f,{cacheKey:e,businessName:a,sessionId:s,onLogout:y,onDisconnect:S,disconnecting:b,userName:m,userAvatar:g,role:u,children:(0,E.jsx)(I,{cacheKey:e})})}):(0,E.jsx)(`div`,{className:`tasks-page`,children:(0,E.jsxs)(`div`,{className:`tasks-empty`,children:[(0,E.jsx)(`p`,{children:`You are not signed in.`}),(0,E.jsxs)(`p`,{children:[`Open the `,(0,E.jsx)(`a`,{href:`/`,className:`tasks-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,E.jsx)(n,{surface:`gate`})}(0,g.createRoot)(document.getElementById(`root`)).render((0,E.jsx)(L,{}));
@@ -1 +1 @@
1
- import{P as e}from"./useSubAccountSwitcher-CJKjEPNN.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
+ import{P as e}from"./useSubAccountSwitcher-DH0P6QMV.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};
@@ -0,0 +1,3 @@
1
+ �����B�����"@GzN�n?�V��VF�Ybf�|c�9����Ja���'�T�
2
+ ��s��'X`�cQ�Al�A�_� ڢ4��o ���6N|�Ϋ7A���8�$OI%��o��7D��dG��ݮ��m5��9�u��
3
+ �^ʠ"I��22k'�l�ûV�Li����>� ۟`;;��z�����s�~�ι�n~��>��P�_��@&��%~ p3$)H_ ���f��R*�]��������)v�P�g?�,+���95䅷6��mxJ�w1
@@ -1 +1 @@
1
- import{P as e}from"./useSubAccountSwitcher-CJKjEPNN.js";var t=e(`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`}]]);export{t};
1
+ import{P as e}from"./useSubAccountSwitcher-DH0P6QMV.js";var t=e(`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`}]]);export{t};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{K as t,r as n}from"./useSubAccountSwitcher-CJKjEPNN.js";var r=e(t(),1);function i(e){let[t,i]=(0,r.useState)(`idle`),a=(0,r.useRef)(null),o=(0,r.useRef)(e?.onResult);return o.current=e?.onResult,(0,r.useEffect)(()=>()=>{a.current&&clearTimeout(a.current)},[]),{status:t,copy:(0,r.useCallback)(async e=>{let t=await n(e);i(t?`ok`:`fail`),o.current?.(t),a.current&&clearTimeout(a.current),a.current=setTimeout(()=>i(`idle`),1500)},[])}}export{i as t};
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{K as t,r as n}from"./useSubAccountSwitcher-DH0P6QMV.js";var r=e(t(),1);function i(e){let[t,i]=(0,r.useState)(`idle`),a=(0,r.useRef)(null),o=(0,r.useRef)(e?.onResult);return o.current=e?.onResult,(0,r.useEffect)(()=>()=>{a.current&&clearTimeout(a.current)},[]),{status:t,copy:(0,r.useCallback)(async e=>{let t=await n(e);i(t?`ok`:`fail`),o.current?.(t),a.current&&clearTimeout(a.current),a.current=setTimeout(()=>i(`idle`),1500)},[])}}export{i as t};