@camstack/addon-admin-ui 1.2.523 → 1.2.524
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/{AddonAssetIcon-VXnpNoSj.js → AddonAssetIcon-CYhJlTNc.js} +1 -1
- package/dist/assets/Addons-BRZelwav.js +5 -0
- package/dist/assets/{AdminPage-B9JLs4rT.js → AdminPage-B1Q3Lunl.js} +1 -1
- package/dist/assets/{AdminSectionedPage-EY_w3HY7.js → AdminSectionedPage-CDZfKkL5.js} +1 -1
- package/dist/assets/AiProfiles-DC8OxOmV.js +3 -0
- package/dist/assets/BrokerEditorDialog-BX5w7CMy.js +1 -0
- package/dist/assets/Build-BVaH843t.js +40 -0
- package/dist/assets/{Calendars-ClQsQ24o.js → Calendars-q3MUFOBU.js} +1 -1
- package/dist/assets/Cluster-BKvY1r-a.js +1 -0
- package/dist/assets/ComposedDeviceEditDialog-BLfm22uf.js +1 -0
- package/dist/assets/CompositionBlockEditor-CJhCzXua.js +2 -0
- package/dist/assets/{CompositionEditorPage-NlrSqavW.js → CompositionEditorPage-dOMxAK9V.js} +1 -1
- package/dist/assets/Data-BVPL4yIo.js +2 -0
- package/dist/assets/DeviceDetail-BO5_O1mV.js +2 -0
- package/dist/assets/{DeviceDoActionFields-CSKUhZmq.js → DeviceDoActionFields-B50ODgPq.js} +1 -1
- package/dist/assets/{Devices-DtEGEpYK.js → Devices-CrdlW5-A.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-Er_9ZZbp.js → EmbedPlayerPage-JBC0G-2I.js} +1 -1
- package/dist/assets/History-BP1mlcwA.js +1 -0
- package/dist/assets/Identity-CY_zYbdN.js +1 -0
- package/dist/assets/IntegrationDetail-DCjuDqWm.js +1 -0
- package/dist/assets/IntegrationHub-DE2mwBdj.js +1 -0
- package/dist/assets/Integrations-BmHL7d-i.js +1 -0
- package/dist/assets/Integrations-CKAi9srg.js +1 -0
- package/dist/assets/{Library-CWzUsm1c.js → Library-BrWQ54N7.js} +1 -1
- package/dist/assets/Locations-3qWlGxP3.js +3 -0
- package/dist/assets/{Logs-CkwhOBrz.js → Logs-DYi_B3vg.js} +1 -1
- package/dist/assets/{MaskShapeCanvas-B_J8Nub8.js → MaskShapeCanvas-D8Ke0Dim.js} +1 -1
- package/dist/assets/{MotionZonesSettings-DSDOgPiK.js → MotionZonesSettings--YqW3Onz.js} +1 -1
- package/dist/assets/MyAccess-DswPvXxB.js +2 -0
- package/dist/assets/Network-ChYmByS2.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-CNSfsu26.js → NodeAddonsSettingsPanel-DtvhgNC4.js} +1 -1
- package/dist/assets/Notifications-5onsUC_w.js +1 -0
- package/dist/assets/Pipeline-CgmB5Be8.js +1 -0
- package/dist/assets/{PrivacyMaskSettings-Zr9fXd19.js → PrivacyMaskSettings-B-vpuYKA.js} +1 -1
- package/dist/assets/Recordings-Bglrn4rQ.js +1 -0
- package/dist/assets/RemoteGrid-C_9BszV-.js +1 -0
- package/dist/assets/{ScanNetworkModal-BO8EFEZ1.js → ScanNetworkModal-BnhOMFd1.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-CvqEBzUw.js → SceneMonitorEditor-CkaBEtmE.js} +1 -1
- package/dist/assets/SessionsList--FQem8XB.js +2 -0
- package/dist/assets/{Showroom-ClQBf_59.js → Showroom-B9J1IdLQ.js} +1 -1
- package/dist/assets/{System-d-rVWfA6.js → System-BVE97mrs.js} +1 -1
- package/dist/assets/Templates-CvoAkIdF.js +1 -0
- package/dist/assets/{Terminal-dvCiPiu7.js → Terminal-ieNh6d83.js} +5 -5
- package/dist/assets/{Viewer-D04RI6WE.js → Viewer-CAf7sAU0.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CO8DU_dY.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Bi1zqe4S.js} +1 -1
- package/dist/assets/{addon-icons-context-BsBIxYDH.js → addon-icons-context-RPiI9H0L.js} +1 -1
- package/dist/assets/{archive-Do2e48DU.js → archive-DQvuyIac.js} +1 -1
- package/dist/assets/{assignment-candidates-8RM__6oC.js → assignment-candidates-83kFfE1Z.js} +1 -1
- package/dist/assets/{authed-media-BYa-9dIZ.js → authed-media-BSoR_xYF.js} +1 -1
- package/dist/assets/{bell-off-RPYQoGP1.js → bell-off-C3u183tq.js} +1 -1
- package/dist/assets/{board-model-C9BgTio0.js → board-model-sARab1AV.js} +1 -1
- package/dist/assets/{boxes-BEverhi4.js → boxes-CVkAEP7e.js} +1 -1
- package/dist/assets/circle-slash-C86XHeiD.js +1 -0
- package/dist/assets/client-DcvpIFoh.js +674 -0
- package/dist/assets/{cloud-upload-nVfWiPdO.js → cloud-upload-CHQjI4ZF.js} +1 -1
- package/dist/assets/crop-Ct8elLRy.js +1 -0
- package/dist/assets/{device-integration-icon-C2pH_5Gl.js → device-integration-icon-DCuiIOlj.js} +1 -1
- package/dist/assets/device-picker-model-BvJkcx-a.js +1 -0
- package/dist/assets/{dist-BVH-vBQM.js → dist-B5lzpDFY.js} +1 -1
- package/dist/assets/{dist-ByEQfnSV.js → dist-BSrNHoV1.js} +1 -1
- package/dist/assets/{file-up-CUjXrmMK.js → file-up-C9_pj2VT.js} +1 -1
- package/dist/assets/{format-BccZ2tds.js → format-DGQA45Ye.js} +1 -1
- package/dist/assets/grip-vertical-C_VoFjYu.js +1 -0
- package/dist/assets/{hard-drive-download-DiXdli_I.js → hard-drive-download-DiC0khcq.js} +1 -1
- package/dist/assets/{hostInit-Bta217FF.js → hostInit-Dq6hIrVo.js} +1 -1
- package/dist/assets/{i18n-COiZcYwm.js → i18n-C-H4BlYV.js} +1 -1
- package/dist/assets/icons-C7pfBl-Q.js +1 -0
- package/dist/assets/index-DjwiZ7qT.css +2 -0
- package/dist/assets/index-o6kBNilE.js +4 -0
- package/dist/assets/{key-C0PivC5X.js → key-Cz6uvkUc.js} +1 -1
- package/dist/assets/{key-round-Cu5Tucyk.js → key-round-B9WTP907.js} +1 -1
- package/dist/assets/{layers-Cd1UYZNk.js → layers-DGMlfnn4.js} +1 -1
- package/dist/assets/{linked-devices-model-CFrDp7fw.js → linked-devices-model-D6PgoQtW.js} +1 -1
- package/dist/assets/{list-ordered-Bkr6PCeB.js → list-ordered-wHEw5a_e.js} +1 -1
- package/dist/assets/location-owned-usage-B-4MuD-Z.js +1 -0
- package/dist/assets/{log-in-DV8GfIgr.js → log-in-Da7IGp_j.js} +1 -1
- package/dist/assets/{memory-stick-C6TRN6ht.js → memory-stick-BLbgKSl7.js} +1 -1
- package/dist/assets/{message-square-plus-DTJ5QsLH.js → message-square-plus-CMdSHNUk.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-c0dc6497.js → mf-entry-bootstrap-0-e016a0f6.js} +2 -2
- package/dist/assets/{mic-off-gUMH3Z4J.js → mic-off-CIzR-elk.js} +1 -1
- package/dist/assets/{monitor-off-C4w1KSTZ.js → monitor-off-lToaeJ-K.js} +1 -1
- package/dist/assets/{monitor-smartphone-CpCqKvAV.js → monitor-smartphone-Dr1ELple.js} +1 -1
- package/dist/assets/mount-BvJkcx-a.js +1 -0
- package/dist/assets/{player-overlays-CZbAbeZY.js → player-overlays-oTS1TZZY.js} +1 -1
- package/dist/assets/{recycle-BaznD-UX.js → recycle-BNUPyJ7u.js} +1 -1
- package/dist/assets/remoteEntry-BK4ei3jy.js +1 -0
- package/dist/assets/{ruler-BSo-rKM0.js → ruler-CvDT4Z7Y.js} +1 -1
- package/dist/assets/{scan-eye-DN1vlvLP.js → scan-eye-BhxGMB3E.js} +1 -1
- package/dist/assets/{scissors-CC58_qMU.js → scissors-C-pdrglA.js} +1 -1
- package/dist/assets/{search-x-tQuhnR8q.js → search-x-wBrdZZXu.js} +1 -1
- package/dist/assets/{send-CAZEgHzo.js → send-D5hwnH6i.js} +1 -1
- package/dist/assets/{settings-2-BuBH9G2o.js → settings-2-D64sFGFI.js} +1 -1
- package/dist/assets/{shapes-D2hlOKTD.js → shapes-HTfCvSL2.js} +1 -1
- package/dist/assets/{sigma-Ceyn_S95.js → sigma-BYdS13dc.js} +1 -1
- package/dist/assets/{speaker-BRYEJSzP.js → speaker-DCCyafUF.js} +1 -1
- package/dist/assets/src-XEHc18wE.js +67 -0
- package/dist/assets/{step-inspector-model-BfR3NdqL.js → step-inspector-model-a05i0m0c.js} +1 -1
- package/dist/assets/{table-2-CuSc759e.js → table-2-BgDon14h.js} +1 -1
- package/dist/assets/{timer-reset-Bvn2aK40.js → timer-reset-Dst_i1Qg.js} +1 -1
- package/dist/assets/{unlink-BU_py8I2.js → unlink-CmmNdYky.js} +1 -1
- package/dist/assets/{usb-TZrC9eYC.js → usb-BCFcIAg4.js} +1 -1
- package/dist/assets/{use-device-bound-caps-CYR80PtH.js → use-device-bound-caps-CI6zlnII.js} +1 -1
- package/dist/assets/{use-scenes-feed-Ddftx740.js → use-scenes-feed-junBfGeR.js} +1 -1
- package/dist/assets/{use-stationary-objects-CJ3xxs43.js → use-stationary-objects-blP9Y5SS.js} +1 -1
- package/dist/assets/useEventInvalidation-BvJkcx-a.js +1 -0
- package/dist/assets/{useNodeUrlSelection-DNEz-JoD.js → useNodeUrlSelection-Cb470tqR.js} +1 -1
- package/dist/assets/user-round-D3ZUZuP3.js +1 -0
- package/dist/assets/{user-x-CYHlbR6F.js → user-x-891p2Gny.js} +1 -1
- package/dist/assets/{variable-BNQlwoos.js → variable-HM7A54CP.js} +1 -1
- package/dist/assets/{video-CrmOxhYy.js → video-Dx3E7zlj.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Bucq-FfY.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DHe9cBRl.js} +2 -2
- package/dist/index.html +10 -10
- package/dist/server/addon.js +43 -6
- package/package.json +1 -1
- package/dist/assets/Addons-DlINdzv0.js +0 -5
- package/dist/assets/AiProfiles-fuyzr8D4.js +0 -3
- package/dist/assets/BrokerEditorDialog-DoEQXizE.js +0 -1
- package/dist/assets/Build-CvZFLBc9.js +0 -40
- package/dist/assets/Cluster-D31IV0wr.js +0 -1
- package/dist/assets/ComposedDeviceEditDialog-Chymp38w.js +0 -1
- package/dist/assets/CompositionBlockEditor-CpPHLcVD.js +0 -2
- package/dist/assets/Data-BBsE7UVR.js +0 -2
- package/dist/assets/DeviceDetail-zZcKfcTs.js +0 -2
- package/dist/assets/History-DEuMaAFu.js +0 -1
- package/dist/assets/Identity-Bo-ulITU.js +0 -1
- package/dist/assets/IntegrationDetail-IopkO40B.js +0 -1
- package/dist/assets/IntegrationHub-CaKFrwmD.js +0 -1
- package/dist/assets/Integrations-B0XFfGvM.js +0 -1
- package/dist/assets/Integrations-DrmJI4oI.js +0 -1
- package/dist/assets/Locations-CUYgtHWg.js +0 -3
- package/dist/assets/MyAccess-kZWZLQ6w.js +0 -2
- package/dist/assets/Network-CsAvssW1.js +0 -1
- package/dist/assets/Notifications-eEXyaFax.js +0 -1
- package/dist/assets/Pipeline-CL-VwLPy.js +0 -1
- package/dist/assets/Recordings-BrITac0q.js +0 -1
- package/dist/assets/RemoteGrid-BGbiDThN.js +0 -1
- package/dist/assets/SessionsList-BkbXjQt1.js +0 -2
- package/dist/assets/Templates-BY9R_5lz.js +0 -1
- package/dist/assets/circle-slash-Bb_aa_QL.js +0 -1
- package/dist/assets/client-D-g0nOrC.js +0 -674
- package/dist/assets/crop-DVR1vsA9.js +0 -1
- package/dist/assets/device-picker-model-DBfk1Co5.js +0 -1
- package/dist/assets/icons-CDeaov6N.js +0 -1
- package/dist/assets/index-DnHMM2c9.css +0 -2
- package/dist/assets/index-Dqmlzvdc.js +0 -4
- package/dist/assets/location-owned-usage-E6eX4phu.js +0 -1
- package/dist/assets/mount-DBfk1Co5.js +0 -1
- package/dist/assets/remoteEntry-8jIMK97P.js +0 -1
- package/dist/assets/src-iRjUEwun.js +0 -67
- package/dist/assets/useEventInvalidation-DBfk1Co5.js +0 -1
- package/dist/assets/user-round-jCdxL4f8.js +0 -1
|
@@ -0,0 +1,40 @@
|
|
|
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{Ar as m,Ei as h,Fn as g,Ht as _,In as v,Ni as y,Oi as b,Tr as x,Vn as S,bi as C,dt as w,ea as T,fr as E,ia as D,ma as O,mr as k,st as A,vt as j,wn as M,yn as N,zt as P}from"./player-overlays-oTS1TZZY.js";import{$i as F,Aa as I,Ai as L,Ca as R,Da as z,Ea as ee,Hi as B,Ja as V,Ko as te,Ma as ne,Mi as re,Ni as ie,Oa as ae,Pa as H,Sa as oe,Ta as se,Ya as ce,Yi as le,aa as ue,ja as de,jo as fe,ka as pe,nn as U,ra as W,wa as me,xa as he}from"./client-DcvpIFoh.js";import{t as ge}from"./boxes-CVkAEP7e.js";import{i as _e,n as ve,r as ye,t as be}from"./variable-HM7A54CP.js";import{s as xe}from"./video-Dx3E7zlj.js";import{$a as Se,Ad as G,An as Ce,B as we,Ci as Te,Cr as Ee,Ct as De,Dd as Oe,Ei as ke,Fd as K,Fo as Ae,Ga as je,Ir as Me,Ka as Ne,Md as Pe,Nd as Fe,Nr as q,On as Ie,Or as Le,Pd as Re,Pr as ze,Qa as Be,Qd as Ve,R as He,Si as Ue,Tr as We,Ua as Ge,Vo as Ke,Vr as qe,Wa as Je,Wr as Ye,Ya as Xe,Za as Ze,Zn as Qe,Zt as $e,_t as et,bi as tt,cn as nt,ct as rt,di as J,dn as it,ef as at,eo as ot,jn as st,jo as ct,nn as lt,oi as ut,ri as Y,rn as dt,rs as ft,wi as pt,wn as mt,wr as ht,xr as gt,yi as _t,yr as vt,yt}from"./src-XEHc18wE.js";import{t as X}from"./i18n-C-H4BlYV.js";import{t as Z}from"./useTranslation-BJr-n0es.js";import{L as bt,T as xt,_r as St,h as Ct,lr as wt,m as Tt,mr as Et,pr as Dt,yr as Ot}from"./index-o6kBNilE.js";import{t as kt}from"./AdminSectionedPage-CDZfKkL5.js";import{n as At}from"./format-DGQA45Ye.js";import{a as jt,c as Mt,i as Nt,l as Pt,n as Ft,o as It,r as Lt,s as Rt,t as zt}from"./ComposedDeviceEditDialog-BLfm22uf.js";import{C as Bt,G as Vt,Q as Ht,Y as Ut,a as Wt,at as Gt,b as Kt,g as qt,i as Jt,n as Yt,nt as Xt,o as Zt,r as Qt,w as $t,y as en}from"./CompositionBlockEditor-CJhCzXua.js";var tn=`const AUTOMATION_RECIPE =`,nn=`// 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 rn(e){return e.includes(tn)}function an(e){let t=e.indexOf(tn);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 on(e){let t=an(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=ae.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 sn(e){let t=an(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)}${nn}${e.slice(i)}`}u();var cn={ran:`success`,failed:`danger`,aborted:`danger`,"skipped-trigger":`neutral`,"skipped-conditions":`warning`,"skipped-cooldown":`neutral`,"skipped-overlap":`neutral`},ln={pass:`border-success/50 bg-success/10`,fail:`border-danger/50 bg-danger/10`,idle:`border-border bg-surface text-foreground-subtle`},un={pass:`text-success`,fail:`text-danger`,idle:`text-foreground-subtle`};function dn(){let{t:e}=Z();return t=>{switch(t){case`ran`:return e(`flow.runs.outcomeRan`,`Ran`);case`failed`:return e(`flow.runs.outcomeFailed`,`Failed`);case`aborted`:return e(`flow.runs.outcomeAborted`,`Stopped`);case`skipped-trigger`:return e(`flow.runs.outcomeSkippedTrigger`,`Trigger not met`);case`skipped-conditions`:return e(`flow.runs.outcomeSkippedConditions`,`Skipped by conditions`);case`skipped-cooldown`:return e(`flow.runs.outcomeSkippedCooldown`,`Skipped by cooldown`);default:return e(`flow.runs.outcomeSkippedOverlap`,`Skipped by run mode`)}}}function fn({traces:t,selectedId:n,onSelect:r}){let{t:i}=Z(),a=dn(),s=t===void 0?[]:t.toReversed();return o(Ie,{headingId:`runs-heading`,title:i(`flow.runs.title`,`Runs`),icon:x,children:t===void 0?o(Me,{className:`m-3 h-16`}):s.length===0?o(ze,{title:i(`flow.runs.emptyTitle`,`No runs yet`),description:i(`flow.runs.emptyDescription`,`Each run appears here with what it decided.`)}):e(p,{children:[o(`ul`,{className:`divide-y divide-border-subtle`,"data-testid":`runs-panel`,children:s.map(t=>{let i=t.runId===n;return o(`li`,{children:e(`button`,{type:`button`,"aria-pressed":i,onClick:()=>r(i?null:t.runId),className:`flex w-full flex-col gap-1 px-3 py-2 text-left hover:bg-surface-hover ${i?`bg-primary/10`:``}`,children:[e(`span`,{className:`flex flex-wrap items-center gap-2`,children:[o(J,{variant:cn[t.outcome],children:a(t.outcome)}),t.repeat>1&&o(J,{variant:`neutral`,style:`outline`,children:`x${String(t.repeat)}`}),o(`span`,{className:`text-xs text-foreground-subtle`,children:At(t.lastAt)})]}),o(`span`,{className:`truncate text-sm text-foreground`,children:t.trigger.reason})]})},t.runId)})}),o(`p`,{className:`border-t border-border-subtle px-3 py-2 text-xs text-foreground-subtle`,children:i(`flow.runs.hint`,`Select a run to colour the blocks: green passed, red failed, grey not evaluated.`)})]})})}function pn(e){return ln[e]}function mn({step:t,title:n,hint:r,trace:i,children:a}){return e(`section`,{className:`rounded-lg border p-3 ${i===null?`border-border bg-surface`:ln[i.tone]}`,"data-testid":`block-${t}`,children:[e(`div`,{className:`mb-2 flex flex-wrap items-baseline gap-2`,children:[o(`h4`,{className:`text-sm font-semibold uppercase tracking-wide`,children:n}),r!==void 0&&o(`span`,{className:`text-xs text-foreground-subtle`,children:r})]}),i!==null&&i.reason!==null&&o(`p`,{className:`mb-2 text-xs font-medium ${un[i.tone]}`,children:i.reason}),o(`div`,{className:`space-y-2`,children:a})]})}function Q({children:e}){return o(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function hn(e){let t=Nt(e.deviceId);if(t.data!==void 0)return Ft(t.data,e.cap).find(t=>t.path===e.fieldPath)}function gn({value:t,devices:n,onChange:r}){let{t:i}=Z(),[a,s]=c(!1),l=n.find(e=>e.id===t.deviceId),u=t.deviceId===0?i(`automation.fieldPicker.pickAValue`,`Pick a device value…`):`${l?.name??`#${String(t.deviceId)}`}${t.cap===``?``:` · ${t.cap}.${t.fieldPath}`}`;return e(`div`,{className:`min-w-[14rem] max-w-full flex-[2]`,children:[o(Q,{children:i(`automation.fieldPicker.value`,`Device value`)}),e(Y,{variant:`outline`,className:`w-full min-w-0 justify-between`,"data-testid":`field-picker-open`,onClick:()=>s(!0),children:[o(`span`,{className:`w-0 flex-1 truncate text-left`,children:u}),o(b,{className:`size-3.5 shrink-0`})]}),a&&o(_n,{value:t,devices:n,onCancel:()=>s(!1),onConfirm:e=>{s(!1),r(e)}})]})}function _n({value:t,devices:n,onCancel:i,onConfirm:a}){let{t:s}=Z(),l=Ae({projection:`slim`}),u=r(()=>new Set(n.map(e=>e.id)),[n]),d=r(()=>e=>u.has(e.id),[u]),[f,p]=c(null),[m,h]=c(!1),[g,_]=c(t.cap===``?null:{cap:t.cap,path:t.fieldPath});!m&&l.status===`success`&&(h(!0),p(Gt(l.data).find(e=>e.id===t.deviceId)??null));let v=s(`automation.fieldPicker.title`,`Device value`);return o(vt,{open:!0,onOpenChange:e=>!e&&i(),children:e(gt,{width:`xl`,children:[o(ht,{children:o(We,{children:v})}),o(Ht,{kind:`formula`,enabled:!0,hostId:-1,destination:{cap:`automation`,targetId:`field`,title:v,pickerTargetKind:null},device:f,field:g,deviceFilter:d,onDeviceChange:p,onFieldChange:_}),e(Ee,{className:`flex flex-wrap gap-2`,children:[o(Y,{variant:`ghost`,onClick:i,children:s(`common.cancel`,`Cancel`)}),o(Y,{disabled:f===null||g===null,"data-testid":`field-picker-confirm`,onClick:()=>{f===null||g===null||a({deviceId:f.id,cap:g.cap,fieldPath:g.path})},children:s(`automation.fieldPicker.use`,`Use this value`)})]})]})})}var vn=1e4;function yn(e,t,n){let r=Object.fromEntries(Object.entries(e??{}).filter(([e])=>e!==t)),i=n===null?r:{...r,[t]:n};return Object.keys(i).length===0?void 0:i}function bn(e,t){return{kind:`action`,actionId:e.actionId,...t===void 0?{}:{variables:t}}}function xn({step:t,onChange:n}){let{t:r}=Z(),i=Te({},{refetchInterval:vn});if(i.data===void 0)return o(Me,{className:`h-8 w-64`});let a=i.data.find(e=>e.id===t.actionId),s=t.actionId!==``&&a===void 0;return e(`div`,{className:`space-y-2`,"data-testid":`run-action-step`,children:[e(`label`,{className:`block max-w-sm`,children:[o(Q,{children:r(`automation.runAction.action`,`Action`)}),o(G,{value:t.actionId,onChange:e=>n({kind:`action`,actionId:e.target.value}),options:[{value:``,label:r(`automation.runAction.pick`,`Pick an action`)},...s?[{value:t.actionId,label:r(`automation.runAction.missing`,`Missing action ({{id}})`,{id:t.actionId})}]:[],...i.data.map(e=>({value:e.id,label:e.name}))]})]}),s&&o(`p`,{className:`text-xs text-danger`,children:r(`automation.runAction.missingHint`,`This action no longer exists. Pick another, or the step will fail.`)}),(a?.variables??[]).length>0&&o(`div`,{className:`flex flex-wrap items-end gap-3`,children:(a?.variables??[]).map(e=>o(Sn,{variable:e,value:t.variables?.[e.name],onChange:r=>n(bn(t,yn(t.variables,e.name,r)))},e.name))})]})}function Sn({variable:t,value:n,onChange:r}){let{t:i}=Z(),a=t.label??t.name,s=t.default===void 0?i(`automation.runAction.required`,`required`):i(`automation.runAction.defaultIs`,`default {{value}}`,{value:String(t.default)});if(t.type===`boolean`||t.type===`select`){let c=t.type===`boolean`?[{value:`true`,label:i(`common.yes`,`Yes`)},{value:`false`,label:i(`common.no`,`No`)}]:(t.options??[]).map(e=>({value:e,label:e}));return e(`label`,{className:`block`,children:[o(Q,{children:a}),o(Mt,{widthClass:`w-40`,value:n===void 0?``:String(n),onChange:e=>{e.target.value===``?r(null):r(t.type===`boolean`?e.target.value===`true`:e.target.value)},options:[{value:``,label:s},...c]})]})}return t.type===`number`?e(`label`,{className:`block`,children:[o(Q,{children:a}),o(Pt,{className:`w-40`,placeholder:s,value:typeof n==`number`?n:void 0,onValue:r})]}):e(`label`,{className:`block`,children:[o(Q,{children:a}),o(K,{className:`w-40`,placeholder:s,value:n===void 0?``:String(n),onChange:e=>r(e.target.value===``?null:e.target.value)})]})}var Cn=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function wn(e){switch(e){case`boolean`:return[`eq`,`ne`];case`number`:return[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`];case`string`:case`enum`:return[`eq`,`ne`,`contains`,`in`];default:return Cn}}function Tn(e){switch(e){case`eq`:return X.t(`helpers.recipeParts.op_eq`);case`ne`:return X.t(`helpers.recipeParts.op_ne`);case`gt`:return X.t(`helpers.recipeParts.op_gt`);case`gte`:return X.t(`helpers.recipeParts.op_gte`);case`lt`:return X.t(`helpers.recipeParts.op_lt`);case`lte`:return X.t(`helpers.recipeParts.op_lte`);case`contains`:return X.t(`helpers.recipeParts.op_contains`);default:return X.t(`helpers.recipeParts.op_in`)}}function En(e){return wn(e).map(e=>({value:e,label:Tn(e)}))}function Dn(e){switch(e){case`device-state`:return X.t(`helpers.recipeParts.trigger_device_state`);case`device-event`:return X.t(`helpers.recipeParts.trigger_device_event`);case`schedule`:return X.t(`helpers.recipeParts.trigger_schedule`);case`stationary`:return X.t(`flow.trigger.stationary`);case`detection`:return X.t(`flow.trigger.detection`);case`interval`:return X.t(`flow.trigger.interval`);default:return X.t(`helpers.recipeParts.trigger_manual`)}}var On={triggers:[],actions:[]};function kn(e){switch(e){case`device-state`:return{kind:e,deviceId:0,cap:``,fieldPath:``};case`device-event`:return{kind:e,category:``};case`schedule`:return{kind:e,cron:`0 30 23 * * *`};case`detection`:return{kind:e,classes:[],deviceIds:[]};case`stationary`:return{kind:e,deviceIds:[],phase:`appeared`};case`interval`:return{kind:e,minutes:5};default:return{kind:`manual`}}}function An(e){switch(e){case`wait`:return{kind:e,seconds:5};case`code`:return{kind:e,code:`// runs inside this automation, with ctx in scope
|
|
4
|
+
`};case`action`:return{kind:e,actionId:``};default:return{kind:`cap`,deviceId:0,cap:``,method:``}}}function jn(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function Mn(){return{kind:`stationary-present`,deviceId:0}}function Nn(){return{kind:`expression`,expr:``,bindings:{}}}function Pn(e,t,n){return e.map((e,r)=>r===t?n:e)}function Fn(e,t){return e.filter((e,n)=>n!==t)}function In(e,t,n){let r=e[t];if(r===void 0)return e;let i=Math.min(Math.max(n,0),e.length-1);if(i===t)return e;let a=Fn(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function Ln(e,t){return{...e,triggers:[...t]}}function Rn(e,t){return{...e,actions:[...t]}}var zn=[{value:`cap`,labelKey:`automation.actionList.kindCap`},{value:`action`,labelKey:`automation.actionList.kindAction`},{value:`wait`,labelKey:`automation.actionList.kindWait`},{value:`code`,labelKey:`automation.actionList.kindCode`}];function Bn({actions:t,devices:n,devicesState:r=`answered`,allowedKinds:i,variables:a=[],stepTones:s,onChange:c}){let{t:l}=Z(),u=zn.filter(e=>i===void 0||i.includes(e.value));return e(`div`,{className:`space-y-2`,children:[t.length===0&&o(`p`,{className:`text-xs text-warning`,children:l(`automation.actionList.noActionsYetAnAutomation`,`No actions yet. An automation that does nothing is not an automation.`)}),t.map((i,d)=>e(`div`,{className:`space-y-2 rounded border p-3 ${s===void 0?`border-border`:pn(s[d]??`idle`)}`,children:[e(`div`,{className:`flex flex-wrap items-end gap-2`,children:[o(J,{variant:`default`,children:d+1}),e(`label`,{className:`w-40`,children:[o(Q,{children:l(`automation.actionList.step`,`Step`)}),o(G,{value:i.kind,onChange:e=>c(Pn(t,d,An(Vn(e.target.value)))),options:u.map(e=>({value:e.value,label:l(e.labelKey)}))})]}),e(`div`,{className:`ml-auto flex items-center gap-1`,children:[o(Y,{variant:`ghost`,disabled:d===0,onClick:()=>c(In(t,d,d-1)),title:l(`automation.actionList.runThisStepEarlier`,`Run this step earlier`),children:o(T,{className:`h-3.5 w-3.5`})}),o(Y,{variant:`ghost`,disabled:d===t.length-1,onClick:()=>c(In(t,d,d+1)),title:l(`automation.actionList.runThisStepLater`,`Run this step later`),children:o(D,{className:`h-3.5 w-3.5`})}),o(Y,{variant:`ghost`,onClick:()=>c(Fn(t,d)),title:l(`automation.actionList.removeThisStep`,`Remove this step`),children:o(_,{className:`h-3.5 w-3.5`})})]})]}),i.kind===`wait`&&e(`label`,{className:`block w-32`,children:[o(Q,{children:l(`automation.actionList.seconds`,`Seconds`)}),o(K,{type:`number`,min:0,max:300,value:String(i.seconds),onChange:e=>c(Pn(t,d,{kind:`wait`,seconds:Number(e.target.value)}))})]}),i.kind===`code`&&e(`label`,{className:`block`,children:[o(Q,{children:l(`automation.actionList.code`,`Code`)}),o(`textarea`,{className:`h-32 w-full rounded-md border border-border bg-surface p-2 font-mono text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,value:i.code,spellCheck:!1,onChange:e=>c(Pn(t,d,{kind:`code`,code:e.target.value}))}),o(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:o(Dt,{i18nKey:`automation.actionList.codeHint`,components:{code:o(`code`,{})}})})]}),i.kind===`cap`&&o(jt,{step:i,devices:n,devicesState:r,variables:a,onChange:e=>c(Pn(t,d,e))}),i.kind===`action`&&o(xn,{step:i,onChange:e=>c(Pn(t,d,e))})]},`${i.kind}-${String(d)}`)),e(`div`,{className:`flex items-center gap-2`,children:[e(Y,{variant:`outline`,onClick:()=>c([...t,An(u[0]?.value??`cap`)]),children:[o(g,{className:`h-4 w-4`}),` `,l(`automation.actionList.addStep`)]}),t.length>1&&o(`span`,{className:`text-xs text-foreground-subtle`,children:l(`automation.actionList.stepsRunInOrderAnd`,`Steps run in order and stop at the first failure.`)})]})]})}function Vn(e){return zn.find(t=>t.value===e)?.value??`cap`}function Hn(e,t){return e.map(e=>({name:e.name,hint:e.label??t(`flow.scope.type_${e.type}`,e.type)}))}function Un(e){return[{name:`deviceId`,hint:e(`flow.scope.deviceId`,`the camera that saw it`)},{name:`className`,hint:e(`flow.scope.className`,`what it saw`)},{name:`trackId`,hint:e(`flow.scope.trackId`,`the track`)},{name:`score`,hint:e(`flow.scope.score`,`how sure the detector was`)}]}function Wn(e){return[{name:`deviceId`,hint:e(`flow.scope.deviceId`,`the camera that saw it`)},{name:`className`,hint:e(`flow.scope.className`,`what it saw`)},{name:`phase`,hint:e(`flow.scope.phase`,`appeared or departed`)},{name:`entryId`,hint:e(`flow.scope.entryId`,`the stopped object`)}]}function Gn(e,t){if(e.length===0)return[];let[n,...r]=e.map(e=>e.kind===`detection`?Un(t):e.kind===`stationary`?Wn(t):[]);return n===void 0?[]:n.filter(e=>r.every(t=>t.some(t=>t.name===e.name)))}var Kn=`conditions`;function qn(e){return e===void 0||e.trim()===``?null:e}function Jn(e){let t=e.slice(e.lastIndexOf(`.`)+1),n=Number(t);return Number.isInteger(n)?n:0}function Yn(e){return e.steps.map(e=>({index:Jn(e.path),tone:e.outcome===`ok`?`pass`:e.outcome===`error`?`fail`:`idle`,message:qn(e.message)}))}function Xn(e){let t=e.conditions.find(e=>e.path===Kn);return t===void 0?null:{tone:t.outcome===`pass`?`pass`:t.outcome===`fail`?`fail`:`idle`,reason:qn(t.reason)}}function Zn(e,t){return e.outcome===`ran`?{tone:`pass`,reason:null}:e.outcome===`failed`||e.outcome===`aborted`?{tone:`fail`,reason:t.find(e=>e.tone===`fail`)?.message??null}:{tone:`idle`,reason:qn(e.verdict?.reason)}}function Qn(e){let t=Yn(e);return{when:{tone:e.trigger.outcome===`pass`?`pass`:`fail`,reason:qn(e.trigger.reason)},condition:Xn(e),thenBlock:Zn(e,t),steps:t}}function $n(e,t){return e===null?null:e.steps.find(e=>e.index===t)?.tone??`idle`}var er={name:``,steps:[],variables:[]};function tr(e){return e===null?er:{name:e.name,steps:e.steps??[],variables:e.variables??[]}}function nr(e){let t=[],n=e=>{t.includes(e)||t.push(e)},r=e=>{if(Rt(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),r(t.args));return t}function rr(e){let t=new Set(e.variables.map(e=>e.name));return nr(e.steps).find(e=>!t.has(e))??null}function ir(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=>!lr(e.name));if(t!==void 0)return{ok:!1,reason:{kind:`bad-name`,name:t.name}};let n=ur(e.variables)[0];if(n!==void 0)return{ok:!1,reason:{kind:`duplicate`,name:n}};let r=rr(e);if(r!==null)return{ok:!1,reason:{kind:`undeclared`,name:r}};let i=se.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 ar(e,t,n){return Rt(e)?e.$var===t?{$var:n}:e:Array.isArray(e)?e.map(e=>ar(e,t,n)):typeof e==`object`&&e?Object.fromEntries(Object.entries(e).map(([e,r])=>[e,ar(r,t,n)])):e}function or(e,t,n){if(e.kind!==`cap`)return e;let r=Rt(e.deviceId)&&e.deviceId.$var===t?{$var:n}:e.deviceId,i=e.args===void 0?void 0:Object.fromEntries(Object.entries(e.args).map(([e,r])=>[e,ar(r,t,n)]));return{...e,deviceId:r,...i===void 0?{}:{args:i}}}function sr(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=>or(e,r.name,n))}}function cr(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 lr(e){return/^[A-Za-z_][A-Za-z0-9_]*$/.test(e)}function ur(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]}var dr=[`number`,`string`,`boolean`,`select`];function fr(e,t){return{name:e.name,...e.label===void 0?{}:{label:e.label},type:t,...t===`select`?{options:e.options??[`option`]}:{}}}function pr(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 mr(e,t){let{default:n,...r}=e;return t===null?r:{...r,default:t}}function hr(e,t){let{label:n,...r}=e;return t.trim()===``?r:{...r,label:t}}function gr({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(Ie,{headingId:`vars-heading`,title:i(`actions.variables.title`,`Variables`),icon:be,actions:e(Y,{variant:`outline`,size:`sm`,onClick:()=>n([...t,cr(t)]),children:[o(g,{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(K,{"aria-label":i(`actions.variables.nameAria`,`Variable name`),value:c.name,"aria-invalid":!lr(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(K,{"aria-label":i(`actions.variables.label`,`Label`),value:c.label??``,onChange:e=>s(l,hr(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(Mt,{widthClass:`w-full`,"aria-label":i(`actions.variables.type`,`Type`),value:c.type,options:dr.map(e=>({value:e,label:a(e)})),onChange:e=>{let t=dr.find(t=>t===e.target.value);t!==void 0&&s(l,fr(c,t))}})]}),e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.default`,`Default`)}),o(_r,{variable:c,onChange:e=>s(l,mr(c,e))})]}),e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.options`,`Options`)}),o(K,{"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,pr(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 _r({variable:e,onChange:t}){let{t:n}=Z(),r=n(`actions.variables.default`,`Default`);if(e.type===`number`)return o(Pt,{"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(Mt,{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(K,{"aria-label":r,value:typeof e.default==`string`?e.default:``,onChange:e=>t(e.target.value===``?null:e.target.value)})}u();var vr=5e3;function yr(e){return e.kind===`cap`||e.kind===`wait`}function br(e){return e instanceof Error?e.message:String(e)}function xr(){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 Sr({entry:t,onClose:n,onSaved:i}){let{t:a}=Z(),s=d(),l=A(),u=Lt(),f=xr(),[m,h]=c(()=>tr(t)),[g,y]=c(null),b=t!==null&&t.readOnly,x=()=>{s.invalidateQueries({queryKey:[[`actions`]]})},S=_t({onSuccess:e=>{x(),i(e.action.id)}}),C=ke({onSuccess:x}),w=tt({onSuccess:()=>{x(),n()}}),T=pt({onSuccess:x}),D=Ue({actionId:t?.id??`none`},{enabled:t!==null,refetchInterval:vr}),O=D.data?.traces.find(e=>e.runId===g)??null,j=r(()=>O===null?null:Qn(O),[O]),M=ir(m),N=r(()=>Hn(m.variables,a),[m.variables,a]),P=S.isPending||C.isPending,F=S.error??C.error??w.error??T.error,I=(t?.variables??[]).some(e=>e.required===!0&&e.default===void 0);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(k,{className:`h-4 w-4 text-foreground-muted`}),o(K,{"aria-label":a(`actions.editor.name`,`Name`),className:`max-w-xs flex-1`,value:m.name,disabled:b,placeholder:a(`actions.editor.namePlaceholder`,`What this action does`),onChange:e=>h({...m,name:e.target.value})}),o(J,{variant:b?`info`:`primary`,children:b?t?.addonId??``:a(`actions.source.internal`,`Internal`)})]}),b?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(gr,{variables:m.variables,onChange:e=>h({...m,variables:e}),onRename:(e,t)=>h(sr(m,e,t))}),o(mn,{step:`steps`,title:a(`actions.editor.steps`,`Steps`),trace:j===null?null:j.thenBlock,children:o(Bn,{actions:m.steps,devices:u,allowedKinds:[`cap`,`wait`],variables:N,onChange:e=>h({...m,steps:e.filter(yr)})})})]}),!M.ok&&!b&&m.name!==``&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:f(M.reason)}),F!==null&&o(q,{message:br(F)}),e(`div`,{className:`flex flex-wrap gap-2`,children:[!b&&e(Y,{onClick:()=>{M.ok&&(t===null?S.mutate({action:M.input}):C.mutate({actionId:t.id,action:M.input}))},disabled:P||!M.ok,children:[P&&o(E,{className:`h-4 w-4 animate-spin`}),` `,a(`common.save`,`Save`)]}),t!==null&&e(Y,{variant:`outline`,disabled:T.isPending||I,title:I?a(`actions.editor.runNeedsDefaults`,`Give each required variable a default to run it from here.`):void 0,onClick:()=>T.mutate({actionId:t.id}),children:[o(v,{className:`h-4 w-4`}),` `,a(`actions.editor.runNow`,`Run now`)]}),t!==null&&!b&&e(Y,{variant:`ghost`,disabled:w.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&&w.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(fn,{traces:t===null?[]:D.data?.traces,selectedId:g,onSelect:y})})]})}u();var Cr=5e3;function wr(e){return e instanceof Error?e.message:String(e)}function Tr(){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 Er({createRequested:t=!1,onCreateConsumed:n}){let{t:i}=Z(),a=d(),c=Tr(),{state:l,openNew:u,openEdit:f,close:m}=et({editKey:`action`,newKey:`new`}),h=Te({},{refetchInterval:Cr}),_=pt({onSuccess:()=>void a.invalidateQueries({queryKey:[[`actions`]]})});s(()=>{t&&(u(),n?.())},[t,n,u]);let y=h.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(J,{variant:`info`,children:e.addonId}):o(J,{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:`-`}):At(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(J,{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:_.isPending||t.status.isRunning,"aria-label":i(`actions.list.runAria`,`Run {{name}}`,{name:t.name}),onClick:e=>{e.stopPropagation(),_.mutate({actionId:t.id})},children:[o(v,{className:`h-4 w-4`}),` `,i(`actions.list.run`,`Run`)]}),notSortableReason:i(`actions.list.runNotSortable`,`A control`)}],[_,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.`)}),_.error!=null&&o(q,{message:wr(_.error)}),h.data===void 0?h.error==null?o(Me,{className:`h-24 w-full`}):o(q,{title:i(`actions.list.couldNotRead`,`Could not read the actions`),message:wr(h.error),onRetry:()=>void h.refetch()}):y.length===0?o(ze,{icon:k,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(g,{className:`h-4 w-4`}),` `,i(`actions.list.new`,`New action`)]})}):e(p,{children:[h.error!=null&&o(q,{title:i(`actions.list.couldNotRead`,`Could not read the actions`),message:wr(h.error),onRetry:()=>void h.refetch()}),o(Ce,{columns:x,rows:y,rowKey:e=>e.id,pageSize:25,maxBodyHeight:st,emptyMessage:i(`actions.list.emptyTitle`,`No actions yet`),onRowClick:e=>f(e.id)})]})]}):o(Sr,{entry:b,onClose:m,onSaved:f},b?.id??`new`)}function Dr({value:t,field:n,deviceId:r,cap:i,onChange:a}){let{t:s}=Z(),c=Pr(n,r,i);if(n?.kind===`boolean`)return o(G,{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(G,{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(K,{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(K,{value:String(t),placeholder:s(`common.valueWord`),onChange:e=>a(e.target.value)})}function Or({value:e,field:t,deviceId:n,cap:r,onChange:i}){let{t:a}=Z(),s=Pr(t,n,r);return o(K,{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`&&!H(e)}function Ar(e){return H(e)?e.value:kr(e)?e[0]??``:e}function jr(e){return H(e)?[e.value]:kr(e)?e:typeof e==`boolean`?[]:[e]}function Mr(e){let t=e?.quantity;if(!(e?.kind!==`number`||t===void 0)&&!(!fe(t)||t===`none`||t===`device`))return me(t).length>0?t:void 0}function Nr(e,t){if(!(e===void 0||e===`none`)){if(e!==`device`)return e;if(!(t===void 0||t===`device`||t===`none`))return t}}function Pr(e,t,n){let r=dt(),i=t??0,a=e?.kind===`number`&&e.quantity!==void 0,{data:o}=ct({deviceId:i},{enabled:a&&i>0}),s=o?.sourceInfo?.quantity,c=fe(s)?s:void 0,l=Nr(e?.quantity,c);if(l===void 0)return;let u=o?.display;return lt({quantity:l,display:u,capName:n,unitPreferences:r})}function Fr({leaf:t,devices:n,onChange:r}){let{t:i}=Z(),a={deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath},s=hn(a),c=En(s?.kind),l=t.operator===`in`,u=Mr(s),d=u===void 0?void 0:R(u),f=e=>{let{unit:n,...i}=t;r({...i,deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath})},p=e=>{let n=Ir(e,c),{unit:i,...a}=t;r({...n===`in`?a:t,operator:n,value:n===`in`?jr(t.value):Ar(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(G,{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(Or,{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(He,{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=we(e,d);r({...t,value:n.value,unit:n.unit})}}):o(Dr,{value:Ar(t.value),field:s,deviceId:t.deviceId,cap:t.cap,onChange:e=>r({...t,value:e})})]})]})}function Ir(e,t){return t.find(t=>t.value===e)?.value??`eq`}var Lr={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function Rr({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(K,{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(zr,{alias:e,source:r,devices:n,onRename:n=>s(Gr(t.bindings,e,n)),onChange:n=>s({...t.bindings,[e]:n}),onRemove:()=>s(Kr(t.bindings,e))},e)),e(Y,{variant:`ghost`,onClick:()=>s({...t.bindings,[Wr(t.bindings)]:Lr}),children:[o(g,{className:`h-3.5 w-3.5`}),` `,i(`common.name`)]})]})]})}function zr({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:Hr(r,Vr(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(K,{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(G,{value:l?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:Lr),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(K,{value:n.value===null?``:String(n.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:Br(e.target.value)})})]}):o(gn,{value:u,devices:r,onChange:e=>a({kind:`global`,sourceStableId:Ur(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 Br(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function Vr(e){return e.kind===`global`?e.sourceStableId:``}function Hr(e,t){return e.find(e=>e.stableId===t)?.id??0}function Ur(e,t){return e.find(e=>e.id===t)?.stableId??``}function Wr(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 Gr(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function Kr(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function qr(e){return e.kind===`all`||e.kind===`any`}function Jr(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:qr(t)?t:{kind:`all`,children:[t]}}function Yr(e,t){return t===null||qr(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function Xr(e){return Yr(e,Jr(e))}function Zr(e,t){if(t.length===0)return e;let[n,...r]=t;if(n===void 0)return e;if(e.kind===`not`)return n===0?Zr(e.child,r):null;if(!qr(e))return null;let i=e.children[n];return i===void 0?null:Zr(i,r)}function Qr(e,t,n){if(t.length===0)return n(e);let[r,...i]=t;if(r===void 0)return n(e);if(e.kind===`not`){if(r!==0)return e;let t=Qr(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!qr(e))return e;let a=e.children[r];if(a===void 0)return e;let o=Qr(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 $r(e){return e===null?null:de({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function ei(e){let t=Jr(e);return{depth:t.children.length===0?0:pe(t),leaves:t.children.length===0?0:I(t),depthLimit:3,leafLimit:32}}function ti(e,t){let n=$r(t);return n===null?{ok:!0,recipe:Yr(e,t)}:{ok:!1,reason:n}}function ni(e,t){let n=Jr(e);return ti(e,{kind:n.kind,children:[...n.children,t]})}function ri(e,t,n){return Yr(e,Qr(Jr(e),t,()=>n))}function ii(e,t){return Yr(e,Qr(Jr(e),t,()=>null))}function ai(e,t,n){return Yr(e,Qr(Jr(e),t,e=>qr(e)?{kind:n,children:e.children}:e))}function oi(e,t){return Zr(Jr(e),t)===null?{ok:!1,reason:X.t(`helpers.recipeOps.rowGone`)}:ti(e,Qr(Jr(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function si(e){if(e.length===0)return null;let t=e[e.length-1];return t===void 0?null:{path:e.slice(0,-1),index:t}}function ci(e,t,n){if(t.length<2)return{ok:!1,reason:X.t(`helpers.recipeOps.selectTwo`)};if(new Set(t.map(e=>e.slice(0,-1).join(`/`))).size!==1)return{ok:!1,reason:X.t(`helpers.recipeOps.differentGroups`)};let r=si(t[0]??[]);if(r===null)return{ok:!1,reason:X.t(`helpers.recipeOps.rootGroup`)};let i=Jr(e),a=Zr(i,r.path);if(a===null||!qr(a))return{ok:!1,reason:X.t(`helpers.recipeOps.insideNot`)};let o=[...t.map(e=>e[e.length-1]??-1)].sort((e,t)=>e-t),s=o.map(e=>a.children[e]).filter(e=>e!==void 0);if(s.length!==o.length)return{ok:!1,reason:X.t(`helpers.recipeOps.selectedGone`)};let c=a.children.filter((e,t)=>!o.includes(t)),l=o[0]??0,u={kind:n,children:s},d={kind:a.kind,children:[...c.slice(0,l),u,...c.slice(l)]};return ti(e,Qr(i,r.path,()=>d))}function li(e,t){if(t.length===0)return{ok:!1,reason:X.t(`helpers.recipeOps.outerNotGroup`)};let n=Jr(e),r=Zr(n,t);if(r===null)return{ok:!1,reason:X.t(`helpers.recipeOps.groupGone`)};if(r.kind===`not`)return ti(e,Qr(n,t,()=>r.child));if(!qr(r))return{ok:!1,reason:X.t(`helpers.recipeOps.rowIsCondition`)};let i=si(t);if(i===null)return{ok:!1,reason:X.t(`helpers.recipeOps.noParent`)};let a=Zr(n,i.path);if(a===null||!qr(a))return{ok:!1,reason:X.t(`helpers.recipeOps.groupInNot`)};let o={kind:a.kind,children:[...a.children.slice(0,i.index),...r.children,...a.children.slice(i.index+1)]};return ti(e,Qr(n,i.path,()=>o))}var ui=`text-xs text-foreground-subtle`;function di({children:e}){return o(`span`,{className:ui,children:e})}function fi(e,t){return e.includes(t)?e.filter(e=>e!==t):[...e,t]}function pi(){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 t}}}function mi({selected:t,onChange:n,hint:r}){let{t:i}=Z(),a=pi(),s=ee.map(e=>e.id),c=t.filter(e=>!s.includes(e));return e(`div`,{className:`space-y-1`,children:[o(di,{children:i(`flow.scene.class`,`Class`)}),o(`div`,{className:`flex flex-wrap gap-2`,children:[...s,...c].map(e=>o(Y,{size:`sm`,variant:t.includes(e)?`primary`:`outline`,"aria-pressed":t.includes(e),onClick:()=>n(fi(t,e)),children:a(e)},e))}),r!==void 0&&o(`p`,{className:ui,children:r})]})}function hi({devices:t,selected:n,onChange:r}){let{t:i}=Z(),a=t.filter(e=>e.type===ce.Camera);return e(`div`,{className:`space-y-1`,children:[o(di,{children:i(`flow.scene.cameras`,`Cameras`)}),o(It,{devices:a,selection:`multiple`,noun:`camera`,value:n,testId:`scene-cameras`,onChange:r})]})}function gi({device:t,deviceId:n,selected:r,onToggle:i}){let a=Oe({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:ui,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 _i({devices:t,deviceIds:n,selected:r,onChange:i}){let{t:a}=Z();if(n.length===0)return null;let s=e=>{let t=fi(r,e);i(t.length===0?void 0:t)};return e(`div`,{className:`space-y-1`,children:[o(di,{children:a(`flow.scene.zones`,`Zones`)}),o(`div`,{className:`space-y-2`,children:n.map(e=>o(gi,{device:t.find(t=>t.id===e),deviceId:e,selected:r,onToggle:s},e))}),o(`p`,{className:ui,children:r.length===0?a(`flow.scene.wholeScene`,`None picked: the whole scene counts.`):a(`flow.scene.zonesPicked`,`Only these zones count.`)})]})}var vi=100;function yi({trigger:t,devices:n,onChange:r}){let{t:i}=Z(),a=Math.round((t.minScore??0)*vi),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/vi})};return e(`div`,{className:`w-full space-y-3`,"data-testid":`detection-fields`,children:[o(mi,{selected:t.classes,onChange:e=>r({...t,classes:[...e]})}),o(hi,{devices:n,selected:t.deviceIds,onChange:e=>r({...t,deviceIds:[...e]})}),o(_i,{devices:n,deviceIds:t.deviceIds,selected:t.zones??[],onChange:s}),e(`div`,{className:`space-y-1`,children:[o(di,{children:a===0?i(`flow.scene.minScoreAny`,`Minimum score: any`):i(`flow.scene.minScore`,`Minimum score: {{value}}`,{value:(a/vi).toFixed(2)})}),o(`input`,{type:`range`,min:0,max:vi,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 bi({trigger:t,devices:n,onChange:r}){let{t:i}=Z();return e(`div`,{className:`w-full space-y-3`,"data-testid":`stationary-fields`,children:[o(mi,{selected:t.classes??[],onChange:e=>{let{classes:n,...i}=t;r(e.length===0?i:{...i,classes:[...e]})},hint:t.classes===void 0?i(`flow.scene.anyClass`,`None picked: any class counts.`):void 0}),o(hi,{devices:n,selected:t.deviceIds,onChange:e=>r({...t,deviceIds:[...e]})}),o(_i,{devices:n,deviceIds:t.deviceIds,selected:t.zones??[],onChange:e=>{let{zones:n,...i}=t;r(e===void 0?i:{...i,zones:[...e]})}}),o(rt,{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 xi({trigger:t,onChange:n}){let{t:r}=Z();return e(`div`,{className:`flex items-center gap-2`,"data-testid":`interval-fields`,children:[o(di,{children:r(`flow.scene.every`,`Every`)}),o(Pt,{"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(di,{children:r(`flow.scene.minutes`,`minutes`)})]})}function Si({leaf:t,devices:n,onChange:r}){let{t:i}=Z(),a=n.filter(e=>e.type===ce.Camera),s=e=>{let{classes:n,...i}=t;r(e.length===0?i:{...i,classes:[...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(di,{children:i(`flow.scene.parkedOn`,`An object is parked on`)}),o(It,{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(mi,{selected:t.classes??[],onChange:s,hint:t.classes===void 0?i(`flow.scene.anyClass`,`None picked: any class counts.`):void 0}),o(_i,{devices:n,deviceIds:t.deviceId>0?[t.deviceId]:[],selected:t.zones??[],onChange:c})]})}u();var Ci=[{value:`all`,labelKey:`automation.conditionTree.allOf`},{value:`any`,labelKey:`automation.conditionTree.anyOf`}];function wi(e){return e.join(`/`)}function Ti(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function Ei({recipe:t,devices:n,onChange:i}){let{t:a}=Z(),[s,l]=c([]),[u,d]=c(null),f=Jr(t),p=ei(t),m=r(()=>s.map(Ti),[s]),h=e=>{if(!e.ok){d(e.reason);return}d(null),l([]),i(e.recipe)},_=ci(t,m,`all`),v=ci(t,m,`any`),b=m.length===1?oi(t,m[0]??[]):{ok:!1,reason:a(`automation.conditionTree.selectOneNegate`)},x={devices:n,selected:new Set(s),onToggleSelect:e=>l(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),onUpdate:(e,n)=>i(ri(t,e,n)),onRemove:e=>{l([]),i(ii(t,e))},onSetKind:(e,n)=>i(ai(t,e,n)),onUngroup:e=>h(li(t,e))};return e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(J,{variant:`default`,children:a(`automation.conditionTree.andOnlyIf`,`And only if`)}),o(`div`,{className:`w-32`,children:o(G,{value:f.kind,onChange:e=>i(ai(t,[],Di(e.target.value))),options:Ci.map(e=>({value:e.value,label:a(e.labelKey)}))})}),o(`span`,{className:`text-xs text-foreground-subtle`,children:a(`automation.conditionTree.budget`,{depth:p.depth,depthLimit:p.depthLimit,leaves:p.leaves,leafLimit:p.leafLimit})})]}),f.children.length===0?o(`p`,{className:`text-xs text-foreground-subtle`,children:a(`automation.conditionTree.noConditionsTheActionsRun`,`No conditions. The actions run every time a trigger fires.`)}):o(Oi,{container:f,path:[],handlers:x}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(Y,{variant:`outline`,onClick:()=>h(ni(t,jn())),title:a(`automation.conditionTree.compareOneDeviceFieldTo`,`Compare one device field to a value`),children:[o(g,{className:`h-4 w-4`}),` `,a(`automation.conditionTree.addCondition`)]}),e(Y,{variant:`outline`,onClick:()=>h(ni(t,Nn())),title:a(`automation.conditionTree.arithmeticAcrossDeviceFieldsThe`,`Arithmetic across device fields — the bounded expression engine`),children:[o(_e,{className:`h-4 w-4`}),` `,a(`automation.conditionTree.addExpression`)]}),e(Y,{variant:`outline`,onClick:()=>h(ni(t,Mn())),title:a(`flow.scene.addParkedTitle`,`True while an object is parked on a camera, in a zone`),children:[o(y,{className:`h-4 w-4`}),` `,a(`flow.scene.addParked`,`Parked object`)]}),o(`span`,{className:`mx-1 h-5 w-px bg-border`}),o(Y,{variant:`ghost`,disabled:!_.ok,onClick:()=>h(_),title:_.ok?a(`automation.conditionTree.allSelectedRowsMustBe`,`All selected rows must be true`):_.reason,children:a(`automation.conditionTree.groupAsAll`,`Group as ALL`)}),o(Y,{variant:`ghost`,disabled:!v.ok,onClick:()=>h(v),title:v.ok?a(`automation.conditionTree.anyOneOfTheSelected`,`Any one of the selected rows is enough`):v.reason,children:a(`automation.conditionTree.groupAsAny`,`Group as ANY`)}),o(Y,{variant:`ghost`,disabled:!b.ok,onClick:()=>h(b),title:b.ok?a(`automation.conditionTree.invertTheSelectedRow`,`Invert the selected row`):b.reason,children:`NOT`}),s.length>0&&o(`span`,{className:`text-xs text-foreground-subtle`,children:a(`common.selectedCount`,{count:s.length})})]}),u!==null&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-2 text-xs text-warning`,children:u})]})}function Di(e){return e===`any`?`any`:`all`}function Oi({container:e,path:t,handlers:n}){return o(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>o(ki,{node:e,path:[...t,r],handlers:n},wi([...t,r])))})}function ki({node:t,path:n,handlers:r}){let{t:i}=Z(),a=wi(n),s=o(Qe,{checked:r.selected.has(a),onChange:()=>r.onToggleSelect(a),"aria-label":i(`automation.conditionTree.selectThisRowForGrouping`,`Select this row for grouping`)});return qr(t)?e(`div`,{className:`rounded border border-border bg-surface-subtle/40 p-2`,children:[e(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[s,o(`div`,{className:`w-32`,children:o(G,{value:t.kind,onChange:e=>r.onSetKind(n,Di(e.target.value)),options:Ci.map(e=>({value:e.value,label:i(e.labelKey)}))})}),e(Y,{variant:`ghost`,onClick:()=>r.onUngroup(n),title:i(`automation.conditionTree.dissolveThisGroupKeepingIts`,`Dissolve this group, keeping its rows`),children:[o(ve,{className:`h-3.5 w-3.5`}),` `,i(`automation.conditionTree.ungroup`)]}),o(Y,{variant:`ghost`,onClick:()=>r.onRemove(n),title:i(`automation.conditionTree.deleteThisGroupAndEverything`,`Delete this group and everything in it`),children:o(_,{className:`h-3.5 w-3.5`})})]}),o(`div`,{className:`pl-4`,children:o(Oi,{container:t,path:n,handlers:r})})]}):t.kind===`not`?e(`div`,{className:`rounded border border-border p-2`,children:[e(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[s,o(J,{variant:`warning`,children:`NOT`}),e(Y,{variant:`ghost`,onClick:()=>r.onUngroup(n),title:i(`automation.conditionTree.removeTheNotKeepingThe`,`Remove the NOT, keeping the row`),children:[o(ve,{className:`h-3.5 w-3.5`}),` `,i(`automation.conditionTree.removeNot`)]})]}),o(`div`,{className:`pl-4`,children:o(ki,{node:t.child,path:[...n,0],handlers:r})})]}):e(`div`,{className:`flex items-start gap-2 rounded border border-border p-2`,children:[o(`div`,{className:`pt-6`,children:s}),o(`div`,{className:`min-w-0 flex-1`,children:t.kind===`condition`?o(Fr,{leaf:t,devices:r.devices,onChange:e=>r.onUpdate(n,e)}):t.kind===`expression`?o(Rr,{leaf:t,devices:r.devices,onChange:e=>r.onUpdate(n,e)}):o(Si,{leaf:t,devices:r.devices,onChange:e=>r.onUpdate(n,e)})}),o(Y,{variant:`ghost`,onClick:()=>r.onRemove(n),title:i(`automation.conditionTree.removeThisCondition`,`Remove this condition`),children:o(_,{className:`h-3.5 w-3.5`})})]})}u();function Ai({code:t,error:n,canEject:r,ejecting:i,onEject:a}){let{t:s}=Z(),[l,u]=c(!1),d=A(),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?b:h,{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(xe,{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(mt,{maxHeight:420,children:t})})]})}var ji;function Mi(){return ji??=he(U),ji}function Ni(e,t){switch(e.kind){case`condition`:{if(typeof e.value!=`number`||e.unit!==void 0)return e;let n=t.fieldQuantity(e.cap,e.fieldPath);if(n===void 0||me(n).length<2)return e;let r=R(n);return r===void 0?e:{...e,unit:r}}case`not`:return{...e,child:Ni(e.child,t)};case`all`:case`any`:return{...e,children:e.children.map(e=>Ni(e,t))};default:return e}}function Pi(e,t){if(e.kind!==`cap`||e.args===void 0)return e;let n={...e.argUnits};for(let[r,i]of Object.entries(e.args)){if(typeof i!=`number`||n[r]!==void 0)continue;let a=t.paramMeta(e.cap,e.method,r);a!==void 0&&me(a.quantity).length>1&&(n[r]=a.unit)}return Object.keys(n).length===0?e:{...e,argUnits:n}}function Fi(e,t=Mi()){let n={...e,...e.conditions===void 0?{}:{conditions:Ni(e.conditions,t)},actions:e.actions.map(e=>Pi(e,t))};try{return{ok:!0,recipe:oe(n,t).value}}catch(e){if(e instanceof ne)return{ok:!1,error:e.message};throw e}}var Ii=[`detection`,`stationary`,`device-state`,`device-event`,`schedule`,`interval`,`manual`],Li={detection:`scene`,stationary:`scene`,"device-state":`device`,"device-event":`device`,schedule:`time`,interval:`time`,manual:`manual`};function Ri(){let{t:e}=Z(),t={scene:e(`flow.triggerGroup.scene`,`Scene`),device:e(`flow.triggerGroup.device`,`Devices`),time:e(`flow.triggerGroup.time`,`Time`),manual:e(`flow.triggerGroup.manual`,`By hand`)},n={detection:e(`flow.triggerHint.detection`,`An object class is detected on a camera`),stationary:e(`flow.triggerHint.stationary`,`An object stops, or leaves`),"device-state":e(`flow.triggerHint.deviceState`,`A device value changes or 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`)};return Ii.map(e=>({value:e,label:Dn(e),description:n[e],group:t[Li[e]]}))}var zi=Object.values(te).sort((e,t)=>e.localeCompare(t));function Bi({triggers:t,devices:n,onChange:r}){let{t:i}=Z();return e(`div`,{className:`space-y-2`,children:[t.length===0&&o(`p`,{className:`text-xs text-warning`,children:i(`automation.triggerEditor.noTriggersYetWithoutOne`,`No triggers yet. Without one nothing can ever start this automation — not even "Run actions", which needs a manual trigger to have somewhere to arrive.`)}),t.map((e,i)=>o(Vi,{trigger:e,devices:n,position:i,onChange:e=>r(Pn(t,i,e)),onRemove:()=>r(Fn(t,i))},`${e.kind}-${String(i)}`)),e(Y,{variant:`outline`,onClick:()=>r([...t,kn(`device-state`)]),title:i(`automation.triggerEditor.addAnotherWayThisAutomation`,`Add another way this automation can start`),children:[o(g,{className:`h-4 w-4`}),` `,i(`automation.triggerEditor.trigger`)]})]})}function Vi({trigger:t,devices:n,position:r,onChange:i,onRemove:a}){let{t:s}=Z(),c=Ri();return e(`div`,{className:`rounded border border-border p-3`,children:[e(`div`,{className:`flex flex-wrap items-end gap-2`,children:[o(J,{variant:`default`,children:r===0?s(`automation.triggerEditor.when`,`When`):s(`automation.triggerEditor.orWhen`,`or when`)}),e(`div`,{className:`min-w-[13rem] flex-1`,children:[o(Q,{children:s(`automation.triggerEditor.trigger`,`Trigger`)}),o(ut,{mode:`single`,singleDisplay:`field`,options:c,value:t.kind,onChange:e=>{e!==t.kind&&i(kn(Hi(e)))}})]}),o(Y,{variant:`ghost`,onClick:a,title:s(`automation.triggerEditor.removeThisTrigger`,`Remove this trigger`),children:o(_,{className:`h-4 w-4`})})]}),e(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:[t.kind===`device-state`&&o(Wi,{trigger:t,devices:n,onChange:i}),t.kind===`device-event`&&o(Ki,{trigger:t,devices:n,onChange:i}),t.kind===`schedule`&&e(`label`,{className:`min-w-[14rem] flex-1`,children:[o(Q,{children:s(`automation.triggerEditor.cronExpression`,`Cron expression`)}),o(K,{value:t.cron,placeholder:`0 30 23 * * *`,onChange:e=>i({kind:`schedule`,cron:e.target.value})}),o(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:o(Dt,{i18nKey:`automation.triggerEditor.cronHint`,components:{code:o(`code`,{})}})})]}),t.kind===`detection`&&o(yi,{trigger:t,devices:n,onChange:i}),t.kind===`stationary`&&o(bi,{trigger:t,devices:n,onChange:i}),t.kind===`interval`&&o(xi,{trigger:t,onChange:i}),t.kind===`manual`&&o(`p`,{className:`text-xs text-foreground-subtle`,children:o(Dt,{i18nKey:`automation.triggerEditor.manualHint`,components:{b:o(`strong`,{})}})})]})]})}function Hi(e){return Ii.find(t=>t===e)??`manual`}function Ui(e,t){return{kind:`device-state`,deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath,...t.becomes===void 0?{}:{becomes:t.becomes},...t.edge===void 0?{}:{edge:t.edge},...t.forMs===void 0?{}:{forMs:t.forMs},...t.debounceMs===void 0?{}:{debounceMs:t.debounceMs}}}function Wi({trigger:t,devices:n,onChange:r}){let{t:i}=Z(),a={deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath},s=hn(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(Ui(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(Qe,{checked:t.becomes===void 0,onChange:e=>r(Ui(a,{...c,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),i(`automation.triggerEditor.anyChange`,`any change`)]}),t.becomes!==void 0&&o(Dr,{value:t.becomes,field:s,deviceId:a.deviceId,cap:a.cap,onChange:e=>r(Ui(a,{...c,becomes:e}))})]})]}),e(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[o(Qe,{checked:t.edge===!0,onChange:e=>r(Ui(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(K,{type:`number`,min:0,value:t.forMs===void 0?``:String(t.forMs/1e3),placeholder:`0`,onChange:e=>r(Ui(a,{...c,forMs:Gi(e.target.value)}))})]}),e(`label`,{className:`w-28`,children:[o(Q,{children:i(`automation.triggerEditor.debounceS`,`Debounce (s)`)}),o(K,{type:`number`,min:0,value:t.debounceMs===void 0?``:String(t.debounceMs/1e3),placeholder:`0`,onChange:e=>r(Ui(a,{...c,debounceMs:Gi(e.target.value)}))})]})]})}function Gi(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function Ki({trigger: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(G,{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…`)},...zi.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(It,{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 qi=[`single`,`restart`,`queued`,`parallel`,`cooldown`],Ji=2,Yi=30;function Xi(e){return e.runMode??{mode:`single`}}function Zi(e,t){let{runMode:n,...r}=e;return t.mode===`single`?r:{...r,runMode:t}}function Qi(e){switch(e){case`queued`:return{mode:`queued`,max:Ji};case`parallel`:return{mode:`parallel`,max:Ji};case`cooldown`:return{mode:`cooldown`,minutes:Yi};case`restart`:return{mode:`restart`};default:return{mode:`single`}}}function $i(e){return qi.find(t=>t===e)??`single`}function ea({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(Mt,{widthClass:`w-56`,value:t.mode,options:qi.map(e=>({value:e,label:i[e]})),onChange:e=>n(Qi($i(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(Pt,{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(Pt,{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]})]})}u();var ta=`hub`,na=5e3;function ra({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(()=>Xr(n)),[_,v]=c(!1),[y,b]=c(null),x=Xe({blockId:t?.id??`none`},{enabled:t!==null,refetchInterval:na}),S=x.data?.traces.find(e=>e.runId===y)??null,C=r(()=>S===null?null:Qn(S),[S]),w=r(()=>Gn(h.triggers,f),[h.triggers,f]),T=Lt(),D=de(h),O=r(()=>ia(h),[h]),k=r(()=>aa(p.trim()===``?`Untitled automation`:p.trim(),h),[p,h]),A=p.trim()===``,j=A||D!==null||O!==null||k.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:[o(`div`,{className:`flex flex-wrap items-center gap-2`,children:o(J,{variant:`info`,children:f(`automation.automationEditor.runsOnTheHub`,`runs on the hub`)})}),e(`label`,{className:`block max-w-md text-sm`,children:[o(`span`,{className:`text-foreground-subtle`,children:f(`automation.automationEditor.name`,`Name`)}),o(K,{className:`mt-1`,value:p,onChange:e=>m(e.target.value),placeholder:f(`automation.automationEditor.whatThisAutomationDoes`,`What this automation does`)})]}),o(mn,{step:`when`,title:f(`automation.automationEditor.when`,`When`),trace:C===null?null:C.when,hint:f(`automation.automationEditor.anyOneOfTheseStarts`,`Any one of these starts a run.`),children:o(Bi,{triggers:h.triggers,devices:T,onChange:e=>g(Ln(h,e))})}),o(mn,{step:`if`,title:f(`automation.automationEditor.andOnlyIf`,`And only if`),trace:C===null?null:C.condition,hint:f(`automation.automationEditor.checkedAfterATriggerFires`,`Checked after a trigger fires. Nothing runs unless this is true.`),children:o(Ei,{recipe:h,devices:T,onChange:g})}),o(mn,{step:`then`,title:f(`automation.automationEditor.then`,`Then`),trace:C===null?null:C.thenBlock,hint:f(`automation.automationEditor.inThisOrderStoppingAt`,`In this order, stopping at the first failure.`),children:o(Bn,{actions:h.actions,devices:T,variables:w,stepTones:C===null?void 0:h.actions.map((e,t)=>$n(C,t)??`idle`),onChange:e=>g(Rn(h,e))})}),o(mn,{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(ea,{value:Xi(h),onChange:e=>g(Zi(h,e))})}),o(Ai,{code:k.code,error:k.error,canEject:t!==null,ejecting:s,onEject:u}),D!==null&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:D}),D===null&&O!==null&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:O}),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:()=>{k.code!==null&&l({name:p.trim(),code:k.code,enabled:t?.enabled??!0,placement:ta})},disabled:i||j,children:[i&&o(E,{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`,children:[o(N,{className:`h-4 w-4`}),` `,f(`common.logs`),` `,_?`▾`:`▸`]}),o(Y,{variant:`ghost`,onClick:d,disabled:i,children:f(`common.close`,`Close`)}),A&&o(J,{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(Dt,{i18nKey:`common.logsOf`,values:{id:L(t.id)},components:{code:o(`code`,{})}})}),o(nt,{addonId:L(t.id),maxHeight:`max-h-64`,showFilters:!1})]})]}),o(`div`,{className:`order-first lg:order-last`,children:o(fn,{traces:t===null?[]:x.data?.traces,selectedId:y,onSelect:b})})]})}function ia(e){let t=ae.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 aa(e,t){let n=Fi(t);if(!n.ok)return{code:null,error:n.error};try{return{code:z({name:e,recipe:n.recipe}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function oa(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 sa(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function ca(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function la(e){let t=e=>{let t=oa(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 ua(e){if(e.length===0)return X.t(`helpers.coreBlockStatus.noBlocks`);let t=e.filter(e=>oa(e).tone===`error`).length,n=e.filter(e=>oa(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(` · `)}function da({block:t,logsOpen:n,unreadable:r}){let i=O(),{t:a}=Z(),s=oa(t),c=$e(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(J,{variant:sa(s.tone),children:s.label}),c!==null&&o(`span`,{className:`text-xs text-foreground-subtle`,children:a(`common.edited`,{when:c})})]}),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(Dt,{i18nKey:`common.logsOf`,values:{id:L(t.id)},components:{code:o(`code`,{})}})}),o(nt,{addonId:L(t.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function fa({block:t,busy:n,unreadable:r,onEdit:i,onToggle:a,onToggleLogs:s,onDelete:c}){let{t:l}=Z();return e(`div`,{className:`flex justify-end gap-1`,children:[o(Y,{variant:`ghost`,onClick:e=>{e.stopPropagation(),i()},disabled:r!==null,title:r===null?l(`common.edit`,`Edit`):l(`automation.automationList.thisBlockCannotBeOpened`,`This block cannot be opened visually`),children:o(S,{className:`h-4 w-4`})}),e(Pe,{children:[o(Re,{children:o(Y,{variant:`ghost`,disabled:!0,title:l(`automation.automationList.runActions`,`Run actions`),children:o(v,{className:`h-4 w-4`})})}),o(Fe,{children:l(`automation.automationList.runningAnAutomationByHand`,`Running an automation by hand needs the automation-control authority, which is not wired up yet. There is deliberately no second way to execute one.`)})]}),o(Y,{variant:`ghost`,onClick:e=>{e.stopPropagation(),s()},title:l(`automation.automationList.logs`,`Logs`),children:o(N,{className:`h-4 w-4`})}),o(Y,{variant:`ghost`,onClick:e=>{e.stopPropagation(),a(!t.enabled)},disabled:n,title:t.enabled?l(`common.disable`,`Disable`):l(`common.enable`,`Enable`),children:t.enabled?l(`common.disable`,`Disable`):l(`common.enable`,`Enable`)}),o(Y,{variant:`ghost`,onClick:e=>{e.stopPropagation(),c()},title:l(`common.delete`,`Delete`),children:o(_,{className:`h-4 w-4`})})]})}function pa({onCreate:t}){let{t:n}=Z();return o(Le,{children:e(`div`,{className:`space-y-2 p-4`,children:[o(`p`,{className:`text-sm text-foreground`,children:n(`automation.automationList.noAutomationsYet`,`No automations yet.`)}),o(`p`,{className:`max-w-2xl text-xs text-foreground-subtle`,children:n(`automation.automationList.anAutomationIsATrigger`,`An automation is a trigger, a set of conditions and a list of actions. It compiles to an ordinary block and runs in its own supervised process — there is no separate engine, so anything that goes wrong shows up here with a reason.`)}),o(Y,{onClick:t,children:n(`automation.automationList.newAutomation`,`New automation`)})]})})}u();var ma=[`coreBlocks`,`list`],ha=5e3;function ga(e){return e instanceof Error?e.message:String(e)}function _a({onOpenScripts:t,initialBlockId:i,onBlockIdChange:a,createRequested:u=!1,onCreateConsumed:d}){let{t:p}=Z(),m=w(),{state:h,openNew:g,openEdit:_,close:v}=et({editKey:`block`,newKey:`new`}),[y,b]=c(null),x=A(),[S,C]=c(null),T=n(null),E=h.mode!==`closed`;s(()=>{u&&(b(null),g(),a?.(null),d?.())},[u,d,a,g]);let D=l({queryKey:ma,refetchInterval:ha,queryFn:async()=>(await m.trpcClient.coreBlocks.list.query({})).blocks}),O=()=>{D.refetch()},k=D.data;s(()=>{i===void 0||T.current===i||k?.find(e=>e.id===i&&rn(e.code))!==void 0&&(T.current=i,_(i),a?.(i))},[i,k,_,a]);let M=f({mutationFn:e=>m.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{b(e.block),_(e.block.id),a?.(e.block.id),O()}}),N=f({mutationFn:e=>m.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{b(e.block),_(e.block.id),a?.(e.block.id),O()}}),P=f({mutationFn:e=>m.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:O}),F=f({mutationFn:e=>m.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:O}),I=f({mutationFn:e=>m.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:sn(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:e=>{v(),b(null),O(),t(e.block.id)}}),L=D.data,R=la((L??[]).filter(e=>rn(e.code))),z=L!==void 0&&R.length===0,ee=h.mode===`edit`?R.find(e=>e.id===h.id)??(y!==null&&y.id===h.id?y:null):null,B=h.mode===`new`||ee===null?null:ca(R,ee),V=B===null?null:on(B.code),te=M.error===null?N.error===null?I.error===null?null:ga(I.error):ga(N.error):ga(M.error),ne=r(()=>[{key:`name`,header:p(`build.automationsTab.automation`,`Automation`),nowrap:!1,render:e=>{let t=on(e.code);return o(da,{block:e,logsOpen:S===e.id,unreadable:t.ok?null:t.reason})},sortValue:e=>e.name},{key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,render:e=>{let t=on(e.code);return o(fa,{block:e,busy:F.isPending||P.isPending,unreadable:t.ok?null:t.reason,onEdit:()=>{b(e),_(e.id),a?.(e.id)},onToggle:t=>F.mutate({blockId:e.id,enabled:t}),onToggleLogs:()=>C(S===e.id?null:e.id),onDelete:()=>{x({title:p(`automation.automationList.deleteThisAutomation`,`Delete this automation?`),message:p(`automation.automationList.deleteMessage`,`{{name}} will be deleted. This cannot be undone.`,{name:e.name}),confirmLabel:p(`common.delete`,`Delete`),variant:`danger`}).then(t=>{t&&P.mutate(e.id)})}})}}],[x,S,a,_,P,F,p]);return E?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(j,{className:`h-4 w-4 text-foreground-muted`}),B===null?p(`build.automationsTab.newAutomation`,`New automation`):p(`build.automationsTab.edit`,`Edit {{name}}`,{name:B.name})]}),o(ra,{existing:B,initialRecipe:V!==null&&V.ok?V.recipe:On,saving:M.isPending||N.isPending,saveError:te,ejecting:I.isPending,onSave:e=>{B===null?M.mutate(e):N.mutate({blockId:B.id,block:e})},onEject:()=>{B!==null&&I.mutate(B)},onCancel:()=>{M.reset(),N.reset(),I.reset(),b(null),v(),a?.(null)}},B?.id??`new`),P.error!=null&&o(q,{message:ga(P.error)})]}):e(`div`,{className:`space-y-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:L===void 0?``:ua(R)}),D.error!=null&&o(q,{title:p(`build.automationsTab.couldNotReadTheAutomations`,`Could not read the automations`),message:ga(D.error),onRetry:O}),z?o(pa,{onCreate:()=>{b(null),g(),a?.(null)}}):o(Ce,{columns:ne,rows:R,rowKey:e=>e.id,pageSize:25,maxBodyHeight:st,emptyMessage:L===void 0?p(`build.automationsTab.loadingAutomations`,`Loading automations…`):p(`build.automationsTab.noAutomationsYet`,`No automations yet.`),onRowClick:e=>{b(e),_(e.id),a?.(e.id)}}),P.error!=null&&o(q,{message:ga(P.error)}),F.error!=null&&o(q,{message:ga(F.error)})]})}u();function va({preset:t,saving:n,onSave:i,onBack:a}){let{t:s,i18n:l}=Z(),u=Ut(!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=>[W({addonId:e.addonId,stableId:e.stableId}),e.name])):new Map,[u]),S=r(()=>new Set(Object.values(d).flatMap(e=>e===void 0?[]:[W(e)])),[d]),C=r(()=>u.kind===`known`?{kind:`known`,value:Bt(u.value,S)}:u,[u,S]),w=Qt(t,d),T=u.kind===`known`?$t(u.value,w,!1):null,E=t.build(d),D=Jt(t,d),O=(e,t)=>{v([]),f(n=>({...n,[e]:t}))},k=e=>x.get(W(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(K,{"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:[Xt(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:Xt(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(Zt,{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(Kt,{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 ya=`preset`;function ba({mode:e,onTitle:t}){return o(e===`helper`?xa:Sa,{onTitle:t})}function xa({onTitle:e}){let{t}=Z(),r=St(),i=Ge(),a=ft(),l=Ke({addonId:`composer`}),[u,d]=c(null),[f,p]=c(!1),[m,h]=Ot(),g=Wt(m.get(ya)),_=g===null?wa(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(ya):n.set(ya,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 Oa(o.id,async()=>(await l.refetch()).data??l.data);return s===null?{kind:`refused`,lines:qt(t(`helper.devicePending`))}:(n!==``&&await a.mutateAsync({deviceId:s,name:n}),r(Tt(s),{replace:!0}),{kind:`saved`,deviceId:s})}catch(e){return{kind:`refused`,lines:qt(e instanceof Error?e.message:String(e))}}},b=n(null);return f?o(Sa,{onTitle:e}):g===null?o(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3`,"data-testid":`composition-create-form`,children:o(Yt,{fillHeight:!0,onFreeComposition:()=>p(!0),onPreset:v,purpose:`create`,initial:null,start:`template`,saving:i.isPending,onDraftChange:d,onSave:async(e,n)=>{let o=null,s=await en(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 Oa(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(Ct(f),{replace:!0})}),c=o;return s.length>0||c===null?{kind:`refused`,lines:ka(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(va,{preset:g,saving:i.isPending,onSave:y,onBack:()=>v(null)})})}function Sa({onTitle:t}){let{t:n}=Z(),r=O(),i=St(),a=Ge(),l=ft(),u=Ke({addonId:`composer`}),[d,f]=c(ce.Sensor),[p,m]=c(V.TemperatureSensor),[h,g]=c(``),[_,v]=c(null),y=Vt({type:d,role:p});return s(()=>{t(n(`helper.newComposition`))},[t,n]),e(`div`,{className:`flex flex-col gap-3`,"data-testid":`blank-composition-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(G,{value:d,onChange:e=>{let t=Object.values(ce).find(t=>t===e.target.value);t!==void 0&&f(t)},options:Object.values(ce).map(e=>({value:e,label:at(e,r).label}))})]}),e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[n(`customize.identity.role`),o(G,{value:p??``,onChange:e=>m(Object.values(V).find(t=>t===e.target.value)??null),options:[{value:``,label:n(`customize.identity.noRole`)},...Object.values(V).map(e=>({value:e,label:Ve(e,r).label}))]})]}),e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[n(`compositionEditor.name`),o(K,{"aria-label":n(`compositionEditor.name`),value:h,onChange:e=>g(e.target.value)})]})]}),_!==null&&o(`p`,{role:`alert`,className:`text-xs text-danger`,children:_}),o(Y,{disabled:y===null||a.isPending,onClick:()=>{y!==null&&Ca({composition:y,name:h,create:e=>a.mutateAsync({block:e}),rename:(e,t)=>l.mutateAsync({deviceId:e,name:t}),readFleet:async()=>(await u.refetch()).data??u.data,onError:e=>v(e),onOpen:e=>i(Tt(e),{replace:!0}),pending:n(`helper.devicePending`)})},children:n(`compositionEditor.save`)})]})}async function Ca(e){e.onError(null);try{let t=e.name.trim(),{block:n}=await e.create({...t===``?{}:{name:t},enabled:!0,composition:e.composition}),r=await Oa(n.id,e.readFleet);if(r===null){e.onError(e.pending);return}t!==``&&await e.rename(r,t),e.onOpen(r)}catch(t){e.onError(t instanceof Error?t.message:String(t))}}function wa(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}`);if(e.templateId===`appliance`&&e.appliance!==null)return t(`helper.newTitle.${e.appliance}`);if(e.templateId===`appliance`)return t(`helper.newComposed`);let n=B(e.templateId);return t(n===null?`helper.newComposed`:`helper.newTitle.${n.id}`)}async function Ta(e,t){let n=`${le}${e}`;return(await t())?.find(e=>e.stableId===n)?.id??null}var Ea=10,Da=400;async function Oa(e,t,n=Da){for(let r=0;r<Ea;r+=1){let r=await Ta(e,t);if(r!==null)return r;await new Promise(e=>setTimeout(e,n))}return null}function ka(e,t){return e.length>0?e:qt(t(`helper.devicePending`))}function Aa(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`appliance`:return{section:`group`,kind:`appliance`};case`arithmetic`:return{section:`calculation`,kind:t.op};case`expression`:return{section:`advanced`,kind:`expression`};default:return{section:`calculation`,kind:t.kind}}}function ja(e){return{state:`answered`,byRef:new Map(e.map(e=>[W(e),e]))}}function Ma(e,t){if(e.state!==`unanswered`)return e.byRef.get(W(t))??null}function Na(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function Pa(e){return ue(e).map(e=>e.source)}function Fa(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(...Pa(t));for(let t of Object.values(e.items??{}))for(let e of Object.values(t.fields))n.push(...Pa(e))}let r=new Set;return n.filter(e=>{let t=W(e);return r.has(t)?!1:(r.add(t),!0)})}function Ia(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 La(e,t){let n=e.reason??t??null;switch(e.status){case`running`:return Ia(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 Ra(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 La(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 za(e){return W(e)}function Ba(e,t){let n=Ma(t,e);return{key:W(e),label:n?n.name:za(e),presence:Na(n),deviceId:n?n.id:null}}function Va(e){return e.state.kind===`answered`&&e.state.state!==null?e.state.state.deviceId:null}function Ha(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:F(e.block.id),a=W(i),o=Fa(e).filter(e=>W(e)!==a).map(e=>Ba(e,t)),s=n.features.map(e=>e.enabled===!1?X.t(`helpers.compositionRows.featureOff`,{cap:e.cap}):e.cap),c=Ma(t,i),l=Va(e),u=Ra(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:Aa(n),features:s,state:u,sources:o,reportedDeviceId:l};let d=Na(c);return{blockId:e.block.id,kind:`customization`,name:c?c.name:za(r.device),namePresence:d,type:c?c.type:null,origin:Aa(n),features:s,state:u,sources:o,reportedDeviceId:l}}function Ua(e){return e.state.tone===`error`?0:e.state.tone===`pending`?1:e.state.tone===`ok`?2:3}function Wa(e,t){return Ua(e)-Ua(t)||e.name.localeCompare(t.name)}function Ga(e,t){let n=e.flatMap(e=>{let n=Ha(e,t);return n===null?[]:[n]});return{composed:n.filter(e=>e.kind===`composed`).toSorted(Wa),customizations:n.filter(e=>e.kind===`customization`).toSorted(Wa)}}u();var Ka=1e4;function qa(e){return e instanceof Error?e.message:typeof e==`object`&&e&&`message`in e?String(e.message):String(e)}function Ja(){let e=wt();return e.data===void 0?{state:`unanswered`,reason:e.error==null?X.t(`build.customDeviceTab.deviceListPending`):X.t(`build.customDeviceTab.deviceListUnreadable`,{error:qa(e.error)})}:ja(e.data)}function Ya(e,t){return e===`blank`?`blank`:e===`helper`||e===`1`||t?`helper`:null}function Xa({createRequested:t=!1,onCreateConsumed:n}={}){let{t:r}=Z(),[i,a]=Ot(),s=Ze({},{refetchInterval:Ka}),l=Ja(),u=et({editKey:`block`,newKey:`new`}),d=u.state.mode===`edit`?u.state.id:null,f=d===null?Ya(i.get(`new`),t):null,m=f!==null,[h,g]=c(``),_=A(),v=Je(),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:[Qa(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(yt,{open:m,onClose:y,title:h||r(f===`blank`?`helper.newComposition`:`helper.newComposed`),icon:ge,width:`xl`,testId:`composed-device-editor`,fill:!0,children:f!==null&&o(ba,{mode:f,onTitle:g},f)}),o(zt,{blockId:d,onClose:y}),v.error!=null&&o(q,{message:qa(v.error)})]})}function Za(t){return o(Le,{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 Qa(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:qa(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 Za(e.reason);let a=t==null?null:qa(t);return o($a,{lists:Ga(e.views,r),fleet:r,refreshError:a,handlers:i})}function $a({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(eo,{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(eo,{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 eo({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(Ce,{columns:to(i,s,c,l),rows:r,rowKey:e=>e.blockId,pageSize:25,maxBodyHeight:st,emptyMessage:a,onRowClick:s===`composed`?e=>c.onEditComposed(e.blockId):void 0})]})}function to(t,n,r,i){let a=[{key:`name`,header:t,sortValue:e=>e.name.toLowerCase(),render:e=>o(ro,{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=>no(e.origin,i),render:e=>o(J,{variant:`default`,"data-testid":`composed-origin-badge`,children:no(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(J,{variant:sa(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(ao,{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 no(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 ro({row:t}){let{t:n}=Z();return e(`div`,{className:`space-y-0.5`,children:[o(io,{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 io({row:e}){let{t}=Z(),n=Ye(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(Et,{to:e.kind===`composed`?Ct(e.reportedDeviceId):Tt(e.reportedDeviceId),className:`text-xs font-medium text-foreground hover:underline`,onClick:e=>e.stopPropagation(),children:r})}function ao({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(Et,{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 oo(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 so(e){if(Array.isArray(e))return e}function co(e,t,n){return(t=vo(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function lo(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 uo(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
5
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function fo(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 po(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?fo(Object(n),!0).forEach(function(t){co(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):fo(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function mo(e,t){if(e==null)return{};var n,r,i=ho(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 ho(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 go(e,t){return so(e)||lo(e,t)||yo(e,t)||uo()}function _o(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 vo(e){var t=_o(e,`string`);return typeof t==`symbol`?t:t+``}function yo(e,t){if(e){if(typeof e==`string`)return oo(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)?oo(e,t):void 0}}function bo(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function xo(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 So(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?xo(Object(n),!0).forEach(function(t){bo(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):xo(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Co(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}}function wo(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 To(e){return{}.toString.call(e).includes(`Object`)}function Eo(e){return!Object.keys(e).length}function Do(e){return typeof e==`function`}function Oo(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function ko(e,t){return To(t)||Po(`changeType`),Object.keys(t).some(function(t){return!Oo(e,t)})&&Po(`changeField`),t}function Ao(e){Do(e)||Po(`selectorType`)}function jo(e){Do(e)||To(e)||Po(`handlerType`),To(e)&&Object.values(e).some(function(e){return!Do(e)})&&Po(`handlersType`)}function Mo(e){e||Po(`initialIsRequired`),To(e)||Po(`initialType`),Eo(e)&&Po(`initialContent`)}function No(e,t){throw Error(e[t]||e.default)}var Po=wo(No)({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"}),Fo={changes:ko,selector:Ao,handler:jo,initial:Mo};function Io(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};Fo.initial(e),Fo.handler(t);var n={current:e},r=wo(zo)(n,t),i=wo(Ro)(n),a=wo(Fo.changes)(e),o=wo(Lo)(n);function s(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(e){return e};return Fo.selector(e),e(n.current)}function c(e){Co(r,i,a,o)(e)}return[s,c]}function Lo(e,t){return Do(t)?t(e.current):t}function Ro(e,t){return e.current=So(So({},e.current),t),t}function zo(e,t,n){return Do(t)?t(e.current):Object.keys(n).forEach(function(n){return t[n]?.call(t,e.current[n])}),n}var Bo={create:Io},Vo={paths:{vs:`https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs`}};function Ho(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 Uo(e){return{}.toString.call(e).includes(`Object`)}function Wo(e){return e||Jo(`configIsRequired`),Uo(e)||Jo(`configType`),e.urls?(Go(),{paths:{vs:e.urls.monacoBase}}):e}function Go(){console.warn(qo.deprecation)}function Ko(e,t){throw Error(e[t]||e.default)}var qo={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!
|
|
6
|
+
You are using deprecated way of configuration.
|
|
7
|
+
|
|
8
|
+
Instead of using
|
|
9
|
+
monaco.config({ urls: { monacoBase: '...' } })
|
|
10
|
+
use
|
|
11
|
+
monaco.config({ paths: { vs: '...' } })
|
|
12
|
+
|
|
13
|
+
For more please check the link https://github.com/suren-atoyan/monaco-loader#config
|
|
14
|
+
`},Jo=Ho(Ko)(qo),Yo={config:Wo},Xo=function(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}};function Zo(e,t){return Object.keys(t).forEach(function(n){t[n]instanceof Object&&e[n]&&Object.assign(t[n],Zo(e[n],t[n]))}),po(po({},e),t)}var Qo={type:`cancelation`,msg:`operation is manually canceled`};function $o(e){var t=!1,n=new Promise(function(n,r){e.then(function(e){return t?r(Qo):n(e)}),e.catch(r)});return n.cancel=function(){return t=!0},n}var es=[`monaco`],ts=go(Bo.create({config:Vo,isInitialized:!1,resolve:null,reject:null,monaco:null}),2),ns=ts[0],rs=ts[1];function is(e){var t=Yo.config(e),n=t.monaco,r=mo(t,es);rs(function(e){return{config:Zo(e.config,r),monaco:n}})}function as(){var e=ns(function(e){return{monaco:e.monaco,isInitialized:e.isInitialized,resolve:e.resolve}});if(!e.isInitialized){if(rs({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),$o(fs);if(window.monaco&&window.monaco.editor)return us(window.monaco),e.resolve(window.monaco),$o(fs);Xo(os,cs)(ls)}return $o(fs)}function os(e){return document.body.appendChild(e)}function ss(e){var t=document.createElement(`script`);return e&&(t.src=e),t}function cs(e){var t=ns(function(e){return{config:e.config,reject:e.reject}}),n=ss(`${t.config.paths.vs}/loader.js`);return n.onload=function(){return e()},n.onerror=t.reject,n}function ls(){var e=ns(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;us(n),e.resolve(n)},function(t){e.reject(t)})}function us(e){ns().monaco||rs({monaco:e})}function ds(){return ns(function(e){return e.monaco})}var fs=new Promise(function(e,t){return rs({resolve:e,reject:t})}),ps={config:is,init:as,__getMonacoInstance:ds};u();var ms={wrapper:{display:`flex`,position:`relative`,textAlign:`initial`},fullWidth:{width:`100%`},hide:{display:`none`}},hs={container:{display:`flex`,height:`100%`,width:`100%`,justifyContent:`center`,alignItems:`center`}};function gs({children:e}){return t.createElement(`div`,{style:hs.container},e)}var _s=gs;function vs({width:e,height:n,isEditorReady:r,loading:i,_ref:a,className:o,wrapperProps:s}){return t.createElement(`section`,{style:{...ms.wrapper,width:e,height:n},...s},!r&&t.createElement(_s,null,i),t.createElement(`div`,{ref:a,style:{...ms.fullWidth,...!r&&ms.hide},className:o}))}var ys=i(vs);function bs(e){s(e,[])}var xs=bs;function Ss(e,t,r=!0){let i=n(!0);s(i.current||!r?()=>{i.current=!1}:e,t)}var $=Ss;function Cs(){}function ws(e,t,n,r){return Ts(e,r)||Es(e,t,n,r)}function Ts(e,t){return e.editor.getModel(Ds(e,t))}function Es(e,t,n,r){return e.editor.createModel(t,n,r?Ds(e,r):void 0)}function Ds(e,t){return e.Uri.parse(t)}function Os({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=Cs,onMount:S=Cs}){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);xs(()=>{let e=ps.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=ws(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=ws(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=ws(O.current,e||``,o||i||`text`,u||``),n=ws(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(ys,{width:v,height:_,isEditorReady:C,loading:h,_ref:k,className:y,wrapperProps:b})}i(Os);function ks(e){let t=n();return s(()=>{t.current=e},[e]),t.current}var As=ks,js=new Map;function Ms({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=Cs,onMount:C=Cs,onChange:w,onValidate:T=Cs}){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=As(u),R=n(!1),z=n(!1);xs(()=>{let e=ps.init();return e.then(e=>(A.current=e)&&k(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>j.current?B():e.cancel()}),$(()=>{let t=ws(A.current,e||o||``,r||l||``,u||i||``);t!==j.current?.getModel()&&(g&&js.set(L,j.current?.saveViewState()),j.current?.setModel(t),g&&j.current?.restoreViewState(js.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 ee=a(()=>{if(!(!M.current||!A.current)&&!R.current){P.current(A.current);let t=u||i,n=ws(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(js.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&&ee()},[O,E,ee]),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 B(){F.current?.dispose(),_?g&&js.set(u,j.current.saveViewState()):j.current.getModel()?.dispose(),j.current.dispose()}return t.createElement(ys,{width:v,height:y,isEditorReady:E,loading:p,_ref:M,className:b,wrapperProps:x})}var Ns=i(Ms);u();function Ps(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 Fs={target:99,module:99,moduleResolution:2,strict:!0,noImplicitAny:!0,strictNullChecks:!0,allowNonTsExtensions:!0,isolatedModules:!0};function Is(e,t){let n=e.languages.typescript.typescriptDefaults;n.setCompilerOptions({...n.getCompilerOptions(),...Fs}),n.setExtraLibs(t.map(e=>({filePath:e.filePath,content:e.content})))}function Ls({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,Is(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&&Is(e,r)},[r]),o(Ns,{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 Rs(e){return e.some(e=>e.severity>=8)}var zs=[{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'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A core block. Runs in its own process, with the same \`ctx\` an addon gets.
|
|
18
|
+
* Return a function to release whatever you took (timers, sockets, listeners).
|
|
19
|
+
*
|
|
20
|
+
* Declaring devices: import { reconcileBlockDevices, exposeBlockDevices } from
|
|
21
|
+
* '@camstack/types' and hang them off the shared Blocks integration.
|
|
22
|
+
*/
|
|
23
|
+
export default function block(ctx: AddonContext) {
|
|
24
|
+
ctx.logger.info('hello from a core block')
|
|
25
|
+
|
|
26
|
+
const timer = setInterval(() => {
|
|
27
|
+
ctx.logger.info('tick')
|
|
28
|
+
}, 60_000)
|
|
29
|
+
|
|
30
|
+
return () => {
|
|
31
|
+
clearInterval(timer)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
`}}];function Bs(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 Vs=zs.find(e=>e.id===`blank`)?.files[`main.ts`]??`import type { AddonContext } from '@camstack/types'
|
|
35
|
+
|
|
36
|
+
export default function block(ctx: AddonContext) {
|
|
37
|
+
ctx.logger.info('hello from a core block')
|
|
38
|
+
return () => undefined
|
|
39
|
+
}
|
|
40
|
+
`;function Hs({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 Us=5e3;function Ws(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 Gs({blockId:t}){let{t:n}=Z(),i=L(t),a=Ae({addonId:i,projection:`slim`},{refetchInterval:Us}),s=r(()=>Ws(a.data),[a.data]);return a.isLoading?e(`p`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[o(E,{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(Dt,{i18nKey:`build.scriptDevicesPanel.declaredBy`,values:{addonId:i},components:{code:o(`code`,{className:`text-[11px]`})}})})]}),o(J,{variant:`default`,children:s.length})]}),s.length===0?o(`p`,{className:`text-xs text-foreground-subtle`,children:o(Dt,{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(Et,{to:`/devices/${String(t.id)}`,className:`text-sm font-medium hover:underline`,title:n(`build.scriptDevicesPanel.openDeviceDetail`,`Open device detail`),children:o(qe,{device:{id:t.id,name:t.name,type:t.type,stableId:t.stableId??``,parentDeviceId:null},form:`compact`})}),o(J,{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 Ks(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 qs(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 Js(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 Ys(e){if(typeof e!=`object`||!e||!(`key`in e))return null;let t=Reflect.get(e,`key`);return typeof t==`string`?t:null}function Xs(e){if(!(typeof e!=`object`||!e||!(`value`in e)))return Reflect.get(e,`value`)}function Zs(e){let t={};for(let n of e.sections)for(let e of n.fields){let n=Ys(e);n!==null&&(t[n]=Xs(e))}return t}function Qs(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function $s({blockId:t}){let{t:n}=Z(),i=w(),s=je({blockId:t},{retry:!1}),l=Ne({blockId:t},{refetchInterval:1e4,retry:!1}),u=ot({onSuccess:()=>{l.refetch()}}),d=Be(),f=Se(),[p,m]=c(null),[h,g]=c(null),[_,v]=c(null),[y,b]=c(!1),x=Qs(l.data)?l.data:null,S=r(()=>x===null?{}:Zs(x),[x]),C=p??S,T=a(e=>{m(e)},[]),D=p!==null,O=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]),k=a(async(e,n)=>{if(Ks(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:qs(e)}),s.data?.block?.enabled!==!0&&(await f.mutateAsync({blockId:t,enabled:!0}),v(Js(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(E,{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(Dt,{i18nKey:`build.scriptSettingsPanel.declaredBy`,components:{code:o(`code`,{})}})})]}),e(Y,{size:`sm`,variant:`primary`,onClick:O,disabled:!D||u.isPending||y,children:[u.isPending&&o(E,{className:`h-3.5 w-3.5 animate-spin`}),n(`build.scriptSettingsPanel.saveSettings`,`Save settings`)]})]}),o(bt,{schema:x,values:C,onChange:T,onAction:k}),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 ec=`hub`;function tc({existing:t,typeDefs:n,typeDefsLoading:i,saving:a,saveError:s,restarting:l,restartError:u,onRestart:d,onSave:m,onCancel:h}){let{t:g}=Z(),_=w(),v=A(),{resolvedMode:y}=it(),b=ie({code:t?.code??Vs,files:t?.files,entry:t?.entry}),[x,S]=c(t?.name??``),[T,D]=c(b.files),[O,k]=c(b.entry),[j,F]=c(b.entry),[I,R]=c(t?.placement??ec),[z,ee]=c(t?.integrationId??``),[B,V]=c([]),[te,ne]=c(!1),[re,ae]=c(`blank`),[H,oe]=c(null),[se,ce]=c(``),le=T[j]??``,ue=e=>{D(t=>({...t,[j]:e}))},de=Object.keys(T).toSorted(),fe=zs.length>1,pe=r(()=>[...n?.libs??[],...Ps(T,j)],[n?.libs,T,j]),U=f({mutationFn:()=>_.trpcClient.coreBlocks.compile.mutate({files:T,entry:O})}),W=r(()=>B.filter(e=>e.severity>=8),[B]),me=Rs(B),he=x.trim()===``,ge=t===null?null:ie(t),_e=t===null||ge===null||JSON.stringify(T)!==JSON.stringify(ge.files)||O!==ge.entry||x.trim()!==t.name||I!==t.placement||(z.trim()===``?void 0:z.trim())!==t.integrationId,ve=()=>{U.reset(),m({name:x.trim(),files:T,entry:O,enabled:t?.enabled??!0,placement:I,...z.trim()===``?{}:{integrationId:z.trim()}})},ye=()=>{let e=Bs(Object.keys(T));D(t=>({...t,[e]:``})),F(e),oe(e),ce(e)},be=e=>{oe(e),ce(e)},xe=()=>{if(H===null)return;let e=H,t=se.trim();if(oe(null),!(t===``||t===e)){if(T[t]!==void 0){F(t);return}D(n=>{let r={};for(let[i,a]of Object.entries(n))r[i===e?t:i]=a;return r}),O===e&&k(t),F(t)}},Se=async e=>{let t=zs.find(t=>t.id===e);if(t===void 0)return;let n=zs.find(e=>e.id===`blank`);!(n!==void 0&&JSON.stringify(T)===JSON.stringify(n.files)&&O===n.entry)&&!await v({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`})||(ae(e),D({...t.files}),k(t.entry),F(t.entry),(x.trim()===``||re===`blank`)&&S(t.id===`blank`?``:t.name))},G=t===null?null:oa(t),Ce=Hs({existing:t,dirty:_e,saving:a,restarting:l});return e(`div`,{className:`space-y-4`,children:[G!==null&&o(`div`,{className:`flex flex-wrap items-center gap-2`,children:o(J,{variant:sa(G.tone),children:G.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(K,{className:`mt-1`,value:x,onChange:e=>S(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(K,{className:`mt-1`,value:z,onChange:e=>ee(e.target.value),placeholder:g(`build.blockEditor.leaveEmptyForTheShared`,`Leave empty for the shared system integration`)})]})]}),t===null&&fe&&e(`label`,{className:`block text-sm`,children:[o(`span`,{className:`text-foreground-subtle`,children:g(`build.blockEditor.startFrom`,`Start from`)}),o(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1.5 text-sm`,value:re,onChange:e=>void Se(e.target.value),"data-testid":`script-example-select`,children:zs.map(t=>e(`option`,{value:t.id,children:[t.name,` — `,t.description]},t.id))})]}),e(`div`,{children:[o(De,{selectedNodeId:I,onSelect:R,label:g(`build.blockEditor.runsOn`,`Runs on`),alwaysShow:!0}),I!==ec&&e(`p`,{className:`mt-2 flex items-start gap-2 text-xs text-warning`,children:[o(P,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),o(`span`,{children:o(Dt,{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:[de.map(t=>H===t?o(K,{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(`button`,{type:`button`,className:`rounded px-2 py-1 text-xs ${t===j?`bg-muted font-medium text-foreground`:`text-foreground-subtle hover:text-foreground`}`,onClick:()=>F(t),onDoubleClick:()=>be(t),title:g(`build.blockEditor.doubleClickToRename`,`Double-click to rename`),"data-testid":`script-file-tab-${t}`,children:[t,t===O?` · ${g(`build.blockEditor.entry`)}`:``]},t)),o(`button`,{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`)}),j!==O&&o(`button`,{type:`button`,className:`rounded px-2 py-1 text-xs text-foreground-subtle hover:text-foreground`,onClick:()=>k(j),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(Ls,{value:le,onChange:ue,path:`file:///${j}`,extraLibs:pe,onDiagnostics:V,dark:y===`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.`)}),W.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:W.length})}),W.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}`)),W.length>5&&o(`p`,{className:`text-foreground-subtle`,children:g(`build.blockEditor.moreErrors`,{count:W.length-5})})]}),U.data!==void 0&&(U.data.ok?e(`p`,{className:`flex items-center gap-2 text-xs text-success`,children:[o(C,{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:[U.data.line!==void 0&&o(`span`,{className:`mr-1`,children:g(`build.blockEditor.errorLine`,{line:String(U.data.line)})}),U.data.error??g(`build.blockEditor.theCodeDoesNotCompile`,`the code does not compile`)]})),U.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:`),` `,nc(U.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($s,{blockId:t.id}),o(Gs,{blockId:t.id})]}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(Y,{variant:`outline`,onClick:()=>U.mutate(),disabled:U.isPending||a,title:g(`build.blockEditor.typeCheckOnTheNode`,`Type-check on the node without saving`),children:[U.isPending&&o(E,{className:`h-4 w-4 animate-spin`}),` `,g(`common.compile`)]}),e(Y,{onClick:ve,disabled:a||me||he,children:[a&&o(E,{className:`h-4 w-4 animate-spin`}),` `,g(`common.save`)]}),e(Y,{variant:`outline`,onClick:()=>d?.(),disabled:Ce!==null||d===void 0,title:Ce??g(`build.blockEditor.stopTheProcessAndLet`,`Stop the process and let the supervisor bring it back`),children:[l?o(M,{className:`h-4 w-4 animate-spin`}):o(M,{className:`h-4 w-4`}),` `,g(`build.blockEditor.restart`,`Restart`)]}),e(Y,{variant:`ghost`,onClick:()=>ne(!te),title:g(`build.blockEditor.showThisScriptSProcess`,`Show this script's process logs`),"data-testid":`script-logs-toggle`,children:[o(N,{className:`h-4 w-4`}),` `,g(`common.logs`),` `,te?`▾`:`▸`]}),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:W.length}),_e&&t!==null?` · ${g(`build.blockEditor.unsavedChanges`)}`:``]}),he&&o(J,{variant:`warning`,children:g(`build.blockEditor.nameRequired`,`Name required`)})]}),te&&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(Dt,{i18nKey:`build.blockEditor.logsOf`,values:{id:L(t.id)},components:{code:o(`code`,{})}})})}),t!==null&&o(nt,{addonId:L(t.id),maxHeight:`max-h-[560px]`,showFilters:!1})]})]})}function nc(e){return e instanceof Error?e.message:String(e)}u();var rc=[`coreBlocks`,`list`],ic=[`coreBlocks`,`getTypeDefs`],ac=5e3;function oc(e){return e instanceof Error?e.message:String(e)}function sc({initialBlockId:t,onBlockIdChange:i,createRequested:a=!1,onCreateConsumed:u}={}){let d=O(),{t:p}=Z(),m=w(),{state:h,openNew:g,openEdit:v,close:y}=et({editKey:`block`,newKey:`new`}),[b,x]=c(null),S=A(),[C,T]=c(null),E=l({queryKey:rc,refetchInterval:ac,queryFn:async()=>(await m.trpcClient.coreBlocks.list.query({})).blocks}),D=h.mode!==`closed`,k=l({queryKey:ic,enabled:D,staleTime:1/0,gcTime:1/0,queryFn:()=>m.trpcClient.coreBlocks.getTypeDefs.query({})}),j=()=>{E.refetch()},P=n(null),F=E.data;s(()=>{t===void 0||P.current===t||F?.find(e=>e.id===t&&re(e)===`code`)!==void 0&&(P.current=t,v(t),i?.(t))},[t,F,v,i]),s(()=>{a&&(x(null),g(),i?.(null),u?.())},[a,u,i,g]);let I=f({mutationFn:e=>m.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{x(e.block),v(e.block.id),i?.(e.block.id),j()}}),R=f({mutationFn:e=>m.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{x(e.block),v(e.block.id),i?.(e.block.id),j()}}),z=f({mutationFn:e=>m.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:j}),ee=f({mutationFn:e=>m.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:j}),B=f({mutationFn:e=>m.trpcClient.coreBlocks.restart.mutate({blockId:e}),onSuccess:j}),V=la((E.data??[]).filter(e=>re(e)===`code`)),te=E.data!==void 0&&V.length===0,ne=I.isPending||R.isPending,ie=I.error===null?R.error===null?null:oc(R.error):oc(I.error),ae=h.mode===`edit`?V.find(e=>e.id===h.id)??(b!==null&&b.id===h.id?b:null):null,H=h.mode===`new`||ae===null?null:ca(V,ae),oe=r(()=>[{key:`name`,header:p(`build.scriptsTab.name`,`Name`),render:t=>{let n=oa(t),r=$e(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(J,{variant:sa(n.tone),children:n.label}),o(J,{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}),C===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(Dt,{i18nKey:`common.logsOf`,values:{id:L(t.id)},components:{code:o(`code`,{})}})}),o(nt,{addonId:L(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=ee.isPending||z.isPending,r=B.isPending&&B.variables===t.id;return e(`div`,{className:`flex justify-end gap-1`,children:[o(Y,{variant:`ghost`,onClick:e=>{e.stopPropagation(),x(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(),B.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(M,{className:`h-4 w-4${r?` animate-spin`:``}`})}),o(Y,{variant:`ghost`,onClick:e=>{e.stopPropagation(),T(C===t.id?null:t.id)},title:p(`build.scriptsTab.logs`,`Logs`),children:o(N,{className:`h-4 w-4`})}),o(Y,{variant:`ghost`,onClick:e=>{e.stopPropagation(),ee.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(),S({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`})})]})}}],[S,C,i,v,z,B.isPending,B.variables,ee,p]);return e(`div`,{className:`space-y-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:E.data===void 0?``:ua(V)}),E.error!=null&&o(q,{title:p(`build.scriptsTab.couldNotReadTheScripts`,`Could not read the scripts`),message:oc(E.error),onRetry:j}),o(Ce,{columns:oe,rows:V,rowKey:e=>e.id,pageSize:25,maxBodyHeight:st,emptyMessage:te?p(`build.scriptsTab.noScriptsYetAScript`,`No scripts yet. A script is TypeScript the hub runs in its own process.`):E.data===void 0?p(`build.scriptsTab.loadingScripts`,`Loading scripts…`):p(`build.scriptsTab.noScriptsYet`,`No scripts yet.`),onRowClick:e=>{x(e),v(e.id),i?.(e.id)}}),o(yt,{open:D,onClose:()=>{I.reset(),R.reset(),B.reset(),x(null),y(),i?.(null)},title:H===null?p(`build.scriptsTab.newScript`,`New script`):p(`build.scriptsTab.edit`,`Edit {{name}}`,{name:H.name}),icon:ye,width:`xl`,testId:`script-editor-panel`,children:o(tc,{existing:H,typeDefs:k.data,typeDefsLoading:k.isLoading,saving:ne,saveError:ie,restarting:B.isPending,restartError:B.error===null?null:oc(B.error),onRestart:H===null?void 0:()=>B.mutate(H.id),onSave:e=>{let t=H;t===null?I.mutate(e):R.mutate({blockId:t.id,block:e})},onCancel:()=>{I.reset(),R.reset(),B.reset(),x(null),y(),i?.(null)}})}),z.error!=null&&o(q,{message:oc(z.error)}),ee.error!=null&&o(q,{message:oc(ee.error)}),B.error!=null&&o(q,{message:oc(B.error)})]})}var cc=[`automations`,`actions`,`scripts`,`custom-device`];function lc(e){return e!==null&&cc.some(t=>t===e)}var uc=[`coreBlocks`,`list`,`build-counts`],dc=[`actions`,`list`,`build-counts`],fc=[`block`,`action`,`create`,`new`];function pc(e){return e.filter(e=>re(e)===`code`).length}function mc(e){return e.filter(e=>rn(e.code)).length}function hc(e,t){return t===null?e:`${e} (${String(t)})`}function gc(){let{t}=Z(),n=w(),[r,i]=Ot(),a=r.get(`tab`),s=lc(a)?a:`automations`,c=r.get(`create`)===`1`,u=l({queryKey:uc,refetchInterval:5e3,queryFn:async()=>(await n.trpcClient.coreBlocks.list.query({})).blocks}).data,d=u===void 0?null:pc(u),f=u===void 0?null:mc(u),p=l({queryKey:dc,refetchInterval:1e4,queryFn:async()=>n.trpcClient.actions.list.query({})}),h=p.data===void 0?null:p.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`,`automations`),n.delete(`create`),e===null?n.delete(`block`):n.set(`block`,e),n},{replace:!0})},x=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})},S=()=>{i(e=>{let t=new URLSearchParams(e);return t.set(`create`,`1`),t.delete(`block`),t},{replace:!0})},C=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})},T=()=>{i(()=>{let e=new URLSearchParams(window.location.search);return e.delete(`create`),e},{replace:!0})},E=s===`automations`?t(`build.newAutomation`,`New automation`):s===`actions`?t(`build.newAction`,`New action`):t(`build.newScript`,`New script`),D=xt(`/build`,{t,isAdmin:!0})??{icon:m,title:t(`nav.build`,`Build-your-self`)};return o(kt,{icon:D.icon,title:D.title,subtitle:t(`build.automationsScriptsAndComposedDevices`,`Automations, scripts and composed devices — what this installation does on its own.`),defaultSection:`automations`,sectionsLabel:`${D.title} sections`,fill:!0,actions:s===`custom-device`?e(Y,{type:`button`,onClick:()=>C(`helper`),"data-testid":`build-new-composed`,children:[o(g,{className:`h-4 w-4`}),` `,t(`helper.newComposed`)]}):e(Y,{type:`button`,onClick:S,"data-testid":`build-new`,children:[o(g,{className:`h-4 w-4`}),` `,E]}),sections:[{id:`automations`,label:hc(t(`build.tabAutomations`,`Automations`),f),ownedParams:fc,content:o(_a,{onOpenScripts:y,initialBlockId:s===`automations`?r.get(`block`)??void 0:void 0,onBlockIdChange:b,createRequested:s===`automations`&&c,onCreateConsumed:T})},{id:`actions`,label:hc(t(`build.tabActions`,`Actions`),h),ownedParams:fc,content:o(Er,{createRequested:s===`actions`&&c,onCreateConsumed:T})},{id:`scripts`,label:hc(t(`build.tabCode`,`Code`),d),ownedParams:fc,content:o(sc,{initialBlockId:s===`scripts`?r.get(`block`)??void 0:void 0,onBlockIdChange:x,createRequested:s===`scripts`&&c,onCreateConsumed:T})},{id:`custom-device`,label:hc(t(`build.tabCustomDevice`,`Custom Device`),v),ownedParams:fc,content:o(Xa,{createRequested:s===`custom-device`&&c,onCreateConsumed:T})}]})}export{gc as BuildPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as e,K as t,R as n,S as r,Y as i,et as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Di as s,Ei as c}from"./player-overlays-CZbAbeZY.js";import{hr as l,mr as u}from"./client-D-g0nOrC.js";import{g as d}from"./video-CrmOxhYy.js";import{Ia as f,La as p,Ra as m,Sr as h,_r as g,br as _,ei as v,gr as y,vr as b,xr as x,za as S}from"./src-iRjUEwun.js";import{t as C}from"./i18n-COiZcYwm.js";import{t as w}from"./useTranslation-BJr-n0es.js";import{mr as T,pr as E}from"./index-Dqmlzvdc.js";import{t as D}from"./AdminPage-B9JLs4rT.js";a();var O=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`];function k(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function A(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function j(e){let t=e.getDay();return k(A(e,t===0?-6:1-t))}function M(e,t){if(t===`day`){let t=k(e);return{startMs:t.getTime(),endMs:A(t,1).getTime()}}if(t===`week`){let t=j(e);return{startMs:t.getTime(),endMs:A(t,7).getTime()}}let n=new Date(e.getFullYear(),e.getMonth(),1),r=new Date(e.getFullYear(),e.getMonth()+1,0),i=j(n),a=A(j(r),7);return{startMs:i.getTime(),endMs:a.getTime()}}function N(e,t){if(t===`day`)return e.toLocaleDateString(void 0,{weekday:`long`,year:`numeric`,month:`long`,day:`numeric`});if(t===`week`){let t=j(e),n=A(t,6),r={month:`short`,day:`numeric`};return`${t.toLocaleDateString(void 0,r)} – ${n.toLocaleDateString(void 0,{...r,year:`numeric`})}`}return e.toLocaleDateString(void 0,{month:`long`,year:`numeric`})}function P(e,t,n){return t===`day`?A(e,n):t===`week`?A(e,n*7):new Date(e.getFullYear(),e.getMonth()+n,1)}function F(e,t){if(t===void 0)return e;let n=t.calendars[e.id];return n===void 0?e:{...e,visible:n.visible??e.visible,color:n.color??e.defaultColor}}function I(e){return e.providerAddonId!==void 0&&e.providerAddonId.length>0?e.providerAddonId:e.source===`ha`?`Home Assistant`:e.source}function L(e){if(e.allDay===!0)return C.t(`systemPage.calendars.allDay`);let t=new Date(e.startMs),n=new Date(e.endMs),r={hour:`2-digit`,minute:`2-digit`};return`${t.toLocaleTimeString([],r)} – ${n.toLocaleTimeString([],r)}`}function R(e){let t=u(e),n=new Date(t.startMs),r=new Date(t.endMs),i={weekday:`short`,year:`numeric`,month:`short`,day:`numeric`};if(e.allDay===!0){let e=k(n),t=A(k(r),-1);return H(e,t)?C.t(`systemPage.calendars.dayAllDay`,{date:n.toLocaleDateString(void 0,i)}):C.t(`systemPage.calendars.rangeAllDay`,{from:n.toLocaleDateString(void 0,i),to:t.toLocaleDateString(void 0,i)})}let a={hour:`2-digit`,minute:`2-digit`};return H(n,r)?`${n.toLocaleDateString(void 0,i)} · ${n.toLocaleTimeString([],a)} – ${r.toLocaleTimeString([],a)}`:`${n.toLocaleString(void 0,{...i,...a})} – ${r.toLocaleString(void 0,{...i,...a})}`}function z({label:t,children:n}){return e(`div`,{className:`grid grid-cols-[7rem_minmax(0,1fr)] gap-x-3 gap-y-1 text-sm`,children:[r(`dt`,{className:`text-foreground-subtle`,children:t}),r(`dd`,{className:`min-w-0 break-words text-foreground`,children:n})]})}function B({ev:t,calendarName:n,color:i,onClose:a}){let{t:o}=w();return r(y,{open:!0,onOpenChange:e=>!e&&a(),children:e(b,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`calendars-event-detail`,children:[r(x,{children:e(`div`,{className:`flex min-w-0 items-start gap-2.5`,children:[r(`span`,{className:`mt-1.5 h-3 w-3 shrink-0 rounded-full`,style:{backgroundColor:i},"aria-hidden":!0}),r(h,{className:`min-w-0 break-words`,children:t.title})]})}),r(g,{children:e(`dl`,{className:`space-y-3`,children:[r(z,{label:o(`systemPage.calendars.when`,`When`),children:R(t)}),r(z,{label:o(`systemPage.calendars.calendar`,`Calendar`),children:n}),t.location!==void 0&&t.location.length>0?r(z,{label:o(`systemPage.calendars.location`,`Location`),children:t.location}):null,t.description!==void 0&&t.description.length>0?r(z,{label:o(`systemPage.calendars.description`,`Description`),children:r(`span`,{className:`whitespace-pre-wrap`,children:t.description})}):null]})}),r(_,{children:r(v,{type:`button`,size:`sm`,variant:`secondary`,onClick:a,children:o(`common.close`,`Close`)})})]})})}function V(e,t){return e.filter(e=>l(e,t))}function H(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function U({mode:e,onChange:t}){let{t:n}=w(),i=[{id:`month`,label:n(`systemPage.calendars.month`,`Month`)},{id:`week`,label:n(`systemPage.calendars.week`,`Week`)},{id:`day`,label:n(`systemPage.calendars.day`,`Day`)}];return r(`div`,{className:`inline-flex rounded-lg border border-border bg-surface p-0.5`,role:`group`,"aria-label":n(`systemPage.calendars.calendarView`,`Calendar view`),children:i.map(n=>r(`button`,{type:`button`,className:e===n.id?`rounded-md bg-primary px-2.5 py-1 text-xs font-medium text-primary-foreground`:`rounded-md px-2.5 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground`,"aria-pressed":e===n.id,onClick:()=>t(n.id),"data-testid":`calendars-view-${n.id}`,children:n.label},n.id))})}function W({calendars:t,onToggleVisible:n,onColorChange:i,busy:a}){let{t:o}=w();return e(`aside`,{className:`w-full shrink-0 space-y-2 lg:w-56 xl:w-64`,"data-testid":`calendars-legend`,children:[r(`h2`,{className:`text-xs font-medium text-foreground-subtle`,children:o(`systemPage.calendars.calendars`,`Calendars`)}),r(`ul`,{className:`space-y-1`,children:t.map(t=>e(`li`,{className:`flex items-start gap-2 rounded-md px-1.5 py-1.5 hover:bg-surface`,children:[r(`input`,{type:`checkbox`,className:`mt-1 h-3.5 w-3.5 shrink-0 accent-primary`,checked:t.visible,disabled:a,onChange:e=>n(t.id,e.target.checked),"aria-label":o(`systemPage.calendars.show`,`Show {{name}}`,{name:t.name}),"data-testid":`calendars-visible-${t.id}`}),r(`input`,{type:`color`,className:`mt-0.5 h-6 w-6 shrink-0 cursor-pointer rounded border border-border bg-transparent p-0`,value:t.color,disabled:a,onChange:e=>i(t.id,e.target.value.toUpperCase()),"aria-label":o(`systemPage.calendars.colourFor`,`Colour for {{name}}`,{name:t.name}),"data-testid":`calendars-color-${t.id}`}),e(`div`,{className:`min-w-0 flex-1`,children:[r(`div`,{className:`truncate text-sm font-medium ${t.visible?`text-foreground`:`text-foreground-subtle`}`,children:t.name}),e(`div`,{className:`truncate text-[11px] text-foreground-subtle`,children:[I(t),t.enabled?``:` · ${o(`systemPage.calendars.unavailableAtSource`)}`]})]})]},t.id))})]})}function G({ev:t,color:n,compact:i,onSelect:a}){return r(`button`,{type:`button`,className:i?`block w-full truncate rounded px-1 py-0.5 text-left text-[10px] leading-tight text-white hover:brightness-110`:`block w-full rounded-md px-2 py-1.5 text-left text-xs text-white hover:brightness-110`,style:{backgroundColor:n},title:t.title,onClick:()=>a(t),"data-testid":`calendars-event-${t.id}`,children:i?t.title:e(o,{children:[r(`div`,{className:`font-medium`,children:t.title}),r(`div`,{className:`opacity-90`,children:L(t)})]})})}function K({anchor:t,events:n,colorById:i,today:a,onSelectEvent:o}){let{t:s}=w(),{startMs:c,endMs:l}=M(t,`month`),u=[];for(let e=new Date(c);e.getTime()<l;e=A(e,1))u.push(e);let d=t.getMonth();return e(`div`,{"data-testid":`calendars-month`,children:[r(`div`,{className:`mb-1 grid grid-cols-7 gap-px`,children:O.map(e=>r(`div`,{className:`px-1 py-1 text-center text-[11px] font-medium text-foreground-subtle`,children:e},e))}),r(`div`,{className:`grid grid-cols-7 gap-px overflow-hidden rounded-lg border border-border bg-border`,children:u.map(t=>{let c=k(t).getTime(),l=V(n,c),u=t.getMonth()!==d,f=H(t,a);return e(`div`,{className:`min-h-[5.5rem] bg-background p-1 ${u?`opacity-45`:``}`,children:[r(`div`,{className:f?`mb-1 inline-flex h-5 w-5 items-center justify-center rounded-full bg-primary text-[11px] font-semibold text-primary-foreground`:`mb-1 text-[11px] font-medium text-foreground-subtle`,children:t.getDate()}),e(`div`,{className:`space-y-0.5`,children:[l.slice(0,3).map(e=>r(G,{ev:e,color:i.get(e.calendarId)??`#64748B`,compact:!0,onSelect:o},e.id)),l.length>3?r(`div`,{className:`text-[10px] text-foreground-subtle`,children:s(`common.moreCount`,{count:l.length-3})}):null]})]},c)})})]})}function q({anchor:t,events:n,colorById:i,today:a,onSelectEvent:o}){let s=j(t);return r(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-7 sm:gap-px sm:overflow-hidden sm:rounded-lg sm:border sm:border-border sm:bg-border`,"data-testid":`calendars-week`,children:Array.from({length:7},(e,t)=>A(s,t)).map(t=>{let s=k(t).getTime(),c=V(n,s);return e(`div`,{className:`min-h-[8rem] bg-background p-2 sm:min-h-[12rem]`,children:[r(`div`,{className:H(t,a)?`mb-2 text-xs font-semibold text-primary`:`mb-2 text-xs font-medium text-foreground-subtle`,children:t.toLocaleDateString(void 0,{weekday:`short`,day:`numeric`})}),r(`div`,{className:`space-y-1`,children:c.length===0?r(`p`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):c.map(e=>r(G,{ev:e,color:i.get(e.calendarId)??`#64748B`,onSelect:o},e.id))})]},s)})})}function J({anchor:t,events:n,colorById:i,calName:a,onSelectEvent:o}){let{t:s}=w(),c=V(n,k(t).getTime());return c.length===0?r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-day-empty`,children:s(`systemPage.calendars.noEventsOnThisDay`,`No events on this day.`)}):r(`ul`,{className:`divide-y divide-border rounded-lg border border-border`,"data-testid":`calendars-day`,children:c.map(t=>r(`li`,{children:e(`button`,{type:`button`,className:`flex w-full items-start gap-3 px-3 py-3 text-left hover:bg-surface`,onClick:()=>o(t),"data-testid":`calendars-event-${t.id}`,children:[r(`span`,{className:`mt-1 h-2.5 w-2.5 shrink-0 rounded-full`,style:{backgroundColor:i.get(t.calendarId)??`#64748B`}}),e(`div`,{className:`min-w-0`,children:[r(`div`,{className:`font-medium text-sm text-foreground`,children:t.title}),e(`div`,{className:`text-xs text-foreground-subtle`,children:[L(t),` · `,a.get(t.calendarId)??t.calendarId]}),t.location!==void 0&&t.location.length>0?r(`div`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:t.location}):null]})]})},t.id))})}function Y(){let{t:a}=w(),o=p(),l=f({}),u=S(),[h,g]=i(`month`),[_,v]=i(()=>k(new Date)),[y,b]=i(null),x=t(()=>k(new Date),[]),C=o.isSuccess,O=l.isSuccess&&l.data!==void 0?l.data:void 0,A=t(()=>!C||o.data===void 0?[]:o.data.map(e=>F(e,O)),[C,o.data,O]),j=t(()=>A.filter(e=>e.visible),[A]),I=t(()=>j.map(e=>e.id),[j]),L=t(()=>M(_,h),[_,h]),R=m({startMs:L.startMs,endMs:L.endMs,calendarIds:[...I]},{enabled:C&&I.length>0}),z=R.data??[],V=t(()=>{let e=new Map;for(let t of A)e.set(t.id,t.color);return e},[A]),H=t(()=>{let e=new Map;for(let t of A)e.set(t.id,t.name);return e},[A]),G=n((e,t)=>{u.mutateAsync({calendarId:e,visible:t}).then(()=>l.refetch())},[l,u]),Y=n((e,t)=>{/^#[0-9A-Fa-f]{6}$/.test(t)&&u.mutateAsync({calendarId:e,color:t}).then(()=>l.refetch())},[l,u]),X=n(()=>v(k(new Date)),[]),Z=n(()=>v(e=>P(e,h,-1)),[h]),ee=n(()=>v(e=>P(e,h,1)),[h]),Q=`inline-flex h-8 w-8 items-center justify-center rounded-lg border border-border bg-surface text-foreground hover:bg-primary/5 disabled:opacity-50`,$;return $=o.isPending?r(`p`,{className:`text-sm text-foreground-subtle`,children:a(`systemPage.calendars.loadingCalendars`,`Loading calendars…`)}):o.isError?e(`p`,{className:`text-sm text-destructive`,children:[a(`systemPage.calendars.couldNotListCalendars`,`Could not list calendars:`),` `,o.error.message]}):A.length===0?r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-sources`,children:r(E,{i18nKey:`systemPage.calendars.emptySources`,components:{link:r(T,{to:`/system/integrations?tab=calendars`,className:`text-accent underline-offset-2 hover:underline`})}})}):I.length===0?e(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[r(W,{calendars:A,onToggleVisible:G,onColorChange:Y,busy:u.isPending}),r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-hidden`,children:a(`systemPage.calendars.allCalendarsAreHiddenTurn`,`All calendars are hidden. Turn one on in the legend to see events.`)})]}):e(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[r(W,{calendars:A,onToggleVisible:G,onColorChange:Y,busy:u.isPending}),e(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(U,{mode:h,onChange:g}),e(`div`,{className:`flex items-center gap-1`,children:[r(`button`,{type:`button`,className:Q,onClick:Z,"aria-label":a(`systemPage.calendars.previous`,`Previous`),"data-testid":`calendars-prev`,children:r(s,{className:`h-4 w-4`})}),r(`button`,{type:`button`,className:`inline-flex items-center rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5`,onClick:X,"data-testid":`calendars-today`,children:a(`systemPage.calendars.today`,`Today`)}),r(`button`,{type:`button`,className:Q,onClick:ee,"aria-label":a(`common.next`,`Next`),"data-testid":`calendars-next`,children:r(c,{className:`h-4 w-4`})})]}),r(`span`,{className:`text-sm font-medium text-foreground`,"data-testid":`calendars-period`,children:N(_,h)})]}),R.isPending?r(`p`,{className:`text-sm text-foreground-subtle`,children:a(`systemPage.calendars.loadingEvents`,`Loading events…`)}):R.isError?e(`p`,{className:`text-sm text-destructive`,children:[a(`systemPage.calendars.couldNotListEvents`,`Could not list events:`),` `,R.error.message]}):h===`month`?r(K,{anchor:_,events:z,colorById:V,today:x,onSelectEvent:b}):h===`week`?r(q,{anchor:_,events:z,colorById:V,today:x,onSelectEvent:b}):r(J,{anchor:_,events:z,colorById:V,calName:H,onSelectEvent:b})]})]}),e(D,{icon:d,title:a(`systemPage.calendars.calendars`,`Calendars`),subtitle:a(`systemPage.calendars.calendarsFromConnectedSourcesUsed`,`Calendars from connected sources. Used by Calendar events notification rules.`),children:[$,y===null?null:r(B,{ev:y,calendarName:H.get(y.calendarId)??y.calendarId,color:V.get(y.calendarId)??`#64748B`,onClose:()=>b(null)})]})}export{Y as CalendarsPage,Y as default};
|
|
1
|
+
import{C as e,K as t,R as n,S as r,Y as i,et as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Di as s,Ei as c}from"./player-overlays-oTS1TZZY.js";import{_r as l,vr as u}from"./client-DcvpIFoh.js";import{g as d}from"./video-Dx3E7zlj.js";import{Ba as f,Cr as p,Ha as m,Tr as h,Va as g,br as _,ri as v,wr as y,xr as b,yr as x,za as S}from"./src-XEHc18wE.js";import{t as C}from"./i18n-C-H4BlYV.js";import{t as w}from"./useTranslation-BJr-n0es.js";import{mr as T,pr as E}from"./index-o6kBNilE.js";import{t as D}from"./AdminPage-B1Q3Lunl.js";a();var O=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`];function k(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function A(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function j(e){let t=e.getDay();return k(A(e,t===0?-6:1-t))}function M(e,t){if(t===`day`){let t=k(e);return{startMs:t.getTime(),endMs:A(t,1).getTime()}}if(t===`week`){let t=j(e);return{startMs:t.getTime(),endMs:A(t,7).getTime()}}let n=new Date(e.getFullYear(),e.getMonth(),1),r=new Date(e.getFullYear(),e.getMonth()+1,0),i=j(n),a=A(j(r),7);return{startMs:i.getTime(),endMs:a.getTime()}}function N(e,t){if(t===`day`)return e.toLocaleDateString(void 0,{weekday:`long`,year:`numeric`,month:`long`,day:`numeric`});if(t===`week`){let t=j(e),n=A(t,6),r={month:`short`,day:`numeric`};return`${t.toLocaleDateString(void 0,r)} – ${n.toLocaleDateString(void 0,{...r,year:`numeric`})}`}return e.toLocaleDateString(void 0,{month:`long`,year:`numeric`})}function P(e,t,n){return t===`day`?A(e,n):t===`week`?A(e,n*7):new Date(e.getFullYear(),e.getMonth()+n,1)}function F(e,t){if(t===void 0)return e;let n=t.calendars[e.id];return n===void 0?e:{...e,visible:n.visible??e.visible,color:n.color??e.defaultColor}}function I(e){return e.providerAddonId!==void 0&&e.providerAddonId.length>0?e.providerAddonId:e.source===`ha`?`Home Assistant`:e.source}function L(e){if(e.allDay===!0)return C.t(`systemPage.calendars.allDay`);let t=new Date(e.startMs),n=new Date(e.endMs),r={hour:`2-digit`,minute:`2-digit`};return`${t.toLocaleTimeString([],r)} – ${n.toLocaleTimeString([],r)}`}function R(e){let t=l(e),n=new Date(t.startMs),r=new Date(t.endMs),i={weekday:`short`,year:`numeric`,month:`short`,day:`numeric`};if(e.allDay===!0){let e=k(n),t=A(k(r),-1);return H(e,t)?C.t(`systemPage.calendars.dayAllDay`,{date:n.toLocaleDateString(void 0,i)}):C.t(`systemPage.calendars.rangeAllDay`,{from:n.toLocaleDateString(void 0,i),to:t.toLocaleDateString(void 0,i)})}let a={hour:`2-digit`,minute:`2-digit`};return H(n,r)?`${n.toLocaleDateString(void 0,i)} · ${n.toLocaleTimeString([],a)} – ${r.toLocaleTimeString([],a)}`:`${n.toLocaleString(void 0,{...i,...a})} – ${r.toLocaleString(void 0,{...i,...a})}`}function z({label:t,children:n}){return e(`div`,{className:`grid grid-cols-[7rem_minmax(0,1fr)] gap-x-3 gap-y-1 text-sm`,children:[r(`dt`,{className:`text-foreground-subtle`,children:t}),r(`dd`,{className:`min-w-0 break-words text-foreground`,children:n})]})}function B({ev:t,calendarName:n,color:i,onClose:a}){let{t:o}=w();return r(x,{open:!0,onOpenChange:e=>!e&&a(),children:e(b,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`calendars-event-detail`,children:[r(y,{children:e(`div`,{className:`flex min-w-0 items-start gap-2.5`,children:[r(`span`,{className:`mt-1.5 h-3 w-3 shrink-0 rounded-full`,style:{backgroundColor:i},"aria-hidden":!0}),r(h,{className:`min-w-0 break-words`,children:t.title})]})}),r(_,{children:e(`dl`,{className:`space-y-3`,children:[r(z,{label:o(`systemPage.calendars.when`,`When`),children:R(t)}),r(z,{label:o(`systemPage.calendars.calendar`,`Calendar`),children:n}),t.location!==void 0&&t.location.length>0?r(z,{label:o(`systemPage.calendars.location`,`Location`),children:t.location}):null,t.description!==void 0&&t.description.length>0?r(z,{label:o(`systemPage.calendars.description`,`Description`),children:r(`span`,{className:`whitespace-pre-wrap`,children:t.description})}):null]})}),r(p,{children:r(v,{type:`button`,size:`sm`,variant:`secondary`,onClick:a,children:o(`common.close`,`Close`)})})]})})}function V(e,t){return e.filter(e=>u(e,t))}function H(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function U({mode:e,onChange:t}){let{t:n}=w(),i=[{id:`month`,label:n(`systemPage.calendars.month`,`Month`)},{id:`week`,label:n(`systemPage.calendars.week`,`Week`)},{id:`day`,label:n(`systemPage.calendars.day`,`Day`)}];return r(`div`,{className:`inline-flex rounded-lg border border-border bg-surface p-0.5`,role:`group`,"aria-label":n(`systemPage.calendars.calendarView`,`Calendar view`),children:i.map(n=>r(`button`,{type:`button`,className:e===n.id?`rounded-md bg-primary px-2.5 py-1 text-xs font-medium text-primary-foreground`:`rounded-md px-2.5 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground`,"aria-pressed":e===n.id,onClick:()=>t(n.id),"data-testid":`calendars-view-${n.id}`,children:n.label},n.id))})}function W({calendars:t,onToggleVisible:n,onColorChange:i,busy:a}){let{t:o}=w();return e(`aside`,{className:`w-full shrink-0 space-y-2 lg:w-56 xl:w-64`,"data-testid":`calendars-legend`,children:[r(`h2`,{className:`text-xs font-medium text-foreground-subtle`,children:o(`systemPage.calendars.calendars`,`Calendars`)}),r(`ul`,{className:`space-y-1`,children:t.map(t=>e(`li`,{className:`flex items-start gap-2 rounded-md px-1.5 py-1.5 hover:bg-surface`,children:[r(`input`,{type:`checkbox`,className:`mt-1 h-3.5 w-3.5 shrink-0 accent-primary`,checked:t.visible,disabled:a,onChange:e=>n(t.id,e.target.checked),"aria-label":o(`systemPage.calendars.show`,`Show {{name}}`,{name:t.name}),"data-testid":`calendars-visible-${t.id}`}),r(`input`,{type:`color`,className:`mt-0.5 h-6 w-6 shrink-0 cursor-pointer rounded border border-border bg-transparent p-0`,value:t.color,disabled:a,onChange:e=>i(t.id,e.target.value.toUpperCase()),"aria-label":o(`systemPage.calendars.colourFor`,`Colour for {{name}}`,{name:t.name}),"data-testid":`calendars-color-${t.id}`}),e(`div`,{className:`min-w-0 flex-1`,children:[r(`div`,{className:`truncate text-sm font-medium ${t.visible?`text-foreground`:`text-foreground-subtle`}`,children:t.name}),e(`div`,{className:`truncate text-[11px] text-foreground-subtle`,children:[I(t),t.enabled?``:` · ${o(`systemPage.calendars.unavailableAtSource`)}`]})]})]},t.id))})]})}function G({ev:t,color:n,compact:i,onSelect:a}){return r(`button`,{type:`button`,className:i?`block w-full truncate rounded px-1 py-0.5 text-left text-[10px] leading-tight text-white hover:brightness-110`:`block w-full rounded-md px-2 py-1.5 text-left text-xs text-white hover:brightness-110`,style:{backgroundColor:n},title:t.title,onClick:()=>a(t),"data-testid":`calendars-event-${t.id}`,children:i?t.title:e(o,{children:[r(`div`,{className:`font-medium`,children:t.title}),r(`div`,{className:`opacity-90`,children:L(t)})]})})}function K({anchor:t,events:n,colorById:i,today:a,onSelectEvent:o}){let{t:s}=w(),{startMs:c,endMs:l}=M(t,`month`),u=[];for(let e=new Date(c);e.getTime()<l;e=A(e,1))u.push(e);let d=t.getMonth();return e(`div`,{"data-testid":`calendars-month`,children:[r(`div`,{className:`mb-1 grid grid-cols-7 gap-px`,children:O.map(e=>r(`div`,{className:`px-1 py-1 text-center text-[11px] font-medium text-foreground-subtle`,children:e},e))}),r(`div`,{className:`grid grid-cols-7 gap-px overflow-hidden rounded-lg border border-border bg-border`,children:u.map(t=>{let c=k(t).getTime(),l=V(n,c),u=t.getMonth()!==d,f=H(t,a);return e(`div`,{className:`min-h-[5.5rem] bg-background p-1 ${u?`opacity-45`:``}`,children:[r(`div`,{className:f?`mb-1 inline-flex h-5 w-5 items-center justify-center rounded-full bg-primary text-[11px] font-semibold text-primary-foreground`:`mb-1 text-[11px] font-medium text-foreground-subtle`,children:t.getDate()}),e(`div`,{className:`space-y-0.5`,children:[l.slice(0,3).map(e=>r(G,{ev:e,color:i.get(e.calendarId)??`#64748B`,compact:!0,onSelect:o},e.id)),l.length>3?r(`div`,{className:`text-[10px] text-foreground-subtle`,children:s(`common.moreCount`,{count:l.length-3})}):null]})]},c)})})]})}function q({anchor:t,events:n,colorById:i,today:a,onSelectEvent:o}){let s=j(t);return r(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-7 sm:gap-px sm:overflow-hidden sm:rounded-lg sm:border sm:border-border sm:bg-border`,"data-testid":`calendars-week`,children:Array.from({length:7},(e,t)=>A(s,t)).map(t=>{let s=k(t).getTime(),c=V(n,s);return e(`div`,{className:`min-h-[8rem] bg-background p-2 sm:min-h-[12rem]`,children:[r(`div`,{className:H(t,a)?`mb-2 text-xs font-semibold text-primary`:`mb-2 text-xs font-medium text-foreground-subtle`,children:t.toLocaleDateString(void 0,{weekday:`short`,day:`numeric`})}),r(`div`,{className:`space-y-1`,children:c.length===0?r(`p`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):c.map(e=>r(G,{ev:e,color:i.get(e.calendarId)??`#64748B`,onSelect:o},e.id))})]},s)})})}function J({anchor:t,events:n,colorById:i,calName:a,onSelectEvent:o}){let{t:s}=w(),c=V(n,k(t).getTime());return c.length===0?r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-day-empty`,children:s(`systemPage.calendars.noEventsOnThisDay`,`No events on this day.`)}):r(`ul`,{className:`divide-y divide-border rounded-lg border border-border`,"data-testid":`calendars-day`,children:c.map(t=>r(`li`,{children:e(`button`,{type:`button`,className:`flex w-full items-start gap-3 px-3 py-3 text-left hover:bg-surface`,onClick:()=>o(t),"data-testid":`calendars-event-${t.id}`,children:[r(`span`,{className:`mt-1 h-2.5 w-2.5 shrink-0 rounded-full`,style:{backgroundColor:i.get(t.calendarId)??`#64748B`}}),e(`div`,{className:`min-w-0`,children:[r(`div`,{className:`font-medium text-sm text-foreground`,children:t.title}),e(`div`,{className:`text-xs text-foreground-subtle`,children:[L(t),` · `,a.get(t.calendarId)??t.calendarId]}),t.location!==void 0&&t.location.length>0?r(`div`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:t.location}):null]})]})},t.id))})}function Y(){let{t:a}=w(),o=f(),l=S({}),u=m(),[p,h]=i(`month`),[_,v]=i(()=>k(new Date)),[y,b]=i(null),x=t(()=>k(new Date),[]),C=o.isSuccess,O=l.isSuccess&&l.data!==void 0?l.data:void 0,A=t(()=>!C||o.data===void 0?[]:o.data.map(e=>F(e,O)),[C,o.data,O]),j=t(()=>A.filter(e=>e.visible),[A]),I=t(()=>j.map(e=>e.id),[j]),L=t(()=>M(_,p),[_,p]),R=g({startMs:L.startMs,endMs:L.endMs,calendarIds:[...I]},{enabled:C&&I.length>0}),z=R.data??[],V=t(()=>{let e=new Map;for(let t of A)e.set(t.id,t.color);return e},[A]),H=t(()=>{let e=new Map;for(let t of A)e.set(t.id,t.name);return e},[A]),G=n((e,t)=>{u.mutateAsync({calendarId:e,visible:t}).then(()=>l.refetch())},[l,u]),Y=n((e,t)=>{/^#[0-9A-Fa-f]{6}$/.test(t)&&u.mutateAsync({calendarId:e,color:t}).then(()=>l.refetch())},[l,u]),X=n(()=>v(k(new Date)),[]),Z=n(()=>v(e=>P(e,p,-1)),[p]),ee=n(()=>v(e=>P(e,p,1)),[p]),Q=`inline-flex h-8 w-8 items-center justify-center rounded-lg border border-border bg-surface text-foreground hover:bg-primary/5 disabled:opacity-50`,$;return $=o.isPending?r(`p`,{className:`text-sm text-foreground-subtle`,children:a(`systemPage.calendars.loadingCalendars`,`Loading calendars…`)}):o.isError?e(`p`,{className:`text-sm text-destructive`,children:[a(`systemPage.calendars.couldNotListCalendars`,`Could not list calendars:`),` `,o.error.message]}):A.length===0?r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-sources`,children:r(E,{i18nKey:`systemPage.calendars.emptySources`,components:{link:r(T,{to:`/system/integrations?tab=calendars`,className:`text-accent underline-offset-2 hover:underline`})}})}):I.length===0?e(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[r(W,{calendars:A,onToggleVisible:G,onColorChange:Y,busy:u.isPending}),r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-hidden`,children:a(`systemPage.calendars.allCalendarsAreHiddenTurn`,`All calendars are hidden. Turn one on in the legend to see events.`)})]}):e(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[r(W,{calendars:A,onToggleVisible:G,onColorChange:Y,busy:u.isPending}),e(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(U,{mode:p,onChange:h}),e(`div`,{className:`flex items-center gap-1`,children:[r(`button`,{type:`button`,className:Q,onClick:Z,"aria-label":a(`systemPage.calendars.previous`,`Previous`),"data-testid":`calendars-prev`,children:r(s,{className:`h-4 w-4`})}),r(`button`,{type:`button`,className:`inline-flex items-center rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5`,onClick:X,"data-testid":`calendars-today`,children:a(`systemPage.calendars.today`,`Today`)}),r(`button`,{type:`button`,className:Q,onClick:ee,"aria-label":a(`common.next`,`Next`),"data-testid":`calendars-next`,children:r(c,{className:`h-4 w-4`})})]}),r(`span`,{className:`text-sm font-medium text-foreground`,"data-testid":`calendars-period`,children:N(_,p)})]}),R.isPending?r(`p`,{className:`text-sm text-foreground-subtle`,children:a(`systemPage.calendars.loadingEvents`,`Loading events…`)}):R.isError?e(`p`,{className:`text-sm text-destructive`,children:[a(`systemPage.calendars.couldNotListEvents`,`Could not list events:`),` `,R.error.message]}):p===`month`?r(K,{anchor:_,events:z,colorById:V,today:x,onSelectEvent:b}):p===`week`?r(q,{anchor:_,events:z,colorById:V,today:x,onSelectEvent:b}):r(J,{anchor:_,events:z,colorById:V,calName:H,onSelectEvent:b})]})]}),e(D,{icon:d,title:a(`systemPage.calendars.calendars`,`Calendars`),subtitle:a(`systemPage.calendars.calendarsFromConnectedSourcesUsed`,`Calendars from connected sources. Used by Calendar events notification rules.`),children:[$,y===null?null:r(B,{ev:y,calendarName:H.get(y.calendarId)??y.calendarId,color:V.get(y.calendarId)??`#64748B`,onClose:()=>b(null)})]})}export{Y as CalendarsPage,Y as default};
|