@camstack/addon-admin-ui 1.2.647 → 1.2.648
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 +6 -0
- package/dist/assets/{Addons-C1rCMYSj.js → Addons-BRJLrkwT.js} +1 -1
- package/dist/assets/{AdminPage-Cve4EeKX.js → AdminPage-BoBZR6uA.js} +1 -1
- package/dist/assets/{AdminSectionedPage-V0guU8PD.js → AdminSectionedPage-L4C7Phdd.js} +1 -1
- package/dist/assets/{AiProfiles-COv7z6F-.js → AiProfiles-DlucJ2e_.js} +1 -1
- package/dist/assets/{BootstrapSettingsForm-DtS11lHd.js → BootstrapSettingsForm-BYyiguAD.js} +1 -1
- package/dist/assets/{Build-D5T3SI7b.js → Build-C7W-XZrf.js} +1 -1
- package/dist/assets/{Calendars-BhsUg2gV.js → Calendars-mymGxZsU.js} +1 -1
- package/dist/assets/{CameraGrids-CM8Yxxdq.js → CameraGrids-Bj3Z_Pcc.js} +1 -1
- package/dist/assets/{Cluster-BP9fRDMS.js → Cluster-CgMRCsps.js} +1 -1
- package/dist/assets/{CompositionBlockEditor-xQIVx_j0.js → CompositionBlockEditor-COm_6ogX.js} +1 -1
- package/dist/assets/{CompositionEditorPage-DHUcurin.js → CompositionEditorPage-CP_PHsfM.js} +1 -1
- package/dist/assets/{Data-DJbrnaPU.js → Data-BhXREBZ6.js} +1 -1
- package/dist/assets/{DeviceDetail-CaQ51F0f.js → DeviceDetail-Bgqvz6LO.js} +1 -1
- package/dist/assets/{Devices-Cf3ZTJ1J.js → Devices-IeMtX8HI.js} +1 -1
- package/dist/assets/{EmbedDevicePage-B9J6ucMX.js → EmbedDevicePage-DZgb5GB6.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-DP7b5VUK.js → EmbedPlayerPage-DbcUQsaR.js} +1 -1
- package/dist/assets/{History-Dx7eMiJH.js → History-B4cuBJ9s.js} +1 -1
- package/dist/assets/{Identity-D3MJ59NJ.js → Identity-DiMZm2ME.js} +1 -1
- package/dist/assets/{InstancesTable-bYSuSJuI.js → InstancesTable-pH3oYjHd.js} +1 -1
- package/dist/assets/{IntegrationDetail-c2pjtV64.js → IntegrationDetail-ClV3Saht.js} +1 -1
- package/dist/assets/{IntegrationWizard-DpekcaJ2.js → IntegrationWizard-DXKqbhGb.js} +1 -1
- package/dist/assets/{Integrations-B4MvBXRJ.js → Integrations-ChAwiavW.js} +1 -1
- package/dist/assets/{Integrations-Ci8Mqya9.js → Integrations-ChpwR1bq.js} +1 -1
- package/dist/assets/{Library-D0tz7PS_.js → Library-B-Y18dDd.js} +1 -1
- package/dist/assets/{Locations-BFeQBE-F.js → Locations-rKV353P0.js} +1 -1
- package/dist/assets/{Logs-DtjMaCC4.js → Logs-Bf7lB4Fl.js} +1 -1
- package/dist/assets/{MyAccess-B83bBSQi.js → MyAccess-DvyNpsOp.js} +1 -1
- package/dist/assets/{Network-BF1ofy4e.js → Network-CMZXMxES.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-BhNHsNDz.js → NodeAddonsSettingsPanel-Cqw9BMNg.js} +1 -1
- package/dist/assets/{Notifications-BDmKjk8l.js → Notifications-tmDmEumh.js} +1 -1
- package/dist/assets/{Pipeline-3BkMMjQC.js → Pipeline-CVkKmqvo.js} +1 -1
- package/dist/assets/{Recordings-CdbZm7N3.js → Recordings-C_LVPbT_.js} +1 -1
- package/dist/assets/{RemoteGrid-D9lQtkK4.js → RemoteGrid-rdbpCVSQ.js} +1 -1
- package/dist/assets/{ScanSubnetEditor-D1wWQv5l.js → ScanSubnetEditor-C7lmoWdP.js} +1 -1
- package/dist/assets/{SessionsList-AtYEgm7p.js → SessionsList-tD4A7E3T.js} +1 -1
- package/dist/assets/{Showroom-BCX4Yyt6.js → Showroom-DJYzUxEc.js} +1 -1
- package/dist/assets/{StorageLocationsTable-CInEvHND.js → StorageLocationsTable-FczbEPcL.js} +1 -1
- package/dist/assets/{System-DvinM4KN.js → System-BFzxJ3an.js} +1 -1
- package/dist/assets/{Templates-AolwZ6TI.js → Templates-CMOSFF23.js} +1 -1
- package/dist/assets/{Terminal-DoBiePC-.js → Terminal-COBZmFpS.js} +1 -1
- package/dist/assets/{TrainingProviders-BKZ0teUD.js → TrainingProviders-B91sOQOt.js} +1 -1
- package/dist/assets/{Viewer-q6dKXR67.js → Viewer-vnvh2eNL.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-M59fwoAQ.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-GkPyO1aX.js} +1 -1
- package/dist/assets/{assignment-candidates-C5pHZht5.js → assignment-candidates-ywq2QZGE.js} +1 -1
- package/dist/assets/{authed-media-Q5YVSoIj.js → authed-media-BpBHZnVV.js} +1 -1
- package/dist/assets/{create-composition-k03FONcQ.js → create-composition-CuDTI4oW.js} +1 -1
- package/dist/assets/{device-detail-okAAAxvr.js → device-detail-QogRNcnP.js} +1 -1
- package/dist/assets/{device-integration-icon-CzQF4KNa.js → device-integration-icon-Du0OOWVL.js} +1 -1
- package/dist/assets/device-picker-model-DQQApnAQ.js +1 -0
- package/dist/assets/{hostInit-JJE2ncUY.js → hostInit-R6aRLO6f.js} +1 -1
- package/dist/assets/{index-DKKQtgP2.js → index-BK_1kQTJ.js} +3 -3
- package/dist/assets/{linked-devices-model-XNuspKgG.js → linked-devices-model-l7VwE3qS.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-0cbecd57.js → mf-entry-bootstrap-0-f5c7db8d.js} +2 -2
- package/dist/assets/mount-DQQApnAQ.js +1 -0
- package/dist/assets/remoteEntry-CRdIUxja.js +1 -0
- package/dist/assets/{src-CvlhNDJc.js → src-5h33Ujaz.js} +1 -1
- package/dist/assets/{step-inspector-model-B1WjzUY-.js → step-inspector-model-CRzHv57F.js} +1 -1
- package/dist/assets/{use-scenes-feed-Dx37Wfqx.js → use-scenes-feed-0tdRPh1u.js} +1 -1
- package/dist/assets/{use-stationary-objects-CVyIgKy4.js → use-stationary-objects-B-7xI3IZ.js} +1 -1
- package/dist/assets/{useAdminDeviceRemoval-Dfw_WOjy.js → useAdminDeviceRemoval-DyJlz4Qu.js} +1 -1
- package/dist/assets/useEventInvalidation-DQQApnAQ.js +1 -0
- package/dist/assets/{useNodeUrlSelection-C7M0t1Bu.js → useNodeUrlSelection-Cd7C-Q8s.js} +1 -1
- package/dist/assets/{useTemplateSave-BXH2v4XY.js → useTemplateSave-DjD9dD7s.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BZIvKvKs.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-qyH7YtIe.js} +2 -2
- package/dist/index.html +4 -4
- package/dist/server/addon.js +1 -1
- package/package.json +2 -2
- package/dist/assets/device-picker-model-DkSaYUyU.js +0 -1
- package/dist/assets/mount-DkSaYUyU.js +0 -1
- package/dist/assets/remoteEntry-DhUUWtf1.js +0 -1
- package/dist/assets/useEventInvalidation-DkSaYUyU.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
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,k as d,o as f,t as p,x as m,z as h}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$n as g,Ar as _,Br as v,Ca as y,Gr as b,Hi as x,Ia as S,Kt as C,Nn as w,Or as T,Pi as E,Qn as D,Xi as O,Yt as k,_a as A,ct as j,gt as M,ir as N,ka as P,ut as F,wt as I,zn as L}from"./player-overlays-DpoShe47.js";import{Ao as R,Bo as z,Co as B,Do as V,Eo as ee,Fa as H,Fo as te,Go as ne,Gt as re,Io as ie,Ji as U,Lo as ae,Mo as oe,No as se,Oo as ce,Po as le,Pr as ue,So as de,To as fe,Ua as pe,Uo as me,Va as he,Vo as ge,Xi as _e,Xs as ve,Zi as ye,_o as be,bo as xe,co as Se,da as Ce,go as we,ho as Te,io as Ee,jo as De,ko as Oe,lo as ke,mo as Ae,oa as je,oo as Me,po as Ne,ps as Pe,ro as Fe,so as Ie,uc as Le,uo as Re,vo as ze,wo as Be,xo as Ve,yo as He,za as Ue,zo as We}from"./client-Dzzkm60X.js";import{t as Ge}from"./chevron-down-CBb-F8DT.js";import{t as Ke}from"./boxes-k5PsZ3NR.js";import{c as qe}from"./video-BV-3O_ZC.js";import{n as Je,r as Ye,t as Xe}from"./variable-Cy0obf0C.js";import{$d as W,$r as Ze,Af as Qe,Ai as $e,Au as et,Bd as tt,Bt as nt,Cs as rt,Fi as it,Fu as at,Ga as ot,Gr as st,H as ct,Hn as lt,Hr as ut,Ii as dt,Io as ft,Jr as pt,Ka as mt,Kr as ht,Ln as gt,Mi as _t,Mo as vt,Mu as yt,Nu as bt,Ou as xt,Pi as St,Pt as Ct,Pu as wt,Q as Tt,Qa as Et,Ri as Dt,S as Ot,Sn as kt,Ud as G,Un as At,Uo as jt,Vd as K,Vn as Mt,Wd as Nt,Wn as Pt,Wr as Ft,Xa as It,Xr as Lt,Z as Rt,Zr as zt,_ as Bt,_n as Vt,ar as Ht,as as Ut,b as Wt,cr as Gt,eo as Kt,fi as qt,h as Jt,hr as Yt,ii as Xt,ji as Zt,ju as Qt,ku as $t,ld as en,li as tn,mf as nn,nf as rn,no as an,or as on,pf as sn,pr as cn,ps as ln,qa as un,qr as dn,rt as fn,sf as q,sr as pn,to as mn,tu as hn,w as gn,wn as _n,zt as vn}from"./src-
|
|
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,k as d,o as f,t as p,x as m,z as h}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$n as g,Ar as _,Br as v,Ca as y,Gr as b,Hi as x,Ia as S,Kt as C,Nn as w,Or as T,Pi as E,Qn as D,Xi as O,Yt as k,_a as A,ct as j,gt as M,ir as N,ka as P,ut as F,wt as I,zn as L}from"./player-overlays-DpoShe47.js";import{Ao as R,Bo as z,Co as B,Do as V,Eo as ee,Fa as H,Fo as te,Go as ne,Gt as re,Io as ie,Ji as U,Lo as ae,Mo as oe,No as se,Oo as ce,Po as le,Pr as ue,So as de,To as fe,Ua as pe,Uo as me,Va as he,Vo as ge,Xi as _e,Xs as ve,Zi as ye,_o as be,bo as xe,co as Se,da as Ce,go as we,ho as Te,io as Ee,jo as De,ko as Oe,lo as ke,mo as Ae,oa as je,oo as Me,po as Ne,ps as Pe,ro as Fe,so as Ie,uc as Le,uo as Re,vo as ze,wo as Be,xo as Ve,yo as He,za as Ue,zo as We}from"./client-Dzzkm60X.js";import{t as Ge}from"./chevron-down-CBb-F8DT.js";import{t as Ke}from"./boxes-k5PsZ3NR.js";import{c as qe}from"./video-BV-3O_ZC.js";import{n as Je,r as Ye,t as Xe}from"./variable-Cy0obf0C.js";import{$d as W,$r as Ze,Af as Qe,Ai as $e,Au as et,Bd as tt,Bt as nt,Cs as rt,Fi as it,Fu as at,Ga as ot,Gr as st,H as ct,Hn as lt,Hr as ut,Ii as dt,Io as ft,Jr as pt,Ka as mt,Kr as ht,Ln as gt,Mi as _t,Mo as vt,Mu as yt,Nu as bt,Ou as xt,Pi as St,Pt as Ct,Pu as wt,Q as Tt,Qa as Et,Ri as Dt,S as Ot,Sn as kt,Ud as G,Un as At,Uo as jt,Vd as K,Vn as Mt,Wd as Nt,Wn as Pt,Wr as Ft,Xa as It,Xr as Lt,Z as Rt,Zr as zt,_ as Bt,_n as Vt,ar as Ht,as as Ut,b as Wt,cr as Gt,eo as Kt,fi as qt,h as Jt,hr as Yt,ii as Xt,ji as Zt,ju as Qt,ku as $t,ld as en,li as tn,mf as nn,nf as rn,no as an,or as on,pf as sn,pr as cn,ps as ln,qa as un,qr as dn,rt as fn,sf as q,sr as pn,to as mn,tu as hn,w as gn,wn as _n,zt as vn}from"./src-5h33Ujaz.js";import{t as J}from"./i18n-DWUEvjgE.js";import{t as Y}from"./useTranslation-BJr-n0es.js";import{H as yn,Kr as bn,Qr as xn,Xr as Sn,ct as Cn,dt as wn,m as Tn,p as En,qr as Dn,x as On}from"./index-BK_1kQTJ.js";import{t as kn}from"./AdminSectionedPage-L4C7Phdd.js";import{n as An}from"./format-BoPK6WDS.js";import{C as jn,Tt as Mn,a as Nn,at as Pn,b as Fn,g as In,i as Ln,lt as Rn,n as zn,nt as Bn,o as Vn,r as Hn,w as Un,y as Wn}from"./CompositionBlockEditor-COm_6ogX.js";import{a as Gn,c as X,i as Kn,l as qn,n as Jn,o as Yn,r as Xn,s as Zn,t as Qn,u as $n}from"./create-composition-CuDTI4oW.js";import{a as er,i as tr,n as nr,o as rr,r as ir,s as ar}from"./action-draft-DB5j6cca.js";var or=`const AUTOMATION_RECIPE =`,sr=`// EJECTED from the visual automation editor — this file is now hand-owned.
|
|
2
2
|
// The recipe that produced it was removed with it, on purpose: while it was
|
|
3
3
|
// here the editor could re-open this block and overwrite everything below.`;function cr(e){return e.includes(or)}function lr(e){let t=e.indexOf(or);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 ur(e){let t=lr(e);if(t===null)return{ok:!1,reason:J.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:J.t(`helpers.recipeFromCode.badJson`,{detail:t})}}let r=xe.safeParse(n);if(!r.success){let e=r.error.issues[0];return{ok:!1,reason:e===void 0?J.t(`helpers.recipeFromCode.schemaMismatch`):J.t(`helpers.recipeFromCode.schemaMismatchAt`,{path:e.path.join(`.`),message:e.message})}}return{ok:!0,recipe:r.data}}function dr(e){let t=lr(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)}${sr}${e.slice(i)}`}u();var fr=`when`;function pr(e){return e===void 0||e.trim()===``?null:e}function mr(e){let t=e.slice(e.lastIndexOf(`.`)+1),n=Number(t);return Number.isInteger(n)?n:0}function hr(e){return e===`ok`?`pass`:e===`error`||e===`failed-continued`||e===`timed-out`?`fail`:`idle`}function gr(e){return e.steps.map(e=>({index:mr(e.path),tone:hr(e.outcome),message:pr(e.message)}))}function _r(e){let t=e.trigger.outcome===`pass`?`pass`:`fail`,n=pr(e.trigger.reason),r=e.conditions.find(e=>e.path===fr);return t===`fail`||r===void 0?{tone:t,reason:n}:r.outcome===`fail`?{tone:`fail`,reason:pr(r.reason)??n}:{tone:r.outcome===`pass`?`pass`:`idle`,reason:n}}function vr(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:pr(e.verdict?.reason)}}function yr(e){let t=gr(e);return{when:_r(e),thenBlock:vr(e,t),steps:t}}function br(e,t){return e===null?null:e.steps.find(e=>e.index===t)?.tone??`idle`}function xr(e){return e===null?{kind:`unknown`}:{kind:`value`,text:Array.isArray(e)?e.join(`, `):String(e)}}function Sr(e){return{kind:e.kind,tone:hr(e.outcome),message:pr(e.message)}}function Cr(e){if(e===void 0)return null;if(e===`else`)return{kind:`else`};let t=Number(e.slice(e.lastIndexOf(`.`)+1));return Number.isInteger(t)?{kind:`branch`,index:t}:null}function wr(e,t){return t===void 0?null:e===void 0?t:`${e}.${t}`}function Tr(e){return{vars:Object.entries(e.trigger.vars).map(([e,t])=>({name:e,value:xr(t)})),conditions:e.conditions.map(e=>({path:e.path,depth:e.path.split(`.`).length-1,kind:e.kind,outcome:e.outcome,reason:pr(e.reason),subject:wr(e.cap,e.fieldPath),operator:e.operator??null,deviceId:e.deviceId??null,expected:e.expected===void 0?null:xr(e.expected),observed:e.observed===void 0?null:xr(e.observed),rawExpected:e.expected,rawObserved:e.observed})),steps:e.steps.map(e=>({index:mr(e.path),kind:e.kind,tone:hr(e.outcome),message:pr(e.message),args:Object.entries(e.args??{}).map(([e,t])=>({name:e,value:xr(t)})),devices:(e.devices??[]).map(e=>({deviceId:e.deviceId,tone:e.outcome===`ok`?`pass`:`fail`,message:pr(e.message)})),chose:Cr(e.branch),nested:(e.steps??[]).map(e=>({...Sr(e),chose:Cr(e.branch),rounds:e.iterations??null,inner:(e.steps??[]).map(Sr)})),rounds:e.iterations??null}))}}function Er(e){let t=Tr(e);return{nodes:new Map(t.conditions.map(e=>[e.path,e])),triggerPath:e.trigger.path??null,vars:t.vars}}var Dr=6;function Or(e,t,n){if(typeof e!=`number`||t===void 0||n===void 0)return xr(e);let r=ne(e,t,n);return r===void 0?xr(e):{kind:`value`,text:`${String(Number(r.toPrecision(Dr)))} ${n}`}}function kr(e){let t=e.steps.find(e=>e.outcome===`error`),n=t===void 0?pr(e.verdict?.reason)??pr(e.trigger.reason):pr(t.message);return{stepsRun:e.steps.filter(e=>e.outcome===`ok`).length,stepsTotal:e.steps.length,reason:n}}var Ar={ran:`success`,failed:`danger`,aborted:`danger`,"skipped-trigger":`neutral`,"skipped-conditions":`warning`,"skipped-cooldown":`neutral`,"skipped-overlap":`neutral`},jr={pass:`border-success/50 bg-success/10`,fail:`border-danger/50 bg-danger/10`,idle:`border-border bg-surface text-foreground-subtle`},Mr={pass:`text-success`,fail:`text-danger`,idle:`text-foreground-subtle`};function Nr(){let{t:e}=Y();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`)}}}var Pr={done:`success`,missed:`warning`,inactive:`neutral`,"condition-false":`neutral`,failed:`danger`,held:`success`,"gave-up":`danger`,overridden:`info`,"suspended-manual":`warning`};function Fr(){let{t:e}=Y();return t=>{switch(t){case`done`:return e(`flow.runs.schedulerDone`,`Done`);case`missed`:return e(`flow.runs.schedulerMissed`,`Missed`);case`inactive`:return e(`flow.runs.schedulerInactive`,`Not active`);case`condition-false`:return e(`flow.runs.schedulerConditionFalse`,`Condition not met`);case`failed`:return e(`flow.runs.schedulerFailed`,`Failed`);case`held`:return e(`flow.runs.schedulerHeld`,`Held`);case`gave-up`:return e(`flow.runs.schedulerGaveUp`,`Gave up`);case`overridden`:return e(`flow.runs.schedulerOverridden`,`Changed by hand`);default:return e(`flow.runs.schedulerSuspendedManual`,`Paused by hand`)}}}var Ir=`max-h-64`;function Lr(){let e=nn(),t=sn();return e||t}function Rr({expanded:t,onToggle:n}){let{t:r}=Y();return e(W,{variant:`unstyled`,type:`button`,"aria-expanded":t,"data-testid":`runs-toggle`,onClick:n,className:`flex w-full items-center gap-2 px-3 py-2 text-left text-xs text-foreground-muted hover:bg-surface-hover`,children:[o(rn,{expanded:t}),o(`span`,{children:t?r(`flow.runs.hide`,`Hide runs`):r(`flow.runs.show`,`Show runs`)})]})}function zr({run:t}){let{t:n}=Y(),r=Nr(),i=kr(t);return e(`p`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 border-t border-border-subtle bg-primary/5 px-3 py-2 text-xs`,"data-testid":`run-summary`,children:[o(G,{variant:Ar[t.outcome],children:r(t.outcome)}),i.reason!==null&&o(`span`,{className:`min-w-0 break-words text-foreground`,children:i.reason}),i.stepsTotal>0&&o(`span`,{className:`text-foreground-subtle`,children:n(`flow.runs.stepsRan`,`{{run}} of {{total}} steps ran`,{run:i.stepsRun,total:i.stepsTotal})})]})}function Br({traces:t,selectedId:n,onSelect:r}){let{t:i}=Y(),a=Nr(),s=Fr(),l=Lr(),[u,d]=c(null),f=u??!l,p=t===void 0?[]:t.toReversed(),h=p.find(e=>e.runId===n)??null;return e(Mt,{headingId:`runs-heading`,title:i(`flow.runs.title`,`Runs`),icon:v,children:[o(Rr,{expanded:f,onToggle:()=>d(!f)}),f?t===void 0?o(Nt,{className:`m-3 h-16`}):p.length===0?o(Xt,{title:i(`flow.runs.emptyTitle`,`No runs yet`),description:i(`flow.runs.emptyDescription`,`Each run appears here with what it decided.`)}):e(m,{children:[o(`ul`,{className:`${Ir} divide-y divide-border-subtle overflow-y-auto`,"data-testid":`runs-panel`,children:p.map(t=>{let i=t.runId===n;return o(`li`,{children:e(W,{variant:`unstyled`,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:[t.scheduler===void 0?o(G,{variant:Ar[t.outcome],children:a(t.outcome)}):o(G,{variant:Pr[t.scheduler],children:s(t.scheduler)}),t.repeat>1&&o(G,{variant:`neutral`,style:`outline`,children:`x${String(t.repeat)}`}),o(`span`,{className:`text-xs text-foreground-subtle`,children:An(t.lastAt)})]}),o(`span`,{className:`truncate text-sm text-foreground`,children:t.trigger.reason})]})},t.runId)})}),h!==null&&o(zr,{run:h}),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.`)})]}):h!==null&&o(zr,{run:h})]})}function Vr(e){return jr[e]}var Hr={pass:`border-success/50`,fail:`border-danger/50`,idle:`border-border`};function Ur(e){return Hr[e]}function Wr({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`:jr[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 ${Mr[i.tone]}`,children:i.reason}),o(`div`,{className:`space-y-2`,children:a})]})}var Gr=[`count`,`while`,`until`,`forEach`],Kr=2,qr=10,Jr={kind:`all`,children:[]};function Yr(e){return e===`count`||e===`while`||e===`until`||e===`forEach`}function Xr(e,t){return Number.isFinite(e)?Math.min(t,Math.max(1,Math.round(e))):1}function Zr(e){return Xr(e,20)}function Qr(e){return Xr(e,50)}function $r(e){switch(e){case`count`:return{by:e,count:Kr};case`while`:case`until`:return{by:e,when:Jr,maxIterations:qr};case`forEach`:return{by:e,target:{kind:`devices`,ids:[]}}}}function ei(e,t){if(e.by!==`while`&&e.by!==`until`)return e;let{waitS:n,...r}=e;return t===null?r:{...r,waitS:Xr(t,de)}}function ti(){return{kind:`repeat`,loop:$r(`count`),steps:[]}}var ni=[`s`,`min`,`h`],ri={s:1,min:60,h:3600};function ii(e){return e===`s`||e===`min`||e===`h`}function ai(e){return e%ri.h===0?{value:e/ri.h,unit:`h`}:e%ri.min===0?{value:e/ri.min,unit:`min`}:{value:e,unit:`s`}}function oi(e,t){let n=Math.round(e*ri[t]);return Number.isFinite(n)?Math.min(Math.max(n,1),B):1}function si(){return{kind:`wait-until`,when:{kind:`all`,children:[]},timeoutS:600,onTimeout:`continue`}}var ci=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function li(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 ci}}function ui(e){switch(e){case`eq`:return J.t(`helpers.recipeParts.op_eq`);case`ne`:return J.t(`helpers.recipeParts.op_ne`);case`gt`:return J.t(`helpers.recipeParts.op_gt`);case`gte`:return J.t(`helpers.recipeParts.op_gte`);case`lt`:return J.t(`helpers.recipeParts.op_lt`);case`lte`:return J.t(`helpers.recipeParts.op_lte`);case`contains`:return J.t(`helpers.recipeParts.op_contains`);default:return J.t(`helpers.recipeParts.op_in`)}}function di(e){return li(e).map(e=>({value:e,label:ui(e)}))}Fe.filter(e=>Ee(e).role===`event`),Fe.filter(e=>Ee(e).role===`state`);function fi(e){return J.t(`${Ee(e).i18nKey}.label`)}function pi(e){return J.t(`${Ee(e).i18nKey}.description`)}function mi(e){return J.t(`${Ee(e).i18nKey}.example`)}var hi={when:{kind:`all`,children:[]},actions:[]};function gi(e){return Me(e)}function _i(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
4
|
`};case`action`:return{kind:e,actionId:``};case`stop`:return{kind:e,reason:``,outcome:`ok`};case`set`:return{kind:e,vars:{}};case`wait-until`:return si();case`parallel`:return{kind:e,steps:[]};case`repeat`:return ti();case`choose`:return{kind:e,branches:[{if:{kind:`all`,children:[]},steps:[]}]};default:return{kind:`cap`,deviceId:0,cap:``,method:``}}}function Z(e,t,n){return e.map((e,r)=>r===t?n:e)}function vi(e,t){return e.filter((e,n)=>n!==t)}function yi(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=vi(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function bi(e,t){return{...e,actions:[...t]}}var xi={pass:`success`,fail:`danger`,"not-evaluated":`neutral`},Si={pass:`success`,fail:`danger`,idle:`neutral`};function Ci({value:e}){let{t}=Y();return e.kind===`unknown`?o(`span`,{className:`italic text-foreground-subtle`,"data-testid":`trace-value-unknown`,children:t(`flow.runs.unknownValue`,`unknown`)}):o(`span`,{className:`font-mono text-foreground`,children:e.text})}function wi(){let{t:e}=Y();return t=>t===`pass`?e(`flow.runs.nodePass`,`Passed`):t===`fail`?e(`flow.runs.nodeFail`,`Failed`):e(`flow.runs.nodeNotEvaluated`,`Not evaluated`)}function Ti(e){let t=ee.safeParse(e);return t.success?ui(t.data):e}function Ei({items:t,testId:n}){return t.length===0?null:o(`dl`,{className:`grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-0.5 text-[11px]`,"data-testid":n,children:t.map(t=>e(`div`,{className:`contents`,children:[o(`dt`,{className:`text-foreground-subtle`,children:t.name}),o(`dd`,{className:`break-words`,children:o(Ci,{value:t.value})})]},t.name))})}function Di({node:t,vars:n=[],expected:r,observed:i}){let{t:a}=Y(),s=wi(),c=t.subject===null?null:`${t.subject}${t.operator===null?``:` ${Ti(t.operator)}`}`;return e(`div`,{className:`space-y-1 border-t border-border-subtle pt-2 text-xs`,"data-testid":`trace-result`,"data-outcome":t.outcome,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(G,{variant:xi[t.outcome],children:s(t.outcome)}),t.reason!==null&&o(`span`,{className:`min-w-0 break-words text-foreground`,children:t.reason})]}),c!==null&&o(`div`,{className:`text-[11px] text-foreground-subtle`,children:c}),(r!==null||i!==null)&&e(`div`,{className:`flex flex-wrap gap-x-3 text-[11px] text-foreground-subtle`,children:[r!==null&&e(`span`,{"data-testid":`trace-expected`,children:[a(`flow.runs.expected`,`Expected`),` `,o(Ci,{value:r})]}),i!==null&&e(`span`,{"data-testid":`trace-observed`,children:[a(`flow.runs.observed`,`Observed`),` `,o(Ci,{value:i})]})]}),o(Ei,{testId:`trace-vars`,items:n})]})}function Oi({step:t,deviceName:n}){let{t:r}=Y(),i=t.tone===`pass`?r(`flow.runs.stepOk`,`OK`):t.tone===`fail`?r(`flow.runs.stepError`,`Error`):r(`flow.runs.stepNotRun`,`Not run`);return e(`div`,{className:`space-y-1 border-t border-border-subtle pt-2 text-xs`,"data-testid":`step-result`,"data-tone":t.tone,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(G,{variant:Si[t.tone],children:i}),t.message!==null&&o(`span`,{className:`min-w-0 break-words text-foreground`,children:t.message})]}),t.chose!==null&&o(`div`,{className:`text-foreground-subtle`,"data-testid":`step-chose`,children:t.chose.kind===`else`?r(`flow.runs.choseElse`,`Ran the "otherwise" list`):r(`flow.runs.choseBranch`,`Ran branch {{n}}`,{n:t.chose.index+1})}),t.rounds!==null&&t.nested.length>0&&o(`div`,{className:`text-foreground-subtle`,"data-testid":`step-last-round`,children:r(`flow.runs.lastRound`,`The last of {{n}} rounds:`,{n:t.rounds})}),t.nested.length>0&&o(`ol`,{className:`space-y-0.5 text-[11px]`,"data-testid":`step-nested`,children:t.nested.map((t,n)=>e(`li`,{className:`space-y-0.5`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(G,{variant:Si[t.tone],children:[String(n+1),` · `,t.kind]}),t.message!==null&&o(`span`,{className:`min-w-0 break-words text-foreground-subtle`,children:t.message}),t.chose!==null&&o(`span`,{className:`text-foreground-subtle`,"data-testid":`nested-chose-${String(n)}`,children:t.chose.kind===`else`?r(`flow.runs.choseElse`,`Ran the "otherwise" list`):r(`flow.runs.choseBranch`,`Ran branch {{n}}`,{n:t.chose.index+1})}),t.rounds!==null&&t.inner.length>0&&o(`span`,{className:`text-foreground-subtle`,"data-testid":`nested-rounds-${String(n)}`,children:r(`flow.runs.lastRound`,`The last of {{n}} rounds:`,{n:t.rounds})})]}),t.inner.length>0&&o(`ol`,{className:`space-y-0.5 border-l border-border-subtle pl-2`,"data-testid":`nested-inner-${String(n)}`,children:t.inner.map((t,n)=>e(`li`,{className:`flex flex-wrap items-center gap-2`,children:[e(G,{variant:Si[t.tone],children:[String(n+1),` · `,t.kind]}),t.message!==null&&o(`span`,{className:`min-w-0 break-words text-foreground-subtle`,children:t.message})]},String(n)))})]},String(n)))}),o(Ei,{testId:`step-args`,items:t.args}),t.devices.length>0&&o(`ul`,{className:`space-y-0.5 text-[11px]`,"data-testid":`step-devices`,children:t.devices.map(t=>e(`li`,{className:`flex flex-wrap items-center gap-2`,children:[o(G,{variant:Si[t.tone],children:n(t.deviceId)}),t.message!==null&&o(`span`,{className:`min-w-0 break-words text-foreground-subtle`,children:t.message})]},t.deviceId))})]})}u();function Q({children:e}){return o(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function ki(e){let t=Gn(e.deviceId);if(t.data!==void 0)return Xn(t.data,e.cap).find(t=>t.path===e.fieldPath)}function Ai({value:t,devices:n,onChange:r}){let{t:i}=Y(),[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(W,{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(Ge,{className:`size-3.5 shrink-0`})]}),a&&o(ji,{value:t,onCancel:()=>s(!1),onConfirm:e=>{s(!1),r(e)}})]})}function ji({value:t,onCancel:n,onConfirm:r}){let{t:i}=Y(),a=ft({projection:`slim`}),[s,l]=c(null),[u,d]=c(!1),[f,p]=c(t.cap===``?null:{cap:t.cap,path:t.fieldPath});!u&&a.status===`success`&&(d(!0),l(Mn(a.data).find(e=>e.id===t.deviceId)??null));let h=i(`automation.fieldPicker.title`,`Device value`);return o(Tt,{open:!0,onClose:n,title:h,width:`xl`,fill:!0,testId:`field-picker-dialog`,footer:e(m,{children:[o(W,{variant:`ghost`,onClick:n,children:i(`common.cancel`,`Cancel`)}),o(W,{disabled:s===null||f===null,"data-testid":`field-picker-confirm`,onClick:()=>{s===null||f===null||r({deviceId:s.id,cap:f.cap,fieldPath:f.path})},children:i(`automation.fieldPicker.use`,`Use this value`)})]}),children:o(Pn,{kind:`formula`,enabled:!0,fillHeight:!0,hostId:-1,destination:{cap:`automation`,targetId:`field`,title:h,pickerTargetKind:null},device:s,field:f,excludeTypes:qn,onDeviceChange:l,onFieldChange:p})})}var Mi=1e4;function Ni(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 Pi(e,t){return{kind:`action`,actionId:e.actionId,...t===void 0?{}:{variables:t}}}function Fi({step:t,onChange:n}){let{t:r}=Y(),i=it({},{refetchInterval:Mi});if(i.data===void 0)return o(Nt,{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(F,{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(Ii,{variable:e,value:t.variables?.[e.name],onChange:r=>n(Pi(t,Ni(t.variables,e.name,r)))},e.name))})]})}function Ii({variable:t,value:n,onChange:r}){let{t:i}=Y(),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(Zn,{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(X,{className:`w-40`,placeholder:s,value:typeof n==`number`?n:void 0,onValue:r})]}):e(`label`,{className:`block`,children:[o(Q,{children:a}),o(q,{className:`w-40`,placeholder:s,value:n===void 0?``:String(n),onChange:e=>r(e.target.value===``?null:e.target.value)})]})}function Li({onMove:e,label:t,reason:n,testId:r,children:i}){let a=e===null?n:t;return o(`span`,{className:`inline-flex`,title:a,"data-testid":`${r}-wrap`,children:o(W,{variant:`ghost`,disabled:e===null,onClick:e??void 0,"aria-label":t,title:a,"data-testid":r,children:i})})}function Ri({move:t,texts:n}){let{t:r}=Y(),i=n??{up:r(`automation.whenTree.moveUp`,`Move up`),down:r(`automation.whenTree.moveDown`,`Move down`),atFirst:r(`automation.whenTree.alreadyFirst`,`Already first in this block`),atLast:r(`automation.whenTree.alreadyLast`,`Already last in this block`)};return e(m,{children:[o(Li,{onMove:t.up,label:i.up,reason:i.atFirst,testId:`move-up`,children:o(A,{className:`h-3.5 w-3.5`})}),o(Li,{onMove:t.down,label:i.down,reason:i.atLast,testId:`move-down`,children:o(y,{className:`h-3.5 w-3.5`})})]})}var zi=[`cap`,`action`,`wait`,`set`,`stop`],Bi=[`cap`,`action`,`wait`];function Vi(e){return Ui(e)&&Bi.includes(e.kind)}var Hi={kind:`all`,children:[]};function Ui(e){return zi.includes(e.kind)?!(`if`in e)&&!(`else`in e):!1}function Wi(){return{if:Hi,steps:[]}}function Gi(e){return e.branches.length<6}function Ki(e){return Gi(e)?{...e,branches:[...e.branches,Wi()]}:e}function qi(e){return e.branches.length>1}function Ji(e,t){return qi(e)?{...e,branches:e.branches.filter((e,n)=>n!==t)}:e}function Yi(e,t,n){return{...e,branches:e.branches.map((e,r)=>r===t?n:e)}}function Xi(e,t){let{else:n,...r}=e;return t===void 0?r:{...r,else:[...t]}}var Zi=[...zi,`wait-until`,`choose`,`parallel`,`repeat`];function Qi(e){return e<2?Zi:zi}function $i(e){if(Ui(e))return!0;switch(e.kind){case`wait-until`:case`parallel`:return!0;case`repeat`:return e.steps.every(Ui);case`choose`:return e.branches.every(e=>e.steps.every(Ui))&&(e.else??[]).every(Ui);default:return!1}}var ea=[`border-chart-series-a`,`border-chart-series-f`,`border-chart-series-b`,`border-chart-series-d`];function ta(e,t){let n=ea.length;return(e+1+t%(n-1))%n}function na(e,t){let n=0;return e.map(e=>De(e)?null:ta(t,n++))}function ra(e){return ea[e%ea.length]??ea[0]}function ia(e){let t=[],n=0;return ce(e,e=>{R(e)&&(n+=1,e.id!==void 0&&t.push({id:e.id,ordinal:n,leaf:e}))}),t}function aa(e){return Oe(e.when)?!0:e.actions.some(e=>Be(e).some(e=>Oe(e.when)))}function oa(e){let t=1;for(;e.has(`t${t}`);)t+=1;return`t${t}`}function sa(e,t){if(De(e)){if(!R(e)||e.id!==void 0)return e;let n=oa(t);return t.add(n),{...e,id:n}}if(e.kind===`not`){let n=sa(e.child,t);return n===e.child?e:{...e,child:n}}let n=e.children.map(e=>sa(e,t));return n.every((t,n)=>t===e.children[n])?e:{...e,children:n}}function ca(e){if(!aa(e))return e;let t=new Set(ia(e.when).map(e=>e.id)),n=sa(e.when,t);return n===e.when?e:{...e,when:n}}function la(e,t,n){let r=e.leafIds.includes(t)?e.leafIds.filter(e=>e!==t):[...e.leafIds,t];return{kind:`triggered-by`,leafIds:n.filter(e=>r.includes(e))}}function ua(e,t){return e.leafIds.filter(e=>!t.includes(e))}u();var da=[],fa=d(null);function pa({when:e,children:t}){let n=r(()=>ia(e),[e]);return o(fa.Provider,{value:n,children:t})}function ma(){return h(fa)??da}function ha(){return h(fa)!==null}var ga=[`triggered-by`];function _a(e){return{label:fi(e),description:pi(e),example:mi(e)}}function va({open:e,onOpenChange:t,mode:n,context:r,underNot:i,treeFull:a,onPick:s}){let{t:c}=Y(),l=ha();return o(Bt,{open:e,onOpenChange:t,title:n===`add`?c(`automation.leafPicker.title`,`Add a row`):c(`automation.leafPicker.changeTitle`,`Change the row type`),context:r,underNot:i,treeFull:a,...l?{}:{hidden:ga},recentKey:`automation-${r}`,textsOf:_a,categoryLabelOf:e=>c(`automation.leafPicker.category.${e}`),reasonOf:e=>c(`automation.leafPicker.reason.${e}`),onPick:e=>{s(e),t(!1)}})}var ya=`none`;function ba(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<=0))return Math.round(t*1e3)}function xa({hold:t,modes:n,onChange:r}){let{t:i}=Y(),a={held:i(`automation.hold.held`,`held`),stable:i(`automation.hold.stable`,`stable`)},s=e=>{if(e===ya){r(void 0);return}let i=n.find(t=>t===e);if(i===void 0)return;let a=t?.ms??3e4;r(i===`stable`&&t?.tolerance!==void 0?{ms:a,mode:i,tolerance:t.tolerance}:{ms:a,mode:i})};return e(m,{children:[e(`label`,{className:`w-32`,children:[o(Q,{children:i(`automation.hold.label`,`For`)}),o(F,{value:t?.mode??ya,onChange:e=>s(e.target.value),options:[{value:ya,label:i(`automation.hold.none`,`no hold`)},...n.map(e=>({value:e,label:a[e]}))]})]}),t!==void 0&&e(`label`,{className:`w-24`,children:[o(Q,{children:i(`automation.hold.seconds`,`Seconds`)}),o(q,{type:`number`,min:1,value:String(t.ms/1e3),onChange:e=>{let n=ba(e.target.value);r(n===void 0?void 0:{...t,ms:n})}})]}),t?.mode===`stable`&&e(`label`,{className:`w-28`,children:[o(Q,{children:i(`automation.hold.tolerance`,`± tolerance`)}),o(q,{type:`number`,min:0,step:`any`,value:t.tolerance===void 0?``:String(t.tolerance),placeholder:`0`,onChange:e=>{let n=e.target.value.trim(),i=n===``?NaN:Number(n),{tolerance:a,...o}=t;r(Number.isNaN(i)||i<0?o:{...o,tolerance:i})}})]})]})}function Sa({value:t,field:n,deviceId:r,cap:i,onChange:a}){let{t:s}=Y(),c=ka(n,r,i);if(n?.kind===`boolean`)return o(F,{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(F,{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(q,{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(q,{value:String(t),placeholder:s(`common.valueWord`),onChange:e=>a(e.target.value)})}function Ca({value:e,field:t,deviceId:n,cap:r,onChange:i}){let{t:a}=Y(),s=ka(t,n,r);return o(q,{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 wa(e){return typeof e==`object`&&!me(e)}function Ta(e){return me(e)?e.value:wa(e)?e[0]??``:e}function Ea(e){return me(e)?[e.value]:wa(e)?e:typeof e==`boolean`?[]:[e]}function Da(e){let t=e?.quantity;if(!(e?.kind!==`number`||t===void 0)&&!(!ve(t)||t===`none`||t===`device`))return Re(t).length>0?t:void 0}function Oa(e,t){if(!(e===void 0||e===`none`)){if(e!==`device`)return e;if(!(t===void 0||t===`device`||t===`none`))return t}}function ka(e,t,n){let r=nt(),i=t??0,a=e?.kind===`number`&&e.quantity!==void 0,{data:o}=vt({deviceId:i},{enabled:a&&i>0}),s=o?.sourceInfo?.quantity,c=ve(s)?s:void 0,l=Oa(e?.quantity,c);if(l===void 0)return;let u=o?.display;return vn({quantity:l,display:u,capName:n,unitPreferences:r})}function Aa({leaf:t,devices:n,onChange:r}){let{t:i}=Y(),a={deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath},s=ki(a),c=di(s?.kind),l=t.operator===`in`,u=Da(s),d=u===void 0?void 0:ke(u),f=e=>{let{unit:n,...i}=t;r({...i,deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath})},p=e=>{let n=ja(e,c),{unit:i,...a}=t;r({...n===`in`?a:t,operator:n,value:n===`in`?[...Ea(t.value)]:Ta(t.value)})};return e(`div`,{className:`flex flex-wrap items-end gap-2`,children:[o(Ai,{value:a,devices:n,onChange:f}),e(`label`,{className:`min-w-[8rem]`,children:[o(Q,{children:i(`automation.conditionRow.comparison`,`Comparison`)}),o(F,{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(Ca,{value:Ea(t.value),field:s,deviceId:t.deviceId,cap:t.cap,onChange:e=>r({...t,value:[...e]})}):u!==void 0&&d!==void 0?o(Ot,{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=gn(e,d);r({...t,value:n.value,unit:n.unit})}}):o(Sa,{value:Ta(t.value),field:s,deviceId:t.deviceId,cap:t.cap,onChange:e=>r({...t,value:e})})]}),o(xa,{hold:t.for,modes:[`held`,`stable`],onChange:e=>{let{for:n,...i}=t;r(e===void 0?i:{...i,for:e})}})]})}function ja(e,t){return t.find(t=>t.value===e)?.value??`eq`}var Ma=Object.values(Le).sort((e,t)=>e.localeCompare(t));function Na({leaf:t,onChange:n}){let{t:r}=Y();return e(`label`,{className:`min-w-[14rem] flex-1`,children:[o(Q,{children:r(`automation.triggerEditor.cronExpression`,`Cron expression`)}),o(q,{value:t.cron,placeholder:`0 30 23 * * *`,onChange:e=>n({kind:`schedule`,cron:e.target.value})}),o(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:o(bn,{i18nKey:`automation.triggerEditor.cronHint`,components:{code:o(`code`,{})}})})]})}function Pa(){return o(`p`,{className:`text-xs text-foreground-subtle`,children:o(bn,{i18nKey:`automation.triggerEditor.manualHint`,components:{b:o(`strong`,{})}})})}function Fa(e,t){return{kind:`device-becomes`,deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath,...t.becomes===void 0?{}:{becomes:t.becomes},...t.operator===void 0||t.value===void 0?{}:{operator:t.operator,value:t.value},...t.hold===void 0?{}:{for:t.hold},...t.debounceMs===void 0?{}:{debounceMs:t.debounceMs}}}function Ia(e){return e.operator===void 0?e.becomes===void 0?`any`:`becomes`:e.operator}var La=[`any`,`becomes`,`gt`,`gte`,`lt`,`lte`,`between`,`outside`];function Ra(e){return e===`between`||e===`outside`}function za(e){if(e.trim()===``)return;let t=Number(e);return Number.isNaN(t)?void 0:t}function Ba(e){return typeof e==`number`?e:void 0}function Va({leaf:t,devices:n,onChange:r}){let{t:i}=Y(),a={deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath},s=ki(a),c=te(t),l=Ia(t),u=Ba(t.value),d=Array.isArray(t.value)?[t.value[0],t.value[1]]:[void 0,void 0],f={...t.becomes===void 0?{}:{becomes:t.becomes},...t.operator===void 0||t.value===void 0?{}:{operator:t.operator,value:t.value},...c===void 0?{}:{hold:c},...t.debounceMs===void 0?{}:{debounceMs:t.debounceMs}},{becomes:p,operator:h,value:g,..._}=f,v=e=>{if(e===`any`){r(Fa(a,_));return}if(e===`becomes`){r(Fa(a,{..._,becomes:``}));return}let t=le.safeParse(e);t.success&&r(Fa(a,{..._,operator:t.data,value:Ra(t.data)?[0,0]:0}))},y={any:i(`automation.triggerEditor.anyChange`,`any change`),becomes:i(`automation.triggerEditor.becomesValue`,`becomes a value`),gt:i(`automation.triggerEditor.crossesAbove`,`rises above`),gte:i(`automation.triggerEditor.reachesAtLeast`,`reaches at least`),lt:i(`automation.triggerEditor.dropsBelow`,`drops below`),lte:i(`automation.triggerEditor.reachesAtMost`,`reaches at most`),between:i(`automation.triggerEditor.entersRange`,`enters the range`),outside:i(`automation.triggerEditor.leavesRange`,`leaves the range`),eq:i(`automation.triggerEditor.becomesValue`,`becomes a value`),ne:i(`automation.triggerEditor.stopsBeing`,`stops being`)};return e(m,{children:[o(Ai,{value:a,devices:n,onChange:e=>r(Fa(e,f))}),e(`label`,{className:`min-w-[10rem]`,children:[o(Q,{children:i(`automation.triggerEditor.becomes`,`Becomes`)}),o(F,{value:l,onChange:e=>v(e.target.value),options:La.map(e=>({value:e,label:y[e]}))})]}),l===`becomes`&&t.becomes!==void 0&&e(`div`,{className:`min-w-[9rem] flex-1`,children:[o(Q,{children:i(`automation.conditionRow.value`,`Value`)}),o(Sa,{value:t.becomes,field:s,deviceId:a.deviceId,cap:a.cap,onChange:e=>r(Fa(a,{...f,becomes:e}))})]}),t.operator!==void 0&&!Ra(l)&&e(`label`,{className:`w-28`,children:[o(Q,{children:i(`automation.conditionRow.value`,`Value`)}),o(q,{type:`number`,step:`any`,value:u===void 0?``:String(u),onChange:e=>{let n=za(e.target.value);n!==void 0&&r(Fa(a,{...f,operator:t.operator,value:n}))}})]}),t.operator!==void 0&&Ra(l)&&[0,1].map(n=>e(`label`,{className:`w-24`,children:[o(Q,{children:n===0?i(`automation.triggerEditor.rangeFrom`,`From`):i(`automation.triggerEditor.rangeTo`,`To`)}),o(q,{type:`number`,step:`any`,value:d[n]===void 0?``:String(d[n]),onChange:e=>{let i=za(e.target.value);if(i===void 0)return;let o=[d[0]??0,d[1]??0];o[n]=i,r(Fa(a,{...f,operator:t.operator,value:o}))}})]},n)),o(xa,{hold:c,modes:[`held`,`stable`],onChange:e=>{let{hold:t,...n}=f;r(Fa(a,e===void 0?n:{...n,hold:e}))}}),e(`label`,{className:`w-28`,children:[o(Q,{children:i(`automation.triggerEditor.debounceS`,`Debounce (s)`)}),o(q,{type:`number`,min:0,value:t.debounceMs===void 0?``:String(t.debounceMs/1e3),placeholder:`0`,onChange:e=>r(Fa(a,{...f,debounceMs:Ha(e.target.value)}))})]})]})}function Ha(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function Ua({leaf:t,onChange:n}){let{t:r}=Y();return e(m,{children:[e(`label`,{className:`min-w-[15rem] flex-1`,children:[o(Q,{children:r(`automation.triggerEditor.eventCategory`,`Event category`)}),o(F,{value:t.category,onChange:e=>n({kind:`device-event`,category:e.target.value,...t.deviceId===void 0?{}:{deviceId:t.deviceId}}),options:[{value:``,label:r(`automation.triggerEditor.selectAnEvent`,`Select an event…`)},...Ma.map(e=>({value:e,label:e}))]})]}),e(`div`,{className:`min-w-[11rem] flex-1`,children:[o(Q,{children:r(`automation.triggerEditor.fromDevice`,`From device`)}),o($e,{pick:`device`,excludeTypes:qn,recentKey:`build-targets`,value:t.deviceId===void 0?null:{deviceId:t.deviceId},placeholder:r(`automation.triggerEditor.anyDevice`,`Any device`),testId:`trigger-event-device`,onChange:e=>n({kind:`device-event`,category:t.category,...e===null?{}:{deviceId:e.deviceId}})})]})]})}function Wa(e,t){let n=e.find(e=>e.id===t.deviceId);return{kind:`global`,sourceStableId:n?.stableId??``,...n?.addonId===void 0?{}:{addonId:n.addonId},cap:t.cap,fieldPath:t.fieldPath}}function Ga(e,t){if(t.addonId!==void 0)return e.find(e=>e.stableId===t.sourceStableId&&e.addonId===t.addonId)?.id??0;let n=e.filter(e=>e.stableId===t.sourceStableId);return n.length===1?n[0]?.id??0:0}var Ka={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function qa({leaf:t,devices:n,onChange:r}){let{t:i}=Y(),a=Object.entries(t.bindings),s=e=>{r({...t,bindings:e})};return e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`block`,children:[o(Jt,{label:i(`automation.expressionLeafRow.expression`,`Expression`),value:t.expr,placeholder:i(`automation.expressionLeafRow.indoorOutdoor5`,`indoor - outdoor > 5`),bindings:Object.keys(t.bindings),onChange:e=>r({...t,expr:e})}),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(Ja,{alias:e,source:r,devices:n,onRename:n=>s(Za(t.bindings,e,n)),onChange:n=>s({...t.bindings,[e]:n}),onRemove:()=>s(Qa(t.bindings,e))},e)),e(W,{variant:`ghost`,onClick:()=>s({...t.bindings,[Xa(t.bindings)]:Ka}),children:[o(D,{className:`h-3.5 w-3.5`}),` `,i(`common.name`)]})]}),o(`div`,{className:`flex flex-wrap items-end gap-2`,children:o(xa,{hold:t.for,modes:[`held`],onChange:e=>{let{for:n,...i}=t;r(e===void 0?i:{...i,for:e})}})})]})}function Ja({alias:t,source:n,devices:r,onRename:i,onChange:a,onRemove:s}){let{t:c}=Y(),l=n.kind===`literal`,u=l?{deviceId:0,cap:``,fieldPath:``}:{deviceId:n.kind===`global`?Ga(r,n):0,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(q,{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(F,{value:l?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:Ka),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(q,{value:n.value===null?``:String(n.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:Ya(e.target.value)})})]}):o(Ai,{value:u,devices:r,onChange:e=>a(Wa(r,e))}),o(W,{variant:`ghost`,onClick:s,title:c(`automation.expressionLeafRow.removeThisName`,`Remove this name`),children:o(k,{className:`h-3.5 w-3.5`})})]})}function Ya(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function Xa(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 Za(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function Qa(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}var $a=`event-emitter`;function eo(e){if(e.status===`pending`)return{kind:`pending`};if(e.status===`error`)return{kind:`unknown`};let t=be.safeParse(e.data);return t.success?{kind:`known`,vocabulary:We(t.data)}:{kind:`unknown`}}function to(e){let t=new Map;for(let n of e)n.source!==void 0&&!t.has(n.source.id)&&t.set(n.source.id,n.source);return[...t.values()]}function no(e,t){let n=new Map;for(let r of e)t!==void 0&&r.source?.id!==t||n.has(r.id)||n.set(r.id,r);return[...n.values()]}function ro(e,t){return{kind:`device-fired`,...e.id===void 0?{}:{id:e.id},deviceId:t}}function io(e,t,n){let{sourceIds:r,eventIds:i,...a}=e,o=new Set(no(n,t).map(e=>e.id)),s=(i??[]).filter(e=>o.has(e));return{...a,...t===void 0?{}:{sourceIds:[t]},...s.length===0?{}:{eventIds:s}}}function ao(e,t){let{eventIds:n,...r}=e;return{...r,...t===void 0?{}:{eventIds:[t]}}}function oo(e,t){let n=new Set(to(t).map(e=>e.id)),r=new Set(t.map(e=>e.id));return{sourceIds:(e.sourceIds??[]).filter(e=>!n.has(e)),eventIds:(e.eventIds??[]).filter(e=>!r.has(e))}}var so=``,co={caps:[$a]};function lo({leaf:t,onChange:n}){let{t:r}=Y(),i=t.deviceId>0,a=ln({deviceId:t.deviceId,capName:$a},{enabled:i}),s=eo({status:a.status,data:a.data}),c=s.kind===`known`?s.vocabulary:[],l=to(c),u=t.sourceIds?.[0],d=t.eventIds?.[0],f=no(c,u),p=s.kind===`known`?oo(t,c):null,h=r(`automation.fired.anyEvent`,`Any event`),g=s.kind===`pending`?r(`automation.fired.loading`,`Reading what this device can fire…`):r(`automation.fired.unknown`,`What this device can fire could not be read.`);return e(m,{children:[e(`div`,{className:`min-w-[13rem] flex-1`,children:[o(Q,{children:r(`automation.fired.device`,`Device`)}),o($e,{pick:`device`,requires:co,recentKey:`automation-device-fired`,value:i?{deviceId:t.deviceId}:null,onChange:e=>n(ro(t,e?.deviceId??0))})]}),i&&s.kind!==`known`&&o(`p`,{className:`min-w-[13rem] flex-1 text-xs ${s.kind===`unknown`?`text-warning`:`text-foreground-subtle`}`,"data-testid":`fired-vocabulary-${s.kind}`,children:g}),i&&s.kind===`known`&&l.length>0&&e(`label`,{className:`min-w-[11rem] flex-1`,children:[o(Q,{children:r(`automation.fired.source`,`From`)}),o(F,{"data-testid":`fired-source`,value:u??so,onChange:e=>n(io(t,e.target.value===so?void 0:e.target.value,c)),options:[{value:so,label:r(`automation.fired.anySource`,`Any button`)},...l.map(e=>({value:e.id,label:e.label})),...(p?.sourceIds??[]).map(e=>({value:e,label:r(`automation.fired.gone`,`{{id}} (no longer declared)`,{id:e})}))]})]}),i&&s.kind===`known`&&e(`label`,{className:`min-w-[11rem] flex-1`,children:[o(Q,{children:r(`automation.fired.event`,`Event`)}),o(F,{"data-testid":`fired-event`,value:d??so,onChange:e=>n(ao(t,e.target.value===so?void 0:e.target.value)),options:[{value:so,label:h},...f.map(e=>({value:e.id,label:e.label})),...(p?.eventIds??[]).map(e=>({value:e,label:r(`automation.fired.gone`,`{{id}} (no longer declared)`,{id:e})}))]})]}),p!==null&&p.sourceIds.length+p.eventIds.length>0&&o(`p`,{className:`basis-full text-xs text-warning`,"data-testid":`fired-stale`,children:r(`automation.fired.staleHint`,`This row names something the device no longer declares, so it will not start a run. Pick again.`)}),(t.kinds!==void 0||t.match!==void 0)&&o(`p`,{className:`basis-full text-xs text-foreground-subtle`,"data-testid":`fired-extra`,children:r(`automation.fired.extraHint`,`This row also carries filters set outside the editor ({{what}}); they are kept as they are.`,{what:[...t.kinds??[],...(t.match??[]).map(e=>`${e.path} = ${String(e.equals)}`)].join(`, `)})})]})}var uo=`text-xs text-foreground-subtle`;function fo({children:e}){return o(`span`,{className:uo,children:e})}function po(e,t){return e.includes(t)?e.filter(e=>e!==t):[...e,t]}function mo({selected:t,onChange:n}){let{t:r}=Y();return e(`div`,{className:`space-y-1`,children:[o(fo,{children:r(`flow.scene.cameras`,`Cameras`)}),o($e,{multiple:!0,pick:`device`,noun:`camera`,fixedTypes:$n,recentKey:`build-cameras`,value:zt(t),testId:`scene-cameras`,onChange:e=>n(Lt(e))})]})}function ho({device:t,deviceId:n,selected:r,onToggle:i}){let a=tt({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:uo,children:t?.name??`#${String(n)}`}),a.data.map(e=>o(W,{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 go({devices:t,deviceIds:n,selected:r,onChange:i}){let{t:a}=Y();if(n.length===0)return null;let s=e=>{let t=po(r,e);i(t.length===0?void 0:t)};return e(`div`,{className:`space-y-1`,children:[o(fo,{children:a(`flow.scene.zones`,`Zones`)}),o(`div`,{className:`space-y-2`,children:n.map(e=>o(ho,{device:t.find(t=>t.id===e),deviceId:e,selected:r,onToggle:s},e))}),o(`p`,{className:uo,children:r.length===0?a(`flow.scene.wholeScene`,`None picked: the whole scene counts.`):a(`flow.scene.zonesPicked`,`Only these zones count.`)})]})}var _o=[`animal`,`person`,`vehicle`,`package`,`other`];function vo(e){return _o.find(t=>t===e)??`other`}function yo(e){switch(e){case`animal`:return{macro:`animal`};case`person`:return{macro:`person`};case`vehicle`:return{macro:`vehicle`};case`package`:return{macro:`package`};default:return{macro:`other`,className:``}}}function bo(){let{t:e}=Y();return t=>{switch(t){case`person`:return e(`flow.class.person`,`Person`);case`vehicle`:return e(`flow.class.vehicle`,`Vehicle`);case`animal`:return e(`flow.class.animal`,`Animal`);case`package`:return e(`flow.class.package`,`Package`);default:return e(`automation.whenTree.macroOther`,`Other class`)}}}function xo(e,t){let n={kind:`sub-class`,className:t};switch(e){case`animal`:return{macro:e,label:n};case`package`:return{macro:e,label:n};case`vehicle`:return{macro:e,label:n};default:return{macro:`person`}}}var So=[`automation`,`class-taxonomy`];function Co(){let e=M();return re(l({queryKey:So,retry:!1,staleTime:1/0,queryFn:()=>e.trpcClient.notificationRules.getConditionCatalog.query({})}).data?.taxonomy)}function wo(e,t,n){let r=n?.groups.find(t=>t.key===e),i=r===void 0?ge(e).filter(t=>t!==e).map(e=>({value:e,label:e})):r.options.filter(t=>t.value!==e).map(e=>({value:e.value,label:e.label}));return t!==void 0&&!i.some(e=>e.value===t)?[...i,{value:t,label:t}]:i}function To({subject:e,onChange:t}){let{t:n}=Y(),r=e.label?.kind===`sub-class`?e.label.className:void 0,i=Co(),a=wo(e.macro,r,i);return a.length===0?null:o(F,{"aria-label":n(`automation.whenTree.labelAria`,`Narrow to`),"data-testid":`subject-label`,value:r??``,options:[{value:``,label:n(`automation.whenTree.anyLabel`,`Any`)},...a],onChange:n=>{let r=n.target.value;t(r===``?yo(e.macro):xo(e.macro,r))}})}function Eo({onChange:e,subject:t}){let{t:n}=Y(),r=rt(),i=t.macro===`person`?t.label:void 0,a=r.data??[],s=a.map(e=>({value:e.id,label:e.name}));return i!==void 0&&!a.some(e=>e.id===i.identityId)&&s.push({value:i.identityId,label:i.name}),o(F,{"aria-label":n(`automation.whenTree.labelAria`,`Narrow to`),"data-testid":`subject-label`,value:i?.identityId??``,options:[{value:``,label:n(`automation.whenTree.anyPerson`,`Anyone`)},...s],onChange:t=>{let n=t.target.value,r=s.find(e=>e.value===n);e(n===``||r===void 0?{macro:`person`}:{macro:`person`,label:{kind:`identity`,identityId:n,name:r.label}})}})}var Do=`plate:`,Oo=`class:`,ko=200;function Ao({onChange:e,subject:t}){let{t:n}=Y(),r=hn({includeCrops:!1,limit:ko}),i=t.macro===`vehicle`?t.label:void 0,a=i?.kind===`plate`?i.text:void 0,s=Co(),c=i?.kind===`sub-class`?i.className:void 0,l=[...new Set((r.data??[]).map(e=>e.text))];a!==void 0&&!l.includes(a)&&l.push(a);let u=a===void 0?c===void 0?``:`${Oo}${c}`:`${Do}${a}`;return o(F,{"aria-label":n(`automation.whenTree.labelAria`,`Narrow to`),"data-testid":`subject-label`,value:u,options:[{value:``,label:n(`automation.whenTree.anyLabel`,`Any`)},...wo(`vehicle`,c,s).map(e=>({value:`${Oo}${e.value}`,label:e.label})),...l.map(e=>({value:`${Do}${e}`,label:n(`automation.whenTree.plateOption`,`Plate {{text}}`,{text:e})}))],onChange:t=>{let n=t.target.value;n.startsWith(Do)?e({macro:`vehicle`,label:{kind:`plate`,text:n.slice(6)}}):n.startsWith(Oo)?e({macro:`vehicle`,label:{kind:`sub-class`,className:n.slice(6)}}):e({macro:`vehicle`})}})}function jo({subject:t,classLabelsOnly:n,verb:r,onChange:i,onRemove:a}){let{t:s}=Y(),c=bo(),l=t.macro===`other`?[]:z[t.macro],u=l.some(e=>e.kind===`cap`&&e.label===`identity`),d=l.some(e=>e.kind===`cap`&&e.label===`plate`);return e(`div`,{className:`flex flex-wrap items-center gap-2`,"data-testid":`subject-row`,children:[o(`div`,{className:`w-36`,children:o(F,{"aria-label":s(`automation.whenTree.macroAria`,`Class`),"data-testid":`subject-macro`,value:t.macro,options:_o.map(e=>({value:e,label:c(e)})),onChange:e=>{let n=vo(e.target.value);n!==t.macro&&i(yo(n))}})}),o(`span`,{className:`text-sm text-foreground-muted`,children:r}),t.macro===`other`?o(q,{className:`w-40`,"aria-label":s(`automation.whenTree.className`,`Class name`),"data-testid":`subject-class-name`,placeholder:s(`automation.whenTree.classNamePlaceholder`,`Class name`),value:t.className,onChange:e=>i({macro:`other`,className:e.target.value})}):u&&!n?o(`div`,{className:`w-44`,children:o(Eo,{subject:t,onChange:i})}):d&&!n?o(`div`,{className:`w-44`,children:o(Ao,{subject:t,onChange:i})}):!u&&o(`div`,{className:`w-44`,children:o(To,{subject:t,onChange:i})}),a!==null&&o(W,{variant:`ghost`,onClick:a,title:s(`automation.whenTree.removeClass`,`Remove this class`),children:o(k,{className:`h-3.5 w-3.5`})})]})}function Mo({subjects:t,optional:n,classLabelsOnly:r,verb:i,onChange:a}){let{t:s}=Y(),c=n||t.length>1;return e(`div`,{className:`space-y-2`,"data-testid":`subject-picker`,children:[t.map((e,n)=>o(jo,{subject:e,classLabelsOnly:r,verb:n===0?i:s(`automation.whenTree.orSubject`,`or`),onChange:e=>a(t.map((t,r)=>r===n?e:t)),onRemove:c?()=>a(t.filter((e,t)=>t!==n)):null},`${e.macro}-${String(n)}`)),t.length===0&&o(`p`,{className:`text-xs text-foreground-subtle`,children:s(`flow.scene.anyClass`,`None picked: any class counts.`)}),e(W,{variant:`ghost`,size:`sm`,onClick:()=>a([...t,yo(`person`)]),children:[o(D,{className:`h-3.5 w-3.5`}),` `,t.length===0?s(`automation.whenTree.onlySomeClasses`,`Only some classes`):s(`automation.whenTree.addClass`,`Add a class`)]})]})}var No=100;function Po({leaf:t,devices:n,onChange:r}){let{t:i}=Y(),a=Math.round((t.minScore??0)*No),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/No})};return e(`div`,{className:`w-full space-y-3`,"data-testid":`detection-fields`,children:[o(Mo,{subjects:t.subjects,optional:!1,classLabelsOnly:!1,verb:i(`automation.whenTree.detected`,`detected`),onChange:e=>r({...t,subjects:[...e]})}),o(mo,{selected:t.deviceIds,onChange:e=>r({...t,deviceIds:[...e]})}),o(go,{devices:n,deviceIds:t.deviceIds,selected:t.zones??[],onChange:s}),e(`div`,{className:`space-y-1`,children:[o(fo,{children:a===0?i(`flow.scene.minScoreAny`,`Minimum score: any`):i(`flow.scene.minScore`,`Minimum score: {{value}}`,{value:(a/No).toFixed(2)})}),o(P,{min:0,max:No,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 Fo({leaf:t,devices:n,onChange:r}){let{t:i}=Y();return e(`div`,{className:`w-full space-y-3`,"data-testid":`stationary-fields`,children:[o(Mo,{subjects:t.subjects??[],optional:!0,classLabelsOnly:!0,verb:i(`automation.whenTree.parked`,`object`),onChange:e=>{let{subjects:n,...i}=t;r(e.length===0?i:{...i,subjects:[...e]})}}),o(mo,{selected:t.deviceIds,onChange:e=>r({...t,deviceIds:[...e]})}),o(go,{devices:n,deviceIds:t.deviceIds,selected:t.zones??[],onChange:e=>{let{zones:n,...i}=t;r(e===void 0?i:{...i,zones:[...e]})}}),o(ct,{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 Io({leaf:t,onChange:n}){let{t:r}=Y();return e(`div`,{className:`flex items-center gap-2`,"data-testid":`interval-fields`,children:[o(fo,{children:r(`flow.scene.every`,`Every`)}),o(X,{"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(fo,{children:r(`flow.scene.minutes`,`minutes`)})]})}function Lo({leaf:t,devices:n,onChange:r}){let{t:i}=Y(),a=e=>{let{subjects:n,...i}=t;r(e.length===0?i:{...i,subjects:[...e]})},s=e=>{let{zones:n,...i}=t;r(e===void 0?i:{...i,zones:[...e]})},c=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(fo,{children:i(`flow.scene.parkedOn`,`An object is parked on`)}),o($e,{pick:`device`,noun:`camera`,fixedTypes:$n,recentKey:`build-cameras`,clearable:!1,value:t.deviceId>0?{deviceId:t.deviceId}:null,testId:`stationary-present-camera`,onChange:e=>{e!==null&&e.deviceId!==t.deviceId&&c(e.deviceId)}})]}),o(Mo,{subjects:t.subjects??[],optional:!0,classLabelsOnly:!0,verb:i(`automation.whenTree.isParked`,`is parked`),onChange:a}),e(`div`,{className:`flex items-center gap-2`,children:[o(fo,{children:i(`flow.scene.minCount`,`At least`)}),o(X,{"aria-label":i(`flow.scene.minCountAria`,`Minimum parked objects`),"data-testid":`stationary-present-min-count`,className:`w-20`,value:t.minCount??1,onValue:e=>{let{minCount:n,...i}=t;r(e===null||e<=1?i:{...i,minCount:Math.floor(e)})}}),o(fo,{children:i(`flow.scene.minCountUnit`,`parked objects`)})]}),o(go,{devices:n,deviceIds:t.deviceId>0?[t.deviceId]:[],selected:t.zones??[],onChange:s})]})}var Ro=[`mon`,`tue`,`wed`,`thu`,`fri`,`sat`,`sun`],zo=720,Bo=1440;function Vo(){return{name:``,enabled:!0,priority:0,maxLateMs:Ne,profiles:[Ho(`profile-1`,`Every day`)]}}function Ho(e,t){return{id:e,name:t,enabled:!0,days:[...Ro],points:[]}}function Uo(e,t,n){return{id:t,at:{kind:`clock`,hh:Math.floor(n/60),mm:n%60},mode:e,steps:[]}}function Wo(e,t){let n=t.length+1;for(;t.includes(`${e}-${String(n)}`);)n+=1;return`${e}-${String(n)}`}function Go(e){return e.location===null?null:{lat:e.location.latitude,lon:e.location.longitude,timeZone:e.timeZone}}function Ko(e,t){let n=new Intl.DateTimeFormat(`en-US`,{timeZone:t,hourCycle:`h23`,hour:`2-digit`,minute:`2-digit`}).formatToParts(new Date(e)),r=e=>Number(n.find(t=>t.type===e)?.value??0);return r(`hour`)*60+r(`minute`)}function qo(e,t=Date.now()){return ie(t,e.timeZone)}function Jo(e,t,n){let r=Go(t);if(r===null)return e.kind===`clock`?e.hh*60+e.mm:null;let i=ae(e,n,r);return i===null?null:Ko(i,t.timeZone)}function Yo(e,t,n){return e.kind===`sun`?Jo({...e,offsetMin:0},t,n):null}function Xo(e,t,n){if(e.kind===`clock`)return{kind:`clock`,hh:Math.floor(t/60),mm:t%60};if(e.kind===`sun`&&n!==null){let r=Math.max(-720,Math.min(zo,t-n));return{...e,offsetMin:r}}return e}function Zo(e){let t=/^([01]\d|2[0-3]):([0-5]\d)$/.exec(e);return t===null?null:{kind:`clock`,hh:Number(t[1]),mm:Number(t[2])}}function Qo(e,t){return`${String(e).padStart(2,`0`)}:${String(t).padStart(2,`0`)}`}function $o(e){return Qo(Math.floor(e/60),e%60)}function es(e,t,n){let r=e.flatMap(e=>{let r=Jo(e.at,t,n);return r===null?[]:[{point:e,minute:r}]}).toSorted((e,t)=>e.minute-t.minute);return r.flatMap((e,t)=>{if(e.point.mode!==`hold`)return[];let n=r[t+1];return[{id:e.point.id,fromMinute:e.minute,toMinute:n===void 0?Bo:n.minute}]})}function ts(e,t){let n=Ae.safeParse(e);if(!n.success)return{ok:!1,issues:n.error.issues.map(e=>({path:e.path.join(`.`),message:e.message}))};let r=Te(n.data,t);return r.ok?{ok:!0,input:n.data}:{ok:!1,issues:r.issues}}var ns=[`mon`,`tue`,`wed`,`thu`,`fri`,`sat`,`sun`],rs=[`sunrise`,`sunset`,`dawn`,`dusk`],is={from:{kind:`clock`,hh:22,mm:0},to:{kind:`clock`,hh:6,mm:0}};function as(e,t){return{kind:`time-is`,...e===void 0?{}:{between:e},...t===void 0?{}:{days:[...t]}}}function os(e){return e.days??ns}function ss(e,t){let n=os(e),r=n.includes(t)?n.filter(e=>e!==t):ns.filter(e=>e===t||n.includes(e)),i=r.length===ns.length;return as(e.between,i&&e.between!==void 0?void 0:r)}function cs(e,t){if(t){let t=e.days!==void 0&&e.days.length===ns.length;return as(e.between??is,t?void 0:e.days)}return as(void 0,os(e))}function ls(e,t,n){return as({...e.between??is,[t]:n},e.days)}function us(e){return e===`sun`?{kind:`sun`,event:`sunset`,offsetMin:0}:{kind:`clock`,hh:12,mm:0}}function ds(e){return e.kind===`date`?us(`clock`):e}function fs(e){let t=e.between;return t===void 0||t.from.kind!==`clock`||t.to.kind!==`clock`?!1:t.to.hh*60+t.to.mm<=t.from.hh*60+t.from.mm}function ps(e,t){if(t===void 0)return null;let n=we(e,t)[0];return n===void 0?null:`${n.path}: ${n.message}`}function ms({label:t,testId:n,end:r,onChange:i}){let{t:a}=Y(),s=e=>`${t}: ${e}`;return e(`div`,{role:`group`,"aria-label":t,"data-testid":n,children:[o(Q,{children:t}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(F,{wrapperClassName:`relative w-40`,"aria-label":t,value:r.kind,options:[{value:`clock`,label:a(`schedulers.point.clock`,`At a time`)},{value:`sun`,label:a(`schedulers.point.sun`,`At a sun event`)}],onChange:e=>{let t=e.target.value;(t===`clock`||t===`sun`)&&t!==r.kind&&i(us(t))}}),r.kind===`clock`&&o(q,{type:`time`,className:`w-28`,"aria-label":s(a(`schedulers.point.time`,`Time`)),value:Qo(r.hh,r.mm),onChange:e=>{let t=Zo(e.target.value);t!==null&&t.kind===`clock`&&i(t)}}),r.kind===`sun`&&e(m,{children:[o(F,{wrapperClassName:`relative w-40`,"aria-label":s(a(`schedulers.point.sunEvent`,`Sun event`)),value:r.event,options:rs.map(e=>({value:e,label:a(`schedulers.sun.${e}`,e)})),onChange:e=>{let t=rs.find(t=>t===e.target.value);t!==void 0&&i({...r,event:t})}}),o(X,{"aria-label":s(a(`schedulers.point.offset`,`Offset (minutes, negative = before)`)),title:a(`schedulers.point.offset`,`Offset (minutes, negative = before)`),className:`w-20`,value:r.offsetMin,onValue:e=>{e!==null&&i({...r,offsetMin:Math.round(e)})}})]})]})]})}function hs({leaf:t,onChange:n}){let{t:r}=Y(),i=t.between,a=os(t);return e(`div`,{className:`flex w-full flex-col gap-2`,"data-testid":`time-is-fields`,children:[e(`div`,{className:`flex flex-wrap items-end gap-x-4 gap-y-2`,children:[e(`label`,{children:[o(Q,{children:r(`automation.timeIs.window`,`Time of day`)}),o(F,{wrapperClassName:`relative w-40`,"aria-label":r(`automation.timeIs.window`,`Time of day`),value:i===void 0?`whole-day`:`between`,options:[{value:`between`,label:r(`automation.timeIs.between`,`Between two times`)},{value:`whole-day`,label:r(`automation.timeIs.wholeDay`,`The whole day`)}],onChange:e=>n(cs(t,e.target.value===`between`))})]}),i!==void 0&&e(m,{children:[o(ms,{label:r(`automation.timeIs.from`,`From`),testId:`time-is-from`,end:ds(i.from),onChange:e=>n(ls(t,`from`,e))}),o(ms,{label:r(`automation.timeIs.to`,`To`),testId:`time-is-to`,end:ds(i.to),onChange:e=>n(ls(t,`to`,e))})]})]}),e(`div`,{children:[o(Q,{children:r(`schedulers.profile.days`,`Days`)}),o(`div`,{className:`flex flex-wrap gap-1`,role:`group`,"aria-label":r(`schedulers.profile.days`,`Days`),children:ns.map(e=>{let i=a.includes(e);return o(W,{size:`sm`,variant:i?`primary`:`outline`,"aria-pressed":i,onClick:()=>n(ss(t,e)),children:r(`schedulers.day.${e}`,e)},e)})}),a.length===0&&o(`p`,{className:`mt-1 text-xs text-warning`,"data-testid":`time-is-no-days`,children:r(`automation.timeIs.noDays`,`Pick at least one day.`)}),fs(t)&&o(`p`,{className:`mt-1 text-xs text-foreground-subtle`,"data-testid":`time-is-wraps`,children:r(`automation.timeIs.wraps`,`This window ends the next day. The days are the days it starts on.`)})]})]})}function gs(e,t){let n=e.leaf;if(n.kind!==`device-becomes`&&n.kind!==`device-event`&&n.kind!==`device-fired`)return;let r=t.find(e=>e.id===n.deviceId)?.name;return n.kind===`device-becomes`?r:n.kind===`device-fired`?[r,[...n.sourceIds??[],...n.eventIds??[]].join(` `)].filter(e=>e!==void 0&&e!==``).join(` · `)||void 0:r===void 0?n.category:`${n.category} · ${r}`}function _s({leaf:t,devices:n,onChange:r}){let{t:i}=Y(),a=ma(),s=a.map(e=>e.id),c=ua(t,s),l=i(`automation.triggeredBy.triggers`,`Started by`);return e(`div`,{children:[o(Q,{children:l}),a.length===0?o(`p`,{className:`text-xs text-warning`,"data-testid":`triggered-by-no-rows`,children:i(`automation.triggeredBy.noRows`,`This automation has no trigger row to choose. Add one to the rules first.`)}):o(`div`,{className:`flex flex-wrap gap-1`,role:`group`,"aria-label":l,children:a.map(e=>{let i=t.leafIds.includes(e.id),a=gs(e,n);return o(W,{size:`sm`,variant:i?`primary`:`outline`,"aria-pressed":i,className:`h-auto min-h-8 whitespace-normal py-1 text-left`,onClick:()=>r(la(t,e.id,s)),children:`${e.ordinal}. ${fi(e.leaf.kind)}${a===void 0?``:` · ${a}`}`},e.id)})}),a.length>0&&t.leafIds.length===0&&o(`p`,{className:`mt-1 text-xs text-warning`,"data-testid":`triggered-by-none-picked`,children:i(`automation.triggeredBy.nonePicked`,`Pick at least one trigger.`)}),c.length>0&&o(`p`,{className:`mt-1 text-xs text-warning`,"data-testid":`triggered-by-missing`,children:i(`automation.triggeredBy.missing`,{count:c.length,defaultValue_one:`{{count}} chosen trigger no longer exists. Press a trigger to drop it.`,defaultValue_other:`{{count}} chosen triggers no longer exist. Press a trigger to drop them.`})})]})}function vs(e){return e.kind===`all`||e.kind===`any`}function ys(e){return[`when`,...e].join(`.`)}function bs(e){let t=e.when;return vs(t)?t:{kind:`all`,children:[t]}}function xs(e,t){return{...e,when:t}}function Ss(e){return xs(e,bs(e))}function Cs(e,t){let[n,...r]=t;if(n===void 0)return e;if(e.kind===`not`)return n===0?Cs(e.child,r):null;if(De(e))return null;let i=e.children[n];return i===void 0?null:Cs(i,r)}function ws(e,t,n){let[r,...i]=t;if(r===void 0)return n(e);if(e.kind===`not`){if(r!==0)return e;let t=ws(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(De(e))return e;let a=e.children[r];if(a===void 0)return e;let o=ws(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 Ts(e,t,n){let r=bs(e);return xs(e,ws(r,t,n)??{kind:r.kind,children:[]})}function Es(e){return{kind:e,children:[gi(`device-is`)]}}function Ds(e,t,n){return Ts(e,t,e=>vs(e)?{kind:e.kind,children:[...e.children,n]}:e)}function Os(e,t,n){return Ts(e,t,()=>n)}function ks(e,t){return Ts(e,t,()=>null)}function As(e,t,n){return Ts(e,t,e=>vs(e)?{kind:n,children:e.children}:e)}function js(e,t){return t.length===0?e:Ts(e,t,e=>({kind:`not`,child:e}))}function Ms(e,t){return Ts(e,t,e=>e.kind===`not`?e.child:e)}function Ns(e,t){if(e.kind===t)return e;if(e.kind===`device-is`&&t===`device-becomes`){let{deviceId:n,cap:r,fieldPath:i,operator:a,value:o}=e,s={kind:t,deviceId:n,cap:r,fieldPath:i};return a===`eq`&&!Array.isArray(o)&&typeof o!=`object`?{...s,becomes:o}:s}if(e.kind===`device-becomes`&&t===`device-is`){let{deviceId:n,cap:r,fieldPath:i,becomes:a}=e;return{kind:t,deviceId:n,cap:r,fieldPath:i,operator:`eq`,value:a??``}}let n=gi(t);return R(e)&&e.id!==void 0&&R(n)?{...n,id:e.id}:n}function Ps(e){let t=bs(e),n=t.children.length===0;return{depth:n?0:se(t),leaves:n?0:V(t),depthLimit:4,leafLimit:32}}function Fs(e,t){let n=bs(e),r=1,i=n;for(let e of t){let t=Cs(i,[e]);if(t===null)break;r+=1,i=t}return r+2<=4}function Is(e,t,n){let r=t[t.length-1];if(r===void 0)return e;let i=t.slice(0,-1),a=Cs(bs(e),i);if(a===null||!vs(a))return e;let o=r+n;return o<0||o>=a.children.length?e:Ts(e,i,()=>({kind:a.kind,children:yi(a.children,r,o)}))}function Ls(e,t,n){let r=ys(t),i=ys(n),a=e=>e===r||e.startsWith(`${r}.`)?i+e.slice(r.length):e===i||e.startsWith(`${i}.`)?r+e.slice(i.length):e;return new Set([...e].map(a))}function Rs(e,t){return De(e)?t(e.kind):e.kind===`not`?`NOT ${Rs(e.child,t)}`:e.children.map(e=>zs(e,t)).join(` · `)}function zs(e,t){return vs(e)?`${e.kind.toUpperCase()} (${Rs(e,t)})`:Rs(e,t)}u();function Bs({leaf:t,devices:n,context:r,underNot:i,toneClass:a,result:s,onNegate:l,move:u,onChange:d,onRemove:f}){let{t:p}=Y(),[m,h]=c(!1),g=R(t);return e(`div`,{className:`rounded border p-2 ${a}`,"data-testid":`when-row`,"data-kind":t.kind,children:[e(`div`,{className:`flex flex-wrap items-end gap-2`,children:[e(`div`,{className:`min-w-[13rem] max-w-xs flex-1`,children:[o(Q,{children:p(`automation.whenTree.rowType`,`Row type`)}),e(W,{variant:`outline`,"data-testid":`when-row-type`,className:`w-full justify-between`,onClick:()=>h(!0),title:p(`automation.leafPicker.changeType`,`Change type`),children:[o(`span`,{className:`truncate`,children:fi(t.kind)}),o(`span`,{className:`text-foreground-subtle`,children:p(`automation.leafPicker.changeType`,`Change type`)})]}),o(va,{open:m,onOpenChange:h,mode:`change`,context:r,underNot:i,treeFull:!1,onPick:e=>{e!==t.kind&&d(Ns(t,e))}})]}),o(G,{variant:g?`info`:`neutral`,"data-testid":`when-row-nature`,children:g?p(`automation.whenTree.natureEvent`,`Event`):p(`automation.whenTree.natureState`,`State`)}),o(`span`,{className:`flex-1`}),u!==void 0&&o(Ri,{move:u}),l!==null&&o(W,{variant:`ghost`,onClick:l,title:p(`automation.whenTree.negateRow`,`Invert this row (NOT)`),children:`NOT`}),o(W,{variant:`ghost`,onClick:f,title:p(`automation.whenTree.removeRow`,`Remove this row`),children:o(k,{className:`h-3.5 w-3.5`})})]}),o(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:o(Vs,{leaf:t,devices:n,onChange:d})}),s!==void 0&&o(`div`,{className:`mt-2`,children:s})]})}function Vs({leaf:e,devices:t,onChange:n}){switch(e.kind){case`device-becomes`:return o(Va,{leaf:e,devices:t,onChange:n});case`device-event`:return o(Ua,{leaf:e,onChange:n});case`device-fired`:return o(lo,{leaf:e,onChange:n});case`schedule`:return o(Na,{leaf:e,onChange:n});case`interval`:return o(Io,{leaf:e,onChange:n});case`manual`:return o(Pa,{});case`detection`:return o(Po,{leaf:e,devices:t,onChange:n});case`stationary`:return o(Fo,{leaf:e,devices:t,onChange:n});case`device-is`:return o(Aa,{leaf:e,devices:t,onChange:n});case`stationary-present`:return o(Lo,{leaf:e,devices:t,onChange:n});case`expression`:return o(qa,{leaf:e,devices:t,onChange:n});case`time-is`:return o(hs,{leaf:e,onChange:n});case`triggered-by`:return o(_s,{leaf:e,devices:t,onChange:n})}}u();function Hs(e){return e===`any`?`any`:`all`}function Us(e){return e===`pass`?`pass`:e===`fail`?`fail`:`idle`}function Ws(e,t,n=!0){return e===void 0?t:n?Vr(Us(e)):Ur(Us(e))}function Gs(e,t){return e.run?.nodes.get(ys(t))}function Ks({recipe:t,devices:n,onChange:r,run:i=null,hideRule:a=!1,context:s=`trigger`}){let{t:l}=Y(),u=bs(t),d=Ps(t),[f,p]=c(()=>new Set),m={leafContext:s,recipe:t,devices:n,run:i,onChange:r,reshape:e=>{p(new Set),r(e)},collapsed:f,toggleCollapsed:e=>{let t=ys(e);p(e=>e.has(t)?new Set([...e].filter(e=>e!==t)):new Set([...e,t]))},moveControls:(e,n)=>{let i=e[e.length-1]??0,a=n=>()=>{let a=[...e.slice(0,-1),i+n];p(t=>Ls(t,e,a)),r(Is(t,e,n))};return{up:i>0?a(-1):null,down:i<n-1?a(1):null}}},h=u.children.length===0;return e(`div`,{className:`space-y-2`,"data-testid":`when-tree`,children:[!a&&o(`p`,{className:`text-xs text-foreground-subtle`,children:l(`automation.whenTree.rule`,`An event starts a run when it happens and everything here is true at that moment. With only states, a run starts when they become true.`)}),o(tc,{block:u,path:[],ctx:m,underNot:!1,rail:0,budgetText:l(`automation.whenTree.budget`,{depth:d.depth,depthLimit:d.depthLimit,leaves:d.leaves,leafLimit:d.leafLimit}),move:null,emptyHint:h&&!a?l(`automation.whenTree.empty`,`Add a row to say when this runs. Without one nothing can ever start this automation.`):null})]})}function qs({node:e,path:t,ctx:n,underNot:r,move:i,rail:a}){return De(e)?o(Js,{leaf:e,path:t,ctx:n,underNot:r,move:i}):e.kind===`not`?o(ec,{child:e.child,path:t,ctx:n,move:i,rail:a}):o(tc,{block:e,path:t,ctx:n,underNot:r,move:i,rail:a,budgetText:null,emptyHint:null})}function Js({leaf:e,path:t,ctx:n,underNot:r,move:i}){let a=Gs(n,t),s=n.run!==null&&n.run.triggerPath===ys(t)?n.run.vars:void 0;return o(Bs,{leaf:e,devices:n.devices,context:n.leafContext,underNot:r,toneClass:Ws(a?.outcome,`border-border`),result:a===void 0?void 0:o(Ys,{leaf:e,node:a,vars:s}),onNegate:r?null:()=>n.reshape(js(n.recipe,t)),...i===null?{}:{move:i},onChange:e=>n.onChange(Os(n.recipe,t,e)),onRemove:()=>n.reshape(ks(n.recipe,t))})}function Ys({leaf:e,node:t,vars:n}){return e.kind===`device-is`&&e.unit!==void 0?o(Xs,{leaf:e,node:t,vars:n}):o(Di,{node:t,vars:n,expected:t.expected,observed:t.observed})}function Xs({leaf:e,node:t,vars:n}){let r=Da(ki({deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath})),i=r===void 0?void 0:ke(r),a=t=>t===void 0?null:Or(t,i,e.unit);return o(Di,{node:t,vars:n,expected:a(t.rawExpected),observed:a(t.rawObserved)})}function Zs({node:e}){return e===void 0?null:o(Di,{node:e,expected:null,observed:null})}function Qs({expanded:e,onToggle:t}){let{t:n}=Y(),r=e?n(`automation.whenTree.collapse`,`Collapse this block`):n(`automation.whenTree.expand`,`Expand this block`);return o(W,{variant:`ghost`,"aria-expanded":e,"aria-label":r,title:r,onClick:t,children:o(rn,{expanded:e})})}function $s({node:e}){let{t}=Y(),n=`${t(`automation.whenTree.rowCount`,{count:V(e)})} · ${Rs(e,fi)}`;return o(`p`,{"data-testid":`when-block-summary`,title:n,className:`break-words text-xs text-foreground-muted sm:truncate`,children:n})}function ec({child:t,path:n,ctx:r,move:i,rail:a}){let{t:s}=Y(),c=!r.collapsed.has(ys(n));return e(`div`,{className:`space-y-1.5 rounded border p-2 ${Ws(Gs(r,n)?.outcome,`border-warning/40`,!1)}`,"data-testid":`when-not`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(Qs,{expanded:c,onToggle:()=>r.toggleCollapsed(n)}),o(G,{variant:`warning`,children:`NOT`}),o(`span`,{className:`text-xs text-foreground-subtle`,children:s(`automation.whenTree.notHint`,`True when what is below is not`)}),o(`span`,{className:`flex-1`}),i!==null&&o(Ri,{move:i}),e(W,{variant:`ghost`,onClick:()=>r.reshape(Ms(r.recipe,n)),title:s(`automation.whenTree.removeNot`,`Remove the NOT, keeping what is inside`),children:[o(Je,{className:`h-3.5 w-3.5`}),` `,s(`automation.whenTree.removeNotLabel`,`Remove NOT`)]})]}),o(Zs,{node:Gs(r,n)}),c?o(`div`,{className:`pl-3`,children:o(qs,{node:t,path:[...n,0],ctx:r,underNot:!0,move:null,rail:a})}):o($s,{node:t})]})}function tc({block:t,path:n,ctx:r,underNot:i,move:a,rail:s,budgetText:l,emptyHint:u}){let{t:d}=Y(),f=n.length===0,p=f||!r.collapsed.has(ys(n)),m=Fs(r.recipe,n),[h,g]=c(!1),_=na(t.children,s),v=[{value:`all`,label:d(`automation.whenTree.allOf`,`All of (AND)`)},{value:`any`,label:d(`automation.whenTree.anyOf`,`Any of (OR)`)}];return e(`div`,{className:`space-y-2 rounded border p-2 ${Ws(Gs(r,n)?.outcome,`border-border`,!1)}`,"data-testid":`when-block`,"data-kind":t.kind,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[!f&&o(Qs,{expanded:p,onToggle:()=>r.toggleCollapsed(n)}),o(`div`,{className:`w-40`,children:o(F,{"aria-label":d(`automation.whenTree.blockKind`,`How the rows below combine`),"data-testid":`when-block-kind`,value:t.kind,options:v,onChange:e=>r.onChange(As(r.recipe,n,Hs(e.target.value)))})}),l!==null&&o(`span`,{className:`text-xs text-foreground-subtle`,children:l}),o(`span`,{className:`flex-1`}),a!==null&&o(Ri,{move:a}),!f&&!i&&o(W,{variant:`ghost`,onClick:()=>r.reshape(js(r.recipe,n)),title:d(`automation.whenTree.negateBlock`,`Invert this block (NOT)`),children:`NOT`}),!f&&o(W,{variant:`ghost`,onClick:()=>r.reshape(ks(r.recipe,n)),title:d(`automation.whenTree.removeBlock`,`Delete this block and everything in it`),children:o(k,{className:`h-3.5 w-3.5`})})]}),o(Zs,{node:Gs(r,n)}),u!==null&&o(`p`,{className:`text-xs text-foreground-subtle`,children:u}),!p&&o($s,{node:t}),p&&t.children.length>0&&o(`div`,{className:`space-y-1.5 border-l-2 pl-3 ${ra(s)}`,"data-testid":`when-block-rail`,"data-rail":s,children:t.children.map((e,i)=>o(qs,{node:e,path:[...n,i],ctx:r,underNot:!1,move:r.moveControls([...n,i],t.children.length),rail:_[i]??s},ys([...n,i])))}),p&&e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(W,{variant:`outline`,onClick:()=>g(!0),title:d(`automation.whenTree.addRowTitle`,`Add one row: an event or a state`),children:[o(D,{className:`h-4 w-4`}),` `,d(`automation.whenTree.addRow`,`Add row`)]}),o(va,{open:h,onOpenChange:g,mode:`add`,context:r.leafContext,underNot:i,treeFull:V(bs(r.recipe))>=32,onPick:e=>r.onChange(Ds(r.recipe,n,gi(e)))}),e(W,{variant:`outline`,disabled:!m,onClick:()=>r.onChange(Ds(r.recipe,n,Es(t.kind===`all`?`any`:`all`))),title:m?d(`automation.whenTree.addBlockTitle`,`Add a nested block of rows`):d(`automation.whenTree.tooDeep`,`The rules nest at most {{max}} levels deep`,{max:Ps(r.recipe).depthLimit}),children:[o(D,{className:`h-4 w-4`}),` `,d(`automation.whenTree.addBlock`,`Add block`)]})]})]})}var nc={kind:`all`,children:[]};function rc(e){return e.kind===`wait`||e.kind===`cap`}function ic(e){return!De(e)&&e.kind!==`not`&&e.children.length===0?null:oe(e)}function ac(e){let{if:t,else:n,...r}=e;return r}function oc({when:t,devices:n,hint:r,onChange:i,children:a}){let{t:s}=Y(),c=t===void 0?null:{when:t,actions:[]},l=t===void 0?null:ic(t);return e(`div`,{className:`space-y-2 border-t border-border-subtle pt-2`,children:[o(cn,{checked:t!==void 0,label:s(`automation.stepGuard.if`,`Only if…`),"aria-label":s(`automation.stepGuard.if`,`Only if…`),onCheckedChange:e=>i(e?nc:void 0)}),c!==null&&e(m,{children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:r}),o(Ks,{hideRule:!0,context:`guard`,recipe:c,devices:n,onChange:e=>i(e.when)}),l!==null&&o(K,{variant:`warning`,message:l}),a]})]})}function sc({step:t,devices:n,devicesState:r,variables:i,onChange:a}){let{t:s}=Y();return e(oc,{when:t.if,devices:n,hint:s(`automation.stepGuard.hint`,`Checked when this step is reached. If a state cannot be read, the step and its else are both skipped.`),onChange:e=>a(e===void 0?ac(t):{...t,if:e}),children:[o(cn,{checked:t.else!==void 0,label:s(`automation.stepGuard.else`,`Otherwise, run…`),"aria-label":s(`automation.stepGuard.else`,`Otherwise, run…`),onCheckedChange:e=>{if(e)a({...t,else:[]});else{let{else:e,...n}=t;a(n)}}}),t.else!==void 0&&o(`div`,{className:`border-l-2 border-border-subtle pl-3`,children:o(Sc,{nested:!0,actions:t.else,devices:n,...r===void 0?{}:{devicesState:r},...i===void 0?{}:{variables:i},allowedKinds:[`cap`,`wait`],onChange:e=>a({...t,else:e.filter(rc)})})})]})}function cc({index:t,step:n,devices:r,devicesState:i,variables:a,depth:s=0,roundDevices:c,onChange:l}){let{t:u}=Y(),d={nested:!0,flowControl:!0,devices:r,depth:s+1,allowedKinds:Qi(s+1),...c===void 0?{}:{roundDevices:c},...i===void 0?{}:{devicesState:i},...a===void 0?{}:{variables:a}};return e(`div`,{className:`space-y-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:u(`automation.choose.hint`,`Read top to bottom: the first branch whose condition is true runs, and only that one. If a condition cannot be read, nothing runs.`)}),n.branches.map((i,a)=>{let s={when:i.if,actions:[]},c=ic(i.if);return e(`div`,{className:`space-y-2 border-l-2 border-border-subtle pl-3`,"data-testid":`choose-branch-${String(t)}-${String(a)}`,children:[e(`div`,{className:`flex items-center gap-2`,children:[o(Q,{children:a===0?u(`automation.choose.if`,`If`):u(`automation.choose.elseIf`,`Otherwise, if`)}),o(W,{variant:`ghost`,className:`ml-auto`,disabled:!qi(n),"data-testid":`choose-remove-${String(t)}-${String(a)}`,onClick:()=>l(Ji(n,a)),title:qi(n)?u(`automation.choose.removeBranch`,`Remove this branch`):u(`automation.choose.lastBranch`,`A choose keeps at least one branch`),children:o(k,{className:`h-3.5 w-3.5`})})]}),o(Ks,{hideRule:!0,context:`guard`,recipe:s,devices:r,onChange:e=>l(Yi(n,a,{...i,if:e.when}))}),c!==null&&o(K,{variant:`warning`,message:c}),o(Q,{children:u(`automation.choose.then`,`Then run`)}),o(Sc,{...d,actions:i.steps,onChange:e=>l(Yi(n,a,{...i,steps:e.filter($i)}))})]},String(a))}),e(W,{variant:`outline`,"data-testid":`choose-add-${String(t)}`,disabled:!Gi(n),onClick:()=>l(Ki(n)),title:Gi(n)?void 0:u(`automation.choose.maxBranches`,`A choose takes at most 6 branches`),children:[o(D,{className:`h-4 w-4`}),` `,u(`automation.choose.addBranch`,`Add a branch`)]}),o(cn,{"data-testid":`choose-else-${String(t)}`,checked:n.else!==void 0,label:u(`automation.choose.else`,`Otherwise, run…`),"aria-label":u(`automation.choose.else`,`Otherwise, run…`),onCheckedChange:e=>l(Xi(n,e?[]:void 0))}),n.else!==void 0&&o(`div`,{className:`border-l-2 border-border-subtle pl-3`,children:o(Sc,{...d,actions:n.else,onChange:e=>l(Xi(n,e.filter($i)))})})]})}function lc(e){return Object.entries(e).map(([e,t])=>({name:e,value:t}))}function uc(e){return Object.fromEntries(e.map(e=>[e.name,e.value]))}function dc(e,t,n){let r=lc(e);return r.some((e,r)=>r!==t&&e.name===n)?e:uc(r.map((e,r)=>r===t?{...e,name:n}:e))}function fc(e,t,n){return uc(lc(e).map((e,r)=>r===t?{...e,value:n}:e))}function pc(e){return!Object.keys(e).includes(``)}function mc(e){return pc(e)?{...e,"":``}:e}function hc(e,t){return uc(lc(e).filter((e,n)=>n!==t))}var gc=`{{vars.name}}`;function _c({index:t,vars:n,onChange:r}){let{t:i}=Y();return e(`div`,{className:`space-y-2`,children:[lc(n).map((a,s)=>e(`div`,{className:`flex flex-wrap items-end gap-2`,children:[e(`label`,{className:`w-40`,children:[o(Q,{children:i(`automation.actionList.setName`,`Variable`)}),o(q,{"data-testid":`set-name-${String(t)}-${String(s)}`,value:a.name,spellCheck:!1,onChange:e=>r(dc(n,s,e.target.value))})]}),e(`label`,{className:`min-w-40 flex-1`,children:[o(Q,{children:i(`automation.actionList.setValue`,`Value`)}),o(q,{"data-testid":`set-value-${String(t)}-${String(s)}`,value:String(a.value),onChange:e=>r(fc(n,s,e.target.value))})]}),o(W,{variant:`ghost`,onClick:()=>r(hc(n,s)),title:i(`automation.actionList.setRemove`,`Remove this variable`),children:o(k,{className:`h-3.5 w-3.5`})})]},String(s))),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(W,{variant:`outline`,"data-testid":`set-add-${String(t)}`,disabled:!pc(n),onClick:()=>r(mc(n)),children:[o(D,{className:`h-4 w-4`}),` `,i(`automation.actionList.setAdd`,`Add a variable`)]}),o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`automation.actionList.setHint`,`The steps after this one can use it as {{slot}}.`,{slot:gc,interpolation:{escapeValue:!1}})})]})]})}function vc({index:t,step:n,devices:r,devicesState:i,variables:a,depth:s=0,roundDevices:c,onChange:l}){let{t:u}=Y(),{loop:d}=n,f={count:u(`automation.repeat.byCount`,`A number of times`),while:u(`automation.repeat.byWhile`,`While a condition is true`),until:u(`automation.repeat.byUntil`,`Until a condition is true`),forEach:u(`automation.repeat.byForEach`,`Once for each device`)},p=d.by===`while`||d.by===`until`,h=p?ic(d.when):null,g={name:Ve,hint:u(`automation.repeat.itemHint`,`the device of this round`)},_=d.by===`forEach`?[...a??[],g]:a,v=d.by===`forEach`?d.target.ids:c;return e(`div`,{className:`space-y-2`,children:[o(`div`,{className:`w-64`,children:o(F,{"data-testid":`repeat-by-${String(t)}`,"aria-label":u(`automation.repeat.by`,`Repeat`),value:d.by,onChange:e=>{let t=e.target.value;Yr(t)&&t!==d.by&&l({...n,loop:$r(t)})},options:Gr.map(e=>({value:e,label:f[e]}))})}),d.by===`count`&&e(`label`,{className:`block w-24`,children:[o(Q,{children:u(`automation.repeat.count`,`Times`)}),o(q,{type:`number`,min:1,max:20,"data-testid":`repeat-count-${String(t)}`,value:String(d.count),onChange:e=>l({...n,loop:{...d,count:Zr(Number(e.target.value))}})})]}),p&&e(m,{children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:d.by===`while`?u(`automation.repeat.whileHint`,`Read before each round: if it is not true at the start, nothing runs. A condition that cannot be read ends the loop.`):u(`automation.repeat.untilHint`,`Read after each round, so the steps run at least once. A condition that cannot be read ends the loop.`)}),o(Ks,{hideRule:!0,context:`guard`,recipe:{when:d.when,actions:[]},devices:r,onChange:e=>l({...n,loop:{...d,when:e.when}})}),h!==null&&o(K,{variant:`warning`,message:h}),e(`div`,{className:`flex flex-wrap items-end gap-2`,children:[e(`label`,{className:`w-28`,children:[o(Q,{children:u(`automation.repeat.max`,`At most (rounds)`)}),o(q,{type:`number`,min:1,max:50,"data-testid":`repeat-max-${String(t)}`,value:String(d.maxIterations),onChange:e=>l({...n,loop:{...d,maxIterations:Qr(Number(e.target.value))}})})]}),e(`label`,{className:`w-40`,children:[o(Q,{children:u(`automation.repeat.wait`,`Pause between rounds (s)`)}),o(q,{type:`number`,min:1,max:3600,"data-testid":`repeat-wait-${String(t)}`,value:d.waitS===void 0?``:String(d.waitS),placeholder:u(`automation.repeat.noWait`,`none`),onChange:e=>l({...n,loop:ei(d,e.target.value===``?null:Number(e.target.value))})})]})]}),o(`p`,{className:`text-xs text-foreground-subtle`,children:u(`automation.repeat.maxHint`,`A loop that reaches its maximum stops there, is marked in the run, and the run goes on.`)})]}),d.by===`forEach`&&e(`div`,{className:`space-y-1`,children:[o($e,{multiple:!0,pick:`device`,maxItems:50,value:d.target.ids.map(e=>({deviceId:e})),onChange:e=>l({...n,loop:{...d,target:{kind:`devices`,ids:e.map(e=>e.deviceId)}}})}),o(`p`,{className:`text-xs text-foreground-subtle`,children:u(`automation.repeat.forEachHint`,`One round per device, in this order. In a round the steps read the device as the variable "item".`)})]}),o(Q,{children:u(`automation.repeat.steps`,`Each time, run`)}),o(`div`,{className:`border-l-2 border-border-subtle pl-3`,"data-testid":`repeat-steps-${String(t)}`,children:o(Sc,{nested:!0,flowControl:!0,actions:n.steps,devices:r,depth:s+1,allowedKinds:Qi(s+1),maxSteps:10,...i===void 0?{}:{devicesState:i},..._===void 0?{}:{variables:_},...v===void 0?{}:{roundDevices:v},onChange:e=>l({...n,steps:e.filter($i)})})})]})}function yc({index:t,step:n,devices:r,onChange:i}){let{t:a}=Y(),s={when:n.when,actions:[]},c=ic(n.when),l=ai(n.timeoutS),u={s:a(`automation.waitUntil.unitSeconds`,`seconds`),min:a(`automation.waitUntil.unitMinutes`,`minutes`),h:a(`automation.waitUntil.unitHours`,`hours`)};return e(`div`,{className:`space-y-2`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:a(`automation.waitUntil.hint`,`The run pauses here until this is true. A value that cannot be read is not "true": the run keeps waiting.`)}),o(Ks,{hideRule:!0,context:`guard`,recipe:s,devices:r,onChange:e=>i({...n,when:e.when})}),c!==null&&o(K,{variant:`warning`,message:c}),e(`div`,{className:`flex flex-wrap items-end gap-2`,children:[e(`label`,{className:`w-24`,children:[o(Q,{children:a(`automation.waitUntil.timeout`,`At most`)}),o(q,{type:`number`,min:1,"data-testid":`wait-until-timeout-${String(t)}`,value:String(l.value),onChange:e=>i({...n,timeoutS:oi(Number(e.target.value),l.unit)})})]}),o(`div`,{className:`w-32`,children:o(F,{"data-testid":`wait-until-unit-${String(t)}`,"aria-label":a(`automation.waitUntil.unit`,`Unit`),value:l.unit,onChange:e=>i({...n,timeoutS:oi(l.value,ii(e.target.value)?e.target.value:l.unit)}),options:ni.map(e=>({value:e,label:u[e]}))})}),e(`label`,{className:`min-w-56 flex-1`,children:[o(Q,{children:a(`automation.waitUntil.onTimeout`,`If it does not happen in time`)}),o(F,{"data-testid":`wait-until-on-timeout-${String(t)}`,value:n.onTimeout,onChange:e=>i({...n,onTimeout:e.target.value===`stop`?`stop`:`continue`}),options:[{value:`continue`,label:a(`automation.waitUntil.continue`,`Go on with the next step`)},{value:`stop`,label:a(`automation.waitUntil.stop`,`Stop the run as a failure`)}]})]})]})]})}var bc=[{value:`cap`,labelKey:`automation.actionList.kindCap`},{value:`action`,labelKey:`automation.actionList.kindAction`},{value:`wait`,labelKey:`automation.actionList.kindWait`},{value:`wait-until`,labelKey:`automation.actionList.kindWaitUntil`},{value:`set`,labelKey:`automation.actionList.kindSet`},{value:`stop`,labelKey:`automation.actionList.kindStop`},{value:`choose`,labelKey:`automation.actionList.kindChoose`},{value:`parallel`,labelKey:`automation.actionList.kindParallel`},{value:`repeat`,labelKey:`automation.actionList.kindRepeat`},{value:`code`,labelKey:`automation.actionList.kindCode`}],xc=[`set`,`stop`,`choose`,`wait-until`,`parallel`,`repeat`];function Sc({actions:t,devices:n,devicesState:r=`answered`,allowedKinds:i,variables:a=[],stepTones:s,stepResults:c,nested:l=!1,flowControl:u=!1,maxSteps:d,roundDevices:f,depth:p=0,onChange:m}){let{t:h}=Y(),g=bc.filter(e=>(i===void 0||i.includes(e.value))&&(u||!xc.includes(e.value))),_=h(`automation.actionList.flowGuardHint`,`Checked when this step is reached. If it is false, or a state cannot be read, the step does nothing.`),v={up:h(`automation.actionList.runThisStepEarlier`,`Run this step earlier`),down:h(`automation.actionList.runThisStepLater`,`Run this step later`),atFirst:h(`automation.actionList.alreadyFirstStep`,`This step already runs first`),atLast:h(`automation.actionList.alreadyLastStep`,`This step already runs last`)};return e(`div`,{className:`space-y-2`,children:[t.length===0&&o(`p`,{className:`text-xs text-warning`,children:h(`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`:Vr(s[d]??`idle`)}`,children:[e(`div`,{className:`flex flex-wrap items-end gap-2`,children:[o(G,{variant:`default`,children:d+1}),e(`label`,{className:`w-40`,children:[o(Q,{children:h(`automation.actionList.step`,`Step`)}),o(F,{"data-testid":`step-kind-${String(d)}`,value:i.kind,onChange:e=>m(Z(t,d,_i(Cc(e.target.value)))),options:g.map(e=>({value:e.value,label:h(e.labelKey)}))})]}),e(`div`,{className:`ml-auto flex items-center gap-1`,children:[o(Ri,{move:{up:d===0?null:()=>m(yi(t,d,d-1)),down:d===t.length-1?null:()=>m(yi(t,d,d+1))},texts:v}),o(W,{variant:`ghost`,onClick:()=>m(vi(t,d)),title:h(`automation.actionList.removeThisStep`,`Remove this step`),children:o(k,{className:`h-3.5 w-3.5`})})]})]}),i.kind===`wait`&&e(`label`,{className:`block w-32`,children:[o(Q,{children:h(`automation.actionList.seconds`,`Seconds`)}),o(q,{type:`number`,min:0,max:3600,value:String(i.seconds),onChange:e=>m(Z(t,d,{...i,seconds:Number(e.target.value)}))})]}),i.kind===`stop`&&e(`div`,{className:`flex flex-wrap items-end gap-2`,children:[e(`label`,{className:`min-w-48 flex-1`,children:[o(Q,{children:h(`automation.actionList.stopReason`,`Reason`)}),o(q,{"data-testid":`stop-reason-${String(d)}`,value:i.reason,maxLength:200,onChange:e=>m(Z(t,d,{...i,reason:e.target.value}))})]}),e(`label`,{className:`w-48`,children:[o(Q,{children:h(`automation.actionList.stopOutcome`,`The run ends as`)}),o(F,{"data-testid":`stop-outcome-${String(d)}`,value:i.outcome,onChange:e=>m(Z(t,d,{...i,outcome:e.target.value===`failed`?`failed`:`ok`})),options:[{value:`ok`,label:h(`automation.actionList.stopOk`,`A success`)},{value:`failed`,label:h(`automation.actionList.stopFailed`,`A failure`)}]})]})]}),i.kind===`set`&&o(_c,{index:d,vars:i.vars,onChange:e=>m(Z(t,d,{...i,vars:e}))}),i.kind===`wait-until`&&o(yc,{index:d,step:i,devices:n,onChange:e=>m(Z(t,d,e))}),i.kind===`repeat`&&o(vc,{index:d,step:i,devices:n,devicesState:r,variables:a,depth:p,...f===void 0?{}:{roundDevices:f},onChange:e=>m(Z(t,d,e))}),i.kind===`parallel`&&e(`div`,{className:`space-y-2`,"data-testid":`parallel-steps-${String(d)}`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:h(`automation.parallel.hint`,`These start together and the run goes on when all are done. If one fails, the run fails once the others finished.`)}),o(`div`,{className:`border-l-2 border-border-subtle pl-3`,children:o(Sc,{nested:!0,flowControl:!0,actions:i.steps,devices:n,devicesState:r,variables:a,allowedKinds:Bi,depth:p+1,...f===void 0?{}:{roundDevices:f},maxSteps:5,onChange:e=>m(Z(t,d,{...i,steps:e.filter(Vi)}))})})]}),i.kind===`choose`&&o(cc,{index:d,step:i,devices:n,devicesState:r,variables:a,depth:p,...f===void 0?{}:{roundDevices:f},onChange:e=>m(Z(t,d,e))}),!l&&(i.kind===`stop`||i.kind===`set`)&&o(oc,{when:i.if,devices:n,hint:_,onChange:e=>{let{if:n,...r}=i;m(Z(t,d,e===void 0?r:{...r,if:e}))}}),i.kind===`code`&&e(`label`,{className:`block`,children:[o(Q,{children:h(`automation.actionList.code`,`Code`)}),o(Yt,{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=>m(Z(t,d,{kind:`code`,code:e.target.value}))}),o(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:o(bn,{i18nKey:`automation.actionList.codeHint`,components:{code:o(`code`,{})}})})]}),i.kind===`cap`&&o(Yn,{step:i,devices:n,devicesState:r,variables:a,...f===void 0?{}:{roundDevices:f},onChange:e=>m(Z(t,d,{...e,...i.continueOnError===!0?{continueOnError:!0}:{},...i.if===void 0?{}:{if:i.if},...i.else===void 0?{}:{else:i.else}}))}),i.kind===`action`&&o(Fi,{step:i,onChange:e=>m(Z(t,d,{...e,...i.continueOnError===!0?{continueOnError:!0}:{}}))}),u&&(i.kind===`cap`||i.kind===`action`)&&o(cn,{"data-testid":`continue-on-error-${String(d)}`,checked:i.continueOnError===!0,label:h(`automation.actionList.continueOnError`,`Continue if this step fails`),"aria-label":h(`automation.actionList.continueOnError`,`Continue if this step fails`),onCheckedChange:e=>{let{continueOnError:n,...r}=i;m(Z(t,d,e?{...r,continueOnError:!0}:r))}}),!l&&(i.kind===`wait`||i.kind===`cap`)&&o(sc,{step:i,devices:n,devicesState:r,variables:a,onChange:e=>m(Z(t,d,e))}),c?.[d]!==void 0&&o(Oi,{step:c[d],deviceName:e=>n.find(t=>t.id===e)?.name??`#${String(e)}`})]},`${i.kind}-${String(d)}`)),e(`div`,{className:`flex items-center gap-2`,children:[e(W,{variant:`outline`,disabled:d!==void 0&&t.length>=d,onClick:()=>m([...t,_i(g[0]?.value??`cap`)]),children:[o(D,{className:`h-4 w-4`}),` `,h(`automation.actionList.addStep`)]}),t.length>1&&o(`span`,{className:`text-xs text-foreground-subtle`,children:h(`automation.actionList.stepsRunInOrderAnd`,`Steps run in order and stop at the first failure.`)})]})]})}function Cc(e){return bc.find(t=>t.value===e)?.value??`cap`}function wc(e,t){return e.map(e=>({name:e.name,hint:e.label??t(`flow.scope.type_${e.type}`,e.type)}))}function Tc(e,t){return He(e).map(e=>({name:e.name,hint:t(`flow.scope.${e.hintKey??e.name}`,e.description)}))}function Ec(e){return e.some(e=>e.required===!0&&e.default===void 0)}function Dc(e){return Object.fromEntries(e.map(e=>[e.name,e.default??(e.type===`boolean`?!1:void 0)]))}function Oc(e){return e===void 0?!1:typeof e==`string`?e.trim()!==``:typeof e==`number`?Number.isFinite(e):!0}function kc(e,t){return e.filter(e=>e.required===!0&&!Oc(t[e.name])).map(e=>e.name)}function Ac(e,t){let n={};for(let r of e){let e=t[r.name];Oc(e)&&(n[r.name]=e)}return n}u();function jc({variable:e,value:t,onChange:n}){let{t:r}=Y(),i=e.label??e.name;return e.type===`number`?o(X,{"aria-label":i,value:typeof t==`number`?t:void 0,onValue:e=>n(e??void 0)}):e.type===`boolean`?o(Zn,{widthClass:`w-28`,"aria-label":i,value:t===!0?`yes`:`no`,onChange:e=>n(e.target.value===`yes`),options:[{value:`yes`,label:r(`common.yes`,`Yes`)},{value:`no`,label:r(`common.no`,`No`)}]}):e.type===`select`?o(Zn,{widthClass:`w-48`,"aria-label":i,value:typeof t==`string`?t:``,onChange:e=>n(e.target.value===``?void 0:e.target.value),options:[{value:``,label:r(`actions.editor.runDialog.choose`,`Choose…`)},...(e.options??[]).map(e=>({value:e,label:e}))]}):o(q,{"aria-label":i,value:typeof t==`string`?t:``,onChange:e=>n(e.target.value)})}function Mc({actionName:t,variables:n,running:r,onRun:i,onCancel:a}){let{t:s}=Y(),[l,u]=c(()=>Dc(n)),d=kc(n,l);return o(ut,{open:!0,onOpenChange:e=>!e&&a(),children:e(Ft,{"aria-label":s(`actions.editor.runDialog.title`,`Run {{name}}`,{name:t}),children:[e(dn,{children:[o(pt,{children:s(`actions.editor.runDialog.title`,`Run {{name}}`,{name:t})}),o(st,{children:s(`actions.editor.runDialog.description`,`Give the variables this run should use.`)})]}),o(`div`,{className:`space-y-3`,"data-testid":`run-variables-form`,children:n.map(t=>e(`label`,{className:`block space-y-1`,children:[e(`span`,{className:`text-xs text-foreground-subtle`,children:[t.label??t.name,t.required===!0?` *`:``]}),o(jc,{variable:t,value:l[t.name],onChange:e=>u({...l,[t.name]:e})})]},t.name))}),e(ht,{className:`flex flex-wrap gap-2`,children:[o(W,{variant:`ghost`,onClick:a,children:s(`common.cancel`,`Cancel`)}),e(W,{disabled:r||d.length>0,onClick:()=>i(Ac(n,l)),children:[r?o(T,{className:`h-4 w-4 animate-spin`}):o(g,{className:`h-4 w-4`}),` `,s(`actions.editor.runNow`,`Run now`)]})]})]})})}var Nc=[`number`,`string`,`boolean`,`select`];function Pc(e,t){return{name:e.name,...e.label===void 0?{}:{label:e.label},type:t,...t===`select`?{options:e.options??[`option`]}:{}}}function Fc(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 Ic(e,t){let{default:n,...r}=e;return t===null?r:{...r,default:t}}function Lc(e,t){let{label:n,...r}=e;return t.trim()===``?r:{...r,label:t}}function Rc({variables:t,onChange:n,onRename:r}){let{t:i}=Y(),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(Mt,{headingId:`vars-heading`,title:i(`actions.variables.title`,`Variables`),icon:Xe,actions:e(W,{variant:`outline`,size:`sm`,onClick:()=>n([...t,er(t)]),children:[o(D,{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(q,{"aria-label":i(`actions.variables.nameAria`,`Variable name`),value:c.name,"aria-invalid":!tr(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(q,{"aria-label":i(`actions.variables.label`,`Label`),value:c.label??``,onChange:e=>s(l,Lc(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(Zn,{widthClass:`w-full`,"aria-label":i(`actions.variables.type`,`Type`),value:c.type,options:Nc.map(e=>({value:e,label:a(e)})),onChange:e=>{let t=Nc.find(t=>t===e.target.value);t!==void 0&&s(l,Pc(c,t))}})]}),e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.default`,`Default`)}),o(zc,{variable:c,onChange:e=>s(l,Ic(c,e))})]}),e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.options`,`Options`)}),o(q,{"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,Fc(c,e.target.value))})]}),o(W,{variant:`ghost`,"aria-label":i(`actions.variables.remove`,`Remove variable`),onClick:()=>n(t.filter((e,t)=>t!==l)),children:o(k,{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 zc({variable:e,onChange:t}){let{t:n}=Y(),r=n(`actions.variables.default`,`Default`);if(e.type===`number`)return o(X,{"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(Zn,{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(q,{"aria-label":r,value:typeof e.default==`string`?e.default:``,onChange:e=>t(e.target.value===``?null:e.target.value)})}u();var Bc=5e3;function Vc(e){return e.kind===`cap`||e.kind===`wait`}function Hc(e){return e instanceof Error?e.message:String(e)}function Uc(){let{t:e}=Y();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 Wc({entry:t,onClose:i,onSaved:a,preset:l=null}){let{t:u}=Y(),d=f(),p=j(),h=Kn(),v=Uc(),[y,b]=c(()=>ir(t)),x=n(!1);s(()=>{if(t!==null||l!==`trigger-alarm`||x.current)return;let e=h.find(e=>e.type===Pe.AlarmPanel);e!==void 0&&(x.current=!0,b(ar(e.id,u(`actions.editor.triggerAlarmName`,`Trigger the alarm`))))},[h,t,l,u]);let[S,C]=c(null),[w,E]=c(!1),D=t!==null&&t.readOnly,O=()=>{d.invalidateQueries({queryKey:[[`actions`]]})},A=Zt({onSuccess:e=>{O(),a(e.action.id)}}),M=Dt({onSuccess:O}),N=_t({onSuccess:()=>{O(),i()}}),P=dt({onSuccess:O}),F=St({actionId:t?.id??`none`},{enabled:t!==null,refetchInterval:Bc}),I=F.data?.traces.find(e=>e.runId===S)??null,L=r(()=>I===null?null:yr(I),[I]),R=r(()=>I===null?null:Tr(I).steps,[I]),z=nr(y),B=r(()=>wc(y.variables,u),[y.variables,u]),V=A.isPending||M.isPending,ee=A.error??M.error??N.error??P.error,H=Ec(t?.variables??[]);return e(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]`,"data-testid":`action-editor`,children:[e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(_,{className:`h-4 w-4 text-foreground-muted`}),o(q,{"aria-label":u(`actions.editor.name`,`Name`),className:`max-w-xs flex-1`,value:y.name,disabled:D,placeholder:u(`actions.editor.namePlaceholder`,`What this action does`),onChange:e=>b({...y,name:e.target.value})}),o(G,{variant:D?`info`:`primary`,children:D?t?.addonId??``:u(`actions.source.internal`,`Internal`)})]}),D?o(`p`,{className:`rounded-md border border-border bg-surface p-3 text-sm text-foreground-muted`,children:u(`actions.editor.readOnly`,`This action is declared by {{addon}}. Edit it there; you can run it from here.`,{addon:t?.addonId??``})}):e(m,{children:[o(Rc,{variables:y.variables,onChange:e=>b({...y,variables:e}),onRename:(e,t)=>b(rr(y,e,t))}),o(Wr,{step:`steps`,title:u(`actions.editor.steps`,`Steps`),trace:L===null?null:L.thenBlock,children:o(Sc,{actions:y.steps,devices:h,allowedKinds:[`cap`,`wait`],stepTones:L===null?void 0:y.steps.map((e,t)=>br(L,t)??`idle`),stepResults:R===null?void 0:y.steps.map((e,t)=>R.find(e=>e.index===t)),variables:B,onChange:e=>b({...y,steps:e.filter(Vc)})})})]}),!z.ok&&!D&&y.name!==``&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:v(z.reason)}),ee!==null&&o(K,{message:Hc(ee)}),e(`div`,{className:`flex flex-wrap gap-2`,children:[!D&&e(W,{onClick:()=>{z.ok&&(t===null?A.mutate({action:z.input}):M.mutate({actionId:t.id,action:z.input}))},disabled:V||!z.ok,children:[V&&o(T,{className:`h-4 w-4 animate-spin`}),` `,u(`common.save`,`Save`)]}),t!==null&&e(W,{variant:`outline`,disabled:P.isPending,onClick:()=>H?E(!0):P.mutate({actionId:t.id}),children:[o(g,{className:`h-4 w-4`}),` `,u(`actions.editor.runNow`,`Run now`)]}),t!==null&&!D&&e(W,{variant:`ghost`,disabled:N.isPending,onClick:()=>{p({title:u(`actions.editor.deleteTitle`,`Delete this action?`),message:u(`actions.editor.deleteMessage`,`{{name}} will be deleted, and removed from every camera that links it.`,{name:t.name}),confirmLabel:u(`common.delete`,`Delete`),variant:`danger`}).then(e=>{e&&N.mutate({actionId:t.id})})},children:[o(k,{className:`h-4 w-4`}),` `,u(`common.delete`,`Delete`)]}),o(W,{variant:`ghost`,onClick:i,children:u(`common.close`,`Close`)})]})]}),o(`div`,{className:`order-first lg:order-last`,children:o(Br,{traces:t===null?[]:F.data?.traces,selectedId:S,onSelect:C})}),w&&t!==null&&o(Mc,{actionName:t.name,variables:t.variables??[],running:P.isPending,onCancel:()=>E(!1),onRun:e=>{P.mutate({actionId:t.id,variables:e}),E(!1)}})]})}u();var Gc=5e3;function Kc(e){return e instanceof Error?e.message:String(e)}function qc(){let{t:e}=Y();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 Jc({createRequested:t=!1,onCreateConsumed:n}){let{t:i}=Y(),[a]=xn(),c=f(),l=qc(),{state:u,openNew:d,openEdit:p,close:h}=Rt({editKey:`action`,newKey:`new`}),v=it({},{refetchInterval:Gc}),y=dt({onSuccess:()=>void c.invalidateQueries({queryKey:[[`actions`]]})});s(()=>{t&&(d(),n?.())},[t,n,d]);let b=v.data??[],x=u.mode===`edit`?b.find(e=>e.id===u.id)??null:null,S=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(G,{variant:`info`,children:e.addonId}):o(G,{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:`-`}):An(e.status.lastRunAt),sortValue:e=>e.status.lastRunAt},{key:`status`,header:i(`actions.list.status`,`Status`),render:e=>{let t=l(e);return o(`span`,{title:e.status.lastError??void 0,children:o(G,{variant:t.variant,children:t.label})})},notSortableReason:i(`actions.list.statusNotSortable`,`Derived from the latest run`)},{key:`run`,align:`right`,render:t=>e(W,{variant:`outline`,size:`sm`,disabled:y.isPending||t.status.isRunning,"aria-label":i(`actions.list.runAria`,`Run {{name}}`,{name:t.name}),onClick:e=>{e.stopPropagation(),y.mutate({actionId:t.id})},children:[o(g,{className:`h-4 w-4`}),` `,i(`actions.list.run`,`Run`)]}),notSortableReason:i(`actions.list.runNotSortable`,`A control`)}],[y,l,i]);return u.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.`)}),y.error!=null&&o(K,{message:Kc(y.error)}),v.data===void 0?v.error==null?o(Nt,{className:`h-24 w-full`}):o(K,{title:i(`actions.list.couldNotRead`,`Could not read the actions`),message:Kc(v.error),onRetry:()=>void v.refetch()}):b.length===0?o(Xt,{icon:_,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(W,{onClick:d,children:[o(D,{className:`h-4 w-4`}),` `,i(`actions.list.new`,`New action`)]})}):e(m,{children:[v.error!=null&&o(K,{title:i(`actions.list.couldNotRead`,`Could not read the actions`),message:Kc(v.error),onRetry:()=>void v.refetch()}),o(At,{columns:S,rows:b,rowKey:e=>e.id,pageSize:25,maxBodyHeight:Pt,emptyMessage:i(`actions.list.emptyTitle`,`No actions yet`),onRowClick:e=>p(e.id)})]})]}):o(Wc,{entry:x,onClose:h,onSaved:p,preset:u.mode===`new`?a.get(`preset`):null},x?.id??`new`)}u();function Yc({code:t,error:n,canEject:r,ejecting:i,onEject:a}){let{t:s}=Y(),[l,u]=c(!1),d=j(),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(W,{variant:`ghost`,onClick:()=>u(!l),children:[o(l?Ge:x,{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(W,{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(qe,{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(gt,{maxHeight:420,children:t})})]})}var Xc=[`single`,`restart`,`queued`,`parallel`,`cooldown`],Zc=2,Qc=30;function $c(e){return e.runMode??{mode:`single`}}function el(e,t){let{runMode:n,...r}=e;return t.mode===`single`?r:{...r,runMode:t}}function tl(e){switch(e){case`queued`:return{mode:`queued`,max:Zc};case`parallel`:return{mode:`parallel`,max:Zc};case`cooldown`:return{mode:`cooldown`,minutes:Qc};case`restart`:return{mode:`restart`};default:return{mode:`single`}}}function nl(e){return Xc.find(t=>t===e)??`single`}function rl({value:t,onChange:n}){let{t:r}=Y(),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(Zn,{widthClass:`w-56`,value:t.mode,options:Xc.map(e=>({value:e,label:i[e]})),onChange:e=>n(tl(nl(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(X,{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(X,{className:`w-20`,"aria-label":r(`flow.runMode.minutes`,`Minutes`),value:t.minutes,onValue:e=>{e!==null&&n({mode:`cooldown`,minutes:Math.round(e)})}})]}),o(`p`,{className:`basis-full text-xs text-foreground-subtle`,children:a[t.mode]})]})}var il;function al(){return il??=Se(ue),il}function ol(e,t=al()){return Ie(e,t)}u();var sl=`hub`,cl=5e3;function ll({existing:t,initialRecipe:n,saving:i,saveError:a,ejecting:s,onSave:l,onEject:u,onCancel:d}){let{t:f}=Y(),[p,m]=c(t?.name??``),[h,g]=c(()=>Ss(n)),_=e=>g(ca(e)),[v,y]=c(!1),[b,x]=c(null),S=It({blockId:t?.id??`none`},{enabled:t!==null,refetchInterval:cl}),C=S.data?.traces.find(e=>e.runId===b)??null,E=r(()=>C===null?null:yr(C),[C]),D=r(()=>Tc(h.when,f),[h.when,f]),O=r(()=>C===null?null:Er(C),[C]),k=r(()=>C===null?null:Tr(C).steps,[C]),A=Kn(),j=fe(h),M=r(()=>ul(h),[h]),N=r(()=>dl(p.trim()===``?`Untitled automation`:p.trim(),h),[p,h]),P=en().data,F=r(()=>M===null?ps(h,P):null,[h,P,M]),I=p.trim()===``,L=I||j!==null||M!==null||F!==null||N.code===null;return e(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]`,"data-testid":`automation-editor`,children:[o(pa,{when:h.when,children:e(`div`,{className:`space-y-4`,children:[e(`label`,{className:`block max-w-md text-sm`,children:[o(`span`,{className:`text-foreground-subtle`,children:f(`automation.automationEditor.name`,`Name`)}),o(q,{className:`mt-1`,value:p,onChange:e=>m(e.target.value),placeholder:f(`automation.automationEditor.whatThisAutomationDoes`,`What this automation does`)})]}),o(Wr,{step:`when`,title:f(`automation.automationEditor.when`,`When`),trace:E===null?null:E.when,children:o(Ks,{recipe:h,devices:A,run:O,onChange:_})}),o(Wr,{step:`then`,title:f(`automation.automationEditor.then`,`Then`),trace:E===null?null:E.thenBlock,hint:f(`automation.automationEditor.inThisOrderStoppingAt`,`In this order, stopping at the first failure.`),children:o(Sc,{flowControl:!0,actions:h.actions,devices:A,variables:D,stepTones:E===null?void 0:h.actions.map((e,t)=>br(E,t)??`idle`),stepResults:k===null?void 0:h.actions.map((e,t)=>k.find(e=>e.index===t)),onChange:e=>_(bi(h,e))})}),o(Wr,{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(rl,{value:$c(h),onChange:e=>_(el(h,e))})}),o(Yc,{code:N.code,error:N.error,canEject:t!==null,ejecting:s,onEject:u}),j!==null&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:j}),j===null&&M!==null&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:M}),j===null&&F!==null&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,"data-testid":`automation-site-error`,children:F}),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(W,{onClick:()=>{N.code!==null&&l({name:p.trim(),code:N.code,enabled:t?.enabled??!0,placement:sl})},disabled:i||L,children:[i&&o(T,{className:`h-4 w-4 animate-spin`}),` `,f(`common.save`)]}),e(W,{variant:`ghost`,onClick:()=>y(!v),disabled:t===null,title:t===null?f(`automation.automationEditor.logsAppearOnceTheAutomation`,`Logs appear once the automation has been saved and started`):f(`automation.automationEditor.showThisAutomationSProcess`,`Show this automation's process logs`),"data-testid":`automation-logs-toggle`,"aria-expanded":v,children:[o(w,{className:`h-4 w-4`}),` `,f(`common.logs`),` `,o(rn,{expanded:v})]}),o(W,{variant:`ghost`,onClick:d,disabled:i,children:f(`common.close`,`Close`)}),I&&o(G,{variant:`warning`,children:f(`automation.automationEditor.nameRequired`,`Name required`)})]}),v&&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(bn,{i18nKey:`common.logsOf`,values:{id:U(t.id)},components:{code:o(`code`,{})}})}),o(kt,{addonId:U(t.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}),o(`div`,{className:`order-first lg:order-last`,children:o(Br,{traces:t===null?[]:S.data?.traces,selectedId:b,onSelect:x})})]})}function ul(e){let t=xe.safeParse(e);if(t.success)return null;let n=t.error.issues[0];return n===void 0?J.t(`helpers.automationEditor.incomplete`):`${n.path.length===0?``:`${n.path.join(`.`)}: `}${n.message}`}function dl(e,t){let n=ol(t);if(!n.ok)return{code:null,error:n.error};try{return{code:ze({name:e,recipe:n.recipe}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function fl(e){if(!e.enabled)return{tone:`idle`,label:J.t(`helpers.coreBlockStatus.disabled`),detail:J.t(`helpers.coreBlockStatus.disabledDetail`)};switch(e.status){case`running`:return{tone:`ok`,label:J.t(`helpers.coreBlockStatus.running`),detail:J.t(`helpers.coreBlockStatus.runningDetail`)};case`starting`:return{tone:`pending`,label:J.t(`helpers.coreBlockStatus.starting`),detail:e.lastError??J.t(`helpers.coreBlockStatus.startingDetail`)};case`failed`:return{tone:`error`,label:J.t(`helpers.coreBlockStatus.failed`),detail:e.lastError??J.t(`helpers.coreBlockStatus.failedDetail`)};default:return{tone:`error`,label:J.t(`helpers.coreBlockStatus.notRunning`),detail:e.lastError??J.t(`helpers.coreBlockStatus.notRunningDetail`)}}}function pl(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function ml(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function hl(e){let t=e=>{let t=fl(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 gl(e){if(e.length===0)return J.t(`helpers.coreBlockStatus.noBlocks`);let t=e.filter(e=>fl(e).tone===`error`).length,n=e.filter(e=>fl(e).tone===`ok`).length,r=[J.t(`helpers.coreBlockStatus.blocks`,{count:e.length})];return n>0&&r.push(J.t(`helpers.coreBlockStatus.runningCount`,{count:n})),t>0&&r.push(J.t(`helpers.coreBlockStatus.notRunningCount`,{count:t})),r.join(` · `)}var _l=3e4;function vl({block:t,logsOpen:n,unreadable:r}){let i=S(),{t:a}=Y(),s=fl(t),c=Ct(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(G,{variant:pl(s.tone),children:s.label}),c!==null&&o(`span`,{className:`text-xs text-foreground-subtle`,children:a(`common.edited`,{when:c})})]}),(s.tone===`error`||s.tone===`pending`)&&o(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:s.detail}),r!==null&&o(`p`,{className:`mt-0.5 text-xs text-warning`,children:a(`automation.editor.listUnreadable`,{reason:r})}),n&&e(`div`,{className:`mt-2 rounded border border-border`,children:[o(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:o(bn,{i18nKey:`common.logsOf`,values:{id:U(t.id)},components:{code:o(`code`,{})}})}),o(kt,{addonId:U(t.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}var yl=2;function bl(e){let t=[];if(ce(e.when,e=>{R(e)&&t.push(fi(e.kind))}),t.length===0)return V(e.when)===0?``:J.t(`automation.whenTree.stateOnly`);let n=[...new Set(t)],r=n.slice(0,yl).join(`, `),i=n.length-yl;return i>0?`${r} +${i}`:r}function xl({recipe:e}){let{t}=Y();if(e===null)return o(`span`,{className:`text-foreground-subtle`,children:`-`});let n=bl(e);return n===``?o(`span`,{className:`text-foreground-subtle`,children:t(`automation.automationList.noTrigger`,`No trigger`)}):o(`span`,{children:n})}function Sl({blockId:t}){let{t:n}=Y(),r=It({blockId:t},{refetchInterval:_l});if(r.data===void 0)return r.error===null||r.error===void 0?o(Nt,{className:`h-4 w-16`}):o(`span`,{className:`text-foreground-subtle`,children:n(`automation.automationList.lastRunUnknown`,`Unknown`)});let i=r.data.traces.findLast(e=>!e.outcome.startsWith(`skipped-`));if(i===void 0)return o(`span`,{className:`text-foreground-subtle`,children:n(`automation.automationList.neverRan`,`Never ran`)});let a=i.outcome===`failed`||i.outcome===`aborted`;return e(`span`,{className:`inline-flex items-center gap-2`,children:[An(i.lastAt),a&&o(G,{variant:`danger`,children:n(`automation.automationList.lastRunFailed`,`Failed`)})]})}function Cl({block:e,disabled:t,onToggle:n}){let{t:r}=Y();return o(`span`,{className:`inline-flex`,onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:o(cn,{checked:e.enabled,disabled:t,onCheckedChange:n,"aria-label":e.enabled?r(`automation.automationList.disableNamed`,`Disable {{name}}`,{name:e.name}):r(`automation.automationList.enableNamed`,`Enable {{name}}`,{name:e.name})})})}function wl({unreadable:e,onEdit:t,onToggleLogs:n,onDelete:r}){let{t:i}=Y();return o(`span`,{className:`inline-flex justify-end`,onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:o(Vt,{items:[{id:`edit`,label:i(`common.edit`,`Edit`),icon:N,disabled:e!==null,description:e===null?void 0:i(`automation.automationList.thisBlockCannotBeOpened`,`This block cannot be opened visually`),onClick:t},{id:`run`,label:i(`automation.automationList.runActions`,`Run actions`),icon:g,disabled:!0,description:i(`automation.automationList.runNotAvailable`,`Not available yet`),onClick:()=>void 0},{id:`logs`,label:i(`automation.automationList.logs`,`Logs`),icon:w,onClick:n},{id:`delete`,label:i(`common.delete`,`Delete`),icon:k,danger:!0,separatorBefore:!0,onClick:r}]})})}function Tl({onCreate:t}){let{t:n}=Y();return o(Xt,{icon:I,title:n(`automation.automationList.noAutomationsYet`,`No automations yet.`),action:e(W,{onClick:t,"data-testid":`automation-empty-new`,children:[o(D,{className:`h-4 w-4`}),` `,n(`automation.automationList.newAutomation`,`New automation`)]})})}u();var El=[`coreBlocks`,`list`],Dl=5e3;function Ol(e){return e instanceof Error?e.message:String(e)}function kl({onOpenScripts:t,createRequested:n=!1,onCreateConsumed:i}){let{t:a}=Y(),u=M(),{state:d,openNew:f,openEdit:m,close:h}=Rt({editKey:`block`,newKey:`new`}),g=j(),[_,v]=c(null),y=d.mode!==`closed`;s(()=>{n&&(f(),i?.())},[n,i,f]);let b=l({queryKey:El,refetchInterval:Dl,queryFn:async()=>(await u.trpcClient.coreBlocks.list.query({})).blocks}),x=()=>{b.refetch()},S=e=>{h(),x(),Cn({title:a(`build.automationsTab.saved`,`Automation saved`),message:e.name,severity:`info`})},C=p({mutationFn:e=>u.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>S(e.block)}),w=p({mutationFn:e=>u.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>S(e.block)}),T=p({mutationFn:e=>u.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:x}),E=p({mutationFn:e=>u.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:x}),D=p({mutationFn:e=>u.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:dr(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:e=>{h(),x(),t(e.block.id)}}),O=b.data,k=hl((O??[]).filter(e=>cr(e.code))),A=O!==void 0&&k.length===0,N=d.mode===`edit`?k.find(e=>e.id===d.id)??null:null,P=d.mode===`edit`&&O!==void 0&&N===null;s(()=>{P&&h()},[P,h]);let F=N===null?null:ur(N.code),L=C.error===null?w.error===null?D.error===null?null:Ol(D.error):Ol(w.error):Ol(C.error),R=r(()=>[{key:`name`,header:a(`build.automationsTab.automation`,`Automation`),nowrap:!1,render:e=>{let t=ur(e.code);return o(vl,{block:e,logsOpen:_===e.id,unreadable:t.ok?null:t.reason})},sortValue:e=>e.name},{key:`trigger`,header:a(`build.automationsTab.trigger`,`Trigger`),render:e=>{let t=ur(e.code);return o(xl,{recipe:t.ok?t.recipe:null})},notSortableReason:a(`build.automationsTab.triggerNotSortable`,`Read from the recipe`)},{key:`lastRun`,header:a(`build.automationsTab.lastRun`,`Last run`),render:e=>o(Sl,{blockId:e.id}),notSortableReason:a(`build.automationsTab.lastRunNotSortable`,`Read per automation`)},{key:`enabled`,header:a(`build.automationsTab.enabled`,`Enabled`),render:e=>o(Cl,{block:e,disabled:E.isPending,onToggle:t=>E.mutate({blockId:e.id,enabled:t})}),sortValue:e=>+!!e.enabled},{key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,render:e=>{let t=ur(e.code);return o(wl,{unreadable:t.ok?null:t.reason,onEdit:()=>m(e.id),onToggleLogs:()=>v(_===e.id?null:e.id),onDelete:()=>{g({title:a(`automation.automationList.deleteThisAutomation`,`Delete this automation?`),message:a(`automation.automationList.deleteMessage`,`{{name}} will be deleted. This cannot be undone.`,{name:e.name}),confirmLabel:a(`common.delete`,`Delete`),variant:`danger`}).then(t=>{t&&T.mutate(e.id)})}})}}],[g,_,m,T,E,a]);return y?d.mode===`edit`&&N===null?o(Nt,{className:`h-24 w-full`}):e(`div`,{className:`space-y-3`,"data-testid":`automation-editor-panel`,children:[e(`h3`,{className:`flex items-center gap-2 text-sm font-semibold`,children:[o(I,{className:`h-4 w-4 text-foreground-muted`}),N===null?a(`build.automationsTab.newAutomation`,`New automation`):a(`build.automationsTab.edit`,`Edit {{name}}`,{name:N.name})]}),o(ll,{existing:N,initialRecipe:F!==null&&F.ok?F.recipe:hi,saving:C.isPending||w.isPending,saveError:L,ejecting:D.isPending,onSave:e=>{N===null?C.mutate(e):w.mutate({blockId:N.id,block:e})},onEject:()=>{N!==null&&D.mutate(N)},onCancel:()=>{C.reset(),w.reset(),D.reset(),h()}},N?.id??`new`),T.error!=null&&o(K,{message:Ol(T.error)})]}):e(`div`,{className:`space-y-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:O===void 0?``:gl(k)}),b.error!=null&&o(K,{title:a(`build.automationsTab.couldNotReadTheAutomations`,`Could not read the automations`),message:Ol(b.error),onRetry:x}),A?o(Tl,{onCreate:f}):o(At,{columns:R,rows:k,rowKey:e=>e.id,pageSize:25,maxBodyHeight:Pt,emptyMessage:O===void 0?a(`build.automationsTab.loadingAutomations`,`Loading automations…`):a(`build.automationsTab.noAutomationsYet`,`No automations yet.`),onRowClick:e=>m(e.id)}),T.error!=null&&o(K,{message:Ol(T.error)}),E.error!=null&&o(K,{message:Ol(E.error)})]})}var Al={kind:`all`,children:[]};function jl({value:t,devices:n,label:r,onChange:i}){let{t:a}=Y(),s=t===void 0?null:{when:t,actions:[]};return e(`div`,{className:`space-y-2`,children:[o(cn,{checked:t!==void 0,label:r,"aria-label":r,onCheckedChange:e=>i(e?Al:void 0)}),s!==null&&e(m,{children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:a(`schedulers.activeWhen.hint`,`Only states count here, such as "someone is home". While they are false, nothing runs and holds pause.`)}),o(Ks,{recipe:s,devices:n,onChange:e=>i(e.when)})]})]})}var Ml=[`sunrise`,`sunset`,`dawn`,`dusk`],Nl=6e4;function Pl(e){return e.kind===`cap`||e.kind===`wait`}function Fl(e,t){let n={id:e.id,at:e.at,mode:t,steps:t===`release`?[]:e.steps,...e.conditions===void 0?{}:{conditions:e.conditions}};return t===`hold`?{...n,...e.override===void 0?{}:{override:e.override},...e.maxHoldAttempts===void 0?{}:{maxHoldAttempts:e.maxHoldAttempts}}:n}function Il({point:t,devices:n,site:r,localDate:i,issues:a,onChange:s,onRemove:c}){let{t:l}=Y(),u=t.at,d=u.kind===`sun`?Jo(u,r,i):null,f=Yo(u,r,i),p=t.override??{mode:`respect`},h=e=>s({...t,at:e});return e(`div`,{className:`space-y-3`,"data-testid":`point-editor`,children:[e(`div`,{className:`flex flex-wrap items-end gap-3`,children:[e(`label`,{className:`space-y-1 text-xs text-foreground-muted`,children:[o(`span`,{children:l(`schedulers.point.kind`,`Point type`)}),o(F,{"aria-label":l(`schedulers.point.kind`,`Point type`),value:t.mode,options:[{value:`edge`,label:l(`schedulers.point.edge`,`Edge: run once`)},{value:`hold`,label:l(`schedulers.point.hold`,`Hold: keep true`)},{value:`release`,label:l(`schedulers.point.release`,`Release: end the hold`)}],onChange:e=>{let n=e.target.value;(n===`edge`||n===`hold`||n===`release`)&&s(Fl(t,n))}})]}),e(`label`,{className:`space-y-1 text-xs text-foreground-muted`,children:[o(`span`,{children:l(`schedulers.point.when`,`When`)}),o(F,{"aria-label":l(`schedulers.point.when`,`When`),value:u.kind===`sun`?`sun`:`clock`,options:[{value:`clock`,label:l(`schedulers.point.clock`,`At a time`)},{value:`sun`,label:l(`schedulers.point.sun`,`At a sun event`)}],onChange:e=>{e.target.value===`sun`?h({kind:`sun`,event:`sunset`,offsetMin:0}):h({kind:`clock`,hh:12,mm:0})}})]}),u.kind===`clock`&&e(`label`,{className:`space-y-1 text-xs text-foreground-muted`,children:[o(`span`,{children:l(`schedulers.point.time`,`Time`)}),o(q,{type:`time`,"aria-label":l(`schedulers.point.time`,`Time`),value:Qo(u.hh,u.mm),onChange:e=>{let t=Zo(e.target.value);t!==null&&h(t)}})]}),u.kind===`sun`&&e(m,{children:[e(`label`,{className:`space-y-1 text-xs text-foreground-muted`,children:[o(`span`,{children:l(`schedulers.point.sunEvent`,`Sun event`)}),o(F,{"aria-label":l(`schedulers.point.sunEvent`,`Sun event`),value:u.event,options:Ml.map(e=>({value:e,label:l(`schedulers.sun.${e}`,e)})),onChange:e=>{let t=Ml.find(t=>t===e.target.value);t!==void 0&&h({...u,event:t})}})]}),e(`label`,{className:`space-y-1 text-xs text-foreground-muted`,children:[o(`span`,{children:l(`schedulers.point.offset`,`Offset (minutes, negative = before)`)}),o(X,{"aria-label":l(`schedulers.point.offset`,`Offset (minutes, negative = before)`),className:`w-28`,value:u.offsetMin,onValue:e=>{e!==null&&h({...u,offsetMin:Math.round(e)})}})]}),o(`p`,{className:`pb-2 text-xs text-foreground-muted`,"data-testid":`sun-computed`,children:d===null||f===null?l(`schedulers.point.sunUnknown`,`No time today: the site location is not set.`):l(`schedulers.point.sunComputed`,`Today at {{time}} ({{zone}})`,{time:$o(d),zone:r.timeZone})})]}),e(W,{variant:`ghost`,className:`ml-auto`,onClick:c,"aria-label":l(`schedulers.point.remove`,`Remove point`),children:[o(k,{className:`h-4 w-4`}),` `,l(`schedulers.point.remove`,`Remove point`)]})]}),t.mode!==`release`&&o(Sc,{actions:t.steps,devices:n,allowedKinds:[`cap`,`wait`],onChange:e=>s({...t,steps:e.filter(Pl)})}),t.mode===`release`&&o(`p`,{className:`text-xs text-foreground-subtle`,children:l(`schedulers.point.releaseHint`,`A release ends the running hold without doing anything to the devices.`)}),t.mode===`hold`&&e(`div`,{className:`flex flex-wrap items-end gap-3`,children:[e(`label`,{className:`space-y-1 text-xs text-foreground-muted`,children:[o(`span`,{children:l(`schedulers.point.override`,`If someone changes it by hand`)}),o(F,{"aria-label":l(`schedulers.point.override`,`If someone changes it by hand`),value:p.mode,options:[{value:`respect`,label:l(`schedulers.point.respect`,`Leave it alone`)},{value:`reassert`,label:l(`schedulers.point.reassert`,`Put the hold back after a while`)}],onChange:e=>s({...t,override:e.target.value===`reassert`?{mode:`reassert`,graceMs:10*Nl}:{mode:`respect`}})})]}),p.mode===`reassert`&&e(`label`,{className:`space-y-1 text-xs text-foreground-muted`,children:[o(`span`,{children:l(`schedulers.point.grace`,`Wait (minutes)`)}),o(X,{"aria-label":l(`schedulers.point.grace`,`Wait (minutes)`),className:`w-24`,value:p.graceMs/Nl,onValue:e=>{e!==null&&s({...t,override:{mode:`reassert`,graceMs:Math.max(0,Math.round(e*Nl))}})}})]})]}),a.length>0&&o(`ul`,{className:`space-y-1 rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:a.map(e=>o(`li`,{children:e.message},`${e.path}:${e.message}`))})]})}u();var Ll=5e3,Rl=600,zl=6e4,Bl={timeZone:`UTC`,location:null};function Vl(e){return e instanceof Error?e.message:String(e)}function Hl(e){if(e===null)return Vo();let{id:t,createdAt:n,updatedAt:r,...i}=e;return i}function Ul(e,t){let[n,r]=c(e);return s(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n}function Wl(e,t){return t(`schedulers.day.${e}`,e)}function Gl({entry:t,onClose:n,onSaved:i}){let{t:a}=Y(),s=f(),l=j(),u=Kn(),d=en(),p=d.data??Bl,[m,h]=c(()=>Hl(t)),[g,_]=c(()=>m.profiles[0]?.id??``),[v,y]=c(null),[b,x]=c(null),S=()=>{s.invalidateQueries({queryKey:[[`schedulers`]]})},C=$t({onSuccess:e=>{S(),i(e.scheduler.id)}}),w=at({onSuccess:S}),E=et({onSuccess:()=>{S(),n()}}),A=yt({schedulerId:t?.id??`none`},{enabled:t!==null,refetchInterval:Ll}),M=r(()=>ts(m,p),[m,p]),N=m.profiles.some(e=>e.points.some(e=>e.mode===`hold`)),P=Ul(M.ok?M.input:null,Rl),F=xt(P===null?{scheduler:m}:t===null?{scheduler:P}:{scheduler:P,schedulerId:t.id},{enabled:P!==null&&N&&d.data!==void 0}),I=m.profiles.find(e=>e.id===g)??m.profiles[0],L=I===void 0?-1:m.profiles.indexOf(I),R=qo(p),z=I?.points.find(e=>e.id===v)??null,B=I===void 0||z===null?-1:I.points.indexOf(z),V=M.ok?[]:M.issues,ee=e=>V.filter(t=>t.path===e||t.path.startsWith(`${e}.`)),H=e=>h({...m,profiles:m.profiles.map((t,n)=>n===L?e:t)}),te=e=>{I!==void 0&&H({...I,points:I.points.map(t=>t.id===e.id?e:t)})},ne=r(()=>I===void 0?[]:I.points.flatMap(e=>{let t=Jo(e.at,p,R);if(t===null)return[];let n=e.at.kind===`sun`?`${a(`schedulers.sun.${e.at.event}`,e.at.event)} ${e.at.offsetMin>=0?`+`:``}${String(e.at.offsetMin)} (${$o(t)})`:Qo(e.at.hh,e.at.mm);return[{id:e.id,minute:t,label:n,tone:e.mode===`hold`?`success`:e.mode===`release`?`neutral`:`primary`,draggable:e.at.kind===`clock`||e.at.kind===`sun`&&Yo(e.at,p,R)!==null}]}),[I,p,R,a]),re=r(()=>I===void 0?[]:es(I.points,p,R),[I,p,R]),ie=(e,t)=>{let n=I?.points.find(t=>t.id===e);n!==void 0&&te({...n,at:Xo(n.at,t,Yo(n.at,p,R))})},U=e=>{if(I===void 0)return;let t=Wo(`point`,m.profiles.flatMap(e=>e.points.map(e=>e.id)));H({...I,points:[...I.points,Uo(e,t,720)]}),y(t)},ae=()=>{let e=Wo(`profile`,m.profiles.map(e=>e.id));h({...m,profiles:[...m.profiles,Ho(e,a(`schedulers.profile.newName`,`New profile`))]}),_(e),y(null)},oe=C.isPending||w.isPending,se=C.error??w.error??E.error;return e(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]`,"data-testid":`scheduler-editor`,children:[e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(O,{className:`h-4 w-4 text-foreground-muted`}),o(q,{"aria-label":a(`schedulers.editor.name`,`Name`),className:`max-w-xs flex-1`,value:m.name,placeholder:a(`schedulers.editor.namePlaceholder`,`What this scheduler does`),onChange:e=>h({...m,name:e.target.value})})]}),e(Mt,{headingId:`scheduler-settings`,title:a(`schedulers.editor.settings`,`Settings`),children:[e(`div`,{className:`divide-y divide-border px-3`,children:[o(lt,{label:a(`schedulers.editor.enabled`,`Enabled`),children:o(cn,{checked:m.enabled,"aria-label":a(`schedulers.editor.enabled`,`Enabled`),onCheckedChange:e=>h({...m,enabled:e})})}),o(lt,{label:a(`schedulers.editor.priority`,`Priority (higher wins a conflict)`),children:o(X,{"aria-label":a(`schedulers.editor.priority`,`Priority (higher wins a conflict)`),className:`w-24`,value:m.priority,onValue:e=>{e!==null&&h({...m,priority:Math.round(e)})}})}),o(lt,{label:a(`schedulers.editor.maxLate`,`Run a missed point up to (minutes late)`),children:o(X,{"aria-label":a(`schedulers.editor.maxLate`,`Run a missed point up to (minutes late)`),className:`w-24`,value:m.maxLateMs/zl,onValue:e=>{e!==null&&h({...m,maxLateMs:Math.round(e*zl)})}})})]}),e(`div`,{className:`p-3`,children:[o(jl,{value:m.activeWhen,devices:u,label:a(`schedulers.editor.activeWhen`,`Only when a condition holds`),onChange:e=>{let{activeWhen:t,...n}=m;h(e===void 0?n:{...n,activeWhen:e})}}),ee(`activeWhen`).map(e=>o(`p`,{className:`mt-1 text-xs text-warning`,children:e.message},e.message))]})]}),o(Mt,{headingId:`scheduler-profiles`,title:a(`schedulers.editor.profiles`,`Profiles`),actions:e(W,{variant:`outline`,size:`sm`,onClick:ae,children:[o(D,{className:`h-4 w-4`}),` `,a(`schedulers.profile.add`,`Add profile`)]}),children:e(`div`,{className:`space-y-3 p-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:a(`schedulers.profile.hint`,`Each day, the first profile in this order whose days and condition hold is the one that runs.`)}),I!==void 0&&e(Ht,{value:I.id,onValueChange:e=>{_(e),y(null)},appearance:`pills`,children:[o(pn,{children:m.profiles.map(e=>o(Gt,{value:e.id,children:e.name},e.id))}),e(on,{value:I.id,className:`space-y-3 pt-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(q,{"aria-label":a(`schedulers.profile.name`,`Profile name`),className:`max-w-xs`,value:I.name,onChange:e=>H({...I,name:e.target.value})}),o(cn,{checked:I.enabled,label:a(`schedulers.profile.enabled`,`Enabled`),onCheckedChange:e=>H({...I,enabled:e})}),m.profiles.length>1&&e(W,{variant:`ghost`,size:`sm`,onClick:()=>{h({...m,profiles:m.profiles.filter(e=>e.id!==I.id)}),_(``),y(null)},children:[o(k,{className:`h-4 w-4`}),` `,a(`schedulers.profile.remove`,`Remove profile`)]})]}),o(`div`,{className:`flex flex-wrap gap-1`,role:`group`,"aria-label":a(`schedulers.profile.days`,`Days`),children:Ro.map(e=>{let t=I.days.includes(e);return o(W,{size:`sm`,variant:t?`primary`:`outline`,"aria-pressed":t,onClick:()=>H({...I,days:t?I.days.filter(t=>t!==e):Ro.filter(t=>t===e||I.days.includes(t))}),children:Wl(e,a)},e)})}),ee(`profiles.${String(L)}.days`).map(e=>o(`p`,{className:`text-xs text-warning`,children:a(`schedulers.profile.daysNeeded`,`Pick at least one day.`)},e.message)),o(jl,{value:I.activeWhen,devices:u,label:a(`schedulers.profile.activeWhen`,`This profile only when a condition holds`),onChange:e=>{let{activeWhen:t,...n}=I;H(e===void 0?n:{...n,activeWhen:e})}}),o(Wt,{ariaLabel:a(`schedulers.timeline.label`,`Day timeline`),markers:ne,bands:re,selectedId:v,onSelect:y,onMove:ie}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(W,{variant:`outline`,size:`sm`,onClick:()=>U(`edge`),children:[o(D,{className:`h-4 w-4`}),` `,a(`schedulers.point.addEdge`,`Edge`)]}),e(W,{variant:`outline`,size:`sm`,onClick:()=>U(`hold`),children:[o(D,{className:`h-4 w-4`}),` `,a(`schedulers.point.addHold`,`Hold`)]}),e(W,{variant:`outline`,size:`sm`,onClick:()=>U(`release`),children:[o(D,{className:`h-4 w-4`}),` `,a(`schedulers.point.addRelease`,`Release`)]}),o(G,{variant:`neutral`,children:p.timeZone})]}),I.points.length===0&&o(`p`,{className:`text-xs text-foreground-subtle`,children:a(`schedulers.timeline.empty`,`Add a point to place something on the day.`)}),z!==null&&o(Il,{point:z,devices:u,site:p,localDate:R,issues:ee(`profiles.${String(L)}.points.${String(B)}`),onChange:te,onRemove:()=>{H({...I,points:I.points.filter(e=>e.id!==z.id)}),y(null)}},z.id)]})]})]})}),F.data!==void 0&&F.data.conflicts.length>0&&o(`ul`,{className:`space-y-1 rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:F.data.conflicts.map(e=>o(`li`,{children:a(`schedulers.conflict.message`,`{{other}} wants device {{device}} in another state from {{from}} to {{to}} ({{winner}}).`,{other:e.other.schedulerName,device:e.deviceId,from:$o(e.fromMinute),to:$o(e.toMinute),winner:e.winner===`mine`?a(`schedulers.conflict.mine`,`this one wins`):e.winner===`other`?a(`schedulers.conflict.other`,`the other one wins`):a(`schedulers.conflict.tie`,`the one that started first wins`)})},`${e.other.schedulerId}:${e.other.pointId}:${e.mine.pointId}:${String(e.deviceId)}`))}),!M.ok&&m.name!==``&&V.length>0&&z===null&&o(`ul`,{className:`space-y-1 rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:V.map(e=>o(`li`,{children:e.message},`${e.path}:${e.message}`))}),se!==null&&o(K,{message:Vl(se)}),e(`div`,{className:`flex flex-wrap gap-2`,children:[e(W,{onClick:()=>{M.ok&&(t===null?C.mutate({scheduler:M.input}):w.mutate({schedulerId:t.id,scheduler:M.input}))},disabled:oe||!M.ok||d.data===void 0,children:[oe&&o(T,{className:`h-4 w-4 animate-spin`}),` `,a(`common.save`,`Save`)]}),t!==null&&e(W,{variant:`ghost`,disabled:E.isPending,onClick:()=>{l({title:a(`schedulers.editor.deleteTitle`,`Delete this scheduler?`),message:a(`schedulers.editor.deleteMessage`,`{{name}} will be deleted and any hold it keeps will stop.`,{name:t.name}),confirmLabel:a(`common.delete`,`Delete`),variant:`danger`}).then(e=>{e&&E.mutate({schedulerId:t.id})})},children:[o(k,{className:`h-4 w-4`}),` `,a(`common.delete`,`Delete`)]}),o(W,{variant:`ghost`,onClick:n,children:a(`common.close`,`Close`)})]})]}),o(`div`,{className:`order-first lg:order-last`,children:o(Br,{traces:t===null?[]:A.data?.traces,selectedId:b,onSelect:x})})]})}u();var Kl=5e3;function ql(e){return e instanceof Error?e.message:String(e)}function Jl({createRequested:t=!1,onCreateConsumed:n}){let{t:i}=Y(),a=f(),{state:c,openNew:l,openEdit:u,close:d}=Rt({editKey:`scheduler`,newKey:`new`}),p=bt({},{refetchInterval:Kl}),m=Qt({},{refetchInterval:Kl}),h=wt({onSuccess:()=>void a.invalidateQueries({queryKey:[[`schedulers`]]})});s(()=>{t&&(l(),n?.())},[t,n,l]);let g=p.data??[],_=c.mode===`edit`?g.find(e=>e.id===c.id)??null:null,v=e=>{if(!e.enabled)return{variant:`neutral`,label:i(`schedulers.status.off`,`Off`)};let t=m.data?.find(t=>t.schedulerId===e.id);return t===void 0?{variant:`neutral`,label:`-`}:t.hold===null?{variant:`neutral`,label:i(`schedulers.status.idle`,`Idle`)}:t.hold.suspendedInactive?{variant:`warning`,label:i(`schedulers.status.paused`,`Paused`)}:t.hold.targets.some(e=>e.status===`gave-up`)?{variant:`danger`,label:i(`schedulers.status.gaveUp`,`Gave up`)}:{variant:`success`,label:i(`schedulers.status.holding`,`Holding`)}},y=r(()=>[{key:`name`,header:i(`schedulers.list.name`,`Name`),render:e=>o(`span`,{className:`font-medium`,children:e.name}),sortValue:e=>e.name},{key:`enabled`,header:i(`schedulers.list.enabled`,`Enabled`),render:e=>o(`span`,{onClick:e=>e.stopPropagation(),children:o(cn,{checked:e.enabled,disabled:h.isPending,"aria-label":i(`schedulers.list.enabledAria`,`Enable {{name}}`,{name:e.name}),onCheckedChange:t=>h.mutate({schedulerId:e.id,enabled:t})})}),sortValue:e=>Number(e.enabled)},{key:`profiles`,header:i(`schedulers.list.profiles`,`Profiles`),render:e=>String(e.profiles.length),sortValue:e=>e.profiles.length},{key:`priority`,header:i(`schedulers.list.priority`,`Priority`),render:e=>String(e.priority),sortValue:e=>e.priority},{key:`status`,header:i(`schedulers.list.status`,`Now`),render:e=>{let t=v(e);return o(G,{variant:t.variant,children:t.label})},notSortableReason:i(`schedulers.list.statusNotSortable`,`Derived from the live hold`)},{key:`updated`,header:i(`schedulers.list.updated`,`Updated`),render:e=>An(e.updatedAt),sortValue:e=>e.updatedAt}],[h,m.data,i]);return c.mode===`closed`?e(`div`,{className:`space-y-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:i(`schedulers.list.hint`,`A scheduler does things over the day: run something at a time or at sunset, or keep a device in a state for a stretch of time.`)}),h.error!=null&&o(K,{message:ql(h.error)}),p.data===void 0?p.error==null?o(Nt,{className:`h-24 w-full`}):o(K,{title:i(`schedulers.list.couldNotRead`,`Could not read the schedulers`),message:ql(p.error),onRetry:()=>void p.refetch()}):g.length===0?o(Xt,{icon:O,title:i(`schedulers.list.emptyTitle`,`No schedulers yet`),description:i(`schedulers.list.emptyDescription`,`A scheduler turns the garden lights on at sunset and off at 23:00, every day or only on some days.`),action:e(W,{onClick:l,children:[o(D,{className:`h-4 w-4`}),` `,i(`schedulers.list.new`,`New scheduler`)]})}):o(At,{columns:y,rows:g,rowKey:e=>e.id,pageSize:25,maxBodyHeight:Pt,emptyMessage:i(`schedulers.list.emptyTitle`,`No schedulers yet`),onRowClick:e=>u(e.id)})]}):o(Gl,{entry:_,onClose:d,onSaved:u},_?.id??`new`)}async function Yl(e,t){let n=`${pe}${e}`;return(await t())?.find(e=>e.stableId===n)?.id??null}var Xl=10,Zl=400;async function Ql(e,t,n=Zl){for(let r=0;r<Xl;r+=1){let r=await Yl(e,t);if(r!==null)return r;await new Promise(e=>setTimeout(e,n))}return null}var $l=`media-player`;function eu(e){return e===Pe.MediaPlayer?`media-source`:`none`}function tu(e){return e===Pe.MediaPlayer?{fieldChoice:`operator`,purpose:`member`,multiple:!1,max:1,deviceTypes:[Pe.MediaPlayer],accept:[{cap:$l,fieldPath:`state`,valueKind:`state`}],history:{required:!1,minRetentionMs:null},mustBindCaps:[$l],exclude:[]}:null}function nu(e){return e===null||e.cap!==`media-player`?[]:[{kind:`fields`,cap:$l,fields:{},commands:Object.fromEntries(Object.keys(Ce()).map(t=>[t,{kind:`forward`,source:e.source,cap:$l,method:t}]))}]}function ru(e,t){let n=e===Pe.MediaPlayer?nu(t):[];return{target:{kind:`new`,type:e},features:n}}u();function iu({onTitle:t}){let{t:n}=Y(),r=S(),i=Sn(),a=Qn(),l=Ut(),u=jt({addonId:`composer`}),[d,f]=c(Pe.Sensor),[p,m]=c(``),[h,g]=c([]),[_,v]=c(null),y=h[0]??null,b=tu(d),x=ru(d,y);s(()=>{t(n(`helper.newDevice`))},[t,n]);let C=async()=>{v(null);try{let e=p.trim(),{block:t}=await a.mutateAsync({block:{...e===``?{}:{name:e},enabled:!0,composition:x}}),r=await Ql(t.id,async()=>(await u.refetch()).data??u.data);if(r===null){v(n(`helper.devicePending`));return}e!==``&&await l.mutateAsync({deviceId:r,name:e}),i(En(r),{replace:!0})}catch(e){v(e instanceof Error?e.message:String(e))}};return e(`div`,{className:`flex flex-col gap-3`,"data-testid":`device-create-form`,children:[e(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[n(`compositionEditor.targetType`),o(F,{value:d,onChange:e=>{let t=Object.values(Pe).find(t=>t===e.target.value);t!==void 0&&(f(t),g([]))},options:Object.values(Pe).map(e=>({value:e,label:Qe(e,r).label}))})]}),e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[n(`compositionEditor.name`),o(q,{"aria-label":n(`compositionEditor.name`),value:p,onChange:e=>m(e.target.value)})]})]}),b!==null&&e(`div`,{className:`flex flex-col gap-1`,"data-testid":`device-create-source`,children:[o(`p`,{className:`text-[11px] text-foreground-muted`,children:n(`helper.deviceSource.${eu(d)}`)}),o(Pn,{kind:`members`,request:b,enabled:!0,members:h,onMembersChange:g,onRefuse:()=>void 0})]}),_!==null&&o(`p`,{role:`alert`,className:`text-xs text-danger`,children:_}),o(W,{disabled:a.isPending,onClick:()=>void C(),children:n(`compositionEditor.save`)})]})}u();function au({preset:t,saving:n,onSave:i,onBack:a}){let{t:s,i18n:l}=Y(),u=Bn(!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=>[Ue({addonId:e.addonId,stableId:e.stableId}),e.name])):new Map,[u]),S=r(()=>new Set(Object.values(d).flatMap(e=>e===void 0?[]:[Ue(e)])),[d]),C=r(()=>u.kind===`known`?{kind:`known`,value:jn(u.value,S)}:u,[u,S]),w=Hn(t,d),T=u.kind===`known`?Un(u.value,w,!1):null,E=t.build(d),D=Ln(t,d),O=(e,t)=>{v([]),f(n=>({...n,[e]:t}))},k=e=>x.get(Ue(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(q,{"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:[Rn(t.expectedCap,l.language),t.optionalGroup===void 0?``:` · ${s(`preset.optional`)}`]})]}),e(`div`,{className:`flex flex-wrap gap-1`,children:[o(W,{variant:`outline`,size:`sm`,onClick:()=>g(t),children:n===void 0?s(`preset.choose`):k(n)}),n!==void 0&&t.optionalGroup!==void 0&&o(W,{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:Rn(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(Vn,{lines:_,testId:`preset-refusals`}),e(`div`,{className:`mt-auto flex flex-wrap gap-2`,children:[o(W,{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(W,{variant:`ghost`,onClick:a,children:s(`preset.back`)})]}),o(Fn,{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 ou=`preset`;function su({mode:e,onTitle:t}){return o(e===`helper`?cu:iu,{onTitle:t})}function cu({onTitle:e}){let{t}=Y(),r=Sn(),i=Qn(),a=Ut(),l=jt({addonId:`composer`}),[u,d]=c(null),[f,p]=c(!1),[m,h]=xn(),g=Nn(m.get(ou)),_=g===null?lu(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(ou):n.set(ou,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 Ql(o.id,async()=>(await l.refetch()).data??l.data);return s===null?{kind:`refused`,lines:In(t(`helper.devicePending`))}:(n!==``&&await a.mutateAsync({deviceId:s,name:n}),r(En(s),{replace:!0}),{kind:`saved`,deviceId:s})}catch(e){return{kind:`refused`,lines:In(e instanceof Error?e.message:String(e))}}},b=n(null);return f?o(iu,{onTitle:e}):g===null?o(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3`,"data-testid":`composition-create-form`,children:o(zn,{fillHeight:!0,onDevice:()=>p(!0),onPreset:v,purpose:`create`,initial:null,start:`template`,saving:i.isPending,onDraftChange:d,onSave:async(e,n)=>{let o=null,s=await Wn(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 Ql(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(Tn(f),{replace:!0})}),c=o;return s.length>0||c===null?{kind:`refused`,lines:uu(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(au,{preset:g,saving:i.isPending,onSave:y,onBack:()=>v(null)})})}function lu(e,t){if(e===null)return t(`helper.newComposed`);if(e.kind===`statistic`)return t(`helper.newTitle.statistic`);if(e.kind===`integral`)return t(`helper.newTitle.integral`);if(e.kind===`arithmetic`)return t(`helper.newTitle.${e.op}`);if(e.kind===`threshold`||e.kind===`expression`||e.kind===`derivative`)return t(`helper.newTitle.${e.kind}`);let n=je(e.templateId);return t(n===null?`helper.newComposed`:`helper.newTitle.${n.id}`)}function uu(e,t){return e.length>0?e:In(t(`helper.devicePending`))}function du(e){let t=e.helper;if(t===void 0)return{section:`advanced`,kind:null};switch(t.kind){case`group`:return{section:`group`,kind:t.templateId};case`arithmetic`:return{section:`calculation`,kind:t.op};case`expression`:return{section:`advanced`,kind:`expression`};default:return{section:`calculation`,kind:t.kind}}}function fu(e){return{state:`answered`,byRef:new Map(e.map(e=>[Ue(e),e]))}}function pu(e,t){if(e.state!==`unanswered`)return e.byRef.get(Ue(t))??null}function mu(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function hu(e){return he(e).map(e=>e.source)}function gu(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(...hu(t));for(let t of Object.values(e.items??{}))for(let e of Object.values(t.fields))n.push(...hu(e))}let r=new Set;return n.filter(e=>{let t=Ue(e);return r.has(t)?!1:(r.add(t),!0)})}function _u(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:J.t(`helpers.compositionRows.running`),reason:null};let r=[...t.length>0?[J.t(`helpers.compositionRows.fieldsUnavailable`,{count:t.length})]:[],...n.length>0?[J.t(`helpers.compositionRows.fieldsStale`,{count:n.length})]:[]].join(`, `),i=t[0]??n[0],a=i===void 0?``:` — ${i.cap}.${i.path}: ${i.reason??J.t(`helpers.compositionRows.noReason`)}`;return{tone:`pending`,label:J.t(`helpers.compositionRows.running`),reason:`${r}${a}`}}function vu(e,t){let n=e.reason??t??null;switch(e.status){case`running`:return _u(e);case`degraded`:return{tone:`pending`,label:J.t(`helpers.compositionRows.degraded`),reason:n??J.t(`helpers.compositionRows.degradedReason`)};case`starting`:return{tone:`pending`,label:J.t(`helpers.compositionRows.starting`),reason:n};case`failed`:return{tone:`error`,label:J.t(`helpers.compositionRows.failed`),reason:n??J.t(`helpers.compositionRows.failedReason`)};default:return{tone:`error`,label:J.t(`helpers.compositionRows.notRunning`),reason:n??J.t(`helpers.compositionRows.notRunningReason`)}}}function yu(e){let{block:t,state:n}=e;if(!t.enabled)return{tone:`idle`,label:J.t(`helpers.compositionRows.off`),reason:null};if(n.kind===`unreachable`)return{tone:`pending`,label:J.t(`helpers.compositionRows.unknown`),reason:J.t(`helpers.compositionRows.unreachable`,{error:n.error})};if(n.state!==null)return vu(n.state,t.lastError);let r=t.lastError===void 0?t.status:`${t.status}: ${t.lastError}`;return{tone:`pending`,label:J.t(`helpers.compositionRows.notReported`),reason:J.t(`helpers.compositionRows.noRecord`,{stored:r})}}function bu(e){return Ue(e)}function xu(e,t){let n=pu(t,e);return{key:Ue(e),label:n?n.name:bu(e),presence:mu(n),deviceId:n?n.id:null}}function Su(e){return e.state.kind===`answered`&&e.state.state!==null?e.state.state.deviceId:null}function Cu(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:H(e.block.id),a=Ue(i),o=gu(e).filter(e=>Ue(e)!==a).map(e=>xu(e,t)),s=n.features.map(e=>e.enabled===!1?J.t(`helpers.compositionRows.featureOff`,{cap:e.cap}):e.cap),c=pu(t,i),l=Su(e),u=yu(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:du(n),features:s,state:u,sources:o,reportedDeviceId:l};let d=mu(c);return{blockId:e.block.id,kind:`customization`,name:c?c.name:bu(r.device),namePresence:d,type:c?c.type:null,origin:du(n),features:s,state:u,sources:o,reportedDeviceId:l}}function wu(e){return e.state.tone===`error`?0:e.state.tone===`pending`?1:e.state.tone===`ok`?2:3}function Tu(e,t){return wu(e)-wu(t)||e.name.localeCompare(t.name)}function Eu(e,t){let n=e.flatMap(e=>{let n=Cu(e,t);return n===null?[]:[n]});return{composed:n.filter(e=>e.kind===`composed`).toSorted(Tu),customizations:n.filter(e=>e.kind===`customization`).toSorted(Tu)}}u();var Du=1e4;function Ou(e){return e instanceof Error?e.message:typeof e==`object`&&e&&`message`in e?String(e.message):String(e)}function ku(){let e=yn();return e.data===void 0?{state:`unanswered`,reason:e.error==null?J.t(`build.customDeviceTab.deviceListPending`):J.t(`build.customDeviceTab.deviceListUnreadable`,{error:Ou(e.error)})}:fu(e.data)}function Au(e,t){return e===`blank`?`blank`:e===`helper`||e===`1`||t?`helper`:null}function ju({createRequested:t=!1,onCreateConsumed:n}={}){let{t:r}=Y(),[i,a]=xn(),s=Et({},{refetchInterval:Du}),l=ku(),u=Rt({editKey:`block`,newKey:`new`}),d=u.state.mode===`edit`?u.state.id:null,f=d===null?Au(i.get(`new`),t):null,p=f!==null,[h,g]=c(``),_=j(),v=ot(),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(m,{children:[Nu(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(Tt,{open:p,onClose:y,title:h||r(f===`blank`?`helper.newComposition`:`helper.newComposed`),icon:Ke,width:`xl`,testId:`composed-device-editor`,fill:!0,children:f!==null&&o(su,{mode:f,onTitle:g},f)}),o(Jn,{blockId:d,onClose:y}),v.error!=null&&o(K,{message:Ou(v.error)})]})}function Mu(t){return o(Ze,{children:e(`div`,{className:`space-y-1 p-4`,children:[o(`p`,{className:`text-sm text-warning`,children:J.t(`build.customDeviceTab.theCompositionStoreHasNot`,`The composition store has not been read yet.`)}),e(`p`,{className:`text-xs text-foreground-subtle`,children:[J.t(`build.customDeviceTab.thisIsNotTheSame`,`This is not the same as having none — the list appears once the hub has read it (`),t,`).`]})]})})}function Nu(e,t,n,r,i){if(t!=null&&e===void 0)return o(K,{title:J.t(`build.customDeviceTab.couldNotReadTheCompositions`,`Could not read the compositions`),message:Ou(t),onRetry:n});if(e===void 0)return o(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:J.t(`build.customDeviceTab.loadingCompositions`,`Loading compositions…`)});if(e.state===`not-loaded`)return Mu(e.reason);let a=t==null?null:Ou(t);return o(Pu,{lists:Eu(e.views,r),fleet:r,refreshError:a,handlers:i})}function Pu({lists:t,fleet:n,refreshError:r,handlers:i}){let{t:a}=Y();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(Fu,{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(Fu,{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 Fu({title:t,hint:n,rows:r,nameHeader:i,emptyMessage:a,kind:s,handlers:c}){let{t:l}=Y();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(At,{columns:Iu(i,s,c,l),rows:r,rowKey:e=>e.blockId,pageSize:25,maxBodyHeight:Pt,emptyMessage:a,onRowClick:s===`composed`?e=>c.onEditComposed(e.blockId):void 0})]})}function Iu(t,n,r,i){let a=[{key:`name`,header:t,sortValue:e=>e.name.toLowerCase(),render:e=>o(Ru,{row:e})},{key:`type`,header:J.t(`build.customDeviceTab.type`,`Type`),sortValue:e=>e.type,render:e=>o(`span`,{className:`text-xs text-foreground-subtle`,children:e.type??J.t(`common.unknownWord`)})},...n===`composed`?[{key:`origin`,header:J.t(`build.customDeviceTab.builtAs`,`Built as`),sortValue:e=>Lu(e.origin,i),render:e=>o(G,{variant:`default`,"data-testid":`composed-origin-badge`,children:Lu(e.origin,i)})}]:[],{key:`state`,header:J.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(G,{variant:pl(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:J.t(`build.customDeviceTab.sources`,`Sources`),nowrap:!1,notSortableReason:`A list of devices has no single order.`,render:e=>o(Bu,{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(W,{variant:`ghost`,title:i(`common.edit`,`Edit`),onClick:e=>{e.stopPropagation(),r.onEditComposed(t.blockId)},children:i(`common.edit`,`Edit`)}),o(W,{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(k,{className:`h-4 w-4`})})]})}),a}function Lu(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 Ru({row:t}){let{t:n}=Y();return e(`div`,{className:`space-y-0.5`,children:[o(zu,{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 zu({row:e}){let{t}=Y(),n=qt(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(Dn,{to:e.kind===`composed`?Tn(e.reportedDeviceId):En(e.reportedDeviceId),className:`text-xs font-medium text-foreground hover:underline`,onClick:e=>e.stopPropagation(),children:r})}function Bu({sources:t}){let{t:n}=Y();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(Dn,{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 Vu(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 Hu(e){if(Array.isArray(e))return e}function Uu(e,t,n){return(t=Qu(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Wu(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 Gu(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
@@ -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{Hi as s,Oa as c,Ui as l}from"./player-overlays-DpoShe47.js";import{$a as u,eo as d}from"./client-Dzzkm60X.js";import{y as f}from"./video-BV-3O_ZC.js";import{$d as p,Ba as m,Ha as h,Hr as g,Jr as _,Kr as v,Ua as y,Ur as b,Va as x,Wr as S,qr as C,sf as w}from"./src-CvlhNDJc.js";import{t as T}from"./i18n-DWUEvjgE.js";import{t as E}from"./useTranslation-BJr-n0es.js";import{Kr as D,Z as O,qr as k}from"./index-DKKQtgP2.js";import{t as A}from"./AdminPage-Cve4EeKX.js";a();function ee(e,t){return e.flatMap(e=>e.instances.map(n=>({addonId:e.addonId,id:n.id,name:n.name,enabled:n.enabled!==!1,providerName:t.get(e.addonId)??e.addonId})))}function te(e,t,n){let r=new Set,i=(e,t)=>`${e}\u0000${t}`,a=e.map(e=>{let a=e.instanceId===void 0?null:t.find(t=>t.addonId===e.providerAddonId&&t.id===e.instanceId)??null;return a!==null&&r.add(i(a.addonId,a.id)),{key:a===null?e.id:`instance:${a.addonId}:${a.id}`,name:e.name,providerName:a?.providerName??n(e),calendar:e,instance:a}});for(let e of t)r.has(i(e.addonId,e.id))||a.push({key:`instance:${e.addonId}:${e.id}`,name:e.name,providerName:e.providerName,calendar:null,instance:e});return a}var j=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`];function M(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function N(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function P(e){let t=e.getDay();return M(N(e,t===0?-6:1-t))}function F(e,t){if(t===`day`){let t=M(e);return{startMs:t.getTime(),endMs:N(t,1).getTime()}}if(t===`week`){let t=P(e);return{startMs:t.getTime(),endMs:N(t,7).getTime()}}let n=new Date(e.getFullYear(),e.getMonth(),1),r=new Date(e.getFullYear(),e.getMonth()+1,0),i=P(n),a=N(P(r),7);return{startMs:i.getTime(),endMs:a.getTime()}}function I(e,t){if(t===`day`)return e.toLocaleDateString(void 0,{weekday:`long`,year:`numeric`,month:`long`,day:`numeric`});if(t===`week`){let t=P(e),n=N(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 L(e,t,n){return t===`day`?N(e,n):t===`week`?N(e,n*7):new Date(e.getFullYear(),e.getMonth()+n,1)}function R(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 z(e){return e.providerAddonId!==void 0&&e.providerAddonId.length>0?e.providerAddonId:e.source===`ha`?`Home Assistant`:e.source}function B(e){if(e.allDay===!0)return T.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 V(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=M(n),t=N(M(r),-1);return G(e,t)?T.t(`systemPage.calendars.dayAllDay`,{date:n.toLocaleDateString(void 0,i)}):T.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 G(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 H({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 U({ev:t,calendarName:n,color:i,onClose:a}){let{t:o}=E();return r(g,{open:!0,onOpenChange:e=>!e&&a(),children:e(S,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`calendars-event-detail`,children:[r(C,{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(_,{className:`min-w-0 break-words`,children:t.title})]})}),r(b,{children:e(`dl`,{className:`space-y-3`,children:[r(H,{label:o(`systemPage.calendars.when`,`When`),children:V(t)}),r(H,{label:o(`systemPage.calendars.calendar`,`Calendar`),children:n}),t.location!==void 0&&t.location.length>0?r(H,{label:o(`systemPage.calendars.location`,`Location`),children:t.location}):null,t.description!==void 0&&t.description.length>0?r(H,{label:o(`systemPage.calendars.description`,`Description`),children:r(`span`,{className:`whitespace-pre-wrap`,children:t.description})}):null]})}),r(v,{children:r(p,{type:`button`,size:`sm`,variant:`secondary`,onClick:a,children:o(`common.close`,`Close`)})})]})})}function W(e,t){return e.filter(e=>d(e,t))}function G(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function K({mode:e,onChange:t}){let{t:n}=E(),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(p,{variant:`unstyled`,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 q({rows:t,onToggleVisible:n,onColorChange:i,busy:a}){let{t:s}=E();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:s(`systemPage.calendars.calendars`,`Calendars`)}),r(`ul`,{className:`space-y-1`,children:t.map(t=>{let l=t.calendar,u=t.instance!==null&&!t.instance.enabled;return e(`li`,{className:`flex items-start gap-2 rounded-md px-1.5 py-1.5 hover:bg-surface ${u?`opacity-60`:``}`,"data-testid":`calendars-row-${t.key}`,children:[l!==null&&!u?e(o,{children:[r(c,{className:`mt-1 h-3.5 w-3.5 shrink-0 accent-primary`,checked:l.visible,disabled:a,onChange:e=>n(l.id,e.target.checked),"aria-label":s(`systemPage.calendars.show`,`Show {{name}}`,{name:t.name}),"data-testid":`calendars-visible-${l.id}`}),r(w,{type:`color`,className:`mt-0.5 h-6 w-6 shrink-0 cursor-pointer rounded border border-border bg-transparent p-0`,value:l.color,disabled:a,onChange:e=>i(l.id,e.target.value.toUpperCase()),"aria-label":s(`systemPage.calendars.colourFor`,`Colour for {{name}}`,{name:t.name}),"data-testid":`calendars-color-${l.id}`})]}):null,e(`div`,{className:`min-w-0 flex-1`,children:[r(`div`,{className:`truncate text-sm font-medium ${l?.visible===!0&&!u?`text-foreground`:`text-foreground-subtle`}`,children:t.name}),e(`div`,{className:`truncate text-[11px] text-foreground-subtle`,children:[t.providerName,u?` · ${s(`systemPage.calendars.switchedOff`)}`:``,l!==null&&!l.enabled?` · ${s(`systemPage.calendars.unavailableAtSource`)}`:``]})]})]},t.key)})}),r(k,{to:`/system/integrations?tab=calendars`,className:`block text-[11px] text-primary underline-offset-2 hover:underline`,"data-testid":`calendars-manage-sources`,children:s(`systemPage.calendars.manageSources`,`Manage sources`)})]})}function J({ev:t,color:n,compact:i,onSelect:a}){return r(p,{variant:`unstyled`,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:B(t)})]})})}function ne({anchor:t,events:n,colorById:i,today:a,onSelectEvent:o}){let{t:s}=E(),{startMs:c,endMs:l}=F(t,`month`),u=[];for(let e=new Date(c);e.getTime()<l;e=N(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:j.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=M(t).getTime(),l=W(n,c),u=t.getMonth()!==d,f=G(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(J,{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 re({anchor:t,events:n,colorById:i,today:a,onSelectEvent:o}){let s=P(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)=>N(s,t)).map(t=>{let s=M(t).getTime(),c=W(n,s);return e(`div`,{className:`min-h-[8rem] bg-background p-2 sm:min-h-[12rem]`,children:[r(`div`,{className:G(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(J,{ev:e,color:i.get(e.calendarId)??`#64748B`,onSelect:o},e.id))})]},s)})})}function ie({anchor:t,events:n,colorById:i,calName:a,onSelectEvent:o}){let{t:s}=E(),c=W(n,M(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(p,{variant:`unstyled`,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:[B(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}=E(),o=x(),c=m({}),u=y(),d=O(`calendar-source`),[g,_]=i(`month`),[v,b]=i(()=>M(new Date)),[S,C]=i(null),w=t(()=>M(new Date),[]),T=o.isSuccess,j=c.isSuccess&&c.data!==void 0?c.data:void 0,N=t(()=>!T||o.data===void 0?[]:o.data.map(e=>R(e,j)),[T,o.data,j]),P=t(()=>N.filter(e=>e.visible),[N]),B=t(()=>P.map(e=>e.id),[P]),V=t(()=>F(v,g),[v,g]),H=h({startMs:V.startMs,endMs:V.endMs,calendarIds:[...B]},{enabled:T&&B.length>0}),W=H.data??[],G=t(()=>{let e=new Map;for(let t of N)e.set(t.id,t.color);return e},[N]),J=t(()=>{let e=new Map;for(let t of N)e.set(t.id,t.name);return e},[N]),Y=t(()=>te(N,ee(d.holders,d.displayNames),z),[N,d.holders,d.displayNames]),X=n((e,t)=>{u.mutateAsync({calendarId:e,visible:t}).then(()=>c.refetch())},[c,u]),Z=n((e,t)=>{/^#[0-9A-Fa-f]{6}$/.test(t)&&u.mutateAsync({calendarId:e,color:t}).then(()=>c.refetch())},[c,u]),ae=n(()=>b(M(new Date)),[]),oe=n(()=>b(e=>L(e,g,-1)),[g]),se=n(()=>b(e=>L(e,g,1)),[g]),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||d.state===`pending`?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]}):d.state===`error`&&Y.length===0?e(`p`,{className:`text-sm text-danger`,children:[a(`systemPage.calendars.couldNotListCalendars`,`Could not list calendars:`),` `,d.error]}):Y.length===0?r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-sources`,children:r(D,{i18nKey:`systemPage.calendars.emptySources`,components:{link:r(k,{to:`/system/integrations?tab=calendars`,className:`text-accent underline-offset-2 hover:underline`})}})}):B.length===0?e(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[r(q,{rows:Y,onToggleVisible:X,onColorChange:Z,busy:u.isPending}),r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-hidden`,children:N.length===0?a(`systemPage.calendars.allSwitchedOff`):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(q,{rows:Y,onToggleVisible:X,onColorChange:Z,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(K,{mode:g,onChange:_}),e(`div`,{className:`flex items-center gap-1`,children:[r(p,{variant:`unstyled`,type:`button`,className:Q,onClick:oe,"aria-label":a(`systemPage.calendars.previous`,`Previous`),"data-testid":`calendars-prev`,children:r(l,{className:`h-4 w-4`})}),r(p,{variant:`unstyled`,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:ae,"data-testid":`calendars-today`,children:a(`systemPage.calendars.today`,`Today`)}),r(p,{variant:`unstyled`,type:`button`,className:Q,onClick:se,"aria-label":a(`common.next`,`Next`),"data-testid":`calendars-next`,children:r(s,{className:`h-4 w-4`})})]}),r(`span`,{className:`text-sm font-medium text-foreground`,"data-testid":`calendars-period`,children:I(v,g)})]}),H.isPending?r(`p`,{className:`text-sm text-foreground-subtle`,children:a(`systemPage.calendars.loadingEvents`,`Loading events…`)}):H.isError?e(`p`,{className:`text-sm text-destructive`,children:[a(`systemPage.calendars.couldNotListEvents`,`Could not list events:`),` `,H.error.message]}):g===`month`?r(ne,{anchor:v,events:W,colorById:G,today:w,onSelectEvent:C}):g===`week`?r(re,{anchor:v,events:W,colorById:G,today:w,onSelectEvent:C}):r(ie,{anchor:v,events:W,colorById:G,calName:J,onSelectEvent:C})]})]}),e(A,{icon:f,title:a(`systemPage.calendars.calendars`,`Calendars`),subtitle:a(`systemPage.calendars.calendarsFromConnectedSourcesUsed`,`Calendars from connected sources. Used by Calendar events notification rules.`),children:[d.state===`error`&&Y.length>0?e(`p`,{className:`mb-3 text-sm text-warning`,role:`status`,"data-testid":`calendars-switches-unavailable`,children:[a(`systemPage.calendars.switchesUnavailable`,`The calendar switches could not be loaded, so they are hidden. Calendars switched off are not listed until they load.`),` `,d.error]}):null,$,S===null?null:r(U,{ev:S,calendarName:J.get(S.calendarId)??S.calendarId,color:G.get(S.calendarId)??`#64748B`,onClose:()=>C(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{Hi as s,Oa as c,Ui as l}from"./player-overlays-DpoShe47.js";import{$a as u,eo as d}from"./client-Dzzkm60X.js";import{y as f}from"./video-BV-3O_ZC.js";import{$d as p,Ba as m,Ha as h,Hr as g,Jr as _,Kr as v,Ua as y,Ur as b,Va as x,Wr as S,qr as C,sf as w}from"./src-5h33Ujaz.js";import{t as T}from"./i18n-DWUEvjgE.js";import{t as E}from"./useTranslation-BJr-n0es.js";import{Kr as D,Z as O,qr as k}from"./index-BK_1kQTJ.js";import{t as A}from"./AdminPage-BoBZR6uA.js";a();function ee(e,t){return e.flatMap(e=>e.instances.map(n=>({addonId:e.addonId,id:n.id,name:n.name,enabled:n.enabled!==!1,providerName:t.get(e.addonId)??e.addonId})))}function te(e,t,n){let r=new Set,i=(e,t)=>`${e}\u0000${t}`,a=e.map(e=>{let a=e.instanceId===void 0?null:t.find(t=>t.addonId===e.providerAddonId&&t.id===e.instanceId)??null;return a!==null&&r.add(i(a.addonId,a.id)),{key:a===null?e.id:`instance:${a.addonId}:${a.id}`,name:e.name,providerName:a?.providerName??n(e),calendar:e,instance:a}});for(let e of t)r.has(i(e.addonId,e.id))||a.push({key:`instance:${e.addonId}:${e.id}`,name:e.name,providerName:e.providerName,calendar:null,instance:e});return a}var j=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`];function M(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function N(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function P(e){let t=e.getDay();return M(N(e,t===0?-6:1-t))}function F(e,t){if(t===`day`){let t=M(e);return{startMs:t.getTime(),endMs:N(t,1).getTime()}}if(t===`week`){let t=P(e);return{startMs:t.getTime(),endMs:N(t,7).getTime()}}let n=new Date(e.getFullYear(),e.getMonth(),1),r=new Date(e.getFullYear(),e.getMonth()+1,0),i=P(n),a=N(P(r),7);return{startMs:i.getTime(),endMs:a.getTime()}}function I(e,t){if(t===`day`)return e.toLocaleDateString(void 0,{weekday:`long`,year:`numeric`,month:`long`,day:`numeric`});if(t===`week`){let t=P(e),n=N(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 L(e,t,n){return t===`day`?N(e,n):t===`week`?N(e,n*7):new Date(e.getFullYear(),e.getMonth()+n,1)}function R(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 z(e){return e.providerAddonId!==void 0&&e.providerAddonId.length>0?e.providerAddonId:e.source===`ha`?`Home Assistant`:e.source}function B(e){if(e.allDay===!0)return T.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 V(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=M(n),t=N(M(r),-1);return G(e,t)?T.t(`systemPage.calendars.dayAllDay`,{date:n.toLocaleDateString(void 0,i)}):T.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 G(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 H({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 U({ev:t,calendarName:n,color:i,onClose:a}){let{t:o}=E();return r(g,{open:!0,onOpenChange:e=>!e&&a(),children:e(S,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`calendars-event-detail`,children:[r(C,{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(_,{className:`min-w-0 break-words`,children:t.title})]})}),r(b,{children:e(`dl`,{className:`space-y-3`,children:[r(H,{label:o(`systemPage.calendars.when`,`When`),children:V(t)}),r(H,{label:o(`systemPage.calendars.calendar`,`Calendar`),children:n}),t.location!==void 0&&t.location.length>0?r(H,{label:o(`systemPage.calendars.location`,`Location`),children:t.location}):null,t.description!==void 0&&t.description.length>0?r(H,{label:o(`systemPage.calendars.description`,`Description`),children:r(`span`,{className:`whitespace-pre-wrap`,children:t.description})}):null]})}),r(v,{children:r(p,{type:`button`,size:`sm`,variant:`secondary`,onClick:a,children:o(`common.close`,`Close`)})})]})})}function W(e,t){return e.filter(e=>d(e,t))}function G(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function K({mode:e,onChange:t}){let{t:n}=E(),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(p,{variant:`unstyled`,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 q({rows:t,onToggleVisible:n,onColorChange:i,busy:a}){let{t:s}=E();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:s(`systemPage.calendars.calendars`,`Calendars`)}),r(`ul`,{className:`space-y-1`,children:t.map(t=>{let l=t.calendar,u=t.instance!==null&&!t.instance.enabled;return e(`li`,{className:`flex items-start gap-2 rounded-md px-1.5 py-1.5 hover:bg-surface ${u?`opacity-60`:``}`,"data-testid":`calendars-row-${t.key}`,children:[l!==null&&!u?e(o,{children:[r(c,{className:`mt-1 h-3.5 w-3.5 shrink-0 accent-primary`,checked:l.visible,disabled:a,onChange:e=>n(l.id,e.target.checked),"aria-label":s(`systemPage.calendars.show`,`Show {{name}}`,{name:t.name}),"data-testid":`calendars-visible-${l.id}`}),r(w,{type:`color`,className:`mt-0.5 h-6 w-6 shrink-0 cursor-pointer rounded border border-border bg-transparent p-0`,value:l.color,disabled:a,onChange:e=>i(l.id,e.target.value.toUpperCase()),"aria-label":s(`systemPage.calendars.colourFor`,`Colour for {{name}}`,{name:t.name}),"data-testid":`calendars-color-${l.id}`})]}):null,e(`div`,{className:`min-w-0 flex-1`,children:[r(`div`,{className:`truncate text-sm font-medium ${l?.visible===!0&&!u?`text-foreground`:`text-foreground-subtle`}`,children:t.name}),e(`div`,{className:`truncate text-[11px] text-foreground-subtle`,children:[t.providerName,u?` · ${s(`systemPage.calendars.switchedOff`)}`:``,l!==null&&!l.enabled?` · ${s(`systemPage.calendars.unavailableAtSource`)}`:``]})]})]},t.key)})}),r(k,{to:`/system/integrations?tab=calendars`,className:`block text-[11px] text-primary underline-offset-2 hover:underline`,"data-testid":`calendars-manage-sources`,children:s(`systemPage.calendars.manageSources`,`Manage sources`)})]})}function J({ev:t,color:n,compact:i,onSelect:a}){return r(p,{variant:`unstyled`,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:B(t)})]})})}function ne({anchor:t,events:n,colorById:i,today:a,onSelectEvent:o}){let{t:s}=E(),{startMs:c,endMs:l}=F(t,`month`),u=[];for(let e=new Date(c);e.getTime()<l;e=N(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:j.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=M(t).getTime(),l=W(n,c),u=t.getMonth()!==d,f=G(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(J,{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 re({anchor:t,events:n,colorById:i,today:a,onSelectEvent:o}){let s=P(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)=>N(s,t)).map(t=>{let s=M(t).getTime(),c=W(n,s);return e(`div`,{className:`min-h-[8rem] bg-background p-2 sm:min-h-[12rem]`,children:[r(`div`,{className:G(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(J,{ev:e,color:i.get(e.calendarId)??`#64748B`,onSelect:o},e.id))})]},s)})})}function ie({anchor:t,events:n,colorById:i,calName:a,onSelectEvent:o}){let{t:s}=E(),c=W(n,M(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(p,{variant:`unstyled`,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:[B(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}=E(),o=x(),c=m({}),u=y(),d=O(`calendar-source`),[g,_]=i(`month`),[v,b]=i(()=>M(new Date)),[S,C]=i(null),w=t(()=>M(new Date),[]),T=o.isSuccess,j=c.isSuccess&&c.data!==void 0?c.data:void 0,N=t(()=>!T||o.data===void 0?[]:o.data.map(e=>R(e,j)),[T,o.data,j]),P=t(()=>N.filter(e=>e.visible),[N]),B=t(()=>P.map(e=>e.id),[P]),V=t(()=>F(v,g),[v,g]),H=h({startMs:V.startMs,endMs:V.endMs,calendarIds:[...B]},{enabled:T&&B.length>0}),W=H.data??[],G=t(()=>{let e=new Map;for(let t of N)e.set(t.id,t.color);return e},[N]),J=t(()=>{let e=new Map;for(let t of N)e.set(t.id,t.name);return e},[N]),Y=t(()=>te(N,ee(d.holders,d.displayNames),z),[N,d.holders,d.displayNames]),X=n((e,t)=>{u.mutateAsync({calendarId:e,visible:t}).then(()=>c.refetch())},[c,u]),Z=n((e,t)=>{/^#[0-9A-Fa-f]{6}$/.test(t)&&u.mutateAsync({calendarId:e,color:t}).then(()=>c.refetch())},[c,u]),ae=n(()=>b(M(new Date)),[]),oe=n(()=>b(e=>L(e,g,-1)),[g]),se=n(()=>b(e=>L(e,g,1)),[g]),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||d.state===`pending`?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]}):d.state===`error`&&Y.length===0?e(`p`,{className:`text-sm text-danger`,children:[a(`systemPage.calendars.couldNotListCalendars`,`Could not list calendars:`),` `,d.error]}):Y.length===0?r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-sources`,children:r(D,{i18nKey:`systemPage.calendars.emptySources`,components:{link:r(k,{to:`/system/integrations?tab=calendars`,className:`text-accent underline-offset-2 hover:underline`})}})}):B.length===0?e(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[r(q,{rows:Y,onToggleVisible:X,onColorChange:Z,busy:u.isPending}),r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-hidden`,children:N.length===0?a(`systemPage.calendars.allSwitchedOff`):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(q,{rows:Y,onToggleVisible:X,onColorChange:Z,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(K,{mode:g,onChange:_}),e(`div`,{className:`flex items-center gap-1`,children:[r(p,{variant:`unstyled`,type:`button`,className:Q,onClick:oe,"aria-label":a(`systemPage.calendars.previous`,`Previous`),"data-testid":`calendars-prev`,children:r(l,{className:`h-4 w-4`})}),r(p,{variant:`unstyled`,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:ae,"data-testid":`calendars-today`,children:a(`systemPage.calendars.today`,`Today`)}),r(p,{variant:`unstyled`,type:`button`,className:Q,onClick:se,"aria-label":a(`common.next`,`Next`),"data-testid":`calendars-next`,children:r(s,{className:`h-4 w-4`})})]}),r(`span`,{className:`text-sm font-medium text-foreground`,"data-testid":`calendars-period`,children:I(v,g)})]}),H.isPending?r(`p`,{className:`text-sm text-foreground-subtle`,children:a(`systemPage.calendars.loadingEvents`,`Loading events…`)}):H.isError?e(`p`,{className:`text-sm text-destructive`,children:[a(`systemPage.calendars.couldNotListEvents`,`Could not list events:`),` `,H.error.message]}):g===`month`?r(ne,{anchor:v,events:W,colorById:G,today:w,onSelectEvent:C}):g===`week`?r(re,{anchor:v,events:W,colorById:G,today:w,onSelectEvent:C}):r(ie,{anchor:v,events:W,colorById:G,calName:J,onSelectEvent:C})]})]}),e(A,{icon:f,title:a(`systemPage.calendars.calendars`,`Calendars`),subtitle:a(`systemPage.calendars.calendarsFromConnectedSourcesUsed`,`Calendars from connected sources. Used by Calendar events notification rules.`),children:[d.state===`error`&&Y.length>0?e(`p`,{className:`mb-3 text-sm text-warning`,role:`status`,"data-testid":`calendars-switches-unavailable`,children:[a(`systemPage.calendars.switchesUnavailable`,`The calendar switches could not be loaded, so they are hidden. Calendars switched off are not listed until they load.`),` `,d.error]}):null,$,S===null?null:r(U,{ev:S,calendarName:J.get(S.calendarId)??S.calendarId,color:G.get(S.calendarId)??`#64748B`,onClose:()=>C(null)})]})}export{Y as CalendarsPage,Y as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{S as e}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Nr as t}from"./player-overlays-DpoShe47.js";import{t as n}from"./useTranslation-BJr-n0es.js";import{t as r}from"./InstancesTable-
|
|
1
|
+
import{S as e}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Nr as t}from"./player-overlays-DpoShe47.js";import{t as n}from"./useTranslation-BJr-n0es.js";import{t as r}from"./InstancesTable-pH3oYjHd.js";function i(){let{t:i}=n();return e(r,{functionCap:`camera-grid-layout`,icon:t,title:i(`cameraGrids.title`,`Camera grids`),subtitle:i(`cameraGrids.subtitle`,`A grid is a composite camera: several cameras composed into one picture, recorded and played back like any other. Create one with a name, then open its camera to lay it out.`),emptyTitle:i(`cameraGrids.empty`,`No camera grids yet`),emptyDescription:i(`cameraGrids.emptyHint`,`Add a grid to compose several cameras into one.`),addLabel:i(`cameraGrids.add`,`Add grid`)})}export{i as CameraGridsPage};
|