@camstack/addon-admin-ui 1.2.141 → 1.2.142

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 (108) hide show
  1. package/dist/assets/{AddLocationWizard-CdoufjHB.js → AddLocationWizard-BEWTYRkd.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-DeZdmgUz.js → AddonCollectionPage-Bwd1mfzq.js} +1 -1
  3. package/dist/assets/{Addons-hvUanm8h.js → Addons-CVoKSfko.js} +1 -1
  4. package/dist/assets/{AdminTabs-fwNNU8c7.js → AdminTabs-CqZmMiLw.js} +1 -1
  5. package/dist/assets/{AiProfiles-Dluiz96J.js → AiProfiles-BLtkfbAe.js} +1 -1
  6. package/dist/assets/{BrokerForm-7d4xFkGC.js → BrokerForm-DRH2Xbft.js} +1 -1
  7. package/dist/assets/{Build-5qOR_z-4.js → Build-BGjqaGJE.js} +1 -1
  8. package/dist/assets/{Capabilities-ZZgecT57.js → Capabilities-UIdIpssZ.js} +1 -1
  9. package/dist/assets/{CapabilityBadges-Df19YUw6.js → CapabilityBadges-D2RR4BL8.js} +1 -1
  10. package/dist/assets/{Cluster-CEGBFcQt.js → Cluster-NuyVo4NU.js} +1 -1
  11. package/dist/assets/{Data-Bn67KrXk.js → Data-BfBL8DHz.js} +1 -1
  12. package/dist/assets/{DetectionIntelligence-B7MNvl8i.js → DetectionIntelligence-BkFRyCbn.js} +1 -1
  13. package/dist/assets/{DeviceAggregateSection-DsE47wfH.js → DeviceAggregateSection-Cq6NSh4-.js} +1 -1
  14. package/dist/assets/{DeviceDetail-kVl_NB_j.js → DeviceDetail-CtlHQLD7.js} +1 -1
  15. package/dist/assets/{Devices-BTiI6NNE.js → Devices-Cj0XH3Tz.js} +1 -1
  16. package/dist/assets/{EmbedPlayerPage-Cs8b1fVn.js → EmbedPlayerPage-BAEp7OAu.js} +1 -1
  17. package/dist/assets/{Events-BJIGsZ4b.js → Events-Cqmkwtd9.js} +1 -1
  18. package/dist/assets/{FormBuilder-DgvtVD8W.js → FormBuilder-CUiC8-34.js} +1 -1
  19. package/dist/assets/{Identity-DaHTsijF.js → Identity-KWojpusZ.js} +1 -1
  20. package/dist/assets/{IntegrationDetail-D2j10M2-.js → IntegrationDetail-tmhL-34K.js} +1 -1
  21. package/dist/assets/{Integrations-FE8Ef3Fw.js → Integrations-C6zNnYIN.js} +1 -1
  22. package/dist/assets/{Integrations-D9TNnvpN.js → Integrations-CjaR4SZV.js} +1 -1
  23. package/dist/assets/{Locations-BRbd1JHZ.js → Locations-B4lfzyHW.js} +1 -1
  24. package/dist/assets/{Logs-B3bgikYo.js → Logs-CzXqI4a8.js} +1 -1
  25. package/dist/assets/{MotionZonesSettings-Cdq-cQYm.js → MotionZonesSettings-B929txaT.js} +1 -1
  26. package/dist/assets/{MyAccess-B71GxA27.js → MyAccess-CxZT9DEs.js} +1 -1
  27. package/dist/assets/{Network-Dn0lkcwO.js → Network-DNJbsrxh.js} +1 -1
  28. package/dist/assets/{NodeAddonsSettingsPanel-4j9h05Vg.js → NodeAddonsSettingsPanel-B5W0S_6w.js} +1 -1
  29. package/dist/assets/{NodeInferenceDevices-UmKuC0_i.js → NodeInferenceDevices-URK6EmWb.js} +1 -1
  30. package/dist/assets/{Notifications-CFM9n-Tj.js → Notifications-Ct29OF-U.js} +1 -1
  31. package/dist/assets/{Pipeline-D-7IfvY0.js → Pipeline-C3YzhtBU.js} +1 -1
  32. package/dist/assets/{Plates-DwePCO3K.js → Plates-I8DjAgx9.js} +1 -1
  33. package/dist/assets/{PrivacyMaskSettings-DXHUf-J5.js → PrivacyMaskSettings-B78n_IH5.js} +1 -1
  34. package/dist/assets/{ProviderIcon-Boglr5Qu.js → ProviderIcon-C1mS4XxM.js} +1 -1
  35. package/dist/assets/{Recordings-CcQY3u-3.js → Recordings-DvMWgSjc.js} +1 -1
  36. package/dist/assets/{ScanNetworkModal-Dv5q0aAe.js → ScanNetworkModal-Fb7DhSXD.js} +1 -1
  37. package/dist/assets/{SceneMonitorEditor-NImQe9Q6.js → SceneMonitorEditor-BOBmN54z.js} +1 -1
  38. package/dist/assets/{Scenes-DDIsbaHW.js → Scenes-CDxgTdin.js} +1 -1
  39. package/dist/assets/{Settings-pxpdbMkY.js → Settings-Cqk_-Aco.js} +1 -1
  40. package/dist/assets/{Showroom-DknbTM7Q.js → Showroom-DyBW7LGa.js} +1 -1
  41. package/dist/assets/{StorageLocationsPanel-CICkHygZ.js → StorageLocationsPanel-Didj66Hz.js} +1 -1
  42. package/dist/assets/{Terminal-B2kwJSW4.js → Terminal-BAI0e5YM.js} +1 -1
  43. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-U83gzRZM.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-_L8d3w9K.js} +1 -1
  44. package/dist/assets/{bell-off-D8N0zRax.js → bell-off-DsLQMD5U.js} +1 -1
  45. package/dist/assets/{bell-ring-BzkYw_jF.js → bell-ring-vqHUwRYF.js} +1 -1
  46. package/dist/assets/{boxes-CIbHat4r.js → boxes-CZnbLP9P.js} +1 -1
  47. package/dist/assets/circle-check-big-BvHeM1LY.js +1 -0
  48. package/dist/assets/circle-dot-BLnF4dJR.js +1 -0
  49. package/dist/assets/circle-slash-B-5dS85p.js +1 -0
  50. package/dist/assets/{circle-x-DgOvPSCw.js → circle-x-4Dl6gVrz.js} +1 -1
  51. package/dist/assets/clock-fhpkQDEm.js +1 -0
  52. package/dist/assets/{copy-kO9TUFbx.js → copy-C58XU9mC.js} +1 -1
  53. package/dist/assets/{debounced-invalidate-DtA81wiP.js → debounced-invalidate-Dj05UKK5.js} +1 -1
  54. package/dist/assets/{dist-C_lca_Fu.js → dist-B4EGueGc.js} +1 -1
  55. package/dist/assets/{dist-DnMIlAMX.js → dist-CMaEyNKr.js} +1 -1
  56. package/dist/assets/{download-BthqNrtL.js → download-B6w2lrQQ.js} +1 -1
  57. package/dist/assets/{face-bbox-BL2qwCCF.js → face-bbox-CBiv7JlE.js} +1 -1
  58. package/dist/assets/{flame-qBVMo0ch.js → flame-KsH2sGjb.js} +1 -1
  59. package/dist/assets/{hard-drive-BL3oY1u7.js → hard-drive-BJUcdsGQ.js} +1 -1
  60. package/dist/assets/{hard-drive-download-Dj3aVgwc.js → hard-drive-download-BEpVEf7Q.js} +1 -1
  61. package/dist/assets/{hostInit-DS4XMP-Z.js → hostInit-CrqOeaaw.js} +1 -1
  62. package/dist/assets/{index-MHuc7l_c.js → index-COjcrxBt.js} +3 -3
  63. package/dist/assets/{key-round-BwsJDPdY.js → key-round-Ce87rimg.js} +1 -1
  64. package/dist/assets/{layers-D9phahbM.js → layers-CGZ8WUVB.js} +1 -1
  65. package/dist/assets/{mf-entry-bootstrap-0-0216d8ab.js → mf-entry-bootstrap-0-5d1ed412.js} +2 -2
  66. package/dist/assets/{pencil-MICqy4MD.js → pencil-DoE75RwV.js} +1 -1
  67. package/dist/assets/play-B84SrcvR.js +1 -0
  68. package/dist/assets/{player-overlays-DWqOEI94.js → player-overlays-o9jF7-FW.js} +1 -1
  69. package/dist/assets/plus-CezysZVA.js +1 -0
  70. package/dist/assets/power-CvOo2kCO.js +1 -0
  71. package/dist/assets/{radio-DJaDrpzo.js → radio-BMqprMmY.js} +1 -1
  72. package/dist/assets/{refresh-cw-CnFbQxHl.js → refresh-cw-DgGcyCy7.js} +1 -1
  73. package/dist/assets/remoteEntry-DEOpXf9g.js +1 -0
  74. package/dist/assets/rotate-ccw-_qyjIbAS.js +1 -0
  75. package/dist/assets/rotate-cw-seLHMWMS.js +1 -0
  76. package/dist/assets/{send-CwlLF556.js → send-DahSF3af.js} +1 -1
  77. package/dist/assets/{server-B4iG1vdW.js → server-BIHbmJRc.js} +1 -1
  78. package/dist/assets/{shield-DSd_6QdB.js → shield-B7oln0YR.js} +1 -1
  79. package/dist/assets/{shield-alert-SMtHj47H.js → shield-alert-4xYqDrFd.js} +1 -1
  80. package/dist/assets/square-D1oiCqcu.js +1 -0
  81. package/dist/assets/{square-check-big-zTK6qy3B.js → square-check-big-BKAkZG8V.js} +1 -1
  82. package/dist/assets/{src-B4NOGVsx.js → src-4oGT5Voh.js} +1 -1
  83. package/dist/assets/{src-rZAVP-8-.js → src-D9QFy74P.js} +3 -3
  84. package/dist/assets/{undo-2-UYOGv0zz.js → undo-2-DAr06108.js} +1 -1
  85. package/dist/assets/{use-scenes-feed-CVMCbrf3.js → use-scenes-feed-BwTm9H2S.js} +1 -1
  86. package/dist/assets/useEventInvalidation-IQzx-Bea.js +1 -0
  87. package/dist/assets/{useNodeUrlSelection-Dcb9Cmy_.js → useNodeUrlSelection-BXTlDNv4.js} +1 -1
  88. package/dist/assets/user-round-BSoMUNPE.js +1 -0
  89. package/dist/assets/{video-CLfrtjUD.js → video-B17QC8iA.js} +1 -1
  90. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DOXSkqyj.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DYjpfOK3.js} +2 -2
  91. package/dist/assets/{wifi-37iCuU7H.js → wifi-BDoILjan.js} +1 -1
  92. package/dist/assets/{zap-Drh_qIsL.js → zap-DcQFzh7K.js} +1 -1
  93. package/dist/index.html +5 -5
  94. package/dist/server/addon.js +1 -1
  95. package/package.json +1 -1
  96. package/dist/assets/circle-check-big-0DidlcLj.js +0 -1
  97. package/dist/assets/circle-dot-psZ4_Yj_.js +0 -1
  98. package/dist/assets/circle-slash-Byu8-oUY.js +0 -1
  99. package/dist/assets/clock-OlU3cIuc.js +0 -1
  100. package/dist/assets/play-DmW_NZO9.js +0 -1
  101. package/dist/assets/plus-ShS1ufOP.js +0 -1
  102. package/dist/assets/power-BSVi0Xfc.js +0 -1
  103. package/dist/assets/remoteEntry-CmCVytWt.js +0 -1
  104. package/dist/assets/rotate-ccw-B6ouAnrS.js +0 -1
  105. package/dist/assets/rotate-cw-BtL-GrdV.js +0 -1
  106. package/dist/assets/square-VTY9fnGJ.js +0 -1
  107. package/dist/assets/useEventInvalidation-D8U6tF0j.js +0 -1
  108. package/dist/assets/user-round-D7yuyq1n.js +0 -1
@@ -1,4 +1,4 @@
1
- import{I as e,K as t,M as n,Q as r,S as i,T as a,W as o,a as s,b as c,q as l,t as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Q as p}from"./player-overlays-DWqOEI94.js";import{Ft as m,It as h,J as g,Kr as _,Lt as v,Nt as y,Pt as b,Rt as x,V as S,X as C,Xt as w,bt as T,dt as E,ft as D,g as O,it as k,lt as A,un as j,ut as M,vt as N,yt as P}from"./src-rZAVP-8-.js";import{Ut as F,W as I,_t as ee,bt as L,dt as R,gt as z,vt as te,yt as ne}from"./src-B4NOGVsx.js";import{t as re}from"./boxes-CIbHat4r.js";import{t as ie}from"./pencil-MICqy4MD.js";import{t as ae}from"./play-DmW_NZO9.js";import{t as B}from"./plus-ShS1ufOP.js";import{t as oe}from"./rotate-cw-BtL-GrdV.js";import{E as se,F as ce,J as le,L as ue,Q as de,S as fe,a as pe,m as me,o as V,w as he,z as ge}from"./index-MHuc7l_c.js";import{t as _e}from"./AdminPage-CCD07UMs.js";var ve=le(`arrow-down`,[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]),ye=le(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),be=le(`braces`,[[`path`,{d:`M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1`,key:`ezmyqa`}],[`path`,{d:`M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1`,key:`e1hn23`}]]),xe=le(`ungroup`,[[`rect`,{width:`8`,height:`6`,x:`5`,y:`4`,rx:`1`,key:`nzclkv`}],[`rect`,{width:`8`,height:`6`,x:`11`,y:`14`,rx:`1`,key:`4tytwb`}]]);r();var Se=6e4;function Ce(){let e=_({projection:`slim`});return o(()=>(e.data??[]).map(e=>({id:e.id,name:e.name,stableId:e.stableId})).toSorted((e,t)=>e.name.localeCompare(t.name)),[e.data])}function we(e){let t=p();return s({queryKey:[`automation`,`device-caps`,e],enabled:e>0,staleTime:Se,queryFn:async()=>{let n=await t.trpcClient.deviceManager.getBindings.query({deviceId:e});return[...new Set(n.entries.map(e=>e.capName))].sort((e,t)=>e.localeCompare(t))}})}function Te(e){let t=p();return s({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:Se,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function Ee(e,t){return e.find(e=>e.cap===t)?.fields??[]}function De(){let e=new Set;for(let t of Object.values(I))t.capScope===`device`&&e.add(t.capName);return[...e].sort((e,t)=>e.localeCompare(t))}function Oe(e){if(e===``)return[];let t=new Set;for(let[n,r]of Object.entries(I)){if(r.capName!==e||r.capScope!==`device`||r.access===`view`)continue;let i=n.slice(n.indexOf(`.`)+1);i!==``&&t.add(i)}return[...t].sort((e,t)=>e.localeCompare(t))}function H({children:e}){return d(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function ke(e){let t=Te(e.deviceId);if(t.data!==void 0)return Ee(t.data,e.cap).find(t=>t.path===e.fieldPath)}function Ae({value:e,devices:t,onChange:n}){let r=Te(e.deviceId),a=r.data??[],o=Ee(a,e.cap);return i(c,{children:[i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(H,{children:`Device`}),d(b,{value:String(e.deviceId),onChange:e=>n({deviceId:Number(e.target.value),cap:``,fieldPath:``}),options:[{value:`0`,label:`Select a device…`},...t.map(e=>({value:String(e.id),label:e.name}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(H,{children:`Capability`}),d(b,{value:e.cap,disabled:e.deviceId===0,onChange:t=>n({...e,cap:t.target.value,fieldPath:``}),options:[{value:``,label:je(e.deviceId,a.length,r.isLoading)},...a.map(e=>({value:e.cap,label:e.cap}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(H,{children:`Field`}),d(b,{value:e.fieldPath,disabled:e.cap===``,onChange:t=>n({...e,fieldPath:t.target.value}),options:[{value:``,label:o.length===0?`No readable fields`:`Select a field…`},...o.map(e=>({value:e.path,label:`${e.path} (${e.kind})`}))]})]})]})}function je(e,t,n){return e===0?`Pick a device first`:n?`Reading this device…`:t===0?`This device reports no readable capabilities`:`Select a capability…`}var Me=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function Ne(e){switch(e){case`boolean`:return[`eq`,`ne`];case`number`:return[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`];case`string`:case`enum`:return[`eq`,`ne`,`contains`,`in`];default:return Me}}function Pe(e){switch(e){case`eq`:return`is`;case`ne`:return`is not`;case`gt`:return`is above`;case`gte`:return`is at least`;case`lt`:return`is below`;case`lte`:return`is at most`;case`contains`:return`contains`;default:return`is one of`}}function Fe(e){return Ne(e).map(e=>({value:e,label:Pe(e)}))}function Ie(e){switch(e){case`device-state`:return`A device field changes`;case`device-event`:return`An event happens`;case`schedule`:return`On a schedule`;default:return`Only when run by hand`}}var Le={triggers:[],actions:[]};function Re(e){switch(e){case`device-state`:return{kind:e,deviceId:0,cap:``,fieldPath:``};case`device-event`:return{kind:e,category:``};case`schedule`:return{kind:e,cron:`0 30 23 * * *`};default:return{kind:`manual`}}}function ze(e){switch(e){case`wait`:return{kind:e,seconds:5};case`code`:return{kind:e,code:`// runs inside this automation, with ctx in scope
1
+ import{I as e,K as t,M as n,Q as r,S as i,T as a,W as o,a as s,b as c,q as l,t as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Q as p}from"./player-overlays-o9jF7-FW.js";import{Ft as m,It as h,J as g,Kr as _,Lt as v,Nt as y,Pt as b,Rt as x,V as S,X as C,Xt as w,bt as T,dt as E,ft as D,g as O,it as k,lt as A,un as j,ut as M,vt as N,yt as P}from"./src-D9QFy74P.js";import{Ut as F,W as I,_t as ee,bt as L,dt as R,gt as z,vt as te,yt as ne}from"./src-4oGT5Voh.js";import{t as re}from"./boxes-CZnbLP9P.js";import{t as ie}from"./pencil-DoE75RwV.js";import{t as ae}from"./play-B84SrcvR.js";import{t as B}from"./plus-CezysZVA.js";import{t as oe}from"./rotate-cw-seLHMWMS.js";import{E as se,F as ce,J as le,L as ue,Q as de,S as fe,a as pe,m as me,o as V,w as he,z as ge}from"./index-COjcrxBt.js";import{t as _e}from"./AdminPage-CCD07UMs.js";var ve=le(`arrow-down`,[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]),ye=le(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),be=le(`braces`,[[`path`,{d:`M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1`,key:`ezmyqa`}],[`path`,{d:`M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1`,key:`e1hn23`}]]),xe=le(`ungroup`,[[`rect`,{width:`8`,height:`6`,x:`5`,y:`4`,rx:`1`,key:`nzclkv`}],[`rect`,{width:`8`,height:`6`,x:`11`,y:`14`,rx:`1`,key:`4tytwb`}]]);r();var Se=6e4;function Ce(){let e=_({projection:`slim`});return o(()=>(e.data??[]).map(e=>({id:e.id,name:e.name,stableId:e.stableId})).toSorted((e,t)=>e.name.localeCompare(t.name)),[e.data])}function we(e){let t=p();return s({queryKey:[`automation`,`device-caps`,e],enabled:e>0,staleTime:Se,queryFn:async()=>{let n=await t.trpcClient.deviceManager.getBindings.query({deviceId:e});return[...new Set(n.entries.map(e=>e.capName))].sort((e,t)=>e.localeCompare(t))}})}function Te(e){let t=p();return s({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:Se,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function Ee(e,t){return e.find(e=>e.cap===t)?.fields??[]}function De(){let e=new Set;for(let t of Object.values(I))t.capScope===`device`&&e.add(t.capName);return[...e].sort((e,t)=>e.localeCompare(t))}function Oe(e){if(e===``)return[];let t=new Set;for(let[n,r]of Object.entries(I)){if(r.capName!==e||r.capScope!==`device`||r.access===`view`)continue;let i=n.slice(n.indexOf(`.`)+1);i!==``&&t.add(i)}return[...t].sort((e,t)=>e.localeCompare(t))}function H({children:e}){return d(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function ke(e){let t=Te(e.deviceId);if(t.data!==void 0)return Ee(t.data,e.cap).find(t=>t.path===e.fieldPath)}function Ae({value:e,devices:t,onChange:n}){let r=Te(e.deviceId),a=r.data??[],o=Ee(a,e.cap);return i(c,{children:[i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(H,{children:`Device`}),d(b,{value:String(e.deviceId),onChange:e=>n({deviceId:Number(e.target.value),cap:``,fieldPath:``}),options:[{value:`0`,label:`Select a device…`},...t.map(e=>({value:String(e.id),label:e.name}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(H,{children:`Capability`}),d(b,{value:e.cap,disabled:e.deviceId===0,onChange:t=>n({...e,cap:t.target.value,fieldPath:``}),options:[{value:``,label:je(e.deviceId,a.length,r.isLoading)},...a.map(e=>({value:e.cap,label:e.cap}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(H,{children:`Field`}),d(b,{value:e.fieldPath,disabled:e.cap===``,onChange:t=>n({...e,fieldPath:t.target.value}),options:[{value:``,label:o.length===0?`No readable fields`:`Select a field…`},...o.map(e=>({value:e.path,label:`${e.path} (${e.kind})`}))]})]})]})}function je(e,t,n){return e===0?`Pick a device first`:n?`Reading this device…`:t===0?`This device reports no readable capabilities`:`Select a capability…`}var Me=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function Ne(e){switch(e){case`boolean`:return[`eq`,`ne`];case`number`:return[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`];case`string`:case`enum`:return[`eq`,`ne`,`contains`,`in`];default:return Me}}function Pe(e){switch(e){case`eq`:return`is`;case`ne`:return`is not`;case`gt`:return`is above`;case`gte`:return`is at least`;case`lt`:return`is below`;case`lte`:return`is at most`;case`contains`:return`contains`;default:return`is one of`}}function Fe(e){return Ne(e).map(e=>({value:e,label:Pe(e)}))}function Ie(e){switch(e){case`device-state`:return`A device field changes`;case`device-event`:return`An event happens`;case`schedule`:return`On a schedule`;default:return`Only when run by hand`}}var Le={triggers:[],actions:[]};function Re(e){switch(e){case`device-state`:return{kind:e,deviceId:0,cap:``,fieldPath:``};case`device-event`:return{kind:e,category:``};case`schedule`:return{kind:e,cron:`0 30 23 * * *`};default:return{kind:`manual`}}}function ze(e){switch(e){case`wait`:return{kind:e,seconds:5};case`code`:return{kind:e,code:`// runs inside this automation, with ctx in scope
2
2
  `};default:return{kind:`cap`,deviceId:0,cap:``,method:``}}}function Be(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function Ve(){return{kind:`expression`,expr:``,bindings:{}}}function He(e,t,n){return e.map((e,r)=>r===t?n:e)}function Ue(e,t){return e.filter((e,n)=>n!==t)}function We(e,t,n){let r=e[t];if(r===void 0)return e;let i=Math.min(Math.max(n,0),e.length-1);if(i===t)return e;let a=Ue(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function Ge(e,t){return{...e,triggers:[...t]}}function Ke(e,t){return{...e,actions:[...t]}}var qe=`deviceId`,Je=`$trigger`,Ye=[{value:`cap`,label:`Do something`},{value:`wait`,label:`Wait`},{value:`code`,label:`Run code`}];function Xe({actions:e,devices:t,onChange:n}){return i(`div`,{className:`space-y-2`,children:[e.length===0&&d(`p`,{className:`text-xs text-warning`,children:`No actions yet. An automation that does nothing is not an automation.`}),e.map((r,a)=>i(`div`,{className:`rounded border border-border p-3 space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(v,{variant:`default`,children:a+1}),i(`label`,{className:`w-40`,children:[d(H,{children:`Step`}),d(b,{value:r.kind,onChange:t=>n(He(e,a,ze(Ze(t.target.value)))),options:Ye.map(e=>({value:e.value,label:e.label}))})]}),i(`div`,{className:`ml-auto flex items-center gap-1`,children:[d(x,{variant:`ghost`,disabled:a===0,onClick:()=>n(We(e,a,a-1)),title:`Run this step earlier`,children:d(ye,{className:`h-3.5 w-3.5`})}),d(x,{variant:`ghost`,disabled:a===e.length-1,onClick:()=>n(We(e,a,a+1)),title:`Run this step later`,children:d(ve,{className:`h-3.5 w-3.5`})}),d(x,{variant:`ghost`,onClick:()=>n(Ue(e,a)),title:`Remove this step`,children:d(V,{className:`h-3.5 w-3.5`})})]})]}),r.kind===`wait`&&i(`label`,{className:`block w-32`,children:[d(H,{children:`Seconds`}),d(m,{type:`number`,min:0,max:300,value:String(r.seconds),onChange:t=>n(He(e,a,{kind:`wait`,seconds:Number(t.target.value)}))})]}),r.kind===`code`&&i(`label`,{className:`block`,children:[d(H,{children:`Code`}),d(`textarea`,{className:`h-32 w-full rounded-md border border-border bg-surface p-2 font-mono text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,value:r.code,spellCheck:!1,onChange:t=>n(He(e,a,{kind:`code`,code:t.target.value}))}),i(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Compiled into this automation's own block by the same compiler as a script — not evaluated at run time. `,d(`code`,{children:`ctx`}),` and `,d(`code`,{children:`vars`}),` are in scope.`]})]}),r.kind===`cap`&&d(Qe,{action:r,devices:t,onChange:t=>n(He(e,a,t))})]},`${r.kind}-${String(a)}`)),i(`div`,{className:`flex items-center gap-2`,children:[i(x,{variant:`outline`,onClick:()=>n([...e,ze(`cap`)]),children:[d(B,{className:`h-4 w-4`}),` Step`]}),e.length>1&&d(`span`,{className:`text-xs text-foreground-subtle`,children:`Steps run in order and stop at the first failure.`})]})]})}function Ze(e){return Ye.find(t=>t.value===e)?.value??`cap`}function Qe({action:e,devices:t,onChange:n}){let r=typeof e.deviceId!=`number`,a=typeof e.deviceId==`number`?e.deviceId:0,o=we(a),s=r?De():o.data??[],c=Oe(e.cap);return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(H,{children:`Device`}),d(b,{value:r?Je:String(a),onChange:t=>n({...e,deviceId:t.target.value===Je?{$var:qe}:Number(t.target.value),cap:``,method:``}),options:[{value:`0`,label:`Select a device…`},{value:Je,label:`The device that triggered this run`},...t.map(e=>({value:String(e.id),label:e.name}))]})]}),i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(H,{children:`Capability`}),d(b,{value:e.cap,disabled:s.length===0,onChange:t=>n({...e,cap:t.target.value,method:``}),options:[{value:``,label:s.length===0?`Pick a device first`:`Select a capability…`},...s.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(H,{children:`Method`}),d(b,{value:e.method,disabled:c.length===0,onChange:t=>n({...e,method:t.target.value}),options:[{value:``,label:c.length===0?`Pick a capability first`:`Select a method…`},...c.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[10rem] flex-1`,children:[d(H,{children:`Arguments (JSON)`}),d(m,{value:e.args===void 0?``:JSON.stringify(e.args),placeholder:`{"mode":"away"}`,onChange:t=>n($e(e,t.target.value))})]})]})}function $e(e,t){if(t.trim()===``)return{kind:`cap`,deviceId:e.deviceId,cap:e.cap,method:e.method};try{let n=JSON.parse(t);if(typeof n!=`object`||!n||Array.isArray(n))return e;let r={};for(let[e,t]of Object.entries(n))r[e]=t;return{...e,args:r}}catch{return e}}function et({value:e,field:t,onChange:n}){return t?.kind===`boolean`?d(b,{value:e===!0?`true`:`false`,onChange:e=>n(e.target.value===`true`),options:[{value:`true`,label:`true`},{value:`false`,label:`false`}]}):t?.kind===`enum`&&t.enumValues!==void 0&&t.enumValues.length>0?d(b,{value:String(e),onChange:e=>n(e.target.value),options:t.enumValues.map(e=>({value:e,label:e}))}):t?.kind===`number`?d(m,{type:`number`,value:typeof e==`number`?String(e):``,placeholder:`0`,onChange:e=>{let t=Number(e.target.value);e.target.value!==``&&!Number.isNaN(t)&&n(t)}}):d(m,{value:String(e),placeholder:`value`,onChange:e=>n(e.target.value)})}function tt({value:e,field:t,onChange:n}){return d(m,{value:e.join(`, `),placeholder:`one, two, three`,onChange:e=>{let r=e.target.value.split(`,`).map(e=>e.trim()).filter(e=>e!==``);n(t?.kind===`number`?r.map(e=>Number(e)).filter(e=>!Number.isNaN(e)):r)}})}function nt(e){return typeof e==`object`}function rt(e){return nt(e)?e[0]??``:e}function it(e){return nt(e)?e:typeof e==`boolean`?[]:[e]}function at({leaf:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=ke(r),o=Fe(a?.kind),s=e.operator===`in`,c=t=>{n({...e,deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath})},l=t=>{let r=ot(t,o);n({...e,operator:r,value:r===`in`?it(e.value):rt(e.value)})};return i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(Ae,{value:r,devices:t,onChange:c}),i(`label`,{className:`min-w-[8rem]`,children:[d(H,{children:`Comparison`}),d(b,{value:e.operator,onChange:e=>l(e.target.value),options:o.map(e=>({value:e.value,label:e.label}))})]}),i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(H,{children:`Value`}),s?d(tt,{value:it(e.value),field:a,onChange:t=>n({...e,value:t})}):d(et,{value:rt(e.value),field:a,onChange:t=>n({...e,value:t})})]})]})}function ot(e,t){return t.find(t=>t.value===e)?.value??`eq`}var st={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function ct({leaf:e,devices:t,onChange:n}){let r=Object.entries(e.bindings),a=t=>{n({kind:`expression`,expr:e.expr,bindings:t})};return i(`div`,{className:`space-y-2`,children:[i(`label`,{className:`block`,children:[d(H,{children:`Expression`}),d(m,{value:e.expr,placeholder:`indoor - outdoor > 5`,onChange:t=>n({kind:`expression`,expr:t.target.value,bindings:e.bindings})}),d(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:`Must evaluate to true or false. Every name in it has to be bound below — an unbound name is refused when the automation is saved, not when it runs.`})]}),i(`div`,{className:`space-y-1.5`,children:[r.length===0&&d(`p`,{className:`text-xs text-foreground-subtle`,children:`No names bound yet. An expression reads devices only through these.`}),r.map(([n,r])=>d(lt,{alias:n,source:r,devices:t,onRename:t=>a(ht(e.bindings,n,t)),onChange:t=>a({...e.bindings,[n]:t}),onRemove:()=>a(gt(e.bindings,n))},n)),i(x,{variant:`ghost`,onClick:()=>a({...e.bindings,[mt(e.bindings)]:st}),children:[d(B,{className:`h-3.5 w-3.5`}),` Name`]})]})]})}function lt({alias:e,source:t,devices:n,onRename:r,onChange:a,onRemove:o}){let s=t.kind===`literal`,c=s?{deviceId:0,cap:``,fieldPath:``}:{deviceId:ft(n,dt(t)),cap:t.cap,fieldPath:t.fieldPath};return i(`div`,{className:`flex flex-wrap items-end gap-2 rounded border border-border p-2`,children:[i(`label`,{className:`w-32`,children:[d(H,{children:`Name`}),d(m,{value:e,placeholder:`indoor`,onChange:e=>r(e.target.value)})]}),i(`label`,{className:`w-36`,children:[d(H,{children:`Reads`}),d(b,{value:s?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:st),options:[{value:`global`,label:`A device field`},{value:`literal`,label:`A constant`}]})]}),s?i(`label`,{className:`min-w-[9rem] flex-1`,children:[d(H,{children:`Constant`}),d(m,{value:t.value===null?``:String(t.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:ut(e.target.value)})})]}):d(Ae,{value:c,devices:n,onChange:e=>a({kind:`global`,sourceStableId:pt(n,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),d(x,{variant:`ghost`,onClick:o,title:`Remove this name`,children:d(V,{className:`h-3.5 w-3.5`})})]})}function ut(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function dt(e){return e.kind===`global`?e.sourceStableId:``}function ft(e,t){return e.find(e=>e.stableId===t)?.id??0}function pt(e,t){return e.find(e=>e.id===t)?.stableId??``}function mt(e){for(let t=0;t<26;t+=1){let n=String.fromCharCode(97+t);if(!(n in e))return n}return`n${String(Object.keys(e).length)}`}function ht(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function gt(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function U(e){return e.kind===`all`||e.kind===`any`}function W(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:U(t)?t:{kind:`all`,children:[t]}}function _t(e,t){return t===null||U(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function vt(e){return _t(e,W(e))}function G(e,t){if(t.length===0)return e;let[n,...r]=t;if(n===void 0)return e;if(e.kind===`not`)return n===0?G(e.child,r):null;if(!U(e))return null;let i=e.children[n];return i===void 0?null:G(i,r)}function K(e,t,n){if(t.length===0)return n(e);let[r,...i]=t;if(r===void 0)return n(e);if(e.kind===`not`){if(r!==0)return e;let t=K(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!U(e))return e;let a=e.children[r];if(a===void 0)return e;let o=K(a,i,n),s=o===null?[...e.children.slice(0,r),...e.children.slice(r+1)]:[...e.children.slice(0,r),o,...e.children.slice(r+1)];return s.length===0?null:{kind:e.kind,children:s}}function yt(e){return e===null?null:L({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function bt(e){let t=W(e);return{depth:t.children.length===0?0:te(t),leaves:t.children.length===0?0:ne(t),depthLimit:3,leafLimit:32}}function xt(e,t){let n=yt(t);return n===null?{ok:!0,recipe:_t(e,t)}:{ok:!1,reason:n}}function St(e,t){let n=W(e);return xt(e,{kind:n.kind,children:[...n.children,t]})}function Ct(e,t,n){return _t(e,K(W(e),t,()=>n))}function wt(e,t){return _t(e,K(W(e),t,()=>null))}function Tt(e,t,n){return _t(e,K(W(e),t,e=>U(e)?{kind:n,children:e.children}:e))}function Et(e,t){return G(W(e),t)===null?{ok:!1,reason:`that row is no longer there`}:xt(e,K(W(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function Dt(e){if(e.length===0)return null;let t=e[e.length-1];return t===void 0?null:{path:e.slice(0,-1),index:t}}function Ot(e,t,n){if(t.length<2)return{ok:!1,reason:`select at least two rows — a group of one is just the row`};if(new Set(t.map(e=>e.slice(0,-1).join(`/`))).size!==1)return{ok:!1,reason:`those rows are in different groups — a group can only be made from rows side by side`};let r=Dt(t[0]??[]);if(r===null)return{ok:!1,reason:`the root list cannot be grouped into itself`};let i=W(e),a=G(i,r.path);if(a===null||!U(a))return{ok:!1,reason:`those rows are inside a NOT — remove it before grouping them`};let o=[...t.map(e=>e[e.length-1]??-1)].sort((e,t)=>e-t),s=o.map(e=>a.children[e]).filter(e=>e!==void 0);if(s.length!==o.length)return{ok:!1,reason:`one of the selected rows is no longer there`};let c=a.children.filter((e,t)=>!o.includes(t)),l=o[0]??0,u={kind:n,children:s},d={kind:a.kind,children:[...c.slice(0,l),u,...c.slice(l)]};return xt(e,K(i,r.path,()=>d))}function kt(e,t){if(t.length===0)return{ok:!1,reason:`the outer list is not a group — there is nothing to dissolve`};let n=W(e),r=G(n,t);if(r===null)return{ok:!1,reason:`that group is no longer there`};if(r.kind===`not`)return xt(e,K(n,t,()=>r.child));if(!U(r))return{ok:!1,reason:`that row is a condition, not a group`};let i=Dt(t);if(i===null)return{ok:!1,reason:`that group has no parent to dissolve into`};let a=G(n,i.path);if(a===null||!U(a))return{ok:!1,reason:`a group inside a NOT cannot be dissolved in place`};let o={kind:a.kind,children:[...a.children.slice(0,i.index),...r.children,...a.children.slice(i.index+1)]};return xt(e,K(n,i.path,()=>o))}r();var At=[{value:`all`,label:`ALL of`},{value:`any`,label:`ANY of`}];function jt(e){return e.join(`/`)}function Mt(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function Nt({recipe:e,devices:t,onChange:n}){let[r,a]=l([]),[s,c]=l(null),u=W(e),f=bt(e),p=o(()=>r.map(Mt),[r]),m=e=>{if(!e.ok){c(e.reason);return}c(null),a([]),n(e.recipe)},h=Ot(e,p,`all`),g=Ot(e,p,`any`),_=p.length===1?Et(e,p[0]??[]):{ok:!1,reason:`select exactly one row to negate`},y={devices:t,selected:new Set(r),onToggleSelect:e=>a(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),onUpdate:(t,r)=>n(Ct(e,t,r)),onRemove:t=>{a([]),n(wt(e,t))},onSetKind:(t,r)=>n(Tt(e,t,r)),onUngroup:t=>m(kt(e,t))};return i(`div`,{className:`space-y-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(v,{variant:`default`,children:`And only if`}),d(`div`,{className:`w-32`,children:d(b,{value:u.kind,onChange:t=>n(Tt(e,[],Pt(t.target.value))),options:At})}),i(`span`,{className:`text-xs text-foreground-subtle`,children:[`depth `,f.depth,`/`,f.depthLimit,` · `,f.leaves,`/`,f.leafLimit,` conditions`]})]}),u.children.length===0?d(`p`,{className:`text-xs text-foreground-subtle`,children:`No conditions. The actions run every time a trigger fires.`}):d(Ft,{container:u,path:[],handlers:y}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(x,{variant:`outline`,onClick:()=>m(St(e,Be())),title:`Compare one device field to a value`,children:[d(B,{className:`h-4 w-4`}),` Condition`]}),i(x,{variant:`outline`,onClick:()=>m(St(e,Ve())),title:`Arithmetic across device fields — the bounded expression engine`,children:[d(be,{className:`h-4 w-4`}),` Expression`]}),d(`span`,{className:`mx-1 h-5 w-px bg-border`}),d(x,{variant:`ghost`,disabled:!h.ok,onClick:()=>m(h),title:h.ok?`All selected rows must be true`:h.reason,children:`Group as ALL`}),d(x,{variant:`ghost`,disabled:!g.ok,onClick:()=>m(g),title:g.ok?`Any one of the selected rows is enough`:g.reason,children:`Group as ANY`}),d(x,{variant:`ghost`,disabled:!_.ok,onClick:()=>m(_),title:_.ok?`Invert the selected row`:_.reason,children:`NOT`}),r.length>0&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[r.length,` selected`]})]}),s!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-2 text-xs text-warning`,children:s})]})}function Pt(e){return e===`any`?`any`:`all`}function Ft({container:e,path:t,handlers:n}){return d(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>d(It,{node:e,path:[...t,r],handlers:n},jt([...t,r])))})}function It({node:e,path:t,handlers:n}){let r=jt(t),a=d(y,{checked:n.selected.has(r),onChange:()=>n.onToggleSelect(r),"aria-label":`Select this row for grouping`});return U(e)?i(`div`,{className:`rounded border border-border bg-surface-subtle/40 p-2`,children:[i(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[a,d(`div`,{className:`w-32`,children:d(b,{value:e.kind,onChange:e=>n.onSetKind(t,Pt(e.target.value)),options:At})}),i(x,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Dissolve this group, keeping its rows`,children:[d(xe,{className:`h-3.5 w-3.5`}),` Ungroup`]}),d(x,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Delete this group and everything in it`,children:d(V,{className:`h-3.5 w-3.5`})})]}),d(`div`,{className:`pl-4`,children:d(Ft,{container:e,path:t,handlers:n})})]}):e.kind===`not`?i(`div`,{className:`rounded border border-border p-2`,children:[i(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[a,d(v,{variant:`warning`,children:`NOT`}),i(x,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Remove the NOT, keeping the row`,children:[d(xe,{className:`h-3.5 w-3.5`}),` Remove NOT`]})]}),d(`div`,{className:`pl-4`,children:d(It,{node:e.child,path:[...t,0],handlers:n})})]}):i(`div`,{className:`flex items-start gap-2 rounded border border-border p-2`,children:[d(`div`,{className:`pt-6`,children:a}),d(`div`,{className:`min-w-0 flex-1`,children:e.kind===`condition`?d(at,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)}):d(ct,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)})}),d(x,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Remove this condition`,children:d(V,{className:`h-3.5 w-3.5`})})]})}r();function Lt({code:e,error:t,canEject:n,ejecting:r,onEject:a}){let[o,s]=l(!1),c=j(),u=async()=>{await c({title:`Eject to code — this cannot be undone`,message:`The recipe is removed from the block and it becomes an ordinary script. The visual editor will no longer open it, and there is no way back to it except authoring a new automation from scratch. The code itself is kept exactly as it is now.`,confirmLabel:`Eject to code`,cancelLabel:`Keep it visual`,variant:`warning`})&&a()};return i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2 px-3 py-2`,children:[i(x,{variant:`ghost`,onClick:()=>s(!o),children:[d(o?ge:ue,{className:`h-4 w-4`}),`Generated code`]}),d(`span`,{className:`text-xs text-foreground-subtle`,children:`Derived from the recipe above — regenerated on every save, never edited here.`}),i(x,{className:`ml-auto`,variant:`ghost`,disabled:!n||e===null||r,onClick:()=>void u(),title:n?`Take permanent ownership of this code as a script`:`Save the automation first — there is no stored block to eject yet`,children:[d(fe,{className:`h-4 w-4`}),` Eject to code`]})]}),o&&d(`div`,{className:`border-t border-border p-3`,children:e===null?d(`p`,{className:`text-xs text-warning`,children:t??`The recipe is not complete enough to generate a block yet.`}):d(k,{maxHeight:420,children:e})})]})}var Rt=[`device-state`,`device-event`,`schedule`,`manual`],zt=Object.values(F).sort((e,t)=>e.localeCompare(t));function Bt({triggers:e,devices:t,onChange:n}){return i(`div`,{className:`space-y-2`,children:[e.length===0&&d(`p`,{className:`text-xs text-warning`,children:`No triggers yet. Without one nothing can ever start this automation — not even "Run actions", which needs a manual trigger to have somewhere to arrive.`}),e.map((r,i)=>d(Vt,{trigger:r,devices:t,position:i,onChange:t=>n(He(e,i,t)),onRemove:()=>n(Ue(e,i))},`${r.kind}-${String(i)}`)),i(x,{variant:`outline`,onClick:()=>n([...e,Re(`device-state`)]),title:`Add another way this automation can start`,children:[d(B,{className:`h-4 w-4`}),` Trigger`]})]})}function Vt({trigger:e,devices:t,position:n,onChange:r,onRemove:a}){return i(`div`,{className:`rounded border border-border p-3`,children:[i(`div`,{className:`flex flex-wrap items-end gap-2`,children:[d(v,{variant:`default`,children:n===0?`When`:`or when`}),i(`label`,{className:`min-w-[13rem] flex-1`,children:[d(H,{children:`Trigger`}),d(b,{value:e.kind,onChange:e=>r(Re(Ht(e.target.value))),options:Rt.map(e=>({value:e,label:Ie(e)}))})]}),d(x,{variant:`ghost`,onClick:a,title:`Remove this trigger`,children:d(V,{className:`h-4 w-4`})})]}),i(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:[e.kind===`device-state`&&d(Ut,{trigger:e,devices:t,onChange:r}),e.kind===`device-event`&&d(Gt,{trigger:e,devices:t,onChange:r}),e.kind===`schedule`&&i(`label`,{className:`min-w-[14rem] flex-1`,children:[d(H,{children:`Cron expression`}),d(m,{value:e.cron,placeholder:`0 30 23 * * *`,onChange:e=>r({kind:`schedule`,cron:e.target.value})}),i(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Six fields, seconds first. `,d(`code`,{children:`0 30 23 * * *`}),` is every night at 23:30.`]})]}),e.kind===`manual`&&i(`p`,{className:`text-xs text-foreground-subtle`,children:[`Runs only when someone presses `,d(`strong`,{children:`Run actions`}),`. The conditions are still evaluated — a manual run is a run, not an override.`]})]})]})}function Ht(e){return Rt.find(t=>t===e)??`manual`}function q(e,t){return{kind:`device-state`,deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath,...t.becomes===void 0?{}:{becomes:t.becomes},...t.edge===void 0?{}:{edge:t.edge},...t.forMs===void 0?{}:{forMs:t.forMs},...t.debounceMs===void 0?{}:{debounceMs:t.debounceMs}}}function Ut({trigger:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},a=ke(r),o={...e.becomes===void 0?{}:{becomes:e.becomes},...e.edge===void 0?{}:{edge:e.edge},...e.forMs===void 0?{}:{forMs:e.forMs},...e.debounceMs===void 0?{}:{debounceMs:e.debounceMs}};return i(c,{children:[d(Ae,{value:r,devices:t,onChange:e=>n(q(e,o))}),i(`div`,{className:`min-w-[11rem] flex-1`,children:[d(H,{children:`Becomes`}),i(`div`,{className:`flex items-center gap-2`,children:[i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(y,{checked:e.becomes===void 0,onChange:e=>n(q(r,{...o,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),`any change`]}),e.becomes!==void 0&&d(et,{value:e.becomes,field:a,onChange:e=>n(q(r,{...o,becomes:e}))})]})]}),i(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[d(y,{checked:e.edge===!0,onChange:e=>n(q(r,{...o,...e.target.checked?{edge:!0}:{edge:void 0}}))}),`only on a change`]}),i(`label`,{className:`w-28`,children:[d(H,{children:`Held for (s)`}),d(m,{type:`number`,min:0,value:e.forMs===void 0?``:String(e.forMs/1e3),placeholder:`0`,onChange:e=>n(q(r,{...o,forMs:Wt(e.target.value)}))})]}),i(`label`,{className:`w-28`,children:[d(H,{children:`Debounce (s)`}),d(m,{type:`number`,min:0,value:e.debounceMs===void 0?``:String(e.debounceMs/1e3),placeholder:`0`,onChange:e=>n(q(r,{...o,debounceMs:Wt(e.target.value)}))})]})]})}function Wt(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function Gt({trigger:e,devices:t,onChange:n}){return i(c,{children:[i(`label`,{className:`min-w-[15rem] flex-1`,children:[d(H,{children:`Event category`}),d(b,{value:e.category,onChange:t=>n({kind:`device-event`,category:t.target.value,...e.deviceId===void 0?{}:{deviceId:e.deviceId}}),options:[{value:``,label:`Select an event…`},...zt.map(e=>({value:e,label:e}))]})]}),i(`label`,{className:`min-w-[11rem] flex-1`,children:[d(H,{children:`From device`}),d(b,{value:e.deviceId===void 0?``:String(e.deviceId),onChange:t=>n({kind:`device-event`,category:e.category,...t.target.value===``?{}:{deviceId:Number(t.target.value)}}),options:[{value:``,label:`Any device`},...t.map(e=>({value:String(e.id),label:e.name}))]})]})]})}r();var Kt=`hub`;function qt({existing:e,initialRecipe:t,saving:n,saveError:r,ejecting:a,onSave:s,onEject:c,onCancel:u}){let[f,p]=l(e?.name??``),[_,y]=l(()=>vt(t)),[b,S]=l(!1),C=Ce(),w=L(_),T=o(()=>Yt(_),[_]),E=o(()=>Xt(f.trim()===``?`Untitled automation`:f.trim(),_),[f,_]),D=f.trim()===``,O=D||w!==null||T!==null||E.code===null;return d(h,{children:i(`div`,{className:`space-y-4 p-4`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`h3`,{className:`font-medium`,children:e===null?`New automation`:`Edit ${e.name}`}),d(v,{variant:`info`,children:`runs on the hub`})]}),i(`label`,{className:`block max-w-md text-sm`,children:[d(`span`,{className:`text-foreground-subtle`,children:`Name`}),d(m,{className:`mt-1`,value:f,onChange:e=>p(e.target.value),placeholder:`What this automation does`})]}),d(Jt,{step:`1`,title:`When`,subtitle:`Any one of these starts a run.`,children:d(Bt,{triggers:_.triggers,devices:C,onChange:e=>y(Ge(_,e))})}),d(Jt,{step:`2`,title:`And only if`,subtitle:`Checked after a trigger fires. Nothing runs unless this is true.`,children:d(Nt,{recipe:_,devices:C,onChange:y})}),d(Jt,{step:`3`,title:`Then`,subtitle:`In this order, stopping at the first failure.`,children:d(Xe,{actions:_.actions,devices:C,onChange:e=>y(Ke(_,e))})}),d(Lt,{code:E.code,error:E.error,canEject:e!==null,ejecting:a,onEject:c}),b&&e!==null&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:R(e.id)})]}),d(g,{addonId:R(e.id),maxHeight:`max-h-64`,showFilters:!1})]}),w!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:w}),w===null&&T!==null&&d(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:T}),r!==null&&d(`p`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:r}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(x,{onClick:()=>{E.code!==null&&s({name:f.trim(),code:E.code,enabled:e?.enabled??!0,placement:Kt})},disabled:n||O,children:[n&&d(he,{className:`h-4 w-4 animate-spin`}),` Save`]}),i(x,{variant:`ghost`,onClick:()=>S(!b),disabled:e===null,title:e===null?`Logs appear once the automation has been saved and started`:`Show this automation's process logs`,children:[d(me,{className:`h-4 w-4`}),` Logs`]}),d(x,{variant:`ghost`,onClick:u,disabled:n,children:`Close`}),D&&d(v,{variant:`warning`,children:`Name required`})]})]})})}function Jt({step:e,title:t,subtitle:n,children:r}){return i(`section`,{className:`border-l-2 border-border pl-4`,children:[i(`div`,{className:`mb-2 flex flex-wrap items-baseline gap-2`,children:[d(`span`,{className:`text-xs font-mono text-foreground-subtle`,children:e}),d(`h4`,{className:`text-sm font-medium uppercase tracking-wide`,children:t}),d(`span`,{className:`text-xs text-foreground-subtle`,children:n})]}),r]})}function Yt(e){let t=ee.safeParse(e);if(t.success)return null;let n=t.error.issues[0];return n===void 0?`this automation is not complete yet`:`${n.path.length===0?``:`${n.path.join(`.`)}: `}${n.message}`}function Xt(e,t){try{return{code:z({name:e,recipe:t}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function J(e){if(!e.enabled)return{tone:`idle`,label:`Disabled`,detail:`Not started — the block is turned off.`};switch(e.status){case`running`:return{tone:`ok`,label:`Running`,detail:`One process, supervised.`};case`starting`:return{tone:`pending`,label:`Starting`,detail:e.lastError??`Waiting for the process to report ready.`};case`failed`:return{tone:`error`,label:`Failed`,detail:e.lastError??`Failed with no reason recorded — check the node logs.`};default:return{tone:`error`,label:`Not running`,detail:e.lastError??`Enabled but no process is running. The supervisor reconciles every 15s; if this persists, the node may not be running a block supervisor.`}}}function Zt(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function Qt(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function $t(e){let t=e=>{let t=J(e).tone;return t===`error`?0:t===`pending`?1:t===`ok`?2:3};return[...e].sort((e,n)=>t(e)-t(n)||e.name.localeCompare(n.name))}function en(e){if(e.length===0)return`No blocks yet.`;let t=e.filter(e=>J(e).tone===`error`).length,n=e.filter(e=>J(e).tone===`ok`).length,r=[`${String(e.length)} block${e.length===1?``:`s`}`];return n>0&&r.push(`${String(n)} running`),t>0&&r.push(`${String(t)} NOT running`),r.join(` · `)}function tn({block:e,busy:t,confirming:n,logsOpen:r,unreadable:a,onEdit:o,onToggle:s,onToggleLogs:c,onAskDelete:l,onCancelDelete:u,onConfirmDelete:f}){let p=J(e),m=S(e.updatedAt);return i(`li`,{className:`flex flex-col gap-2 p-3`,children:[i(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`span`,{className:`truncate font-medium`,children:e.name}),d(v,{variant:Zt(p.tone),children:p.label}),m!==null&&i(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,m]})]}),d(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:p.detail}),a!==null&&i(`p`,{className:`mt-0.5 text-xs text-warning`,children:[`Its recipe cannot be read (`,a,`), so it cannot be opened visually. The code is intact and still running — edit it as a script.`]})]}),n?i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this automation?`}),d(x,{variant:`danger`,onClick:f,disabled:t,children:`Delete`}),d(x,{variant:`ghost`,onClick:u,children:`Cancel`})]}):i(`div`,{className:`flex items-center gap-2`,children:[d(x,{variant:`ghost`,onClick:o,disabled:a!==null,title:a===null?`Edit`:`This block cannot be opened visually`,children:d(ie,{className:`h-4 w-4`})}),i(N,{children:[d(T,{children:d(x,{variant:`ghost`,disabled:!0,title:`Run actions`,children:d(ae,{className:`h-4 w-4`})})}),d(P,{children:`Running an automation by hand needs the automation-control authority, which is not wired up yet. There is deliberately no second way to execute one.`})]}),d(x,{variant:`ghost`,onClick:c,title:`Logs`,children:d(me,{className:`h-4 w-4`})}),d(x,{variant:`ghost`,onClick:()=>s(!e.enabled),disabled:t,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),d(x,{variant:`ghost`,onClick:l,title:`Delete`,children:d(V,{className:`h-4 w-4`})})]})]}),r&&i(`div`,{className:`rounded border border-border`,children:[i(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,d(`code`,{children:R(e.id)})]}),d(g,{addonId:R(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function nn({onCreate:e}){return d(h,{children:i(`div`,{className:`space-y-2 p-4`,children:[d(`p`,{className:`text-sm text-foreground`,children:`No automations yet.`}),d(`p`,{className:`max-w-2xl text-xs text-foreground-subtle`,children:`An automation is a trigger, a set of conditions and a list of actions. It compiles to an ordinary block and runs in its own supervised process — there is no separate engine, so anything that goes wrong shows up here with a reason.`}),d(x,{onClick:e,children:`New automation`})]})})}var rn=`const AUTOMATION_RECIPE =`,an=`// EJECTED from the visual automation editor — this file is now hand-owned.
3
3
  // The recipe that produced it was removed with it, on purpose: while it was
4
4
  // here the editor could re-open this block and overwrite everything below.`;function on(e){return e.includes(rn)}function sn(e){let t=e.indexOf(rn);if(t<0)return null;let n=e.indexOf(`{`,t+25);if(n<0)return null;let r=0,i=!1,a=!1;for(let o=n;o<e.length;o+=1){let s=e.charAt(o);if(i){a?a=!1:s===`\\`?a=!0:s===`"`&&(i=!1);continue}if(s===`"`){i=!0;continue}if(s===`{`)r+=1;else if(s===`}`&&(--r,r===0))return{declStart:t,literalEnd:o+1,json:e.slice(n,o+1)}}return null}function cn(e){let t=sn(e);if(t===null)return{ok:!1,reason:`this block carries no AUTOMATION_RECIPE literal`};let n;try{n=JSON.parse(t.json)}catch(e){return{ok:!1,reason:`the embedded recipe is not readable JSON: ${e instanceof Error?e.message:String(e)}`}}let r=ee.safeParse(n);if(!r.success){let e=r.error.issues[0];return{ok:!1,reason:`the embedded recipe does not match the recipe schema${e===void 0?``:` at ${e.path.join(`.`)}: ${e.message}`}`}}return{ok:!0,recipe:r.data}}function ln(e){let t=sn(e);if(t===null)return e;let n=e.slice(t.literalEnd),r=/^\s*as\s+const/.exec(n),i=t.literalEnd+(r===null?0:r[0].length);return`${e.slice(0,t.declStart)}${an}${e.slice(i)}`}r();var un=[`coreBlocks`,`list`],dn=5e3;function Y(e){return e instanceof Error?e.message:String(e)}function fn({onOpenScripts:e}){let t=p(),[n,r]=l({mode:`closed`}),[a,o]=l(null),[c,f]=l(null),m=s({queryKey:un,refetchInterval:dn,queryFn:async()=>(await t.trpcClient.coreBlocks.list.query({})).blocks}),g=()=>{m.refetch()},_=u({mutationFn:e=>t.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{r({mode:`edit`,block:e.block}),g()}}),v=u({mutationFn:e=>t.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{r({mode:`edit`,block:e.block}),g()}}),y=u({mutationFn:e=>t.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{o(null),g()}}),b=u({mutationFn:e=>t.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:g}),S=u({mutationFn:e=>t.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:ln(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:t=>{r({mode:`closed`}),g(),e(t.block.id)}}),C=m.data,T=$t((C??[]).filter(e=>on(e.code))),E=C!==void 0&&T.length===0,D=n.mode===`edit`&&n.block!==null?Qt(T,n.block):null,O=D===null?null:cn(D.code),k=_.error===null?v.error===null?S.error===null?null:Y(S.error):Y(v.error):Y(_.error);return i(`div`,{className:`space-y-3`,children:[i(`div`,{className:`flex items-center justify-between gap-3`,children:[d(`p`,{className:`text-xs text-foreground-subtle`,children:C===void 0?``:en(T)}),i(x,{onClick:()=>r({mode:`edit`,block:null}),children:[d(B,{className:`h-4 w-4`}),` New automation`]})]}),m.error!=null&&d(w,{title:`Could not read the automations`,message:Y(m.error),onRetry:g}),n.mode===`edit`&&d(qt,{existing:D,initialRecipe:O!==null&&O.ok?O.recipe:Le,saving:_.isPending||v.isPending,saveError:k,ejecting:S.isPending,onSave:e=>{D===null?_.mutate(e):v.mutate({blockId:D.id,block:e})},onEject:()=>{D!==null&&S.mutate(D)},onCancel:()=>{_.reset(),v.reset(),S.reset(),r({mode:`closed`})}},D?.id??`new`),E&&d(nn,{onCreate:()=>r({mode:`edit`,block:null})}),T.length>0&&d(h,{children:d(`ul`,{className:`divide-y divide-border`,children:T.map(e=>{let t=cn(e.code);return d(tn,{block:e,busy:b.isPending||y.isPending,confirming:a===e.id,logsOpen:c===e.id,unreadable:t.ok?null:t.reason,onEdit:()=>r({mode:`edit`,block:e}),onToggle:t=>b.mutate({blockId:e.id,enabled:t}),onToggleLogs:()=>f(c===e.id?null:e.id),onAskDelete:()=>o(e.id),onCancelDelete:()=>o(null),onConfirmDelete:()=>y.mutate(e.id)},e.id)})})}),y.error!=null&&d(w,{message:Y(y.error)}),b.error!=null&&d(w,{message:Y(b.error)})]})}function pn({onOpenScripts:e}){return d(h,{children:i(`div`,{className:`max-w-2xl space-y-3 p-6`,children:[i(`div`,{className:`flex items-center gap-2`,children:[d(re,{className:`h-5 w-5 text-foreground-subtle`}),d(`h3`,{className:`font-medium`,children:`Composed devices are not built yet`})]}),i(`p`,{className:`text-sm text-foreground-subtle`,children:[`A composed device will be a real device — its own row, its own name, its own on/off — with its state `,d(`strong`,{children:`derived from other devices`}),` and, optionally, methods that forward to them. Because it is a device row and not an overlay, it reaches HomeKit, Alexa, Home Assistant and the notification rules with nothing having to learn about it.`]}),i(`p`,{className:`text-sm text-foreground-subtle`,children:[`Nothing is hidden behind this section: no device can be declared this way yet, so there is no list to show and no form that would work. A `,d(`strong`,{children:`script`}),` is the surface that exists today — it runs in its own supervised process with the full addon context, which is the same context a composed device will be built on.`]}),d(x,{variant:`outline`,onClick:e,children:`Write a script instead`})]})})}function mn(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function hn(e){if(Array.isArray(e))return e}function gn(e,t,n){return(t=Tn(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function _n(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t!==0)for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function vn(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
@@ -1 +1 @@
1
- import{Q as e,S as t,W as n,a as r,q as i,t as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Q as s}from"./player-overlays-DWqOEI94.js";import{Xt as c}from"./src-rZAVP-8-.js";import{t as l}from"./circle-check-big-0DidlcLj.js";import{I as u,u as d,w as f}from"./index-MHuc7l_c.js";import{t as p}from"./AdminPage-CCD07UMs.js";e();var m={detection:`border-green-500`,detector:`border-green-500`,streaming:`border-blue-500`,decode:`border-blue-500`,decoder:`border-blue-500`,recording:`border-orange-500`,recorder:`border-orange-500`,transcoding:`border-purple-500`,transcoder:`border-purple-500`,restream:`border-cyan-500`,restreamer:`border-cyan-500`,storage:`border-yellow-500`,notification:`border-pink-500`,notifier:`border-pink-500`,faces:`border-indigo-500`},h={detection:`bg-green-500/5`,detector:`bg-green-500/5`,streaming:`bg-blue-500/5`,decode:`bg-blue-500/5`,decoder:`bg-blue-500/5`,recording:`bg-orange-500/5`,recorder:`bg-orange-500/5`,transcoding:`bg-purple-500/5`,transcoder:`bg-purple-500/5`,restream:`bg-cyan-500/5`,restreamer:`bg-cyan-500/5`,storage:`bg-yellow-500/5`,notification:`bg-pink-500/5`,notifier:`bg-pink-500/5`,faces:`bg-indigo-500/5`};function g({entry:e,actions:n}){let r=e.name.toLowerCase(),i=m[r]??`border-primary`,a=h[r]??`bg-primary/5`,s=e.providers.find(e=>e.active),c=n?.pendingCapability===e.name;return t(`div`,{className:`rounded-lg border-t-2 border border-border ${i} ${a} p-3 space-y-2`,children:[t(`div`,{className:`flex items-center justify-between gap-2`,children:[t(`span`,{className:`text-xs font-semibold text-foreground capitalize flex items-center gap-1.5`,children:[e.name,c&&o(f,{className:`h-3 w-3 animate-spin text-primary`})]}),o(`span`,{className:`rounded-full px-2 py-0.5 text-[10px] font-medium ${e.mode===`singleton`?`bg-primary/10 text-primary`:`bg-info/10 text-info`}`,children:e.mode})]}),e.mode===`singleton`?o(_,{entry:e,actions:n,activeProvider:s,isPending:c}):o(v,{entry:e,actions:n,isPending:c})]})}function _({entry:e,actions:n,activeProvider:r,isPending:i}){if(!n)return o(`div`,{children:r?t(`div`,{className:`flex items-center gap-1.5 text-[10px] text-foreground`,children:[o(l,{className:`h-3 w-3 text-green-400 shrink-0`}),o(`span`,{className:`font-medium`,children:r.addonName}),o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto`,children:`ACTIVE`})]}):o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No active provider`})});if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});let a=`__inherit__`;return t(`div`,{className:`space-y-2`,children:[o(`div`,{className:`space-y-1`,children:e.providers.map(r=>{let a=r.active;return t(`button`,{type:`button`,disabled:i||a,onClick:()=>n.onSelectSingleton(e.name,r.addonId),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${a?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${a?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:r.addonName}),a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},r.addonId)})}),e.perNode&&e.perNode.length>0&&o(`div`,{className:`space-y-2 pt-1 border-t border-border/40`,children:e.perNode.map(r=>{let s=r.hasOverride&&r.resolvedActive?r.resolvedActive:a,c=[{value:a,label:`Inherit global${r.resolvedActive?` (${r.resolvedActive})`:``}`},...r.providers.map(e=>({value:e,label:e}))],l=t=>{t===a?n.onClearNodeSingleton(e.name,r.nodeId):n.onSelectNodeSingleton(e.name,r.nodeId,t)},u=i;return t(`div`,{className:`space-y-0.5`,children:[t(`div`,{className:`text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60 px-1.5`,children:[r.nodeId,r.hasOverride&&o(`span`,{className:`ml-1.5 rounded-full bg-primary/10 text-primary px-1 py-0.5 normal-case tracking-normal font-medium`,children:`override`})]}),c.map(e=>{let n=s===e.value;return t(`button`,{type:`button`,disabled:u||n,onClick:()=>l(e.value),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${n?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${n?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:e.label}),n&&e.value!==a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},e.value)})]},r.nodeId)})})]})}function v({entry:e,actions:n,isPending:r}){if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});if(!n)return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`div`,{className:`flex items-center justify-between gap-2 text-[10px]`,children:[o(`span`,{className:`text-foreground-subtle`,children:e.addonName}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium`,children:`ACTIVE`})]},e.addonId))});let i=e.providers.filter(e=>e.active).map(e=>e.addonId),a=(t,r)=>{let a=r?[...new Set([...i,t])]:i.filter(e=>e!==t);n.onToggleCollection(e.name,a)};return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`label`,{className:`flex items-center justify-between gap-2 text-[10px] rounded px-1.5 py-1 transition-colors ${r?`opacity-50`:`hover:bg-surface-hover cursor-pointer`}`,children:[t(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[o(`input`,{type:`checkbox`,checked:e.active,disabled:r,onChange:t=>a(e.addonId,t.target.checked),className:`h-3 w-3 accent-green-500 shrink-0`}),o(`span`,{className:`text-foreground truncate`,children:e.addonName})]}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium shrink-0`,children:`ACTIVE`})]},e.addonId))})}function y({capabilities:e,actions:t}){return e.length===0?o(`div`,{className:`text-xs text-foreground-subtle text-center py-8`,children:`No capabilities registered`}):o(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3`,children:e.map(e=>o(g,{entry:e,actions:t},e.name))})}var b=[`capabilities`,`listCapabilities`];function x(e){return e===`singleton`||e===`collection`}function S(e){let t=e.indexOf(`@`);return t===-1?`${e} (hub)`:`${e.slice(0,t)} (${e.slice(t+1)})`}function C(e,t){return{name:e.name,mode:t,providers:e.providers.map(n=>({addonId:n,addonName:S(n),active:t===`singleton`?e.activeProvider===n:!e.disabledProviders.includes(n)})),...t===`singleton`&&e.perNode?{perNode:e.perNode}:{}}}function w(){let e=s(),[f,m]=i(null),[h,g]=i(null),_=r({queryKey:b,queryFn:()=>e.trpcClient.capabilities.listCapabilities.query()}),v=n(()=>{let e=(_.data??[]).flatMap(e=>x(e.mode)?[C(e,e.mode)]:[]),t=e.filter(e=>e.mode===`singleton`).toSorted((e,t)=>e.name.localeCompare(t.name)),n=e.filter(e=>e.mode===`collection`).toSorted((e,t)=>e.name.localeCompare(t.name));return[...t,...n]},[_.data]),S=n(()=>v.filter(e=>e.mode===`singleton`),[v]),w=n(()=>v.filter(e=>e.mode===`collection`),[v]),T=a({mutationFn:t=>e.trpcClient.capabilities.setActiveSingleton.mutate({capability:t.capName,addonId:t.addonId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} → ${t.addonId} is now active.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),E=a({mutationFn:t=>e.trpcClient.capabilities.setActiveSingleton.mutate({capability:t.capName,addonId:t.addonId,nodeId:t.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} → ${t.addonId}.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),D=a({mutationFn:t=>e.trpcClient.capabilities.clearSingletonNodeOverride.mutate({capability:t.capName,nodeId:t.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} now inherits the global default.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to clear ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),O=a({mutationFn:t=>e.trpcClient.capabilities.setCollectionEnabledProviders.mutate({capability:t.capName,enabledAddonIds:[...t.enabledAddonIds]}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName}: ${t.enabledAddonIds.length} provider(s) enabled.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to update ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),k={onSelectSingleton:(e,t)=>T.mutate({capName:e,addonId:t}),onSelectNodeSingleton:(e,t,n)=>E.mutate({capName:e,nodeId:t,addonId:n}),onClearNodeSingleton:(e,t)=>D.mutate({capName:e,nodeId:t}),onToggleCollection:(e,t)=>O.mutate({capName:e,enabledAddonIds:t}),pendingCapability:f};return t(p,{icon:d,title:`Capabilities`,subtitle:`Choose which provider is active for each system capability. Singleton caps pick exactly one provider; collection caps enable a set.`,children:[h&&t(`div`,{className:`flex items-center gap-2 rounded-md border px-3 py-2 text-xs ${h.kind===`success`?`border-green-500/30 bg-green-500/10 text-green-700 dark:text-green-300`:`border-danger/40 bg-danger/10 text-danger`}`,children:[h.kind===`success`?o(l,{className:`h-3.5 w-3.5 shrink-0`}):o(u,{className:`h-3.5 w-3.5 shrink-0`}),o(`span`,{children:h.message})]}),_.isLoading&&o(`div`,{className:`flex items-center justify-center py-16`,children:o(`div`,{className:`animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full`})}),_.isError&&!_.isLoading&&o(c,{title:`Failed to load capabilities`,message:_.error instanceof Error?_.error.message:`Unknown error`,onRetry:()=>void _.refetch()}),!_.isLoading&&!_.isError&&v.length===0&&o(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No capabilities registered.`}),!_.isLoading&&!_.isError&&v.length>0&&t(`div`,{className:`space-y-6`,children:[S.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Singleton — pick one provider`}),o(y,{capabilities:S,actions:k})]}),w.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Collection — enable a set`}),o(y,{capabilities:w,actions:k})]})]})]})}export{w as CapabilitiesPage,w as default};
1
+ import{Q as e,S as t,W as n,a as r,q as i,t as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Q as s}from"./player-overlays-o9jF7-FW.js";import{Xt as c}from"./src-D9QFy74P.js";import{t as l}from"./circle-check-big-BvHeM1LY.js";import{I as u,u as d,w as f}from"./index-COjcrxBt.js";import{t as p}from"./AdminPage-CCD07UMs.js";e();var m={detection:`border-green-500`,detector:`border-green-500`,streaming:`border-blue-500`,decode:`border-blue-500`,decoder:`border-blue-500`,recording:`border-orange-500`,recorder:`border-orange-500`,transcoding:`border-purple-500`,transcoder:`border-purple-500`,restream:`border-cyan-500`,restreamer:`border-cyan-500`,storage:`border-yellow-500`,notification:`border-pink-500`,notifier:`border-pink-500`,faces:`border-indigo-500`},h={detection:`bg-green-500/5`,detector:`bg-green-500/5`,streaming:`bg-blue-500/5`,decode:`bg-blue-500/5`,decoder:`bg-blue-500/5`,recording:`bg-orange-500/5`,recorder:`bg-orange-500/5`,transcoding:`bg-purple-500/5`,transcoder:`bg-purple-500/5`,restream:`bg-cyan-500/5`,restreamer:`bg-cyan-500/5`,storage:`bg-yellow-500/5`,notification:`bg-pink-500/5`,notifier:`bg-pink-500/5`,faces:`bg-indigo-500/5`};function g({entry:e,actions:n}){let r=e.name.toLowerCase(),i=m[r]??`border-primary`,a=h[r]??`bg-primary/5`,s=e.providers.find(e=>e.active),c=n?.pendingCapability===e.name;return t(`div`,{className:`rounded-lg border-t-2 border border-border ${i} ${a} p-3 space-y-2`,children:[t(`div`,{className:`flex items-center justify-between gap-2`,children:[t(`span`,{className:`text-xs font-semibold text-foreground capitalize flex items-center gap-1.5`,children:[e.name,c&&o(f,{className:`h-3 w-3 animate-spin text-primary`})]}),o(`span`,{className:`rounded-full px-2 py-0.5 text-[10px] font-medium ${e.mode===`singleton`?`bg-primary/10 text-primary`:`bg-info/10 text-info`}`,children:e.mode})]}),e.mode===`singleton`?o(_,{entry:e,actions:n,activeProvider:s,isPending:c}):o(v,{entry:e,actions:n,isPending:c})]})}function _({entry:e,actions:n,activeProvider:r,isPending:i}){if(!n)return o(`div`,{children:r?t(`div`,{className:`flex items-center gap-1.5 text-[10px] text-foreground`,children:[o(l,{className:`h-3 w-3 text-green-400 shrink-0`}),o(`span`,{className:`font-medium`,children:r.addonName}),o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto`,children:`ACTIVE`})]}):o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No active provider`})});if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});let a=`__inherit__`;return t(`div`,{className:`space-y-2`,children:[o(`div`,{className:`space-y-1`,children:e.providers.map(r=>{let a=r.active;return t(`button`,{type:`button`,disabled:i||a,onClick:()=>n.onSelectSingleton(e.name,r.addonId),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${a?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${a?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:r.addonName}),a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},r.addonId)})}),e.perNode&&e.perNode.length>0&&o(`div`,{className:`space-y-2 pt-1 border-t border-border/40`,children:e.perNode.map(r=>{let s=r.hasOverride&&r.resolvedActive?r.resolvedActive:a,c=[{value:a,label:`Inherit global${r.resolvedActive?` (${r.resolvedActive})`:``}`},...r.providers.map(e=>({value:e,label:e}))],l=t=>{t===a?n.onClearNodeSingleton(e.name,r.nodeId):n.onSelectNodeSingleton(e.name,r.nodeId,t)},u=i;return t(`div`,{className:`space-y-0.5`,children:[t(`div`,{className:`text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60 px-1.5`,children:[r.nodeId,r.hasOverride&&o(`span`,{className:`ml-1.5 rounded-full bg-primary/10 text-primary px-1 py-0.5 normal-case tracking-normal font-medium`,children:`override`})]}),c.map(e=>{let n=s===e.value;return t(`button`,{type:`button`,disabled:u||n,onClick:()=>l(e.value),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${n?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[o(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${n?`border-green-400 bg-green-400`:`border-border`}`}),o(`span`,{className:`font-medium truncate`,children:e.label}),n&&e.value!==a&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},e.value)})]},r.nodeId)})})]})}function v({entry:e,actions:n,isPending:r}){if(e.providers.length===0)return o(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});if(!n)return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`div`,{className:`flex items-center justify-between gap-2 text-[10px]`,children:[o(`span`,{className:`text-foreground-subtle`,children:e.addonName}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium`,children:`ACTIVE`})]},e.addonId))});let i=e.providers.filter(e=>e.active).map(e=>e.addonId),a=(t,r)=>{let a=r?[...new Set([...i,t])]:i.filter(e=>e!==t);n.onToggleCollection(e.name,a)};return o(`div`,{className:`space-y-1`,children:e.providers.map(e=>t(`label`,{className:`flex items-center justify-between gap-2 text-[10px] rounded px-1.5 py-1 transition-colors ${r?`opacity-50`:`hover:bg-surface-hover cursor-pointer`}`,children:[t(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[o(`input`,{type:`checkbox`,checked:e.active,disabled:r,onChange:t=>a(e.addonId,t.target.checked),className:`h-3 w-3 accent-green-500 shrink-0`}),o(`span`,{className:`text-foreground truncate`,children:e.addonName})]}),e.active&&o(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium shrink-0`,children:`ACTIVE`})]},e.addonId))})}function y({capabilities:e,actions:t}){return e.length===0?o(`div`,{className:`text-xs text-foreground-subtle text-center py-8`,children:`No capabilities registered`}):o(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3`,children:e.map(e=>o(g,{entry:e,actions:t},e.name))})}var b=[`capabilities`,`listCapabilities`];function x(e){return e===`singleton`||e===`collection`}function S(e){let t=e.indexOf(`@`);return t===-1?`${e} (hub)`:`${e.slice(0,t)} (${e.slice(t+1)})`}function C(e,t){return{name:e.name,mode:t,providers:e.providers.map(n=>({addonId:n,addonName:S(n),active:t===`singleton`?e.activeProvider===n:!e.disabledProviders.includes(n)})),...t===`singleton`&&e.perNode?{perNode:e.perNode}:{}}}function w(){let e=s(),[f,m]=i(null),[h,g]=i(null),_=r({queryKey:b,queryFn:()=>e.trpcClient.capabilities.listCapabilities.query()}),v=n(()=>{let e=(_.data??[]).flatMap(e=>x(e.mode)?[C(e,e.mode)]:[]),t=e.filter(e=>e.mode===`singleton`).toSorted((e,t)=>e.name.localeCompare(t.name)),n=e.filter(e=>e.mode===`collection`).toSorted((e,t)=>e.name.localeCompare(t.name));return[...t,...n]},[_.data]),S=n(()=>v.filter(e=>e.mode===`singleton`),[v]),w=n(()=>v.filter(e=>e.mode===`collection`),[v]),T=a({mutationFn:t=>e.trpcClient.capabilities.setActiveSingleton.mutate({capability:t.capName,addonId:t.addonId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} → ${t.addonId} is now active.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),E=a({mutationFn:t=>e.trpcClient.capabilities.setActiveSingleton.mutate({capability:t.capName,addonId:t.addonId,nodeId:t.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} → ${t.addonId}.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),D=a({mutationFn:t=>e.trpcClient.capabilities.clearSingletonNodeOverride.mutate({capability:t.capName,nodeId:t.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} now inherits the global default.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to clear ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),O=a({mutationFn:t=>e.trpcClient.capabilities.setCollectionEnabledProviders.mutate({capability:t.capName,enabledAddonIds:[...t.enabledAddonIds]}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName}: ${t.enabledAddonIds.length} provider(s) enabled.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to update ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),k={onSelectSingleton:(e,t)=>T.mutate({capName:e,addonId:t}),onSelectNodeSingleton:(e,t,n)=>E.mutate({capName:e,nodeId:t,addonId:n}),onClearNodeSingleton:(e,t)=>D.mutate({capName:e,nodeId:t}),onToggleCollection:(e,t)=>O.mutate({capName:e,enabledAddonIds:t}),pendingCapability:f};return t(p,{icon:d,title:`Capabilities`,subtitle:`Choose which provider is active for each system capability. Singleton caps pick exactly one provider; collection caps enable a set.`,children:[h&&t(`div`,{className:`flex items-center gap-2 rounded-md border px-3 py-2 text-xs ${h.kind===`success`?`border-green-500/30 bg-green-500/10 text-green-700 dark:text-green-300`:`border-danger/40 bg-danger/10 text-danger`}`,children:[h.kind===`success`?o(l,{className:`h-3.5 w-3.5 shrink-0`}):o(u,{className:`h-3.5 w-3.5 shrink-0`}),o(`span`,{children:h.message})]}),_.isLoading&&o(`div`,{className:`flex items-center justify-center py-16`,children:o(`div`,{className:`animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full`})}),_.isError&&!_.isLoading&&o(c,{title:`Failed to load capabilities`,message:_.error instanceof Error?_.error.message:`Unknown error`,onRetry:()=>void _.refetch()}),!_.isLoading&&!_.isError&&v.length===0&&o(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No capabilities registered.`}),!_.isLoading&&!_.isError&&v.length>0&&t(`div`,{className:`space-y-6`,children:[S.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Singleton — pick one provider`}),o(y,{capabilities:S,actions:k})]}),w.length>0&&t(`section`,{className:`space-y-2`,children:[o(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Collection — enable a set`}),o(y,{capabilities:w,actions:k})]})]})]})}export{w as CapabilitiesPage,w as default};
@@ -1 +1 @@
1
- import{S as e,x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{t as n}from"./circle-dot-psZ4_Yj_.js";import{n as r,t as i}from"./video-CLfrtjUD.js";import{t as a}from"./radio-DJaDrpzo.js";import{t as o}from"./refresh-cw-CnFbQxHl.js";import{t as s}from"./shield-DSd_6QdB.js";import{t as c}from"./zap-Drh_qIsL.js";import{A as l,G as u,H as d,J as f,P as p,U as m,c as h,f as g}from"./index-MHuc7l_c.js";var _=f(`battery-full`,[[`rect`,{width:`16`,height:`10`,x:`2`,y:`7`,rx:`2`,ry:`2`,key:`1w10f2`}],[`line`,{x1:`22`,x2:`22`,y1:`11`,y2:`13`,key:`4dh1rd`}],[`line`,{x1:`6`,x2:`6`,y1:`11`,y2:`13`,key:`1wd6dw`}],[`line`,{x1:`10`,x2:`10`,y1:`11`,y2:`13`,key:`haxvl5`}],[`line`,{x1:`14`,x2:`14`,y1:`11`,y2:`13`,key:`c6fn6x`}]]),v=f(`grid-2x2`,[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}]]),y=f(`map`,[[`path`,{d:`M14.106 5.553a2 2 0 0 0 1.788 0l3.659-1.83A1 1 0 0 1 21 4.619v12.764a1 1 0 0 1-.553.894l-4.553 2.277a2 2 0 0 1-1.788 0l-4.212-2.106a2 2 0 0 0-1.788 0l-3.659 1.83A1 1 0 0 1 3 19.381V6.618a1 1 0 0 1 .553-.894l4.553-2.277a2 2 0 0 1 1.788 0z`,key:`169xi5`}],[`path`,{d:`M15 5.764v15`,key:`1pn4in`}],[`path`,{d:`M9 3.236v15`,key:`1uimfh`}]]),b={streaming:{icon:i,label:`Streaming`},detection:{icon:l,label:`Detection`},recording:{icon:n,label:`Recording`},audio:{icon:r,label:`Audio`},snapshot:{icon:d,label:`Snapshot`},motion:{icon:c,label:`Motion`},ptz:{icon:g,label:`PTZ`},webrtc:{icon:a,label:`WebRTC`},onvif:{icon:s,label:`ONVIF`},analytics:{icon:p,label:`Analytics`},"battery-operated":{icon:_,label:`Battery`},"native-snapshot":{icon:d,label:`Native Snapshot`},"pan-tilt-zoom":{icon:g,label:`PTZ`},"two-way-audio":{icon:r,label:`Two-way Audio`},"doorbell-button":{icon:u,label:`Doorbell`},rebootable:{icon:o,label:`Rebootable`},"vacuum-has-map":{icon:y,label:`Map`},"vacuum-has-ai":{icon:h,label:`AI Obstacle`},"mower-has-map":{icon:y,label:`Map`},"mower-has-targeted-mowing":{icon:v,label:`Targeted Mowing`}},x=m;function S({capabilities:n,showLabels:r=!1}){return t(`div`,{className:`flex items-center gap-1 flex-wrap`,children:n.map(n=>{let i=b[n],a=i?.icon??x,o=i?.label??n;return e(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-surface-hover px-1.5 py-0.5 text-[10px] text-foreground-subtle`,title:o,children:[t(a,{className:`h-3 w-3`}),r&&t(`span`,{children:o})]},n)})})}export{S as t};
1
+ import{S as e,x as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{t as n}from"./circle-dot-BLnF4dJR.js";import{n as r,t as i}from"./video-B17QC8iA.js";import{t as a}from"./radio-BMqprMmY.js";import{t as o}from"./refresh-cw-DgGcyCy7.js";import{t as s}from"./shield-B7oln0YR.js";import{t as c}from"./zap-DcQFzh7K.js";import{A as l,G as u,H as d,J as f,P as p,U as m,c as h,f as g}from"./index-COjcrxBt.js";var _=f(`battery-full`,[[`rect`,{width:`16`,height:`10`,x:`2`,y:`7`,rx:`2`,ry:`2`,key:`1w10f2`}],[`line`,{x1:`22`,x2:`22`,y1:`11`,y2:`13`,key:`4dh1rd`}],[`line`,{x1:`6`,x2:`6`,y1:`11`,y2:`13`,key:`1wd6dw`}],[`line`,{x1:`10`,x2:`10`,y1:`11`,y2:`13`,key:`haxvl5`}],[`line`,{x1:`14`,x2:`14`,y1:`11`,y2:`13`,key:`c6fn6x`}]]),v=f(`grid-2x2`,[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 12h18`,key:`1i2n21`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}]]),y=f(`map`,[[`path`,{d:`M14.106 5.553a2 2 0 0 0 1.788 0l3.659-1.83A1 1 0 0 1 21 4.619v12.764a1 1 0 0 1-.553.894l-4.553 2.277a2 2 0 0 1-1.788 0l-4.212-2.106a2 2 0 0 0-1.788 0l-3.659 1.83A1 1 0 0 1 3 19.381V6.618a1 1 0 0 1 .553-.894l4.553-2.277a2 2 0 0 1 1.788 0z`,key:`169xi5`}],[`path`,{d:`M15 5.764v15`,key:`1pn4in`}],[`path`,{d:`M9 3.236v15`,key:`1uimfh`}]]),b={streaming:{icon:i,label:`Streaming`},detection:{icon:l,label:`Detection`},recording:{icon:n,label:`Recording`},audio:{icon:r,label:`Audio`},snapshot:{icon:d,label:`Snapshot`},motion:{icon:c,label:`Motion`},ptz:{icon:g,label:`PTZ`},webrtc:{icon:a,label:`WebRTC`},onvif:{icon:s,label:`ONVIF`},analytics:{icon:p,label:`Analytics`},"battery-operated":{icon:_,label:`Battery`},"native-snapshot":{icon:d,label:`Native Snapshot`},"pan-tilt-zoom":{icon:g,label:`PTZ`},"two-way-audio":{icon:r,label:`Two-way Audio`},"doorbell-button":{icon:u,label:`Doorbell`},rebootable:{icon:o,label:`Rebootable`},"vacuum-has-map":{icon:y,label:`Map`},"vacuum-has-ai":{icon:h,label:`AI Obstacle`},"mower-has-map":{icon:y,label:`Map`},"mower-has-targeted-mowing":{icon:v,label:`Targeted Mowing`}},x=m;function S({capabilities:n,showLabels:r=!1}){return t(`div`,{className:`flex items-center gap-1 flex-wrap`,children:n.map(n=>{let i=b[n],a=i?.icon??x,o=i?.label??n;return e(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-surface-hover px-1.5 py-0.5 text-[10px] text-foreground-subtle`,title:o,children:[t(a,{className:`h-3 w-3`}),r&&t(`span`,{children:o})]},n)})})}export{S as t};
@@ -1,4 +1,4 @@
1
- import{I as e,K as t,Q as n,S as r,V as i,W as a,b as o,o as s,q as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Q as d}from"./player-overlays-DWqOEI94.js";import{Ct as f,Go as p,Ho as m,J as h,Ka as g,Kr as _,St as v,Uo as y,Wo as b,Xs as x,Ys as S,ca as C,do as w,ds as T,ea as E,la as ee,nt as D,q as O,sa as k,ta as A,tt as te,ua as ne,un as re,wt as ie,xt as ae}from"./src-rZAVP-8-.js";import{Dt as oe}from"./src-B4NOGVsx.js";import{t as se}from"./hard-drive-download-Dj3aVgwc.js";import{t as ce}from"./pencil-MICqy4MD.js";import{t as le}from"./radio-DJaDrpzo.js";import{t as ue}from"./refresh-cw-CnFbQxHl.js";import{t as j}from"./rotate-cw-BtL-GrdV.js";import{t as de}from"./server-B4iG1vdW.js";import{B as fe,J as M,L as pe,P as me,U as he,a as N,m as ge,o as _e,p as ve,r as P,t as F,w as I,z as ye}from"./index-MHuc7l_c.js";import{t as be}from"./NodeAddonsSettingsPanel-4j9h05Vg.js";import{t as L}from"./format-size-DIxKXxtj.js";import{n as xe,r as Se,t as Ce}from"./useNodeUrlSelection-Dcb9Cmy_.js";var we=M(`arrow-down-to-line`,[[`path`,{d:`M12 17V3`,key:`1cwfxf`}],[`path`,{d:`m6 11 6 6 6-6`,key:`12ii2o`}],[`path`,{d:`M19 21H5`,key:`150jfl`}]]),Te=M(`memory-stick`,[[`path`,{d:`M6 19v-3`,key:`1nvgqn`}],[`path`,{d:`M10 19v-3`,key:`iu8nkm`}],[`path`,{d:`M14 19v-3`,key:`kcehxu`}],[`path`,{d:`M18 19v-3`,key:`1vh91z`}],[`path`,{d:`M8 11V9`,key:`63erz4`}],[`path`,{d:`M16 11V9`,key:`fru6f3`}],[`path`,{d:`M12 11V9`,key:`ha00sb`}],[`path`,{d:`M2 15h20`,key:`16ne18`}],[`path`,{d:`M2 7a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v1.1a2 2 0 0 0 0 3.837V17a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-5.1a2 2 0 0 0 0-3.837Z`,key:`lhddv3`}]]);n();function Ee(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}function De({state:e}){return l(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e===`running`?`bg-success/10 text-success`:e===`crashed`||e===`failed`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e})}var Oe=[`trace`,`debug`,`info`,`warn`,`error`];function ke({proc:e,nodeId:t,defaultExpanded:n,activePanel:i,onTogglePanel:a}){let o=e.services??[],s=o.length===1,[u,d]=c(s||n),[p,m]=c(null),[g,_]=c(`info`),y=e.name.includes(`(core)`),b=C(),x=ee(),S=ne(),w=async e=>{m(e);try{await b.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{m(null)}},T=async()=>{m(e.name);try{await x.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{m(null)}},E=async n=>{let r=`${t}/${e.name}`;try{await S.mutateAsync({nodeId:r,level:n}),_(n)}catch(e){console.error(`Failed to set log level:`,e)}};return r(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[r(`div`,{role:s?void 0:`button`,tabIndex:s?void 0:0,onClick:s?void 0:()=>d(!u),onKeyDown:s?void 0:e=>{(e.key===`Enter`||e.key===` `)&&d(!u)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${s?``:`hover:bg-muted/40 cursor-pointer`}`,children:[s?l(`span`,{className:`h-3 w-3 shrink-0`}):l(u?ye:pe,{className:`h-3 w-3 text-muted-foreground shrink-0`}),y?l(de,{className:`h-3.5 w-3.5 text-primary shrink-0`}):l(he,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),l(`span`,{className:`text-xs font-semibold flex-1`,children:e.name}),r(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`PID `,e.pid]}),l(De,{state:e.state}),r(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[e.cpuPercent,`% CPU`]}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:L(e.memoryRss)}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:Ee(e.uptimeSeconds)}),!y&&r(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[r(ae,{children:[l(ie,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:`Set log level`,children:g}),l(v,{align:`end`,className:`min-w-[70px] py-0.5`,children:Oe.map(e=>l(f,{onClick:()=>E(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===g?`text-primary font-semibold`:``}`,children:e},e))})]}),l(`button`,{onClick:T,disabled:p===e.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart process`,children:l(j,{className:`h-3 w-3 ${p===e.name?`animate-spin`:``}`})})]})]}),u&&o.length>0&&l(`div`,{className:`divide-y divide-border/30`,children:o.map(e=>r(`div`,{children:[r(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[l(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),l(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:e.addonId}),e.capabilities.length>0&&r(`div`,{className:`flex gap-1 flex-shrink-0`,children:[e.capabilities.slice(0,3).map(e=>l(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400 truncate max-w-[80px]`,children:e},e)),e.capabilities.length>3&&r(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),r(`div`,{className:`flex items-center gap-1 shrink-0`,children:[l(`button`,{onClick:()=>a(e.addonId,`logs`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show logs for ${e.addonId}`,children:l(ge,{className:`h-3 w-3`})}),l(`button`,{onClick:()=>a(e.addonId,`events`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show events for ${e.addonId}`,children:l(le,{className:`h-3 w-3`})}),l(`button`,{onClick:()=>w(e.addonId),disabled:p===e.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.addonId}`,children:l(j,{className:`h-3 w-3 ${p===e.addonId?`animate-spin`:``}`})})]})]}),i?.addonId===e.addonId&&i.type===`logs`&&l(`div`,{className:`border-t border-border/40 bg-muted/5`,children:l(h,{addonId:e.addonId,agentId:t,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>a(e.addonId,`logs`)})}),i?.addonId===e.addonId&&i.type===`events`&&l(`div`,{className:`border-t border-border/40 bg-muted/5`,children:l(O,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>a(e.addonId,`events`)})})]},e.addonId))}),u&&o.length===0&&l(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:`No services`})]})}function Ae({nodeId:e,processes:t}){let[n,r]=c(null),i=(e,t)=>{r(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?l(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No processes on this node`}):l(`div`,{className:`space-y-2 py-1`,children:t.map((t,r)=>l(ke,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}var je={system:0,managed:1,root:2};n();function Me(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m ${e%60}s`:e<86400?`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`:`${Math.floor(e/86400)}d ${Math.floor(e%86400/3600)}h`}function Ne(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function Pe({nodeId:e}){let t=s(),n=x(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:i}=A({nodeId:e}),o=n?.processes??i,c=a(()=>o?[...o]:[],[o]),u=a(()=>[{key:`classification`,header:`Class`,sortValue:e=>je[e.classification],render:e=>l(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`root`?`bg-sky-500/20 text-sky-400`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})},{key:`pid`,header:`PID`,align:`right`,sortValue:e=>e.pid,render:e=>l(`span`,{className:`font-mono`,children:e.pid})},{key:`ppid`,header:`PPID`,align:`right`,sortValue:e=>e.ppid,render:e=>l(`span`,{className:`font-mono text-foreground-subtle`,children:e.ppid})},{key:`addonId`,header:`Addon`,sortValue:e=>e.addonId,render:e=>l(`span`,{className:`text-foreground-subtle text-[11px]`,children:e.addonId??`—`})},{key:`command`,header:`Command`,nowrap:!1,render:e=>l(`span`,{className:`font-mono text-[10px] text-foreground-subtle break-all`,children:Ne(e.command)})},{key:`cpuPercent`,header:`CPU%`,align:`right`,sortValue:e=>e.cpuPercent,render:e=>e.cpuPercent.toFixed(1)},{key:`memoryRssBytes`,header:`RSS`,align:`right`,sortValue:e=>e.memoryRssBytes,render:e=>L(e.memoryRssBytes)},{key:`uptimeSec`,header:`Uptime`,align:`right`,sortValue:e=>e.uptimeSec,render:e=>l(`span`,{className:`text-foreground-subtle`,children:Me(e.uptimeSec)})}],[]);return r(`div`,{className:`space-y-4`,children:[l(`div`,{className:`flex items-start justify-end gap-4`,children:r(`button`,{type:`button`,onClick:()=>t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[l(ue,{className:`h-3 w-3`}),` Refresh`]})}),l(te,{columns:u,rows:c,rowKey:e=>e.pid,minWidthPx:880,mobileMode:`scroll`,maxBodyHeight:D,emptyMessage:`Scanning…`})]})}var R={width:320,height:64},z=.8,B=Math.ceil(8*z-3)+1,V=R.width+34,H=R.height+B+1+11,Fe=B+R.height+1+3+Math.ceil(8*z),Ie=[1,2,5,10],Le=[1,2,4,8,16,32,64,128,256,512,1024],U=[1,1.5,2,2.5,3,4,5],W=[4,3,5,2],Re=1e-9;function ze(e,t){if(!Number.isFinite(e)||e<=0)return!1;if(t===`bytes`){if(!Number.isInteger(e))return!1;let t=e/1024**Math.floor(Math.log(e)/Math.log(1024));return U.some(e=>Math.abs(t-e)<Re)}let n=e/10**Math.floor(Math.log10(e));return U.some(e=>Math.abs(n-e)<Re)}function Be(e,t,n){let r=0;for(let t of e)t!==null&&t>r&&(r=t);if(r<=t)return t;if(n===`bytes`){let e=1024**Math.floor(Math.log(r)/Math.log(1024));for(let t of Le){let n=t*e;if(n>=r)return n}return 1024*e}let i=10**Math.floor(Math.log10(r));for(let e of Ie){let t=e*i;if(t>=r)return t}return 10*i}function Ve(e,t){if(!Number.isFinite(e)||e<=0)return[];let n=W.find(n=>ze(e/n,t))??W[W.length-1],r=e/n,i=[];for(let e=1;e<=n;e++)i.push(r*e);return i}var He=2.5;function Ue(e){return e*He}function G(e,t,n,r){if(e.length===0)return[];let i=e[0].atMs,a=e.at(-1).atMs-i,o=n<=0?1:n,s=r!==void 0&&r>0?r:null;return e.map((r,c)=>{let l=a>0?(r.atMs-i)/a*t.width:c/Math.max(1,e.length-1)*t.width,u=c>0?e[c-1]:void 0;return{x:l,y:r.value===null?null:t.height-Math.min(r.value,n)/o*t.height,gapBefore:s!==null&&u!==void 0&&r.atMs-u.atMs>s}})}function K(e){let t=[],n=!1;for(let r of e){if(r.y===null){n=!1;continue}r.gapBefore&&(n=!1),t.push(`${n?`L`:`M`}${r.x.toFixed(1)},${r.y.toFixed(1)}`),n=!0}return t.join(` `)}function We(e,t){let n=[],r=[],i=()=>{if(r.length<2){r=[];return}let e=r.map((e,t)=>`${t===0?`M`:`L`}${e.x.toFixed(1)},${e.top.toFixed(1)}`),t=[...r].reverse().map(e=>`L${e.x.toFixed(1)},${e.bottom.toFixed(1)}`);n.push(`${e.join(` `)} ${t.join(` `)} Z`),r=[]};for(let n=0;n<e.length;n++){let a=e[n],o=t[n];if(!a||!o||a.y===null||o.y===null){i();continue}(a.gapBefore||o.gapBefore)&&i(),r.push({x:a.x,top:a.y,bottom:o.y})}return i(),n.join(` `)}function Ge(e,t,n=3){if(e.length<2||n<2)return[];let r=e[0].atMs,i=e.at(-1).atMs-r;if(i<=0)return[];let a=[];for(let e=0;e<n;e++){let o=e/(n-1);a.push({atMs:r+i*o,x:o*t.width,anchor:e===0?`start`:e===n-1?`end`:`middle`})}return a}function Ke(e){return e.length<2?0:Math.max(0,e.at(-1).atMs-e[0].atMs)}function qe(e){let t=[];for(let n=1;n<e.length;n++){let r=e[n];r.gapBefore&&t.push({fromX:e[n-1].x,toX:r.x})}return t}function Je(e,t){if(e.length===0)return null;let n=0,r=1/0;for(let i=0;i<e.length;i++){let a=Math.abs(e[i].x-t);a<r&&(r=a,n=i)}return n}n();var q={main:`var(--load-series-main)`,gc:`var(--load-series-gc)`},Ye=`
1
+ import{I as e,K as t,Q as n,S as r,V as i,W as a,b as o,o as s,q as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Q as d}from"./player-overlays-o9jF7-FW.js";import{Ct as f,Go as p,Ho as m,J as h,Ka as g,Kr as _,St as v,Uo as y,Wo as b,Xs as x,Ys as S,ca as C,do as w,ds as T,ea as E,la as ee,nt as D,q as O,sa as k,ta as A,tt as te,ua as ne,un as re,wt as ie,xt as ae}from"./src-D9QFy74P.js";import{Dt as oe}from"./src-4oGT5Voh.js";import{t as se}from"./hard-drive-download-BEpVEf7Q.js";import{t as ce}from"./pencil-DoE75RwV.js";import{t as le}from"./radio-BMqprMmY.js";import{t as ue}from"./refresh-cw-DgGcyCy7.js";import{t as j}from"./rotate-cw-seLHMWMS.js";import{t as de}from"./server-BIHbmJRc.js";import{B as fe,J as M,L as pe,P as me,U as he,a as N,m as ge,o as _e,p as ve,r as P,t as F,w as I,z as ye}from"./index-COjcrxBt.js";import{t as be}from"./NodeAddonsSettingsPanel-B5W0S_6w.js";import{t as L}from"./format-size-DIxKXxtj.js";import{n as xe,r as Se,t as Ce}from"./useNodeUrlSelection-BXTlDNv4.js";var we=M(`arrow-down-to-line`,[[`path`,{d:`M12 17V3`,key:`1cwfxf`}],[`path`,{d:`m6 11 6 6 6-6`,key:`12ii2o`}],[`path`,{d:`M19 21H5`,key:`150jfl`}]]),Te=M(`memory-stick`,[[`path`,{d:`M6 19v-3`,key:`1nvgqn`}],[`path`,{d:`M10 19v-3`,key:`iu8nkm`}],[`path`,{d:`M14 19v-3`,key:`kcehxu`}],[`path`,{d:`M18 19v-3`,key:`1vh91z`}],[`path`,{d:`M8 11V9`,key:`63erz4`}],[`path`,{d:`M16 11V9`,key:`fru6f3`}],[`path`,{d:`M12 11V9`,key:`ha00sb`}],[`path`,{d:`M2 15h20`,key:`16ne18`}],[`path`,{d:`M2 7a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v1.1a2 2 0 0 0 0 3.837V17a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-5.1a2 2 0 0 0 0-3.837Z`,key:`lhddv3`}]]);n();function Ee(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}function De({state:e}){return l(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e===`running`?`bg-success/10 text-success`:e===`crashed`||e===`failed`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e})}var Oe=[`trace`,`debug`,`info`,`warn`,`error`];function ke({proc:e,nodeId:t,defaultExpanded:n,activePanel:i,onTogglePanel:a}){let o=e.services??[],s=o.length===1,[u,d]=c(s||n),[p,m]=c(null),[g,_]=c(`info`),y=e.name.includes(`(core)`),b=C(),x=ee(),S=ne(),w=async e=>{m(e);try{await b.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{m(null)}},T=async()=>{m(e.name);try{await x.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{m(null)}},E=async n=>{let r=`${t}/${e.name}`;try{await S.mutateAsync({nodeId:r,level:n}),_(n)}catch(e){console.error(`Failed to set log level:`,e)}};return r(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[r(`div`,{role:s?void 0:`button`,tabIndex:s?void 0:0,onClick:s?void 0:()=>d(!u),onKeyDown:s?void 0:e=>{(e.key===`Enter`||e.key===` `)&&d(!u)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${s?``:`hover:bg-muted/40 cursor-pointer`}`,children:[s?l(`span`,{className:`h-3 w-3 shrink-0`}):l(u?ye:pe,{className:`h-3 w-3 text-muted-foreground shrink-0`}),y?l(de,{className:`h-3.5 w-3.5 text-primary shrink-0`}):l(he,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),l(`span`,{className:`text-xs font-semibold flex-1`,children:e.name}),r(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`PID `,e.pid]}),l(De,{state:e.state}),r(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[e.cpuPercent,`% CPU`]}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:L(e.memoryRss)}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:Ee(e.uptimeSeconds)}),!y&&r(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[r(ae,{children:[l(ie,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:`Set log level`,children:g}),l(v,{align:`end`,className:`min-w-[70px] py-0.5`,children:Oe.map(e=>l(f,{onClick:()=>E(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===g?`text-primary font-semibold`:``}`,children:e},e))})]}),l(`button`,{onClick:T,disabled:p===e.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart process`,children:l(j,{className:`h-3 w-3 ${p===e.name?`animate-spin`:``}`})})]})]}),u&&o.length>0&&l(`div`,{className:`divide-y divide-border/30`,children:o.map(e=>r(`div`,{children:[r(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[l(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),l(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:e.addonId}),e.capabilities.length>0&&r(`div`,{className:`flex gap-1 flex-shrink-0`,children:[e.capabilities.slice(0,3).map(e=>l(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400 truncate max-w-[80px]`,children:e},e)),e.capabilities.length>3&&r(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),r(`div`,{className:`flex items-center gap-1 shrink-0`,children:[l(`button`,{onClick:()=>a(e.addonId,`logs`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show logs for ${e.addonId}`,children:l(ge,{className:`h-3 w-3`})}),l(`button`,{onClick:()=>a(e.addonId,`events`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show events for ${e.addonId}`,children:l(le,{className:`h-3 w-3`})}),l(`button`,{onClick:()=>w(e.addonId),disabled:p===e.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.addonId}`,children:l(j,{className:`h-3 w-3 ${p===e.addonId?`animate-spin`:``}`})})]})]}),i?.addonId===e.addonId&&i.type===`logs`&&l(`div`,{className:`border-t border-border/40 bg-muted/5`,children:l(h,{addonId:e.addonId,agentId:t,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>a(e.addonId,`logs`)})}),i?.addonId===e.addonId&&i.type===`events`&&l(`div`,{className:`border-t border-border/40 bg-muted/5`,children:l(O,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>a(e.addonId,`events`)})})]},e.addonId))}),u&&o.length===0&&l(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:`No services`})]})}function Ae({nodeId:e,processes:t}){let[n,r]=c(null),i=(e,t)=>{r(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?l(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No processes on this node`}):l(`div`,{className:`space-y-2 py-1`,children:t.map((t,r)=>l(ke,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}var je={system:0,managed:1,root:2};n();function Me(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m ${e%60}s`:e<86400?`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`:`${Math.floor(e/86400)}d ${Math.floor(e%86400/3600)}h`}function Ne(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function Pe({nodeId:e}){let t=s(),n=x(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:i}=A({nodeId:e}),o=n?.processes??i,c=a(()=>o?[...o]:[],[o]),u=a(()=>[{key:`classification`,header:`Class`,sortValue:e=>je[e.classification],render:e=>l(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`root`?`bg-sky-500/20 text-sky-400`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})},{key:`pid`,header:`PID`,align:`right`,sortValue:e=>e.pid,render:e=>l(`span`,{className:`font-mono`,children:e.pid})},{key:`ppid`,header:`PPID`,align:`right`,sortValue:e=>e.ppid,render:e=>l(`span`,{className:`font-mono text-foreground-subtle`,children:e.ppid})},{key:`addonId`,header:`Addon`,sortValue:e=>e.addonId,render:e=>l(`span`,{className:`text-foreground-subtle text-[11px]`,children:e.addonId??`—`})},{key:`command`,header:`Command`,nowrap:!1,render:e=>l(`span`,{className:`font-mono text-[10px] text-foreground-subtle break-all`,children:Ne(e.command)})},{key:`cpuPercent`,header:`CPU%`,align:`right`,sortValue:e=>e.cpuPercent,render:e=>e.cpuPercent.toFixed(1)},{key:`memoryRssBytes`,header:`RSS`,align:`right`,sortValue:e=>e.memoryRssBytes,render:e=>L(e.memoryRssBytes)},{key:`uptimeSec`,header:`Uptime`,align:`right`,sortValue:e=>e.uptimeSec,render:e=>l(`span`,{className:`text-foreground-subtle`,children:Me(e.uptimeSec)})}],[]);return r(`div`,{className:`space-y-4`,children:[l(`div`,{className:`flex items-start justify-end gap-4`,children:r(`button`,{type:`button`,onClick:()=>t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[l(ue,{className:`h-3 w-3`}),` Refresh`]})}),l(te,{columns:u,rows:c,rowKey:e=>e.pid,minWidthPx:880,mobileMode:`scroll`,maxBodyHeight:D,emptyMessage:`Scanning…`})]})}var R={width:320,height:64},z=.8,B=Math.ceil(8*z-3)+1,V=R.width+34,H=R.height+B+1+11,Fe=B+R.height+1+3+Math.ceil(8*z),Ie=[1,2,5,10],Le=[1,2,4,8,16,32,64,128,256,512,1024],U=[1,1.5,2,2.5,3,4,5],W=[4,3,5,2],Re=1e-9;function ze(e,t){if(!Number.isFinite(e)||e<=0)return!1;if(t===`bytes`){if(!Number.isInteger(e))return!1;let t=e/1024**Math.floor(Math.log(e)/Math.log(1024));return U.some(e=>Math.abs(t-e)<Re)}let n=e/10**Math.floor(Math.log10(e));return U.some(e=>Math.abs(n-e)<Re)}function Be(e,t,n){let r=0;for(let t of e)t!==null&&t>r&&(r=t);if(r<=t)return t;if(n===`bytes`){let e=1024**Math.floor(Math.log(r)/Math.log(1024));for(let t of Le){let n=t*e;if(n>=r)return n}return 1024*e}let i=10**Math.floor(Math.log10(r));for(let e of Ie){let t=e*i;if(t>=r)return t}return 10*i}function Ve(e,t){if(!Number.isFinite(e)||e<=0)return[];let n=W.find(n=>ze(e/n,t))??W[W.length-1],r=e/n,i=[];for(let e=1;e<=n;e++)i.push(r*e);return i}var He=2.5;function Ue(e){return e*He}function G(e,t,n,r){if(e.length===0)return[];let i=e[0].atMs,a=e.at(-1).atMs-i,o=n<=0?1:n,s=r!==void 0&&r>0?r:null;return e.map((r,c)=>{let l=a>0?(r.atMs-i)/a*t.width:c/Math.max(1,e.length-1)*t.width,u=c>0?e[c-1]:void 0;return{x:l,y:r.value===null?null:t.height-Math.min(r.value,n)/o*t.height,gapBefore:s!==null&&u!==void 0&&r.atMs-u.atMs>s}})}function K(e){let t=[],n=!1;for(let r of e){if(r.y===null){n=!1;continue}r.gapBefore&&(n=!1),t.push(`${n?`L`:`M`}${r.x.toFixed(1)},${r.y.toFixed(1)}`),n=!0}return t.join(` `)}function We(e,t){let n=[],r=[],i=()=>{if(r.length<2){r=[];return}let e=r.map((e,t)=>`${t===0?`M`:`L`}${e.x.toFixed(1)},${e.top.toFixed(1)}`),t=[...r].reverse().map(e=>`L${e.x.toFixed(1)},${e.bottom.toFixed(1)}`);n.push(`${e.join(` `)} ${t.join(` `)} Z`),r=[]};for(let n=0;n<e.length;n++){let a=e[n],o=t[n];if(!a||!o||a.y===null||o.y===null){i();continue}(a.gapBefore||o.gapBefore)&&i(),r.push({x:a.x,top:a.y,bottom:o.y})}return i(),n.join(` `)}function Ge(e,t,n=3){if(e.length<2||n<2)return[];let r=e[0].atMs,i=e.at(-1).atMs-r;if(i<=0)return[];let a=[];for(let e=0;e<n;e++){let o=e/(n-1);a.push({atMs:r+i*o,x:o*t.width,anchor:e===0?`start`:e===n-1?`end`:`middle`})}return a}function Ke(e){return e.length<2?0:Math.max(0,e.at(-1).atMs-e[0].atMs)}function qe(e){let t=[];for(let n=1;n<e.length;n++){let r=e[n];r.gapBefore&&t.push({fromX:e[n-1].x,toX:r.x})}return t}function Je(e,t){if(e.length===0)return null;let n=0,r=1/0;for(let i=0;i<e.length;i++){let a=Math.abs(e[i].x-t);a<r&&(r=a,n=i)}return n}n();var q={main:`var(--load-series-main)`,gc:`var(--load-series-gc)`},Ye=`
2
2
  .load-chart-scope { --load-series-main: #2a78d6; --load-series-gc: #e87ba4; }
3
3
  @media (prefers-color-scheme: dark) {
4
4
  :root:not([data-theme="light"]) .load-chart-scope {
@@ -1 +1 @@
1
- import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{$n as l,Fn as u,Jo as d,Ko as f,Qn as p,Zn as m,ar as h,cr as g,er as _,ir as v,nr as y,or as b,qo as x,rr as S,sr as C,ss as w,tr as T,un as E}from"./src-rZAVP-8-.js";import{t as D}from"./circle-slash-Byu8-oUY.js";import{t as O}from"./circle-x-DgOvPSCw.js";import{t as k}from"./clock-OlU3cIuc.js";import{t as A}from"./download-BthqNrtL.js";import{i as j,n as M,r as N,t as P}from"./AddLocationWizard-CdoufjHB.js";import{t as F}from"./hard-drive-download-Dj3aVgwc.js";import{t as ee}from"./hard-drive-BL3oY1u7.js";import{t as I}from"./pencil-MICqy4MD.js";import{t as te}from"./play-DmW_NZO9.js";import{t as ne}from"./plus-ShS1ufOP.js";import{t as L}from"./rotate-cw-BtL-GrdV.js";import{F as re,J as R,K as ie,L as ae,o as z,r as B,w as V,z as oe}from"./index-MHuc7l_c.js";import{t as H}from"./AdminPage-CCD07UMs.js";import{r as U}from"./authed-media-BPd_L9jr.js";import{t as W}from"./AdminTabs-fwNNU8c7.js";import{t as G}from"./format-size-DIxKXxtj.js";var K=R(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),q=R(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),se=R(`ban`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m4.9 4.9 14.2 14.2`,key:`1m5liu`}]]),ce=R(`calendar-clock`,[[`path`,{d:`M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5`,key:`1osxxc`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M17.5 17.5 16 16.3V14`,key:`akvzfd`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]),le=R(`cloud-upload`,[[`path`,{d:`M12 13v8`,key:`1l5pq0`}],[`path`,{d:`M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242`,key:`1pljnt`}],[`path`,{d:`m8 17 4-4 4 4`,key:`1quai1`}]]);t();function ue(){let e=a(),t=E(),{data:i,isLoading:c,isError:l}=d({}),u=x(),p=r(()=>u.data??[],[u.data]),[m,h]=o(null),[g,_]=o(null),v=f({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),y=w({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),b=(e,t)=>{y.mutate(j(e,{enabled:t}))},S=(e,t)=>{y.mutate(j(e,{readOnly:t}))},C=async e=>{if(await t({title:`Delete location "${e.displayName}"?`,message:`This removes the location record. Files on disk are not deleted; the underlying directory or remote path stays untouched.`,confirmLabel:`Delete`,variant:`danger`}))try{await v.mutateAsync({id:e.id})}catch(n){await t({title:`Delete anyway?`,message:`${n instanceof Error?n.message:String(n)}\n\nForcing the delete removes the record only. Anything still on that location becomes unreachable — index rows naming it stop resolving, and playback of those segments goes silently black rather than erroring.`,confirmLabel:`Force delete`,variant:`danger`})&&v.mutate({id:e.id,force:!0})}},T=r(()=>{let e=new Map;for(let t of i??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[i]),D=c||u.isLoading,O=l||u.isError;return n(H,{children:[D&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),O&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!D&&!O&&n(`div`,{className:`space-y-3`,children:[p.length===0&&s(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:`No storage locations declared by any installed addon.`}),p.map(e=>s(N,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:T.get(e.id)??[],onAdd:e=>h(e),onEdit:e=>_(e),onDelete:e=>{C(e)},onToggleEnabled:(e,t)=>b(e,t),onToggleReadOnly:(e,t)=>S(e,t)},e.id))]}),m!==null&&s(P,{initialType:m,onClose:()=>h(null),onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),h(null)}}),g!==null&&s(M,{location:g,onClose:()=>_(null),onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),_(null)}})]})}t();var de=[[`backup`,`listDestinations`]],fe=[`backup`,`listArchives`];function pe({destinationId:t,restoreSupported:i,onOpenRestoreWizard:c}){let l=a(),u=E(),{data:d,isLoading:f,isError:m}=T({destinationId:t}),h=d??[],g=p({onSuccess:()=>{l.invalidateQueries({queryKey:[[...fe]]}),l.invalidateQueries({queryKey:de})}}),_=e(async e=>{await u({title:`Delete this archive?`,message:`Permanently deletes "${e.label??e.id}" and frees ${G(e.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&g.mutate({destinationId:t,backupId:e.id})},[u,t,g]),[v,y]=o(null),b=e(async e=>{y(e.id);try{let n=await U(me(t,e.id)),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.label??e.id}.tar.gz`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}finally{y(null)}},[t]),x=r(()=>[...h].toSorted((e,t)=>t.createdAt-e.createdAt),[h]);return f?s(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):m?s(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):x.length===0?s(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):s(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`When`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),s(`tbody`,{children:x.map(e=>n(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:he(e.createdAt)}),s(`td`,{className:`px-3 py-1.5 text-foreground`,children:e.label??s(`span`,{className:`text-foreground-subtle italic`,children:`—`})}),s(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:e.locations.join(`, `)}),s(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:G(e.sizeBytes)}),s(`td`,{className:`px-3 py-1.5`,children:n(`div`,{className:`flex items-center justify-end gap-1`,children:[n(`button`,{onClick:()=>{b(e)},disabled:v===e.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:text-foreground hover:bg-primary/10 disabled:opacity-50`,title:`Download archive`,children:[v===e.id?s(V,{className:`h-3 w-3 animate-spin`}):s(A,{className:`h-3 w-3`}),`Download`]}),i&&c&&n(`button`,{onClick:()=>c({destinationId:t,archiveId:e.id}),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-primary hover:bg-primary/10`,title:`Restore from this archive`,children:[s(L,{className:`h-3 w-3`}),`Restore`]}),s(`button`,{onClick:()=>{_(e)},disabled:g.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete archive`,children:g.isPending?s(V,{className:`h-3 w-3 animate-spin`}):s(z,{className:`h-3 w-3`})})]})})]},e.id))})]})})}function me(e,t){return`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}function he(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}t();var J=[[`backup`,`listSchedules`]];function ge({onEdit:e,onOpenRestoreWizard:t}){let{data:i,isLoading:a,isError:c}=v(),l=i??[],u=y().data??[],d=r(()=>{let e=new Map;for(let t of u)e.set(t.id,t);return e},[u]),[f,p]=o(null),m=e=>{p(t=>t===e?null:e)};return a?s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading backup entries…`}):c?s(`div`,{className:`text-xs text-danger`,children:`Failed to load backup entries`}):l.length===0?s(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-8 text-center`,children:s(`p`,{className:`text-xs text-foreground-subtle`,children:`No backup entries yet. Create one to schedule backups across one or more storage locations.`})}):s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[820px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle border-b border-border bg-background/40`,children:[s(`th`,{className:`text-left px-3 py-2 font-medium w-6`}),s(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Entry`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-20`,children:`Enabled`}),s(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Locations`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-24`,children:`Retention`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-48`,children:`Schedule`}),s(`th`,{className:`text-right px-3 py-2 font-medium w-52`,children:`Actions`})]})}),s(`tbody`,{children:l.map(n=>s(_e,{row:n,destById:d,isOpen:f===n.id,onToggle:()=>m(n.id),onEdit:()=>e(n),...t?{onOpenRestoreWizard:t}:{}},n.id))})]})})}function _e({row:t,destById:u,isOpen:d,onToggle:f,onEdit:p,onOpenRestoreWizard:m}){let h=a(),_=E(),v=g({onSuccess:()=>{h.invalidateQueries({queryKey:J})}}),y=l({onSuccess:()=>{h.invalidateQueries({queryKey:J})}}),b=C({onMutate:()=>{h.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})},onSuccess:()=>{h.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),h.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),h.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})}}),[x,S]=o(String(t.retentionCount));c(()=>{S(String(t.retentionCount))},[t.retentionCount]);let w=r(()=>({id:t.id,label:t.label,cron:t.cron,locationIds:[...t.locationIds],retentionCount:t.retentionCount,...t.dataSources?{dataSources:[...t.dataSources]}:{}}),[t]),T=e(e=>{v.mutate({...w,enabled:e})},[v,w]),D=e(()=>{let e=Number.parseInt(x,10);if(Number.isNaN(e)||e<1){S(String(t.retentionCount));return}e!==t.retentionCount&&v.mutate({...w,enabled:t.enabled,retentionCount:e})},[v,w,x,t.retentionCount,t.enabled]),O=e(()=>{t.locationIds.length!==0&&b.mutate({destinations:[...t.locationIds],...t.dataSources&&t.dataSources.length>0?{locations:[...t.dataSources]}:{},label:t.label,retentionCount:t.retentionCount})},[b,t]),k=e(async()=>{await _({title:`Delete backup entry?`,message:`"${t.label||t.id}" will stop running. Existing archives are kept.`,confirmLabel:`Delete`,variant:`warning`})&&y.mutate({id:t.id})},[_,y,t.id,t.label]),A=t.cron.trim().length>0,j=v.isPending||y.isPending;return n(i,{children:[n(`tr`,{className:`border-t border-border first:border-t-0 hover:bg-primary/5`,children:[s(`td`,{className:`px-2 py-2`,children:s(`button`,{onClick:f,className:`inline-flex items-center justify-center rounded p-1 text-foreground-subtle hover:bg-primary/10 hover:text-foreground`,title:d?`Hide archives`:`Show archives`,children:s(d?oe:ae,{className:`h-3.5 w-3.5`})})}),s(`td`,{className:`px-3 py-2`,children:n(`button`,{onClick:p,className:`text-left hover:underline focus:outline-none`,children:[s(`div`,{className:`text-foreground font-medium`,children:t.label||`(unnamed)`}),t.lastRunAt!==void 0&&n(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:[`last run `,new Date(t.lastRunAt).toLocaleString()]})]})}),s(`td`,{className:`px-3 py-2`,children:s(`label`,{className:`inline-flex items-center cursor-pointer`,children:s(`input`,{type:`checkbox`,className:`accent-primary`,checked:t.enabled,disabled:j,onChange:e=>T(e.target.checked)})})}),s(`td`,{className:`px-3 py-2`,children:n(`div`,{className:`flex flex-wrap gap-1`,children:[t.locationIds.length===0&&s(`span`,{className:`text-[11px] text-danger italic`,children:`No locations`}),t.locationIds.map(e=>s(`span`,{className:`inline-flex items-center rounded border border-border bg-background px-1.5 py-0.5 text-[10px] text-foreground`,title:e,children:u.get(e)?.displayName??e},e))]})}),s(`td`,{className:`px-3 py-2`,children:s(`input`,{type:`number`,min:1,max:1e3,value:x,disabled:j,onChange:e=>S(e.target.value),onBlur:D,onKeyDown:e=>{e.key===`Enter`&&e.target.blur(),e.key===`Escape`&&S(String(t.retentionCount))},className:`w-16 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})}),s(`td`,{className:`px-3 py-2`,children:n(`button`,{onClick:p,className:`group flex flex-col items-start gap-0.5 text-left`,title:`Edit schedule`,children:[n(`span`,{className:`inline-flex items-center gap-1`,children:[s(ce,{className:`h-3 w-3 text-foreground-subtle group-hover:text-foreground`}),s(`span`,{className:`font-mono text-[11px] text-foreground`,children:A?t.cron:`Manual`})]}),A&&t.nextRunAt!==void 0&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`next `,new Date(t.nextRunAt).toLocaleString()]})]})}),s(`td`,{className:`px-3 py-2`,children:n(`div`,{className:`flex items-center justify-end gap-1.5`,children:[n(`button`,{onClick:O,disabled:b.isPending||t.locationIds.length===0,className:`inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,title:`Run this entry now`,children:[b.isPending?s(V,{className:`h-3 w-3 animate-spin`}):s(te,{className:`h-3 w-3`}),`Run now`]}),s(`button`,{onClick:p,className:`inline-flex items-center justify-center rounded border border-border p-1 text-foreground-subtle hover:text-foreground hover:bg-primary/5`,title:`Edit entry`,children:s(I,{className:`h-3 w-3`})}),s(`button`,{onClick:()=>{k()},disabled:j,className:`inline-flex items-center justify-center rounded border border-border p-1 text-foreground-subtle hover:text-danger hover:border-danger/40 disabled:opacity-50`,title:`Delete entry`,children:s(z,{className:`h-3 w-3`})})]})})]}),d&&s(`tr`,{className:`border-t border-border bg-background/30`,children:n(`td`,{colSpan:7,className:`px-4 py-3 space-y-4`,children:[t.locationIds.length===0&&s(`p`,{className:`text-xs text-foreground-subtle italic`,children:`This entry has no locations selected.`}),t.locationIds.map(e=>n(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-medium text-foreground-subtle`,children:u.get(e)?.displayName??e}),s(pe,{destinationId:e,restoreSupported:u.get(e)?.restoreSupported??!0,...m?{onOpenRestoreWizard:m}:{}})]},e))]})})]})}t();var Y=[{id:`manual`,label:`Manual only`,cron:``},{id:`hourly`,label:`Every hour`,cron:`0 * * * *`,description:`On the hour`},{id:`every-3h`,label:`Every 3 hours`,cron:`0 */3 * * *`,description:`00:00, 03:00, 06:00, 09:00 …`},{id:`every-6h`,label:`Every 6 hours`,cron:`0 */6 * * *`,description:`00:00, 06:00, 12:00, 18:00`},{id:`daily-3am`,label:`Daily at 03:00`,cron:`0 3 * * *`,description:`Every night at 3 AM`},{id:`weekly-sun`,label:`Weekly Sunday 03:00`,cron:`0 3 * * 0`,description:`Sunday morning at 3 AM`}];function ve(e){let t=e.trim();for(let e of Y)if(e.cron===t)return e.id;return`custom`}function ye({value:e,onChange:t,previewCount:r=5,disabled:i=!1}){let a=ve(e),[l,u]=o(a===`custom`);c(()=>{a!==`custom`&&u(!1)},[a]);let d=Se(e,250),f=h({cron:d,count:r},{enabled:d.trim().length>0}),p=f.data??null,m=e=>{u(!1),t(e.cron)},g=l||a===`custom`;return n(`div`,{className:`space-y-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),n(`div`,{className:`flex flex-wrap gap-1.5`,children:[Y.map(e=>s(`button`,{type:`button`,onClick:()=>m(e),disabled:i,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!l&&a===e.id?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),title:e.description??e.label,children:e.label},e.id)),s(`button`,{type:`button`,onClick:()=>{u(!0),e.trim().length===0&&t(`0 3 * * *`)},disabled:i,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(g?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:`Custom…`})]})]}),g&&n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),s(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),disabled:i,placeholder:`0 3 * * *`,spellCheck:!1,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`}),n(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,s(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),s(be,{cron:d,preview:p,loading:f.isFetching})]})}function be({cron:e,preview:t,loading:r}){return r&&t===null?n(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[s(V,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?s(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:`No future runs match this expression.`}):n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),s(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>n(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[s(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),s(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:xe(e)})]},`${e}-${t}`))})]}):s(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:t.error??`Invalid cron expression`})}function xe(e){let t=e-Date.now();if(t<=0)return`now`;let n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;let r=Math.floor(n/60);if(r<60)return`in ${r}m`;let i=Math.floor(r/60);return i<24?`in ${i}h`:`in ${Math.floor(i/24)}d`}function Se(e,t){let[n,i]=o(e),a=r(()=>e,[e]);return c(()=>{let e=setTimeout(()=>i(a),t);return()=>clearTimeout(e)},[a,t]),n}t();var Ce=[[`backup`,`listSchedules`]];function we({entry:e,onClose:t,onSaved:i}){let c=a(),l=y(),u=l.data??[],[d,f]=o(e?.label??``),[p,m]=o(e?.cron??`0 3 * * *`),[h,_]=o(e?.enabled??!0),[v,b]=o(String(e?.retentionCount??7)),[x,S]=o(new Set(e?.locationIds??[])),C=g({onSuccess:()=>{c.invalidateQueries({queryKey:Ce}),i()}}),w=e=>{S(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},T=Number.parseInt(v,10),E=r(()=>d.trim().length>0&&x.size>0&&!Number.isNaN(T)&&T>=1&&T<=1e3,[d,x,T]),D=()=>{E&&C.mutate({...e?{id:e.id}:{},label:d.trim(),cron:p.trim(),enabled:h,locationIds:Array.from(x),retentionCount:T})},O=C.error instanceof Error?C.error.message:null;return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:n(`div`,{className:`w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[n(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3 sticky top-0 bg-surface`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e?`Edit backup entry`:`New backup entry`}),s(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:s(B,{className:`h-4 w-4`})})]}),n(`div`,{className:`p-4 space-y-4`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Name`}),s(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`Nightly offsite`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),n(`div`,{className:`space-y-1.5`,children:[n(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:[`Locations (`,x.size,` selected)`]}),l.isLoading&&n(`div`,{className:`flex items-center gap-2 px-1 py-2 text-xs text-foreground-subtle`,children:[s(V,{className:`h-3.5 w-3.5 animate-spin`}),`Loading locations…`]}),!l.isLoading&&u.length===0&&s(`div`,{className:`rounded border border-border bg-background px-3 py-2 text-xs text-foreground-subtle italic`,children:"No `backups` storage locations configured. Add one in Settings → Storage first."}),u.length>0&&s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-52 overflow-y-auto`,children:u.map(e=>n(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`checkbox`,checked:x.has(e.id),onChange:()=>w(e.id),className:`accent-primary`}),s(`span`,{className:`text-foreground`,children:e.displayName})]}),n(`div`,{className:`flex items-center gap-1.5`,children:[s(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-surface border border-border rounded px-1.5 py-0.5`,children:e.kind}),s(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.id})]})]},e.id))})]}),n(`div`,{className:`grid grid-cols-2 gap-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Retention (archives kept)`}),s(`input`,{type:`number`,min:1,max:1e3,value:v,onChange:e=>b(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Enabled`}),n(`label`,{className:`inline-flex items-center gap-2 py-1.5 cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:h,onChange:e=>_(e.target.checked),className:`accent-primary`}),s(`span`,{className:`text-xs text-foreground-subtle`,children:`Run on schedule`})]})]})]}),n(`div`,{className:`space-y-1.5 border-t border-border pt-3`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Schedule`}),s(ye,{value:p,onChange:m,disabled:C.isPending})]}),O&&s(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:O})]}),n(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3 sticky bottom-0 bg-surface`,children:[s(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),n(`button`,{onClick:D,disabled:!E||C.isPending,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[C.isPending&&s(V,{className:`h-3.5 w-3.5 animate-spin`}),e?`Save`:`Create entry`]})]})]})})}t();var Te=2e3,Ee=5e3;function X(e){return e.state===`queued`||e.state===`running`}function De(e){if(e.state===`queued`)return{title:`Cancel queued backup run?`,message:`This run has not started. Cancelling removes it from the queue — nothing has been written, nothing is deleted.`,confirmLabel:`Cancel run`,variant:`warning`};let t=e.completedDestinationIds.length;return{title:`Stop this backup run?`,message:`The half-written staging archive is deleted and the destination currently uploading discards its partial copy. ${t>0?`${t===1?`The 1 destination`:`The ${t} destinations`} that already completed KEEP${t===1?`S`:``} the archive.`:`No destination has completed yet, so nothing will be kept.`}`,confirmLabel:`Stop run`,variant:`danger`}}function Oe(){let t=E(),[n,r]=o(null),i=S(void 0,{refetchInterval:e=>(e.state.data??[]).some(X)?Te:Ee}),a=m({onSettled:()=>{r(null),i.refetch()}}),c=e(async e=>{await t(De(e))&&(r(e.id),a.mutate({runId:e.id}))},[t,a]);return s(ke,{queryState:i.isError?`error`:i.data===void 0?`pending`:`ready`,runs:i.data??[],cancelingId:n,onCancelRequest:e=>{c(e)},now:Date.now()})}function ke({queryState:e,runs:t,cancelingId:r,onCancelRequest:i,now:a}){let o=e===`ready`&&t.some(X),c=t.filter(e=>e.state===`running`),l=t.filter(e=>e.state===`queued`),u=t.filter(e=>!X(e)),d=[...c,...l,...u];return n(`section`,{className:`rounded-lg border border-border bg-surface`,children:[n(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-border`,children:[s(`h2`,{className:`text-xs font-semibold text-foreground`,children:`Runs`}),o&&n(`span`,{className:`inline-flex items-center gap-1 text-[10px] font-medium text-primary`,title:`A backup run is in progress`,children:[s(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary animate-pulse`}),`live`]}),s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:`One run executes at a time — queued runs wait in line.`})]}),e===`pending`&&s(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle animate-pulse`,children:`Checking for backup runs…`}),e===`error`&&s(`div`,{className:`px-3 py-2.5 text-xs text-danger`,children:`Could not read backup runs — the orchestrator did not answer.`}),e===`ready`&&t.length===0&&s(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle italic`,children:`No backup runs yet. Runs appear here the moment one starts — manual or scheduled.`}),e===`ready`&&t.length>0&&s(`div`,{className:`overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[720px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Run`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`State`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Progress`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Destinations`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Timing`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium w-28`,children:`Actions`})]})}),s(`tbody`,{children:d.map(e=>s(Ae,{run:e,canceling:r===e.id,onCancelRequest:i,now:a},e.id))})]})})]})}function Ae({run:e,canceling:t,onCancelRequest:r,now:i}){let a=X(e);return n(`tr`,{className:`border-t border-border hover:bg-primary/5 align-top`,children:[n(`td`,{className:`px-3 py-2`,children:[s(`div`,{className:`text-foreground`,children:e.label??s(`span`,{className:`text-foreground-subtle italic`,children:`manual`})}),s(`div`,{className:`text-[10px] text-foreground-subtle font-mono`,title:e.id,children:e.id.slice(0,8)})]}),n(`td`,{className:`px-3 py-2`,children:[s(je,{run:e}),e.state===`failed`&&e.error!==void 0&&s(`div`,{className:`mt-1 text-[10px] text-danger max-w-56 truncate`,title:e.error,children:e.error})]}),s(`td`,{className:`px-3 py-2`,children:s(Me,{run:e})}),s(`td`,{className:`px-3 py-2`,children:s(Ne,{run:e})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle tabular-nums`,children:s(Pe,{run:e,now:i})}),s(`td`,{className:`px-3 py-2`,children:s(`div`,{className:`flex justify-end`,children:a&&n(`button`,{onClick:()=>r(e),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:e.state===`queued`?`Remove this run from the queue before it starts`:`Stop this run — the half-written archive is discarded`,children:[t?s(V,{className:`h-3 w-3 animate-spin`}):s(se,{className:`h-3 w-3`}),e.state===`queued`?`Cancel`:`Stop`]})})})]})}function je({run:e}){switch(e.state){case`queued`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:[s(k,{className:`h-3 w-3`}),`Queued`]});case`running`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`,children:[s(V,{className:`h-3 w-3 animate-spin`}),e.phase===`uploading`?`Uploading`:`Building archive`]});case`succeeded`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-success/10 px-1.5 py-0.5 text-[10px] font-medium text-success`,children:[s(re,{className:`h-3 w-3`}),`Succeeded`]});case`failed`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-danger/10 px-1.5 py-0.5 text-[10px] font-medium text-danger`,children:[s(O,{className:`h-3 w-3`}),`Failed`]});case`cancelled`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-amber-500/10 px-1.5 py-0.5 text-[10px] font-medium text-amber-700 dark:text-amber-300`,title:`Stopped before completing every destination — not a success`,children:[s(D,{className:`h-3 w-3`}),`Stopped`]})}}function Me({run:e}){if(e.state===`queued`)return s(`span`,{className:`text-foreground-subtle`,children:e.queuePosition===void 0?s(`span`,{className:`italic`,children:`waiting its turn`}):n(`span`,{className:`inline-flex items-center gap-1`,children:[s(`span`,{className:e.queuePosition===1?`rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`:`rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium`,children:Fe(e.queuePosition)}),`in line`]})});if(e.state===`running`&&e.phase===`building`)return n(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[s(F,{className:`h-3 w-3 text-primary`}),s(`span`,{className:`tabular-nums font-medium animate-pulse`,children:G(e.stagedBytes)}),s(`span`,{className:`text-foreground-subtle`,children:`staged so far`})]});if(e.state===`running`){let t=e.archiveSizeBytes;return n(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[s(le,{className:`h-3 w-3 text-primary`}),n(`span`,{className:`tabular-nums font-medium`,children:[G(e.uploadedBytes),t===void 0?``:` / ${G(t)}`]}),s(`span`,{className:`text-foreground-subtle`,children:`to current destination`})]})}let t=e.archiveSizeBytes??(e.stagedBytes>0?e.stagedBytes:void 0);return t===void 0?s(`span`,{className:`text-foreground-subtle italic`,children:`—`}):n(`span`,{className:`tabular-nums text-foreground`,children:[G(t),` archive`]})}function Ne({run:e}){let t=e.destinationIds.length,r=e.completedDestinationIds.length,i=e.failedDestinationIds.length;return t===0?s(`span`,{className:`text-foreground-subtle italic`,children:`not resolved yet`}):n(`div`,{className:`flex flex-col gap-0.5`,children:[n(`span`,{className:`text-foreground-subtle`,title:e.destinationIds.join(`, `),children:[t,` target`,t===1?``:`s`]}),n(`span`,{className:`inline-flex items-center gap-2 text-[10px]`,children:[r>0&&n(`span`,{className:`text-success`,title:`Kept their archive: ${e.completedDestinationIds.join(`, `)}`,children:[`✓ `,r,` completed`]}),i>0&&n(`span`,{className:`text-danger`,title:`Failed: ${e.failedDestinationIds.join(`, `)}`,children:[`✗ `,i,` failed`]})]})]})}function Pe({run:e,now:t}){return e.state===`queued`?n(`span`,{children:[`queued `,Z(t-e.requestedAt),` ago`]}):e.startedAt===void 0?s(`span`,{children:`—`}):e.finishedAt===void 0?n(`span`,{children:[`running for `,Z(t-e.startedAt)]}):n(`div`,{className:`flex flex-col gap-0.5`,children:[s(`span`,{children:Q(e.finishedAt)}),n(`span`,{className:`text-[10px]`,children:[`took `,Z(e.finishedAt-e.startedAt)]})]})}function Fe(e){if(e<=1)return`next`;let t=e%100;if(t>=11&&t<=13)return`${e}th`;switch(e%10){case 1:return`${e}st`;case 2:return`${e}nd`;case 3:return`${e}rd`;default:return`${e}th`}}function Z(e){let t=Math.max(0,Math.floor(e/1e3));if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m ${String(t%60).padStart(2,`0`)}s`:`${Math.floor(n/60)}h ${String(n%60).padStart(2,`0`)}m`}function Q(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}t();var Ie=[[`backup`,`list`]];function Le({initialDestinationId:e,initialArchiveId:t,onClose:i,onScheduled:l}){let u=a(),[d,f]=o(e&&t?2:1),[p,m]=o(e),[h,g]=o(t),[v,x]=o(new Set),{data:S}=y(),C=S??[],{data:w,isLoading:E}=T({destinationId:p??``},{enabled:!!p}),D=w??[];c(()=>{if(p!==void 0)return;let e=C.filter(e=>e.restoreSupported);e.length===1&&m(e[0].id)},[p,C]);let{data:O}=_({destinationId:p??``,backupId:h??``},{enabled:!!p&&!!h}),k=r(()=>O?.locations??[],[O]);c(()=>{k.length!==0&&x(e=>e.size===0?new Set(k):e)},[k]);let A=b({onSuccess:()=>{u.invalidateQueries({queryKey:Ie}),l(),i()}}),j=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},M=!!p&&!!h,N=v.size>0,P=M&&N&&!A.isPending,F=()=>{!p||!h||A.mutate({destinationId:p,backupId:h,locations:[...v]})};return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:i,children:n(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[n(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[n(`div`,{className:`space-y-0.5`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Restore Backup`}),n(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,d,` of 3 —`,` `,d===1?`pick source`:d===2?`pick locations`:`confirm`]})]}),s(`button`,{onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:s(B,{className:`h-4 w-4`})})]}),d===1&&s(Re,{destinations:C,destinationId:p,onPickDestination:e=>{m(e),g(void 0),x(new Set)},archives:D,archivesLoading:E,archiveId:h,onPickArchive:g}),d===2&&s(ze,{locations:k,picked:v,onToggle:j}),d===3&&s(Be,{destinationName:C.find(e=>e.id===p)?.displayName??p??``,archive:D.find(e=>e.id===h),picked:[...v]}),n(`div`,{className:`flex justify-between gap-2 border-t border-border px-4 py-3`,children:[s(`div`,{children:d>1&&n(`button`,{onClick:()=>f(e=>e===3?2:1),className:`inline-flex items-center gap-1 rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:[s(ie,{className:`h-3 w-3`}),`Back`]})}),n(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:i,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),d<3?n(`button`,{disabled:d===1&&!M||d===2&&!N,onClick:()=>f(e=>e===1?2:3),className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[`Next`,s(q,{className:`h-3 w-3`})]}):n(`button`,{onClick:F,disabled:!P,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[A.isPending?s(V,{className:`h-3.5 w-3.5 animate-spin`}):s(L,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function Re({destinations:e,destinationId:t,onPickDestination:r,archives:i,archivesLoading:a,archiveId:o,onPickArchive:c}){let l=e.filter(e=>e.restoreSupported);return n(`div`,{className:`p-4 space-y-3`,children:[n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),n(`select`,{value:t??``,onChange:e=>r(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:[s(`option`,{value:``,disabled:!0,children:`Select destination…`}),l.map(e=>n(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&a&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!a&&i.length===0&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&i.length>0&&s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:i.map(e=>{let t=o===e.id;return n(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>c(e.id),className:`accent-primary`}),n(`div`,{children:[s(`div`,{className:`font-medium text-foreground`,children:e.label??e.id}),s(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),s(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:G(e.sizeBytes)})]},e.id)})})]})]})}function ze({locations:e,picked:t,onToggle:r}){return e.length===0?s(`div`,{className:`p-4`,children:s(`div`,{className:`text-xs text-foreground-subtle`,children:`Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball.`})}):n(`div`,{className:`p-4 space-y-3`,children:[s(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`Selected entries will overwrite live data on the next server restart. Unchecked entries stay current.`}),n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>n(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>r(e),className:`accent-primary`}),s(`span`,{className:`font-mono text-foreground`,children:e}),s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:He(e)})]},e))})]})]})}function Be({destinationName:e,archive:t,picked:r}){return n(`div`,{className:`p-4 space-y-3 text-xs`,children:[s(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-amber-700 dark:text-amber-300`,children:`Restore is applied at next server boot. Active connections will drop when you restart.`}),n(`dl`,{className:`space-y-1.5`,children:[s($,{term:`Destination`,value:e}),s($,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&s($,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${G(t.sizeBytes)}`}),s($,{term:`Locations`,value:r.length>0?r.join(`, `):`— (full archive)`})]})]})}function $({term:e,value:t}){return n(`div`,{className:`flex justify-between gap-3`,children:[s(`dt`,{className:`text-foreground-subtle`,children:e}),s(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var Ve={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function He(e){return Ve[e]??``}t();function Ue(){let e=E(),t=u(),[r,i]=o(null),[a,c]=o(!1),[l,d]=o(!1),[f,p]=o(void 0),m=async()=>{await e({title:`Restart server now?`,message:`Active connections will drop and the apply-backup hook will run before boot.`,confirmLabel:`Restart`,variant:`warning`})&&t.mutate({confirm:!0})};return n(H,{children:[n(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[n(`button`,{onClick:()=>c(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[s(L,{className:`h-3.5 w-3.5`}),`Restore…`]}),n(`button`,{onClick:()=>p(null),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[s(ne,{className:`h-3.5 w-3.5`}),`New entry`]})]}),l&&s(`div`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2.5 text-xs text-amber-700 dark:text-amber-300`,children:n(`div`,{className:`flex items-center justify-between gap-3`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(L,{className:`h-3.5 w-3.5`}),s(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),n(`button`,{onClick:()=>{m()},disabled:t.isPending,className:`inline-flex items-center gap-1.5 rounded bg-amber-500/20 px-2 py-1 font-medium text-amber-800 dark:text-amber-200 hover:bg-amber-500/30 disabled:opacity-50`,children:[t.isPending?s(V,{className:`h-3.5 w-3.5 animate-spin`}):s(L,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),s(Oe,{}),s(ge,{onEdit:e=>p(e),onOpenRestoreWizard:e=>i(e)}),f!==void 0&&s(we,{entry:f,onClose:()=>p(void 0),onSaved:()=>p(void 0)}),(r||a)&&s(Le,{...r?{initialDestinationId:r.destinationId,initialArchiveId:r.archiveId}:{},onClose:()=>{i(null),c(!1)},onScheduled:()=>d(!0)})]})}function We(){return s(`div`,{className:`flex flex-col p-4`,children:s(W,{tabs:[{id:`storage`,label:`Storage`,icon:ee,content:s(ue,{})},{id:`backup`,label:`Backup`,icon:K,content:s(Ue,{})}]})})}export{We as DataPage};
1
+ import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{$n as l,Fn as u,Jo as d,Ko as f,Qn as p,Zn as m,ar as h,cr as g,er as _,ir as v,nr as y,or as b,qo as x,rr as S,sr as C,ss as w,tr as T,un as E}from"./src-D9QFy74P.js";import{t as D}from"./circle-slash-B-5dS85p.js";import{t as O}from"./circle-x-4Dl6gVrz.js";import{t as k}from"./clock-fhpkQDEm.js";import{t as A}from"./download-B6w2lrQQ.js";import{i as j,n as M,r as N,t as P}from"./AddLocationWizard-BEWTYRkd.js";import{t as F}from"./hard-drive-download-BEpVEf7Q.js";import{t as ee}from"./hard-drive-BJUcdsGQ.js";import{t as I}from"./pencil-DoE75RwV.js";import{t as te}from"./play-B84SrcvR.js";import{t as ne}from"./plus-CezysZVA.js";import{t as L}from"./rotate-cw-seLHMWMS.js";import{F as re,J as R,K as ie,L as ae,o as z,r as B,w as V,z as oe}from"./index-COjcrxBt.js";import{t as H}from"./AdminPage-CCD07UMs.js";import{r as U}from"./authed-media-BPd_L9jr.js";import{t as W}from"./AdminTabs-CqZmMiLw.js";import{t as G}from"./format-size-DIxKXxtj.js";var K=R(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),q=R(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),se=R(`ban`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m4.9 4.9 14.2 14.2`,key:`1m5liu`}]]),ce=R(`calendar-clock`,[[`path`,{d:`M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5`,key:`1osxxc`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M17.5 17.5 16 16.3V14`,key:`akvzfd`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]),le=R(`cloud-upload`,[[`path`,{d:`M12 13v8`,key:`1l5pq0`}],[`path`,{d:`M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242`,key:`1pljnt`}],[`path`,{d:`m8 17 4-4 4 4`,key:`1quai1`}]]);t();function ue(){let e=a(),t=E(),{data:i,isLoading:c,isError:l}=d({}),u=x(),p=r(()=>u.data??[],[u.data]),[m,h]=o(null),[g,_]=o(null),v=f({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),y=w({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),b=(e,t)=>{y.mutate(j(e,{enabled:t}))},S=(e,t)=>{y.mutate(j(e,{readOnly:t}))},C=async e=>{if(await t({title:`Delete location "${e.displayName}"?`,message:`This removes the location record. Files on disk are not deleted; the underlying directory or remote path stays untouched.`,confirmLabel:`Delete`,variant:`danger`}))try{await v.mutateAsync({id:e.id})}catch(n){await t({title:`Delete anyway?`,message:`${n instanceof Error?n.message:String(n)}\n\nForcing the delete removes the record only. Anything still on that location becomes unreachable — index rows naming it stop resolving, and playback of those segments goes silently black rather than erroring.`,confirmLabel:`Force delete`,variant:`danger`})&&v.mutate({id:e.id,force:!0})}},T=r(()=>{let e=new Map;for(let t of i??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[i]),D=c||u.isLoading,O=l||u.isError;return n(H,{children:[D&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),O&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!D&&!O&&n(`div`,{className:`space-y-3`,children:[p.length===0&&s(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:`No storage locations declared by any installed addon.`}),p.map(e=>s(N,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:T.get(e.id)??[],onAdd:e=>h(e),onEdit:e=>_(e),onDelete:e=>{C(e)},onToggleEnabled:(e,t)=>b(e,t),onToggleReadOnly:(e,t)=>S(e,t)},e.id))]}),m!==null&&s(P,{initialType:m,onClose:()=>h(null),onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),h(null)}}),g!==null&&s(M,{location:g,onClose:()=>_(null),onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),_(null)}})]})}t();var de=[[`backup`,`listDestinations`]],fe=[`backup`,`listArchives`];function pe({destinationId:t,restoreSupported:i,onOpenRestoreWizard:c}){let l=a(),u=E(),{data:d,isLoading:f,isError:m}=T({destinationId:t}),h=d??[],g=p({onSuccess:()=>{l.invalidateQueries({queryKey:[[...fe]]}),l.invalidateQueries({queryKey:de})}}),_=e(async e=>{await u({title:`Delete this archive?`,message:`Permanently deletes "${e.label??e.id}" and frees ${G(e.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&g.mutate({destinationId:t,backupId:e.id})},[u,t,g]),[v,y]=o(null),b=e(async e=>{y(e.id);try{let n=await U(me(t,e.id)),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.label??e.id}.tar.gz`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}finally{y(null)}},[t]),x=r(()=>[...h].toSorted((e,t)=>t.createdAt-e.createdAt),[h]);return f?s(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):m?s(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):x.length===0?s(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):s(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`When`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),s(`tbody`,{children:x.map(e=>n(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:he(e.createdAt)}),s(`td`,{className:`px-3 py-1.5 text-foreground`,children:e.label??s(`span`,{className:`text-foreground-subtle italic`,children:`—`})}),s(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:e.locations.join(`, `)}),s(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:G(e.sizeBytes)}),s(`td`,{className:`px-3 py-1.5`,children:n(`div`,{className:`flex items-center justify-end gap-1`,children:[n(`button`,{onClick:()=>{b(e)},disabled:v===e.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:text-foreground hover:bg-primary/10 disabled:opacity-50`,title:`Download archive`,children:[v===e.id?s(V,{className:`h-3 w-3 animate-spin`}):s(A,{className:`h-3 w-3`}),`Download`]}),i&&c&&n(`button`,{onClick:()=>c({destinationId:t,archiveId:e.id}),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-primary hover:bg-primary/10`,title:`Restore from this archive`,children:[s(L,{className:`h-3 w-3`}),`Restore`]}),s(`button`,{onClick:()=>{_(e)},disabled:g.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete archive`,children:g.isPending?s(V,{className:`h-3 w-3 animate-spin`}):s(z,{className:`h-3 w-3`})})]})})]},e.id))})]})})}function me(e,t){return`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}function he(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}t();var J=[[`backup`,`listSchedules`]];function ge({onEdit:e,onOpenRestoreWizard:t}){let{data:i,isLoading:a,isError:c}=v(),l=i??[],u=y().data??[],d=r(()=>{let e=new Map;for(let t of u)e.set(t.id,t);return e},[u]),[f,p]=o(null),m=e=>{p(t=>t===e?null:e)};return a?s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading backup entries…`}):c?s(`div`,{className:`text-xs text-danger`,children:`Failed to load backup entries`}):l.length===0?s(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-8 text-center`,children:s(`p`,{className:`text-xs text-foreground-subtle`,children:`No backup entries yet. Create one to schedule backups across one or more storage locations.`})}):s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[820px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle border-b border-border bg-background/40`,children:[s(`th`,{className:`text-left px-3 py-2 font-medium w-6`}),s(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Entry`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-20`,children:`Enabled`}),s(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Locations`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-24`,children:`Retention`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-48`,children:`Schedule`}),s(`th`,{className:`text-right px-3 py-2 font-medium w-52`,children:`Actions`})]})}),s(`tbody`,{children:l.map(n=>s(_e,{row:n,destById:d,isOpen:f===n.id,onToggle:()=>m(n.id),onEdit:()=>e(n),...t?{onOpenRestoreWizard:t}:{}},n.id))})]})})}function _e({row:t,destById:u,isOpen:d,onToggle:f,onEdit:p,onOpenRestoreWizard:m}){let h=a(),_=E(),v=g({onSuccess:()=>{h.invalidateQueries({queryKey:J})}}),y=l({onSuccess:()=>{h.invalidateQueries({queryKey:J})}}),b=C({onMutate:()=>{h.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})},onSuccess:()=>{h.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),h.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),h.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})}}),[x,S]=o(String(t.retentionCount));c(()=>{S(String(t.retentionCount))},[t.retentionCount]);let w=r(()=>({id:t.id,label:t.label,cron:t.cron,locationIds:[...t.locationIds],retentionCount:t.retentionCount,...t.dataSources?{dataSources:[...t.dataSources]}:{}}),[t]),T=e(e=>{v.mutate({...w,enabled:e})},[v,w]),D=e(()=>{let e=Number.parseInt(x,10);if(Number.isNaN(e)||e<1){S(String(t.retentionCount));return}e!==t.retentionCount&&v.mutate({...w,enabled:t.enabled,retentionCount:e})},[v,w,x,t.retentionCount,t.enabled]),O=e(()=>{t.locationIds.length!==0&&b.mutate({destinations:[...t.locationIds],...t.dataSources&&t.dataSources.length>0?{locations:[...t.dataSources]}:{},label:t.label,retentionCount:t.retentionCount})},[b,t]),k=e(async()=>{await _({title:`Delete backup entry?`,message:`"${t.label||t.id}" will stop running. Existing archives are kept.`,confirmLabel:`Delete`,variant:`warning`})&&y.mutate({id:t.id})},[_,y,t.id,t.label]),A=t.cron.trim().length>0,j=v.isPending||y.isPending;return n(i,{children:[n(`tr`,{className:`border-t border-border first:border-t-0 hover:bg-primary/5`,children:[s(`td`,{className:`px-2 py-2`,children:s(`button`,{onClick:f,className:`inline-flex items-center justify-center rounded p-1 text-foreground-subtle hover:bg-primary/10 hover:text-foreground`,title:d?`Hide archives`:`Show archives`,children:s(d?oe:ae,{className:`h-3.5 w-3.5`})})}),s(`td`,{className:`px-3 py-2`,children:n(`button`,{onClick:p,className:`text-left hover:underline focus:outline-none`,children:[s(`div`,{className:`text-foreground font-medium`,children:t.label||`(unnamed)`}),t.lastRunAt!==void 0&&n(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:[`last run `,new Date(t.lastRunAt).toLocaleString()]})]})}),s(`td`,{className:`px-3 py-2`,children:s(`label`,{className:`inline-flex items-center cursor-pointer`,children:s(`input`,{type:`checkbox`,className:`accent-primary`,checked:t.enabled,disabled:j,onChange:e=>T(e.target.checked)})})}),s(`td`,{className:`px-3 py-2`,children:n(`div`,{className:`flex flex-wrap gap-1`,children:[t.locationIds.length===0&&s(`span`,{className:`text-[11px] text-danger italic`,children:`No locations`}),t.locationIds.map(e=>s(`span`,{className:`inline-flex items-center rounded border border-border bg-background px-1.5 py-0.5 text-[10px] text-foreground`,title:e,children:u.get(e)?.displayName??e},e))]})}),s(`td`,{className:`px-3 py-2`,children:s(`input`,{type:`number`,min:1,max:1e3,value:x,disabled:j,onChange:e=>S(e.target.value),onBlur:D,onKeyDown:e=>{e.key===`Enter`&&e.target.blur(),e.key===`Escape`&&S(String(t.retentionCount))},className:`w-16 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})}),s(`td`,{className:`px-3 py-2`,children:n(`button`,{onClick:p,className:`group flex flex-col items-start gap-0.5 text-left`,title:`Edit schedule`,children:[n(`span`,{className:`inline-flex items-center gap-1`,children:[s(ce,{className:`h-3 w-3 text-foreground-subtle group-hover:text-foreground`}),s(`span`,{className:`font-mono text-[11px] text-foreground`,children:A?t.cron:`Manual`})]}),A&&t.nextRunAt!==void 0&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`next `,new Date(t.nextRunAt).toLocaleString()]})]})}),s(`td`,{className:`px-3 py-2`,children:n(`div`,{className:`flex items-center justify-end gap-1.5`,children:[n(`button`,{onClick:O,disabled:b.isPending||t.locationIds.length===0,className:`inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,title:`Run this entry now`,children:[b.isPending?s(V,{className:`h-3 w-3 animate-spin`}):s(te,{className:`h-3 w-3`}),`Run now`]}),s(`button`,{onClick:p,className:`inline-flex items-center justify-center rounded border border-border p-1 text-foreground-subtle hover:text-foreground hover:bg-primary/5`,title:`Edit entry`,children:s(I,{className:`h-3 w-3`})}),s(`button`,{onClick:()=>{k()},disabled:j,className:`inline-flex items-center justify-center rounded border border-border p-1 text-foreground-subtle hover:text-danger hover:border-danger/40 disabled:opacity-50`,title:`Delete entry`,children:s(z,{className:`h-3 w-3`})})]})})]}),d&&s(`tr`,{className:`border-t border-border bg-background/30`,children:n(`td`,{colSpan:7,className:`px-4 py-3 space-y-4`,children:[t.locationIds.length===0&&s(`p`,{className:`text-xs text-foreground-subtle italic`,children:`This entry has no locations selected.`}),t.locationIds.map(e=>n(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-medium text-foreground-subtle`,children:u.get(e)?.displayName??e}),s(pe,{destinationId:e,restoreSupported:u.get(e)?.restoreSupported??!0,...m?{onOpenRestoreWizard:m}:{}})]},e))]})})]})}t();var Y=[{id:`manual`,label:`Manual only`,cron:``},{id:`hourly`,label:`Every hour`,cron:`0 * * * *`,description:`On the hour`},{id:`every-3h`,label:`Every 3 hours`,cron:`0 */3 * * *`,description:`00:00, 03:00, 06:00, 09:00 …`},{id:`every-6h`,label:`Every 6 hours`,cron:`0 */6 * * *`,description:`00:00, 06:00, 12:00, 18:00`},{id:`daily-3am`,label:`Daily at 03:00`,cron:`0 3 * * *`,description:`Every night at 3 AM`},{id:`weekly-sun`,label:`Weekly Sunday 03:00`,cron:`0 3 * * 0`,description:`Sunday morning at 3 AM`}];function ve(e){let t=e.trim();for(let e of Y)if(e.cron===t)return e.id;return`custom`}function ye({value:e,onChange:t,previewCount:r=5,disabled:i=!1}){let a=ve(e),[l,u]=o(a===`custom`);c(()=>{a!==`custom`&&u(!1)},[a]);let d=Se(e,250),f=h({cron:d,count:r},{enabled:d.trim().length>0}),p=f.data??null,m=e=>{u(!1),t(e.cron)},g=l||a===`custom`;return n(`div`,{className:`space-y-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),n(`div`,{className:`flex flex-wrap gap-1.5`,children:[Y.map(e=>s(`button`,{type:`button`,onClick:()=>m(e),disabled:i,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!l&&a===e.id?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),title:e.description??e.label,children:e.label},e.id)),s(`button`,{type:`button`,onClick:()=>{u(!0),e.trim().length===0&&t(`0 3 * * *`)},disabled:i,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(g?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:`Custom…`})]})]}),g&&n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),s(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),disabled:i,placeholder:`0 3 * * *`,spellCheck:!1,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`}),n(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,s(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),s(be,{cron:d,preview:p,loading:f.isFetching})]})}function be({cron:e,preview:t,loading:r}){return r&&t===null?n(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[s(V,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?s(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:`No future runs match this expression.`}):n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),s(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>n(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[s(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),s(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:xe(e)})]},`${e}-${t}`))})]}):s(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:t.error??`Invalid cron expression`})}function xe(e){let t=e-Date.now();if(t<=0)return`now`;let n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;let r=Math.floor(n/60);if(r<60)return`in ${r}m`;let i=Math.floor(r/60);return i<24?`in ${i}h`:`in ${Math.floor(i/24)}d`}function Se(e,t){let[n,i]=o(e),a=r(()=>e,[e]);return c(()=>{let e=setTimeout(()=>i(a),t);return()=>clearTimeout(e)},[a,t]),n}t();var Ce=[[`backup`,`listSchedules`]];function we({entry:e,onClose:t,onSaved:i}){let c=a(),l=y(),u=l.data??[],[d,f]=o(e?.label??``),[p,m]=o(e?.cron??`0 3 * * *`),[h,_]=o(e?.enabled??!0),[v,b]=o(String(e?.retentionCount??7)),[x,S]=o(new Set(e?.locationIds??[])),C=g({onSuccess:()=>{c.invalidateQueries({queryKey:Ce}),i()}}),w=e=>{S(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},T=Number.parseInt(v,10),E=r(()=>d.trim().length>0&&x.size>0&&!Number.isNaN(T)&&T>=1&&T<=1e3,[d,x,T]),D=()=>{E&&C.mutate({...e?{id:e.id}:{},label:d.trim(),cron:p.trim(),enabled:h,locationIds:Array.from(x),retentionCount:T})},O=C.error instanceof Error?C.error.message:null;return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:n(`div`,{className:`w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[n(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3 sticky top-0 bg-surface`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e?`Edit backup entry`:`New backup entry`}),s(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:s(B,{className:`h-4 w-4`})})]}),n(`div`,{className:`p-4 space-y-4`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Name`}),s(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`Nightly offsite`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),n(`div`,{className:`space-y-1.5`,children:[n(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:[`Locations (`,x.size,` selected)`]}),l.isLoading&&n(`div`,{className:`flex items-center gap-2 px-1 py-2 text-xs text-foreground-subtle`,children:[s(V,{className:`h-3.5 w-3.5 animate-spin`}),`Loading locations…`]}),!l.isLoading&&u.length===0&&s(`div`,{className:`rounded border border-border bg-background px-3 py-2 text-xs text-foreground-subtle italic`,children:"No `backups` storage locations configured. Add one in Settings → Storage first."}),u.length>0&&s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-52 overflow-y-auto`,children:u.map(e=>n(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`checkbox`,checked:x.has(e.id),onChange:()=>w(e.id),className:`accent-primary`}),s(`span`,{className:`text-foreground`,children:e.displayName})]}),n(`div`,{className:`flex items-center gap-1.5`,children:[s(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-surface border border-border rounded px-1.5 py-0.5`,children:e.kind}),s(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.id})]})]},e.id))})]}),n(`div`,{className:`grid grid-cols-2 gap-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Retention (archives kept)`}),s(`input`,{type:`number`,min:1,max:1e3,value:v,onChange:e=>b(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Enabled`}),n(`label`,{className:`inline-flex items-center gap-2 py-1.5 cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:h,onChange:e=>_(e.target.checked),className:`accent-primary`}),s(`span`,{className:`text-xs text-foreground-subtle`,children:`Run on schedule`})]})]})]}),n(`div`,{className:`space-y-1.5 border-t border-border pt-3`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Schedule`}),s(ye,{value:p,onChange:m,disabled:C.isPending})]}),O&&s(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:O})]}),n(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3 sticky bottom-0 bg-surface`,children:[s(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),n(`button`,{onClick:D,disabled:!E||C.isPending,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[C.isPending&&s(V,{className:`h-3.5 w-3.5 animate-spin`}),e?`Save`:`Create entry`]})]})]})})}t();var Te=2e3,Ee=5e3;function X(e){return e.state===`queued`||e.state===`running`}function De(e){if(e.state===`queued`)return{title:`Cancel queued backup run?`,message:`This run has not started. Cancelling removes it from the queue — nothing has been written, nothing is deleted.`,confirmLabel:`Cancel run`,variant:`warning`};let t=e.completedDestinationIds.length;return{title:`Stop this backup run?`,message:`The half-written staging archive is deleted and the destination currently uploading discards its partial copy. ${t>0?`${t===1?`The 1 destination`:`The ${t} destinations`} that already completed KEEP${t===1?`S`:``} the archive.`:`No destination has completed yet, so nothing will be kept.`}`,confirmLabel:`Stop run`,variant:`danger`}}function Oe(){let t=E(),[n,r]=o(null),i=S(void 0,{refetchInterval:e=>(e.state.data??[]).some(X)?Te:Ee}),a=m({onSettled:()=>{r(null),i.refetch()}}),c=e(async e=>{await t(De(e))&&(r(e.id),a.mutate({runId:e.id}))},[t,a]);return s(ke,{queryState:i.isError?`error`:i.data===void 0?`pending`:`ready`,runs:i.data??[],cancelingId:n,onCancelRequest:e=>{c(e)},now:Date.now()})}function ke({queryState:e,runs:t,cancelingId:r,onCancelRequest:i,now:a}){let o=e===`ready`&&t.some(X),c=t.filter(e=>e.state===`running`),l=t.filter(e=>e.state===`queued`),u=t.filter(e=>!X(e)),d=[...c,...l,...u];return n(`section`,{className:`rounded-lg border border-border bg-surface`,children:[n(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-border`,children:[s(`h2`,{className:`text-xs font-semibold text-foreground`,children:`Runs`}),o&&n(`span`,{className:`inline-flex items-center gap-1 text-[10px] font-medium text-primary`,title:`A backup run is in progress`,children:[s(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary animate-pulse`}),`live`]}),s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:`One run executes at a time — queued runs wait in line.`})]}),e===`pending`&&s(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle animate-pulse`,children:`Checking for backup runs…`}),e===`error`&&s(`div`,{className:`px-3 py-2.5 text-xs text-danger`,children:`Could not read backup runs — the orchestrator did not answer.`}),e===`ready`&&t.length===0&&s(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle italic`,children:`No backup runs yet. Runs appear here the moment one starts — manual or scheduled.`}),e===`ready`&&t.length>0&&s(`div`,{className:`overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[720px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Run`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`State`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Progress`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Destinations`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Timing`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium w-28`,children:`Actions`})]})}),s(`tbody`,{children:d.map(e=>s(Ae,{run:e,canceling:r===e.id,onCancelRequest:i,now:a},e.id))})]})})]})}function Ae({run:e,canceling:t,onCancelRequest:r,now:i}){let a=X(e);return n(`tr`,{className:`border-t border-border hover:bg-primary/5 align-top`,children:[n(`td`,{className:`px-3 py-2`,children:[s(`div`,{className:`text-foreground`,children:e.label??s(`span`,{className:`text-foreground-subtle italic`,children:`manual`})}),s(`div`,{className:`text-[10px] text-foreground-subtle font-mono`,title:e.id,children:e.id.slice(0,8)})]}),n(`td`,{className:`px-3 py-2`,children:[s(je,{run:e}),e.state===`failed`&&e.error!==void 0&&s(`div`,{className:`mt-1 text-[10px] text-danger max-w-56 truncate`,title:e.error,children:e.error})]}),s(`td`,{className:`px-3 py-2`,children:s(Me,{run:e})}),s(`td`,{className:`px-3 py-2`,children:s(Ne,{run:e})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle tabular-nums`,children:s(Pe,{run:e,now:i})}),s(`td`,{className:`px-3 py-2`,children:s(`div`,{className:`flex justify-end`,children:a&&n(`button`,{onClick:()=>r(e),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:e.state===`queued`?`Remove this run from the queue before it starts`:`Stop this run — the half-written archive is discarded`,children:[t?s(V,{className:`h-3 w-3 animate-spin`}):s(se,{className:`h-3 w-3`}),e.state===`queued`?`Cancel`:`Stop`]})})})]})}function je({run:e}){switch(e.state){case`queued`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:[s(k,{className:`h-3 w-3`}),`Queued`]});case`running`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`,children:[s(V,{className:`h-3 w-3 animate-spin`}),e.phase===`uploading`?`Uploading`:`Building archive`]});case`succeeded`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-success/10 px-1.5 py-0.5 text-[10px] font-medium text-success`,children:[s(re,{className:`h-3 w-3`}),`Succeeded`]});case`failed`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-danger/10 px-1.5 py-0.5 text-[10px] font-medium text-danger`,children:[s(O,{className:`h-3 w-3`}),`Failed`]});case`cancelled`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-amber-500/10 px-1.5 py-0.5 text-[10px] font-medium text-amber-700 dark:text-amber-300`,title:`Stopped before completing every destination — not a success`,children:[s(D,{className:`h-3 w-3`}),`Stopped`]})}}function Me({run:e}){if(e.state===`queued`)return s(`span`,{className:`text-foreground-subtle`,children:e.queuePosition===void 0?s(`span`,{className:`italic`,children:`waiting its turn`}):n(`span`,{className:`inline-flex items-center gap-1`,children:[s(`span`,{className:e.queuePosition===1?`rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`:`rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium`,children:Fe(e.queuePosition)}),`in line`]})});if(e.state===`running`&&e.phase===`building`)return n(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[s(F,{className:`h-3 w-3 text-primary`}),s(`span`,{className:`tabular-nums font-medium animate-pulse`,children:G(e.stagedBytes)}),s(`span`,{className:`text-foreground-subtle`,children:`staged so far`})]});if(e.state===`running`){let t=e.archiveSizeBytes;return n(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[s(le,{className:`h-3 w-3 text-primary`}),n(`span`,{className:`tabular-nums font-medium`,children:[G(e.uploadedBytes),t===void 0?``:` / ${G(t)}`]}),s(`span`,{className:`text-foreground-subtle`,children:`to current destination`})]})}let t=e.archiveSizeBytes??(e.stagedBytes>0?e.stagedBytes:void 0);return t===void 0?s(`span`,{className:`text-foreground-subtle italic`,children:`—`}):n(`span`,{className:`tabular-nums text-foreground`,children:[G(t),` archive`]})}function Ne({run:e}){let t=e.destinationIds.length,r=e.completedDestinationIds.length,i=e.failedDestinationIds.length;return t===0?s(`span`,{className:`text-foreground-subtle italic`,children:`not resolved yet`}):n(`div`,{className:`flex flex-col gap-0.5`,children:[n(`span`,{className:`text-foreground-subtle`,title:e.destinationIds.join(`, `),children:[t,` target`,t===1?``:`s`]}),n(`span`,{className:`inline-flex items-center gap-2 text-[10px]`,children:[r>0&&n(`span`,{className:`text-success`,title:`Kept their archive: ${e.completedDestinationIds.join(`, `)}`,children:[`✓ `,r,` completed`]}),i>0&&n(`span`,{className:`text-danger`,title:`Failed: ${e.failedDestinationIds.join(`, `)}`,children:[`✗ `,i,` failed`]})]})]})}function Pe({run:e,now:t}){return e.state===`queued`?n(`span`,{children:[`queued `,Z(t-e.requestedAt),` ago`]}):e.startedAt===void 0?s(`span`,{children:`—`}):e.finishedAt===void 0?n(`span`,{children:[`running for `,Z(t-e.startedAt)]}):n(`div`,{className:`flex flex-col gap-0.5`,children:[s(`span`,{children:Q(e.finishedAt)}),n(`span`,{className:`text-[10px]`,children:[`took `,Z(e.finishedAt-e.startedAt)]})]})}function Fe(e){if(e<=1)return`next`;let t=e%100;if(t>=11&&t<=13)return`${e}th`;switch(e%10){case 1:return`${e}st`;case 2:return`${e}nd`;case 3:return`${e}rd`;default:return`${e}th`}}function Z(e){let t=Math.max(0,Math.floor(e/1e3));if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m ${String(t%60).padStart(2,`0`)}s`:`${Math.floor(n/60)}h ${String(n%60).padStart(2,`0`)}m`}function Q(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}t();var Ie=[[`backup`,`list`]];function Le({initialDestinationId:e,initialArchiveId:t,onClose:i,onScheduled:l}){let u=a(),[d,f]=o(e&&t?2:1),[p,m]=o(e),[h,g]=o(t),[v,x]=o(new Set),{data:S}=y(),C=S??[],{data:w,isLoading:E}=T({destinationId:p??``},{enabled:!!p}),D=w??[];c(()=>{if(p!==void 0)return;let e=C.filter(e=>e.restoreSupported);e.length===1&&m(e[0].id)},[p,C]);let{data:O}=_({destinationId:p??``,backupId:h??``},{enabled:!!p&&!!h}),k=r(()=>O?.locations??[],[O]);c(()=>{k.length!==0&&x(e=>e.size===0?new Set(k):e)},[k]);let A=b({onSuccess:()=>{u.invalidateQueries({queryKey:Ie}),l(),i()}}),j=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},M=!!p&&!!h,N=v.size>0,P=M&&N&&!A.isPending,F=()=>{!p||!h||A.mutate({destinationId:p,backupId:h,locations:[...v]})};return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:i,children:n(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[n(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[n(`div`,{className:`space-y-0.5`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Restore Backup`}),n(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,d,` of 3 —`,` `,d===1?`pick source`:d===2?`pick locations`:`confirm`]})]}),s(`button`,{onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:s(B,{className:`h-4 w-4`})})]}),d===1&&s(Re,{destinations:C,destinationId:p,onPickDestination:e=>{m(e),g(void 0),x(new Set)},archives:D,archivesLoading:E,archiveId:h,onPickArchive:g}),d===2&&s(ze,{locations:k,picked:v,onToggle:j}),d===3&&s(Be,{destinationName:C.find(e=>e.id===p)?.displayName??p??``,archive:D.find(e=>e.id===h),picked:[...v]}),n(`div`,{className:`flex justify-between gap-2 border-t border-border px-4 py-3`,children:[s(`div`,{children:d>1&&n(`button`,{onClick:()=>f(e=>e===3?2:1),className:`inline-flex items-center gap-1 rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:[s(ie,{className:`h-3 w-3`}),`Back`]})}),n(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:i,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),d<3?n(`button`,{disabled:d===1&&!M||d===2&&!N,onClick:()=>f(e=>e===1?2:3),className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[`Next`,s(q,{className:`h-3 w-3`})]}):n(`button`,{onClick:F,disabled:!P,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[A.isPending?s(V,{className:`h-3.5 w-3.5 animate-spin`}):s(L,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function Re({destinations:e,destinationId:t,onPickDestination:r,archives:i,archivesLoading:a,archiveId:o,onPickArchive:c}){let l=e.filter(e=>e.restoreSupported);return n(`div`,{className:`p-4 space-y-3`,children:[n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),n(`select`,{value:t??``,onChange:e=>r(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:[s(`option`,{value:``,disabled:!0,children:`Select destination…`}),l.map(e=>n(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&a&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!a&&i.length===0&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&i.length>0&&s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:i.map(e=>{let t=o===e.id;return n(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>c(e.id),className:`accent-primary`}),n(`div`,{children:[s(`div`,{className:`font-medium text-foreground`,children:e.label??e.id}),s(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),s(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:G(e.sizeBytes)})]},e.id)})})]})]})}function ze({locations:e,picked:t,onToggle:r}){return e.length===0?s(`div`,{className:`p-4`,children:s(`div`,{className:`text-xs text-foreground-subtle`,children:`Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball.`})}):n(`div`,{className:`p-4 space-y-3`,children:[s(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`Selected entries will overwrite live data on the next server restart. Unchecked entries stay current.`}),n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>n(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>r(e),className:`accent-primary`}),s(`span`,{className:`font-mono text-foreground`,children:e}),s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:He(e)})]},e))})]})]})}function Be({destinationName:e,archive:t,picked:r}){return n(`div`,{className:`p-4 space-y-3 text-xs`,children:[s(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-amber-700 dark:text-amber-300`,children:`Restore is applied at next server boot. Active connections will drop when you restart.`}),n(`dl`,{className:`space-y-1.5`,children:[s($,{term:`Destination`,value:e}),s($,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&s($,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${G(t.sizeBytes)}`}),s($,{term:`Locations`,value:r.length>0?r.join(`, `):`— (full archive)`})]})]})}function $({term:e,value:t}){return n(`div`,{className:`flex justify-between gap-3`,children:[s(`dt`,{className:`text-foreground-subtle`,children:e}),s(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var Ve={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function He(e){return Ve[e]??``}t();function Ue(){let e=E(),t=u(),[r,i]=o(null),[a,c]=o(!1),[l,d]=o(!1),[f,p]=o(void 0),m=async()=>{await e({title:`Restart server now?`,message:`Active connections will drop and the apply-backup hook will run before boot.`,confirmLabel:`Restart`,variant:`warning`})&&t.mutate({confirm:!0})};return n(H,{children:[n(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[n(`button`,{onClick:()=>c(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[s(L,{className:`h-3.5 w-3.5`}),`Restore…`]}),n(`button`,{onClick:()=>p(null),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[s(ne,{className:`h-3.5 w-3.5`}),`New entry`]})]}),l&&s(`div`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2.5 text-xs text-amber-700 dark:text-amber-300`,children:n(`div`,{className:`flex items-center justify-between gap-3`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(L,{className:`h-3.5 w-3.5`}),s(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),n(`button`,{onClick:()=>{m()},disabled:t.isPending,className:`inline-flex items-center gap-1.5 rounded bg-amber-500/20 px-2 py-1 font-medium text-amber-800 dark:text-amber-200 hover:bg-amber-500/30 disabled:opacity-50`,children:[t.isPending?s(V,{className:`h-3.5 w-3.5 animate-spin`}):s(L,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),s(Oe,{}),s(ge,{onEdit:e=>p(e),onOpenRestoreWizard:e=>i(e)}),f!==void 0&&s(we,{entry:f,onClose:()=>p(void 0),onSaved:()=>p(void 0)}),(r||a)&&s(Le,{...r?{initialDestinationId:r.destinationId,initialArchiveId:r.archiveId}:{},onClose:()=>{i(null),c(!1)},onScheduled:()=>d(!0)})]})}function We(){return s(`div`,{className:`flex flex-col p-4`,children:s(W,{tabs:[{id:`storage`,label:`Storage`,icon:ee,content:s(ue,{})},{id:`backup`,label:`Backup`,icon:K,content:s(Ue,{})}]})})}export{We as DataPage};