@camstack/addon-admin-ui 1.2.613 → 1.2.614
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.
- package/CHANGELOG.md +7 -0
- package/dist/assets/Addons-BJfkLwLO.js +5 -0
- package/dist/assets/{AdminPage-CQKqrawX.js → AdminPage-CFwzuQZq.js} +1 -1
- package/dist/assets/{AdminSectionedPage-DwIVrzMv.js → AdminSectionedPage-CLelstTQ.js} +1 -1
- package/dist/assets/{AiProfiles-BmANABOn.js → AiProfiles-BRWqnNZw.js} +2 -2
- package/dist/assets/{Authentication-C2KfbF99.js → Authentication-DnTfdKv0.js} +1 -1
- package/dist/assets/Build-Dcb2pWJ3.js +39 -0
- package/dist/assets/{Calendars-C3xWZQbZ.js → Calendars-e6-I6axd.js} +1 -1
- package/dist/assets/{CameraGrids-BBCAyFtL.js → CameraGrids-B50NWiaX.js} +1 -1
- package/dist/assets/{Cluster-Cnoc9etN.js → Cluster-D9cpYS50.js} +1 -1
- package/dist/assets/{CompositionBlockEditor-DnMSvA7o.js → CompositionBlockEditor-B6jhi4aP.js} +2 -2
- package/dist/assets/{CompositionEditorPage-72libfQe.js → CompositionEditorPage-BNCoZYmk.js} +1 -1
- package/dist/assets/{Data-BsFgvDDc.js → Data-BFkaT-HN.js} +2 -2
- package/dist/assets/DeviceDetail-CRQXzGOA.js +2 -0
- package/dist/assets/{DeviceDoActionFields-B5up4yrq.js → DeviceDoActionFields-Ck7XT6eT.js} +1 -1
- package/dist/assets/{Devices-D6FHREfO.js → Devices-BheZyJ-P.js} +1 -1
- package/dist/assets/{EditTemplateButton-DPX0WOqP.js → EditTemplateButton-DfaR1xaE.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-C-RZWQie.js → EmbedPlayerPage-BLyprrLe.js} +1 -1
- package/dist/assets/History-CMAcE6-w.js +1 -0
- package/dist/assets/Identity-BLgJKNk9.js +1 -0
- package/dist/assets/{InstancesTable-CmdXLlKr.js → InstancesTable-D2yWNUaZ.js} +1 -1
- package/dist/assets/IntegrationDetail-xN1LX9eo.js +1 -0
- package/dist/assets/{IntegrationHub-B9BtSaMu.js → IntegrationHub-C2lol4OL.js} +1 -1
- package/dist/assets/{Integrations-DFWCDQ4i.js → Integrations-DcQm6Aj2.js} +2 -2
- package/dist/assets/Integrations-g-niY6cn.js +1 -0
- package/dist/assets/{Library-0JeelG3C.js → Library-CyT_JYCP.js} +1 -1
- package/dist/assets/{Locations-idlnsvni.js → Locations-EQv-h_uV.js} +2 -2
- package/dist/assets/{Logs-9-5UvjLl.js → Logs-DnrXua_L.js} +1 -1
- package/dist/assets/{MaskShapeCanvas-DlWfqm1o.js → MaskShapeCanvas-C6oPs8v9.js} +1 -1
- package/dist/assets/{MotionZonesSettings-Dsogfste.js → MotionZonesSettings-CQDdomka.js} +1 -1
- package/dist/assets/MyAccess-B_zQMOku.js +2 -0
- package/dist/assets/{Network-fU18SAUw.js → Network-6hbESyUy.js} +1 -1
- package/dist/assets/NodeAddonsSettingsPanel-cxbuP4ql.js +1 -0
- package/dist/assets/Notifications-NBpKEuZV.js +1 -0
- package/dist/assets/Pipeline-BvFoujQo.js +1 -0
- package/dist/assets/{PrivacyMaskSettings-GEXILi7D.js → PrivacyMaskSettings-B393FBCM.js} +1 -1
- package/dist/assets/Recordings-D5nf9HZf.js +1 -0
- package/dist/assets/{ScanSubnetEditor-D8DeFgGd.js → ScanSubnetEditor-DDCY_Smw.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-DNjCVEYZ.js → SceneMonitorEditor-C4SLNj7I.js} +1 -1
- package/dist/assets/{SessionsList-hKb6VChZ.js → SessionsList-DpwHjjFs.js} +2 -2
- package/dist/assets/{Showroom-DpUejfiW.js → Showroom-CAKlBSf_.js} +1 -1
- package/dist/assets/{StorageLocationsTable-BTWBlLcF.js → StorageLocationsTable-CqPhkqVL.js} +1 -1
- package/dist/assets/System-tBNwbwSw.js +1 -0
- package/dist/assets/{Templates-sjHTHHlU.js → Templates-15bFODqK.js} +1 -1
- package/dist/assets/{Terminal-k7iMG1o7.js → Terminal-CKF5OWVY.js} +3 -3
- package/dist/assets/{TrainingProviders-CLlxgUAb.js → TrainingProviders-TZdkLaIZ.js} +1 -1
- package/dist/assets/{Viewer-CkbwufzS.js → Viewer-DFYKi9Wb.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DC97HC4f.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BP4WbWeD.js} +1 -1
- package/dist/assets/{addon-icons-context-C0tNs6xW.js → addon-icons-context-BATuZHTE.js} +1 -1
- package/dist/assets/{archive-q0nUTtLZ.js → archive-BoBKxtQ-.js} +1 -1
- package/dist/assets/{assignment-candidates-BSthRvB4.js → assignment-candidates-CxG90bWr.js} +1 -1
- package/dist/assets/{authed-media-BKgp95tT.js → authed-media-DnXUvZXJ.js} +1 -1
- package/dist/assets/{bell-off-CAtUxhvq.js → bell-off-BzoeiUVh.js} +1 -1
- package/dist/assets/{boxes-B_Eu0xYD.js → boxes-C6W6e-rK.js} +1 -1
- package/dist/assets/{calendar-clock-dlTytvhp.js → calendar-clock-pwKTUpB4.js} +1 -1
- package/dist/assets/circle-slash-B2xq8hu-.js +1 -0
- package/dist/assets/client-Dd2wRwgL.js +809 -0
- package/dist/assets/create-composition-D1HcJt41.js +2 -0
- package/dist/assets/crop-DdLH59eG.js +1 -0
- package/dist/assets/{database-zap-DSRFTyhx.js → database-zap-BixS9sEU.js} +1 -1
- package/dist/assets/{device-integration-icon-DJJlbRLB.js → device-integration-icon-B20WxJ4F.js} +1 -1
- package/dist/assets/device-picker-model-DVfMULL6.js +1 -0
- package/dist/assets/{dist-B4-yMFSq.js → dist-BGAl5BvD.js} +1 -1
- package/dist/assets/dist-Cs_aK-Rt.js +809 -0
- package/dist/assets/{eraser-CUhE6HSY.js → eraser-BgUWN8pT.js} +1 -1
- package/dist/assets/{file-up-CXWI0vro.js → file-up-DH881GrF.js} +1 -1
- package/dist/assets/{grip-vertical-BXgHxWsV.js → grip-vertical-_jfdera5.js} +1 -1
- package/dist/assets/{hard-drive-download-VeG-eE4r.js → hard-drive-download-BGhjVh74.js} +1 -1
- package/dist/assets/{hostInit-C1WJ96M_.js → hostInit-CO036Kz-.js} +1 -1
- package/dist/assets/{icons-VDLpNA-_.js → icons-BUi4kBRk.js} +1 -1
- package/dist/assets/{index-DbICehF2.js → index-BCsJtJDS.js} +3 -3
- package/dist/assets/{key-P9Z4k-0x.js → key-4O6zcP-D.js} +1 -1
- package/dist/assets/{key-square-DIbfpLYV.js → key-square-45doQ7Dg.js} +1 -1
- package/dist/assets/{layers-550lFq3G.js → layers-DaT1iT13.js} +1 -1
- package/dist/assets/{link-2-off-BdR1HwXS.js → link-2-off-DtNWZ97C.js} +1 -1
- package/dist/assets/{linked-devices-model-CgT70tWv.js → linked-devices-model-BxWV-O4v.js} +1 -1
- package/dist/assets/{list-ordered-DkmlIGQW.js → list-ordered-cIv3ExKb.js} +1 -1
- package/dist/assets/{memory-stick-C7a1pnZA.js → memory-stick-PjDavRx_.js} +1 -1
- package/dist/assets/{message-square-plus-BbSNBLpN.js → message-square-plus-DXescy-B.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-1031b78a.js → mf-entry-bootstrap-0-f77a2fc3.js} +2 -2
- package/dist/assets/{mic-off-BQRhIJ6Z.js → mic-off-BXQSysjl.js} +1 -1
- package/dist/assets/{monitor-off-Dnx5Uidp.js → monitor-off-DBW86jnf.js} +1 -1
- package/dist/assets/{monitor-smartphone-C08yRk5k.js → monitor-smartphone-BuyeEe1i.js} +1 -1
- package/dist/assets/mount-DVfMULL6.js +1 -0
- package/dist/assets/{player-overlays-ywd6nvhM.js → player-overlays-DRJ5jYka.js} +1 -1
- package/dist/assets/remoteEntry-BvXi9rH1.js +1 -0
- package/dist/assets/{ruler-DLPl8aKF.js → ruler-Bu3N8rrH.js} +1 -1
- package/dist/assets/{scan-eye-C7Kvo33Q.js → scan-eye-BZaxSxlS.js} +1 -1
- package/dist/assets/{scissors-D9pfuljG.js → scissors-DJgb5Dpv.js} +1 -1
- package/dist/assets/{search-x-CyWzUJHP.js → search-x-CXApjOId.js} +1 -1
- package/dist/assets/{send-DHAuefQL.js → send-SWldcTuN.js} +1 -1
- package/dist/assets/{settings-2-C0E3sNyV.js → settings-2-CWXy2awV.js} +1 -1
- package/dist/assets/{shapes-DUA5YHLG.js → shapes-BmXpqq30.js} +1 -1
- package/dist/assets/{sigma-BDlc8TxF.js → sigma-DiGmvY8h.js} +1 -1
- package/dist/assets/{speaker-D8B2puzu.js → speaker-B8m2jKCq.js} +1 -1
- package/dist/assets/src-He9Tsysa.js +100 -0
- package/dist/assets/{step-inspector-model-BQR3F7Jg.js → step-inspector-model-qn2KNkFH.js} +1 -1
- package/dist/assets/{table-2-Cjb75Gi9.js → table-2-D4kzIxer.js} +1 -1
- package/dist/assets/{timer-reset-H8wqMb8F.js → timer-reset-kOifM6eK.js} +1 -1
- package/dist/assets/{unlink-BQ-yuMty.js → unlink-C_Ulygv5.js} +1 -1
- package/dist/assets/{usb-DDx9zAx4.js → usb-CkkUZj4I.js} +1 -1
- package/dist/assets/{use-device-bound-caps-BZuh_-FO.js → use-device-bound-caps-CZpFb_Qq.js} +1 -1
- package/dist/assets/{use-scenes-feed-CYqbMC8a.js → use-scenes-feed-Cu_zC57R.js} +1 -1
- package/dist/assets/{use-stationary-objects-BRzkuAzf.js → use-stationary-objects-Q5PKhCS6.js} +1 -1
- package/dist/assets/{useAdminDeviceRemoval-B3-kERGS.js → useAdminDeviceRemoval-Bz4WkutY.js} +1 -1
- package/dist/assets/useEventInvalidation-DVfMULL6.js +1 -0
- package/dist/assets/{useNodeUrlSelection-ndIqCMdG.js → useNodeUrlSelection-tdR3ldN7.js} +1 -1
- package/dist/assets/user-round-DjzMluaj.js +1 -0
- package/dist/assets/{user-x-ACxq5S24.js → user-x-BLftkftU.js} +1 -1
- package/dist/assets/{variable-DE3g0D48.js → variable-DjMixfBE.js} +1 -1
- package/dist/assets/{video-BvnxG-kU.js → video-CYBcnY0R.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Kr7hlZBe.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-C8oQmSMS.js} +2 -2
- package/dist/index.html +8 -8
- package/dist/server/addon.js +447 -595
- package/package.json +2 -2
- package/dist/assets/Addons-CqYKVI-X.js +0 -5
- package/dist/assets/Build-D7fMtVOm.js +0 -39
- package/dist/assets/DeviceDetail-xmvg__cy.js +0 -2
- package/dist/assets/History-DWl0AFGJ.js +0 -1
- package/dist/assets/Identity-DTaZ5LwU.js +0 -1
- package/dist/assets/IntegrationDetail-Dy7KkoXf.js +0 -1
- package/dist/assets/Integrations-Db97Y6T6.js +0 -1
- package/dist/assets/MyAccess-B1AP34J3.js +0 -2
- package/dist/assets/NodeAddonsSettingsPanel-z9e763EA.js +0 -1
- package/dist/assets/Notifications-Do0-oVK9.js +0 -1
- package/dist/assets/Pipeline-prDhU2J4.js +0 -1
- package/dist/assets/Recordings-DsJl2FhW.js +0 -1
- package/dist/assets/System-BXb83rJF.js +0 -1
- package/dist/assets/circle-slash-w9FRTZfM.js +0 -1
- package/dist/assets/client-mCEzjXIR.js +0 -809
- package/dist/assets/create-composition-Qtc7PTdK.js +0 -2
- package/dist/assets/crop-D5ieSxDF.js +0 -1
- package/dist/assets/device-picker-model-D7WYy-h_.js +0 -1
- package/dist/assets/dist-1KrVcdTB.js +0 -809
- package/dist/assets/mount-D7WYy-h_.js +0 -1
- package/dist/assets/remoteEntry-LTVk7I4e.js +0 -1
- package/dist/assets/src-DmG3r3oz.js +0 -100
- package/dist/assets/useEventInvalidation-D7WYy-h_.js +0 -1
- package/dist/assets/user-round-BcQrMUco.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@camstack/addon-admin-ui",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.614",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Admin UI — Vite frontend build and server-side addon",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
}
|
|
51
51
|
],
|
|
52
52
|
"requires": {
|
|
53
|
-
"server": ">=1.2.
|
|
53
|
+
"server": ">=1.2.805"
|
|
54
54
|
}
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import{B as e,C as t,J as n,K as r,R as i,S as a,V as o,Y as s,et as c,o as l,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$n as d,Bn as f,Fn as p,Ii as m,Kt as h,Li as g,Ni as _,Oi as v,Q as y,Rt as b,Sn as x,Tn as S,Ut as C,ai as w,bi as T,bt as ee,ct as te,fn as ne,ot as re,ut as E,wn as ie,xr as D}from"./player-overlays-ywd6nvhM.js";import{vs as O}from"./client-mCEzjXIR.js";import{a as k,p as ae}from"./video-BvnxG-kU.js";import{$i as A,Br as oe,Ei as se,Fr as ce,Hc as j,Ir as le,Of as M,Pr as ue,Rr as N,Vt as de,Xs as fe,Zi as pe,_a as P,_n as me,aa as he,af as ge,ar as F,ba as _e,ca as I,da as L,ea as R,er as z,fa as ve,ga as B,gn as ye,ha as be,ia as V,jf as xe,jt as H,la as U,ma as Se,na as Ce,nr as we,oa as W,ra as Te,rr as Ee,ta as De,tr as Oe,ua as ke,vi as G,xa as Ae,ya as je,zr as Me}from"./src-DmG3r3oz.js";import{t as K}from"./useTranslation-BJr-n0es.js";import"./mount-D7WYy-h_.js";import{Br as Ne,Pr as Pe,Rr as q}from"./index-DbICehF2.js";import{t as J}from"./AdminPage-CQKqrawX.js";import{i as Fe,r as Ie,t as Le}from"./addon-kind-filter-CEGKkC1O.js";import{t as Re}from"./framework-packages-DoBKjjer.js";import{t as Y}from"./NodeAddonsSettingsPanel-z9e763EA.js";import{n as ze,t as Be}from"./useNodeUrlSelection-ndIqCMdG.js";function Ve(e){if(e===void 0)return null;switch(e.state){case`failed`:case`refused`:case`missing`:case`crashed`:return{kind:e.state,...e.reason===void 0?{}:{reason:e.reason}};default:return null}}c();var X={queued:{icon:T,bg:`bg-muted text-foreground-subtle`,labelKey:`addons.addonRowBadge.queued`},updating:{icon:D,bg:`bg-primary/10 text-primary`,labelKey:`addons.addonRowBadge.updating`,spin:!0},"done-pending-restart":{icon:p,bg:`bg-amber-500/10 text-amber-700`,labelKey:`addons.addonRowBadge.pendingRestart`},done:{icon:g,bg:`bg-success/10 text-success`,labelKey:`addons.addonRowBadge.done`},failed:{icon:k,bg:`bg-danger/10 text-danger`,labelKey:`addons.addonRowBadge.failed`}};function Z({item:e}){let{t:n}=K(),r=X[e.status],i=r.icon;return t(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded ${r.bg}`,title:e.error,children:[a(i,{className:`w-2.5 h-2.5 ${r.spin?`animate-spin`:``}`}),n(r.labelKey)]})}var He=new Set([`completed`,`failed`,`partially-failed`,`cancelled`]),Ue=new Set([`done`,`failed`,`skipped`]);function We(e){return!Ue.has(e.phase)&&!He.has(e.jobState)}function Ge(e,t){let n=new Map,r=[...e].sort((e,t)=>e.createdAtMs-t.createdAtMs);for(let e of r){let r=He.has(e.state);for(let i of e.tasks)r&&i.finishedAtMs!==null&&t-i.finishedAtMs>6e4||n.set(i.packageName,{jobId:e.jobId,packageName:i.packageName,phase:i.phase,fromVersion:i.fromVersion,toVersion:i.toVersion,error:i.error,jobState:e.state,finishedAtMs:i.finishedAtMs})}return n}function Ke(){let{data:e}=U({activeOnly:!0},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data?.length??0)>0?3e3:!1}),{map:t}=xe(O.AddonsJobProgress,e=>e.job.jobId);return r(()=>{let n=new Map;for(let t of e??[])n.set(t.jobId,t);for(let[e,r]of t)n.set(e,r.job);return Ge([...n.values()],Date.now())},[e,t])}var qe={queued:{icon:T,cls:`bg-muted text-foreground-subtle`,labelKey:`addons.jobProgress.queued`},fetching:{icon:D,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.fetching`,spin:!0},staged:{icon:D,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.staged`,spin:!0},validating:{icon:D,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.validating`,spin:!0},applying:{icon:D,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.applying`,spin:!0},restarting:{icon:D,cls:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,labelKey:`addons.jobProgress.restarting`,spin:!0},applied:{icon:D,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.finalizing`,spin:!0},done:{icon:g,cls:`bg-success/10 text-success`,labelKey:`addons.jobProgress.updated`},failed:{icon:k,cls:`bg-danger/10 text-danger`,labelKey:`addons.jobProgress.failed`},skipped:{icon:ne,cls:`bg-muted text-foreground-subtle`,labelKey:`addons.jobProgress.skipped`}};function Je({progress:e}){let{t:n}=K(),r=qe[e.phase],i=r.icon,o=e.error??`${e.packageName}: ${e.fromVersion??`?`} → ${e.toVersion}`;return t(`span`,{"data-testid":`addon-job-progress`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded shrink-0 ${r.cls}`,title:o,children:[a(i,{className:`w-2.5 h-2.5 ${r.spin?`animate-spin`:``}`}),n(r.labelKey),t(`span`,{className:`font-mono`,children:[`→ `,e.toVersion]})]})}function Ye(e,t){return e.filter(e=>e.packageName===t).slice().sort((e,t)=>e.isHub===t.isHub?e.nodeName.localeCompare(t.nodeName):e.isHub?-1:1)}function Xe(e){let t=e.version===null?``:` ${e.version}`,n=e.isOnline?``:` (offline: removed when it reconnects)`;return`- ${e.nodeName}${t}${n}`}function Q(e,t,n){let r=[`${e} will be uninstalled from ${t.length} node(s). Its runners stop, its capabilities are deregistered and its code is deleted:`,...t.map(Xe)];return n.length>0&&r.push(`Could not ask: ${n.join(`, `)} — not included.`),r.push(`This cannot be undone.`),r.join(`
|
|
2
|
-
`)}function Ze(e,t,n){let r=[`${e} will be uninstalled from ${t}: its runners stop and its code is deleted.`];return n.length>0&&r.push(`It stays installed on: ${n.map(e=>e.nodeName).join(`, `)}. Use "Everywhere" to remove it from every node.`),r.push(`This cannot be undone.`),r.join(`
|
|
3
|
-
`)}var Qe={uninstalled:`uninstalled`,"not-installed":`was not installed`,refused:`REFUSED`,failed:`FAILED`,"pending-reconnect":`offline — removed when it reconnects`};function $e(e,t){let n=[];for(let r of e.results){let e=r.runnersStopped.length>0?` (stopped ${r.runnersStopped.join(`, `)})`:``;n.push(`${t(r.nodeId)}: ${Qe[r.outcome]}${e}`),r.error!==void 0&&n.push(` ${r.error}`);for(let e of r.warnings)n.push(` ${e}`)}return n.join(`
|
|
4
|
-
`)}var et={},tt=3e4,nt=`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-border text-foreground-subtle hover:text-red-400 hover:border-red-500/30 hover:bg-red-500/10 disabled:opacity-50 transition-colors`;function rt({packageName:e,displayName:n,selectedNode:r,hideNodeAction:i,disabled:o}){let{t:s}=K(),c=l(),u=te(),d=re(),f=I(et,{staleTime:tt}),p=f.data?.installations??[],m=(f.data?.unreachable??[]).map(e=>e.nodeId),g=Ye(p,e),_=e=>g.find(t=>t.nodeId===e)?.nodeName??(e===r.id?r.name:e),v=_e({onSettled:()=>{c.invalidateQueries({queryKey:[[`addons`]]}),c.invalidateQueries({queryKey:[[`addonPages`]]}),c.invalidateQueries({queryKey:[[`capabilities`]]}),c.invalidateQueries({queryKey:[[`nodes`]]})}}),y=async e=>{await d({title:e.success?s(`addons.addonUninstallControls.uninstalled`,`{{displayName}} uninstalled`,{displayName:n}):s(`addons.addonUninstallControls.notEveryNodeWasCleaned`,`{{displayName}}: not every node was cleaned`,{displayName:n}),message:$e(e,_),variant:e.success?`default`:`danger`})},b=async t=>{try{await y(await v.mutateAsync({packageName:e,...t}))}catch(e){await d({title:s(`addons.addonUninstallControls.uninstallFailed`,`Uninstall {{displayName}} failed`,{displayName:n}),message:e instanceof Error?e.message:String(e),variant:`danger`})}},x=async()=>{let e=g.filter(e=>e.nodeId!==r.id);await u({title:s(`addons.addonUninstallControls.uninstallFrom`,`Uninstall {{displayName}} from {{name}}?`,{displayName:n,name:r.name}),message:Ze(n,r.name,e),confirmLabel:s(`addons.addonUninstallControls.uninstall`,`Uninstall`),variant:`danger`})&&await b(r.isHub?{}:{nodeId:r.id})},S=async()=>{let t=(await f.refetch()).data;if(t===void 0){await d({title:s(`addons.addonUninstallControls.cannotListTheNodes`,`Cannot list the nodes`),message:s(`addons.addonUninstallControls.theHubDidNotAnswer`,`The hub did not answer which nodes have this package — nothing was removed.`),variant:`danger`});return}let r=Ye(t.installations,e);await u({title:s(`addons.addonUninstallControls.uninstallEverywhere`,`Uninstall {{displayName}} everywhere?`,{displayName:n}),message:Q(n,r,t.unreachable.map(e=>e.nodeId)),confirmLabel:s(`addons.addonUninstallControls.uninstallFromNodeS`,`Uninstall from {{length}} node(s)`,{length:r.length}),variant:`danger`})&&await b({everywhere:!0})},C=v.isPending||o===!0;return t(`div`,{className:`flex items-center gap-1.5`,children:[i!==!0&&t(G,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),x()},disabled:C,className:nt,title:s(`addons.addonUninstallControls.uninstallFrom2`,`Uninstall from {{name}}`,{name:r.name}),children:[a(h,{className:`h-3 w-3`}),v.isPending?s(`addons.addonUninstallControls.removing`,`Removing...`):s(`addons.addonUninstallControls.uninstall`,`Uninstall`)]}),(g.length>1||i===!0||m.length>0)&&t(G,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),S()},disabled:C,className:nt,title:s(`addons.addonUninstallControls.uninstallFromEveryNodeThat`,`Uninstall from every node that has it`),children:[a(ae,{className:`h-3 w-3`}),g.length>0?s(`addons.uninstallControls.everywhereCount`,{count:g.length}):s(`addons.uninstallControls.everywhere`)]})]})}function it(e){return typeof e.deprecated==`string`&&e.deprecated.length>0}function at(e,t){return t?e:e.filter(e=>e.distTags.includes(`latest`)||!it(e))}function ot(e){return e.length-at(e,!1).length}c();function st({packageName:e,currentVersion:n,installSource:r,onInstall:i,onClose:o,onSelect:c,selectedVersion:l}){let{t:d}=K(),f=r===`upload`||r===`local`,[p,m]=s(!1),{data:h,isLoading:_,isError:v}=V({name:e}),y=h?at(h,p):[],x=h?ot(h):0;return t(`div`,{className:`fixed z-50 w-72 rounded-lg border border-border bg-surface shadow-xl overflow-hidden`,style:{top:`auto`,bottom:`auto`},ref:e=>{if(!e)return;let t=e.parentElement?.getBoundingClientRect();if(!t)return;let n=window.innerHeight-t.bottom,r=t.top;n<280&&r>n?(e.style.bottom=`${window.innerHeight-t.top+4}px`,e.style.top=`auto`):(e.style.top=`${t.bottom+4}px`,e.style.bottom=`auto`),e.style.right=`${window.innerWidth-t.right}px`},onClick:e=>e.stopPropagation(),children:[t(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[a(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:d(`addons.versionPicker.versions`,`Versions`)}),a(G,{variant:`unstyled`,type:`button`,onClick:o,className:`text-foreground-subtle hover:text-foreground`,children:a(ee,{className:`h-3 w-3`})})]}),f&&t(`div`,{className:`flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]`,children:[a(b,{className:`h-3 w-3 mt-0.5 text-cyan-500 shrink-0`}),t(`div`,{className:`text-cyan-700 dark:text-cyan-200`,children:[a(`span`,{className:`font-semibold`,children:d(`addons.versionPicker.inPlace`,{kind:r===`upload`?d(`addons.versionPicker.uploadedCopy`,`Uploaded copy`):d(`addons.versionPicker.localCopy`,`Local copy`)})}),` `,a(Pe,{i18nKey:`addons.versionPicker.reinstall`,values:{version:n},components:{mono:a(`span`,{className:`font-mono`})}})]})]}),_&&t(`div`,{className:`flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle`,children:[a(D,{className:`h-3.5 w-3.5 animate-spin`}),d(`addons.versionPicker.loadingVersions`,`Loading versions...`)]}),v&&a(`div`,{className:`px-3 py-4 text-center text-[10px] text-danger`,children:d(`addons.versionPicker.registryError`,`Could not load versions from the registry.`)}),y.length>0&&a(`div`,{className:`max-h-64 overflow-auto divide-y divide-border`,children:y.map(e=>{let r=e.version===n,o=c!==void 0&&e.version===l,s=/-(alpha|beta|rc|dev|canary|next)/i.test(e.version),f=t(u,{children:[a(`span`,{className:`font-mono flex-1 text-left ${r?`text-primary font-semibold`:s?`text-amber-400`:`text-foreground`}`,children:e.version}),r&&a(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium bg-primary/10 text-primary`,children:d(`common.current`)}),e.distTags.map(e=>a(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e===`latest`?`bg-emerald-500/15 text-emerald-400`:e===`beta`?`bg-amber-500/15 text-amber-400`:`bg-gray-500/15 text-gray-400`}`,children:e},e)),it(e)&&a(`span`,{className:`text-[9px] text-red-400 line-through`,children:d(`common.deprecated`)}),a(`span`,{className:`text-[9px] text-foreground-subtle shrink-0`,children:new Date(e.publishedAt).toLocaleDateString()})]});return c?t(G,{variant:`unstyled`,type:`button`,"aria-label":d(`addons.versionPicker.select`,`Select {{version}}`,{version:e.version}),onClick:()=>c(e.version),className:`w-full flex items-center gap-2 px-3 py-2 text-[11px] ${o?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[f,o?a(g,{className:`h-3 w-3 text-primary shrink-0`}):a(`span`,{className:`w-3 shrink-0`})]},e.version):t(`div`,{className:`flex items-center gap-2 px-3 py-2 text-[11px] ${r?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[f,a(G,{variant:`unstyled`,type:`button`,onClick:()=>i(e.version),className:`shrink-0 rounded p-0.5 hover:bg-primary/20 text-foreground-subtle hover:text-primary transition-colors`,title:r?d(`addons.versionPicker.reInstallFromNpm`,`Re-install {{version}} from npm`,{version:e.version}):d(`addons.versionPicker.install`,`Install {{version}}`,{version:e.version}),children:a(w,{className:`h-3 w-3`})})]},e.version)})}),!_&&!v&&h&&h.length===0&&a(`div`,{className:`py-4 text-center text-[10px] text-foreground-subtle`,children:d(`addons.versionPicker.noVersionsFound`,`No versions found`)}),x>0&&a(G,{type:`button`,variant:`ghost`,size:`sm`,className:`h-auto w-full justify-start rounded-none border-t border-border px-3 py-2 text-left text-[10px] font-normal text-foreground-subtle`,onClick:()=>m(e=>!e),children:p?d(`addons.versionPicker.hideOlder`,`Hide older versions`):d(`addons.versionPicker.showOlder`,`Show older versions ({{count}})`,{count:x})})]})}c();var ct=`device-export`;function lt(e){return e.capabilities.some(e=>(typeof e==`string`?e:e.name)===ct)}function ut(e){return e!==`local`&&e!==`upload`}function dt({isBundle:e,installSource:n,addonId:r,iconPath:i,color:o}){let[c,l]=s(!1),u=o?{backgroundColor:`${o.startsWith(`#`)?o:`#${o}`}26`}:void 0,p=e?`bg-indigo-500/20 text-indigo-700 dark:text-indigo-300`:`bg-purple-500/20 text-purple-700 dark:text-purple-300`,m=r&&i?y(`/api/addon-assets/${r}/${i}`):null,h=!!m&&!c;return t(`div`,{className:`relative flex-shrink-0`,children:[a(`div`,{className:`h-8 w-8 rounded-md flex items-center justify-center ${u?``:p}`,style:u,children:h?a(`img`,{src:m,alt:r,className:`h-4 w-4`,onError:()=>l(!0)}):a(e?d:f,{className:`h-3.5 w-3.5`})}),n===`local`&&a(`span`,{className:`absolute -top-1.5 -left-1.5 text-[7px] font-bold leading-none bg-orange-500 text-white px-1 py-0.5 rounded -rotate-12 shadow-sm`,children:`DEV`}),ut(n)&&a(`span`,{className:`absolute -top-1 -left-1 w-4 h-4 rounded bg-[#cb3837] flex items-center justify-center -rotate-12 shadow-sm`,children:a(`svg`,{viewBox:`0 0 780 250`,className:`w-[11px] h-[11px]`,children:a(`path`,{fill:`#fff`,d:`M240 250h100V50h100v200h340V0H0v250z`})})}),n===`upload`&&a(`span`,{className:`absolute -top-1.5 -left-1.5 flex items-center justify-center h-4 w-4 rounded bg-cyan-500 -rotate-12 shadow-sm`,children:a(b,{className:`h-2.5 w-2.5 text-white`})})]})}function ft({version:e,availableUpdate:n,selectedVersion:r,isUpdating:i,installSource:o,disabled:s,onUpdate:c,onOpenPicker:l,children:u}){let{t:d}=K();if(i)return t(`span`,{className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border border-blue-500/30 bg-blue-500/10 text-blue-400 shrink-0`,children:[a(D,{className:`h-3 w-3 animate-spin`}),d(`addons.addonCard.updating`,`Updating…`)]});if(n){let i=r??n;return t(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[c&&t(G,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),c()},disabled:s,className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-semibold border border-blue-500/30 bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,title:d(`addons.addonCard.updateTo`,`Update to {{target}}`,{target:i}),children:[a(w,{className:`h-3 w-3`}),d(`addons.addonCard.update`,`Update`)]}),t(G,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),l()},disabled:s,"aria-label":d(`addons.addonCard.selectVersionToInstall`,`Select version to install`),title:d(`addons.addonCard.installedUpdateAvailableSelectedTap`,`Installed {{version}} — update available. Selected {{target}}; tap to choose another version.`,{version:e,target:i}),className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-bold font-mono border border-amber-500/40 bg-amber-500/15 text-amber-500 hover:bg-amber-500/25 animate-pulse disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[a(`span`,{className:`font-normal opacity-70`,children:e}),a(`span`,{className:`font-normal opacity-70`,children:`→`}),i,a(m,{className:`h-3 w-3`})]}),u]})}return t(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[t(G,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),l()},disabled:s,className:[`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-bold font-mono border transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,o===`local`?`border-orange-500/30 bg-orange-500/10 text-orange-400 hover:bg-orange-500/20`:`border-emerald-500/30 bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20`].join(` `),title:d(`addons.addonCard.versionTapToViewAll`,`Version {{version}} — tap to view all versions`,{version:e}),children:[e,a(m,{className:`h-3 w-3 opacity-50`})]}),u]})}function pt({addonId:e}){let t=l(),{data:n=`inherit`}=R({addonId:e}),r=B({onSuccess:()=>{t.invalidateQueries({queryKey:[[`addons`,`getAddonAutoUpdate`]]})}});return a(`div`,{className:`flex rounded-lg border border-border overflow-hidden text-[10px] font-medium`,children:[`inherit`,`off`,`latest`,`beta`].map(t=>a(G,{variant:`unstyled`,type:`button`,onClick:n=>{n.stopPropagation(),r.mutate({addonId:e,channel:t})},disabled:r.isPending,className:`px-2.5 py-1 transition-colors capitalize ${n===t?t===`inherit`?`bg-gray-700/50 text-gray-700 dark:text-gray-300`:t===`off`?`bg-gray-700 text-gray-700 dark:text-gray-300`:t===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${t===`inherit`?``:`border-l border-border`}`,children:t},t))})}var mt={id:`hub`,name:`Hub`,isHub:!0};function ht({addon:e,clusterStatus:n,hideVersion:r,availableUpdate:i,blockedUpdate:c,onUpdate:f,isUpdating:h,jobProgress:g,bundle:v,bulkItem:y,disabledByBulk:b,isSystem:C,selectedNode:w}){let{t:T}=K(),[te,ne]=s(!1),[re,E]=s(!1),[ie,D]=s(null);o(()=>{D(null)},[i]);let O=ie??i,[ae,A]=s(!1),[j,M]=s(!1),[fe,pe]=s(`logs`),P=l(),ge=q(),{manifest:F}=e,_e=!v&&!F.protected&&F.removable!==!1,I=!!v,L=v?.displayName??F.name,R=v?.packageName??F.packageName,z=v?.version??F.packageVersion??F.version,B=v?.installSource??e.installSource,be=v?v.bundle?.description??v.addons[0]?.manifest.description:F.description,V=ve({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]})}}),xe=he({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]}),P.invalidateQueries({queryKey:[[`addonPages`]]}),P.invalidateQueries({queryKey:[[`capabilities`]]}),P.invalidateQueries({queryKey:[[`integrations`]]})}}),H=Se({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]}),P.invalidateQueries({queryKey:[[`alerts`]]})}}),U=e.health,Ce=U?.phase===`failed`&&!U.inGracePeriod,we=Ce&&U?.nextRetryAt&&!U.retrying,W=Ve(e.process);return t(`div`,{className:`rounded-md border bg-surface overflow-hidden ${Ce?`border-red-500/50`:`border-border`}`,children:[Ce&&U&&t(`div`,{className:`bg-danger/10 border-b border-danger/30 px-3 py-2 flex items-start gap-2`,children:[a(k,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),t(`div`,{className:`flex-1 min-w-0`,children:[a(`div`,{className:`text-xs font-semibold text-danger`,children:T(`addons.addonCard.failedToLoad`,{attempt:U.retryCount})}),a(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:U.lastError?.message??T(`addons.addonCard.unknownError`,`Unknown error`)}),we&&U.nextRetryAt&&a(`div`,{className:`text-[10px] text-foreground-subtle mt-1`,children:T(`addons.addonCard.autoRetryAt`,{time:new Date(U.nextRetryAt).toLocaleTimeString()})})]}),t(G,{variant:`unstyled`,type:`button`,disabled:H.isPending||U.retrying,onClick:e=>{e.stopPropagation(),H.mutate({packageName:R})},className:`inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] font-semibold border border-red-400/40 bg-red-400/10 text-red-700 dark:text-red-300 hover:bg-red-400/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors shrink-0`,title:T(`addons.addonCard.resetRetryCounterAndForce`,`Reset retry counter and force immediate reload`),children:[a(p,{className:`h-3 w-3 ${H.isPending||U.retrying?`animate-spin`:``}`}),T(`addons.addonCard.retryNow`,`Retry now`)]})]}),W!==null&&t(`div`,{className:`bg-danger/10 border-b border-danger/30 px-3 py-2 flex items-start gap-2`,children:[a(k,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),t(`div`,{className:`flex-1 min-w-0`,children:[a(`div`,{className:`text-xs font-semibold text-danger`,children:T(`addons.addonCard.processProblem.${W.kind}`)}),W.reason!==void 0&&a(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:W.reason})]})]}),t(`div`,{className:`flex items-start gap-2.5 px-3 py-2`,children:[a(dt,{isBundle:I||!!F.components&&F.components.length>1,installSource:B,addonId:I?v.addons[0]?.manifest.id:F.id,iconPath:I?v.bundle?.icon??v.addons[0]?.manifest.icon:F.icon,color:I?v.addons[0]?.manifest.color:F.color}),t(`div`,{className:`flex-1 min-w-0`,children:[t(`div`,{className:`flex items-start justify-between gap-2`,children:[a(`span`,{className:`text-xs font-semibold text-foreground truncate min-w-0`,children:L}),!r&&a(ft,{version:z,availableUpdate:i,...O===void 0?{}:{selectedVersion:O},isUpdating:h,installSource:B,disabled:b,...f&&O!==void 0?{onUpdate:()=>f(O)}:{},onOpenPicker:()=>E(e=>!e),children:re&&a(st,{packageName:R,currentVersion:z,...B?{installSource:B}:{},...i!==void 0&&O!==void 0?{selectedVersion:O,onSelect:e=>{D(e),E(!1)}}:{},onInstall:e=>{E(!1),xe.mutate({packageName:R,version:e})},onClose:()=>E(!1)})})]}),t(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1 mt-0.5`,children:[R!==L&&a(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate max-w-full`,children:R}),I&&t(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,children:[a(d,{className:`h-3 w-3`}),v.addons.length]}),C&&t(`span`,{className:`text-[10px] rounded-full bg-amber-500/15 text-amber-700 dark:text-amber-300 px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,title:T(`addons.addonCard.systemPackageUpdatingRestartsThe`,`System package — updating restarts the hub`),children:[a(p,{className:`h-3 w-3`}),T(`addons.addonCard.system`,`System`)]}),y!=null&&a(Z,{item:y}),c!==void 0&&a(se,{variant:`warning`,title:T(`addons.addonCard.updateHeldTitle`,{defaultValue:`{{latest}} is held until the server is {{required}} or newer`,latest:c.latestVersion,required:c.requiredServer}),children:T(`addons.addonCard.requiresServer`,{defaultValue:`requires server ≥ {{version}}`,version:c.requiredServer})}),g!=null&&a(Je,{progress:g})]}),be&&a(`p`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-1`,children:be}),!I&&e.process&&t(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[a(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.mode===`forked`?`bg-blue-500/15 text-blue-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.mode===`forked`?T(`addons.addonCard.forked`):T(`addons.addonCard.inProcess`)}),e.process.pid!=null&&t(`span`,{className:`text-[9px] font-mono text-foreground-subtle`,children:[`PID `,e.process.pid]}),a(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.state===`running`?`bg-emerald-500/15 text-emerald-400`:W===null?`bg-gray-500/15 text-gray-400`:`bg-red-500/15 text-red-400`}`,children:e.process.state})]})]})]}),!I&&t(`div`,{className:`flex items-center gap-1 px-3 py-1 border-t border-border/50 bg-surface-hover/20`,children:[t(G,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),V.mutate({addonId:F.id})},disabled:V.isPending||b,className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border border-border text-foreground-subtle hover:text-blue-400 hover:border-blue-500/30 hover:bg-blue-500/10 disabled:opacity-50 transition-colors`,children:[a(p,{className:`h-3 w-3 ${V.isPending?`animate-spin`:``}`}),T(`addons.addonCard.restart`,`Restart`)]}),t(G,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),A(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border transition-colors ${ae?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[a(S,{className:`h-3 w-3`}),T(`addons.addonCard.logs`,`Logs`)]}),!I&&t(G,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),M(!0)},className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border transition-colors ${j?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[a(x,{className:`h-3 w-3`}),T(`addons.addonCard.settings`,`Settings`)]}),a(`div`,{className:`flex-1`}),_e&&a(rt,{packageName:F.packageName,displayName:F.name,selectedNode:w??mt,disabled:b})]}),n&&n.nodes.length>1&&!I&&t(`div`,{className:`border-t border-border px-3 py-1.5 bg-muted/10`,children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle mb-1.5`,children:T(`addons.addonCard.clusterDeployment`,`Cluster Deployment`)}),a(`div`,{className:`space-y-1`,children:n.nodes.map(e=>t(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[a(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`offline`?`bg-muted-foreground/30`:e.synced?`bg-success`:`bg-amber-500`}`}),a(`span`,{className:`font-medium text-foreground min-w-[60px]`,children:e.name}),a(`span`,{className:`font-mono text-foreground-subtle`,children:e.version}),!e.synced&&e.status!==`offline`&&a(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20`,children:T(`addons.addonCard.outdated`)}),e.status===`offline`&&a(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:T(`common.offline`)}),e.synced&&e.status!==`offline`&&a(`span`,{className:`text-[9px] text-success`,children:T(`common.synced`)})]},e.nodeId))})]}),ae&&!I&&t(`div`,{className:`border-t border-border`,children:[t(`div`,{className:`flex items-center px-3 py-0.5 bg-surface-hover/20 border-b border-border/50`,children:[t(`div`,{className:`flex rounded border border-border overflow-hidden text-[9px]`,children:[a(G,{variant:`unstyled`,type:`button`,onClick:()=>pe(`logs`),className:`px-2 py-0.5 transition-colors ${fe===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:T(`addons.addonCard.logs`,`Logs`)}),a(G,{variant:`unstyled`,type:`button`,onClick:()=>pe(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${fe===`events`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:T(`addons.addonCard.events`,`Events`)})]}),a(`div`,{className:`flex-1`}),a(G,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),A(!1)},className:`text-foreground-subtle hover:text-foreground`,children:a(ee,{className:`h-3.5 w-3.5`})})]}),fe===`logs`&&a(me,{addonId:F.id,maxHeight:`max-h-64`,showFilters:!1}),fe===`events`&&a(ye,{addonId:F.id,category:`addon.*`,maxHeight:`max-h-64`})]}),I&&t(u,{children:[a(G,{variant:`unstyled`,type:`button`,onClick:()=>ne(e=>!e),className:`w-full flex items-center justify-center border-t border-border py-1 hover:bg-surface-hover/50 transition-colors`,children:a(te?_:m,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),te&&a(`div`,{className:`border-t border-border px-2.5 py-1.5 space-y-1.5`,children:v.addons.map(e=>a(ht,{addon:e,hideVersion:!0},e.manifest.id))})]}),j&&!I&&a(ue,{open:!0,onOpenChange:e=>!e&&M(!1),children:t(le,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(Me,{children:t(oe,{className:`flex items-center gap-2`,children:[a(x,{className:`h-4 w-4 text-primary`}),T(`addons.addonCard.settingsTitle`,{name:L})]})}),t(ce,{className:`space-y-4`,children:[a(`div`,{className:`text-[10px] text-foreground-subtle mb-2`,children:T(`addons.addonCard.clusterWideSettingsOneValue`,`Cluster-wide settings — one value for every node. Per-node settings live under Cluster → the node → Settings.`)}),a(Y,{nodeId:null,addonIds:[F.id],level:`global`,fieldScope:`cluster`,emptyMessage:T(`addons.addonCard.thisAddonExposesNoCluster`,`This addon exposes no cluster-wide settings. Anything it can configure is per-node — open it from Cluster → the node → Settings.`)}),lt(F)&&t(`div`,{children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:T(`addons.addonCard.deviceExport`,`Device export`)}),a(de,{addonId:F.id,onOpenDevice:e=>ge(`/devices/${e}`)})]}),ut(B)&&t(`div`,{children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:T(`addons.addonCard.autoUpdate`,`Auto-Update`)}),a(pt,{addonId:F.id})]}),F.components&&F.components.length>0&&t(`div`,{children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:T(`addons.addonCard.components`,{count:F.components.length})}),a(`div`,{className:`flex flex-wrap gap-1`,children:F.components.map(e=>a(`span`,{className:`text-[10px] rounded bg-background border border-border px-1.5 py-0.5 text-foreground-subtle font-mono`,children:e},e))})]})]}),a(N,{children:a(G,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>M(!1),children:T(`common.close`,`Close`)})})]})})]})}c();var gt=`.tgz,.tar.gz,.zip`;function _t({onUploadSuccess:e}){let{t:r}=K(),[o,c]=s(!1),l=n(null),d=i(async t=>{c(!0);let n=new FormData;n.append(`file`,t);let r=localStorage.getItem(`camstack_admin_token`)??``;try{(await(await fetch(y(`/api/addons/upload`),{method:`POST`,headers:{Authorization:`Bearer ${r}`},body:n})).json()).success&&e()}finally{c(!1)}},[e]);return t(u,{children:[a(F,{ref:l,accept:gt,onChange:i(e=>{let t=e.target.files?.[0];t&&d(t),e.target.value=``},[d]),className:`hidden`}),t(G,{variant:`unstyled`,type:`button`,onClick:()=>l.current?.click(),disabled:o,className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,children:[o?a(D,{className:`w-3.5 h-3.5 animate-spin`}):a(b,{className:`w-3.5 h-3.5`}),o?r(`addons.addonUploadZone.uploading`,`Uploading...`):r(`addons.addonUploadZone.upload`,`Upload`)]})]})}var vt=/```[^\n]*\n([\s\S]*?)```/g;function yt(e){let t=[],n=0;for(let r of e.matchAll(vt)){let i=r.index??0;i>n&&t.push({kind:`text`,body:e.slice(n,i)}),t.push({kind:`code`,body:r[1]??``}),n=i+r[0].length}return n<e.length&&t.push({kind:`text`,body:e.slice(n)}),t}function bt(e){let t=e.trim();return t.startsWith(`https://`)||t.startsWith(`http://`)?t:null}function xt(e,t){let n=[],r=/(\*\*[^*]+\*\*|`[^`]+`|\[[^\]]+\]\([^)]+\))/g,i=0,o=0;for(let s of e.matchAll(r)){let r=s.index??0;r>i&&n.push(e.slice(i,r));let c=s[0],l=`${t}-${o}`;if(o+=1,c.startsWith(`**`))n.push(a(`strong`,{children:c.slice(2,-2)},l));else if(c.startsWith("`"))n.push(a(`code`,{className:`font-mono text-[0.9em]`,children:c.slice(1,-1)},l));else{let e=/^\[([^\]]+)\]\(([^)]+)\)$/.exec(c),t=e?.[1]??c,r=e?bt(e[2]??``):null;n.push(r?a(`a`,{href:r,target:`_blank`,rel:`noreferrer noopener`,className:`text-primary underline`,children:t},l):a(`span`,{children:t},l))}i=r+c.length}return i<e.length&&n.push(e.slice(i)),n}function St(e,t){let n=e.split(`
|
|
5
|
-
`),r=[],i=[],o=[],s=0,c=()=>{if(i.length===0)return;let e=i.join(` `).trim();i=[],e.length!==0&&(r.push(a(`p`,{className:`mb-2 last:mb-0`,children:xt(e,`${t}-p-${s}`)},`${t}-p-${s}`)),s+=1)},l=()=>{if(o.length===0)return;let e=o;o=[],r.push(a(`ul`,{className:`mb-2 list-disc pl-4 last:mb-0`,children:e.map((e,n)=>a(`li`,{children:xt(e,`${t}-li-${s}-${n}`)},`${t}-li-${s}-${n}`))},`${t}-ul-${s}`)),s+=1};for(let e of n){let n=/^(#{1,3})\s+(.*)$/.exec(e),u=/^\s*[-*]\s+(.*)$/.exec(e);if(n){c(),l();let e=n[1]?.length??1,i=xt(n[2]??``,`${t}-h-${s}`),o=e===1?`text-sm font-semibold mb-2`:`text-xs font-semibold mb-1.5 mt-2`;r.push(a(e===1?`h3`:`h4`,{className:o,children:i},`${t}-h-${s}`)),s+=1;continue}if(u){c(),o=[...o,u[1]??``];continue}if(e.trim().length===0){c(),l();continue}l(),i=[...i,e.trim()]}return c(),l(),r}function Ct({markdown:e}){return a(`div`,{className:`text-xs text-foreground leading-relaxed`,children:yt(e).map((e,t)=>e.kind===`code`?a(`pre`,{className:`mb-2 overflow-auto rounded-md bg-surface-hover p-2 font-mono text-[10px] last:mb-0`,children:e.body.replace(/\n$/,``)},`code-${t}`):a(`div`,{children:St(e.body,`b${t}`)},`text-${t}`))})}c();function wt(e){return e.replace(/^@camstack\/(addon-)?/,``)}function Tt(e,t,n){let r=at(e,n);return r.some(e=>e.version===t)?r:[{version:t,distTags:[],deprecated:void 0},...r]}function Et({pending:e,failed:n,body:r,missing:i}){let{t:o}=K();return e?t(`div`,{className:`flex items-center gap-2 py-6 text-xs text-foreground-subtle`,children:[a(D,{className:`h-3.5 w-3.5 animate-spin`}),o(`addons.installDialog.loadingDocument`,`Loading…`)]}):n||r===void 0?a(`p`,{className:`py-4 text-xs text-danger`,children:o(`addons.installDialog.couldNotLoadDocument`,`Could not load this file from the registry.`)}):r.status===`ok`&&r.markdown!==void 0?a(Ct,{markdown:r.markdown}):r.status===`error`?a(`p`,{className:`py-4 text-xs text-danger`,children:o(`addons.installDialog.documentError`,`Could not load this file. {{message}}`,{message:r.message??``})}):a(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:i})}function Dt({target:e,installing:n,installError:r,onClose:i,onInstall:o}){let{t:c}=K(),[l,u]=s(e.version),[d,f]=s(!1),p=V({name:e.name}),m=Te({name:e.name,version:l}),h=p.data??[],g=ot(h),_=Tt(h,l,d),v=m.data;return a(ue,{open:!0,onOpenChange:e=>!e&&i(),children:t(le,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(Me,{children:a(oe,{children:c(`addons.installDialog.title`,`Install {{name}}`,{name:wt(e.name)})})}),t(ce,{className:`space-y-3`,children:[a(`p`,{className:`font-mono text-[10px] text-foreground-subtle`,children:e.name}),e.description.length>0&&a(`p`,{className:`text-xs text-foreground`,children:e.description}),t(`div`,{className:`space-y-1.5`,children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:c(`addons.installDialog.version`,`Version`)}),a(E,{"aria-label":c(`addons.installDialog.version`,`Version`),value:l,options:_.map(e=>({value:e.version,label:it(e)?c(`addons.installDialog.deprecatedVersion`,`{{version}} (deprecated)`,{version:e.version}):e.version})),onChange:e=>u(e.target.value)}),p.isError&&a(`p`,{className:`text-[10px] text-danger`,children:c(`addons.versionPicker.registryError`,`Could not load versions from the registry.`)}),g>0&&a(G,{type:`button`,variant:`ghost`,size:`sm`,className:`h-auto justify-start px-0 text-[10px] font-normal text-foreground-subtle underline`,onClick:()=>f(e=>!e),children:d?c(`addons.versionPicker.hideOlder`,`Hide older versions`):c(`addons.versionPicker.showOlder`,`Show older versions ({{count}})`,{count:g})})]}),t(z,{defaultValue:`readme`,children:[t(we,{children:[a(Ee,{value:`readme`,children:c(`addons.installDialog.readme`,`README`)}),a(Ee,{value:`changelog`,children:c(`addons.installDialog.changelog`,`CHANGELOG`)})]}),a(Oe,{value:`readme`,children:a(`div`,{className:`max-h-80 overflow-auto rounded-md border border-border bg-background p-3`,children:a(Et,{pending:m.isPending,failed:m.isError,body:v?.readme,missing:c(`addons.installDialog.missingReadme`,`This package has no README.`)})})}),a(Oe,{value:`changelog`,children:a(`div`,{className:`max-h-80 overflow-auto rounded-md border border-border bg-background p-3`,children:a(Et,{pending:m.isPending,failed:m.isError,body:v?.changelog,missing:c(`addons.installDialog.missingChangelog`,`This package has no CHANGELOG.`)})})})]}),r!=null&&r.length>0&&a(`p`,{className:`text-xs text-danger`,children:r})]}),t(N,{children:[a(G,{type:`button`,variant:`outline`,size:`sm`,onClick:i,children:c(`common.cancel`,`Cancel`)}),a(G,{type:`button`,size:`sm`,disabled:n||l.length===0,onClick:()=>o(e.name,l),children:n?a(D,{className:`h-3.5 w-3.5 animate-spin`}):c(`addons.installDialog.install`,`Install`)})]})]})})}var Ot=new Set([`@camstack/server`,`@camstack/types`,`@camstack/sdk`,`@camstack/ui-library`,`@camstack/addon-agent-ui`]);function kt(e,t){let n=new Map;for(let r of e){if(r.isHub||r.onHub||Ot.has(r.packageName)||!t.isHub&&r.nodeId!==t.id)continue;let e=n.get(r.packageName)??[];e.push(r),n.set(r.packageName,e)}return[...n].map(([e,t])=>({packageName:e,rows:t})).sort((e,t)=>e.packageName.localeCompare(t.packageName))}function At({selectedNode:e}){let{t:n}=K(),{data:r}=I(et,{staleTime:tt});if(r===void 0)return null;let i=kt(r.installations,e),o=r.unreachable.filter(t=>e.isHub||t.nodeId===e.id);return i.length===0&&o.length===0?null:t(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 px-3 py-2.5 space-y-2`,children:[t(`div`,{className:`flex items-center gap-2 text-[11px] font-semibold text-foreground`,children:[a(C,{className:`h-3.5 w-3.5 text-warning`}),e.isHub?n(`addons.nodeOnlyPackagesPanel.installedOnAgentsButNot`,`Installed on agents but not on the hub`):n(`addons.nodeOnlyPackagesPanel.installedOnButNotOn`,`Installed on {{name}} but not on the hub`,{name:e.name})]}),o.length>0&&a(`div`,{className:`text-[10px] text-foreground-subtle`,children:n(`addons.nodeOnlyPackagesPanel.unreachable`,{nodes:o.map(e=>e.nodeId).join(`, `)})}),i.map(n=>t(`div`,{className:`flex items-center justify-between gap-3 flex-wrap rounded-md border border-border bg-surface px-3 py-2`,children:[t(`div`,{className:`min-w-0`,children:[a(`div`,{className:`text-xs font-mono text-foreground break-all`,children:n.packageName}),a(`div`,{className:`text-[10px] text-foreground-subtle`,children:n.rows.map(e=>`${e.nodeName}${e.version===null?``:` ${e.version}`}${e.isOnline?``:` (offline)`}`).join(` · `)})]}),a(rt,{packageName:n.packageName,displayName:n.packageName,selectedNode:e,hideNodeAction:e.isHub})]},n.packageName))]})}function jt({addon:e,installing:n,onInstall:r}){let{t:i}=K();return t(`div`,{className:`flex items-center gap-3 px-3 py-2 hover:bg-surface-hover transition-colors`,children:[a(`div`,{className:`w-6 h-6 rounded-md bg-primary/10 flex items-center justify-center text-primary text-[9px] font-bold shrink-0`,children:e.name.replace(`@camstack/addon-`,``).charAt(0).toUpperCase()}),t(`div`,{className:`flex-1 min-w-0`,children:[t(`div`,{className:`flex items-baseline gap-2 min-w-0`,children:[a(`span`,{className:`text-[11px] font-semibold break-words`,children:e.name.replace(/^@camstack\/(addon-)?/,``)}),t(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`v`,e.version]})]}),a(`div`,{className:`font-mono text-[9px] text-foreground-subtle/80 truncate`,children:e.name}),e.description&&a(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.description})]}),e.installed?a(se,{variant:`success`,icon:a(g,{className:`h-3 w-3`}),children:e.installedVersion??i(`system.capabilityCatalog.installed`,`Installed`)}):t(G,{size:`sm`,onClick:()=>r(e),disabled:n,className:`shrink-0`,children:[n?a(D,{className:`h-3 w-3 animate-spin`}):a(w,{className:`h-3 w-3`}),i(`system.capabilityCatalog.install`,`Install`)]})]})}function Mt({capability:e,installing:n,onInstall:r}){let{t:i}=K(),{data:o,isPending:s,isError:c}=be({capability:e}),l;if(c)l=a(`div`,{className:`px-3 py-2 text-xs text-danger`,children:i(`system.capabilityCatalog.couldNotSearchTheNpm`,`Could not search the npm catalog right now. Try again in a moment.`)});else if(s||o===void 0)l=t(`div`,{className:`flex items-center gap-2 px-3 py-2 text-xs text-foreground-subtle`,children:[a(D,{className:`h-3 w-3 animate-spin`}),i(`system.capabilityCatalog.searchingTheNpmCatalog`,`Searching the npm catalog…`)]});else{let t=o.filter(e=>!e.installed);l=t.length===0?a(`div`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:o.length===0?i(`system.capabilityCatalog.noPublishedAddonDeclaresThe`,`No published addon declares the "{{capability}}" capability.`,{capability:e}):i(`system.capabilityCatalog.everyPublishedAddonThatDeclares`,`Every published addon that declares "{{capability}}" is already installed.`,{capability:e})}):a(`div`,{className:`divide-y divide-border`,children:t.map(e=>a(jt,{addon:e,installing:n,onInstall:r},e.name))})}return t(`section`,{className:`rounded-md border border-border bg-surface overflow-hidden`,"aria-label":i(`system.capabilityCatalog.availableToInstall`,`Available to install`),children:[a(`h2`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:i(`system.capabilityCatalog.availableToInstall`,`Available to install`)}),l]})}c();function Nt(e){return e===`npm`||e===`dev`?e:null}var Pt=`rounded-full border border-primary bg-primary/10 px-2 py-0.5 text-[10px] text-foreground`,Ft=`rounded-full border border-border px-2 py-0.5 text-[10px] text-foreground-muted hover:bg-surface-hover`,It=[{seconds:900,label:`15m`},{seconds:3600,label:`1h`},{seconds:21600,label:`6h`},{seconds:43200,label:`12h`},{seconds:86400,label:`24h`}],Lt={id:`hub`,name:`Hub`,isHub:!0,isOnline:!0};function Rt(e,t){let n=e??`hub-only`;return n===`any-node`?!0:n===`hub-only`?t:!t}function zt(e){return e===`local`?`dev`:`npm`}function Bt(e){let t=e;if(!t?.manifest)return null;let n={...t.manifest,name:t.manifest.name??t.manifest.id,version:t.manifest.version??`0.0.0`,capabilities:t.manifest.capabilities??[]},r=t.process,i=r?{pid:r.pid,mode:r.mode===`forked`?`forked`:`in-process`,state:r.state??`unknown`,...r.reason===void 0?{}:{reason:r.reason}}:void 0,a=t.health,o=t.declaration?.execution,s=t.manifest.execution,c=o?.placement??s?.placement;return{manifest:n,enabled:!0,source:t.source,installSource:t.installSource,installedOn:[],...i?{process:i}:{},hasBackup:t.hasBackup,...a?{health:a}:{},...c?{placement:c}:{}}}function Vt(e){let t=new Map,n=[];for(let r of e){let e=r.manifest.packageName;if(!e){n.push(r);continue}let i=t.get(e);if(i)i.addons.push(r);else{let n=r.manifest.bundle,i={packageName:e,displayName:n?.displayName??r.manifest.packageDisplayName??r.manifest.name,version:r.manifest.packageVersion,addons:[r],...r.installSource===void 0?{}:{installSource:r.installSource},...n===void 0?{}:{bundle:n}};t.set(e,i)}}let r=[];for(let e of t.values())e.bundle!==void 0||e.addons.length>=2?r.push({bundle:e,representative:e.addons[0]}):r.push(e.addons[0]);return r.push(...n),r}function $(e){return`bundle`in e}function Ht({addons:c,clusterStatus:u,selectedNode:d,onRefresh:f,listPhase:m}){let{t:h}=K(),g=l(),[_,y]=s(``),b=e(_),[x,S]=s(!1),C=n(null);o(()=>{if(!x)return;let e=e=>{C.current&&!C.current.contains(e.target)&&S(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[x]);let{data:T}=ke({nodeId:d.id}),ee=r(()=>{let e=new Map;for(let t of T??[])t.blockedBy===void 0&&e.set(t.name,t.latestVersion);return e},[T]),ne=r(()=>{let e=new Map;for(let t of T??[]){let n=t.blockedBy?.find(e=>e.kind===`server-too-old`);n!==void 0&&e.set(t.name,{latestVersion:t.latestVersion,requiredServer:n.required})}return e},[T]),re=r(()=>(T??[]).filter(e=>!e.isSystem&&e.blockedBy===void 0).length,[T]),[O,k]=s(()=>new Set),[ae,A]=s(()=>new Map),oe=i(e=>{k(t=>new Set(t).add(e))},[]),se=i(e=>{k(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),ce=i((e,t)=>{A(n=>new Map(n).set(e,t))},[]),j=i(e=>{A(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),le=Ae({onMutate:e=>{oe(e.name),j(e.name)},onSuccess:(e,t)=>{se(t.name);let n=e;if(n&&n.success===!1){ce(t.name,n.error??`Update failed (no error message returned by server)`);return}g.invalidateQueries({queryKey:[[`addons`]]}),g.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]})},onError:(e,t)=>{se(t.name),ce(t.name,e instanceof Error?e.message:String(e))}}),M=Ke(),ue=n(new Set);o(()=>{let e=new Set;for(let[t,n]of M)We(n)&&e.add(t);let t=[...ue.current].some(t=>!e.has(t));ue.current=e,t&&(g.invalidateQueries({queryKey:[[`addons`]]}),g.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]}))},[M,g]);let{data:N}=De(void 0),de=pe({onSuccess:()=>{g.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),me=P({onSuccess:()=>{g.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),{data:F,isFetching:_e}=be({query:b||void 0},{enabled:x}),I=je(),{data:L}=Ce(void 0),R=L?.requestedAt,[z,ve]=s(null),[B,ye]=s(!1);o(()=>{if(L?.kind===`framework-bulk-update`&&L.requestedAt!==z){ve(L.requestedAt),ye(!0);let e=window.setTimeout(()=>ye(!1),6e3);return()=>window.clearTimeout(e)}},[R,z,L]),te();let V=i(async()=>{let e=(T??[]).filter(e=>!e.isSystem&&e.blockedBy===void 0);if(e.length!==0){if(!d.isHub){for(let t of e)await le.mutateAsync({name:t.name,version:t.latestVersion,nodeId:d.id});return}await I.mutateAsync({kind:`update`,targets:e.map(e=>({name:e.name,version:e.latestVersion})),nodeIds:[d.id]})}},[T,d.id,d.isHub,I,le]),[xe,H]=s(null),[U,Se]=s(null),we=e=>{Se(null),H(e)},W=he({onSuccess:()=>{H(null),Se(null),g.invalidateQueries({queryKey:[[`addons`]]}),g.invalidateQueries({queryKey:[[`addonPages`]]}),g.invalidateQueries({queryKey:[[`capabilities`]]}),g.invalidateQueries({queryKey:[[`integrations`]]})},onError:e=>{Se(e instanceof Error?e.message:`Install failed`)}}),[Te,Ee]=s(`type`),[Oe,Me]=s(()=>typeof window>`u`?`grouped`:window.localStorage.getItem(`camstack.addons.viewMode`)===`flat`?`flat`:`grouped`),Pe=e=>{Me(e),typeof window<`u`&&window.localStorage.setItem(`camstack.addons.viewMode`,e)},[q,J]=Ne(),Y=q.get(`capability`),ze=q.get(`updatable`)===`1`,Be=q.get(`error`)===`1`,X=Nt(q.get(`source`)),Z=Fe(q.get(Le))===`integration`,{data:He}=fe(void 0,{enabled:Z}),Ue=r(()=>He===void 0?null:new Set(He.map(e=>e.addonId)),[He]),Ge=i(e=>{let t=new URLSearchParams(q);e?t.set(Le,`integration`):t.delete(Le),J(t,{replace:!0})},[q,J]),qe=i(e=>{let t=new URLSearchParams(q);e?t.set(`updatable`,`1`):t.delete(`updatable`),J(t,{replace:!0})},[q,J]),Je=i(e=>{let t=new URLSearchParams(q);e?t.set(`error`,`1`):t.delete(`error`),J(t,{replace:!0})},[q,J]),Ye=i(e=>{let t=new URLSearchParams(q);e===null?t.delete(`source`):t.set(`source`,e),J(t,{replace:!0})},[q,J]),Xe=r(()=>c.filter(e=>Ve(e.process)!==null).length,[c]),Q=r(()=>{let e=c.filter(e=>!Re(e.manifest.packageName));return d.isHub||(e=e.filter(e=>Rt(e.placement,d.isHub))),Y&&(e=e.filter(e=>(e.manifest.capabilities??[]).some(e=>(typeof e==`string`?e:e.name)===Y))),Z&&(e=[...Ie(e,Ue)]),ze&&(e=e.filter(e=>{let t=e.manifest.packageName;return t!==void 0&&ee.has(t)})),X!==null&&(e=e.filter(e=>zt(e.installSource)===X)),Be&&(e=e.filter(e=>Ve(e.process)!==null)),e},[c,d.isHub,Y,ze,X,Be,Z,Ue,ee]),Ze=()=>{let e=new URLSearchParams(q);e.delete(`capability`),J(e,{replace:!0})},Qe=Oe===`flat`?Q:Vt(Q),$e=r(()=>{let e=[...Qe];switch(Te){case`type`:e.sort((e,t)=>{let n=+!$(e),r=+!$(t);if(n!==r)return n-r;let i=$(e)?e.bundle.displayName:e.manifest.name,a=$(t)?t.bundle.displayName:t.manifest.name;return i.localeCompare(a)});break;case`name`:e.sort((e,t)=>{let n=$(e)?e.bundle.displayName:e.manifest.name,r=$(t)?t.bundle.displayName:t.manifest.name;return n.localeCompare(r)});break;case`source`:e.sort((e,t)=>{let n=$(e)?e.bundle.installSource??``:e.installSource??``,r=$(t)?t.bundle.installSource??``:t.installSource??``;return n.localeCompare(r)});break}return e},[Qe,Te]);return t(`div`,{className:`space-y-3`,children:[[...ae.entries()].map(([e,n])=>a(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-2.5 py-1.5 text-[11px]`,children:t(`div`,{className:`flex items-start justify-between gap-3`,children:[t(`div`,{className:`space-y-0.5`,children:[a(`div`,{className:`font-medium text-danger`,children:h(`systemPage.addons.updateFailed`,{name:e})}),a(`div`,{className:`text-foreground-subtle font-mono`,children:n})]}),a(G,{variant:`unstyled`,type:`button`,onClick:()=>j(e),className:`text-foreground-subtle hover:text-foreground text-[10px]`,children:h(`common.dismiss`)})]})},e)),t(`div`,{className:`flex items-center gap-x-2 gap-y-1.5 flex-wrap`,children:[t(`div`,{className:`flex items-center gap-1.5`,children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:h(`admin.system.addons.sort`,`Sort:`)}),t(E,{wrapperClassName:`inline-block w-auto`,value:Te,onChange:e=>Ee(e.target.value),children:[a(`option`,{value:`type`,children:h(`admin.system.addons.bundlesFirst`,`Bundles first`)}),a(`option`,{value:`name`,children:h(`admin.system.addons.name`,`Name`)}),a(`option`,{value:`source`,children:h(`admin.system.addons.installSource`,`Install source`)})]})]}),t(`div`,{className:`flex items-center gap-1.5`,children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:h(`admin.system.addons.view`,`View:`)}),a(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`grouped`,`flat`].map(e=>a(G,{variant:`unstyled`,type:`button`,onClick:()=>Pe(e),className:`px-2 py-1 transition-colors capitalize ${Oe===e?`bg-primary/10 text-primary`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`}`,title:e===`grouped`?h(`admin.system.addons.groupMultiAddonPackagesInto`,`Group multi-addon packages into a bundle card`):h(`admin.system.addons.showEveryAddonAsIts`,`Show every addon as its own card`),children:e},e))})]}),d.isHub&&t(`div`,{className:`flex items-center gap-1.5`,children:[a(p,{className:`h-3 w-3 text-foreground-subtle`}),a(`span`,{className:`text-[10px] text-foreground-subtle`,children:h(`admin.system.addons.autoUpdate`,`Auto-Update:`)}),a(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`off`,`latest`,`beta`].map(e=>a(G,{variant:`unstyled`,type:`button`,onClick:()=>de.mutate({channel:e}),disabled:de.isPending,className:`px-2 py-1 transition-colors capitalize ${N?.channel===e?e===`off`?`bg-gray-700 text-gray-200`:e===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${e===`off`?``:`border-l border-border`}`,children:e},e))})]}),d.isHub&&t(`div`,{className:`flex items-center gap-1.5`,children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:h(`admin.system.addons.checkEvery`,`Check every:`)}),a(E,{wrapperClassName:`inline-block w-auto`,className:`font-medium text-foreground-subtle`,value:N?.updateCheckIntervalSeconds??21600,disabled:me.isPending||N===void 0,onChange:e=>{N!==void 0&&me.mutate({channel:N.channel,updateCheckIntervalSeconds:Number(e.target.value)})},children:It.map(e=>a(`option`,{value:e.seconds,children:e.label},e.seconds))})]}),re>0&&t(G,{variant:`unstyled`,type:`button`,onClick:()=>void V(),disabled:I.isPending,className:`flex items-center gap-1 px-2 py-1 text-[11px] rounded-md bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 border border-blue-500/30 disabled:opacity-50 transition-colors font-medium`,children:[I.isPending?a(D,{className:`w-3 h-3 animate-spin`}):a(w,{className:`w-3 h-3`}),I.isPending?h(`admin.system.addons.updating`,`Updating…`):h(`admin.system.addons.updateAll`,`Update All ({{nonSystemUpdateCount}})`,{nonSystemUpdateCount:re})]})]}),t(`div`,{className:`flex flex-wrap items-center gap-1.5`,role:`group`,"aria-label":h(`admin.system.addons.filterInstalledAddons`,`Filter installed addons`),children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:h(`admin.system.addons.filter`,`Filter:`)}),[{id:`integrations`,label:h(`admin.system.addons.integrations`,`Integrations`),pressed:Z,toggle:()=>Ge(!Z)},{id:`updatable`,label:h(`admin.system.addons.updatable`,`Updatable`),pressed:ze,toggle:()=>qe(!ze)},{id:`error`,label:h(`admin.system.addons.inError`,`In error ({{count}})`,{count:Xe}),pressed:Be,toggle:()=>Je(!Be)},{id:`npm`,label:`npm`,pressed:X===`npm`,toggle:()=>Ye(X===`npm`?null:`npm`)},{id:`dev`,label:h(`admin.system.addons.dev`,`Dev`),pressed:X===`dev`,toggle:()=>Ye(X===`dev`?null:`dev`)}].map(e=>a(G,{variant:`unstyled`,type:`button`,"aria-pressed":e.pressed,onClick:e.toggle,className:e.pressed?Pt:Ft,children:e.label},e.id))]}),t(`div`,{className:`flex flex-col gap-1.5 sm:flex-row sm:items-center sm:gap-2`,children:[t(`div`,{className:`relative flex-1 min-w-0 sm:min-w-[200px]`,ref:C,children:[a(ge,{type:`text`,searchHotkey:!0,value:_,onChange:e=>{y(e.target.value),S(!0)},onFocus:()=>S(!0),placeholder:h(`admin.system.addons.searchAddonsOnNpm`,`Search addons on npm...`),"aria-label":h(`admin.system.addons.searchAddonsOnNpm2`,`Search addons on npm`),disabled:I.isPending,leftSlot:a(ie,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),rightSlot:_e?a(D,{className:`h-3 w-3 animate-spin`}):void 0}),x&&F&&F.length>0&&t(`div`,{className:`absolute left-0 right-0 top-full mt-1 z-40 rounded-md border border-border bg-surface shadow-xl overflow-hidden`,children:[F.length>0&&a(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:h(`systemPage.addons.npmResults`,{count:F.length})}),F&&F.length>0&&a(`div`,{className:`max-h-72 overflow-auto divide-y divide-border`,children:F.map(e=>a(jt,{addon:e,installing:W.isPending,onInstall:e=>we({name:e.name,version:e.version,description:e.description})},e.name))})]})]}),a(_t,{onUploadSuccess:()=>{g.invalidateQueries({queryKey:[[`addons`]]}),f()}})]}),Y&&t(`div`,{className:`flex items-center gap-2 px-2.5 py-1.5 rounded-md bg-primary/10 border border-primary/30 text-xs`,children:[a(`span`,{className:`text-foreground-subtle`,children:h(`admin.system.addons.filteringByCapability`,`Filtering by capability:`)}),a(`span`,{className:`font-mono text-primary font-semibold`,children:Y}),a(G,{variant:`unstyled`,type:`button`,onClick:Ze,className:`ml-auto text-xs text-foreground-subtle hover:text-foreground underline`,children:h(`admin.system.addons.clear`,`Clear`)})]}),Y&&a(Mt,{capability:Y,installing:W.isPending,onInstall:e=>we({name:e.name,version:e.version,description:e.description})}),Y&&Q.length>0&&a(`h2`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:h(`admin.system.addons.installed`,`Installed`)}),B&&t(`div`,{className:`fixed top-[calc(env(safe-area-inset-top)+1rem)] right-[calc(env(safe-area-inset-right)+1rem)] z-50 flex items-start gap-2 px-3 py-2.5 rounded-md border border-green-500/30 bg-green-500/10 shadow-lg max-w-sm pointer-events-auto`,children:[a(v,{className:`w-4 h-4 shrink-0 mt-0.5 text-green-400`}),t(`div`,{children:[a(`div`,{className:`text-[11px] font-semibold text-foreground`,children:h(`admin.system.addons.bulkUpdateCompleted`,`Bulk update completed`)}),a(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:h(`admin.system.addons.systemPackagesUpdatedHubRestarted`,`System packages updated — hub restarted successfully.`)})]})]}),m===`pending`&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[a(D,{className:`h-3 w-3 animate-spin`}),h(`admin.system.addons.loadingInstalled`,`Loading installed addons…`)]}),m===`error`&&a(`div`,{className:`text-xs text-danger`,children:h(`admin.system.addons.failedToLoadAddons`,`Failed to load addons`)}),m===`ready`&&Q.length===0&&a(`div`,{className:`text-xs text-foreground-subtle`,children:c.length===0?h(`admin.system.addons.noAddonsInstalled`,`No addons installed`):Y?h(`admin.system.addons.noInstalledAddonDeclaresThe`,`No installed addon declares the "{{capabilityFilter}}" capability. Any addon you can install appears under "Available to install" above.`,{capabilityFilter:Y}):h(`admin.system.addons.noAddonsCompatibleWithPlacement`,`No addons compatible with {{name}} (placement filter active)`,{name:d.name})}),a(`div`,{className:`space-y-1.5`,children:m===`ready`&&$e.map(e=>{let t=$(e)?e.bundle.packageName:e.manifest.packageName,n=ee.get(t),r=ne.get(t),i=$(e)?e.representative:e,o=n?e=>le.mutate({name:t,version:e,nodeId:d.id}):void 0,s=M.get(t)??null,c=s!==null&&We(s);return a(ht,{addon:i,clusterStatus:u?.[i.manifest.id],bundle:$(e)?e.bundle:void 0,availableUpdate:n,...r===void 0?{}:{blockedUpdate:r},isUpdating:O.has(t)||c,jobProgress:s,onUpdate:o,disabledByBulk:I.isPending,selectedNode:d},$(e)?t:e.manifest.id)})}),xe!==null&&a(Dt,{target:xe,installing:W.isPending,installError:U,onClose:()=>H(null),onInstall:(e,t)=>W.mutate({packageName:e,version:t})})]})}function Ut(){let{t:e}=K(),r=l(),{data:i}=j(void 0),{nodes:s}=M(),{selection:c,selectNode:u,requestedNodeId:d}=Be(s.length>0?s:[Lt]),f=c.node??Lt,m=f.id,h=s.length>0?c.staleNodeId:null,{data:g,isLoading:_,isError:v}=W({nodeId:m}),y=A(),b=L(),x=y.isPending||b.isPending,S=async()=>{await y.mutateAsync({nodeId:m}),await b.mutateAsync(),r.invalidateQueries({queryKey:[[`addons`]]})},C=n(y);C.current=y;let w=n(d??`hub`);o(()=>{C.current.mutate({nodeId:w.current})},[]);let T=(g??[]).map(Bt).filter(e=>e!==null);return t(J,{children:[t(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[a(H,{selectedNodeId:m,onSelect:u}),t(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[!_&&!v&&a(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium`,children:e(`systemPage.addons.installedCount`,{count:T.length})}),t(G,{variant:`unstyled`,type:`button`,onClick:()=>void S(),disabled:x,className:`inline-flex items-center gap-1 px-2 py-1 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,title:e(`admin.system.addons.reFetchAddonsCheckNpm`,`Re-fetch addons + check npm for new versions`),children:[a(p,{className:`w-3 h-3 ${x?`animate-spin`:``}`}),e(`admin.system.addons.checkForUpdates`,`Check for updates`)]})]})]}),a(ze,{staleNodeId:h,shownNodeName:f.name}),a(At,{selectedNode:f}),a(Ht,{addons:T,clusterStatus:i,selectedNode:f,onRefresh:()=>void S(),listPhase:_?`pending`:v?`error`:`ready`})]})}export{Ut as AddonsPage};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import{C as e,E as t,J as n,K as r,P as i,R as a,S as o,V as s,Y as c,a as l,et as u,o as d,t as f,x as p}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Cr as m,Gn as h,Ii as g,Kt as _,Oi as v,Pi as y,Sa as b,St as x,Tn as S,Ut as C,Wn as w,Xn as T,ct as E,ht as D,jn as O,ut as k,xr as A,zr as j}from"./player-overlays-ywd6nvhM.js";import{Aa as M,Ai as N,Ba as P,Da as F,Di as I,Ea as L,Fa as R,Ga as z,Ha as B,Ja as V,Ka as H,La as ee,Ma as te,Na as ne,Pa as re,Ta as U,Ua as ie,Va as ae,Vt as oe,Wa as se,Wi as ce,Xa as le,bo as W,br as ue,ca as de,ea as fe,ia as G,ja as pe,ka as me,ki as he,nr as ge,qa as _e,rs as ve,ua as ye,vs as be,wa as xe,za as Se,zi as Ce}from"./client-mCEzjXIR.js";import{t as we}from"./boxes-B_Eu0xYD.js";import{t as Te}from"./calendar-clock-dlTytvhp.js";import{c as Ee}from"./video-BvnxG-kU.js";import{n as De,r as Oe,t as ke}from"./variable-DE3g0D48.js";import{$a as Ae,Bi as je,Br as Me,Bu as Ne,Df as Pe,Ei as K,Et as Fe,G as Ie,Go as Le,Hu as Re,Ii as ze,In as Be,Ir as Ve,Jr as q,Li as He,Ln as Ue,Lr as We,Lu as Ge,Mn as Ke,Ms as qe,Mt as Je,Pr as Ye,Qa as Xe,Qo as Ze,Rn as Qe,Rr as $e,Ru as et,Ui as tt,Ur as nt,Uu as rt,Vi as it,Vo as at,Vu as ot,Wu as st,Yr as ct,Zd as lt,Zr as ut,_ as dt,_n as ft,af as J,ai as pt,ao as mt,co as ht,dn as gt,ef as _t,eo as vt,er as yt,fn as bt,fu as xt,ht as St,ir as Ct,jt as wt,lo as Tt,lr as Et,ms as Dt,ni as Ot,nr as kt,on as At,q as jt,ro as Mt,rr as Nt,so as Pt,sr as Ft,tr as It,vd as Lt,vi as Y,wt as Rt,xi as zt,yn as Bt,zi as Vt,zn as Ht,zr as Ut,zu as Wt}from"./src-DmG3r3oz.js";import{t as X}from"./i18n-C6fCBciG.js";import{t as Z}from"./useTranslation-BJr-n0es.js";import{Br as Gt,Fr as Kt,H as qt,Pr as Jt,Rr as Yt,S as Xt,h as Zt,m as Qt,st as $t,ut as en}from"./index-DbICehF2.js";import{t as tn}from"./AdminSectionedPage-DwIVrzMv.js";import{n as nn}from"./format-BsOPQm9n.js";import{C as rn,D as an,E as on,O as sn,S as cn,_ as ln,a as Q,b as un,c as dn,d as fn,f as pn,g as mn,h as hn,i as gn,k as _n,l as vn,m as yn,n as bn,o as xn,p as Sn,r as Cn,s as wn,t as Tn,u as En,v as Dn,w as On,x as kn,y as An}from"./create-composition-Qtc7PTdK.js";import{C as jn,a as Mn,at as Nn,b as Pn,g as Fn,i as In,lt as Ln,n as Rn,nt as zn,o as Bn,r as Vn,w as Hn,y as Un}from"./CompositionBlockEditor-DnMSvA7o.js";var Wn=`const AUTOMATION_RECIPE =`,Gn=`// EJECTED from the visual automation editor — this file is now hand-owned.
|
|
2
|
-
// The recipe that produced it was removed with it, on purpose: while it was
|
|
3
|
-
// here the editor could re-open this block and overwrite everything below.`;function Kn(e){return e.includes(Wn)}function qn(e){let t=e.indexOf(Wn);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 Jn(e){let t=qn(e);if(t===null)return{ok:!1,reason:X.t(`helpers.recipeFromCode.noLiteral`)};let n;try{n=JSON.parse(t.json)}catch(e){let t=e instanceof Error?e.message:String(e);return{ok:!1,reason:X.t(`helpers.recipeFromCode.badJson`,{detail:t})}}let r=R.safeParse(n);if(!r.success){let e=r.error.issues[0];return{ok:!1,reason:e===void 0?X.t(`helpers.recipeFromCode.schemaMismatch`):X.t(`helpers.recipeFromCode.schemaMismatchAt`,{path:e.path.join(`.`),message:e.message})}}return{ok:!0,recipe:r.data}}function Yn(e){let t=qn(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)}${Gn}${e.slice(i)}`}u();function Xn(e,t){return e.map(e=>({name:e.name,hint:e.label??t(`flow.scope.type_${e.type}`,e.type)}))}function Zn(e,t){return re(e).map(e=>({name:e.name,hint:t(`flow.scope.${e.name}`,e.description)}))}var Qn={name:``,steps:[],variables:[]};function $n(e){return e===null?Qn:{name:e.name,steps:e.steps??[],variables:e.variables??[]}}function er(e){let t=[],n=e=>{t.includes(e)||t.push(e)},r=e=>{if(on(e)){n(e.$var);return}Array.isArray(e)?e.forEach(r):typeof e==`object`&&e&&Object.values(e).forEach(r)};for(let t of e)t.kind===`cap`&&(r(t.deviceId),t.target?.kind===`var`&&n(t.target.name),r(t.args));return t}function tr(e){let t=new Set(e.variables.map(e=>e.name));return er(e.steps).find(e=>!t.has(e))??null}function nr(e){if(e.name.trim()===``)return{ok:!1,reason:{kind:`name`}};if(e.steps.length===0)return{ok:!1,reason:{kind:`no-steps`}};let t=e.variables.find(e=>!sr(e.name));if(t!==void 0)return{ok:!1,reason:{kind:`bad-name`,name:t.name}};let n=cr(e.variables)[0];if(n!==void 0)return{ok:!1,reason:{kind:`duplicate`,name:n}};let r=tr(e);if(r!==null)return{ok:!1,reason:{kind:`undeclared`,name:r}};let i=me.safeParse({name:e.name.trim(),steps:e.steps,...e.variables.length===0?{}:{variables:e.variables}});if(!i.success){let e=i.error.issues[0];return{ok:!1,reason:{kind:`schema`,message:`${e===void 0||e.path.length===0?``:`${e.path.join(`.`)}: `}${e?.message??`invalid`}`}}}return{ok:!0,input:i.data}}function rr(e,t,n){return on(e)?e.$var===t?{$var:n}:e:Array.isArray(e)?e.map(e=>rr(e,t,n)):typeof e==`object`&&e?Object.fromEntries(Object.entries(e).map(([e,r])=>[e,rr(r,t,n)])):e}function ir(e,t,n){if(e.kind!==`cap`)return e;let r=on(e.deviceId)&&e.deviceId.$var===t?{$var:n}:e.deviceId,i=e.target?.kind===`var`&&e.target.name===t?{kind:`var`,name:n}:e.target,a=e.args===void 0?void 0:Object.fromEntries(Object.entries(e.args).map(([e,r])=>[e,rr(r,t,n)]));return{...e,...r===void 0?{}:{deviceId:r},...i===void 0?{}:{target:i},...a===void 0?{}:{args:a}}}function ar(e,t,n){let r=e.variables[t];return r===void 0||r.name===n?e:{...e,variables:e.variables.map((e,r)=>r===t?{...e,name:n}:e),steps:e.steps.map(e=>ir(e,r.name,n))}}function or(e){let t=new Set(e.map(e=>e.name)),n=`value`;for(let e=2;t.has(n);e++)n=`value${String(e)}`;return{name:n,type:`string`}}function sr(e){return/^[A-Za-z_][A-Za-z0-9_]*$/.test(e)}function cr(e){let t=new Set,n=new Set;for(let r of e)t.has(r.name)&&n.add(r.name),t.add(r.name);return[...n]}function lr(e){return e.some(e=>e.required===!0&&e.default===void 0)}function ur(e){return Object.fromEntries(e.map(e=>[e.name,e.default??(e.type===`boolean`?!1:void 0)]))}function dr(e){return e===void 0?!1:typeof e==`string`?e.trim()!==``:typeof e==`number`?Number.isFinite(e):!0}function fr(e,t){return e.filter(e=>e.required===!0&&!dr(t[e.name])).map(e=>e.name)}function pr(e,t){let n={};for(let r of e){let e=t[r.name];dr(e)&&(n[r.name]=e)}return n}function mr({variable:e,value:t,onChange:n}){let{t:r}=Z(),i=e.label??e.name;return e.type===`number`?o(sn,{"aria-label":i,value:typeof t==`number`?t:void 0,onValue:e=>n(e??void 0)}):e.type===`boolean`?o(an,{widthClass:`w-28`,"aria-label":i,value:t===!0?`yes`:`no`,onChange:e=>n(e.target.value===`yes`),options:[{value:`yes`,label:r(`common.yes`,`Yes`)},{value:`no`,label:r(`common.no`,`No`)}]}):e.type===`select`?o(an,{widthClass:`w-48`,"aria-label":i,value:typeof t==`string`?t:``,onChange:e=>n(e.target.value===``?void 0:e.target.value),options:[{value:``,label:r(`actions.editor.runDialog.choose`,`Choose…`)},...(e.options??[]).map(e=>({value:e,label:e}))]}):o(J,{"aria-label":i,value:typeof t==`string`?t:``,onChange:e=>n(e.target.value)})}function hr({actionName:t,variables:n,running:r,onRun:i,onCancel:a}){let{t:s}=Z(),[l,u]=c(()=>ur(n)),d=fr(n,l);return o(Ye,{open:!0,onOpenChange:e=>!e&&a(),children:e(Ve,{"aria-label":s(`actions.editor.runDialog.title`,`Run {{name}}`,{name:t}),children:[e(Ut,{children:[o(Me,{children:s(`actions.editor.runDialog.title`,`Run {{name}}`,{name:t})}),o(We,{children:s(`actions.editor.runDialog.description`,`Give the variables this run should use.`)})]}),o(`div`,{className:`space-y-3`,"data-testid":`run-variables-form`,children:n.map(t=>e(`label`,{className:`block space-y-1`,children:[e(`span`,{className:`text-xs text-foreground-subtle`,children:[t.label??t.name,t.required===!0?` *`:``]}),o(mr,{variable:t,value:l[t.name],onChange:e=>u({...l,[t.name]:e})})]},t.name))}),e($e,{className:`flex flex-wrap gap-2`,children:[o(Y,{variant:`ghost`,onClick:a,children:s(`common.cancel`,`Cancel`)}),e(Y,{disabled:r||d.length>0,onClick:()=>i(pr(n,l)),children:[r?o(A,{className:`h-4 w-4 animate-spin`}):o(h,{className:`h-4 w-4`}),` `,s(`actions.editor.runNow`,`Run now`)]})]})]})})}var gr=[`number`,`string`,`boolean`,`select`];function _r(e,t){return{name:e.name,...e.label===void 0?{}:{label:e.label},type:t,...t===`select`?{options:e.options??[`option`]}:{}}}function vr(e,t){let n=t.split(`,`).map(e=>e.trim()).filter(e=>e!==``),r=e.default!==void 0&&typeof e.default==`string`&&n.includes(e.default),{default:i,...a}=e;return{...r?e:a,options:n.length===0?[`option`]:n}}function yr(e,t){let{default:n,...r}=e;return t===null?r:{...r,default:t}}function br(e,t){let{label:n,...r}=e;return t.trim()===``?r:{...r,label:t}}function xr({variables:t,onChange:n,onRename:r}){let{t:i}=Z(),a=e=>{switch(e){case`number`:return i(`actions.variables.typeNumber`,`number`);case`string`:return i(`actions.variables.typeText`,`text`);case`boolean`:return i(`actions.variables.typeBoolean`,`yes / no`);default:return i(`actions.variables.typeSelect`,`select`)}},s=(e,r)=>n(t.map((t,n)=>n===e?r:t));return o(Be,{headingId:`vars-heading`,title:i(`actions.variables.title`,`Variables`),icon:ke,actions:e(Y,{variant:`outline`,size:`sm`,onClick:()=>n([...t,or(t)]),children:[o(w,{className:`h-4 w-4`}),` `,i(`actions.variables.add`,`Variable`)]}),children:e(`div`,{className:`space-y-3 p-3`,children:[t.map((c,l)=>e(`div`,{className:`grid gap-2 sm:grid-cols-[1fr_1fr_8rem_1fr_1.2fr_auto] sm:items-end`,"data-testid":`variable-row`,children:[e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.name`,`Name`)}),o(J,{"aria-label":i(`actions.variables.nameAria`,`Variable name`),value:c.name,"aria-invalid":!sr(c.name),onChange:e=>r(l,e.target.value)})]}),e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.label`,`Label`)}),o(J,{"aria-label":i(`actions.variables.label`,`Label`),value:c.label??``,onChange:e=>s(l,br(c,e.target.value))})]}),e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.type`,`Type`)}),o(an,{widthClass:`w-full`,"aria-label":i(`actions.variables.type`,`Type`),value:c.type,options:gr.map(e=>({value:e,label:a(e)})),onChange:e=>{let t=gr.find(t=>t===e.target.value);t!==void 0&&s(l,_r(c,t))}})]}),e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.default`,`Default`)}),o(Sr,{variable:c,onChange:e=>s(l,yr(c,e))})]}),e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.options`,`Options`)}),o(J,{"aria-label":i(`actions.variables.options`,`Options`),value:(c.options??[]).join(`, `),disabled:c.type!==`select`,placeholder:i(`actions.variables.optionsHint`,`Only for a select`),onChange:e=>s(l,vr(c,e.target.value))})]}),o(Y,{variant:`ghost`,"aria-label":i(`actions.variables.remove`,`Remove variable`),onClick:()=>n(t.filter((e,t)=>t!==l)),children:o(_,{className:`h-4 w-4`})})]},`${String(l)}`)),o(`p`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.hint`,`Callers can override a variable. In a step, the {x} button puts one in an argument.`)})]})})}function Sr({variable:e,onChange:t}){let{t:n}=Z(),r=n(`actions.variables.default`,`Default`);if(e.type===`number`)return o(sn,{"aria-label":r,value:typeof e.default==`number`?e.default:void 0,onValue:t});if(e.type===`boolean`||e.type===`select`){let i=e.type===`boolean`?[{value:`true`,label:n(`common.yes`,`Yes`)},{value:`false`,label:n(`common.no`,`No`)}]:(e.options??[]).map(e=>({value:e,label:e}));return o(an,{widthClass:`w-full`,"aria-label":r,value:e.default===void 0?``:String(e.default),options:[{value:``,label:n(`actions.variables.noDefault`,`None`)},...i],onChange:n=>{n.target.value===``?t(null):t(e.type===`boolean`?n.target.value===`true`:n.target.value)}})}return o(J,{"aria-label":r,value:typeof e.default==`string`?e.default:``,onChange:e=>t(e.target.value===``?null:e.target.value)})}u();var Cr=5e3;function wr(e){return e.kind===`cap`||e.kind===`wait`}function Tr(e){return e instanceof Error?e.message:String(e)}function Er(){let{t:e}=Z();return t=>{switch(t.kind){case`name`:return e(`actions.editor.problemName`,`Give the action a name.`);case`no-steps`:return e(`actions.editor.problemNoSteps`,`Add at least one step.`);case`undeclared`:return e(`actions.editor.problemUndeclared`,`A step uses {{name}}, which is not declared under Variables.`,{name:t.name});case`duplicate`:return e(`actions.editor.problemDuplicate`,`The variable {{name}} is declared twice.`,{name:t.name});case`bad-name`:return e(`actions.editor.problemBadName`,`The variable name "{{name}}" must start with a letter and use letters, digits or _.`,{name:t.name});default:return t.message}}}function Dr({entry:t,onClose:n,onSaved:i}){let{t:a}=Z(),s=d(),l=E(),u=wn(),f=Er(),[g,v]=c(()=>$n(t)),[y,b]=c(null),[x,S]=c(!1),C=t!==null&&t.readOnly,w=()=>{s.invalidateQueries({queryKey:[[`actions`]]})},T=ze({onSuccess:e=>{w(),i(e.action.id)}}),D=tt({onSuccess:w}),O=He({onSuccess:()=>{w(),n()}}),k=it({onSuccess:w}),j=Vt({actionId:t?.id??`none`},{enabled:t!==null,refetchInterval:Cr}),M=j.data?.traces.find(e=>e.runId===y)??null,N=r(()=>M===null?null:cn(M),[M]),P=r(()=>M===null?null:kn(M).steps,[M]),F=nr(g),I=r(()=>Xn(g.variables,a),[g.variables,a]),L=T.isPending||D.isPending,R=T.error??D.error??O.error??k.error,z=lr(t?.variables??[]);return e(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]`,"data-testid":`action-editor`,children:[e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(m,{className:`h-4 w-4 text-foreground-muted`}),o(J,{"aria-label":a(`actions.editor.name`,`Name`),className:`max-w-xs flex-1`,value:g.name,disabled:C,placeholder:a(`actions.editor.namePlaceholder`,`What this action does`),onChange:e=>v({...g,name:e.target.value})}),o(K,{variant:C?`info`:`primary`,children:C?t?.addonId??``:a(`actions.source.internal`,`Internal`)})]}),C?o(`p`,{className:`rounded-md border border-border bg-surface p-3 text-sm text-foreground-muted`,children:a(`actions.editor.readOnly`,`This action is declared by {{addon}}. Edit it there; you can run it from here.`,{addon:t?.addonId??``})}):e(p,{children:[o(xr,{variables:g.variables,onChange:e=>v({...g,variables:e}),onRename:(e,t)=>v(ar(g,e,t))}),o(ln,{step:`steps`,title:a(`actions.editor.steps`,`Steps`),trace:N===null?null:N.thenBlock,children:o(Cn,{actions:g.steps,devices:u,allowedKinds:[`cap`,`wait`],stepTones:N===null?void 0:g.steps.map((e,t)=>un(N,t)??`idle`),stepResults:P===null?void 0:g.steps.map((e,t)=>P.find(e=>e.index===t)),variables:I,onChange:e=>v({...g,steps:e.filter(wr)})})})]}),!F.ok&&!C&&g.name!==``&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:f(F.reason)}),R!==null&&o(q,{message:Tr(R)}),e(`div`,{className:`flex flex-wrap gap-2`,children:[!C&&e(Y,{onClick:()=>{F.ok&&(t===null?T.mutate({action:F.input}):D.mutate({actionId:t.id,action:F.input}))},disabled:L||!F.ok,children:[L&&o(A,{className:`h-4 w-4 animate-spin`}),` `,a(`common.save`,`Save`)]}),t!==null&&e(Y,{variant:`outline`,disabled:k.isPending,onClick:()=>z?S(!0):k.mutate({actionId:t.id}),children:[o(h,{className:`h-4 w-4`}),` `,a(`actions.editor.runNow`,`Run now`)]}),t!==null&&!C&&e(Y,{variant:`ghost`,disabled:O.isPending,onClick:()=>{l({title:a(`actions.editor.deleteTitle`,`Delete this action?`),message:a(`actions.editor.deleteMessage`,`{{name}} will be deleted, and removed from every camera that links it.`,{name:t.name}),confirmLabel:a(`common.delete`,`Delete`),variant:`danger`}).then(e=>{e&&O.mutate({actionId:t.id})})},children:[o(_,{className:`h-4 w-4`}),` `,a(`common.delete`,`Delete`)]}),o(Y,{variant:`ghost`,onClick:n,children:a(`common.close`,`Close`)})]})]}),o(`div`,{className:`order-first lg:order-last`,children:o(mn,{traces:t===null?[]:j.data?.traces,selectedId:y,onSelect:b})}),x&&t!==null&&o(hr,{actionName:t.name,variables:t.variables??[],running:k.isPending,onCancel:()=>S(!1),onRun:e=>{k.mutate({actionId:t.id,variables:e}),S(!1)}})]})}u();var Or=5e3;function kr(e){return e instanceof Error?e.message:String(e)}function Ar(){let{t:e}=Z();return t=>t.status.isRunning?{variant:`info`,label:e(`actions.status.running`,`Running`)}:t.status.lastError===null?t.status.lastRunAt===null?{variant:`neutral`,label:e(`actions.status.neverRan`,`Never ran`)}:{variant:`success`,label:e(`actions.status.ok`,`OK`)}:{variant:`danger`,label:e(`actions.status.failed`,`Failed`)}}function jr({createRequested:t=!1,onCreateConsumed:n}){let{t:i}=Z(),a=d(),c=Ar(),{state:l,openNew:u,openEdit:f,close:g}=Rt({editKey:`action`,newKey:`new`}),_=je({},{refetchInterval:Or}),v=it({onSuccess:()=>void a.invalidateQueries({queryKey:[[`actions`]]})});s(()=>{t&&(u(),n?.())},[t,n,u]);let y=_.data??[],b=l.mode===`edit`?y.find(e=>e.id===l.id)??null:null,x=r(()=>[{key:`name`,header:i(`actions.list.name`,`Name`),render:e=>o(`span`,{className:`font-medium`,children:e.name}),sortValue:e=>e.name},{key:`source`,header:i(`actions.list.source`,`Source`),render:e=>e.readOnly?o(K,{variant:`info`,children:e.addonId}):o(K,{variant:`primary`,children:i(`actions.source.internal`,`Internal`)}),sortValue:e=>e.addonId},{key:`lastRun`,header:i(`actions.list.lastRun`,`Last run`),render:e=>e.status.lastRunAt===null?o(`span`,{className:`text-foreground-subtle`,children:`-`}):nn(e.status.lastRunAt),sortValue:e=>e.status.lastRunAt},{key:`status`,header:i(`actions.list.status`,`Status`),render:e=>{let t=c(e);return o(`span`,{title:e.status.lastError??void 0,children:o(K,{variant:t.variant,children:t.label})})},notSortableReason:i(`actions.list.statusNotSortable`,`Derived from the latest run`)},{key:`run`,align:`right`,render:t=>e(Y,{variant:`outline`,size:`sm`,disabled:v.isPending||t.status.isRunning,"aria-label":i(`actions.list.runAria`,`Run {{name}}`,{name:t.name}),onClick:e=>{e.stopPropagation(),v.mutate({actionId:t.id})},children:[o(h,{className:`h-4 w-4`}),` `,i(`actions.list.run`,`Run`)]}),notSortableReason:i(`actions.list.runNotSortable`,`A control`)}],[v,c,i]);return l.mode===`closed`?e(`div`,{className:`space-y-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:i(`actions.list.hint`,`Actions are things this installation can do. Run one here, link it to a camera, or use it in an automation.`)}),v.error!=null&&o(q,{message:kr(v.error)}),_.data===void 0?_.error==null?o(ut,{className:`h-24 w-full`}):o(q,{title:i(`actions.list.couldNotRead`,`Could not read the actions`),message:kr(_.error),onRetry:()=>void _.refetch()}):y.length===0?o(ct,{icon:m,title:i(`actions.list.emptyTitle`,`No actions yet`),description:i(`actions.list.emptyDescription`,`An action is a short list of commands, such as feeding the dog, that you can reuse.`),action:e(Y,{onClick:u,children:[o(w,{className:`h-4 w-4`}),` `,i(`actions.list.new`,`New action`)]})}):e(p,{children:[_.error!=null&&o(q,{title:i(`actions.list.couldNotRead`,`Could not read the actions`),message:kr(_.error),onRetry:()=>void _.refetch()}),o(Qe,{columns:x,rows:y,rowKey:e=>e.id,pageSize:25,maxBodyHeight:Ht,emptyMessage:i(`actions.list.emptyTitle`,`No actions yet`),onRowClick:e=>f(e.id)})]})]}):o(Dr,{entry:b,onClose:g,onSaved:f},b?.id??`new`)}u();function Mr({code:t,error:n,canEject:r,ejecting:i,onEject:a}){let{t:s}=Z(),[l,u]=c(!1),d=E(),f=async()=>{await d({title:s(`automation.generatedCodePanel.ejectToCodeThisCannot`,`Eject to code — this cannot be undone`),message:s(`automation.generatedCodePanel.theRecipeIsRemovedFrom`,`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:s(`automation.generatedCodePanel.ejectToCode`,`Eject to code`),cancelLabel:s(`automation.generatedCodePanel.keepItVisual`,`Keep it visual`),variant:`warning`})&&a()};return e(`div`,{className:`rounded border border-border`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2 px-3 py-2`,children:[e(Y,{variant:`ghost`,onClick:()=>u(!l),children:[o(l?g:y,{className:`h-4 w-4`}),s(`automation.generatedCodePanel.generatedCode`,`Generated code`)]}),o(`span`,{className:`text-xs text-foreground-subtle`,children:s(`automation.generatedCodePanel.derivedFromTheRecipeAbove`,`Derived from the recipe above — regenerated on every save, never edited here.`)}),e(Y,{className:`ml-auto`,variant:`ghost`,disabled:!r||t===null||i,onClick:()=>void f(),title:r?s(`automation.generatedCodePanel.takePermanentOwnershipOfThis`,`Take permanent ownership of this code as a script`):s(`automation.generatedCodePanel.saveTheAutomationFirstThere`,`Save the automation first — there is no stored block to eject yet`),children:[o(Ee,{className:`h-4 w-4`}),` `,s(`automation.generatedCodePanel.eject`)]})]}),l&&o(`div`,{className:`border-t border-border p-3`,children:t===null?o(`p`,{className:`text-xs text-warning`,children:n??s(`automation.generatedCodePanel.theRecipeIsNotComplete`,`The recipe is not complete enough to generate a block yet.`)}):o(Ke,{maxHeight:420,children:t})})]})}var Nr=[`single`,`restart`,`queued`,`parallel`,`cooldown`],Pr=2,Fr=30;function Ir(e){return e.runMode??{mode:`single`}}function Lr(e,t){let{runMode:n,...r}=e;return t.mode===`single`?r:{...r,runMode:t}}function Rr(e){switch(e){case`queued`:return{mode:`queued`,max:Pr};case`parallel`:return{mode:`parallel`,max:Pr};case`cooldown`:return{mode:`cooldown`,minutes:Fr};case`restart`:return{mode:`restart`};default:return{mode:`single`}}}function zr(e){return Nr.find(t=>t===e)??`single`}function Br({value:t,onChange:n}){let{t:r}=Z(),i={single:r(`flow.runMode.single`,`Skip it`),restart:r(`flow.runMode.restart`,`Restart the run`),queued:r(`flow.runMode.queued`,`Queue it`),parallel:r(`flow.runMode.parallel`,`Run at the same time`),cooldown:r(`flow.runMode.cooldown`,`Wait after a run`)},a={single:r(`flow.runMode.singleHint`,`A trigger that arrives during a run is dropped.`),restart:r(`flow.runMode.restartHint`,`The run in progress stops and a new one starts.`),queued:r(`flow.runMode.queuedHint`,`Triggers wait their turn, up to the limit.`),parallel:r(`flow.runMode.parallelHint`,`Runs overlap, up to the limit.`),cooldown:r(`flow.runMode.cooldownHint`,`No new run until this long after the last one began.`)};return e(`div`,{className:`flex flex-wrap items-end gap-3`,"data-testid":`run-mode`,children:[e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`block text-xs text-foreground-subtle`,children:r(`flow.runMode.label`,`When it is already running`)}),o(an,{widthClass:`w-56`,value:t.mode,options:Nr.map(e=>({value:e,label:i[e]})),onChange:e=>n(Rr(zr(e.target.value)))})]}),(t.mode===`queued`||t.mode===`parallel`)&&e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`block text-xs text-foreground-subtle`,children:r(`flow.runMode.max`,`Up to`)}),o(sn,{className:`w-20`,"aria-label":r(`flow.runMode.max`,`Up to`),value:t.max,onValue:e=>{e!==null&&n({mode:t.mode,max:Math.round(e)})}})]}),t.mode===`cooldown`&&e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`block text-xs text-foreground-subtle`,children:r(`flow.runMode.minutes`,`Minutes`)}),o(sn,{className:`w-20`,"aria-label":r(`flow.runMode.minutes`,`Minutes`),value:t.minutes,onValue:e=>{e!==null&&n({mode:`cooldown`,minutes:Math.round(e)})}})]}),o(`p`,{className:`basis-full text-xs text-foreground-subtle`,children:a[t.mode]})]})}var Vr;function Hr(){return Vr??=U(ue),Vr}function Ur(e,t=Hr()){return xe(e,t)}function Wr({value:t,field:n,deviceId:r,cap:i,onChange:a}){let{t:s}=Z(),c=Zr(n,r,i);if(n?.kind===`boolean`)return o(k,{value:t===!0?`true`:`false`,onChange:e=>a(e.target.value===`true`),options:[{value:`true`,label:s(`common.true`)},{value:`false`,label:s(`common.false`)}]});if(n?.kind===`enum`&&n.enumValues!==void 0&&n.enumValues.length>0)return o(k,{value:String(t),onChange:e=>a(e.target.value),options:n.enumValues.map(e=>({value:e,label:e}))});if(n?.kind===`number`){let n=typeof t==`number`&&c?c.toDisplayValue(t):t;return e(`span`,{className:`inline-flex items-center gap-1`,children:[o(J,{type:`number`,value:typeof n==`number`?String(n):``,placeholder:`0`,onChange:e=>{let t=Number(e.target.value);e.target.value!==``&&!Number.isNaN(t)&&a(c?c.fromDisplayValue(t):t)}}),c!==void 0&&c.unit.length>0?o(`span`,{className:`text-xs text-foreground-subtle`,children:c.unit}):null]})}return o(J,{value:String(t),placeholder:s(`common.valueWord`),onChange:e=>a(e.target.value)})}function Gr({value:e,field:t,deviceId:n,cap:r,onChange:i}){let{t:a}=Z(),s=Zr(t,n,r);return o(J,{value:(s?e.map(e=>typeof e==`number`?s.toDisplayValue(e):e):e).join(`, `),placeholder:a(`automation.valueInput.oneTwoThree`,`one, two, three`),onChange:e=>{let n=e.target.value.split(`,`).map(e=>e.trim()).filter(e=>e!==``);i(t?.kind===`number`?n.map(e=>Number(e)).filter(e=>!Number.isNaN(e)).map(e=>s?s.fromDisplayValue(e):e):n)}})}function Kr(e){return typeof e==`object`&&!le(e)}function qr(e){return le(e)?e.value:Kr(e)?e[0]??``:e}function Jr(e){return le(e)?[e.value]:Kr(e)?e:typeof e==`boolean`?[]:[e]}function Yr(e){let t=e?.quantity;if(!(e?.kind!==`number`||t===void 0)&&!(!ve(t)||t===`none`||t===`device`))return F(t).length>0?t:void 0}function Xr(e,t){if(!(e===void 0||e===`none`)){if(e!==`device`)return e;if(!(t===void 0||t===`device`||t===`none`))return t}}function Zr(e,t,n){let r=bt(),i=t??0,a=e?.kind===`number`&&e.quantity!==void 0,{data:o}=at({deviceId:i},{enabled:a&&i>0}),s=o?.sourceInfo?.quantity,c=ve(s)?s:void 0,l=Xr(e?.quantity,c);if(l===void 0)return;let u=o?.display;return gt({quantity:l,display:u,capName:n,unitPreferences:r})}function Qr({leaf:t,devices:n,onChange:r}){let{t:i}=Z(),a={deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath},s=xn(a),c=yn(s?.kind),l=t.operator===`in`,u=Yr(s),d=u===void 0?void 0:L(u),f=e=>{let{unit:n,...i}=t;r({...i,deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath})},p=e=>{let n=$r(e,c),{unit:i,...a}=t;r({...n===`in`?a:t,operator:n,value:n===`in`?[...Jr(t.value)]:qr(t.value)})};return e(`div`,{className:`flex flex-wrap items-end gap-2`,children:[o(gn,{value:a,devices:n,onChange:f}),e(`label`,{className:`min-w-[8rem]`,children:[o(Q,{children:i(`automation.conditionRow.comparison`,`Comparison`)}),o(k,{value:t.operator,onChange:e=>p(e.target.value),options:c.map(e=>({value:e.value,label:e.label}))})]}),e(`label`,{className:`min-w-[9rem] flex-1`,children:[o(Q,{children:i(`automation.conditionRow.value`,`Value`)}),l?o(Gr,{value:Jr(t.value),field:s,deviceId:t.deviceId,cap:t.cap,onChange:e=>r({...t,value:[...e]})}):u!==void 0&&d!==void 0?o(Ie,{quantity:u,storedUnit:d,value:typeof t.value==`number`?t.value:void 0,unit:t.unit,"aria-label":i(`automation.conditionRow.value`,`Value`),onChange:e=>{let n=jt(e,d);r({...t,value:n.value,unit:n.unit})}}):o(Wr,{value:qr(t.value),field:s,deviceId:t.deviceId,cap:t.cap,onChange:e=>r({...t,value:e})})]})]})}function $r(e,t){return t.find(t=>t.value===e)?.value??`eq`}var ei=Object.values(be).sort((e,t)=>e.localeCompare(t));function ti({leaf:t,onChange:n}){let{t:r}=Z();return e(`label`,{className:`min-w-[14rem] flex-1`,children:[o(Q,{children:r(`automation.triggerEditor.cronExpression`,`Cron expression`)}),o(J,{value:t.cron,placeholder:`0 30 23 * * *`,onChange:e=>n({kind:`schedule`,cron:e.target.value})}),o(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:o(Jt,{i18nKey:`automation.triggerEditor.cronHint`,components:{code:o(`code`,{})}})})]})}function ni(){return o(`p`,{className:`text-xs text-foreground-subtle`,children:o(Jt,{i18nKey:`automation.triggerEditor.manualHint`,components:{b:o(`strong`,{})}})})}function ri(e,t){return{kind:`device-becomes`,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 ii({leaf:t,devices:n,onChange:r}){let{t:i}=Z(),a={deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath},s=xn(a),c={...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}};return e(p,{children:[o(gn,{value:a,devices:n,onChange:e=>r(ri(e,c))}),e(`div`,{className:`min-w-[11rem] flex-1`,children:[o(Q,{children:i(`automation.triggerEditor.becomes`,`Becomes`)}),e(`div`,{className:`flex items-center gap-2`,children:[e(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[o(Et,{checked:t.becomes===void 0,onChange:e=>r(ri(a,{...c,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),i(`automation.triggerEditor.anyChange`,`any change`)]}),t.becomes!==void 0&&o(Wr,{value:t.becomes,field:s,deviceId:a.deviceId,cap:a.cap,onChange:e=>r(ri(a,{...c,becomes:e}))})]})]}),e(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[o(Et,{checked:t.edge===!0,onChange:e=>r(ri(a,{...c,...e.target.checked?{edge:!0}:{edge:void 0}}))}),i(`automation.triggerEditor.onlyOnAChange`,`only on a change`)]}),e(`label`,{className:`w-28`,children:[o(Q,{children:i(`automation.triggerEditor.heldForS`,`Held for (s)`)}),o(J,{type:`number`,min:0,value:t.forMs===void 0?``:String(t.forMs/1e3),placeholder:`0`,onChange:e=>r(ri(a,{...c,forMs:ai(e.target.value)}))})]}),e(`label`,{className:`w-28`,children:[o(Q,{children:i(`automation.triggerEditor.debounceS`,`Debounce (s)`)}),o(J,{type:`number`,min:0,value:t.debounceMs===void 0?``:String(t.debounceMs/1e3),placeholder:`0`,onChange:e=>r(ri(a,{...c,debounceMs:ai(e.target.value)}))})]})]})}function ai(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function oi({leaf:t,devices:n,onChange:r}){let{t:i}=Z();return e(p,{children:[e(`label`,{className:`min-w-[15rem] flex-1`,children:[o(Q,{children:i(`automation.triggerEditor.eventCategory`,`Event category`)}),o(k,{value:t.category,onChange:e=>r({kind:`device-event`,category:e.target.value,...t.deviceId===void 0?{}:{deviceId:t.deviceId}}),options:[{value:``,label:i(`automation.triggerEditor.selectAnEvent`,`Select an event…`)},...ei.map(e=>({value:e,label:e}))]})]}),e(`div`,{className:`min-w-[11rem] flex-1`,children:[o(Q,{children:i(`automation.triggerEditor.fromDevice`,`From device`)}),o(_n,{devices:n,selection:`single`,value:t.deviceId===void 0?[]:[t.deviceId],emptyLabel:i(`automation.triggerEditor.anyDevice`,`Any device`),testId:`trigger-event-device`,onChange:e=>r({kind:`device-event`,category:t.category,...e[0]===void 0?{}:{deviceId:e[0]}})})]})]})}var si={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function ci({leaf:t,devices:n,onChange:r}){let{t:i}=Z(),a=Object.entries(t.bindings),s=e=>{r({kind:`expression`,expr:t.expr,bindings:e})};return e(`div`,{className:`space-y-2`,children:[e(`label`,{className:`block`,children:[o(Q,{children:i(`automation.expressionLeafRow.expression`,`Expression`)}),o(J,{value:t.expr,placeholder:i(`automation.expressionLeafRow.indoorOutdoor5`,`indoor - outdoor > 5`),onChange:e=>r({kind:`expression`,expr:e.target.value,bindings:t.bindings})}),o(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:i(`automation.expressionLeafRow.mustEvaluateToTrueOr`,`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.`)})]}),e(`div`,{className:`space-y-1.5`,children:[a.length===0&&o(`p`,{className:`text-xs text-foreground-subtle`,children:i(`automation.expressionLeafRow.noNamesBoundYetAn`,`No names bound yet. An expression reads devices only through these.`)}),a.map(([e,r])=>o(li,{alias:e,source:r,devices:n,onRename:n=>s(hi(t.bindings,e,n)),onChange:n=>s({...t.bindings,[e]:n}),onRemove:()=>s(gi(t.bindings,e))},e)),e(Y,{variant:`ghost`,onClick:()=>s({...t.bindings,[mi(t.bindings)]:si}),children:[o(w,{className:`h-3.5 w-3.5`}),` `,i(`common.name`)]})]})]})}function li({alias:t,source:n,devices:r,onRename:i,onChange:a,onRemove:s}){let{t:c}=Z(),l=n.kind===`literal`,u=l?{deviceId:0,cap:``,fieldPath:``}:{deviceId:fi(r,di(n)),cap:n.cap,fieldPath:n.fieldPath};return e(`div`,{className:`flex flex-wrap items-end gap-2 rounded border border-border p-2`,children:[e(`label`,{className:`w-32`,children:[o(Q,{children:c(`automation.expressionLeafRow.name`,`Name`)}),o(J,{value:t,placeholder:c(`automation.expressionLeafRow.aliasExample`),onChange:e=>i(e.target.value)})]}),e(`label`,{className:`w-36`,children:[o(Q,{children:c(`automation.expressionLeafRow.reads`,`Reads`)}),o(k,{value:l?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:si),options:[{value:`global`,label:c(`automation.expressionLeafRow.aDeviceField`,`A device field`)},{value:`literal`,label:c(`automation.expressionLeafRow.aConstant`,`A constant`)}]})]}),l?e(`label`,{className:`min-w-[9rem] flex-1`,children:[o(Q,{children:c(`automation.expressionLeafRow.constant`,`Constant`)}),o(J,{value:n.value===null?``:String(n.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:ui(e.target.value)})})]}):o(gn,{value:u,devices:r,onChange:e=>a({kind:`global`,sourceStableId:pi(r,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),o(Y,{variant:`ghost`,onClick:s,title:c(`automation.expressionLeafRow.removeThisName`,`Remove this name`),children:o(_,{className:`h-3.5 w-3.5`})})]})}function ui(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function di(e){return e.kind===`global`?e.sourceStableId:``}function fi(e,t){return e.find(e=>e.stableId===t)?.id??0}function pi(e,t){return e.find(e=>e.id===t)?.stableId??``}function mi(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 hi(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function gi(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}var _i=`text-xs text-foreground-subtle`;function vi({children:e}){return o(`span`,{className:_i,children:e})}function yi(e,t){return e.includes(t)?e.filter(e=>e!==t):[...e,t]}function bi({devices:t,selected:n,onChange:r}){let{t:i}=Z(),a=t.filter(e=>e.type===W.Camera);return e(`div`,{className:`space-y-1`,children:[o(vi,{children:i(`flow.scene.cameras`,`Cameras`)}),o(_n,{devices:a,selection:`multiple`,noun:`camera`,value:n,testId:`scene-cameras`,onChange:r})]})}function xi({device:t,deviceId:n,selected:r,onToggle:i}){let a=lt({deviceId:n});return a.data===void 0||a.data.length===0?null:e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(`span`,{className:_i,children:t?.name??`#${String(n)}`}),a.data.map(e=>o(Y,{size:`sm`,variant:r.includes(e.id)?`primary`:`outline`,"aria-pressed":r.includes(e.id),onClick:()=>i(e.id),children:e.name},e.id))]})}function Si({devices:t,deviceIds:n,selected:r,onChange:i}){let{t:a}=Z();if(n.length===0)return null;let s=e=>{let t=yi(r,e);i(t.length===0?void 0:t)};return e(`div`,{className:`space-y-1`,children:[o(vi,{children:a(`flow.scene.zones`,`Zones`)}),o(`div`,{className:`space-y-2`,children:n.map(e=>o(xi,{device:t.find(t=>t.id===e),deviceId:e,selected:r,onToggle:s},e))}),o(`p`,{className:_i,children:r.length===0?a(`flow.scene.wholeScene`,`None picked: the whole scene counts.`):a(`flow.scene.zonesPicked`,`Only these zones count.`)})]})}var Ci=[`animal`,`person`,`vehicle`,`package`,`other`];function wi(e){return Ci.find(t=>t===e)??`other`}function Ti(e){switch(e){case`animal`:return{macro:`animal`};case`person`:return{macro:`person`};case`vehicle`:return{macro:`vehicle`};case`package`:return{macro:`package`};default:return{macro:`other`,className:``}}}function Ei(){let{t:e}=Z();return t=>{switch(t){case`person`:return e(`flow.class.person`,`Person`);case`vehicle`:return e(`flow.class.vehicle`,`Vehicle`);case`animal`:return e(`flow.class.animal`,`Animal`);case`package`:return e(`flow.class.package`,`Package`);default:return e(`automation.whenTree.macroOther`,`Other class`)}}}function Di(e,t){let n={kind:`sub-class`,className:t};switch(e){case`animal`:return{macro:e,label:n};case`package`:return{macro:e,label:n};case`vehicle`:return{macro:e,label:n};default:return{macro:`person`}}}var Oi=[`automation`,`class-taxonomy`];function ki(){let e=D();return oe(l({queryKey:Oi,retry:!1,staleTime:1/0,queryFn:()=>e.trpcClient.notificationRules.getConditionCatalog.query({})}).data?.taxonomy)}function Ai(e,t,n){let r=n?.groups.find(t=>t.key===e),i=r===void 0?V(e).filter(t=>t!==e).map(e=>({value:e,label:e})):r.options.filter(t=>t.value!==e).map(e=>({value:e.value,label:e.label}));return t!==void 0&&!i.some(e=>e.value===t)?[...i,{value:t,label:t}]:i}function ji({subject:e,onChange:t}){let{t:n}=Z(),r=e.label?.kind===`sub-class`?e.label.className:void 0,i=ki(),a=Ai(e.macro,r,i);return a.length===0?null:o(k,{"aria-label":n(`automation.whenTree.labelAria`,`Narrow to`),"data-testid":`subject-label`,value:r??``,options:[{value:``,label:n(`automation.whenTree.anyLabel`,`Any`)},...a],onChange:n=>{let r=n.target.value;t(r===``?Ti(e.macro):Di(e.macro,r))}})}function Mi({onChange:e,subject:t}){let{t:n}=Z(),r=qe(),i=t.macro===`person`?t.label:void 0,a=r.data??[],s=a.map(e=>({value:e.id,label:e.name}));return i!==void 0&&!a.some(e=>e.id===i.identityId)&&s.push({value:i.identityId,label:i.name}),o(k,{"aria-label":n(`automation.whenTree.labelAria`,`Narrow to`),"data-testid":`subject-label`,value:i?.identityId??``,options:[{value:``,label:n(`automation.whenTree.anyPerson`,`Anyone`)},...s],onChange:t=>{let n=t.target.value,r=s.find(e=>e.value===n);e(n===``||r===void 0?{macro:`person`}:{macro:`person`,label:{kind:`identity`,identityId:n,name:r.label}})}})}var Ni=`plate:`,Pi=`class:`,Fi=200;function Ii({onChange:e,subject:t}){let{t:n}=Z(),r=xt({includeCrops:!1,limit:Fi}),i=t.macro===`vehicle`?t.label:void 0,a=i?.kind===`plate`?i.text:void 0,s=ki(),c=i?.kind===`sub-class`?i.className:void 0,l=[...new Set((r.data??[]).map(e=>e.text))];a!==void 0&&!l.includes(a)&&l.push(a);let u=a===void 0?c===void 0?``:`${Pi}${c}`:`${Ni}${a}`;return o(k,{"aria-label":n(`automation.whenTree.labelAria`,`Narrow to`),"data-testid":`subject-label`,value:u,options:[{value:``,label:n(`automation.whenTree.anyLabel`,`Any`)},...Ai(`vehicle`,c,s).map(e=>({value:`${Pi}${e.value}`,label:e.label})),...l.map(e=>({value:`${Ni}${e}`,label:n(`automation.whenTree.plateOption`,`Plate {{text}}`,{text:e})}))],onChange:t=>{let n=t.target.value;n.startsWith(Ni)?e({macro:`vehicle`,label:{kind:`plate`,text:n.slice(6)}}):n.startsWith(Pi)?e({macro:`vehicle`,label:{kind:`sub-class`,className:n.slice(6)}}):e({macro:`vehicle`})}})}function Li({subject:t,classLabelsOnly:n,verb:r,onChange:i,onRemove:a}){let{t:s}=Z(),c=Ei(),l=t.macro===`other`?[]:_e[t.macro],u=l.some(e=>e.kind===`cap`&&e.label===`identity`),d=l.some(e=>e.kind===`cap`&&e.label===`plate`);return e(`div`,{className:`flex flex-wrap items-center gap-2`,"data-testid":`subject-row`,children:[o(`div`,{className:`w-36`,children:o(k,{"aria-label":s(`automation.whenTree.macroAria`,`Class`),"data-testid":`subject-macro`,value:t.macro,options:Ci.map(e=>({value:e,label:c(e)})),onChange:e=>{let n=wi(e.target.value);n!==t.macro&&i(Ti(n))}})}),o(`span`,{className:`text-sm text-foreground-muted`,children:r}),t.macro===`other`?o(J,{className:`w-40`,"aria-label":s(`automation.whenTree.className`,`Class name`),"data-testid":`subject-class-name`,placeholder:s(`automation.whenTree.classNamePlaceholder`,`Class name`),value:t.className,onChange:e=>i({macro:`other`,className:e.target.value})}):u&&!n?o(`div`,{className:`w-44`,children:o(Mi,{subject:t,onChange:i})}):d&&!n?o(`div`,{className:`w-44`,children:o(Ii,{subject:t,onChange:i})}):!u&&o(`div`,{className:`w-44`,children:o(ji,{subject:t,onChange:i})}),a!==null&&o(Y,{variant:`ghost`,onClick:a,title:s(`automation.whenTree.removeClass`,`Remove this class`),children:o(_,{className:`h-3.5 w-3.5`})})]})}function Ri({subjects:t,optional:n,classLabelsOnly:r,verb:i,onChange:a}){let{t:s}=Z(),c=n||t.length>1;return e(`div`,{className:`space-y-2`,"data-testid":`subject-picker`,children:[t.map((e,n)=>o(Li,{subject:e,classLabelsOnly:r,verb:n===0?i:s(`automation.whenTree.orSubject`,`or`),onChange:e=>a(t.map((t,r)=>r===n?e:t)),onRemove:c?()=>a(t.filter((e,t)=>t!==n)):null},`${e.macro}-${String(n)}`)),t.length===0&&o(`p`,{className:`text-xs text-foreground-subtle`,children:s(`flow.scene.anyClass`,`None picked: any class counts.`)}),e(Y,{variant:`ghost`,size:`sm`,onClick:()=>a([...t,Ti(`person`)]),children:[o(w,{className:`h-3.5 w-3.5`}),` `,t.length===0?s(`automation.whenTree.onlySomeClasses`,`Only some classes`):s(`automation.whenTree.addClass`,`Add a class`)]})]})}var zi=100;function Bi({leaf:t,devices:n,onChange:r}){let{t:i}=Z(),a=Math.round((t.minScore??0)*zi),s=e=>{let{zones:n,...i}=t;r(e===void 0?i:{...i,zones:[...e]})},c=e=>{let{minScore:n,...i}=t;r(e<=0?i:{...i,minScore:e/zi})};return e(`div`,{className:`w-full space-y-3`,"data-testid":`detection-fields`,children:[o(Ri,{subjects:t.subjects,optional:!1,classLabelsOnly:!1,verb:i(`automation.whenTree.detected`,`detected`),onChange:e=>r({...t,subjects:[...e]})}),o(bi,{devices:n,selected:t.deviceIds,onChange:e=>r({...t,deviceIds:[...e]})}),o(Si,{devices:n,deviceIds:t.deviceIds,selected:t.zones??[],onChange:s}),e(`div`,{className:`space-y-1`,children:[o(vi,{children:a===0?i(`flow.scene.minScoreAny`,`Minimum score: any`):i(`flow.scene.minScore`,`Minimum score: {{value}}`,{value:(a/zi).toFixed(2)})}),o(Ft,{min:0,max:zi,value:a,"aria-label":i(`flow.scene.minScoreAria`,`Minimum score`),className:`block w-full max-w-sm accent-primary`,onChange:e=>c(Number(e.target.value))})]})]})}function Vi({leaf:t,devices:n,onChange:r}){let{t:i}=Z();return e(`div`,{className:`w-full space-y-3`,"data-testid":`stationary-fields`,children:[o(Ri,{subjects:t.subjects??[],optional:!0,classLabelsOnly:!0,verb:i(`automation.whenTree.parked`,`object`),onChange:e=>{let{subjects:n,...i}=t;r(e.length===0?i:{...i,subjects:[...e]})}}),o(bi,{devices:n,selected:t.deviceIds,onChange:e=>r({...t,deviceIds:[...e]})}),o(Si,{devices:n,deviceIds:t.deviceIds,selected:t.zones??[],onChange:e=>{let{zones:n,...i}=t;r(e===void 0?i:{...i,zones:[...e]})}}),o(St,{label:i(`flow.scene.firesWhen`,`Fires when it`),value:t.phase,onChange:e=>r({...t,phase:e}),options:[{value:`appeared`,label:i(`flow.scene.phaseAppeared`,`Stopped (parked)`)},{value:`departed`,label:i(`flow.scene.phaseDeparted`,`Left`)}]})]})}function Hi({leaf:t,onChange:n}){let{t:r}=Z();return e(`div`,{className:`flex items-center gap-2`,"data-testid":`interval-fields`,children:[o(vi,{children:r(`flow.scene.every`,`Every`)}),o(sn,{"aria-label":r(`flow.scene.intervalMinutes`,`Minutes`),className:`w-20`,value:t.minutes,onValue:e=>{e!==null&&n({kind:`interval`,minutes:Math.round(e)})}}),o(vi,{children:r(`flow.scene.minutes`,`minutes`)})]})}function Ui({leaf:t,devices:n,onChange:r}){let{t:i}=Z(),a=n.filter(e=>e.type===W.Camera),s=e=>{let{subjects:n,...i}=t;r(e.length===0?i:{...i,subjects:[...e]})},c=e=>{let{zones:n,...i}=t;r(e===void 0?i:{...i,zones:[...e]})},l=e=>{let{zones:n,...i}=t;r({...i,deviceId:e})};return e(`div`,{className:`space-y-3`,"data-testid":`stationary-present-fields`,children:[e(`div`,{className:`space-y-1`,children:[o(vi,{children:i(`flow.scene.parkedOn`,`An object is parked on`)}),o(_n,{devices:a,selection:`single`,noun:`camera`,value:t.deviceId>0?[t.deviceId]:[],testId:`stationary-present-camera`,onChange:e=>{let n=e[0];n!==void 0&&n!==t.deviceId&&l(n)}})]}),o(Ri,{subjects:t.subjects??[],optional:!0,classLabelsOnly:!0,verb:i(`automation.whenTree.isParked`,`is parked`),onChange:s}),e(`div`,{className:`flex items-center gap-2`,children:[o(vi,{children:i(`flow.scene.minCount`,`At least`)}),o(sn,{"aria-label":i(`flow.scene.minCountAria`,`Minimum parked objects`),"data-testid":`stationary-present-min-count`,className:`w-20`,value:t.minCount??1,onValue:e=>{let{minCount:n,...i}=t;r(e===null||e<=1?i:{...i,minCount:Math.floor(e)})}}),o(vi,{children:i(`flow.scene.minCountUnit`,`parked objects`)})]}),o(Si,{devices:n,deviceIds:t.deviceId>0?[t.deviceId]:[],selected:t.zones??[],onChange:c})]})}function Wi(e){return e.kind===`all`||e.kind===`any`}function Gi(e){return[`when`,...e].join(`.`)}function Ki(e){let t=e.when;return Wi(t)?t:{kind:`all`,children:[t]}}function qi(e,t){return{...e,when:t}}function Ji(e){return qi(e,Ki(e))}function Yi(e,t){let[n,...r]=t;if(n===void 0)return e;if(e.kind===`not`)return n===0?Yi(e.child,r):null;if(B(e))return null;let i=e.children[n];return i===void 0?null:Yi(i,r)}function Xi(e,t,n){let[r,...i]=t;if(r===void 0)return n(e);if(e.kind===`not`){if(r!==0)return e;let t=Xi(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(B(e))return e;let a=e.children[r];if(a===void 0)return e;let o=Xi(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 Zi(e,t,n){let r=Ki(e);return qi(e,Xi(r,t,n)??{kind:r.kind,children:[]})}function Qi(e){return{kind:e,children:[Sn(`device-is`)]}}function $i(e,t,n){return Zi(e,t,e=>Wi(e)?{kind:e.kind,children:[...e.children,n]}:e)}function ea(e,t,n){return Zi(e,t,()=>n)}function ta(e,t){return Zi(e,t,()=>null)}function na(e,t,n){return Zi(e,t,e=>Wi(e)?{kind:n,children:e.children}:e)}function ra(e,t){return t.length===0?e:Zi(e,t,e=>({kind:`not`,child:e}))}function ia(e,t){return Zi(e,t,e=>e.kind===`not`?e.child:e)}function aa(e,t){let n=Ki(e),r=Yi(n,t),i=t.slice(0,-1),a=t[t.length-1],o=Yi(n,i);return r===null||!Wi(r)||a===void 0||o===null||!Wi(o)?e:Zi(e,i,()=>({kind:o.kind,children:[...o.children.slice(0,a),...r.children,...o.children.slice(a+1)]}))}function oa(e,t){if(e.kind===t)return e;if(e.kind===`device-is`&&t===`device-becomes`){let{deviceId:n,cap:r,fieldPath:i,operator:a,value:o}=e,s={kind:t,deviceId:n,cap:r,fieldPath:i};return a===`eq`&&!Array.isArray(o)&&typeof o!=`object`?{...s,becomes:o}:s}if(e.kind===`device-becomes`&&t===`device-is`){let{deviceId:n,cap:r,fieldPath:i,becomes:a}=e;return{kind:t,deviceId:n,cap:r,fieldPath:i,operator:`eq`,value:a??``}}return Sn(t)}function sa(e){let t=Ki(e),n=t.children.length===0;return{depth:n?0:se(t),leaves:n?0:Se(t),depthLimit:4,leafLimit:32}}function ca(e,t){let n=Ki(e),r=1,i=n;for(let e of t){let t=Yi(i,[e]);if(t===null)break;r+=1,i=t}return r+2<=4}function la(e){let t=new Map,n=(e,r)=>{if(B(e))return!1;let i=e.kind===`not`?[e.child]:e.children,a=!1;if(i.forEach((e,t)=>{n(e,[...r,t])&&(a=!0)}),a)return!0;let o=ie(e);return o===null?!1:(t.set(Gi(r),o),!0)};return n(e,[]),t}function ua(){let{t:e}=Z(),t={detection:e(`flow.triggerHint.detection`,`An object class is detected on a camera`),stationary:e(`flow.triggerHint.stationary`,`An object stops, or leaves`),"device-becomes":e(`automation.whenTree.hint_device_becomes`,`A device value takes a value`),"device-event":e(`flow.triggerHint.deviceEvent`,`An event on the system`),schedule:e(`flow.triggerHint.schedule`,`At a time of day`),interval:e(`flow.triggerHint.interval`,`Again and again, every few minutes`),manual:e(`flow.triggerHint.manual`,`Only when you run it`),"device-is":e(`automation.whenTree.hint_device_is`,`A device value is, right now`),"stationary-present":e(`automation.whenTree.hint_stationary_present`,`An object is parked on a camera, right now`),expression:e(`automation.whenTree.hint_expression`,`Arithmetic across device values, right now`)},n=e(`automation.whenTree.groupEvents`,`Happens (an event)`),r=e(`automation.whenTree.groupStates`,`Is true (a state)`);return fn.map(e=>({value:e,label:pn(e),description:t[e],group:En.includes(e)?n:r}))}function da(e){return fn.find(t=>t===e)??null}function fa({leaf:t,devices:n,toneClass:r,result:i,onNegate:a,onChange:s,onRemove:c}){let{t:l}=Z(),u=ua(),d=ae(t);return e(`div`,{className:`rounded border p-2 ${r}`,"data-testid":`when-row`,"data-kind":t.kind,children:[e(`div`,{className:`flex flex-wrap items-end gap-2`,children:[e(`div`,{className:`min-w-[13rem] max-w-xs flex-1`,children:[o(Q,{children:l(`automation.whenTree.rowType`,`Row type`)}),o(zt,{mode:`single`,singleDisplay:`field`,options:u,value:t.kind,testId:`when-row-type`,optionTestIdPrefix:`when-kind`,onChange:e=>{let n=da(e);n!==null&&n!==t.kind&&s(oa(t,n))}})]}),o(K,{variant:d?`info`:`neutral`,"data-testid":`when-row-nature`,children:d?l(`automation.whenTree.natureEvent`,`Event`):l(`automation.whenTree.natureState`,`State`)}),o(`span`,{className:`flex-1`}),a!==null&&o(Y,{variant:`ghost`,onClick:a,title:l(`automation.whenTree.negateRow`,`Invert this row (NOT)`),children:`NOT`}),o(Y,{variant:`ghost`,onClick:c,title:l(`automation.whenTree.removeRow`,`Remove this row`),children:o(_,{className:`h-3.5 w-3.5`})})]}),o(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:o(pa,{leaf:t,devices:n,onChange:s})}),i!==void 0&&o(`div`,{className:`mt-2`,children:i})]})}function pa({leaf:e,devices:t,onChange:n}){switch(e.kind){case`device-becomes`:return o(ii,{leaf:e,devices:t,onChange:n});case`device-event`:return o(oi,{leaf:e,devices:t,onChange:n});case`schedule`:return o(ti,{leaf:e,onChange:n});case`interval`:return o(Hi,{leaf:e,onChange:n});case`manual`:return o(ni,{});case`detection`:return o(Bi,{leaf:e,devices:t,onChange:n});case`stationary`:return o(Vi,{leaf:e,devices:t,onChange:n});case`device-is`:return o(Qr,{leaf:e,devices:t,onChange:n});case`stationary-present`:return o(Ui,{leaf:e,devices:t,onChange:n});case`expression`:return o(ci,{leaf:e,devices:t,onChange:n})}}u();function ma(e){return e===`any`?`any`:`all`}function ha(e){return e===`pass`?`pass`:e===`fail`?`fail`:`idle`}function ga(e,t,n=!0){return e===void 0?t:n?Dn(ha(e)):An(ha(e))}function _a(e,t){return e.run?.nodes.get(Gi(t))}function va({recipe:t,devices:n,onChange:i,run:a=null}){let{t:s}=Z(),c=Ki(t),l=sa(t),u={recipe:t,devices:n,issues:r(()=>la(c),[c]),run:a,onChange:i},d=c.children.length===0;return e(`div`,{className:`space-y-2`,"data-testid":`when-tree`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:s(`automation.whenTree.rule`,`An event starts a run when it happens and everything here is true at that moment. With only states, a run starts when they become true.`)}),o(Ea,{block:c,path:[],ctx:u,underNot:!1,budgetText:s(`automation.whenTree.budget`,{depth:l.depth,depthLimit:l.depthLimit,leaves:l.leaves,leafLimit:l.leafLimit}),emptyHint:d?s(`automation.whenTree.empty`,`Add a row to say when this runs. Without one nothing can ever start this automation.`):null})]})}function ya({node:e,path:t,ctx:n,underNot:r}){return B(e)?o(ba,{leaf:e,path:t,ctx:n,underNot:r}):e.kind===`not`?o(Ta,{child:e.child,path:t,ctx:n}):o(Ea,{block:e,path:t,ctx:n,underNot:r,budgetText:null,emptyHint:null})}function ba({leaf:e,path:t,ctx:n,underNot:r}){let i=_a(n,t),a=n.run!==null&&n.run.triggerPath===Gi(t)?n.run.vars:void 0;return o(fa,{leaf:e,devices:n.devices,toneClass:ga(i?.outcome,`border-border`),result:i===void 0?void 0:o(xa,{leaf:e,node:i,vars:a}),onNegate:r?null:()=>n.onChange(ra(n.recipe,t)),onChange:e=>n.onChange(ea(n.recipe,t,e)),onRemove:()=>n.onChange(ta(n.recipe,t))})}function xa({leaf:e,node:t,vars:n}){return e.kind===`device-is`&&e.unit!==void 0?o(Sa,{leaf:e,node:t,vars:n}):o(dn,{node:t,vars:n,expected:t.expected,observed:t.observed})}function Sa({leaf:e,node:t,vars:n}){let r=Yr(xn({deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath})),i=r===void 0?void 0:L(r),a=t=>t===void 0?null:rn(t,i,e.unit);return o(dn,{node:t,vars:n,expected:a(t.rawExpected),observed:a(t.rawObserved)})}function Ca({node:e}){return e===void 0?null:o(dn,{node:e,expected:null,observed:null})}function wa({message:e}){return e===void 0?null:o(`p`,{role:`alert`,"data-testid":`when-issue`,className:`rounded border border-warning/40 bg-warning/10 p-2 text-xs text-warning`,children:e})}function Ta({child:t,path:n,ctx:r}){let{t:i}=Z();return e(`div`,{className:`space-y-1.5 rounded border p-2 ${ga(_a(r,n)?.outcome,`border-warning/40`,!1)}`,"data-testid":`when-not`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(K,{variant:`warning`,children:`NOT`}),o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`automation.whenTree.notHint`,`True when what is below is not`)}),o(`span`,{className:`flex-1`}),e(Y,{variant:`ghost`,onClick:()=>r.onChange(ia(r.recipe,n)),title:i(`automation.whenTree.removeNot`,`Remove the NOT, keeping what is inside`),children:[o(De,{className:`h-3.5 w-3.5`}),` `,i(`automation.whenTree.removeNotLabel`,`Remove NOT`)]})]}),o(wa,{message:r.issues.get(Gi(n))}),o(Ca,{node:_a(r,n)}),o(`div`,{className:`pl-3`,children:o(ya,{node:t,path:[...n,0],ctx:r,underNot:!0})})]})}function Ea({block:t,path:n,ctx:r,underNot:i,budgetText:a,emptyHint:s}){let{t:c}=Z(),l=n.length===0,u=ca(r.recipe,n),d=[{value:`all`,label:c(`automation.whenTree.allOf`,`All of (AND)`)},{value:`any`,label:c(`automation.whenTree.anyOf`,`Any of (OR)`)}],f=s===null?r.issues.get(Gi(n)):void 0;return e(`div`,{className:`space-y-2 rounded border p-2 ${ga(_a(r,n)?.outcome,`border-border`,!1)} bg-surface-subtle/40`,"data-testid":`when-block`,"data-kind":t.kind,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(`div`,{className:`w-40`,children:o(k,{"aria-label":c(`automation.whenTree.blockKind`,`How the rows below combine`),"data-testid":`when-block-kind`,value:t.kind,options:d,onChange:e=>r.onChange(na(r.recipe,n,ma(e.target.value)))})}),a!==null&&o(`span`,{className:`text-xs text-foreground-subtle`,children:a}),o(`span`,{className:`flex-1`}),!l&&!i&&o(Y,{variant:`ghost`,onClick:()=>r.onChange(ra(r.recipe,n)),title:c(`automation.whenTree.negateBlock`,`Invert this block (NOT)`),children:`NOT`}),!l&&o(Y,{variant:`ghost`,onClick:()=>r.onChange(aa(r.recipe,n)),title:c(`automation.whenTree.ungroup`,`Dissolve this block, keeping its rows`),children:o(De,{className:`h-3.5 w-3.5`})}),!l&&o(Y,{variant:`ghost`,onClick:()=>r.onChange(ta(r.recipe,n)),title:c(`automation.whenTree.removeBlock`,`Delete this block and everything in it`),children:o(_,{className:`h-3.5 w-3.5`})})]}),o(wa,{message:f}),o(Ca,{node:_a(r,n)}),s!==null&&o(`p`,{className:`text-xs text-warning`,children:s}),t.children.length>0&&o(`div`,{className:`space-y-1.5 border-l border-border pl-3`,children:t.children.map((e,t)=>o(ya,{node:e,path:[...n,t],ctx:r,underNot:!1},Gi([...n,t])))}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(Y,{variant:`outline`,onClick:()=>r.onChange($i(r.recipe,n,Sn(`device-is`))),title:c(`automation.whenTree.addRowTitle`,`Add one row: an event or a state`),children:[o(w,{className:`h-4 w-4`}),` `,c(`automation.whenTree.addRow`,`Add row`)]}),e(Y,{variant:`outline`,disabled:!u,onClick:()=>r.onChange($i(r.recipe,n,Qi(t.kind===`all`?`any`:`all`))),title:u?c(`automation.whenTree.addBlockTitle`,`Add a nested block of rows`):c(`automation.whenTree.tooDeep`,`The rules nest at most {{max}} levels deep`,{max:sa(r.recipe).depthLimit}),children:[o(w,{className:`h-4 w-4`}),` `,c(`automation.whenTree.addBlock`,`Add block`)]})]})]})}u();var Da=`hub`,Oa=5e3;function ka({existing:t,initialRecipe:n,saving:i,saveError:a,ejecting:s,onSave:l,onEject:u,onCancel:d}){let{t:f}=Z(),[p,m]=c(t?.name??``),[h,g]=c(()=>Ji(n)),[_,v]=c(!1),[y,b]=c(null),x=Mt({blockId:t?.id??`none`},{enabled:t!==null,refetchInterval:Oa}),C=x.data?.traces.find(e=>e.runId===y)??null,w=r(()=>C===null?null:cn(C),[C]),T=r(()=>Zn(h.when,f),[h.when,f]),E=r(()=>C===null?null:On(C),[C]),D=r(()=>C===null?null:kn(C).steps,[C]),O=wn(),k=ee(h),j=r(()=>Aa(h),[h]),M=r(()=>ja(p.trim()===``?`Untitled automation`:p.trim(),h),[p,h]),N=p.trim()===``,P=N||k!==null||j!==null||M.code===null;return e(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]`,"data-testid":`automation-editor`,children:[e(`div`,{className:`space-y-4`,children:[e(`label`,{className:`block max-w-md text-sm`,children:[o(`span`,{className:`text-foreground-subtle`,children:f(`automation.automationEditor.name`,`Name`)}),o(J,{className:`mt-1`,value:p,onChange:e=>m(e.target.value),placeholder:f(`automation.automationEditor.whatThisAutomationDoes`,`What this automation does`)})]}),o(ln,{step:`when`,title:f(`automation.automationEditor.when`,`When`),trace:w===null?null:w.when,children:o(va,{recipe:h,devices:O,run:E,onChange:g})}),o(ln,{step:`then`,title:f(`automation.automationEditor.then`,`Then`),trace:w===null?null:w.thenBlock,hint:f(`automation.automationEditor.inThisOrderStoppingAt`,`In this order, stopping at the first failure.`),children:o(Cn,{actions:h.actions,devices:O,variables:T,stepTones:w===null?void 0:h.actions.map((e,t)=>un(w,t)??`idle`),stepResults:D===null?void 0:h.actions.map((e,t)=>D.find(e=>e.index===t)),onChange:e=>g(hn(h,e))})}),o(ln,{step:`mode`,title:f(`flow.runMode.title`,`Overlap`),trace:null,hint:f(`flow.runMode.hint`,`What happens when a trigger arrives mid-run.`),children:o(Br,{value:Ir(h),onChange:e=>g(Lr(h,e))})}),o(Mr,{code:M.code,error:M.error,canEject:t!==null,ejecting:s,onEject:u}),k!==null&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:k}),k===null&&j!==null&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:j}),a!==null&&o(`p`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:a}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(Y,{onClick:()=>{M.code!==null&&l({name:p.trim(),code:M.code,enabled:t?.enabled??!0,placement:Da})},disabled:i||P,children:[i&&o(A,{className:`h-4 w-4 animate-spin`}),` `,f(`common.save`)]}),e(Y,{variant:`ghost`,onClick:()=>v(!_),disabled:t===null,title:t===null?f(`automation.automationEditor.logsAppearOnceTheAutomation`,`Logs appear once the automation has been saved and started`):f(`automation.automationEditor.showThisAutomationSProcess`,`Show this automation's process logs`),"data-testid":`automation-logs-toggle`,"aria-expanded":_,children:[o(S,{className:`h-4 w-4`}),` `,f(`common.logs`),` `,o(_t,{expanded:_})]}),o(Y,{variant:`ghost`,onClick:d,disabled:i,children:f(`common.close`,`Close`)}),N&&o(K,{variant:`warning`,children:f(`automation.automationEditor.nameRequired`,`Name required`)})]}),_&&t!==null&&e(`div`,{className:`rounded border border-border`,"data-testid":`automation-logs-panel`,children:[o(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:o(Jt,{i18nKey:`common.logsOf`,values:{id:I(t.id)},components:{code:o(`code`,{})}})}),o(ft,{addonId:I(t.id),maxHeight:`max-h-64`,showFilters:!1})]})]}),o(`div`,{className:`order-first lg:order-last`,children:o(mn,{traces:t===null?[]:x.data?.traces,selectedId:y,onSelect:b})})]})}function Aa(e){let t=R.safeParse(e);if(t.success)return null;let n=t.error.issues[0];return n===void 0?X.t(`helpers.automationEditor.incomplete`):`${n.path.length===0?``:`${n.path.join(`.`)}: `}${n.message}`}function ja(e,t){let n=Ur(t);if(!n.ok)return{code:null,error:n.error};try{return{code:ne({name:e,recipe:n.recipe}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function Ma(e){if(!e.enabled)return{tone:`idle`,label:X.t(`helpers.coreBlockStatus.disabled`),detail:X.t(`helpers.coreBlockStatus.disabledDetail`)};switch(e.status){case`running`:return{tone:`ok`,label:X.t(`helpers.coreBlockStatus.running`),detail:X.t(`helpers.coreBlockStatus.runningDetail`)};case`starting`:return{tone:`pending`,label:X.t(`helpers.coreBlockStatus.starting`),detail:e.lastError??X.t(`helpers.coreBlockStatus.startingDetail`)};case`failed`:return{tone:`error`,label:X.t(`helpers.coreBlockStatus.failed`),detail:e.lastError??X.t(`helpers.coreBlockStatus.failedDetail`)};default:return{tone:`error`,label:X.t(`helpers.coreBlockStatus.notRunning`),detail:e.lastError??X.t(`helpers.coreBlockStatus.notRunningDetail`)}}}function Na(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function Pa(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function Fa(e){let t=e=>{let t=Ma(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 Ia(e){if(e.length===0)return X.t(`helpers.coreBlockStatus.noBlocks`);let t=e.filter(e=>Ma(e).tone===`error`).length,n=e.filter(e=>Ma(e).tone===`ok`).length,r=[X.t(`helpers.coreBlockStatus.blocks`,{count:e.length})];return n>0&&r.push(X.t(`helpers.coreBlockStatus.runningCount`,{count:n})),t>0&&r.push(X.t(`helpers.coreBlockStatus.notRunningCount`,{count:t})),r.join(` · `)}var La=3e4;function Ra({block:t,logsOpen:n,unreadable:r}){let i=b(),{t:a}=Z(),s=Ma(t),c=At(t.updatedAt,i);return e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(`span`,{className:`truncate font-medium`,children:t.name}),o(K,{variant:Na(s.tone),children:s.label}),c!==null&&o(`span`,{className:`text-xs text-foreground-subtle`,children:a(`common.edited`,{when:c})})]}),(s.tone===`error`||s.tone===`pending`)&&o(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:s.detail}),r!==null&&o(`p`,{className:`mt-0.5 text-xs text-warning`,children:a(`automation.editor.listUnreadable`,{reason:r})}),n&&e(`div`,{className:`mt-2 rounded border border-border`,children:[o(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:o(Jt,{i18nKey:`common.logsOf`,values:{id:I(t.id)},components:{code:o(`code`,{})}})}),o(ft,{addonId:I(t.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}var za=2;function Ba(e){let t=[];if(P(e.when,e=>{ae(e)&&t.push(pn(e.kind))}),t.length===0)return Se(e.when)===0?``:X.t(`automation.whenTree.stateOnly`);let n=[...new Set(t)],r=n.slice(0,za).join(`, `),i=n.length-za;return i>0?`${r} +${i}`:r}function Va({recipe:e}){let{t}=Z();if(e===null)return o(`span`,{className:`text-foreground-subtle`,children:`-`});let n=Ba(e);return n===``?o(`span`,{className:`text-foreground-subtle`,children:t(`automation.automationList.noTrigger`,`No trigger`)}):o(`span`,{children:n})}function Ha({blockId:t}){let{t:n}=Z(),r=Mt({blockId:t},{refetchInterval:La});if(r.data===void 0)return r.error===null||r.error===void 0?o(ut,{className:`h-4 w-16`}):o(`span`,{className:`text-foreground-subtle`,children:n(`automation.automationList.lastRunUnknown`,`Unknown`)});let i=r.data.traces.findLast(e=>!e.outcome.startsWith(`skipped-`));if(i===void 0)return o(`span`,{className:`text-foreground-subtle`,children:n(`automation.automationList.neverRan`,`Never ran`)});let a=i.outcome===`failed`||i.outcome===`aborted`;return e(`span`,{className:`inline-flex items-center gap-2`,children:[nn(i.lastAt),a&&o(K,{variant:`danger`,children:n(`automation.automationList.lastRunFailed`,`Failed`)})]})}function Ua({block:e,disabled:t,onToggle:n}){let{t:r}=Z();return o(`span`,{className:`inline-flex`,onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:o(Ct,{checked:e.enabled,disabled:t,onCheckedChange:n,"aria-label":e.enabled?r(`automation.automationList.disableNamed`,`Disable {{name}}`,{name:e.name}):r(`automation.automationList.enableNamed`,`Enable {{name}}`,{name:e.name})})})}function Wa({unreadable:e,onEdit:t,onToggleLogs:n,onDelete:r}){let{t:i}=Z();return o(`span`,{className:`inline-flex justify-end`,onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:o(Je,{items:[{id:`edit`,label:i(`common.edit`,`Edit`),icon:T,disabled:e!==null,description:e===null?void 0:i(`automation.automationList.thisBlockCannotBeOpened`,`This block cannot be opened visually`),onClick:t},{id:`run`,label:i(`automation.automationList.runActions`,`Run actions`),icon:h,disabled:!0,description:i(`automation.automationList.runNotAvailable`,`Not available yet`),onClick:()=>void 0},{id:`logs`,label:i(`automation.automationList.logs`,`Logs`),icon:S,onClick:n},{id:`delete`,label:i(`common.delete`,`Delete`),icon:_,danger:!0,separatorBefore:!0,onClick:r}]})})}function Ga({onCreate:t}){let{t:n}=Z();return o(ct,{icon:x,title:n(`automation.automationList.noAutomationsYet`,`No automations yet.`),action:e(Y,{onClick:t,"data-testid":`automation-empty-new`,children:[o(w,{className:`h-4 w-4`}),` `,n(`automation.automationList.newAutomation`,`New automation`)]})})}u();var Ka=[`coreBlocks`,`list`],qa=5e3;function Ja(e){return e instanceof Error?e.message:String(e)}function Ya({onOpenScripts:t,createRequested:n=!1,onCreateConsumed:i}){let{t:a}=Z(),u=D(),{state:d,openNew:p,openEdit:m,close:h}=Rt({editKey:`block`,newKey:`new`}),g=E(),[_,v]=c(null),y=d.mode!==`closed`;s(()=>{n&&(p(),i?.())},[n,i,p]);let b=l({queryKey:Ka,refetchInterval:qa,queryFn:async()=>(await u.trpcClient.coreBlocks.list.query({})).blocks}),S=()=>{b.refetch()},C=e=>{h(),S(),$t({title:a(`build.automationsTab.saved`,`Automation saved`),message:e.name,severity:`info`})},w=f({mutationFn:e=>u.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>C(e.block)}),T=f({mutationFn:e=>u.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>C(e.block)}),O=f({mutationFn:e=>u.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:S}),k=f({mutationFn:e=>u.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:S}),A=f({mutationFn:e=>u.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:Yn(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:e=>{h(),S(),t(e.block.id)}}),j=b.data,M=Fa((j??[]).filter(e=>Kn(e.code))),N=j!==void 0&&M.length===0,P=d.mode===`edit`?M.find(e=>e.id===d.id)??null:null,F=d.mode===`edit`&&j!==void 0&&P===null;s(()=>{F&&h()},[F,h]);let I=P===null?null:Jn(P.code),L=w.error===null?T.error===null?A.error===null?null:Ja(A.error):Ja(T.error):Ja(w.error),R=r(()=>[{key:`name`,header:a(`build.automationsTab.automation`,`Automation`),nowrap:!1,render:e=>{let t=Jn(e.code);return o(Ra,{block:e,logsOpen:_===e.id,unreadable:t.ok?null:t.reason})},sortValue:e=>e.name},{key:`trigger`,header:a(`build.automationsTab.trigger`,`Trigger`),render:e=>{let t=Jn(e.code);return o(Va,{recipe:t.ok?t.recipe:null})},notSortableReason:a(`build.automationsTab.triggerNotSortable`,`Read from the recipe`)},{key:`lastRun`,header:a(`build.automationsTab.lastRun`,`Last run`),render:e=>o(Ha,{blockId:e.id}),notSortableReason:a(`build.automationsTab.lastRunNotSortable`,`Read per automation`)},{key:`enabled`,header:a(`build.automationsTab.enabled`,`Enabled`),render:e=>o(Ua,{block:e,disabled:k.isPending,onToggle:t=>k.mutate({blockId:e.id,enabled:t})}),sortValue:e=>+!!e.enabled},{key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,render:e=>{let t=Jn(e.code);return o(Wa,{unreadable:t.ok?null:t.reason,onEdit:()=>m(e.id),onToggleLogs:()=>v(_===e.id?null:e.id),onDelete:()=>{g({title:a(`automation.automationList.deleteThisAutomation`,`Delete this automation?`),message:a(`automation.automationList.deleteMessage`,`{{name}} will be deleted. This cannot be undone.`,{name:e.name}),confirmLabel:a(`common.delete`,`Delete`),variant:`danger`}).then(t=>{t&&O.mutate(e.id)})}})}}],[g,_,m,O,k,a]);return y?d.mode===`edit`&&P===null?o(ut,{className:`h-24 w-full`}):e(`div`,{className:`space-y-3`,"data-testid":`automation-editor-panel`,children:[e(`h3`,{className:`flex items-center gap-2 text-sm font-semibold`,children:[o(x,{className:`h-4 w-4 text-foreground-muted`}),P===null?a(`build.automationsTab.newAutomation`,`New automation`):a(`build.automationsTab.edit`,`Edit {{name}}`,{name:P.name})]}),o(ka,{existing:P,initialRecipe:I!==null&&I.ok?I.recipe:vn,saving:w.isPending||T.isPending,saveError:L,ejecting:A.isPending,onSave:e=>{P===null?w.mutate(e):T.mutate({blockId:P.id,block:e})},onEject:()=>{P!==null&&A.mutate(P)},onCancel:()=>{w.reset(),T.reset(),A.reset(),h()}},P?.id??`new`),O.error!=null&&o(q,{message:Ja(O.error)})]}):e(`div`,{className:`space-y-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:j===void 0?``:Ia(M)}),b.error!=null&&o(q,{title:a(`build.automationsTab.couldNotReadTheAutomations`,`Could not read the automations`),message:Ja(b.error),onRetry:S}),N?o(Ga,{onCreate:p}):o(Qe,{columns:R,rows:M,rowKey:e=>e.id,pageSize:25,maxBodyHeight:Ht,emptyMessage:j===void 0?a(`build.automationsTab.loadingAutomations`,`Loading automations…`):a(`build.automationsTab.noAutomationsYet`,`No automations yet.`),onRowClick:e=>m(e.id)}),O.error!=null&&o(q,{message:Ja(O.error)}),k.error!=null&&o(q,{message:Ja(k.error)})]})}var Xa={kind:`all`,children:[]};function Za({value:t,devices:n,label:r,onChange:i}){let{t:a}=Z(),s=t===void 0?null:{when:t,actions:[]};return e(`div`,{className:`space-y-2`,children:[o(Ct,{checked:t!==void 0,label:r,"aria-label":r,onCheckedChange:e=>i(e?Xa:void 0)}),s!==null&&e(p,{children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:a(`schedulers.activeWhen.hint`,`Only states count here, such as "someone is home". While they are false, nothing runs and holds pause.`)}),o(va,{recipe:s,devices:n,onChange:e=>i(e.when)})]})]})}var Qa=[`mon`,`tue`,`wed`,`thu`,`fri`,`sat`,`sun`],$a=720,eo=1440;function to(){return{name:``,enabled:!0,priority:0,maxLateMs:M,profiles:[no(`profile-1`,`Every day`)]}}function no(e,t){return{id:e,name:t,enabled:!0,days:[...Qa],points:[]}}function ro(e,t,n){return{id:t,at:{kind:`clock`,hh:Math.floor(n/60),mm:n%60},mode:e,steps:[]}}function io(e,t){let n=t.length+1;for(;t.includes(`${e}-${String(n)}`);)n+=1;return`${e}-${String(n)}`}function ao(e){return e.location===null?null:{lat:e.location.latitude,lon:e.location.longitude,timeZone:e.timeZone}}function oo(e,t){let n=new Intl.DateTimeFormat(`en-US`,{timeZone:t,hourCycle:`h23`,hour:`2-digit`,minute:`2-digit`}).formatToParts(new Date(e)),r=e=>Number(n.find(t=>t.type===e)?.value??0);return r(`hour`)*60+r(`minute`)}function so(e,t=Date.now()){return z(t,e.timeZone)}function co(e,t,n){let r=ao(t);if(r===null)return e.kind===`clock`?e.hh*60+e.mm:null;let i=H(e,n,r);return i===null?null:oo(i,t.timeZone)}function lo(e,t,n){return e.kind===`sun`?co({...e,offsetMin:0},t,n):null}function uo(e,t,n){if(e.kind===`clock`)return{kind:`clock`,hh:Math.floor(t/60),mm:t%60};if(e.kind===`sun`&&n!==null){let r=Math.max(-720,Math.min($a,t-n));return{...e,offsetMin:r}}return e}function fo(e){let t=/^([01]\d|2[0-3]):([0-5]\d)$/.exec(e);return t===null?null:{kind:`clock`,hh:Number(t[1]),mm:Number(t[2])}}function po(e,t){return`${String(e).padStart(2,`0`)}:${String(t).padStart(2,`0`)}`}function mo(e){return po(Math.floor(e/60),e%60)}function ho(e,t,n){let r=e.flatMap(e=>{let r=co(e.at,t,n);return r===null?[]:[{point:e,minute:r}]}).toSorted((e,t)=>e.minute-t.minute);return r.flatMap((e,t)=>{if(e.point.mode!==`hold`)return[];let n=r[t+1];return[{id:e.point.id,fromMinute:e.minute,toMinute:n===void 0?eo:n.minute}]})}function go(e,t){let n=pe.safeParse(e);if(!n.success)return{ok:!1,issues:n.error.issues.map(e=>({path:e.path.join(`.`),message:e.message}))};let r=te(n.data,t);return r.ok?{ok:!0,input:n.data}:{ok:!1,issues:r.issues}}var _o=[`sunrise`,`sunset`,`dawn`,`dusk`],vo=6e4;function yo(e){return e.kind===`cap`||e.kind===`wait`}function bo(e,t){let n={id:e.id,at:e.at,mode:t,steps:t===`release`?[]:e.steps,...e.conditions===void 0?{}:{conditions:e.conditions}};return t===`hold`?{...n,...e.override===void 0?{}:{override:e.override},...e.maxHoldAttempts===void 0?{}:{maxHoldAttempts:e.maxHoldAttempts}}:n}function xo({point:t,devices:n,site:r,localDate:i,issues:a,onChange:s,onRemove:c}){let{t:l}=Z(),u=t.at,d=u.kind===`sun`?co(u,r,i):null,f=lo(u,r,i),m=t.override??{mode:`respect`},h=e=>s({...t,at:e});return e(`div`,{className:`space-y-3`,"data-testid":`point-editor`,children:[e(`div`,{className:`flex flex-wrap items-end gap-3`,children:[e(`label`,{className:`space-y-1 text-xs text-foreground-muted`,children:[o(`span`,{children:l(`schedulers.point.kind`,`Point type`)}),o(k,{"aria-label":l(`schedulers.point.kind`,`Point type`),value:t.mode,options:[{value:`edge`,label:l(`schedulers.point.edge`,`Edge: run once`)},{value:`hold`,label:l(`schedulers.point.hold`,`Hold: keep true`)},{value:`release`,label:l(`schedulers.point.release`,`Release: end the hold`)}],onChange:e=>{let n=e.target.value;(n===`edge`||n===`hold`||n===`release`)&&s(bo(t,n))}})]}),e(`label`,{className:`space-y-1 text-xs text-foreground-muted`,children:[o(`span`,{children:l(`schedulers.point.when`,`When`)}),o(k,{"aria-label":l(`schedulers.point.when`,`When`),value:u.kind===`sun`?`sun`:`clock`,options:[{value:`clock`,label:l(`schedulers.point.clock`,`At a time`)},{value:`sun`,label:l(`schedulers.point.sun`,`At a sun event`)}],onChange:e=>{e.target.value===`sun`?h({kind:`sun`,event:`sunset`,offsetMin:0}):h({kind:`clock`,hh:12,mm:0})}})]}),u.kind===`clock`&&e(`label`,{className:`space-y-1 text-xs text-foreground-muted`,children:[o(`span`,{children:l(`schedulers.point.time`,`Time`)}),o(J,{type:`time`,"aria-label":l(`schedulers.point.time`,`Time`),value:po(u.hh,u.mm),onChange:e=>{let t=fo(e.target.value);t!==null&&h(t)}})]}),u.kind===`sun`&&e(p,{children:[e(`label`,{className:`space-y-1 text-xs text-foreground-muted`,children:[o(`span`,{children:l(`schedulers.point.sunEvent`,`Sun event`)}),o(k,{"aria-label":l(`schedulers.point.sunEvent`,`Sun event`),value:u.event,options:_o.map(e=>({value:e,label:l(`schedulers.sun.${e}`,e)})),onChange:e=>{let t=_o.find(t=>t===e.target.value);t!==void 0&&h({...u,event:t})}})]}),e(`label`,{className:`space-y-1 text-xs text-foreground-muted`,children:[o(`span`,{children:l(`schedulers.point.offset`,`Offset (minutes, negative = before)`)}),o(sn,{"aria-label":l(`schedulers.point.offset`,`Offset (minutes, negative = before)`),className:`w-28`,value:u.offsetMin,onValue:e=>{e!==null&&h({...u,offsetMin:Math.round(e)})}})]}),o(`p`,{className:`pb-2 text-xs text-foreground-muted`,"data-testid":`sun-computed`,children:d===null||f===null?l(`schedulers.point.sunUnknown`,`No time today: the site location is not set.`):l(`schedulers.point.sunComputed`,`Today at {{time}} ({{zone}})`,{time:mo(d),zone:r.timeZone})})]}),e(Y,{variant:`ghost`,className:`ml-auto`,onClick:c,"aria-label":l(`schedulers.point.remove`,`Remove point`),children:[o(_,{className:`h-4 w-4`}),` `,l(`schedulers.point.remove`,`Remove point`)]})]}),t.mode!==`release`&&o(Cn,{actions:t.steps,devices:n,allowedKinds:[`cap`,`wait`],onChange:e=>s({...t,steps:e.filter(yo)})}),t.mode===`release`&&o(`p`,{className:`text-xs text-foreground-subtle`,children:l(`schedulers.point.releaseHint`,`A release ends the running hold without doing anything to the devices.`)}),t.mode===`hold`&&e(`div`,{className:`flex flex-wrap items-end gap-3`,children:[e(`label`,{className:`space-y-1 text-xs text-foreground-muted`,children:[o(`span`,{children:l(`schedulers.point.override`,`If someone changes it by hand`)}),o(k,{"aria-label":l(`schedulers.point.override`,`If someone changes it by hand`),value:m.mode,options:[{value:`respect`,label:l(`schedulers.point.respect`,`Leave it alone`)},{value:`reassert`,label:l(`schedulers.point.reassert`,`Put the hold back after a while`)}],onChange:e=>s({...t,override:e.target.value===`reassert`?{mode:`reassert`,graceMs:10*vo}:{mode:`respect`}})})]}),m.mode===`reassert`&&e(`label`,{className:`space-y-1 text-xs text-foreground-muted`,children:[o(`span`,{children:l(`schedulers.point.grace`,`Wait (minutes)`)}),o(sn,{"aria-label":l(`schedulers.point.grace`,`Wait (minutes)`),className:`w-24`,value:m.graceMs/vo,onValue:e=>{e!==null&&s({...t,override:{mode:`reassert`,graceMs:Math.max(0,Math.round(e*vo))}})}})]})]}),a.length>0&&o(`ul`,{className:`space-y-1 rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:a.map(e=>o(`li`,{children:e.message},`${e.path}:${e.message}`))})]})}u();var So=5e3,Co=600,wo=6e4,To={timeZone:`UTC`,location:null};function Eo(e){return e instanceof Error?e.message:String(e)}function Do(e){if(e===null)return to();let{id:t,createdAt:n,updatedAt:r,...i}=e;return i}function Oo(e,t){let[n,r]=c(e);return s(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n}function ko(e,t){return t(`schedulers.day.${e}`,e)}function Ao({entry:t,onClose:n,onSaved:i}){let{t:a}=Z(),s=d(),l=E(),u=wn(),f=Lt(),p=f.data??To,[m,h]=c(()=>Do(t)),[g,v]=c(()=>m.profiles[0]?.id??``),[y,b]=c(null),[x,S]=c(null),C=()=>{s.invalidateQueries({queryKey:[[`schedulers`]]})},T=et({onSuccess:e=>{C(),i(e.scheduler.id)}}),D=st({onSuccess:C}),O=Wt({onSuccess:()=>{C(),n()}}),k=ot({schedulerId:t?.id??`none`},{enabled:t!==null,refetchInterval:So}),j=r(()=>go(m,p),[m,p]),M=m.profiles.some(e=>e.points.some(e=>e.mode===`hold`)),N=Oo(j.ok?j.input:null,Co),P=Ge(N===null?{scheduler:m}:t===null?{scheduler:N}:{scheduler:N,schedulerId:t.id},{enabled:N!==null&&M&&f.data!==void 0}),F=m.profiles.find(e=>e.id===g)??m.profiles[0],I=F===void 0?-1:m.profiles.indexOf(F),L=so(p),R=F?.points.find(e=>e.id===y)??null,z=F===void 0||R===null?-1:F.points.indexOf(R),B=j.ok?[]:j.issues,V=e=>B.filter(t=>t.path===e||t.path.startsWith(`${e}.`)),H=e=>h({...m,profiles:m.profiles.map((t,n)=>n===I?e:t)}),ee=e=>{F!==void 0&&H({...F,points:F.points.map(t=>t.id===e.id?e:t)})},te=r(()=>F===void 0?[]:F.points.flatMap(e=>{let t=co(e.at,p,L);if(t===null)return[];let n=e.at.kind===`sun`?`${a(`schedulers.sun.${e.at.event}`,e.at.event)} ${e.at.offsetMin>=0?`+`:``}${String(e.at.offsetMin)} (${mo(t)})`:po(e.at.hh,e.at.mm);return[{id:e.id,minute:t,label:n,tone:e.mode===`hold`?`success`:e.mode===`release`?`neutral`:`primary`,draggable:e.at.kind===`clock`||e.at.kind===`sun`&&lo(e.at,p,L)!==null}]}),[F,p,L,a]),ne=r(()=>F===void 0?[]:ho(F.points,p,L),[F,p,L]),re=(e,t)=>{let n=F?.points.find(t=>t.id===e);n!==void 0&&ee({...n,at:uo(n.at,t,lo(n.at,p,L))})},U=e=>{if(F===void 0)return;let t=io(`point`,m.profiles.flatMap(e=>e.points.map(e=>e.id)));H({...F,points:[...F.points,ro(e,t,720)]}),b(t)},ie=()=>{let e=io(`profile`,m.profiles.map(e=>e.id));h({...m,profiles:[...m.profiles,no(e,a(`schedulers.profile.newName`,`New profile`))]}),v(e),b(null)},ae=T.isPending||D.isPending,oe=T.error??D.error??O.error;return e(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]`,"data-testid":`scheduler-editor`,children:[e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(Te,{className:`h-4 w-4 text-foreground-muted`}),o(J,{"aria-label":a(`schedulers.editor.name`,`Name`),className:`max-w-xs flex-1`,value:m.name,placeholder:a(`schedulers.editor.namePlaceholder`,`What this scheduler does`),onChange:e=>h({...m,name:e.target.value})})]}),e(Be,{headingId:`scheduler-settings`,title:a(`schedulers.editor.settings`,`Settings`),children:[e(`div`,{className:`divide-y divide-border px-3`,children:[o(Ue,{label:a(`schedulers.editor.enabled`,`Enabled`),children:o(Ct,{checked:m.enabled,"aria-label":a(`schedulers.editor.enabled`,`Enabled`),onCheckedChange:e=>h({...m,enabled:e})})}),o(Ue,{label:a(`schedulers.editor.priority`,`Priority (higher wins a conflict)`),children:o(sn,{"aria-label":a(`schedulers.editor.priority`,`Priority (higher wins a conflict)`),className:`w-24`,value:m.priority,onValue:e=>{e!==null&&h({...m,priority:Math.round(e)})}})}),o(Ue,{label:a(`schedulers.editor.maxLate`,`Run a missed point up to (minutes late)`),children:o(sn,{"aria-label":a(`schedulers.editor.maxLate`,`Run a missed point up to (minutes late)`),className:`w-24`,value:m.maxLateMs/wo,onValue:e=>{e!==null&&h({...m,maxLateMs:Math.round(e*wo)})}})})]}),e(`div`,{className:`p-3`,children:[o(Za,{value:m.activeWhen,devices:u,label:a(`schedulers.editor.activeWhen`,`Only when a condition holds`),onChange:e=>{let{activeWhen:t,...n}=m;h(e===void 0?n:{...n,activeWhen:e})}}),V(`activeWhen`).map(e=>o(`p`,{className:`mt-1 text-xs text-warning`,children:e.message},e.message))]})]}),o(Be,{headingId:`scheduler-profiles`,title:a(`schedulers.editor.profiles`,`Profiles`),actions:e(Y,{variant:`outline`,size:`sm`,onClick:ie,children:[o(w,{className:`h-4 w-4`}),` `,a(`schedulers.profile.add`,`Add profile`)]}),children:e(`div`,{className:`space-y-3 p-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:a(`schedulers.profile.hint`,`Each day, the first profile in this order whose days and condition hold is the one that runs.`)}),F!==void 0&&e(yt,{value:F.id,onValueChange:e=>{v(e),b(null)},appearance:`pills`,children:[o(kt,{children:m.profiles.map(e=>o(Nt,{value:e.id,children:e.name},e.id))}),e(It,{value:F.id,className:`space-y-3 pt-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(J,{"aria-label":a(`schedulers.profile.name`,`Profile name`),className:`max-w-xs`,value:F.name,onChange:e=>H({...F,name:e.target.value})}),o(Ct,{checked:F.enabled,label:a(`schedulers.profile.enabled`,`Enabled`),onCheckedChange:e=>H({...F,enabled:e})}),m.profiles.length>1&&e(Y,{variant:`ghost`,size:`sm`,onClick:()=>{h({...m,profiles:m.profiles.filter(e=>e.id!==F.id)}),v(``),b(null)},children:[o(_,{className:`h-4 w-4`}),` `,a(`schedulers.profile.remove`,`Remove profile`)]})]}),o(`div`,{className:`flex flex-wrap gap-1`,role:`group`,"aria-label":a(`schedulers.profile.days`,`Days`),children:Qa.map(e=>{let t=F.days.includes(e);return o(Y,{size:`sm`,variant:t?`primary`:`outline`,"aria-pressed":t,onClick:()=>H({...F,days:t?F.days.filter(t=>t!==e):Qa.filter(t=>t===e||F.days.includes(t))}),children:ko(e,a)},e)})}),V(`profiles.${String(I)}.days`).map(e=>o(`p`,{className:`text-xs text-warning`,children:a(`schedulers.profile.daysNeeded`,`Pick at least one day.`)},e.message)),o(Za,{value:F.activeWhen,devices:u,label:a(`schedulers.profile.activeWhen`,`This profile only when a condition holds`),onChange:e=>{let{activeWhen:t,...n}=F;H(e===void 0?n:{...n,activeWhen:e})}}),o(dt,{ariaLabel:a(`schedulers.timeline.label`,`Day timeline`),markers:te,bands:ne,selectedId:y,onSelect:b,onMove:re}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(Y,{variant:`outline`,size:`sm`,onClick:()=>U(`edge`),children:[o(w,{className:`h-4 w-4`}),` `,a(`schedulers.point.addEdge`,`Edge`)]}),e(Y,{variant:`outline`,size:`sm`,onClick:()=>U(`hold`),children:[o(w,{className:`h-4 w-4`}),` `,a(`schedulers.point.addHold`,`Hold`)]}),e(Y,{variant:`outline`,size:`sm`,onClick:()=>U(`release`),children:[o(w,{className:`h-4 w-4`}),` `,a(`schedulers.point.addRelease`,`Release`)]}),o(K,{variant:`neutral`,children:p.timeZone})]}),F.points.length===0&&o(`p`,{className:`text-xs text-foreground-subtle`,children:a(`schedulers.timeline.empty`,`Add a point to place something on the day.`)}),R!==null&&o(xo,{point:R,devices:u,site:p,localDate:L,issues:V(`profiles.${String(I)}.points.${String(z)}`),onChange:ee,onRemove:()=>{H({...F,points:F.points.filter(e=>e.id!==R.id)}),b(null)}},R.id)]})]})]})}),P.data!==void 0&&P.data.conflicts.length>0&&o(`ul`,{className:`space-y-1 rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:P.data.conflicts.map(e=>o(`li`,{children:a(`schedulers.conflict.message`,`{{other}} wants device {{device}} in another state from {{from}} to {{to}} ({{winner}}).`,{other:e.other.schedulerName,device:e.deviceId,from:mo(e.fromMinute),to:mo(e.toMinute),winner:e.winner===`mine`?a(`schedulers.conflict.mine`,`this one wins`):e.winner===`other`?a(`schedulers.conflict.other`,`the other one wins`):a(`schedulers.conflict.tie`,`the one that started first wins`)})},`${e.other.schedulerId}:${e.other.pointId}:${e.mine.pointId}:${String(e.deviceId)}`))}),!j.ok&&m.name!==``&&B.length>0&&R===null&&o(`ul`,{className:`space-y-1 rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:B.map(e=>o(`li`,{children:e.message},`${e.path}:${e.message}`))}),oe!==null&&o(q,{message:Eo(oe)}),e(`div`,{className:`flex flex-wrap gap-2`,children:[e(Y,{onClick:()=>{j.ok&&(t===null?T.mutate({scheduler:j.input}):D.mutate({schedulerId:t.id,scheduler:j.input}))},disabled:ae||!j.ok||f.data===void 0,children:[ae&&o(A,{className:`h-4 w-4 animate-spin`}),` `,a(`common.save`,`Save`)]}),t!==null&&e(Y,{variant:`ghost`,disabled:O.isPending,onClick:()=>{l({title:a(`schedulers.editor.deleteTitle`,`Delete this scheduler?`),message:a(`schedulers.editor.deleteMessage`,`{{name}} will be deleted and any hold it keeps will stop.`,{name:t.name}),confirmLabel:a(`common.delete`,`Delete`),variant:`danger`}).then(e=>{e&&O.mutate({schedulerId:t.id})})},children:[o(_,{className:`h-4 w-4`}),` `,a(`common.delete`,`Delete`)]}),o(Y,{variant:`ghost`,onClick:n,children:a(`common.close`,`Close`)})]})]}),o(`div`,{className:`order-first lg:order-last`,children:o(mn,{traces:t===null?[]:k.data?.traces,selectedId:x,onSelect:S})})]})}u();var jo=5e3;function Mo(e){return e instanceof Error?e.message:String(e)}function No({createRequested:t=!1,onCreateConsumed:n}){let{t:i}=Z(),a=d(),{state:c,openNew:l,openEdit:u,close:f}=Rt({editKey:`scheduler`,newKey:`new`}),p=Re({},{refetchInterval:jo}),m=Ne({},{refetchInterval:jo}),h=rt({onSuccess:()=>void a.invalidateQueries({queryKey:[[`schedulers`]]})});s(()=>{t&&(l(),n?.())},[t,n,l]);let g=p.data??[],_=c.mode===`edit`?g.find(e=>e.id===c.id)??null:null,v=e=>{if(!e.enabled)return{variant:`neutral`,label:i(`schedulers.status.off`,`Off`)};let t=m.data?.find(t=>t.schedulerId===e.id);return t===void 0?{variant:`neutral`,label:`-`}:t.hold===null?{variant:`neutral`,label:i(`schedulers.status.idle`,`Idle`)}:t.hold.suspendedInactive?{variant:`warning`,label:i(`schedulers.status.paused`,`Paused`)}:t.hold.targets.some(e=>e.status===`gave-up`)?{variant:`danger`,label:i(`schedulers.status.gaveUp`,`Gave up`)}:{variant:`success`,label:i(`schedulers.status.holding`,`Holding`)}},y=r(()=>[{key:`name`,header:i(`schedulers.list.name`,`Name`),render:e=>o(`span`,{className:`font-medium`,children:e.name}),sortValue:e=>e.name},{key:`enabled`,header:i(`schedulers.list.enabled`,`Enabled`),render:e=>o(`span`,{onClick:e=>e.stopPropagation(),children:o(Ct,{checked:e.enabled,disabled:h.isPending,"aria-label":i(`schedulers.list.enabledAria`,`Enable {{name}}`,{name:e.name}),onCheckedChange:t=>h.mutate({schedulerId:e.id,enabled:t})})}),sortValue:e=>Number(e.enabled)},{key:`profiles`,header:i(`schedulers.list.profiles`,`Profiles`),render:e=>String(e.profiles.length),sortValue:e=>e.profiles.length},{key:`priority`,header:i(`schedulers.list.priority`,`Priority`),render:e=>String(e.priority),sortValue:e=>e.priority},{key:`status`,header:i(`schedulers.list.status`,`Now`),render:e=>{let t=v(e);return o(K,{variant:t.variant,children:t.label})},notSortableReason:i(`schedulers.list.statusNotSortable`,`Derived from the live hold`)},{key:`updated`,header:i(`schedulers.list.updated`,`Updated`),render:e=>nn(e.updatedAt),sortValue:e=>e.updatedAt}],[h,m.data,i]);return c.mode===`closed`?e(`div`,{className:`space-y-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:i(`schedulers.list.hint`,`A scheduler does things over the day: run something at a time or at sunset, or keep a device in a state for a stretch of time.`)}),h.error!=null&&o(q,{message:Mo(h.error)}),p.data===void 0?p.error==null?o(ut,{className:`h-24 w-full`}):o(q,{title:i(`schedulers.list.couldNotRead`,`Could not read the schedulers`),message:Mo(p.error),onRetry:()=>void p.refetch()}):g.length===0?o(ct,{icon:Te,title:i(`schedulers.list.emptyTitle`,`No schedulers yet`),description:i(`schedulers.list.emptyDescription`,`A scheduler turns the garden lights on at sunset and off at 23:00, every day or only on some days.`),action:e(Y,{onClick:l,children:[o(w,{className:`h-4 w-4`}),` `,i(`schedulers.list.new`,`New scheduler`)]})}):o(Qe,{columns:y,rows:g,rowKey:e=>e.id,pageSize:25,maxBodyHeight:Ht,emptyMessage:i(`schedulers.list.emptyTitle`,`No schedulers yet`),onRowClick:e=>u(e.id)})]}):o(Ao,{entry:_,onClose:f,onSaved:u},_?.id??`new`)}async function Po(e,t){let n=`${fe}${e}`;return(await t())?.find(e=>e.stableId===n)?.id??null}var Fo=10,Io=400;async function Lo(e,t,n=Io){for(let r=0;r<Fo;r+=1){let r=await Po(e,t);if(r!==null)return r;await new Promise(e=>setTimeout(e,n))}return null}var Ro=`media-player`;function zo(e){return e===W.MediaPlayer?`media-source`:e===W.Heater?`control-source`:`none`}function Bo(e){return e===W.Heater?ge():e===W.MediaPlayer?{fieldChoice:`operator`,purpose:`member`,multiple:!1,max:1,deviceTypes:[W.MediaPlayer],accept:[{cap:Ro,fieldPath:`state`,valueKind:`state`}],history:{required:!1,minRetentionMs:null},mustBindCaps:[Ro],exclude:[]}:null}function Vo(e,t){return e!==W.Heater||t!==null&&t.cap===`switch`}var Ho={kind:`expression`,expr:`now`,bindings:{}};function Uo(e){return{kind:`fields`,cap:`switch`,fields:{on:{kind:`from`,source:e.source,cap:e.cap,fieldPath:e.fieldPath},lastChangedAt:Ho},commands:{setState:{kind:`forward`,source:e.source,cap:`switch`,method:`setState`}}}}function Wo(e){return e===null||e.cap!==`media-player`?[]:[{kind:`fields`,cap:Ro,fields:{},commands:Object.fromEntries(Object.keys(ce()).map(t=>[t,{kind:`forward`,source:e.source,cap:Ro,method:t}]))}]}function Go(e,t){if(!Vo(e,t))return null;let n=e===W.Heater&&t!==null?[Uo(t)]:e===W.MediaPlayer?Wo(t):[];return{target:{kind:`new`,type:e},features:n}}u();function Ko({onTitle:t}){let{t:n}=Z(),r=b(),i=Yt(),a=Tn(),l=Dt(),u=Ze({addonId:`composer`}),[d,f]=c(W.Sensor),[p,m]=c(``),[h,g]=c([]),[_,v]=c(null),y=h[0]??null,x=Bo(d),S=Go(d,y);s(()=>{t(n(`helper.newDevice`))},[t,n]);let C=async()=>{if(S!==null){v(null);try{let e=p.trim(),{block:t}=await a.mutateAsync({block:{...e===``?{}:{name:e},enabled:!0,composition:S}}),r=await Lo(t.id,async()=>(await u.refetch()).data??u.data);if(r===null){v(n(`helper.devicePending`));return}e!==``&&await l.mutateAsync({deviceId:r,name:e}),i(Qt(r),{replace:!0})}catch(e){v(e instanceof Error?e.message:String(e))}}};return e(`div`,{className:`flex flex-col gap-3`,"data-testid":`device-create-form`,children:[e(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[n(`compositionEditor.targetType`),o(k,{value:d,onChange:e=>{let t=Object.values(W).find(t=>t===e.target.value);t!==void 0&&(f(t),g([]))},options:Object.values(W).map(e=>({value:e,label:Pe(e,r).label}))})]}),e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[n(`compositionEditor.name`),o(J,{"aria-label":n(`compositionEditor.name`),value:p,onChange:e=>m(e.target.value)})]})]}),x!==null&&e(`div`,{className:`flex flex-col gap-1`,"data-testid":`device-create-source`,children:[o(`p`,{className:`text-[11px] text-foreground-muted`,children:n(`helper.deviceSource.${zo(d)}`)}),o(Nn,{kind:`members`,request:x,enabled:!0,members:h,onMembersChange:g,onRefuse:()=>void 0})]}),_!==null&&o(`p`,{role:`alert`,className:`text-xs text-danger`,children:_}),o(Y,{disabled:!Vo(d,y)||a.isPending,onClick:()=>void C(),children:n(`compositionEditor.save`)})]})}u();function qo({preset:t,saving:n,onSave:i,onBack:a}){let{t:s,i18n:l}=Z(),u=zn(!0),[d,f]=c({}),[p,m]=c(s(t.nameKey)),[h,g]=c(null),[_,v]=c([]),[y,b]=c(!1),x=r(()=>u.kind===`known`?new Map(u.value.map(e=>[de({addonId:e.addonId,stableId:e.stableId}),e.name])):new Map,[u]),S=r(()=>new Set(Object.values(d).flatMap(e=>e===void 0?[]:[de(e)])),[d]),C=r(()=>u.kind===`known`?{kind:`known`,value:jn(u.value,S)}:u,[u,S]),w=Vn(t,d),T=u.kind===`known`?Hn(u.value,w,!1):null,E=t.build(d),D=In(t,d),O=(e,t)=>{v([]),f(n=>({...n,[e]:t}))},k=e=>x.get(de(e))??e.stableId;return e(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3`,"data-testid":`preset-wizard`,children:[o(`p`,{className:`text-[11px] text-foreground-muted`,children:s(t.descriptionKey)}),e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[s(`preset.name`),o(J,{"aria-label":s(`preset.name`),value:p,onChange:e=>m(e.target.value)})]}),o(`ul`,{className:`flex flex-col gap-2`,"aria-label":s(`preset.slots`),children:t.slots.map(t=>{let n=d[t.key];return e(`li`,{className:`grid grid-cols-1 gap-1 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-center`,"data-testid":`preset-slot-${t.key}`,children:[e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`text-xs text-foreground`,children:[s(t.labelKey),t.optionalGroup===void 0?` *`:``]}),e(`div`,{className:`text-[11px] text-foreground-muted break-words`,children:[Ln(t.expectedCap,l.language),t.optionalGroup===void 0?``:` · ${s(`preset.optional`)}`]})]}),e(`div`,{className:`flex flex-wrap gap-1`,children:[o(Y,{variant:`outline`,size:`sm`,onClick:()=>g(t),children:n===void 0?s(`preset.choose`):k(n)}),n!==void 0&&t.optionalGroup!==void 0&&o(Y,{variant:`ghost`,size:`sm`,onClick:()=>O(t.key,void 0),children:s(`preset.clear`)})]})]},t.key)})}),E===null&&D.length>0&&o(`p`,{className:`text-[11px] text-foreground-muted`,"data-testid":`preset-missing`,children:s(`preset.missing`,{slots:D.map(e=>s(e.labelKey)).join(`, `)})}),E!==null&&e(`section`,{className:`flex flex-col gap-1`,"data-testid":`preset-preview`,children:[o(`h3`,{className:`text-xs font-medium text-foreground`,children:s(`preset.preview`)}),o(`ul`,{className:`flex flex-col gap-1 text-[11px] text-foreground-muted`,children:E.features.map(e=>e.kind===`fields`?o(`li`,{children:s(`preset.previewFeature`,{cap:Ln(e.cap,l.language),fields:Object.keys(e.fields).length,commands:Object.keys(e.commands??{}).length+Object.values(e.items??{}).filter(e=>e.reset!==void 0).length})},e.cap):null)})]}),o(Bn,{lines:_,testId:`preset-refusals`}),e(`div`,{className:`mt-auto flex flex-wrap gap-2`,children:[o(Y,{disabled:E===null||n||y,onClick:()=>{E===null||y||(b(!0),i(E,p.trim()).then(e=>{e.kind===`refused`&&v(e.lines)}).finally(()=>b(!1)))},"data-testid":`preset-create`,children:s(`preset.create`)}),o(Y,{variant:`ghost`,onClick:a,children:s(`preset.back`)})]}),o(Pn,{open:h!==null,title:h===null?``:s(`preset.pickTitle`,{slot:s(h.labelKey)}),selection:`single`,candidates:C,room:T,confirmLabel:()=>s(`preset.pickConfirm`),onConfirm:e=>{let t=e[0],n=h;g(null),t!==void 0&&n!==null&&O(n.key,t.ref)},onClose:()=>g(null)})]})}u();var Jo=`preset`;function Yo({mode:e,onTitle:t}){return o(e===`helper`?Xo:Ko,{onTitle:t})}function Xo({onTitle:e}){let{t}=Z(),r=Yt(),i=Tn(),a=Dt(),l=Ze({addonId:`composer`}),[u,d]=c(null),[f,p]=c(!1),[m,h]=Gt(),g=Mn(m.get(Jo)),_=g===null?Zo(u,t):t(g.labelKey);s(()=>{f||e(_)},[e,_,f]);let v=e=>h(t=>{let n=new URLSearchParams(t);return e===null?n.delete(Jo):n.set(Jo,e),n},{replace:!0}),y=async(e,n)=>{try{let{block:o}=await i.mutateAsync({block:{...n===``?{}:{name:n},enabled:!0,composition:e}}),s=await Lo(o.id,async()=>(await l.refetch()).data??l.data);return s===null?{kind:`refused`,lines:Fn(t(`helper.devicePending`))}:(n!==``&&await a.mutateAsync({deviceId:s,name:n}),r(Qt(s),{replace:!0}),{kind:`saved`,deviceId:s})}catch(e){return{kind:`refused`,lines:Fn(e instanceof Error?e.message:String(e))}}},b=n(null);return f?o(Ko,{onTitle:e}):g===null?o(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3`,"data-testid":`composition-create-form`,children:o(Rn,{fillHeight:!0,onDevice:()=>p(!0),onPreset:v,purpose:`create`,initial:null,start:`template`,saving:i.isPending,onDraftChange:d,onSave:async(e,n)=>{let o=null,s=await Un(e,async(s,c)=>{let u=b.current,d;if(u!==null&&u.draft===e)d=u.blockId;else{let{block:t}=await i.mutateAsync({block:{...c===``?{}:{name:c},enabled:!0,composition:s}});d=t.id,b.current={draft:e,blockId:d}}let f=await Lo(d,async()=>(await l.refetch()).data??l.data);if(f===null)throw Error(t(`helper.devicePending`));o=f,b.current=null,c!==``&&await a.mutateAsync({deviceId:f,name:c}),n===`open`&&r(Zt(f),{replace:!0})}),c=o;return s.length>0||c===null?{kind:`refused`,lines:Qo(s,t)}:{kind:`saved`,deviceId:c}}})}):o(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3`,"data-testid":`composition-create-form`,children:o(qo,{preset:g,saving:i.isPending,onSave:y,onBack:()=>v(null)})})}function Zo(e,t){if(e===null)return t(`helper.newComposed`);if(e.kind===`statistic`)return t(`helper.newTitle.statistic`);if(e.kind===`integral`)return t(`helper.newTitle.integral`);if(e.kind===`arithmetic`)return t(`helper.newTitle.${e.op}`);if(e.kind===`threshold`||e.kind===`expression`||e.kind===`derivative`)return t(`helper.newTitle.${e.kind}`);let n=Ce(e.templateId);return t(n===null?`helper.newComposed`:`helper.newTitle.${n.id}`)}function Qo(e,t){return e.length>0?e:Fn(t(`helper.devicePending`))}function $o(e){let t=e.helper;if(t===void 0)return{section:`advanced`,kind:null};switch(t.kind){case`group`:return{section:`group`,kind:t.templateId};case`arithmetic`:return{section:`calculation`,kind:t.op};case`expression`:return{section:`advanced`,kind:`expression`};default:return{section:`calculation`,kind:t.kind}}}function es(e){return{state:`answered`,byRef:new Map(e.map(e=>[de(e),e]))}}function ts(e,t){if(e.state!==`unanswered`)return e.byRef.get(de(t))??null}function ns(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function rs(e){return ye(e).map(e=>e.source)}function is(e){let t=e.block.source?.kind===`composition`?e.block.source.composition:null;if(t===null)return[];let n=[];for(let e of t.features){if(e.kind===`passthrough`){n.push(e.source);continue}for(let t of Object.values(e.fields))n.push(...rs(t));for(let t of Object.values(e.items??{}))for(let e of Object.values(t.fields))n.push(...rs(e))}let r=new Set;return n.filter(e=>{let t=de(e);return r.has(t)?!1:(r.add(t),!0)})}function as(e){let t=e.fields.filter(e=>e.state===`unavailable`),n=e.fields.filter(e=>e.state===`stale`);if(t.length===0&&n.length===0)return{tone:`ok`,label:X.t(`helpers.compositionRows.running`),reason:null};let r=[...t.length>0?[X.t(`helpers.compositionRows.fieldsUnavailable`,{count:t.length})]:[],...n.length>0?[X.t(`helpers.compositionRows.fieldsStale`,{count:n.length})]:[]].join(`, `),i=t[0]??n[0],a=i===void 0?``:` — ${i.cap}.${i.path}: ${i.reason??X.t(`helpers.compositionRows.noReason`)}`;return{tone:`pending`,label:X.t(`helpers.compositionRows.running`),reason:`${r}${a}`}}function os(e,t){let n=e.reason??t??null;switch(e.status){case`running`:return as(e);case`degraded`:return{tone:`pending`,label:X.t(`helpers.compositionRows.degraded`),reason:n??X.t(`helpers.compositionRows.degradedReason`)};case`starting`:return{tone:`pending`,label:X.t(`helpers.compositionRows.starting`),reason:n};case`failed`:return{tone:`error`,label:X.t(`helpers.compositionRows.failed`),reason:n??X.t(`helpers.compositionRows.failedReason`)};default:return{tone:`error`,label:X.t(`helpers.compositionRows.notRunning`),reason:n??X.t(`helpers.compositionRows.notRunningReason`)}}}function ss(e){let{block:t,state:n}=e;if(!t.enabled)return{tone:`idle`,label:X.t(`helpers.compositionRows.off`),reason:null};if(n.kind===`unreachable`)return{tone:`pending`,label:X.t(`helpers.compositionRows.unknown`),reason:X.t(`helpers.compositionRows.unreachable`,{error:n.error})};if(n.state!==null)return os(n.state,t.lastError);let r=t.lastError===void 0?t.status:`${t.status}: ${t.lastError}`;return{tone:`pending`,label:X.t(`helpers.compositionRows.notReported`),reason:X.t(`helpers.compositionRows.noRecord`,{stored:r})}}function cs(e){return de(e)}function ls(e,t){let n=ts(t,e);return{key:de(e),label:n?n.name:cs(e),presence:ns(n),deviceId:n?n.id:null}}function us(e){return e.state.kind===`answered`&&e.state.state!==null?e.state.state.deviceId:null}function ds(e,t){let n=e.block.source?.kind===`composition`?e.block.source.composition:null;if(n===null)return null;let r=n.target,i=r.kind===`existing`?r.device:G(e.block.id),a=de(i),o=is(e).filter(e=>de(e)!==a).map(e=>ls(e,t)),s=n.features.map(e=>e.enabled===!1?X.t(`helpers.compositionRows.featureOff`,{cap:e.cap}):e.cap),c=ts(t,i),l=us(e),u=ss(e);if(r.kind===`new`)return{blockId:e.block.id,kind:`composed`,name:e.block.name,namePresence:`present`,type:r.role===void 0?r.type:`${r.type} · ${r.role}`,origin:$o(n),features:s,state:u,sources:o,reportedDeviceId:l};let d=ns(c);return{blockId:e.block.id,kind:`customization`,name:c?c.name:cs(r.device),namePresence:d,type:c?c.type:null,origin:$o(n),features:s,state:u,sources:o,reportedDeviceId:l}}function fs(e){return e.state.tone===`error`?0:e.state.tone===`pending`?1:e.state.tone===`ok`?2:3}function ps(e,t){return fs(e)-fs(t)||e.name.localeCompare(t.name)}function ms(e,t){let n=e.flatMap(e=>{let n=ds(e,t);return n===null?[]:[n]});return{composed:n.filter(e=>e.kind===`composed`).toSorted(ps),customizations:n.filter(e=>e.kind===`customization`).toSorted(ps)}}u();var hs=1e4;function gs(e){return e instanceof Error?e.message:typeof e==`object`&&e&&`message`in e?String(e.message):String(e)}function _s(){let e=qt();return e.data===void 0?{state:`unanswered`,reason:e.error==null?X.t(`build.customDeviceTab.deviceListPending`):X.t(`build.customDeviceTab.deviceListUnreadable`,{error:gs(e.error)})}:es(e.data)}function vs(e,t){return e===`blank`?`blank`:e===`helper`||e===`1`||t?`helper`:null}function ys({createRequested:t=!1,onCreateConsumed:n}={}){let{t:r}=Z(),[i,a]=Gt(),s=mt({},{refetchInterval:hs}),l=_s(),u=Rt({editKey:`block`,newKey:`new`}),d=u.state.mode===`edit`?u.state.id:null,f=d===null?vs(i.get(`new`),t):null,m=f!==null,[h,g]=c(``),_=E(),v=Xe(),y=()=>{u.close(),a(()=>{let e=new URLSearchParams(window.location.search);return e.delete(`new`),e.delete(`block`),e},{replace:!0}),n?.()},b=s.data;return e(p,{children:[xs(b,s.error,()=>void s.refetch(),l,{onEditComposed:e=>u.openEdit(e),deleting:v.isPending,onDelete:e=>{_({title:r(`build.customDeviceTab.deleteThisComposedDevice`,`Delete this composed device?`),message:r(`build.customDeviceTab.deleteMessage`,`{{name}} will be deleted. This cannot be undone.`,{name:e.name}),confirmLabel:r(`common.delete`,`Delete`),variant:`danger`}).then(t=>{t&&v.mutate({blockId:e.blockId},{onSuccess:()=>void s.refetch()})})}}),o(Fe,{open:m,onClose:y,title:h||r(f===`blank`?`helper.newComposition`:`helper.newComposed`),icon:we,width:`xl`,testId:`composed-device-editor`,fill:!0,children:f!==null&&o(Yo,{mode:f,onTitle:g},f)}),o(bn,{blockId:d,onClose:y}),v.error!=null&&o(q,{message:gs(v.error)})]})}function bs(t){return o(nt,{children:e(`div`,{className:`space-y-1 p-4`,children:[o(`p`,{className:`text-sm text-warning`,children:X.t(`build.customDeviceTab.theCompositionStoreHasNot`,`The composition store has not been read yet.`)}),e(`p`,{className:`text-xs text-foreground-subtle`,children:[X.t(`build.customDeviceTab.thisIsNotTheSame`,`This is not the same as having none — the list appears once the hub has read it (`),t,`).`]})]})})}function xs(e,t,n,r,i){if(t!=null&&e===void 0)return o(q,{title:X.t(`build.customDeviceTab.couldNotReadTheCompositions`,`Could not read the compositions`),message:gs(t),onRetry:n});if(e===void 0)return o(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:X.t(`build.customDeviceTab.loadingCompositions`,`Loading compositions…`)});if(e.state===`not-loaded`)return bs(e.reason);let a=t==null?null:gs(t);return o(Ss,{lists:ms(e.views,r),fleet:r,refreshError:a,handlers:i})}function Ss({lists:t,fleet:n,refreshError:r,handlers:i}){let{t:a}=Z();return e(`div`,{className:`space-y-4`,children:[r!==null&&e(`p`,{className:`text-xs text-warning`,children:[a(`build.customDeviceTab.showingTheLastAnswerThe`,`Showing the last answer — the latest refresh failed:`),` `,r]}),n.state===`unanswered`&&e(`p`,{className:`text-xs text-warning`,children:[a(`build.customDeviceTab.deviceNamesAreShownAs`,`Device names are shown as references:`),` `,n.reason,`. No source is marked missing until it has.`]}),o(Cs,{title:a(`build.customDeviceTab.composedDevices`,`Composed devices`),hint:a(`build.customDeviceTab.aNewDeviceWhoseState`,`A new device whose state is derived from other devices.`),rows:t.composed,nameHeader:`Name`,emptyMessage:a(`build.customDeviceTab.noComposedDevices`,`No composed devices.`),kind:`composed`,handlers:i}),o(Cs,{title:a(`build.customDeviceTab.customizations`,`Customizations`),hint:a(`build.customDeviceTab.fieldsAddedToOrReplaced`,`Fields added to or replaced on an existing device — one per device, edited from the device.`),rows:t.customizations,nameHeader:`Device`,emptyMessage:a(`build.customDeviceTab.noCustomizations`,`No customizations.`),kind:`customization`,handlers:i})]})}function Cs({title:t,hint:n,rows:r,nameHeader:i,emptyMessage:a,kind:s,handlers:c}){let{t:l}=Z();return e(`section`,{className:`space-y-2`,"aria-label":t,children:[e(`div`,{children:[o(`h3`,{className:`font-medium`,children:t}),o(`p`,{className:`text-xs text-foreground-subtle`,children:n})]}),o(Qe,{columns:ws(i,s,c,l),rows:r,rowKey:e=>e.blockId,pageSize:25,maxBodyHeight:Ht,emptyMessage:a,onRowClick:s===`composed`?e=>c.onEditComposed(e.blockId):void 0})]})}function ws(t,n,r,i){let a=[{key:`name`,header:t,sortValue:e=>e.name.toLowerCase(),render:e=>o(Es,{row:e})},{key:`type`,header:X.t(`build.customDeviceTab.type`,`Type`),sortValue:e=>e.type,render:e=>o(`span`,{className:`text-xs text-foreground-subtle`,children:e.type??X.t(`common.unknownWord`)})},...n===`composed`?[{key:`origin`,header:X.t(`build.customDeviceTab.builtAs`,`Built as`),sortValue:e=>Ts(e.origin,i),render:e=>o(K,{variant:`default`,"data-testid":`composed-origin-badge`,children:Ts(e.origin,i)})}]:[],{key:`state`,header:X.t(`build.customDeviceTab.state`,`State`),nowrap:!1,notSortableReason:`A state and its reason are read together, not ordered.`,render:t=>e(`div`,{className:`space-y-0.5`,children:[o(K,{variant:Na(t.state.tone),children:t.state.label}),t.state.reason!==null&&o(`p`,{className:`max-w-md whitespace-normal text-xs text-foreground-subtle`,children:t.state.reason})]})},{key:`sources`,header:X.t(`build.customDeviceTab.sources`,`Sources`),nowrap:!1,notSortableReason:`A list of devices has no single order.`,render:e=>o(Os,{sources:e.sources})}];return n===`composed`&&a.push({key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,nowrap:!0,render:t=>e(`div`,{className:`flex justify-end gap-1`,children:[o(Y,{variant:`ghost`,title:i(`common.edit`,`Edit`),onClick:e=>{e.stopPropagation(),r.onEditComposed(t.blockId)},children:i(`common.edit`,`Edit`)}),o(Y,{variant:`ghost`,title:i(`common.delete`,`Delete`),disabled:r.deleting,"aria-label":i(`common.delete`,`Delete`),onClick:e=>{e.stopPropagation(),r.onDelete(t)},children:o(_,{className:`h-4 w-4`})})]})}),a}function Ts(e,t){let n=e.kind===null?null:t(`helper.template.${e.kind}`);return e.section===`group`?t(`helper.badge.group`,{kind:n}):e.section===`calculation`?t(`helper.badge.calculation`,{kind:n}):n===null?t(`helper.badge.advanced`):t(`helper.badge.advancedKind`,{kind:n})}function Es({row:t}){let{t:n}=Z();return e(`div`,{className:`space-y-0.5`,children:[o(Ds,{row:t}),t.namePresence===`missing`&&o(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:n(`build.customDeviceTab.deviceMissing`,`device missing`)}),o(`p`,{className:`text-[11px] text-foreground-subtle`,children:t.features.join(`, `)})]})}function Ds({row:e}){let{t}=Z(),n=pt(e.reportedDeviceId??0,`compact`,e.name),r=e.reportedDeviceId===null?e.name:n;return e.reportedDeviceId===null?e.kind===`composed`?o(`span`,{className:`text-xs font-medium text-foreground`,children:e.name}):o(`span`,{className:`text-xs text-foreground-subtle`,children:t(`build.customDeviceTab.notReported`,{name:r})}):o(Kt,{to:e.kind===`composed`?Zt(e.reportedDeviceId):Qt(e.reportedDeviceId),className:`text-xs font-medium text-foreground hover:underline`,onClick:e=>e.stopPropagation(),children:r})}function Os({sources:t}){let{t:n}=Z();return t.length===0?o(`span`,{className:`text-xs text-foreground-subtle`,children:`—`}):o(`ul`,{className:`space-y-0.5`,children:t.map(t=>e(`li`,{className:`text-xs`,children:[t.deviceId===null?o(`span`,{className:t.presence===`missing`?`text-danger`:`text-foreground`,children:t.label}):o(Kt,{to:`/devices/${String(t.deviceId)}`,className:`hover:underline`,children:t.label}),t.presence===`missing`&&o(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:n(`common.missing`)})]},t.key))})}function ks(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 As(e){if(Array.isArray(e))return e}function js(e,t,n){return(t=Bs(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ms(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 Ns(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
4
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Ps(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function Fs(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Ps(Object(n),!0).forEach(function(t){js(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Ps(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Is(e,t){if(e==null)return{};var n,r,i=Ls(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function Ls(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function Rs(e,t){return As(e)||Ms(e,t)||Vs(e,t)||Ns()}function zs(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Bs(e){var t=zs(e,`string`);return typeof t==`symbol`?t:t+``}function Vs(e,t){if(e){if(typeof e==`string`)return ks(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?ks(e,t):void 0}}function Hs(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Us(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function Ws(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Us(Object(n),!0).forEach(function(t){Hs(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Us(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Gs(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}}function Ks(e){return function t(){var n=this,r=[...arguments];return r.length>=e.length?e.apply(this,r):function(){var e=[...arguments];return t.apply(n,[].concat(r,e))}}}function qs(e){return{}.toString.call(e).includes(`Object`)}function Js(e){return!Object.keys(e).length}function Ys(e){return typeof e==`function`}function Xs(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Zs(e,t){return qs(t)||nc(`changeType`),Object.keys(t).some(function(t){return!Xs(e,t)})&&nc(`changeField`),t}function Qs(e){Ys(e)||nc(`selectorType`)}function $s(e){Ys(e)||qs(e)||nc(`handlerType`),qs(e)&&Object.values(e).some(function(e){return!Ys(e)})&&nc(`handlersType`)}function ec(e){e||nc(`initialIsRequired`),qs(e)||nc(`initialType`),Js(e)&&nc(`initialContent`)}function tc(e,t){throw Error(e[t]||e.default)}var nc=Ks(tc)({initialIsRequired:`initial state is required`,initialType:`initial state should be an object`,initialContent:`initial state shouldn't be an empty object`,handlerType:`handler should be an object or a function`,handlersType:`all handlers should be a functions`,selectorType:`selector should be a function`,changeType:`provided value of changes should be an object`,changeField:`it seams you want to change a field in the state which is not specified in the "initial" state`,default:"an unknown error accured in `state-local` package"}),rc={changes:Zs,selector:Qs,handler:$s,initial:ec};function ic(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};rc.initial(e),rc.handler(t);var n={current:e},r=Ks(sc)(n,t),i=Ks(oc)(n),a=Ks(rc.changes)(e),o=Ks(ac)(n);function s(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(e){return e};return rc.selector(e),e(n.current)}function c(e){Gs(r,i,a,o)(e)}return[s,c]}function ac(e,t){return Ys(t)?t(e.current):t}function oc(e,t){return e.current=Ws(Ws({},e.current),t),t}function sc(e,t,n){return Ys(t)?t(e.current):Object.keys(n).forEach(function(n){return t[n]?.call(t,e.current[n])}),n}var cc={create:ic},lc={paths:{vs:`https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs`}};function uc(e){return function t(){var n=this,r=[...arguments];return r.length>=e.length?e.apply(this,r):function(){var e=[...arguments];return t.apply(n,[].concat(r,e))}}}function dc(e){return{}.toString.call(e).includes(`Object`)}function fc(e){return e||gc(`configIsRequired`),dc(e)||gc(`configType`),e.urls?(pc(),{paths:{vs:e.urls.monacoBase}}):e}function pc(){console.warn(hc.deprecation)}function mc(e,t){throw Error(e[t]||e.default)}var hc={configIsRequired:`the configuration object is required`,configType:`the configuration object should be an object`,default:"an unknown error accured in `@monaco-editor/loader` package",deprecation:`Deprecation warning!
|
|
5
|
-
You are using deprecated way of configuration.
|
|
6
|
-
|
|
7
|
-
Instead of using
|
|
8
|
-
monaco.config({ urls: { monacoBase: '...' } })
|
|
9
|
-
use
|
|
10
|
-
monaco.config({ paths: { vs: '...' } })
|
|
11
|
-
|
|
12
|
-
For more please check the link https://github.com/suren-atoyan/monaco-loader#config
|
|
13
|
-
`},gc=uc(mc)(hc),_c={config:fc},vc=function(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}};function yc(e,t){return Object.keys(t).forEach(function(n){t[n]instanceof Object&&e[n]&&Object.assign(t[n],yc(e[n],t[n]))}),Fs(Fs({},e),t)}var bc={type:`cancelation`,msg:`operation is manually canceled`};function xc(e){var t=!1,n=new Promise(function(n,r){e.then(function(e){return t?r(bc):n(e)}),e.catch(r)});return n.cancel=function(){return t=!0},n}var Sc=[`monaco`],Cc=Rs(cc.create({config:lc,isInitialized:!1,resolve:null,reject:null,monaco:null}),2),wc=Cc[0],Tc=Cc[1];function Ec(e){var t=_c.config(e),n=t.monaco,r=Is(t,Sc);Tc(function(e){return{config:yc(e.config,r),monaco:n}})}function Dc(){var e=wc(function(e){return{monaco:e.monaco,isInitialized:e.isInitialized,resolve:e.resolve}});if(!e.isInitialized){if(Tc({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),xc(Pc);if(window.monaco&&window.monaco.editor)return Mc(window.monaco),e.resolve(window.monaco),xc(Pc);vc(Oc,Ac)(jc)}return xc(Pc)}function Oc(e){return document.body.appendChild(e)}function kc(e){var t=document.createElement(`script`);return e&&(t.src=e),t}function Ac(e){var t=wc(function(e){return{config:e.config,reject:e.reject}}),n=kc(`${t.config.paths.vs}/loader.js`);return n.onload=function(){return e()},n.onerror=t.reject,n}function jc(){var e=wc(function(e){return{config:e.config,resolve:e.resolve,reject:e.reject}}),t=window.require;t.config(e.config),t([`vs/editor/editor.main`],function(t){var n=t.m||t;Mc(n),e.resolve(n)},function(t){e.reject(t)})}function Mc(e){wc().monaco||Tc({monaco:e})}function Nc(){return wc(function(e){return e.monaco})}var Pc=new Promise(function(e,t){return Tc({resolve:e,reject:t})}),Fc={config:Ec,init:Dc,__getMonacoInstance:Nc};u();var Ic={wrapper:{display:`flex`,position:`relative`,textAlign:`initial`},fullWidth:{width:`100%`},hide:{display:`none`}},Lc={container:{display:`flex`,height:`100%`,width:`100%`,justifyContent:`center`,alignItems:`center`}};function Rc({children:e}){return t.createElement(`div`,{style:Lc.container},e)}var zc=Rc;function Bc({width:e,height:n,isEditorReady:r,loading:i,_ref:a,className:o,wrapperProps:s}){return t.createElement(`section`,{style:{...Ic.wrapper,width:e,height:n},...s},!r&&t.createElement(zc,null,i),t.createElement(`div`,{ref:a,style:{...Ic.fullWidth,...!r&&Ic.hide},className:o}))}var Vc=i(Bc);function Hc(e){s(e,[])}var Uc=Hc;function Wc(e,t,r=!0){let i=n(!0);s(i.current||!r?()=>{i.current=!1}:e,t)}var $=Wc;function Gc(){}function Kc(e,t,n,r){return qc(e,r)||Jc(e,t,n,r)}function qc(e,t){return e.editor.getModel(Yc(e,t))}function Jc(e,t,n,r){return e.editor.createModel(t,n,r?Yc(e,r):void 0)}function Yc(e,t){return e.Uri.parse(t)}function Xc({original:e,modified:r,language:i,originalLanguage:o,modifiedLanguage:l,originalModelPath:u,modifiedModelPath:d,keepCurrentOriginalModel:f=!1,keepCurrentModifiedModel:p=!1,theme:m=`light`,loading:h=`Loading...`,options:g={},height:_=`100%`,width:v=`100%`,className:y,wrapperProps:b={},beforeMount:x=Gc,onMount:S=Gc}){let[C,w]=c(!1),[T,E]=c(!0),D=n(null),O=n(null),k=n(null),A=n(S),j=n(x),M=n(!1);Uc(()=>{let e=Fc.init();return e.then(e=>(O.current=e)&&E(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>D.current?F():e.cancel()}),$(()=>{if(D.current&&O.current){let t=D.current.getOriginalEditor(),n=Kc(O.current,e||``,o||i||`text`,u||``);n!==t.getModel()&&t.setModel(n)}},[u],C),$(()=>{if(D.current&&O.current){let e=D.current.getModifiedEditor(),t=Kc(O.current,r||``,l||i||`text`,d||``);t!==e.getModel()&&e.setModel(t)}},[d],C),$(()=>{let e=D.current.getModifiedEditor();e.getOption(O.current.editor.EditorOption.readOnly)?e.setValue(r||``):r!==e.getValue()&&(e.executeEdits(``,[{range:e.getModel().getFullModelRange(),text:r||``,forceMoveMarkers:!0}]),e.pushUndoStop())},[r],C),$(()=>{D.current?.getModel()?.original.setValue(e||``)},[e],C),$(()=>{let{original:e,modified:t}=D.current.getModel();O.current.editor.setModelLanguage(e,o||i||`text`),O.current.editor.setModelLanguage(t,l||i||`text`)},[i,o,l],C),$(()=>{O.current?.editor.setTheme(m)},[m],C),$(()=>{D.current?.updateOptions(g)},[g],C);let N=a(()=>{if(!O.current)return;j.current(O.current);let t=Kc(O.current,e||``,o||i||`text`,u||``),n=Kc(O.current,r||``,l||i||`text`,d||``);D.current?.setModel({original:t,modified:n})},[i,r,l,e,o,u,d]),P=a(()=>{!M.current&&k.current&&(D.current=O.current.editor.createDiffEditor(k.current,{automaticLayout:!0,...g}),N(),O.current?.editor.setTheme(m),w(!0),M.current=!0)},[g,m,N]);s(()=>{C&&A.current(D.current,O.current)},[C]),s(()=>{!T&&!C&&P()},[T,C,P]);function F(){let e=D.current?.getModel();f||e?.original?.dispose(),p||e?.modified?.dispose(),D.current?.dispose()}return t.createElement(Vc,{width:v,height:_,isEditorReady:C,loading:h,_ref:k,className:y,wrapperProps:b})}i(Xc);function Zc(e){let t=n();return s(()=>{t.current=e},[e]),t.current}var Qc=Zc,$c=new Map;function el({defaultValue:e,defaultLanguage:r,defaultPath:i,value:o,language:l,path:u,theme:d=`light`,line:f,loading:p=`Loading...`,options:m={},overrideServices:h={},saveViewState:g=!0,keepCurrentModel:_=!1,width:v=`100%`,height:y=`100%`,className:b,wrapperProps:x={},beforeMount:S=Gc,onMount:C=Gc,onChange:w,onValidate:T=Gc}){let[E,D]=c(!1),[O,k]=c(!0),A=n(null),j=n(null),M=n(null),N=n(C),P=n(S),F=n(),I=n(o),L=Qc(u),R=n(!1),z=n(!1);Uc(()=>{let e=Fc.init();return e.then(e=>(A.current=e)&&k(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>j.current?V():e.cancel()}),$(()=>{let t=Kc(A.current,e||o||``,r||l||``,u||i||``);t!==j.current?.getModel()&&(g&&$c.set(L,j.current?.saveViewState()),j.current?.setModel(t),g&&j.current?.restoreViewState($c.get(u)))},[u],E),$(()=>{j.current?.updateOptions(m)},[m],E),$(()=>{!j.current||o===void 0||(j.current.getOption(A.current.editor.EditorOption.readOnly)?j.current.setValue(o):o!==j.current.getValue()&&(z.current=!0,j.current.executeEdits(``,[{range:j.current.getModel().getFullModelRange(),text:o,forceMoveMarkers:!0}]),j.current.pushUndoStop(),z.current=!1))},[o],E),$(()=>{let e=j.current?.getModel();e&&l&&A.current?.editor.setModelLanguage(e,l)},[l],E),$(()=>{f!==void 0&&j.current?.revealLine(f)},[f],E),$(()=>{A.current?.editor.setTheme(d)},[d],E);let B=a(()=>{if(!(!M.current||!A.current)&&!R.current){P.current(A.current);let t=u||i,n=Kc(A.current,o||e||``,r||l||``,t||``);j.current=A.current?.editor.create(M.current,{model:n,automaticLayout:!0,...m},h),g&&j.current.restoreViewState($c.get(t)),A.current.editor.setTheme(d),f!==void 0&&j.current.revealLine(f),D(!0),R.current=!0}},[e,r,i,o,l,u,m,h,g,d,f]);s(()=>{E&&N.current(j.current,A.current)},[E]),s(()=>{!O&&!E&&B()},[O,E,B]),I.current=o,s(()=>{E&&w&&(F.current?.dispose(),F.current=j.current?.onDidChangeModelContent(e=>{z.current||w(j.current.getValue(),e)}))},[E,w]),s(()=>{if(E){let e=A.current.editor.onDidChangeMarkers(e=>{let t=j.current.getModel()?.uri;if(t&&e.find(e=>e.path===t.path)){let e=A.current.editor.getModelMarkers({resource:t});T?.(e)}});return()=>{e?.dispose()}}return()=>{}},[E,T]);function V(){F.current?.dispose(),_?g&&$c.set(u,j.current.saveViewState()):j.current.getModel()?.dispose(),j.current.dispose()}return t.createElement(Vc,{width:v,height:y,isEditorReady:E,loading:p,_ref:M,className:b,wrapperProps:x})}var tl=i(el);u();function nl(e,t){let n=[];for(let[r,i]of Object.entries(e))r!==t&&(n.push({filePath:`file:///${r}`,content:i}),r.endsWith(`.ts`)&&n.push({filePath:`file:///${r.slice(0,-3)}.js`,content:i}));return n}var rl={target:99,module:99,moduleResolution:2,strict:!0,noImplicitAny:!0,strictNullChecks:!0,allowNonTsExtensions:!0,isolatedModules:!0};function il(e,t){let n=e.languages.typescript.typescriptDefaults;n.setCompilerOptions({...n.getCompilerOptions(),...rl}),n.setExtraLibs(t.map(e=>({filePath:e.filePath,content:e.content})))}function al({value:e,onChange:t,extraLibs:r=[],path:i=`file:///block.ts`,onDiagnostics:c,readOnly:l=!1,heightPx:u=420,dark:d=!0}){let f=n(null),p=a((e,t)=>{if(f.current=t,il(t,r),c===void 0)return;let n=e.getModel();if(n===null)return;let i=()=>{c(t.editor.getModelMarkers({resource:n.uri}).map(e=>({line:e.startLineNumber,column:e.startColumn,message:e.message,severity:e.severity})))};t.editor.onDidChangeMarkers(i),i()},[r,c]);return s(()=>{let e=f.current;e!==null&&il(e,r)},[r]),o(tl,{height:u,defaultLanguage:`typescript`,path:i,theme:d?`vs-dark`:`vs`,value:e,onChange:e=>t(e??``),onMount:p,options:{readOnly:l,minimap:{enabled:!1},fontSize:12,lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,tabSize:2,renderWhitespace:`selection`}})}function ol(e){return e.some(e=>e.severity>=8)}var sl=[{id:`blank`,name:`Blank script`,get description(){return X.t(`helpers.buildExamples.blankDescription`)},entry:`main.ts`,files:{"main.ts":`import type { AddonContext } from '@camstack/types'
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* A core block. Runs in its own process, with the same \`ctx\` an addon gets.
|
|
17
|
-
* Return a function to release whatever you took (timers, sockets, listeners).
|
|
18
|
-
*
|
|
19
|
-
* Declaring devices: import { reconcileBlockDevices, exposeBlockDevices } from
|
|
20
|
-
* '@camstack/types' and hang them off the shared Blocks integration.
|
|
21
|
-
*/
|
|
22
|
-
export default function block(ctx: AddonContext) {
|
|
23
|
-
ctx.logger.info('hello from a core block')
|
|
24
|
-
|
|
25
|
-
const timer = setInterval(() => {
|
|
26
|
-
ctx.logger.info('tick')
|
|
27
|
-
}, 60_000)
|
|
28
|
-
|
|
29
|
-
return () => {
|
|
30
|
-
clearInterval(timer)
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
`}}];function cl(e){let t=e instanceof Set?e:new Set(e);if(!t.has(`file.ts`))return`file.ts`;let n=2;for(;t.has(`file-${String(n)}.ts`);)n+=1;return`file-${String(n)}.ts`}var ll=sl.find(e=>e.id===`blank`)?.files[`main.ts`]??`import type { AddonContext } from '@camstack/types'
|
|
34
|
-
|
|
35
|
-
export default function block(ctx: AddonContext) {
|
|
36
|
-
ctx.logger.info('hello from a core block')
|
|
37
|
-
return () => undefined
|
|
38
|
-
}
|
|
39
|
-
`;function ul({existing:e,dirty:t,saving:n,restarting:r}){return e===null?X.t(`helpers.restartGate.saveFirstNoProcess`):n?X.t(`helpers.restartGate.saving`):r?X.t(`helpers.restartGate.restarting`):t?X.t(`helpers.restartGate.saveFirstDirty`):e.enabled?null:X.t(`helpers.restartGate.disabled`)}u();var dl=5e3;function fl(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(typeof n!=`object`||!n)continue;let e=Reflect.get(n,`id`),r=Reflect.get(n,`name`),i=Reflect.get(n,`type`),a=Reflect.get(n,`stableId`);typeof e!=`number`||typeof r!=`string`||typeof i!=`string`||t.push({id:e,name:r,type:i,...typeof a==`string`?{stableId:a}:{}})}return t}function pl({blockId:t}){let{t:n}=Z(),i=I(t),a=Le({addonId:i,projection:`slim`},{refetchInterval:dl}),s=r(()=>fl(a.data),[a.data]);return a.isLoading?e(`p`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[o(A,{className:`h-3.5 w-3.5 animate-spin`}),` `,n(`build.scriptDevicesPanel.loading`)]}):a.isError?e(`p`,{className:`text-xs text-danger`,children:[n(`build.scriptDevicesPanel.couldNotListDevices`,`Could not list devices:`),` `,a.error instanceof Error?a.error.message:String(a.error)]}):e(`section`,{className:`space-y-3 rounded border border-border p-3`,"data-testid":`script-devices-panel`,children:[e(`div`,{className:`flex items-center justify-between gap-2`,children:[e(`div`,{children:[o(`h4`,{className:`text-sm font-medium`,children:n(`build.scriptDevicesPanel.devices`,`Devices`)}),o(`p`,{className:`text-xs text-foreground-subtle`,children:o(Jt,{i18nKey:`build.scriptDevicesPanel.declaredBy`,values:{addonId:i},components:{code:o(`code`,{className:`text-[11px]`})}})})]}),o(K,{variant:`default`,children:s.length})]}),s.length===0?o(`p`,{className:`text-xs text-foreground-subtle`,children:o(Jt,{i18nKey:`build.scriptDevicesPanel.noDevices`,components:{code:o(`code`,{})}})}):o(`ul`,{className:`space-y-3`,children:s.map(t=>o(`li`,{className:`rounded border border-border/80 px-3 py-2`,"data-testid":`script-device-${t.id}`,children:e(`div`,{className:`flex flex-wrap items-baseline gap-2`,children:[o(Kt,{to:`/devices/${String(t.id)}`,className:`text-sm font-medium hover:underline`,title:n(`build.scriptDevicesPanel.openDeviceDetail`,`Open device detail`),children:o(Ot,{device:{id:t.id,name:t.name,type:t.type,stableId:t.stableId??``,parentDeviceId:null},form:`compact`})}),o(K,{variant:`info`,style:`outline`,children:t.type}),t.stableId!==void 0&&e(`span`,{className:`text-[11px] text-foreground-subtle`,children:[`stableId `,o(`code`,{children:t.stableId})]}),e(`span`,{className:`text-[11px] text-foreground-subtle`,children:[`#`,t.id]})]})},t.id))})]})}u();function ml(e){return e===`refresh-channel-catalog`||e===`send-tv-schedule-now`||e===`refresh-nordvpn-catalog`||e===`probe-nordvpn-italy`||e===`test-nordvpn-endpoint`||e===`refresh-unifi-catalog`}function hl(e){let t=Date.now();switch(e){case`refresh-channel-catalog`:return{channelCatalogRefreshAt:t};case`send-tv-schedule-now`:return{sendNowAt:t};case`refresh-nordvpn-catalog`:return{nordVpnCatalogRefreshAt:t};case`probe-nordvpn-italy`:return{nordVpnProbeAt:t};case`test-nordvpn-endpoint`:return{nordVpnTestAt:t};case`refresh-unifi-catalog`:return{unifiCatalogRefreshAt:t}}}function gl(e){switch(e){case`refresh-channel-catalog`:return X.t(`build.scriptSettingsPanel.enableChannel`);case`send-tv-schedule-now`:return X.t(`build.scriptSettingsPanel.enableTv`);case`refresh-nordvpn-catalog`:return X.t(`build.scriptSettingsPanel.enableNord`);case`probe-nordvpn-italy`:return X.t(`build.scriptSettingsPanel.enableItaly`);case`test-nordvpn-endpoint`:return X.t(`build.scriptSettingsPanel.enableVpn`);case`refresh-unifi-catalog`:return X.t(`build.scriptSettingsPanel.enableUnifi`)}}function _l(e){if(typeof e!=`object`||!e||!(`key`in e))return null;let t=Reflect.get(e,`key`);return typeof t==`string`?t:null}function vl(e){if(!(typeof e!=`object`||!e||!(`value`in e)))return Reflect.get(e,`value`)}function yl(e){let t={};for(let n of e.sections)for(let e of n.fields){let n=_l(e);n!==null&&(t[n]=vl(e))}return t}function bl(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function xl({blockId:t}){let{t:n}=Z(),i=D(),s=Ae({blockId:t},{retry:!1}),l=vt({blockId:t},{refetchInterval:1e4,retry:!1}),u=Tt({onSuccess:()=>{l.refetch()}}),d=Pt(),f=ht(),[p,m]=c(null),[h,g]=c(null),[_,v]=c(null),[y,b]=c(!1),x=bl(l.data)?l.data:null,S=r(()=>x===null?{}:yl(x),[x]),C=p??S,w=a(e=>{m(e)},[]),T=p!==null,E=a(()=>{p!==null&&(g(null),u.mutate({blockId:t,patch:p},{onSuccess:()=>m(null),onError:e=>g(e instanceof Error?e.message:String(e))}))},[t,p,u]),O=a(async(e,n)=>{if(ml(e)){b(!0),g(null),v(null);try{p!==null&&(await i.trpcClient.coreBlocks.updateBlockSettings.mutate({blockId:t,patch:p}),m(null)),await i.trpcClient.coreBlocks.updateBlockSettings.mutate({blockId:t,patch:hl(e)}),s.data?.block?.enabled!==!0&&(await f.mutateAsync({blockId:t,enabled:!0}),v(gl(e))),await d.mutateAsync({blockId:t}),await l.refetch(),e===`send-tv-schedule-now`?v(`Sending tonight’s schedule now…`):e===`probe-nordvpn-italy`?v(`Probing NordVPN Italy stations (no UniFi change)…`):e===`test-nordvpn-endpoint`?v(`Testing VPN endpoint on UniFi…`):e===`refresh-nordvpn-catalog`?v(`Refreshing NordVPN Italy catalog…`):e===`refresh-unifi-catalog`&&v(`Refreshing UniFi ID catalogs…`)}catch(e){g(e instanceof Error?e.message:String(e))}finally{b(!1)}}},[t,s.data?.block?.enabled,p,d,f,l,i.trpcClient.coreBlocks]);return l.isLoading?e(`p`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[o(A,{className:`h-3.5 w-3.5 animate-spin`}),` `,n(`build.scriptSettingsPanel.loading`)]}):l.isError?e(`p`,{className:`text-xs text-danger`,"data-testid":`script-settings-error`,children:[n(`build.scriptSettingsPanel.couldNotLoadSettings`,`Could not load settings:`),` `,l.error instanceof Error?l.error.message:String(l.error)]}):x===null?null:e(`section`,{className:`space-y-3 rounded border border-border p-3`,"data-testid":`script-settings-panel`,children:[e(`div`,{className:`flex items-center justify-between gap-2`,children:[e(`div`,{children:[o(`h4`,{className:`text-sm font-medium`,children:n(`build.scriptSettingsPanel.settings`,`Settings`)}),o(`p`,{className:`text-xs text-foreground-subtle`,children:o(Jt,{i18nKey:`build.scriptSettingsPanel.declaredBy`,components:{code:o(`code`,{})}})})]}),e(Y,{size:`sm`,variant:`primary`,onClick:E,disabled:!T||u.isPending||y,children:[u.isPending&&o(A,{className:`h-3.5 w-3.5 animate-spin`}),n(`build.scriptSettingsPanel.saveSettings`,`Save settings`)]})]}),o(en,{schema:x,values:C,onChange:w,onAction:O}),h===null?null:o(`p`,{className:`text-xs text-danger`,"data-testid":`script-settings-save-error`,children:h}),_===null?null:o(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`script-settings-info`,children:_})]})}u();var Sl=`hub`;function Cl({existing:t,typeDefs:n,typeDefsLoading:i,saving:a,saveError:s,restarting:l,restartError:u,onRestart:d,onSave:m,onCancel:h}){let{t:g}=Z(),_=D(),y=E(),{resolvedMode:b}=Bt(),x=N({code:t?.code??ll,files:t?.files,entry:t?.entry}),[w,T]=c(t?.name??``),[j,M]=c(x.files),[P,F]=c(x.entry),[L,R]=c(x.entry),[z,B]=c(t?.placement??Sl),[V,H]=c(t?.integrationId??``),[ee,te]=c([]),[ne,re]=c(!1),[U,ie]=c(`blank`),[ae,oe]=c(null),[se,ce]=c(``),le=j[L]??``,W=e=>{M(t=>({...t,[L]:e}))},ue=Object.keys(j).toSorted(),de=sl.length>1,fe=r(()=>[...n?.libs??[],...nl(j,L)],[n?.libs,j,L]),G=f({mutationFn:()=>_.trpcClient.coreBlocks.compile.mutate({files:j,entry:P})}),pe=r(()=>ee.filter(e=>e.severity>=8),[ee]),me=ol(ee),he=w.trim()===``,ge=t===null?null:N(t),_e=t===null||ge===null||JSON.stringify(j)!==JSON.stringify(ge.files)||P!==ge.entry||w.trim()!==t.name||z!==t.placement||(V.trim()===``?void 0:V.trim())!==t.integrationId,ve=()=>{G.reset(),m({name:w.trim(),files:j,entry:P,enabled:t?.enabled??!0,placement:z,...V.trim()===``?{}:{integrationId:V.trim()}})},ye=()=>{let e=cl(Object.keys(j));M(t=>({...t,[e]:``})),R(e),oe(e),ce(e)},be=e=>{oe(e),ce(e)},xe=()=>{if(ae===null)return;let e=ae,t=se.trim();if(oe(null),!(t===``||t===e)){if(j[t]!==void 0){R(t);return}M(n=>{let r={};for(let[i,a]of Object.entries(n))r[i===e?t:i]=a;return r}),P===e&&F(t),R(t)}},Se=async e=>{let t=sl.find(t=>t.id===e);if(t===void 0)return;let n=sl.find(e=>e.id===`blank`);!(n!==void 0&&JSON.stringify(j)===JSON.stringify(n.files)&&P===n.entry)&&!await y({title:g(`build.blockEditor.loadExample`,`Load example`),message:g(`build.blockEditor.replaceTheCurrentEditorContents`,`Replace the current editor contents with this example?`),confirmLabel:g(`build.blockEditor.replace`,`Replace`),variant:`warning`})||(ie(e),M({...t.files}),F(t.entry),R(t.entry),(w.trim()===``||U===`blank`)&&T(t.id===`blank`?``:t.name))},Ce=t===null?null:Ma(t),we=ul({existing:t,dirty:_e,saving:a,restarting:l});return e(`div`,{className:`space-y-4`,children:[Ce!==null&&o(`div`,{className:`flex flex-wrap items-center gap-2`,children:o(K,{variant:Na(Ce.tone),children:Ce.label})}),e(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[e(`label`,{className:`block text-sm`,children:[o(`span`,{className:`text-foreground-subtle`,children:g(`build.blockEditor.name`,`Name`)}),o(J,{className:`mt-1`,value:w,onChange:e=>T(e.target.value),placeholder:g(`build.blockEditor.whatThisScriptDoes`,`What this script does`)})]}),e(`label`,{className:`block text-sm`,children:[o(`span`,{className:`text-foreground-subtle`,children:g(`build.blockEditor.integrationOptional`,`Integration (optional)`)}),o(J,{className:`mt-1`,value:V,onChange:e=>H(e.target.value),placeholder:g(`build.blockEditor.leaveEmptyForTheShared`,`Leave empty for the shared system integration`)})]})]}),t===null&&de&&e(`label`,{className:`block text-sm`,children:[o(`span`,{className:`text-foreground-subtle`,children:g(`build.blockEditor.startFrom`,`Start from`)}),o(k,{className:`mt-1 w-full`,value:U,onChange:e=>void Se(e.target.value),"data-testid":`script-example-select`,children:sl.map(t=>e(`option`,{value:t.id,children:[t.name,` — `,t.description]},t.id))})]}),e(`div`,{children:[o(wt,{selectedNodeId:z,onSelect:B,label:g(`build.blockEditor.runsOn`,`Runs on`),alwaysShow:!0}),z!==Sl&&e(`p`,{className:`mt-2 flex items-start gap-2 text-xs text-warning`,children:[o(C,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),o(`span`,{children:o(Jt,{i18nKey:`build.blockEditor.hubOnlyWarning`,components:{strong:o(`strong`,{})}})})]})]}),e(`div`,{className:`flex min-h-[56vh] flex-col rounded border border-border`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border px-2 py-1.5`,children:[ue.map(t=>ae===t?o(J,{value:se,onChange:e=>ce(e.target.value),onBlur:()=>xe(),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),xe()),e.key===`Escape`&&(e.preventDefault(),oe(null))},className:`h-7 w-36 px-2 py-0 text-xs`,autoFocus:!0,"data-testid":`script-file-rename`,"aria-label":g(`build.blockEditor.renameFile`,`Rename file`)},t):e(Y,{variant:`unstyled`,type:`button`,className:`rounded px-2 py-1 text-xs ${t===L?`bg-muted font-medium text-foreground`:`text-foreground-subtle hover:text-foreground`}`,onClick:()=>R(t),onDoubleClick:()=>be(t),title:g(`build.blockEditor.doubleClickToRename`,`Double-click to rename`),"data-testid":`script-file-tab-${t}`,children:[t,t===P?` · ${g(`build.blockEditor.entry`)}`:``]},t)),o(Y,{variant:`unstyled`,type:`button`,className:`ml-1 rounded px-2 py-1 text-xs text-foreground-subtle hover:text-foreground`,onClick:ye,"data-testid":`script-file-add`,children:g(`build.blockEditor.file`,`+ file`)}),L!==P&&o(Y,{variant:`unstyled`,type:`button`,className:`rounded px-2 py-1 text-xs text-foreground-subtle hover:text-foreground`,onClick:()=>F(L),title:g(`build.blockEditor.useThisFileAsThe`,`Use this file as the compile entry`),children:g(`build.blockEditor.setAsEntry`,`Set as entry`)})]}),i?o(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:g(`build.blockEditor.loadingTheNodeSType`,`Loading the node's type definitions…`)}):o(al,{value:le,onChange:W,path:`file:///${L}`,extraLibs:fe,onDiagnostics:te,dark:b===`dark`,heightPx:560})]}),n!==void 0&&n.libs.length===0&&o(`p`,{className:`text-xs text-warning`,children:g(`build.blockEditor.theNodeReturnedNoType`,`The node returned no type definitions, so this code is NOT being checked against the system's types. The server-side compile still applies on save.`)}),pe.length>0&&e(`div`,{className:`space-y-1 rounded border border-danger/40 bg-danger/10 p-3 text-xs`,children:[o(`p`,{className:`font-medium text-danger`,children:g(`build.blockEditor.errorsCannotSave`,{count:pe.length})}),pe.slice(0,5).map(e=>o(`p`,{className:`text-danger`,children:g(`build.blockEditor.diagnosticLine`,{line:e.line,message:e.message})},`${String(e.line)}:${String(e.column)}:${e.message}`)),pe.length>5&&o(`p`,{className:`text-foreground-subtle`,children:g(`build.blockEditor.moreErrors`,{count:pe.length-5})})]}),G.data!==void 0&&(G.data.ok?e(`p`,{className:`flex items-center gap-2 text-xs text-success`,children:[o(v,{className:`h-3.5 w-3.5`}),` `,g(`build.blockEditor.compiledOk`)]}):e(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[G.data.line!==void 0&&o(`span`,{className:`mr-1`,children:g(`build.blockEditor.errorLine`,{line:String(G.data.line)})}),G.data.error??g(`build.blockEditor.theCodeDoesNotCompile`,`the code does not compile`)]})),G.error!==null&&e(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[g(`build.blockEditor.couldNotReachTheCompiler`,`Could not reach the compiler:`),` `,wl(G.error)]}),s!==null&&o(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:s}),u!==null&&o(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:u}),t!==null&&e(`div`,{className:`space-y-3`,children:[o(xl,{blockId:t.id}),o(pl,{blockId:t.id})]}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(Y,{variant:`outline`,onClick:()=>G.mutate(),disabled:G.isPending||a,title:g(`build.blockEditor.typeCheckOnTheNode`,`Type-check on the node without saving`),children:[G.isPending&&o(A,{className:`h-4 w-4 animate-spin`}),` `,g(`common.compile`)]}),e(Y,{onClick:ve,disabled:a||me||he,children:[a&&o(A,{className:`h-4 w-4 animate-spin`}),` `,g(`common.save`)]}),e(Y,{variant:`outline`,onClick:()=>d?.(),disabled:we!==null||d===void 0,title:we??g(`build.blockEditor.stopTheProcessAndLet`,`Stop the process and let the supervisor bring it back`),children:[l?o(O,{className:`h-4 w-4 animate-spin`}):o(O,{className:`h-4 w-4`}),` `,g(`build.blockEditor.restart`,`Restart`)]}),e(Y,{variant:`ghost`,onClick:()=>re(!ne),title:g(`build.blockEditor.showThisScriptSProcess`,`Show this script's process logs`),"data-testid":`script-logs-toggle`,"aria-expanded":ne,children:[o(S,{className:`h-4 w-4`}),` `,g(`common.logs`),` `,o(_t,{expanded:ne})]}),o(Y,{variant:`ghost`,onClick:h,disabled:a,children:g(`common.close`,`Close`)}),e(`span`,{className:`ml-auto text-xs text-foreground-subtle`,children:[g(`build.blockEditor.errorsCount`,{count:pe.length}),_e&&t!==null?` · ${g(`build.blockEditor.unsavedChanges`)}`:``]}),he&&o(K,{variant:`warning`,children:g(`build.blockEditor.nameRequired`,`Name required`)})]}),ne&&e(`div`,{className:`rounded border border-border`,"data-testid":`script-logs-panel`,children:[o(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:t===null?g(`build.blockEditor.logsAppearOnceTheScript`,`Logs appear once the script has been saved and started.`):o(p,{children:o(Jt,{i18nKey:`build.blockEditor.logsOf`,values:{id:I(t.id)},components:{code:o(`code`,{})}})})}),t!==null&&o(ft,{addonId:I(t.id),maxHeight:`max-h-[560px]`,showFilters:!1})]})]})}function wl(e){return e instanceof Error?e.message:String(e)}u();var Tl=[`coreBlocks`,`list`],El=[`coreBlocks`,`getTypeDefs`],Dl=5e3;function Ol(e){return e instanceof Error?e.message:String(e)}function kl({initialBlockId:t,onBlockIdChange:i,createRequested:a=!1,onCreateConsumed:u}={}){let d=b(),{t:p}=Z(),m=D(),{state:h,openNew:g,openEdit:v,close:y}=Rt({editKey:`block`,newKey:`new`}),[x,C]=c(null),w=E(),[T,k]=c(null),A=l({queryKey:Tl,refetchInterval:Dl,queryFn:async()=>(await m.trpcClient.coreBlocks.list.query({})).blocks}),j=h.mode!==`closed`,M=l({queryKey:El,enabled:j,staleTime:1/0,gcTime:1/0,queryFn:()=>m.trpcClient.coreBlocks.getTypeDefs.query({})}),N=()=>{A.refetch()},P=n(null),F=A.data;s(()=>{t===void 0||P.current===t||F?.find(e=>e.id===t&&he(e)===`code`)!==void 0&&(P.current=t,v(t),i?.(t))},[t,F,v,i]),s(()=>{a&&(C(null),g(),i?.(null),u?.())},[a,u,i,g]);let L=f({mutationFn:e=>m.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{C(e.block),v(e.block.id),i?.(e.block.id),N()}}),R=f({mutationFn:e=>m.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{C(e.block),v(e.block.id),i?.(e.block.id),N()}}),z=f({mutationFn:e=>m.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:N}),B=f({mutationFn:e=>m.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:N}),V=f({mutationFn:e=>m.trpcClient.coreBlocks.restart.mutate({blockId:e}),onSuccess:N}),H=Fa((A.data??[]).filter(e=>he(e)===`code`)),ee=A.data!==void 0&&H.length===0,te=L.isPending||R.isPending,ne=L.error===null?R.error===null?null:Ol(R.error):Ol(L.error),re=h.mode===`edit`?H.find(e=>e.id===h.id)??(x!==null&&x.id===h.id?x:null):null,U=h.mode===`new`||re===null?null:Pa(H,re),ie=r(()=>[{key:`name`,header:p(`build.scriptsTab.name`,`Name`),render:t=>{let n=Ma(t),r=At(t.updatedAt,d);return e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(`span`,{className:`truncate font-medium`,children:t.name}),o(K,{variant:Na(n.tone),children:n.label}),o(K,{variant:`info`,children:t.placement}),r!==null&&o(`span`,{className:`text-xs text-foreground-subtle`,children:p(`common.edited`,{when:r})})]}),o(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:n.detail}),T===t.id&&e(`div`,{className:`mt-2 rounded border border-border`,children:[o(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:o(Jt,{i18nKey:`common.logsOf`,values:{id:I(t.id)},components:{code:o(`code`,{})}})}),o(ft,{addonId:I(t.id),maxHeight:`max-h-64`,showFilters:!1})]})]})},sortValue:e=>e.name,nowrap:!1},{key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,render:t=>{let n=B.isPending||z.isPending,r=V.isPending&&V.variables===t.id;return e(`div`,{className:`flex justify-end gap-1`,children:[o(Y,{variant:`ghost`,onClick:e=>{e.stopPropagation(),C(t),v(t.id),i?.(t.id)},title:p(`common.edit`,`Edit`),children:p(`common.edit`,`Edit`)}),o(Y,{variant:`ghost`,onClick:e=>{e.stopPropagation(),V.mutate(t.id)},disabled:n||r||!t.enabled,title:t.enabled?p(`build.scriptsTab.restart`,`Restart`):p(`build.scriptsTab.enableItInsteadADisabled`,`Enable it instead — a disabled script has no process`),children:o(O,{className:`h-4 w-4${r?` animate-spin`:``}`})}),o(Y,{variant:`ghost`,onClick:e=>{e.stopPropagation(),k(T===t.id?null:t.id)},title:p(`build.scriptsTab.logs`,`Logs`),children:o(S,{className:`h-4 w-4`})}),o(Y,{variant:`ghost`,onClick:e=>{e.stopPropagation(),B.mutate({blockId:t.id,enabled:!t.enabled})},disabled:n,title:t.enabled?p(`common.disable`,`Disable`):p(`common.enable`,`Enable`),children:t.enabled?p(`common.disable`,`Disable`):p(`common.enable`,`Enable`)}),o(Y,{variant:`ghost`,onClick:e=>{e.stopPropagation(),w({title:p(`build.scriptsTab.deleteThisScript`,`Delete this script?`),message:p(`build.scriptsTab.deleteMessage`,`{{name}} and its source will be deleted. This cannot be undone.`,{name:t.name}),confirmLabel:p(`common.delete`,`Delete`),variant:`danger`}).then(e=>{e&&z.mutate(t.id)})},title:p(`common.delete`,`Delete`),children:o(_,{className:`h-4 w-4`})})]})}}],[w,T,i,v,z,V.isPending,V.variables,B,p]);return e(`div`,{className:`space-y-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:A.data===void 0?``:Ia(H)}),A.error!=null&&o(q,{title:p(`build.scriptsTab.couldNotReadTheScripts`,`Could not read the scripts`),message:Ol(A.error),onRetry:N}),o(Qe,{columns:ie,rows:H,rowKey:e=>e.id,pageSize:25,maxBodyHeight:Ht,emptyMessage:ee?p(`build.scriptsTab.noScriptsYetAScript`,`No scripts yet. A script is TypeScript the hub runs in its own process.`):A.data===void 0?p(`build.scriptsTab.loadingScripts`,`Loading scripts…`):p(`build.scriptsTab.noScriptsYet`,`No scripts yet.`),onRowClick:e=>{C(e),v(e.id),i?.(e.id)}}),o(Fe,{open:j,onClose:()=>{L.reset(),R.reset(),V.reset(),C(null),y(),i?.(null)},title:U===null?p(`build.scriptsTab.newScript`,`New script`):p(`build.scriptsTab.edit`,`Edit {{name}}`,{name:U.name}),icon:Oe,width:`xl`,testId:`script-editor-panel`,children:o(Cl,{existing:U,typeDefs:M.data,typeDefsLoading:M.isLoading,saving:te,saveError:ne,restarting:V.isPending,restartError:V.error===null?null:Ol(V.error),onRestart:U===null?void 0:()=>V.mutate(U.id),onSave:e=>{let t=U;t===null?L.mutate(e):R.mutate({blockId:t.id,block:e})},onCancel:()=>{L.reset(),R.reset(),V.reset(),C(null),y(),i?.(null)}})}),z.error!=null&&o(q,{message:Ol(z.error)}),B.error!=null&&o(q,{message:Ol(B.error)}),V.error!=null&&o(q,{message:Ol(V.error)})]})}var Al=[`automations`,`actions`,`schedulers`,`scripts`,`custom-device`];function jl(e){return e!==null&&Al.some(t=>t===e)}var Ml=[`coreBlocks`,`list`,`build-counts`],Nl=[`schedulers`,`list`,`build-counts`],Pl=[`actions`,`list`,`build-counts`],Fl=[`block`,`action`,`scheduler`,`create`,`new`];function Il(e){return e.filter(e=>he(e)===`code`).length}function Ll(e){return e.filter(e=>Kn(e.code)).length}function Rl(e,t){return t===null?e:`${e} (${String(t)})`}function zl(){let{t}=Z(),n=D(),[r,i]=Gt(),a=r.get(`tab`),s=jl(a)?a:`automations`,c=r.get(`create`)===`1`,u=l({queryKey:Ml,refetchInterval:5e3,queryFn:async()=>(await n.trpcClient.coreBlocks.list.query({})).blocks}).data,d=u===void 0?null:Il(u),f=u===void 0?null:Ll(u),p=l({queryKey:Pl,refetchInterval:1e4,queryFn:async()=>n.trpcClient.actions.list.query({})}),m=p.data===void 0?null:p.data.length,h=l({queryKey:Nl,refetchInterval:1e4,queryFn:async()=>n.trpcClient.schedulers.list.query({})}),g=h.data===void 0?null:h.data.length,_=l({queryKey:[`coreBlocks`,`listCompositions`,`build-counts`],refetchInterval:1e4,queryFn:async()=>n.trpcClient.coreBlocks.listCompositions.query({})}),v=_.data?.state===`loaded`?_.data.views.length:null,y=e=>{i(t=>{let n=new URLSearchParams(t);return n.set(`tab`,`scripts`),n.delete(`create`),e===void 0?n.delete(`block`):n.set(`block`,e),n},{replace:!0})},b=e=>{i(t=>{let n=new URLSearchParams(t);return n.set(`tab`,`scripts`),n.delete(`create`),e===null?n.delete(`block`):n.set(`block`,e),n},{replace:!0})},x=()=>{i(e=>{let t=new URLSearchParams(e);return t.set(`create`,`1`),t.delete(`block`),t},{replace:!0})},S=e=>{i(()=>{let t=new URLSearchParams(window.location.search);return t.set(`tab`,`custom-device`),t.delete(`block`),t.delete(`create`),t.set(`new`,e),t},{replace:!0})},C=()=>{i(()=>{let e=new URLSearchParams(window.location.search);return e.delete(`create`),e},{replace:!0})},T=s===`automations`?t(`build.newAutomation`,`New automation`):s===`actions`?t(`build.newAction`,`New action`):s===`schedulers`?t(`build.newScheduler`,`New scheduler`):t(`build.newScript`,`New script`),E=Xt(`/build`,{t,isAdmin:!0})??{icon:j,title:t(`nav.build`,`Build-your-self`)};return o(tn,{icon:E.icon,title:E.title,subtitle:t(`build.automationsScriptsAndComposedDevices`,`Automations, scripts and composed devices — what this installation does on its own.`),defaultSection:`automations`,sectionsLabel:`${E.title} sections`,fill:!0,actions:s===`custom-device`?e(Y,{type:`button`,onClick:()=>S(`helper`),"data-testid":`build-new-composed`,children:[o(w,{className:`h-4 w-4`}),` `,t(`helper.newComposed`)]}):e(Y,{type:`button`,onClick:x,"data-testid":`build-new`,children:[o(w,{className:`h-4 w-4`}),` `,T]}),sections:[{id:`automations`,label:Rl(t(`build.tabAutomations`,`Automations`),f),ownedParams:Fl,content:o(Ya,{onOpenScripts:y,createRequested:s===`automations`&&c,onCreateConsumed:C})},{id:`actions`,label:Rl(t(`build.tabActions`,`Actions`),m),ownedParams:Fl,content:o(jr,{createRequested:s===`actions`&&c,onCreateConsumed:C})},{id:`schedulers`,label:Rl(t(`build.tabSchedulers`,`Schedulers`),g),ownedParams:Fl,content:o(No,{createRequested:s===`schedulers`&&c,onCreateConsumed:C})},{id:`scripts`,label:Rl(t(`build.tabCode`,`Code`),d),ownedParams:Fl,content:o(kl,{initialBlockId:s===`scripts`?r.get(`block`)??void 0:void 0,onBlockIdChange:b,createRequested:s===`scripts`&&c,onCreateConsumed:C})},{id:`custom-device`,label:Rl(t(`build.tabCustomDevice`,`Custom Device`),v),ownedParams:Fl,content:o(ys,{createRequested:s===`custom-device`&&c,onCreateConsumed:C})}]})}export{zl as BuildPage};
|