@camstack/addon-admin-ui 1.2.510 → 1.2.512
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 +17 -0
- package/dist/assets/{AddonAssetIcon-C9hAoKXu.js → AddonAssetIcon-DCKCRhEh.js} +1 -1
- package/dist/assets/{Addons-RWj1BxGY.js → Addons-DPAqJ5aW.js} +1 -1
- package/dist/assets/{AdminPage-DlYf-2bp.js → AdminPage-CVSTxsAk.js} +1 -1
- package/dist/assets/{AdminSectionedPage-BZCKp3Ch.js → AdminSectionedPage-BG6w5-w1.js} +1 -1
- package/dist/assets/{AiProfiles-JSlQDV72.js → AiProfiles-DR_I4RIr.js} +1 -1
- package/dist/assets/{BrokerEditorDialog-Bd04efEw.js → BrokerEditorDialog-Dd6KEwRN.js} +1 -1
- package/dist/assets/Build-C8Iyyb5o.js +40 -0
- package/dist/assets/{Calendars-DP9Bg77f.js → Calendars-BHqwUpG9.js} +1 -1
- package/dist/assets/Cluster-DDjN53AW.js +1 -0
- package/dist/assets/CompositionBlockEditor-B81aTqq3.js +1 -0
- package/dist/assets/{CompositionEditorPage-Csnltw_A.js → CompositionEditorPage-CbLv15x4.js} +1 -1
- package/dist/assets/{Data-uCQZVzY1.js → Data-CJqiuGjd.js} +1 -1
- package/dist/assets/{DeviceDetail-BxIy7-Dm.js → DeviceDetail-DvtPS7Er.js} +1 -1
- package/dist/assets/{DeviceDoActionFields-CK01sDyF.js → DeviceDoActionFields-DnA_DSYw.js} +1 -1
- package/dist/assets/{Devices-CVsltbg0.js → Devices-B9SE3Rwm.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-C5TPel_z.js → EmbedPlayerPage-D63WF3oV.js} +1 -1
- package/dist/assets/HelperWizard-BigkVmsB.js +2 -0
- package/dist/assets/{History-B20ge-W7.js → History-D0syoHcx.js} +1 -1
- package/dist/assets/{Identity-DPilvdr-.js → Identity-CElkwZnz.js} +1 -1
- package/dist/assets/{IntegrationDetail-QFz0_FYR.js → IntegrationDetail-DZ8ztuOE.js} +1 -1
- package/dist/assets/{IntegrationHub-B1kSbU1F.js → IntegrationHub-DiscqOsj.js} +1 -1
- package/dist/assets/{Integrations-DL3TkBVs.js → Integrations-BfCE8MnT.js} +1 -1
- package/dist/assets/{Integrations-DZSqPZJX.js → Integrations-CHguUclI.js} +1 -1
- package/dist/assets/{Library-lJCalEoT.js → Library-C2NTg1uA.js} +1 -1
- package/dist/assets/{Locations-B0jWaHF6.js → Locations-DWad73x-.js} +1 -1
- package/dist/assets/{Logs-DQLPAUyF.js → Logs-kEWkWloD.js} +1 -1
- package/dist/assets/{MaskShapeCanvas-CFljj6Sk.js → MaskShapeCanvas-D6XVNdwA.js} +1 -1
- package/dist/assets/{MotionZonesSettings-B8TBt4dC.js → MotionZonesSettings-BXHdXw3X.js} +1 -1
- package/dist/assets/{MyAccess-CZG0q7Mt.js → MyAccess-CS5GrN5k.js} +1 -1
- package/dist/assets/{Network-BBrgIFOt.js → Network-DtfAuiol.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-CeHG4O24.js → NodeAddonsSettingsPanel-lczGJdHs.js} +1 -1
- package/dist/assets/{Notifications-3RTWnoyO.js → Notifications-DchKpNOg.js} +1 -1
- package/dist/assets/{Pipeline-CGdO9F0O.js → Pipeline-vgUZsFFP.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-BJlCR0a3.js → PrivacyMaskSettings-BXiuTmLQ.js} +1 -1
- package/dist/assets/{Recordings-CURYqqF0.js → Recordings-CyPYQ20P.js} +1 -1
- package/dist/assets/{ScanNetworkModal-ojXdkkOk.js → ScanNetworkModal-Bg22q8vm.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-CNgXiExG.js → SceneMonitorEditor-ChgZnP_I.js} +1 -1
- package/dist/assets/{SessionsList-Bd4yBLfB.js → SessionsList-CfuTFr66.js} +1 -1
- package/dist/assets/{Showroom-Df0D9oOc.js → Showroom-R3reqgpn.js} +1 -1
- package/dist/assets/{System-DQkvS75J.js → System-r9rg9iWn.js} +1 -1
- package/dist/assets/{Terminal-BhUVowlr.js → Terminal-B5qyGLn1.js} +1 -1
- package/dist/assets/{Viewer-B4P4Bkxo.js → Viewer-CLvHpMj8.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Cze0rRAV.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-GbWwXkZ2.js} +1 -1
- package/dist/assets/{addon-icons-context-fZFRR8Jh.js → addon-icons-context-ClSTx0Nd.js} +1 -1
- package/dist/assets/{archive-B0Gb92Md.js → archive-P7vGIXBL.js} +1 -1
- package/dist/assets/{assignment-candidates-CLAnrBak.js → assignment-candidates-B0B3pJGN.js} +1 -1
- package/dist/assets/{authed-media-BZXVXyjI.js → authed-media-Ba0gOxiM.js} +1 -1
- package/dist/assets/{bell-off-BFI_PtFI.js → bell-off-B4S4Brhx.js} +1 -1
- package/dist/assets/{board-model-Cb9TF016.js → board-model-DcpPhztF.js} +1 -1
- package/dist/assets/{boxes-C9rq6GsW.js → boxes-Cc83jXU7.js} +1 -1
- package/dist/assets/circle-slash-fwUwJ3r8.js +1 -0
- package/dist/assets/{client-CwJGlpR9.js → client-JLEP7nv7.js} +1 -1
- package/dist/assets/{cloud-upload-kAMSz6c0.js → cloud-upload-BNAApVPM.js} +1 -1
- package/dist/assets/crop-j4n-xPUF.js +1 -0
- package/dist/assets/{device-integration-icon-a0pkysxV.js → device-integration-icon-Nwyo5V5H.js} +1 -1
- package/dist/assets/device-picker-model-C44QyL85.js +1 -0
- package/dist/assets/{dist-CG2a7mCH.js → dist-97mm2unN.js} +1 -1
- package/dist/assets/{dist-D4krkzk0.js → dist-BW5MRjy3.js} +1 -1
- package/dist/assets/{eraser-De_DOv3l.js → eraser-CfQsg9Ve.js} +1 -1
- package/dist/assets/{format-7HUlrbym.js → format-u0sqgb1J.js} +1 -1
- package/dist/assets/{hard-drive-download-DKm5p-Le.js → hard-drive-download-PwUdP9sZ.js} +1 -1
- package/dist/assets/{hostInit-Ct3ew837.js → hostInit-VFHoBRCk.js} +1 -1
- package/dist/assets/i18n-CXGP1uaw.js +1 -0
- package/dist/assets/{icons-3VtN4bSW.js → icons-BJz9Yj7E.js} +1 -1
- package/dist/assets/{index-DUl9HFmr.css → index-Dep3DVAz.css} +1 -1
- package/dist/assets/{index-DG07MiZm.js → index-lH9UKmhf.js} +3 -3
- package/dist/assets/{key-VHIrojXx.js → key-drN5OJov.js} +1 -1
- package/dist/assets/{key-round-Bfq08tmQ.js → key-round-CBhTR29b.js} +1 -1
- package/dist/assets/{layers-C2a0eh6-.js → layers-C5Yl1IY5.js} +1 -1
- package/dist/assets/{linked-devices-model-D3jOXb7G.js → linked-devices-model-COUfIEod.js} +1 -1
- package/dist/assets/{list-ordered-Da2mHuCu.js → list-ordered-A3gv0vJA.js} +1 -1
- package/dist/assets/{location-owned-usage-DqvEUneY.js → location-owned-usage-BmtVONF0.js} +1 -1
- package/dist/assets/{log-in-eLGFJBOn.js → log-in-ChqbFBLh.js} +1 -1
- package/dist/assets/{memory-stick-DnKI7rwN.js → memory-stick-B__TSEyk.js} +1 -1
- package/dist/assets/{message-square-plus-C6KwcZuQ.js → message-square-plus-BERx-QaF.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-98f2c3e4.js → mf-entry-bootstrap-0-556ccfd0.js} +2 -2
- package/dist/assets/{mic-off-D983qPJH.js → mic-off-Dyo6dwK_.js} +1 -1
- package/dist/assets/{monitor-off-BxsFOOUC.js → monitor-off-Czfm61g6.js} +1 -1
- package/dist/assets/{monitor-smartphone-CVLLvvgV.js → monitor-smartphone-tJnvQ6Wt.js} +1 -1
- package/dist/assets/mount-C44QyL85.js +1 -0
- package/dist/assets/{player-overlays-g9d3qYrr.js → player-overlays-B5FSaids.js} +1 -1
- package/dist/assets/{recycle-DO_1Mgmd.js → recycle-droAKct3.js} +1 -1
- package/dist/assets/remoteEntry-De9zVsA0.js +1 -0
- package/dist/assets/{scan-eye-CyJ3ozW9.js → scan-eye-gmpggdW4.js} +1 -1
- package/dist/assets/{scissors-BNMtq6Ob.js → scissors-CCgXntCX.js} +1 -1
- package/dist/assets/{search-x-DDY8MfL6.js → search-x-D1xSmXhu.js} +1 -1
- package/dist/assets/{send-Ch2Il08w.js → send-B8FKrOyC.js} +1 -1
- package/dist/assets/{settings-2-DuqbBWmE.js → settings-2-BdhYf7UQ.js} +1 -1
- package/dist/assets/{sigma-C3PEOK_Y.js → sigma-Bzh2qqL3.js} +1 -1
- package/dist/assets/{speaker-DkdRIL1K.js → speaker-CmGzkRdE.js} +1 -1
- package/dist/assets/{src-DwNoxp86.js → src-IQsaq5W-.js} +4 -4
- package/dist/assets/{step-inspector-model-DQUr_7uJ.js → step-inspector-model-CW9NPxgI.js} +1 -1
- package/dist/assets/{table-2-DoxvwhSo.js → table-2-DaQYtXJ7.js} +1 -1
- package/dist/assets/{timer-reset-DVNN3Abc.js → timer-reset-ceaN5uh6.js} +1 -1
- package/dist/assets/{unlink-C-2ouMww.js → unlink-CZPQIK73.js} +1 -1
- package/dist/assets/{usb-PSQjoR7w.js → usb-CdZusF7Y.js} +1 -1
- package/dist/assets/{use-scenes-feed-B_j7CFbm.js → use-scenes-feed-CQOhXjvP.js} +1 -1
- package/dist/assets/{use-stationary-objects-Drf9XXJR.js → use-stationary-objects-D9KV1ze2.js} +1 -1
- package/dist/assets/useEventInvalidation-C44QyL85.js +1 -0
- package/dist/assets/{useNodeUrlSelection-Cg0TPdbH.js → useNodeUrlSelection-CAyN93HW.js} +1 -1
- package/dist/assets/user-round-yFN2hAUV.js +1 -0
- package/dist/assets/{user-x-BRStn-V-.js → user-x-DKorc3CR.js} +1 -1
- package/dist/assets/{variable-vFOxYqY7.js → variable-BXBhuk59.js} +1 -1
- package/dist/assets/{video-BFmrpvc7.js → video-2nOnVl_R.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-JzLE6zuc.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Dyo8T61H.js} +2 -2
- package/dist/index.html +10 -10
- package/dist/server/addon.js +1 -1
- package/package.json +1 -1
- package/dist/assets/Build-BZi_niS-.js +0 -40
- package/dist/assets/Cluster-Dd_vu_bM.js +0 -1
- package/dist/assets/CompositionBlockEditor-CH-GMXbq.js +0 -1
- package/dist/assets/HelperWizard-BPhC2XoW.js +0 -2
- package/dist/assets/circle-slash-CrgSHCu9.js +0 -1
- package/dist/assets/crop-DKZuvuZ0.js +0 -1
- package/dist/assets/device-picker-model-BTGIE40h.js +0 -1
- package/dist/assets/i18n-9jE1YKjd.js +0 -1
- package/dist/assets/mount-BTGIE40h.js +0 -1
- package/dist/assets/remoteEntry-CpKU5IE2.js +0 -1
- package/dist/assets/useEventInvalidation-BTGIE40h.js +0 -1
- package/dist/assets/user-round-Z0QH_kjR.js +0 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import{C as e,E as t,J as n,K as r,P as i,R as a,S as o,V as s,Y as c,a as l,et as u,o as d,t as f,x as p}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$i as m,Ar as h,Di as g,Fn as _,Ht as v,In as y,Mi as b,Ti as x,Tr as S,Vn as C,dt as w,fr as T,mr as E,pa as D,ra as O,st as k,vt as A,wn as j,yi as M,yn as N,zt as P}from"./player-overlays-B5FSaids.js";import{$i as F,Ai as I,Di as L,Fi as R,Ka as ee,Pi as z,Qi as B,Xi as te,Zi as ne,da as re,ea as ie,fi as ae,fn as V,hi as oe,mi as se,na as ce,on as le,so as ue,ta as de,ua as fe,wi as pe}from"./client-JLEP7nv7.js";import{t as me}from"./boxes-Cc83jXU7.js";import{i as H,n as he,r as ge,t as _e}from"./variable-BXBhuk59.js";import{s as ve}from"./video-2nOnVl_R.js";import{$r as ye,Cn as be,Co as xe,Do as Se,Er as Ce,Fa as we,Ga as Te,Ia as Ee,Ir as De,Jo as Oe,Ka as ke,Kt as Ae,La as je,Md as Me,Mo as Ne,Nr as Pe,Or as Fe,Pd as Ie,Qr as Le,R as Re,Ra as ze,Sn as Be,Tr as U,Ua as Ve,Un as He,Va as Ue,Wa as We,Yr as W,Zt as Ge,_r as Ke,bn as qe,br as Je,cd as Ye,ci as Xe,dd as G,di as Ze,dr as Qe,en as $e,fi as et,ft as tt,gd as K,gi as nt,gn as rt,gr as it,hd as at,hi as ot,hr as st,li as ct,md as lt,mi as ut,mt as dt,pd as ft,pr as pt,ri as q,rn as mt,rt as ht,si as gt,ui as _t,vi as vt,vt as yt}from"./src-IQsaq5W-.js";import{t as J}from"./i18n-CXGP1uaw.js";import{t as Y}from"./useTranslation-BJr-n0es.js";import{L as bt,T as xt,_r as St,h as Ct,lr as wt,m as Tt,mr as Et,pr as X,yr as Dt}from"./index-lH9UKmhf.js";import{t as Ot}from"./AdminSectionedPage-BG6w5-w1.js";import{n as kt}from"./format-u0sqgb1J.js";import{n as At,t as jt}from"./DeviceDoActionFields-DnA_DSYw.js";import{J as Mt,P as Nt,V as Pt,p as Ft,t as It,u as Lt}from"./HelperWizard-BigkVmsB.js";import{t as Rt}from"./CompositionBlockEditor-B81aTqq3.js";var zt=`const AUTOMATION_RECIPE =`,Bt=`// EJECTED from the visual automation editor — this file is now hand-owned.
|
|
2
|
+
// The recipe that produced it was removed with it, on purpose: while it was
|
|
3
|
+
// here the editor could re-open this block and overwrite everything below.`;function Vt(e){return e.includes(zt)}function Ht(e){let t=e.indexOf(zt);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 Ut(e){let t=Ht(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=F.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 Wt(e){let t=Ht(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)}${Bt}${e.slice(i)}`}u();function Gt(e){return e===void 0||!Number.isFinite(e)?``:String(e)}function Kt({value:e,onValue:t,onBrace:n,onBlur:r,...i}){let[a,s]=c(null);return o(K,{...i,inputMode:`decimal`,value:a??Gt(e),onChange:e=>{let r=e.target.value;if(r.includes(`{`)){n?.();return}s(r);let i=r.trim()===``?NaN:Number(r);t(Number.isFinite(i)?i:null)},onBlur:e=>{s(null),r?.(e)}})}function qt({widthClass:e,...t}){return o(`span`,{className:`block max-w-full ${e}`,children:o(G,{...t})})}var Jt=/(\{[A-Za-z0-9_]+\})/;function Yt(e){return e.toLowerCase().startsWith(`it`)?`it`:`en`}function Xt(e){return`${e.cap}:${e.id}`}function Zt(e){if(typeof e!=`object`||!e)return!1;let t=Object.keys(e);return t.length===1&&t[0]===`$var`&&typeof Reflect.get(e,`$var`)==`string`}function Qt(e){let t=[];for(let n of e.split(Jt))n!==``&&(n.startsWith(`{`)&&n.endsWith(`}`)?t.push({kind:`slot`,key:n.slice(1,-1)}):t.push({kind:`text`,text:n}));return t}function $t(e){let t=e.offer;switch(t.kind){case`number`:return{kind:`fixed`,value:t.min??0};case`enum`:{let e=t.values[0];return{kind:`fixed`,value:e===void 0?``:e.value}}case`boolean`:return{kind:`fixed`,value:!1};default:return{kind:`fixed`,value:``}}}function en(e){return Object.fromEntries(e.openArgs.map(e=>[e.key,$t(e)]))}function tn(e,t){return Zt(e)?{kind:`var`,name:e.$var}:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?{kind:`fixed`,value:e}:$t(t)}function nn(e,t){return JSON.stringify(e)===JSON.stringify(t)}function rn(e,t){if(typeof t.deviceId!=`number`)return null;let n=t.args??{},r=null,i=-1;for(let a of e){if(a.cap!==t.cap||a.method!==t.method)continue;let e=Object.entries(a.args);e.every(([e,t])=>nn(n[e],t))&&e.length>i&&(r=a,i=e.length)}if(r===null)return null;let a=Object.fromEntries(r.openArgs.map(e=>[e.key,tn(n[e.key],e)]));return{action:r,values:a}}function an(e){return e.kind===`var`?{$var:e.name}:e.value}function on(e){return e.kind===`fixed`&&e.value===``}function sn(e,t,n){let r={};for(let t of e.openArgs){let e=n[t.key]??$t(t);t.optional===!0&&on(e)||(r[t.key]=an(e))}let i={...e.args,...r};return{kind:`cap`,deviceId:t,cap:e.cap,method:e.method,...Object.keys(i).length===0?{}:{args:i}}}function cn(e,t){if(t.kind===`var`)return null;let n=e.offer;return n.kind===`number`?typeof t.value!=`number`||!Number.isFinite(t.value)?`empty`:n.min!==void 0&&t.value<n.min?`below`:n.max!==void 0&&t.value>n.max?`above`:null:n.kind===`text`||n.kind===`dynamic`?e.optional===!0||t.value!==``?null:`empty`:null}u();function ln(e){return e.kind===`fixed`?String(e.value):``}function un({arg:t,locale:n,variables:r,value:i,onChange:a}){let{t:s}=Y(),[l,u]=c(!1),d=t.label[n],f=cn(t,i),p=i.kind===`var`?o(ye,{label:i.name,onRemove:()=>a($t(t))}):o(dn,{arg:t,locale:n,value:i,onChange:a,onBrace:()=>u(!0)});return e(`span`,{className:`inline-flex flex-col gap-0.5 align-top`,"data-testid":`arg-${t.key}`,children:[e(`span`,{className:`inline-flex items-center gap-1`,children:[p,r.length>0&&e(gt,{open:l,onOpenChange:u,children:[o(_t,{"aria-label":s(`flow.arg.useVariable`,`Use a variable for {{label}}`,{label:d}),className:`h-8 rounded-md border border-border bg-surface px-2 font-mono text-xs text-foreground hover:bg-surface-hover`,children:`{x}`}),o(Xe,{children:r.map(e=>o(ct,{onClick:()=>a({kind:`var`,name:e.name}),children:`${e.name} · ${e.hint}`},e.name))})]})]}),o(pn,{arg:t,value:i,issue:f})]})}function dn({arg:e,locale:t,value:n,onChange:r,onBrace:i}){let{t:a}=Y(),s=e.offer,c=e.label[t];return s.kind===`enum`?o(qt,{widthClass:`w-40`,"aria-label":c,value:String(n.value),onChange:e=>{let t=s.values.find(t=>String(t.value)===e.target.value);t!==void 0&&r({kind:`fixed`,value:t.value})},options:s.values.map(e=>({value:String(e.value),label:e.label[t]}))}):s.kind===`boolean`?o(qt,{widthClass:`w-28`,"aria-label":c,value:n.value===!0?`yes`:`no`,onChange:e=>r({kind:`fixed`,value:e.target.value===`yes`}),options:[{value:`yes`,label:a(`common.yes`,`Yes`)},{value:`no`,label:a(`common.no`,`No`)}]}):s.kind===`number`?o(fn,{label:c,unit:s.unit,value:n,onChange:r,onBrace:i}):o(K,{"aria-label":c,type:s.kind===`text`&&s.secret===!0?`password`:`text`,className:`w-40`,value:ln(n),onChange:e=>{if(e.target.value.includes(`{`)){i();return}r({kind:`fixed`,value:e.target.value})}})}function fn({label:t,unit:n,value:r,onChange:i,onBrace:a}){return e(p,{children:[o(Kt,{"aria-label":t,className:`w-20`,value:typeof r.value==`number`?r.value:void 0,onValue:e=>i({kind:`fixed`,value:e??NaN}),onBrace:a}),n!==void 0&&o(`span`,{className:`text-sm text-foreground-muted`,children:n})]})}function pn({arg:e,value:t,issue:n}){let{t:r}=Y(),i=e.offer;if(t.kind!==`fixed`||i.kind!==`number`||i.min===void 0&&i.max===void 0)return null;let a=i.min!==void 0&&i.max!==void 0?r(`flow.arg.range`,`{{min}} to {{max}} {{unit}}`,{min:i.min,max:i.max,unit:i.unit??``}):i.min===void 0?r(`flow.arg.atMost`,`at most {{max}} {{unit}}`,{max:i.max,unit:i.unit??``}):r(`flow.arg.atLeast`,`at least {{min}} {{unit}}`,{min:i.min,unit:i.unit??``});return o(`span`,{className:`text-[11px] ${n===null?`text-foreground-subtle`:`text-danger`}`,role:n===null?void 0:`alert`,children:a.trim()})}u();function mn({devices:e,value:t,onChange:n,selection:i,noun:a=`device`,listState:s=`answered`,emptyLabel:c,testId:l}){return o(Re,{devices:r(()=>e.map(e=>({id:e.id,name:e.name,...e.type===void 0?{}:{type:e.type},location:e.location??null})),[e]),listState:s,value:[...t],onChange:e=>n(e),selection:i,noun:a,groupBy:`location`,...c===void 0?{}:{emptyLabel:c},testId:l})}u();function hn(e){return typeof e==`number`?e:typeof e==`object`&&e&&`$var`in e?{$var:e.$var}:[...e]}function gn(e,t,n){return e.map(e=>({value:Xt(e),label:e.label[t],description:e.phrase[t].replace(`{device}`,n)}))}function _n({step:t,devices:n,devicesState:i=`answered`,variables:a,onChange:s}){let{t:l,i18n:u}=Y(),d=Yt(u.language),[f,p]=c(!1),m=typeof t.deviceId==`number`,h=typeof t.deviceId==`number`?t.deviceId:0,g=n.find(e=>e.id===h),_=At(m?h:0),v=r(()=>_.data===void 0?[]:le(_.data,g?.type),[_.data,g?.type]),y=r(()=>rn(v,t),[v,t]),b=t.cap===``,x=m&&h>0&&_.data===void 0&&!_.isError;if(!(m&&!f&&(b||y!==null||x)))return o(yn,{step:t,devices:n,devicesState:i,onChange:s,onBack:m&&!b&&y!==null?()=>p(!1):null});let S=n.filter(e=>V(e.type??``));return e(`div`,{className:`space-y-2`,"data-testid":`command-step`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[g?.type!==void 0&&o(q,{variant:`neutral`,children:g.type}),o(W,{variant:`ghost`,size:`sm`,className:`ml-auto`,onClick:()=>p(!0),"data-testid":`command-step-advanced`,children:l(`flow.command.advanced`,`Advanced`)})]}),e(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[o(mn,{devices:S,selection:`single`,listState:i,value:h>0?[h]:[],testId:`command-step-device`,onChange:e=>{let t=e[0]??0;t!==h&&s({kind:`cap`,deviceId:t,cap:``,method:``})}}),o(Le,{mode:`single`,singleDisplay:`field`,options:gn(v,d,g?.name??``),value:y===null?``:Xt(y.action),placeholder:h===0?l(`flow.command.pickDeviceFirst`,`Pick a device first`):l(`flow.command.pickCommand`,`Pick a command`),disabled:h===0||x,searchable:v.length>=8,emptyMessage:l(`flow.command.noCommands`,`This device has no commands to offer.`),onChange:e=>{let t=v.find(t=>Xt(t)===e);t!==void 0&&s(sn(t,h,en(t)))}})]}),y!==null&&o(vn,{action:y.action,values:y.values,deviceName:g?.name??``,locale:d,variables:a,onChange:e=>s(sn(y.action,h,e))})]})}function vn({action:e,values:t,deviceName:n,locale:r,variables:i,onChange:a}){let s=[];return Qt(e.phrase[r]).forEach((c,l)=>{if(c.kind===`text`){s.push(o(`span`,{children:c.text},`t${String(l)}`));return}if(c.key===`device`){s.push(o(`span`,{className:`font-medium`,children:n},`device`));return}let u=e.openArgs.find(e=>e.key===c.key),d=t[c.key];u===void 0||d===void 0||s.push(o(un,{arg:u,locale:r,variables:i,value:d,onChange:e=>a({...t,[c.key]:e})},c.key))}),o(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-2 text-sm`,children:s})}function yn({step:t,devices:n,devicesState:r,onChange:i,onBack:a}){let{t:s}=Y();return e(`div`,{className:`space-y-2`,"data-testid":`command-step-generic`,children:[a!==null&&o(W,{variant:`ghost`,size:`sm`,onClick:a,children:s(`flow.command.backToSentence`,`Back to the sentence`)}),o(jt,{value:t,allowTriggerDevice:!0,allowMultiSameFamily:!0,devices:n,listState:r,onChange:e=>i({kind:`cap`,deviceId:hn(e.deviceId),cap:e.cap,method:e.method,...e.args===void 0?{}:{args:{...e.args}}})})]})}var bn={ran:`success`,failed:`danger`,aborted:`danger`,"skipped-trigger":`neutral`,"skipped-conditions":`warning`,"skipped-cooldown":`neutral`,"skipped-overlap":`neutral`},xn={pass:`border-success/50 bg-success/10`,fail:`border-danger/50 bg-danger/10`,idle:`border-border bg-surface text-foreground-subtle`},Sn={pass:`text-success`,fail:`text-danger`,idle:`text-foreground-subtle`};function Cn(){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`)}}}function wn({traces:t,selectedId:n,onSelect:r}){let{t:i}=Y(),a=Cn(),s=t===void 0?[]:t.toReversed();return o(qe,{headingId:`runs-heading`,title:i(`flow.runs.title`,`Runs`),icon:S,children:t===void 0?o(Fe,{className:`m-3 h-16`}):s.length===0?o(Ce,{title:i(`flow.runs.emptyTitle`,`No runs yet`),description:i(`flow.runs.emptyDescription`,`Each run appears here with what it decided.`)}):e(p,{children:[o(`ul`,{className:`divide-y divide-border-subtle`,"data-testid":`runs-panel`,children:s.map(t=>{let i=t.runId===n;return o(`li`,{children:e(`button`,{type:`button`,"aria-pressed":i,onClick:()=>r(i?null:t.runId),className:`flex w-full flex-col gap-1 px-3 py-2 text-left hover:bg-surface-hover ${i?`bg-primary/10`:``}`,children:[e(`span`,{className:`flex flex-wrap items-center gap-2`,children:[o(q,{variant:bn[t.outcome],children:a(t.outcome)}),t.repeat>1&&o(q,{variant:`neutral`,style:`outline`,children:`x${String(t.repeat)}`}),o(`span`,{className:`text-xs text-foreground-subtle`,children:kt(t.lastAt)})]}),o(`span`,{className:`truncate text-sm text-foreground`,children:t.trigger.reason})]})},t.runId)})}),o(`p`,{className:`border-t border-border-subtle px-3 py-2 text-xs text-foreground-subtle`,children:i(`flow.runs.hint`,`Select a run to colour the blocks: green passed, red failed, grey not evaluated.`)})]})})}function Tn(e){return xn[e]}function En({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`:xn[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 ${Sn[i.tone]}`,children:i.reason}),o(`div`,{className:`space-y-2`,children:a})]})}u();var Dn=6e4;function On(){let e=Se({projection:`slim`});return r(()=>(e.data??[]).filter(e=>V(String(e.type))).map(e=>({id:e.id,name:e.name,stableId:e.stableId,type:String(e.type),location:e.location??null})).toSorted((e,t)=>e.name.localeCompare(t.name)),[e.data])}function kn(e){let t=w();return l({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:Dn,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function An(e,t){return e.find(e=>e.cap===t)?.fields??[]}u();function Z({children:e}){return o(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function jn(e){let t=kn(e.deviceId);if(t.data!==void 0)return An(t.data,e.cap).find(t=>t.path===e.fieldPath)}function Mn({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(Z,{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(g,{className:`size-3.5 shrink-0`})]}),a&&o(Nn,{value:t,devices:n,onCancel:()=>s(!1),onConfirm:e=>{s(!1),r(e)}})]})}function Nn({value:t,devices:n,onCancel:i,onConfirm:a}){let{t:s}=Y(),l=Se({projection:`slim`}),u=r(()=>new Set(n.map(e=>e.id)),[n]),d=r(()=>e=>u.has(e.id),[u]),[f,p]=c(null),[m,h]=c(!1),[g,_]=c(t.cap===``?null:{cap:t.cap,path:t.fieldPath});!m&&l.status===`success`&&(h(!0),p(Mt(l.data).find(e=>e.id===t.deviceId)??null));let v=s(`automation.fieldPicker.title`,`Device value`);return o(Qe,{open:!0,onOpenChange:e=>!e&&i(),children:e(pt,{width:`xl`,children:[o(it,{children:o(Ke,{children:v})}),o(Pt,{kind:`formula`,enabled:!0,hostId:-1,destination:{cap:`automation`,targetId:`field`,title:v,pickerTargetKind:null},device:f,field:g,deviceFilter:d,onDeviceChange:p,onFieldChange:_}),e(st,{className:`flex flex-wrap gap-2`,children:[o(W,{variant:`ghost`,onClick:i,children:s(`common.cancel`,`Cancel`)}),o(W,{disabled:f===null||g===null,"data-testid":`field-picker-confirm`,onClick:()=>{f===null||g===null||a({deviceId:f.id,cap:g.cap,fieldPath:g.path})},children:s(`automation.fieldPicker.use`,`Use this value`)})]})]})})}var Pn=1e4;function Fn(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 In(e,t){return{kind:`action`,actionId:e.actionId,...t===void 0?{}:{variables:t}}}function Ln({step:t,onChange:n}){let{t:r}=Y(),i=ot({},{refetchInterval:Pn});if(i.data===void 0)return o(Fe,{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(Z,{children:r(`automation.runAction.action`,`Action`)}),o(G,{value:t.actionId,onChange:e=>n({kind:`action`,actionId:e.target.value}),options:[{value:``,label:r(`automation.runAction.pick`,`Pick an action`)},...s?[{value:t.actionId,label:r(`automation.runAction.missing`,`Missing action ({{id}})`,{id:t.actionId})}]:[],...i.data.map(e=>({value:e.id,label:e.name}))]})]}),s&&o(`p`,{className:`text-xs text-danger`,children:r(`automation.runAction.missingHint`,`This action no longer exists. Pick another, or the step will fail.`)}),(a?.variables??[]).length>0&&o(`div`,{className:`flex flex-wrap items-end gap-3`,children:(a?.variables??[]).map(e=>o(Rn,{variable:e,value:t.variables?.[e.name],onChange:r=>n(In(t,Fn(t.variables,e.name,r)))},e.name))})]})}function Rn({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(Z,{children:a}),o(qt,{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(Z,{children:a}),o(Kt,{className:`w-40`,placeholder:s,value:typeof n==`number`?n:void 0,onValue:r})]}):e(`label`,{className:`block`,children:[o(Z,{children:a}),o(K,{className:`w-40`,placeholder:s,value:n===void 0?``:String(n),onChange:e=>r(e.target.value===``?null:e.target.value)})]})}var zn=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function Bn(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 zn}}function Vn(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 Hn(e){return Bn(e).map(e=>({value:e,label:Vn(e)}))}function Un(e){switch(e){case`device-state`:return J.t(`helpers.recipeParts.trigger_device_state`);case`device-event`:return J.t(`helpers.recipeParts.trigger_device_event`);case`schedule`:return J.t(`helpers.recipeParts.trigger_schedule`);case`stationary`:return J.t(`flow.trigger.stationary`);case`detection`:return J.t(`flow.trigger.detection`);case`interval`:return J.t(`flow.trigger.interval`);default:return J.t(`helpers.recipeParts.trigger_manual`)}}var Wn={triggers:[],actions:[]};function Gn(e){switch(e){case`device-state`:return{kind:e,deviceId:0,cap:``,fieldPath:``};case`device-event`:return{kind:e,category:``};case`schedule`:return{kind:e,cron:`0 30 23 * * *`};case`detection`:return{kind:e,classes:[],deviceIds:[]};case`stationary`:return{kind:e,deviceIds:[],phase:`appeared`};case`interval`:return{kind:e,minutes:5};default:return{kind:`manual`}}}function Kn(e){switch(e){case`wait`:return{kind:e,seconds:5};case`code`:return{kind:e,code:`// runs inside this automation, with ctx in scope
|
|
4
|
+
`};case`action`:return{kind:e,actionId:``};default:return{kind:`cap`,deviceId:0,cap:``,method:``}}}function qn(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function Jn(){return{kind:`stationary-present`,deviceId:0}}function Yn(){return{kind:`expression`,expr:``,bindings:{}}}function Xn(e,t,n){return e.map((e,r)=>r===t?n:e)}function Zn(e,t){return e.filter((e,n)=>n!==t)}function Qn(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=Zn(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function $n(e,t){return{...e,triggers:[...t]}}function er(e,t){return{...e,actions:[...t]}}var tr=[{value:`cap`,labelKey:`automation.actionList.kindCap`},{value:`action`,labelKey:`automation.actionList.kindAction`},{value:`wait`,labelKey:`automation.actionList.kindWait`},{value:`code`,labelKey:`automation.actionList.kindCode`}];function nr({actions:t,devices:n,devicesState:r=`answered`,allowedKinds:i,variables:a=[],stepTones:s,onChange:c}){let{t:l}=Y(),u=tr.filter(e=>i===void 0||i.includes(e.value));return e(`div`,{className:`space-y-2`,children:[t.length===0&&o(`p`,{className:`text-xs text-warning`,children:l(`automation.actionList.noActionsYetAnAutomation`,`No actions yet. An automation that does nothing is not an automation.`)}),t.map((i,d)=>e(`div`,{className:`space-y-2 rounded border p-3 ${s===void 0?`border-border`:Tn(s[d]??`idle`)}`,children:[e(`div`,{className:`flex flex-wrap items-end gap-2`,children:[o(q,{variant:`default`,children:d+1}),e(`label`,{className:`w-40`,children:[o(Z,{children:l(`automation.actionList.step`,`Step`)}),o(G,{value:i.kind,onChange:e=>c(Xn(t,d,Kn(rr(e.target.value)))),options:u.map(e=>({value:e.value,label:l(e.labelKey)}))})]}),e(`div`,{className:`ml-auto flex items-center gap-1`,children:[o(W,{variant:`ghost`,disabled:d===0,onClick:()=>c(Qn(t,d,d-1)),title:l(`automation.actionList.runThisStepEarlier`,`Run this step earlier`),children:o(m,{className:`h-3.5 w-3.5`})}),o(W,{variant:`ghost`,disabled:d===t.length-1,onClick:()=>c(Qn(t,d,d+1)),title:l(`automation.actionList.runThisStepLater`,`Run this step later`),children:o(O,{className:`h-3.5 w-3.5`})}),o(W,{variant:`ghost`,onClick:()=>c(Zn(t,d)),title:l(`automation.actionList.removeThisStep`,`Remove this step`),children:o(v,{className:`h-3.5 w-3.5`})})]})]}),i.kind===`wait`&&e(`label`,{className:`block w-32`,children:[o(Z,{children:l(`automation.actionList.seconds`,`Seconds`)}),o(K,{type:`number`,min:0,max:300,value:String(i.seconds),onChange:e=>c(Xn(t,d,{kind:`wait`,seconds:Number(e.target.value)}))})]}),i.kind===`code`&&e(`label`,{className:`block`,children:[o(Z,{children:l(`automation.actionList.code`,`Code`)}),o(`textarea`,{className:`h-32 w-full rounded-md border border-border bg-surface p-2 font-mono text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,value:i.code,spellCheck:!1,onChange:e=>c(Xn(t,d,{kind:`code`,code:e.target.value}))}),o(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:o(X,{i18nKey:`automation.actionList.codeHint`,components:{code:o(`code`,{})}})})]}),i.kind===`cap`&&o(_n,{step:i,devices:n,devicesState:r,variables:a,onChange:e=>c(Xn(t,d,e))}),i.kind===`action`&&o(Ln,{step:i,onChange:e=>c(Xn(t,d,e))})]},`${i.kind}-${String(d)}`)),e(`div`,{className:`flex items-center gap-2`,children:[e(W,{variant:`outline`,onClick:()=>c([...t,Kn(u[0]?.value??`cap`)]),children:[o(_,{className:`h-4 w-4`}),` `,l(`automation.actionList.addStep`)]}),t.length>1&&o(`span`,{className:`text-xs text-foreground-subtle`,children:l(`automation.actionList.stepsRunInOrderAnd`,`Steps run in order and stop at the first failure.`)})]})]})}function rr(e){return tr.find(t=>t.value===e)?.value??`cap`}function ir(e,t){return e.map(e=>({name:e.name,hint:e.label??t(`flow.scope.type_${e.type}`,e.type)}))}function ar(e){return[{name:`deviceId`,hint:e(`flow.scope.deviceId`,`the camera that saw it`)},{name:`className`,hint:e(`flow.scope.className`,`what it saw`)},{name:`trackId`,hint:e(`flow.scope.trackId`,`the track`)},{name:`score`,hint:e(`flow.scope.score`,`how sure the detector was`)}]}function or(e){return[{name:`deviceId`,hint:e(`flow.scope.deviceId`,`the camera that saw it`)},{name:`className`,hint:e(`flow.scope.className`,`what it saw`)},{name:`phase`,hint:e(`flow.scope.phase`,`appeared or departed`)},{name:`entryId`,hint:e(`flow.scope.entryId`,`the stopped object`)}]}function sr(e,t){if(e.length===0)return[];let[n,...r]=e.map(e=>e.kind===`detection`?ar(t):e.kind===`stationary`?or(t):[]);return n===void 0?[]:n.filter(e=>r.every(t=>t.some(t=>t.name===e.name)))}var cr=`conditions`;function lr(e){return e===void 0||e.trim()===``?null:e}function ur(e){let t=e.slice(e.lastIndexOf(`.`)+1),n=Number(t);return Number.isInteger(n)?n:0}function dr(e){return e.steps.map(e=>({index:ur(e.path),tone:e.outcome===`ok`?`pass`:e.outcome===`error`?`fail`:`idle`,message:lr(e.message)}))}function fr(e){let t=e.conditions.find(e=>e.path===cr);return t===void 0?null:{tone:t.outcome===`pass`?`pass`:t.outcome===`fail`?`fail`:`idle`,reason:lr(t.reason)}}function pr(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:lr(e.verdict?.reason)}}function mr(e){let t=dr(e);return{when:{tone:e.trigger.outcome===`pass`?`pass`:`fail`,reason:lr(e.trigger.reason)},condition:fr(e),thenBlock:pr(e,t),steps:t}}function hr(e,t){return e===null?null:e.steps.find(e=>e.index===t)?.tone??`idle`}var gr={name:``,steps:[],variables:[]};function _r(e){return e===null?gr:{name:e.name,steps:e.steps??[],variables:e.variables??[]}}function vr(e){let t=[],n=e=>{t.includes(e)||t.push(e)},r=e=>{if(Zt(e)){n(e.$var);return}Array.isArray(e)?e.forEach(r):typeof e==`object`&&e&&Object.values(e).forEach(r)};for(let t of e)t.kind===`cap`&&(r(t.deviceId),r(t.args));return t}function yr(e){let t=new Set(e.variables.map(e=>e.name));return vr(e.steps).find(e=>!t.has(e))??null}function br(e){if(e.name.trim()===``)return{ok:!1,reason:{kind:`name`}};if(e.steps.length===0)return{ok:!1,reason:{kind:`no-steps`}};let t=e.variables.find(e=>!Tr(e.name));if(t!==void 0)return{ok:!1,reason:{kind:`bad-name`,name:t.name}};let n=Er(e.variables)[0];if(n!==void 0)return{ok:!1,reason:{kind:`duplicate`,name:n}};let r=yr(e);if(r!==null)return{ok:!1,reason:{kind:`undeclared`,name:r}};let i=te.safeParse({name:e.name.trim(),steps:e.steps,...e.variables.length===0?{}:{variables:e.variables}});if(!i.success){let e=i.error.issues[0];return{ok:!1,reason:{kind:`schema`,message:`${e===void 0||e.path.length===0?``:`${e.path.join(`.`)}: `}${e?.message??`invalid`}`}}}return{ok:!0,input:i.data}}function xr(e,t,n){return Zt(e)?e.$var===t?{$var:n}:e:Array.isArray(e)?e.map(e=>xr(e,t,n)):typeof e==`object`&&e?Object.fromEntries(Object.entries(e).map(([e,r])=>[e,xr(r,t,n)])):e}function Sr(e,t,n){if(e.kind!==`cap`)return e;let r=Zt(e.deviceId)&&e.deviceId.$var===t?{$var:n}:e.deviceId,i=e.args===void 0?void 0:Object.fromEntries(Object.entries(e.args).map(([e,r])=>[e,xr(r,t,n)]));return{...e,deviceId:r,...i===void 0?{}:{args:i}}}function Cr(e,t,n){let r=e.variables[t];return r===void 0||r.name===n?e:{...e,variables:e.variables.map((e,r)=>r===t?{...e,name:n}:e),steps:e.steps.map(e=>Sr(e,r.name,n))}}function wr(e){let t=new Set(e.map(e=>e.name)),n=`value`;for(let e=2;t.has(n);e++)n=`value${String(e)}`;return{name:n,type:`string`}}function Tr(e){return/^[A-Za-z_][A-Za-z0-9_]*$/.test(e)}function Er(e){let t=new Set,n=new Set;for(let r of e)t.has(r.name)&&n.add(r.name),t.add(r.name);return[...n]}var Dr=[`number`,`string`,`boolean`,`select`];function Or(e,t){return{name:e.name,...e.label===void 0?{}:{label:e.label},type:t,...t===`select`?{options:e.options??[`option`]}:{}}}function kr(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 Ar(e,t){let{default:n,...r}=e;return t===null?r:{...r,default:t}}function jr(e,t){let{label:n,...r}=e;return t.trim()===``?r:{...r,label:t}}function Mr({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(qe,{headingId:`vars-heading`,title:i(`actions.variables.title`,`Variables`),icon:_e,actions:e(W,{variant:`outline`,size:`sm`,onClick:()=>n([...t,wr(t)]),children:[o(_,{className:`h-4 w-4`}),` `,i(`actions.variables.add`,`Variable`)]}),children:e(`div`,{className:`space-y-3 p-3`,children:[t.map((c,l)=>e(`div`,{className:`grid gap-2 sm:grid-cols-[1fr_1fr_8rem_1fr_1.2fr_auto] sm:items-end`,"data-testid":`variable-row`,children:[e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.name`,`Name`)}),o(K,{"aria-label":i(`actions.variables.nameAria`,`Variable name`),value:c.name,"aria-invalid":!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(K,{"aria-label":i(`actions.variables.label`,`Label`),value:c.label??``,onChange:e=>s(l,jr(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(qt,{widthClass:`w-full`,"aria-label":i(`actions.variables.type`,`Type`),value:c.type,options:Dr.map(e=>({value:e,label:a(e)})),onChange:e=>{let t=Dr.find(t=>t===e.target.value);t!==void 0&&s(l,Or(c,t))}})]}),e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.default`,`Default`)}),o(Nr,{variable:c,onChange:e=>s(l,Ar(c,e))})]}),e(`label`,{className:`space-y-1`,children:[o(`span`,{className:`text-xs text-foreground-subtle`,children:i(`actions.variables.options`,`Options`)}),o(K,{"aria-label":i(`actions.variables.options`,`Options`),value:(c.options??[]).join(`, `),disabled:c.type!==`select`,placeholder:i(`actions.variables.optionsHint`,`Only for a select`),onChange:e=>s(l,kr(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(v,{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 Nr({variable:e,onChange:t}){let{t:n}=Y(),r=n(`actions.variables.default`,`Default`);if(e.type===`number`)return o(Kt,{"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(qt,{widthClass:`w-full`,"aria-label":r,value:e.default===void 0?``:String(e.default),options:[{value:``,label:n(`actions.variables.noDefault`,`None`)},...i],onChange:n=>{n.target.value===``?t(null):t(e.type===`boolean`?n.target.value===`true`:n.target.value)}})}return o(K,{"aria-label":r,value:typeof e.default==`string`?e.default:``,onChange:e=>t(e.target.value===``?null:e.target.value)})}u();var Pr=5e3;function Fr(e){return e.kind===`cap`||e.kind===`wait`}function Ir(e){return e instanceof Error?e.message:String(e)}function Lr(){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 Rr({entry:t,onClose:n,onSaved:i}){let{t:a}=Y(),s=d(),l=k(),u=On(),f=Lr(),[m,h]=c(()=>_r(t)),[g,_]=c(null),b=t!==null&&t.readOnly,x=()=>{s.invalidateQueries({queryKey:[[`actions`]]})},S=Ze({onSuccess:e=>{x(),i(e.action.id)}}),C=vt({onSuccess:x}),w=et({onSuccess:()=>{x(),n()}}),D=nt({onSuccess:x}),O=ut({actionId:t?.id??`none`},{enabled:t!==null,refetchInterval:Pr}),A=O.data?.traces.find(e=>e.runId===g)??null,j=r(()=>A===null?null:mr(A),[A]),M=br(m),N=r(()=>ir(m.variables,a),[m.variables,a]),P=S.isPending||C.isPending,F=S.error??C.error??w.error??D.error,I=(t?.variables??[]).some(e=>e.required===!0&&e.default===void 0);return e(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]`,"data-testid":`action-editor`,children:[e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(E,{className:`h-4 w-4 text-foreground-muted`}),o(K,{"aria-label":a(`actions.editor.name`,`Name`),className:`max-w-xs flex-1`,value:m.name,disabled:b,placeholder:a(`actions.editor.namePlaceholder`,`What this action does`),onChange:e=>h({...m,name:e.target.value})}),o(q,{variant:b?`info`:`primary`,children:b?t?.addonId??``:a(`actions.source.internal`,`Internal`)})]}),b?o(`p`,{className:`rounded-md border border-border bg-surface p-3 text-sm text-foreground-muted`,children:a(`actions.editor.readOnly`,`This action is declared by {{addon}}. Edit it there; you can run it from here.`,{addon:t?.addonId??``})}):e(p,{children:[o(Mr,{variables:m.variables,onChange:e=>h({...m,variables:e}),onRename:(e,t)=>h(Cr(m,e,t))}),o(En,{step:`steps`,title:a(`actions.editor.steps`,`Steps`),trace:j===null?null:j.thenBlock,children:o(nr,{actions:m.steps,devices:u,allowedKinds:[`cap`,`wait`],variables:N,onChange:e=>h({...m,steps:e.filter(Fr)})})})]}),!M.ok&&!b&&m.name!==``&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:f(M.reason)}),F!==null&&o(U,{message:Ir(F)}),e(`div`,{className:`flex flex-wrap gap-2`,children:[!b&&e(W,{onClick:()=>{M.ok&&(t===null?S.mutate({action:M.input}):C.mutate({actionId:t.id,action:M.input}))},disabled:P||!M.ok,children:[P&&o(T,{className:`h-4 w-4 animate-spin`}),` `,a(`common.save`,`Save`)]}),t!==null&&e(W,{variant:`outline`,disabled:D.isPending||I,title:I?a(`actions.editor.runNeedsDefaults`,`Give each required variable a default to run it from here.`):void 0,onClick:()=>D.mutate({actionId:t.id}),children:[o(y,{className:`h-4 w-4`}),` `,a(`actions.editor.runNow`,`Run now`)]}),t!==null&&!b&&e(W,{variant:`ghost`,disabled:w.isPending,onClick:()=>{l({title:a(`actions.editor.deleteTitle`,`Delete this action?`),message:a(`actions.editor.deleteMessage`,`{{name}} will be deleted, and removed from every camera that links it.`,{name:t.name}),confirmLabel:a(`common.delete`,`Delete`),variant:`danger`}).then(e=>{e&&w.mutate({actionId:t.id})})},children:[o(v,{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(wn,{traces:t===null?[]:O.data?.traces,selectedId:g,onSelect:_})})]})}u();var zr=5e3;function Br(e){return e instanceof Error?e.message:String(e)}function Vr(){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 Hr({createRequested:t=!1,onCreateConsumed:n}){let{t:i}=Y(),a=d(),c=Vr(),{state:l,openNew:u,openEdit:f,close:m}=tt({editKey:`action`,newKey:`new`}),h=ot({},{refetchInterval:zr}),g=nt({onSuccess:()=>void a.invalidateQueries({queryKey:[[`actions`]]})});s(()=>{t&&(u(),n?.())},[t,n,u]);let v=h.data??[],b=l.mode===`edit`?v.find(e=>e.id===l.id)??null:null,x=r(()=>[{key:`name`,header:i(`actions.list.name`,`Name`),render:e=>o(`span`,{className:`font-medium`,children:e.name}),sortValue:e=>e.name},{key:`source`,header:i(`actions.list.source`,`Source`),render:e=>e.readOnly?o(q,{variant:`info`,children:e.addonId}):o(q,{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:`-`}):kt(e.status.lastRunAt),sortValue:e=>e.status.lastRunAt},{key:`status`,header:i(`actions.list.status`,`Status`),render:e=>{let t=c(e);return o(`span`,{title:e.status.lastError??void 0,children:o(q,{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:g.isPending||t.status.isRunning,"aria-label":i(`actions.list.runAria`,`Run {{name}}`,{name:t.name}),onClick:e=>{e.stopPropagation(),g.mutate({actionId:t.id})},children:[o(y,{className:`h-4 w-4`}),` `,i(`actions.list.run`,`Run`)]}),notSortableReason:i(`actions.list.runNotSortable`,`A control`)}],[g,c,i]);return l.mode===`closed`?e(`div`,{className:`space-y-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:i(`actions.list.hint`,`Actions are things this installation can do. Run one here, link it to a camera, or use it in an automation.`)}),g.error!=null&&o(U,{message:Br(g.error)}),h.data===void 0?h.error==null?o(Fe,{className:`h-24 w-full`}):o(U,{title:i(`actions.list.couldNotRead`,`Could not read the actions`),message:Br(h.error),onRetry:()=>void h.refetch()}):v.length===0?o(Ce,{icon:E,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:u,children:[o(_,{className:`h-4 w-4`}),` `,i(`actions.list.new`,`New action`)]})}):e(p,{children:[h.error!=null&&o(U,{title:i(`actions.list.couldNotRead`,`Could not read the actions`),message:Br(h.error),onRetry:()=>void h.refetch()}),o(Be,{columns:x,rows:v,rowKey:e=>e.id,pageSize:25,maxBodyHeight:be,emptyMessage:i(`actions.list.emptyTitle`,`No actions yet`),onRowClick:e=>f(e.id)})]})]}):o(Rr,{entry:b,onClose:m,onSaved:f},b?.id??`new`)}function Ur({value:t,field:n,deviceId:r,cap:i,onChange:a}){let{t:s}=Y(),c=Yr(n,r,i);if(n?.kind===`boolean`)return o(G,{value:t===!0?`true`:`false`,onChange:e=>a(e.target.value===`true`),options:[{value:`true`,label:s(`common.true`)},{value:`false`,label:s(`common.false`)}]});if(n?.kind===`enum`&&n.enumValues!==void 0&&n.enumValues.length>0)return o(G,{value:String(t),onChange:e=>a(e.target.value),options:n.enumValues.map(e=>({value:e,label:e}))});if(n?.kind===`number`){let n=typeof t==`number`&&c?c.toDisplayValue(t):t;return e(`span`,{className:`inline-flex items-center gap-1`,children:[o(K,{type:`number`,value:typeof n==`number`?String(n):``,placeholder:`0`,onChange:e=>{let t=Number(e.target.value);e.target.value!==``&&!Number.isNaN(t)&&a(c?c.fromDisplayValue(t):t)}}),c!==void 0&&c.unit.length>0?o(`span`,{className:`text-xs text-foreground-subtle`,children:c.unit}):null]})}return o(K,{value:String(t),placeholder:s(`common.valueWord`),onChange:e=>a(e.target.value)})}function Wr({value:e,field:t,deviceId:n,cap:r,onChange:i}){let{t:a}=Y(),s=Yr(t,n,r);return o(K,{value:(s?e.map(e=>typeof e==`number`?s.toDisplayValue(e):e):e).join(`, `),placeholder:a(`automation.valueInput.oneTwoThree`,`one, two, three`),onChange:e=>{let n=e.target.value.split(`,`).map(e=>e.trim()).filter(e=>e!==``);i(t?.kind===`number`?n.map(e=>Number(e)).filter(e=>!Number.isNaN(e)).map(e=>s?s.fromDisplayValue(e):e):n)}})}function Gr(e){return typeof e==`object`}function Kr(e){return Gr(e)?e[0]??``:e}function qr(e){return Gr(e)?e:typeof e==`boolean`?[]:[e]}function Jr(e,t){if(!(e===void 0||e===`none`)){if(e!==`device`)return e;if(!(t===void 0||t===`device`||t===`none`))return t}}function Yr(e,t,n){let r=t??0,i=e?.kind===`number`&&e.quantity!==void 0,{data:a}=xe({deviceId:r},{enabled:i&&r>0}),o=a?.sourceInfo?.quantity,s=ee(o)?o:void 0,c=Jr(e?.quantity,s);if(c===void 0)return;let l=a?.display;return Ge({quantity:c,display:l,capName:n})}function Xr({leaf:t,devices:n,onChange:r}){let{t:i}=Y(),a={deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath},s=jn(a),c=Hn(s?.kind),l=t.operator===`in`,u=e=>{r({...t,deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath})},d=e=>{let n=Zr(e,c);r({...t,operator:n,value:n===`in`?qr(t.value):Kr(t.value)})};return e(`div`,{className:`flex flex-wrap items-end gap-2`,children:[o(Mn,{value:a,devices:n,onChange:u}),e(`label`,{className:`min-w-[8rem]`,children:[o(Z,{children:i(`automation.conditionRow.comparison`,`Comparison`)}),o(G,{value:t.operator,onChange:e=>d(e.target.value),options:c.map(e=>({value:e.value,label:e.label}))})]}),e(`label`,{className:`min-w-[9rem] flex-1`,children:[o(Z,{children:i(`automation.conditionRow.value`,`Value`)}),l?o(Wr,{value:qr(t.value),field:s,deviceId:t.deviceId,cap:t.cap,onChange:e=>r({...t,value:e})}):o(Ur,{value:Kr(t.value),field:s,deviceId:t.deviceId,cap:t.cap,onChange:e=>r({...t,value:e})})]})]})}function Zr(e,t){return t.find(t=>t.value===e)?.value??`eq`}var Qr={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function $r({leaf:t,devices:n,onChange:r}){let{t:i}=Y(),a=Object.entries(t.bindings),s=e=>{r({kind:`expression`,expr:t.expr,bindings:e})};return e(`div`,{className:`space-y-2`,children:[e(`label`,{className:`block`,children:[o(Z,{children:i(`automation.expressionLeafRow.expression`,`Expression`)}),o(K,{value:t.expr,placeholder:i(`automation.expressionLeafRow.indoorOutdoor5`,`indoor - outdoor > 5`),onChange:e=>r({kind:`expression`,expr:e.target.value,bindings:t.bindings})}),o(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:i(`automation.expressionLeafRow.mustEvaluateToTrueOr`,`Must evaluate to true or false. Every name in it has to be bound below — an unbound name is refused when the automation is saved, not when it runs.`)})]}),e(`div`,{className:`space-y-1.5`,children:[a.length===0&&o(`p`,{className:`text-xs text-foreground-subtle`,children:i(`automation.expressionLeafRow.noNamesBoundYetAn`,`No names bound yet. An expression reads devices only through these.`)}),a.map(([e,r])=>o(ei,{alias:e,source:r,devices:n,onRename:n=>s(oi(t.bindings,e,n)),onChange:n=>s({...t.bindings,[e]:n}),onRemove:()=>s(si(t.bindings,e))},e)),e(W,{variant:`ghost`,onClick:()=>s({...t.bindings,[ai(t.bindings)]:Qr}),children:[o(_,{className:`h-3.5 w-3.5`}),` `,i(`common.name`)]})]})]})}function ei({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:ri(r,ni(n)),cap:n.cap,fieldPath:n.fieldPath};return e(`div`,{className:`flex flex-wrap items-end gap-2 rounded border border-border p-2`,children:[e(`label`,{className:`w-32`,children:[o(Z,{children:c(`automation.expressionLeafRow.name`,`Name`)}),o(K,{value:t,placeholder:c(`automation.expressionLeafRow.aliasExample`),onChange:e=>i(e.target.value)})]}),e(`label`,{className:`w-36`,children:[o(Z,{children:c(`automation.expressionLeafRow.reads`,`Reads`)}),o(G,{value:l?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:Qr),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(Z,{children:c(`automation.expressionLeafRow.constant`,`Constant`)}),o(K,{value:n.value===null?``:String(n.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:ti(e.target.value)})})]}):o(Mn,{value:u,devices:r,onChange:e=>a({kind:`global`,sourceStableId:ii(r,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),o(W,{variant:`ghost`,onClick:s,title:c(`automation.expressionLeafRow.removeThisName`,`Remove this name`),children:o(v,{className:`h-3.5 w-3.5`})})]})}function ti(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function ni(e){return e.kind===`global`?e.sourceStableId:``}function ri(e,t){return e.find(e=>e.stableId===t)?.id??0}function ii(e,t){return e.find(e=>e.id===t)?.stableId??``}function ai(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 oi(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function si(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function ci(e){return e.kind===`all`||e.kind===`any`}function Q(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:ci(t)?t:{kind:`all`,children:[t]}}function li(e,t){return t===null||ci(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function ui(e){return li(e,Q(e))}function di(e,t){if(t.length===0)return e;let[n,...r]=t;if(n===void 0)return e;if(e.kind===`not`)return n===0?di(e.child,r):null;if(!ci(e))return null;let i=e.children[n];return i===void 0?null:di(i,r)}function fi(e,t,n){if(t.length===0)return n(e);let[r,...i]=t;if(r===void 0)return n(e);if(e.kind===`not`){if(r!==0)return e;let t=fi(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!ci(e))return e;let a=e.children[r];if(a===void 0)return e;let o=fi(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 pi(e){return e===null?null:ce({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function mi(e){let t=Q(e);return{depth:t.children.length===0?0:ie(t),leaves:t.children.length===0?0:de(t),depthLimit:3,leafLimit:32}}function hi(e,t){let n=pi(t);return n===null?{ok:!0,recipe:li(e,t)}:{ok:!1,reason:n}}function gi(e,t){let n=Q(e);return hi(e,{kind:n.kind,children:[...n.children,t]})}function _i(e,t,n){return li(e,fi(Q(e),t,()=>n))}function vi(e,t){return li(e,fi(Q(e),t,()=>null))}function yi(e,t,n){return li(e,fi(Q(e),t,e=>ci(e)?{kind:n,children:e.children}:e))}function bi(e,t){return di(Q(e),t)===null?{ok:!1,reason:J.t(`helpers.recipeOps.rowGone`)}:hi(e,fi(Q(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function xi(e){if(e.length===0)return null;let t=e[e.length-1];return t===void 0?null:{path:e.slice(0,-1),index:t}}function Si(e,t,n){if(t.length<2)return{ok:!1,reason:J.t(`helpers.recipeOps.selectTwo`)};if(new Set(t.map(e=>e.slice(0,-1).join(`/`))).size!==1)return{ok:!1,reason:J.t(`helpers.recipeOps.differentGroups`)};let r=xi(t[0]??[]);if(r===null)return{ok:!1,reason:J.t(`helpers.recipeOps.rootGroup`)};let i=Q(e),a=di(i,r.path);if(a===null||!ci(a))return{ok:!1,reason:J.t(`helpers.recipeOps.insideNot`)};let o=[...t.map(e=>e[e.length-1]??-1)].sort((e,t)=>e-t),s=o.map(e=>a.children[e]).filter(e=>e!==void 0);if(s.length!==o.length)return{ok:!1,reason:J.t(`helpers.recipeOps.selectedGone`)};let c=a.children.filter((e,t)=>!o.includes(t)),l=o[0]??0,u={kind:n,children:s},d={kind:a.kind,children:[...c.slice(0,l),u,...c.slice(l)]};return hi(e,fi(i,r.path,()=>d))}function Ci(e,t){if(t.length===0)return{ok:!1,reason:J.t(`helpers.recipeOps.outerNotGroup`)};let n=Q(e),r=di(n,t);if(r===null)return{ok:!1,reason:J.t(`helpers.recipeOps.groupGone`)};if(r.kind===`not`)return hi(e,fi(n,t,()=>r.child));if(!ci(r))return{ok:!1,reason:J.t(`helpers.recipeOps.rowIsCondition`)};let i=xi(t);if(i===null)return{ok:!1,reason:J.t(`helpers.recipeOps.noParent`)};let a=di(n,i.path);if(a===null||!ci(a))return{ok:!1,reason:J.t(`helpers.recipeOps.groupInNot`)};let o={kind:a.kind,children:[...a.children.slice(0,i.index),...r.children,...a.children.slice(i.index+1)]};return hi(e,fi(n,i.path,()=>o))}var wi=`text-xs text-foreground-subtle`;function Ti({children:e}){return o(`span`,{className:wi,children:e})}function Ei(e,t){return e.includes(t)?e.filter(e=>e!==t):[...e,t]}function Di(){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 t}}}function Oi({selected:t,onChange:n,hint:r}){let{t:i}=Y(),a=Di(),s=ne.map(e=>e.id),c=t.filter(e=>!s.includes(e));return e(`div`,{className:`space-y-1`,children:[o(Ti,{children:i(`flow.scene.class`,`Class`)}),o(`div`,{className:`flex flex-wrap gap-2`,children:[...s,...c].map(e=>o(W,{size:`sm`,variant:t.includes(e)?`primary`:`outline`,"aria-pressed":t.includes(e),onClick:()=>n(Ei(t,e)),children:a(e)},e))}),r!==void 0&&o(`p`,{className:wi,children:r})]})}function ki({devices:t,selected:n,onChange:r}){let{t:i}=Y(),a=t.filter(e=>e.type===re.Camera);return e(`div`,{className:`space-y-1`,children:[o(Ti,{children:i(`flow.scene.cameras`,`Cameras`)}),o(mn,{devices:a,selection:`multiple`,noun:`camera`,value:n,testId:`scene-cameras`,onChange:r})]})}function Ai({device:t,deviceId:n,selected:r,onToggle:i}){let a=Ye({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:wi,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 ji({devices:t,deviceIds:n,selected:r,onChange:i}){let{t:a}=Y();if(n.length===0)return null;let s=e=>{let t=Ei(r,e);i(t.length===0?void 0:t)};return e(`div`,{className:`space-y-1`,children:[o(Ti,{children:a(`flow.scene.zones`,`Zones`)}),o(`div`,{className:`space-y-2`,children:n.map(e=>o(Ai,{device:t.find(t=>t.id===e),deviceId:e,selected:r,onToggle:s},e))}),o(`p`,{className:wi,children:r.length===0?a(`flow.scene.wholeScene`,`None picked: the whole scene counts.`):a(`flow.scene.zonesPicked`,`Only these zones count.`)})]})}var Mi=100;function Ni({trigger:t,devices:n,onChange:r}){let{t:i}=Y(),a=Math.round((t.minScore??0)*Mi),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/Mi})};return e(`div`,{className:`w-full space-y-3`,"data-testid":`detection-fields`,children:[o(Oi,{selected:t.classes,onChange:e=>r({...t,classes:[...e]})}),o(ki,{devices:n,selected:t.deviceIds,onChange:e=>r({...t,deviceIds:[...e]})}),o(ji,{devices:n,deviceIds:t.deviceIds,selected:t.zones??[],onChange:s}),e(`div`,{className:`space-y-1`,children:[o(Ti,{children:a===0?i(`flow.scene.minScoreAny`,`Minimum score: any`):i(`flow.scene.minScore`,`Minimum score: {{value}}`,{value:(a/Mi).toFixed(2)})}),o(`input`,{type:`range`,min:0,max:Mi,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 Pi({trigger:t,devices:n,onChange:r}){let{t:i}=Y();return e(`div`,{className:`w-full space-y-3`,"data-testid":`stationary-fields`,children:[o(Oi,{selected:t.classes??[],onChange:e=>{let{classes:n,...i}=t;r(e.length===0?i:{...i,classes:[...e]})},hint:t.classes===void 0?i(`flow.scene.anyClass`,`None picked: any class counts.`):void 0}),o(ki,{devices:n,selected:t.deviceIds,onChange:e=>r({...t,deviceIds:[...e]})}),o(ji,{devices:n,deviceIds:t.deviceIds,selected:t.zones??[],onChange:e=>{let{zones:n,...i}=t;r(e===void 0?i:{...i,zones:[...e]})}}),o(ht,{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 Fi({trigger:t,onChange:n}){let{t:r}=Y();return e(`div`,{className:`flex items-center gap-2`,"data-testid":`interval-fields`,children:[o(Ti,{children:r(`flow.scene.every`,`Every`)}),o(Kt,{"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(Ti,{children:r(`flow.scene.minutes`,`minutes`)})]})}function Ii({leaf:t,devices:n,onChange:r}){let{t:i}=Y(),a=n.filter(e=>e.type===re.Camera),s=e=>{let{classes:n,...i}=t;r(e.length===0?i:{...i,classes:[...e]})},c=e=>{let{zones:n,...i}=t;r(e===void 0?i:{...i,zones:[...e]})},l=e=>{let{zones:n,...i}=t;r({...i,deviceId:e})};return e(`div`,{className:`space-y-3`,"data-testid":`stationary-present-fields`,children:[e(`div`,{className:`space-y-1`,children:[o(Ti,{children:i(`flow.scene.parkedOn`,`An object is parked on`)}),o(mn,{devices:a,selection:`single`,noun:`camera`,value:t.deviceId>0?[t.deviceId]:[],testId:`stationary-present-camera`,onChange:e=>{let n=e[0];n!==void 0&&n!==t.deviceId&&l(n)}})]}),o(Oi,{selected:t.classes??[],onChange:s,hint:t.classes===void 0?i(`flow.scene.anyClass`,`None picked: any class counts.`):void 0}),o(ji,{devices:n,deviceIds:t.deviceId>0?[t.deviceId]:[],selected:t.zones??[],onChange:c})]})}u();var Li=[{value:`all`,labelKey:`automation.conditionTree.allOf`},{value:`any`,labelKey:`automation.conditionTree.anyOf`}];function Ri(e){return e.join(`/`)}function zi(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function Bi({recipe:t,devices:n,onChange:i}){let{t:a}=Y(),[s,l]=c([]),[u,d]=c(null),f=Q(t),p=mi(t),m=r(()=>s.map(zi),[s]),h=e=>{if(!e.ok){d(e.reason);return}d(null),l([]),i(e.recipe)},g=Si(t,m,`all`),v=Si(t,m,`any`),y=m.length===1?bi(t,m[0]??[]):{ok:!1,reason:a(`automation.conditionTree.selectOneNegate`)},x={devices:n,selected:new Set(s),onToggleSelect:e=>l(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),onUpdate:(e,n)=>i(_i(t,e,n)),onRemove:e=>{l([]),i(vi(t,e))},onSetKind:(e,n)=>i(yi(t,e,n)),onUngroup:e=>h(Ci(t,e))};return e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(q,{variant:`default`,children:a(`automation.conditionTree.andOnlyIf`,`And only if`)}),o(`div`,{className:`w-32`,children:o(G,{value:f.kind,onChange:e=>i(yi(t,[],Vi(e.target.value))),options:Li.map(e=>({value:e.value,label:a(e.labelKey)}))})}),o(`span`,{className:`text-xs text-foreground-subtle`,children:a(`automation.conditionTree.budget`,{depth:p.depth,depthLimit:p.depthLimit,leaves:p.leaves,leafLimit:p.leafLimit})})]}),f.children.length===0?o(`p`,{className:`text-xs text-foreground-subtle`,children:a(`automation.conditionTree.noConditionsTheActionsRun`,`No conditions. The actions run every time a trigger fires.`)}):o(Hi,{container:f,path:[],handlers:x}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(W,{variant:`outline`,onClick:()=>h(gi(t,qn())),title:a(`automation.conditionTree.compareOneDeviceFieldTo`,`Compare one device field to a value`),children:[o(_,{className:`h-4 w-4`}),` `,a(`automation.conditionTree.addCondition`)]}),e(W,{variant:`outline`,onClick:()=>h(gi(t,Yn())),title:a(`automation.conditionTree.arithmeticAcrossDeviceFieldsThe`,`Arithmetic across device fields — the bounded expression engine`),children:[o(H,{className:`h-4 w-4`}),` `,a(`automation.conditionTree.addExpression`)]}),e(W,{variant:`outline`,onClick:()=>h(gi(t,Jn())),title:a(`flow.scene.addParkedTitle`,`True while an object is parked on a camera, in a zone`),children:[o(b,{className:`h-4 w-4`}),` `,a(`flow.scene.addParked`,`Parked object`)]}),o(`span`,{className:`mx-1 h-5 w-px bg-border`}),o(W,{variant:`ghost`,disabled:!g.ok,onClick:()=>h(g),title:g.ok?a(`automation.conditionTree.allSelectedRowsMustBe`,`All selected rows must be true`):g.reason,children:a(`automation.conditionTree.groupAsAll`,`Group as ALL`)}),o(W,{variant:`ghost`,disabled:!v.ok,onClick:()=>h(v),title:v.ok?a(`automation.conditionTree.anyOneOfTheSelected`,`Any one of the selected rows is enough`):v.reason,children:a(`automation.conditionTree.groupAsAny`,`Group as ANY`)}),o(W,{variant:`ghost`,disabled:!y.ok,onClick:()=>h(y),title:y.ok?a(`automation.conditionTree.invertTheSelectedRow`,`Invert the selected row`):y.reason,children:`NOT`}),s.length>0&&o(`span`,{className:`text-xs text-foreground-subtle`,children:a(`common.selectedCount`,{count:s.length})})]}),u!==null&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-2 text-xs text-warning`,children:u})]})}function Vi(e){return e===`any`?`any`:`all`}function Hi({container:e,path:t,handlers:n}){return o(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>o(Ui,{node:e,path:[...t,r],handlers:n},Ri([...t,r])))})}function Ui({node:t,path:n,handlers:r}){let{t:i}=Y(),a=Ri(n),s=o(He,{checked:r.selected.has(a),onChange:()=>r.onToggleSelect(a),"aria-label":i(`automation.conditionTree.selectThisRowForGrouping`,`Select this row for grouping`)});return ci(t)?e(`div`,{className:`rounded border border-border bg-surface-subtle/40 p-2`,children:[e(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[s,o(`div`,{className:`w-32`,children:o(G,{value:t.kind,onChange:e=>r.onSetKind(n,Vi(e.target.value)),options:Li.map(e=>({value:e.value,label:i(e.labelKey)}))})}),e(W,{variant:`ghost`,onClick:()=>r.onUngroup(n),title:i(`automation.conditionTree.dissolveThisGroupKeepingIts`,`Dissolve this group, keeping its rows`),children:[o(he,{className:`h-3.5 w-3.5`}),` `,i(`automation.conditionTree.ungroup`)]}),o(W,{variant:`ghost`,onClick:()=>r.onRemove(n),title:i(`automation.conditionTree.deleteThisGroupAndEverything`,`Delete this group and everything in it`),children:o(v,{className:`h-3.5 w-3.5`})})]}),o(`div`,{className:`pl-4`,children:o(Hi,{container:t,path:n,handlers:r})})]}):t.kind===`not`?e(`div`,{className:`rounded border border-border p-2`,children:[e(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[s,o(q,{variant:`warning`,children:`NOT`}),e(W,{variant:`ghost`,onClick:()=>r.onUngroup(n),title:i(`automation.conditionTree.removeTheNotKeepingThe`,`Remove the NOT, keeping the row`),children:[o(he,{className:`h-3.5 w-3.5`}),` `,i(`automation.conditionTree.removeNot`)]})]}),o(`div`,{className:`pl-4`,children:o(Ui,{node:t.child,path:[...n,0],handlers:r})})]}):e(`div`,{className:`flex items-start gap-2 rounded border border-border p-2`,children:[o(`div`,{className:`pt-6`,children:s}),o(`div`,{className:`min-w-0 flex-1`,children:t.kind===`condition`?o(Xr,{leaf:t,devices:r.devices,onChange:e=>r.onUpdate(n,e)}):t.kind===`expression`?o($r,{leaf:t,devices:r.devices,onChange:e=>r.onUpdate(n,e)}):o(Ii,{leaf:t,devices:r.devices,onChange:e=>r.onUpdate(n,e)})}),o(W,{variant:`ghost`,onClick:()=>r.onRemove(n),title:i(`automation.conditionTree.removeThisCondition`,`Remove this condition`),children:o(v,{className:`h-3.5 w-3.5`})})]})}u();function Wi({code:t,error:n,canEject:r,ejecting:i,onEject:a}){let{t:s}=Y(),[l,u]=c(!1),d=k(),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?g: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(ve,{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(rt,{maxHeight:420,children:t})})]})}var Gi=[`detection`,`stationary`,`device-state`,`device-event`,`schedule`,`interval`,`manual`],Ki={detection:`scene`,stationary:`scene`,"device-state":`device`,"device-event":`device`,schedule:`time`,interval:`time`,manual:`manual`};function qi(){let{t:e}=Y(),t={scene:e(`flow.triggerGroup.scene`,`Scene`),device:e(`flow.triggerGroup.device`,`Devices`),time:e(`flow.triggerGroup.time`,`Time`),manual:e(`flow.triggerGroup.manual`,`By hand`)},n={detection:e(`flow.triggerHint.detection`,`An object class is detected on a camera`),stationary:e(`flow.triggerHint.stationary`,`An object stops, or leaves`),"device-state":e(`flow.triggerHint.deviceState`,`A device value changes or takes a value`),"device-event":e(`flow.triggerHint.deviceEvent`,`An event on the system`),schedule:e(`flow.triggerHint.schedule`,`At a time of day`),interval:e(`flow.triggerHint.interval`,`Again and again, every few minutes`),manual:e(`flow.triggerHint.manual`,`Only when you run it`)};return Gi.map(e=>({value:e,label:Un(e),description:n[e],group:t[Ki[e]]}))}var Ji=Object.values(ue).sort((e,t)=>e.localeCompare(t));function Yi({triggers:t,devices:n,onChange:r}){let{t:i}=Y();return e(`div`,{className:`space-y-2`,children:[t.length===0&&o(`p`,{className:`text-xs text-warning`,children:i(`automation.triggerEditor.noTriggersYetWithoutOne`,`No triggers yet. Without one nothing can ever start this automation — not even "Run actions", which needs a manual trigger to have somewhere to arrive.`)}),t.map((e,i)=>o(Xi,{trigger:e,devices:n,position:i,onChange:e=>r(Xn(t,i,e)),onRemove:()=>r(Zn(t,i))},`${e.kind}-${String(i)}`)),e(W,{variant:`outline`,onClick:()=>r([...t,Gn(`device-state`)]),title:i(`automation.triggerEditor.addAnotherWayThisAutomation`,`Add another way this automation can start`),children:[o(_,{className:`h-4 w-4`}),` `,i(`automation.triggerEditor.trigger`)]})]})}function Xi({trigger:t,devices:n,position:r,onChange:i,onRemove:a}){let{t:s}=Y(),c=qi();return e(`div`,{className:`rounded border border-border p-3`,children:[e(`div`,{className:`flex flex-wrap items-end gap-2`,children:[o(q,{variant:`default`,children:r===0?s(`automation.triggerEditor.when`,`When`):s(`automation.triggerEditor.orWhen`,`or when`)}),e(`div`,{className:`min-w-[13rem] flex-1`,children:[o(Z,{children:s(`automation.triggerEditor.trigger`,`Trigger`)}),o(Le,{mode:`single`,singleDisplay:`field`,options:c,value:t.kind,onChange:e=>{e!==t.kind&&i(Gn(Zi(e)))}})]}),o(W,{variant:`ghost`,onClick:a,title:s(`automation.triggerEditor.removeThisTrigger`,`Remove this trigger`),children:o(v,{className:`h-4 w-4`})})]}),e(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:[t.kind===`device-state`&&o($i,{trigger:t,devices:n,onChange:i}),t.kind===`device-event`&&o(ta,{trigger:t,devices:n,onChange:i}),t.kind===`schedule`&&e(`label`,{className:`min-w-[14rem] flex-1`,children:[o(Z,{children:s(`automation.triggerEditor.cronExpression`,`Cron expression`)}),o(K,{value:t.cron,placeholder:`0 30 23 * * *`,onChange:e=>i({kind:`schedule`,cron:e.target.value})}),o(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:o(X,{i18nKey:`automation.triggerEditor.cronHint`,components:{code:o(`code`,{})}})})]}),t.kind===`detection`&&o(Ni,{trigger:t,devices:n,onChange:i}),t.kind===`stationary`&&o(Pi,{trigger:t,devices:n,onChange:i}),t.kind===`interval`&&o(Fi,{trigger:t,onChange:i}),t.kind===`manual`&&o(`p`,{className:`text-xs text-foreground-subtle`,children:o(X,{i18nKey:`automation.triggerEditor.manualHint`,components:{b:o(`strong`,{})}})})]})]})}function Zi(e){return Gi.find(t=>t===e)??`manual`}function Qi(e,t){return{kind:`device-state`,deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath,...t.becomes===void 0?{}:{becomes:t.becomes},...t.edge===void 0?{}:{edge:t.edge},...t.forMs===void 0?{}:{forMs:t.forMs},...t.debounceMs===void 0?{}:{debounceMs:t.debounceMs}}}function $i({trigger:t,devices:n,onChange:r}){let{t:i}=Y(),a={deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath},s=jn(a),c={...t.becomes===void 0?{}:{becomes:t.becomes},...t.edge===void 0?{}:{edge:t.edge},...t.forMs===void 0?{}:{forMs:t.forMs},...t.debounceMs===void 0?{}:{debounceMs:t.debounceMs}};return e(p,{children:[o(Mn,{value:a,devices:n,onChange:e=>r(Qi(e,c))}),e(`div`,{className:`min-w-[11rem] flex-1`,children:[o(Z,{children:i(`automation.triggerEditor.becomes`,`Becomes`)}),e(`div`,{className:`flex items-center gap-2`,children:[e(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[o(He,{checked:t.becomes===void 0,onChange:e=>r(Qi(a,{...c,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),i(`automation.triggerEditor.anyChange`,`any change`)]}),t.becomes!==void 0&&o(Ur,{value:t.becomes,field:s,deviceId:a.deviceId,cap:a.cap,onChange:e=>r(Qi(a,{...c,becomes:e}))})]})]}),e(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[o(He,{checked:t.edge===!0,onChange:e=>r(Qi(a,{...c,...e.target.checked?{edge:!0}:{edge:void 0}}))}),i(`automation.triggerEditor.onlyOnAChange`,`only on a change`)]}),e(`label`,{className:`w-28`,children:[o(Z,{children:i(`automation.triggerEditor.heldForS`,`Held for (s)`)}),o(K,{type:`number`,min:0,value:t.forMs===void 0?``:String(t.forMs/1e3),placeholder:`0`,onChange:e=>r(Qi(a,{...c,forMs:ea(e.target.value)}))})]}),e(`label`,{className:`w-28`,children:[o(Z,{children:i(`automation.triggerEditor.debounceS`,`Debounce (s)`)}),o(K,{type:`number`,min:0,value:t.debounceMs===void 0?``:String(t.debounceMs/1e3),placeholder:`0`,onChange:e=>r(Qi(a,{...c,debounceMs:ea(e.target.value)}))})]})]})}function ea(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function ta({trigger:t,devices:n,onChange:r}){let{t:i}=Y();return e(p,{children:[e(`label`,{className:`min-w-[15rem] flex-1`,children:[o(Z,{children:i(`automation.triggerEditor.eventCategory`,`Event category`)}),o(G,{value:t.category,onChange:e=>r({kind:`device-event`,category:e.target.value,...t.deviceId===void 0?{}:{deviceId:t.deviceId}}),options:[{value:``,label:i(`automation.triggerEditor.selectAnEvent`,`Select an event…`)},...Ji.map(e=>({value:e,label:e}))]})]}),e(`div`,{className:`min-w-[11rem] flex-1`,children:[o(Z,{children:i(`automation.triggerEditor.fromDevice`,`From device`)}),o(mn,{devices:n,selection:`single`,value:t.deviceId===void 0?[]:[t.deviceId],emptyLabel:i(`automation.triggerEditor.anyDevice`,`Any device`),testId:`trigger-event-device`,onChange:e=>r({kind:`device-event`,category:t.category,...e[0]===void 0?{}:{deviceId:e[0]}})})]})]})}var na=[`single`,`restart`,`queued`,`parallel`,`cooldown`],ra=2,ia=30;function aa(e){return e.runMode??{mode:`single`}}function oa(e,t){let{runMode:n,...r}=e;return t.mode===`single`?r:{...r,runMode:t}}function sa(e){switch(e){case`queued`:return{mode:`queued`,max:ra};case`parallel`:return{mode:`parallel`,max:ra};case`cooldown`:return{mode:`cooldown`,minutes:ia};case`restart`:return{mode:`restart`};default:return{mode:`single`}}}function ca(e){return na.find(t=>t===e)??`single`}function la({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(qt,{widthClass:`w-56`,value:t.mode,options:na.map(e=>({value:e,label:i[e]})),onChange:e=>n(sa(ca(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(Kt,{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(Kt,{className:`w-20`,"aria-label":r(`flow.runMode.minutes`,`Minutes`),value:t.minutes,onValue:e=>{e!==null&&n({mode:`cooldown`,minutes:Math.round(e)})}})]}),o(`p`,{className:`basis-full text-xs text-foreground-subtle`,children:a[t.mode]})]})}u();var ua=`hub`,da=5e3;function fa({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(()=>ui(n)),[_,v]=c(!1),[y,b]=c(null),x=Ue({blockId:t?.id??`none`},{enabled:t!==null,refetchInterval:da}),S=x.data?.traces.find(e=>e.runId===y)??null,C=r(()=>S===null?null:mr(S),[S]),w=r(()=>sr(h.triggers,f),[h.triggers,f]),E=On(),D=ce(h),O=r(()=>pa(h),[h]),k=r(()=>ma(p.trim()===``?`Untitled automation`:p.trim(),h),[p,h]),A=p.trim()===``,j=A||D!==null||O!==null||k.code===null;return e(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]`,"data-testid":`automation-editor`,children:[e(`div`,{className:`space-y-4`,children:[o(`div`,{className:`flex flex-wrap items-center gap-2`,children:o(q,{variant:`info`,children:f(`automation.automationEditor.runsOnTheHub`,`runs on the hub`)})}),e(`label`,{className:`block max-w-md text-sm`,children:[o(`span`,{className:`text-foreground-subtle`,children:f(`automation.automationEditor.name`,`Name`)}),o(K,{className:`mt-1`,value:p,onChange:e=>m(e.target.value),placeholder:f(`automation.automationEditor.whatThisAutomationDoes`,`What this automation does`)})]}),o(En,{step:`when`,title:f(`automation.automationEditor.when`,`When`),trace:C===null?null:C.when,hint:f(`automation.automationEditor.anyOneOfTheseStarts`,`Any one of these starts a run.`),children:o(Yi,{triggers:h.triggers,devices:E,onChange:e=>g($n(h,e))})}),o(En,{step:`if`,title:f(`automation.automationEditor.andOnlyIf`,`And only if`),trace:C===null?null:C.condition,hint:f(`automation.automationEditor.checkedAfterATriggerFires`,`Checked after a trigger fires. Nothing runs unless this is true.`),children:o(Bi,{recipe:h,devices:E,onChange:g})}),o(En,{step:`then`,title:f(`automation.automationEditor.then`,`Then`),trace:C===null?null:C.thenBlock,hint:f(`automation.automationEditor.inThisOrderStoppingAt`,`In this order, stopping at the first failure.`),children:o(nr,{actions:h.actions,devices:E,variables:w,stepTones:C===null?void 0:h.actions.map((e,t)=>hr(C,t)??`idle`),onChange:e=>g(er(h,e))})}),o(En,{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(la,{value:aa(h),onChange:e=>g(oa(h,e))})}),o(Wi,{code:k.code,error:k.error,canEject:t!==null,ejecting:s,onEject:u}),D!==null&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:D}),D===null&&O!==null&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:O}),a!==null&&o(`p`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:a}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(W,{onClick:()=>{k.code!==null&&l({name:p.trim(),code:k.code,enabled:t?.enabled??!0,placement:ua})},disabled:i||j,children:[i&&o(T,{className:`h-4 w-4 animate-spin`}),` `,f(`common.save`)]}),e(W,{variant:`ghost`,onClick:()=>v(!_),disabled:t===null,title:t===null?f(`automation.automationEditor.logsAppearOnceTheAutomation`,`Logs appear once the automation has been saved and started`):f(`automation.automationEditor.showThisAutomationSProcess`,`Show this automation's process logs`),"data-testid":`automation-logs-toggle`,children:[o(N,{className:`h-4 w-4`}),` `,f(`common.logs`),` `,_?`▾`:`▸`]}),o(W,{variant:`ghost`,onClick:d,disabled:i,children:f(`common.close`,`Close`)}),A&&o(q,{variant:`warning`,children:f(`automation.automationEditor.nameRequired`,`Name required`)})]}),_&&t!==null&&e(`div`,{className:`rounded border border-border`,"data-testid":`automation-logs-panel`,children:[o(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:o(X,{i18nKey:`common.logsOf`,values:{id:ae(t.id)},components:{code:o(`code`,{})}})}),o($e,{addonId:ae(t.id),maxHeight:`max-h-64`,showFilters:!1})]})]}),o(`div`,{className:`order-first lg:order-last`,children:o(wn,{traces:t===null?[]:x.data?.traces,selectedId:y,onSelect:b})})]})}function pa(e){let t=F.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 ma(e,t){try{return{code:B({name:e,recipe:t}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function ha(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 ga(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function _a(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function va(e){let t=e=>{let t=ha(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 ya(e){if(e.length===0)return J.t(`helpers.coreBlockStatus.noBlocks`);let t=e.filter(e=>ha(e).tone===`error`).length,n=e.filter(e=>ha(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(` · `)}function ba({block:t,busy:n,logsOpen:r,unreadable:i,onEdit:a,onToggle:s,onToggleLogs:c,onDelete:l}){let u=D(),{t:d}=Y(),f=ha(t),p=Ae(t.updatedAt,u);return e(`li`,{className:`flex flex-col gap-2 p-3`,children:[e(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[e(`div`,{className:`min-w-0 flex-1`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(`span`,{className:`truncate font-medium`,children:t.name}),o(q,{variant:ga(f.tone),children:f.label}),p!==null&&o(`span`,{className:`text-xs text-foreground-subtle`,children:d(`common.edited`,{when:p})})]}),o(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:f.detail}),i!==null&&o(`p`,{className:`mt-0.5 text-xs text-warning`,children:d(`automation.editor.listUnreadable`,{reason:i})})]}),e(`div`,{className:`flex justify-end gap-1`,children:[o(W,{variant:`ghost`,onClick:e=>{e.stopPropagation(),a()},disabled:i!==null,title:i===null?d(`common.edit`,`Edit`):d(`automation.automationList.thisBlockCannotBeOpened`,`This block cannot be opened visually`),children:o(C,{className:`h-4 w-4`})}),e(ft,{children:[o(at,{children:o(W,{variant:`ghost`,disabled:!0,title:d(`automation.automationList.runActions`,`Run actions`),children:o(y,{className:`h-4 w-4`})})}),o(lt,{children:d(`automation.automationList.runningAnAutomationByHand`,`Running an automation by hand needs the automation-control authority, which is not wired up yet. There is deliberately no second way to execute one.`)})]}),o(W,{variant:`ghost`,onClick:e=>{e.stopPropagation(),c()},title:d(`automation.automationList.logs`,`Logs`),children:o(N,{className:`h-4 w-4`})}),o(W,{variant:`ghost`,onClick:e=>{e.stopPropagation(),s(!t.enabled)},disabled:n,title:t.enabled?d(`common.disable`,`Disable`):d(`common.enable`,`Enable`),children:t.enabled?d(`common.disable`,`Disable`):d(`common.enable`,`Enable`)}),o(W,{variant:`ghost`,onClick:e=>{e.stopPropagation(),l()},title:d(`common.delete`,`Delete`),children:o(v,{className:`h-4 w-4`})})]})]}),r&&e(`div`,{className:`rounded border border-border`,children:[o(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:o(X,{i18nKey:`common.logsOf`,values:{id:ae(t.id)},components:{code:o(`code`,{})}})}),o($e,{addonId:ae(t.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function xa({onCreate:t}){let{t:n}=Y();return o(Je,{children:e(`div`,{className:`space-y-2 p-4`,children:[o(`p`,{className:`text-sm text-foreground`,children:n(`automation.automationList.noAutomationsYet`,`No automations yet.`)}),o(`p`,{className:`max-w-2xl text-xs text-foreground-subtle`,children:n(`automation.automationList.anAutomationIsATrigger`,`An automation is a trigger, a set of conditions and a list of actions. It compiles to an ordinary block and runs in its own supervised process — there is no separate engine, so anything that goes wrong shows up here with a reason.`)}),o(W,{onClick:t,children:n(`automation.automationList.newAutomation`,`New automation`)})]})})}u();var Sa=[`coreBlocks`,`list`],Ca=5e3;function wa(e){return e instanceof Error?e.message:String(e)}function Ta({onOpenScripts:t,initialBlockId:i,onBlockIdChange:a,createRequested:u=!1,onCreateConsumed:d}){let{t:p}=Y(),m=w(),{state:h,openNew:g,openEdit:_,close:v}=tt({editKey:`block`,newKey:`new`}),[y,b]=c(null),x=k(),[S,C]=c(null),T=n(null),E=h.mode!==`closed`;s(()=>{u&&(b(null),g(),a?.(null),d?.())},[u,d,a,g]);let D=l({queryKey:Sa,refetchInterval:Ca,queryFn:async()=>(await m.trpcClient.coreBlocks.list.query({})).blocks}),O=()=>{D.refetch()},j=D.data;s(()=>{i===void 0||T.current===i||j?.find(e=>e.id===i&&Vt(e.code))!==void 0&&(T.current=i,_(i),a?.(i))},[i,j,_,a]);let M=f({mutationFn:e=>m.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{b(e.block),_(e.block.id),a?.(e.block.id),O()}}),N=f({mutationFn:e=>m.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{b(e.block),_(e.block.id),a?.(e.block.id),O()}}),P=f({mutationFn:e=>m.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:O}),F=f({mutationFn:e=>m.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:O}),I=f({mutationFn:e=>m.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:Wt(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:e=>{v(),b(null),O(),t(e.block.id)}}),L=D.data,R=va((L??[]).filter(e=>Vt(e.code))),ee=L!==void 0&&R.length===0,z=h.mode===`edit`?R.find(e=>e.id===h.id)??(y!==null&&y.id===h.id?y:null):null,B=h.mode===`new`||z===null?null:_a(R,z),te=B===null?null:Ut(B.code),ne=M.error===null?N.error===null?I.error===null?null:wa(I.error):wa(N.error):wa(M.error),re=r(()=>[{key:`row`,header:p(`build.automationsTab.automation`,`Automation`),nowrap:!1,notSortableReason:`Composite status row`,render:e=>{let t=Ut(e.code);return o(`ul`,{className:`list-none`,children:o(ba,{block:e,busy:F.isPending||P.isPending,logsOpen:S===e.id,unreadable:t.ok?null:t.reason,onEdit:()=>{b(e),_(e.id),a?.(e.id)},onToggle:t=>F.mutate({blockId:e.id,enabled:t}),onToggleLogs:()=>C(S===e.id?null:e.id),onDelete:()=>{x({title:p(`automation.automationList.deleteThisAutomation`,`Delete this automation?`),message:p(`automation.automationList.deleteMessage`,`{{name}} will be deleted. This cannot be undone.`,{name:e.name}),confirmLabel:p(`common.delete`,`Delete`),variant:`danger`}).then(t=>{t&&P.mutate(e.id)})}})})},sortValue:e=>e.name}],[x,S,a,_,P,F,p]);return E?e(`div`,{className:`space-y-3`,"data-testid":`automation-editor-panel`,children:[e(`h3`,{className:`flex items-center gap-2 text-sm font-semibold`,children:[o(A,{className:`h-4 w-4 text-foreground-muted`}),B===null?p(`build.automationsTab.newAutomation`,`New automation`):p(`build.automationsTab.edit`,`Edit {{name}}`,{name:B.name})]}),o(fa,{existing:B,initialRecipe:te!==null&&te.ok?te.recipe:Wn,saving:M.isPending||N.isPending,saveError:ne,ejecting:I.isPending,onSave:e=>{B===null?M.mutate(e):N.mutate({blockId:B.id,block:e})},onEject:()=>{B!==null&&I.mutate(B)},onCancel:()=>{M.reset(),N.reset(),I.reset(),b(null),v(),a?.(null)}},B?.id??`new`),P.error!=null&&o(U,{message:wa(P.error)})]}):e(`div`,{className:`space-y-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:L===void 0?``:ya(R)}),D.error!=null&&o(U,{title:p(`build.automationsTab.couldNotReadTheAutomations`,`Could not read the automations`),message:wa(D.error),onRetry:O}),ee?o(xa,{onCreate:()=>{b(null),g(),a?.(null)}}):o(Be,{columns:re,rows:R,rowKey:e=>e.id,pageSize:25,maxBodyHeight:be,emptyMessage:L===void 0?p(`build.automationsTab.loadingAutomations`,`Loading automations…`):p(`build.automationsTab.noAutomationsYet`,`No automations yet.`),onRowClick:e=>{b(e),_(e.id),a?.(e.id)}}),P.error!=null&&o(U,{message:wa(P.error)}),F.error!=null&&o(U,{message:wa(F.error)})]})}u();function Ea({mode:e,onTitle:t}){return o(e===`helper`?Da:Oa,{onTitle:t})}function Da({onTitle:e}){let{t}=Y(),r=St(),i=we(),a=Oe(),l=Ne({addonId:`composer`}),[u,d]=c(null),[f,p]=c(!1),m=Aa(u,t);s(()=>{f||e(m)},[e,m,f]);let h=n(null);return f?o(Oa,{onTitle:e}):o(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3`,"data-testid":`composition-create-form`,children:o(It,{fillHeight:!0,onFreeComposition:()=>p(!0),purpose:`create`,initial:null,start:`template`,saving:i.isPending,onDraftChange:d,onSave:async(e,n)=>{let o=null,s=await Ft(e,async(s,c)=>{let u=h.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,h.current={draft:e,blockId:d}}let f=await Pa(d,async()=>(await l.refetch()).data??l.data);if(f===null)throw Error(t(`helper.devicePending`));o=f,h.current=null,c!==``&&await a.mutateAsync({deviceId:f,name:c}),n===`open`&&r(Ct(f),{replace:!0})}),c=o;return s.length>0||c===null?{kind:`refused`,lines:Fa(s,t)}:{kind:`saved`,deviceId:c}}})})}function Oa({onTitle:t}){let{t:n}=Y(),r=D(),i=St(),a=we(),l=Oe(),u=Ne({addonId:`composer`}),[d,f]=c(re.Sensor),[p,m]=c(fe.TemperatureSensor),[h,g]=c(``),[_,v]=c(null),y=Nt({type:d,role:p});return s(()=>{t(n(`helper.newComposition`))},[t,n]),e(`div`,{className:`flex flex-col gap-3`,"data-testid":`blank-composition-form`,children:[e(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[n(`compositionEditor.targetType`),o(G,{value:d,onChange:e=>{let t=Object.values(re).find(t=>t===e.target.value);t!==void 0&&f(t)},options:Object.values(re).map(e=>({value:e,label:Ie(e,r).label}))})]}),e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[n(`customize.identity.role`),o(G,{value:p??``,onChange:e=>m(Object.values(fe).find(t=>t===e.target.value)??null),options:[{value:``,label:n(`customize.identity.noRole`)},...Object.values(fe).map(e=>({value:e,label:Me(e,r).label}))]})]}),e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[n(`compositionEditor.name`),o(K,{"aria-label":n(`compositionEditor.name`),value:h,onChange:e=>g(e.target.value)})]})]}),_!==null&&o(`p`,{role:`alert`,className:`text-xs text-danger`,children:_}),o(W,{disabled:y===null||a.isPending,onClick:()=>{y!==null&&ka({composition:y,name:h,create:e=>a.mutateAsync({block:e}),rename:(e,t)=>l.mutateAsync({deviceId:e,name:t}),readFleet:async()=>(await u.refetch()).data??u.data,onError:e=>v(e),onOpen:e=>i(Tt(e),{replace:!0}),pending:n(`helper.devicePending`)})},children:n(`compositionEditor.save`)})]})}async function ka(e){e.onError(null);try{let t=e.name.trim(),{block:n}=await e.create({...t===``?{}:{name:t},enabled:!0,composition:e.composition}),r=await Pa(n.id,e.readFleet);if(r===null){e.onError(e.pending);return}t!==``&&await e.rename(r,t),e.onOpen(r)}catch(t){e.onError(t instanceof Error?t.message:String(t))}}function Aa(e,t){if(e===null)return t(`helper.newComposed`);if(e.kind===`statistic`)return t(`helper.newTitle.statistic`);if(e.kind===`integral`)return t(`helper.newTitle.integral`);if(e.kind===`arithmetic`)return t(`helper.newTitle.${e.op}`);if(e.kind===`threshold`||e.kind===`expression`||e.kind===`derivative`)return t(`helper.newTitle.${e.kind}`);if(e.templateId===`appliance`&&e.appliance!==null)return t(`helper.newTitle.${e.appliance}`);if(e.templateId===`appliance`)return t(`helper.newComposed`);let n=pe(e.templateId);return t(n===null?`helper.newComposed`:`helper.newTitle.${n.id}`)}async function ja(e,t){let n=`${L}${e}`;return(await t())?.find(e=>e.stableId===n)?.id??null}var Ma=10,Na=400;async function Pa(e,t,n=Na){for(let r=0;r<Ma;r+=1){let r=await ja(e,t);if(r!==null)return r;await new Promise(e=>setTimeout(e,n))}return null}function Fa(e,t){return e.length>0?e:Lt(t(`helper.devicePending`))}function Ia(e){let t=e.helper;if(t===void 0)return{section:`advanced`,kind:null};switch(t.kind){case`group`:return{section:`group`,kind:t.templateId};case`appliance`:return{section:`group`,kind:`appliance`};case`arithmetic`:return{section:`calculation`,kind:t.op};case`expression`:return{section:`advanced`,kind:`expression`};default:return{section:`calculation`,kind:t.kind}}}function La(e){return{state:`answered`,byRef:new Map(e.map(e=>[z(e),e]))}}function Ra(e,t){if(e.state!==`unanswered`)return e.byRef.get(z(t))??null}function za(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function Ba(e){return R(e).map(e=>e.source)}function Va(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(...Ba(t));for(let t of Object.values(e.items??{}))for(let e of Object.values(t.fields))n.push(...Ba(e))}let r=new Set;return n.filter(e=>{let t=z(e);return r.has(t)?!1:(r.add(t),!0)})}function Ha(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 Ua(e,t){let n=e.reason??t??null;switch(e.status){case`running`:return Ha(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 Wa(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 Ua(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 Ga(e){return z(e)}function Ka(e,t){let n=Ra(t,e);return{key:z(e),label:n?n.name:Ga(e),presence:za(n),deviceId:n?n.id:null}}function qa(e){return e.state.kind===`answered`&&e.state.state!==null?e.state.state.deviceId:null}function Ja(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:I(e.block.id),a=z(i),o=Va(e).filter(e=>z(e)!==a).map(e=>Ka(e,t)),s=n.features.map(e=>e.enabled===!1?J.t(`helpers.compositionRows.featureOff`,{cap:e.cap}):e.cap),c=Ra(t,i),l=qa(e),u=Wa(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:Ia(n),features:s,state:u,sources:o,reportedDeviceId:l};let d=za(c);return{blockId:e.block.id,kind:`customization`,name:c?c.name:Ga(r.device),namePresence:d,type:c?c.type:null,origin:Ia(n),features:s,state:u,sources:o,reportedDeviceId:l}}function Ya(e){return e.state.tone===`error`?0:e.state.tone===`pending`?1:e.state.tone===`ok`?2:3}function Xa(e,t){return Ya(e)-Ya(t)||e.name.localeCompare(t.name)}function Za(e,t){let n=e.flatMap(e=>{let n=Ja(e,t);return n===null?[]:[n]});return{composed:n.filter(e=>e.kind===`composed`).toSorted(Xa),customizations:n.filter(e=>e.kind===`customization`).toSorted(Xa)}}u();var Qa=1e4;function $a(e){return e instanceof Error?e.message:typeof e==`object`&&e&&`message`in e?String(e.message):String(e)}function eo(){let e=wt();return e.data===void 0?{state:`unanswered`,reason:e.error==null?J.t(`build.customDeviceTab.deviceListPending`):J.t(`build.customDeviceTab.deviceListUnreadable`,{error:$a(e.error)})}:La(e.data)}function to(e,t){return e===`blank`?`blank`:e===`helper`||e===`1`||t?`helper`:null}function no({createRequested:t=!1,onCreateConsumed:n}={}){let{t:r}=Y(),[i,a]=Dt(),s=Ve({},{refetchInterval:Qa}),l=eo(),u=tt({editKey:`block`,newKey:`new`}),d=u.state.mode===`edit`?u.state.id:null,f=d===null?to(i.get(`new`),t):null,m=f!==null,[h,g]=c(``),_=k(),v=Ee(),y=()=>{u.close(),a(()=>{let e=new URLSearchParams(window.location.search);return e.delete(`new`),e.delete(`block`),e},{replace:!0}),n?.()},b=s.data;return e(p,{children:[io(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(dt,{open:m||d!==null,onClose:y,title:m?h||r(f===`blank`?`helper.newComposition`:`helper.newComposed`):r(`build.customDeviceTab.editComposedDevice`,`Edit composed device`),icon:me,width:`xl`,testId:`composed-device-editor`,fill:!0,children:m&&f!==null?o(Ea,{mode:f,onTitle:g},f):d===null?null:o(Rt,{blockId:d,fillHeight:!0})}),v.error!=null&&o(U,{message:$a(v.error)})]})}function ro(t){return o(Je,{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 io(e,t,n,r,i){if(t!=null&&e===void 0)return o(U,{title:J.t(`build.customDeviceTab.couldNotReadTheCompositions`,`Could not read the compositions`),message:$a(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 ro(e.reason);let a=t==null?null:$a(t);return o(ao,{lists:Za(e.views,r),fleet:r,refreshError:a,handlers:i})}function ao({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(oo,{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(oo,{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 oo({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(Be,{columns:so(i,s,c,l),rows:r,rowKey:e=>e.blockId,pageSize:25,maxBodyHeight:be,emptyMessage:a,onRowClick:s===`composed`?e=>c.onEditComposed(e.blockId):void 0})]})}function so(t,n,r,i){let a=[{key:`name`,header:t,sortValue:e=>e.name.toLowerCase(),render:e=>o(lo,{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=>co(e.origin,i),render:e=>o(q,{variant:`default`,"data-testid":`composed-origin-badge`,children:co(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(q,{variant:ga(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(fo,{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(v,{className:`h-4 w-4`})})]})}),a}function co(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 lo({row:t}){let{t:n}=Y();return e(`div`,{className:`space-y-0.5`,children:[o(uo,{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 uo({row:e}){let{t}=Y(),n=De(e.reportedDeviceId??0,`compact`,e.name),r=e.reportedDeviceId===null?e.name:n;return e.reportedDeviceId===null?e.kind===`composed`?o(`span`,{className:`text-xs font-medium text-foreground`,children:e.name}):o(`span`,{className:`text-xs text-foreground-subtle`,children:t(`build.customDeviceTab.notReported`,{name:r})}):o(Et,{to:e.kind===`composed`?Ct(e.reportedDeviceId):Tt(e.reportedDeviceId),className:`text-xs font-medium text-foreground hover:underline`,onClick:e=>e.stopPropagation(),children:r})}function fo({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(Et,{to:`/devices/${String(t.deviceId)}`,className:`hover:underline`,children:t.label}),t.presence===`missing`&&o(`span`,{className:`ml-1.5 text-[10px] text-danger`,children:n(`common.missing`)})]},t.key))})}function po(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 mo(e){if(Array.isArray(e))return e}function ho(e,t,n){return(t=wo(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function go(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 _o(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
5
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function vo(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function yo(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?vo(Object(n),!0).forEach(function(t){ho(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):vo(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function bo(e,t){if(e==null)return{};var n,r,i=xo(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function xo(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function So(e,t){return mo(e)||go(e,t)||To(e,t)||_o()}function Co(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function wo(e){var t=Co(e,`string`);return typeof t==`symbol`?t:t+``}function To(e,t){if(e){if(typeof e==`string`)return po(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?po(e,t):void 0}}function Eo(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Do(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function Oo(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Do(Object(n),!0).forEach(function(t){Eo(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Do(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function ko(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}}function Ao(e){return function t(){var n=this,r=[...arguments];return r.length>=e.length?e.apply(this,r):function(){var e=[...arguments];return t.apply(n,[].concat(r,e))}}}function jo(e){return{}.toString.call(e).includes(`Object`)}function Mo(e){return!Object.keys(e).length}function No(e){return typeof e==`function`}function Po(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Fo(e,t){return jo(t)||Bo(`changeType`),Object.keys(t).some(function(t){return!Po(e,t)})&&Bo(`changeField`),t}function Io(e){No(e)||Bo(`selectorType`)}function Lo(e){No(e)||jo(e)||Bo(`handlerType`),jo(e)&&Object.values(e).some(function(e){return!No(e)})&&Bo(`handlersType`)}function Ro(e){e||Bo(`initialIsRequired`),jo(e)||Bo(`initialType`),Mo(e)&&Bo(`initialContent`)}function zo(e,t){throw Error(e[t]||e.default)}var Bo=Ao(zo)({initialIsRequired:`initial state is required`,initialType:`initial state should be an object`,initialContent:`initial state shouldn't be an empty object`,handlerType:`handler should be an object or a function`,handlersType:`all handlers should be a functions`,selectorType:`selector should be a function`,changeType:`provided value of changes should be an object`,changeField:`it seams you want to change a field in the state which is not specified in the "initial" state`,default:"an unknown error accured in `state-local` package"}),Vo={changes:Fo,selector:Io,handler:Lo,initial:Ro};function Ho(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};Vo.initial(e),Vo.handler(t);var n={current:e},r=Ao(Go)(n,t),i=Ao(Wo)(n),a=Ao(Vo.changes)(e),o=Ao(Uo)(n);function s(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(e){return e};return Vo.selector(e),e(n.current)}function c(e){ko(r,i,a,o)(e)}return[s,c]}function Uo(e,t){return No(t)?t(e.current):t}function Wo(e,t){return e.current=Oo(Oo({},e.current),t),t}function Go(e,t,n){return No(t)?t(e.current):Object.keys(n).forEach(function(n){return t[n]?.call(t,e.current[n])}),n}var Ko={create:Ho},qo={paths:{vs:`https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs`}};function Jo(e){return function t(){var n=this,r=[...arguments];return r.length>=e.length?e.apply(this,r):function(){var e=[...arguments];return t.apply(n,[].concat(r,e))}}}function Yo(e){return{}.toString.call(e).includes(`Object`)}function Xo(e){return e||es(`configIsRequired`),Yo(e)||es(`configType`),e.urls?(Zo(),{paths:{vs:e.urls.monacoBase}}):e}function Zo(){console.warn($o.deprecation)}function Qo(e,t){throw Error(e[t]||e.default)}var $o={configIsRequired:`the configuration object is required`,configType:`the configuration object should be an object`,default:"an unknown error accured in `@monaco-editor/loader` package",deprecation:`Deprecation warning!
|
|
6
|
+
You are using deprecated way of configuration.
|
|
7
|
+
|
|
8
|
+
Instead of using
|
|
9
|
+
monaco.config({ urls: { monacoBase: '...' } })
|
|
10
|
+
use
|
|
11
|
+
monaco.config({ paths: { vs: '...' } })
|
|
12
|
+
|
|
13
|
+
For more please check the link https://github.com/suren-atoyan/monaco-loader#config
|
|
14
|
+
`},es=Jo(Qo)($o),ts={config:Xo},ns=function(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}};function rs(e,t){return Object.keys(t).forEach(function(n){t[n]instanceof Object&&e[n]&&Object.assign(t[n],rs(e[n],t[n]))}),yo(yo({},e),t)}var is={type:`cancelation`,msg:`operation is manually canceled`};function as(e){var t=!1,n=new Promise(function(n,r){e.then(function(e){return t?r(is):n(e)}),e.catch(r)});return n.cancel=function(){return t=!0},n}var os=[`monaco`],ss=So(Ko.create({config:qo,isInitialized:!1,resolve:null,reject:null,monaco:null}),2),cs=ss[0],ls=ss[1];function us(e){var t=ts.config(e),n=t.monaco,r=bo(t,os);ls(function(e){return{config:rs(e.config,r),monaco:n}})}function ds(){var e=cs(function(e){return{monaco:e.monaco,isInitialized:e.isInitialized,resolve:e.resolve}});if(!e.isInitialized){if(ls({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),as(vs);if(window.monaco&&window.monaco.editor)return gs(window.monaco),e.resolve(window.monaco),as(vs);ns(fs,ms)(hs)}return as(vs)}function fs(e){return document.body.appendChild(e)}function ps(e){var t=document.createElement(`script`);return e&&(t.src=e),t}function ms(e){var t=cs(function(e){return{config:e.config,reject:e.reject}}),n=ps(`${t.config.paths.vs}/loader.js`);return n.onload=function(){return e()},n.onerror=t.reject,n}function hs(){var e=cs(function(e){return{config:e.config,resolve:e.resolve,reject:e.reject}}),t=window.require;t.config(e.config),t([`vs/editor/editor.main`],function(t){var n=t.m||t;gs(n),e.resolve(n)},function(t){e.reject(t)})}function gs(e){cs().monaco||ls({monaco:e})}function _s(){return cs(function(e){return e.monaco})}var vs=new Promise(function(e,t){return ls({resolve:e,reject:t})}),ys={config:us,init:ds,__getMonacoInstance:_s};u();var bs={wrapper:{display:`flex`,position:`relative`,textAlign:`initial`},fullWidth:{width:`100%`},hide:{display:`none`}},xs={container:{display:`flex`,height:`100%`,width:`100%`,justifyContent:`center`,alignItems:`center`}};function Ss({children:e}){return t.createElement(`div`,{style:xs.container},e)}var Cs=Ss;function ws({width:e,height:n,isEditorReady:r,loading:i,_ref:a,className:o,wrapperProps:s}){return t.createElement(`section`,{style:{...bs.wrapper,width:e,height:n},...s},!r&&t.createElement(Cs,null,i),t.createElement(`div`,{ref:a,style:{...bs.fullWidth,...!r&&bs.hide},className:o}))}var Ts=i(ws);function Es(e){s(e,[])}var Ds=Es;function Os(e,t,r=!0){let i=n(!0);s(i.current||!r?()=>{i.current=!1}:e,t)}var $=Os;function ks(){}function As(e,t,n,r){return js(e,r)||Ms(e,t,n,r)}function js(e,t){return e.editor.getModel(Ns(e,t))}function Ms(e,t,n,r){return e.editor.createModel(t,n,r?Ns(e,r):void 0)}function Ns(e,t){return e.Uri.parse(t)}function Ps({original:e,modified:r,language:i,originalLanguage:o,modifiedLanguage:l,originalModelPath:u,modifiedModelPath:d,keepCurrentOriginalModel:f=!1,keepCurrentModifiedModel:p=!1,theme:m=`light`,loading:h=`Loading...`,options:g={},height:_=`100%`,width:v=`100%`,className:y,wrapperProps:b={},beforeMount:x=ks,onMount:S=ks}){let[C,w]=c(!1),[T,E]=c(!0),D=n(null),O=n(null),k=n(null),A=n(S),j=n(x),M=n(!1);Ds(()=>{let e=ys.init();return e.then(e=>(O.current=e)&&E(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>D.current?F():e.cancel()}),$(()=>{if(D.current&&O.current){let t=D.current.getOriginalEditor(),n=As(O.current,e||``,o||i||`text`,u||``);n!==t.getModel()&&t.setModel(n)}},[u],C),$(()=>{if(D.current&&O.current){let e=D.current.getModifiedEditor(),t=As(O.current,r||``,l||i||`text`,d||``);t!==e.getModel()&&e.setModel(t)}},[d],C),$(()=>{let e=D.current.getModifiedEditor();e.getOption(O.current.editor.EditorOption.readOnly)?e.setValue(r||``):r!==e.getValue()&&(e.executeEdits(``,[{range:e.getModel().getFullModelRange(),text:r||``,forceMoveMarkers:!0}]),e.pushUndoStop())},[r],C),$(()=>{D.current?.getModel()?.original.setValue(e||``)},[e],C),$(()=>{let{original:e,modified:t}=D.current.getModel();O.current.editor.setModelLanguage(e,o||i||`text`),O.current.editor.setModelLanguage(t,l||i||`text`)},[i,o,l],C),$(()=>{O.current?.editor.setTheme(m)},[m],C),$(()=>{D.current?.updateOptions(g)},[g],C);let N=a(()=>{if(!O.current)return;j.current(O.current);let t=As(O.current,e||``,o||i||`text`,u||``),n=As(O.current,r||``,l||i||`text`,d||``);D.current?.setModel({original:t,modified:n})},[i,r,l,e,o,u,d]),P=a(()=>{!M.current&&k.current&&(D.current=O.current.editor.createDiffEditor(k.current,{automaticLayout:!0,...g}),N(),O.current?.editor.setTheme(m),w(!0),M.current=!0)},[g,m,N]);s(()=>{C&&A.current(D.current,O.current)},[C]),s(()=>{!T&&!C&&P()},[T,C,P]);function F(){let e=D.current?.getModel();f||e?.original?.dispose(),p||e?.modified?.dispose(),D.current?.dispose()}return t.createElement(Ts,{width:v,height:_,isEditorReady:C,loading:h,_ref:k,className:y,wrapperProps:b})}i(Ps);function Fs(e){let t=n();return s(()=>{t.current=e},[e]),t.current}var Is=Fs,Ls=new Map;function Rs({defaultValue:e,defaultLanguage:r,defaultPath:i,value:o,language:l,path:u,theme:d=`light`,line:f,loading:p=`Loading...`,options:m={},overrideServices:h={},saveViewState:g=!0,keepCurrentModel:_=!1,width:v=`100%`,height:y=`100%`,className:b,wrapperProps:x={},beforeMount:S=ks,onMount:C=ks,onChange:w,onValidate:T=ks}){let[E,D]=c(!1),[O,k]=c(!0),A=n(null),j=n(null),M=n(null),N=n(C),P=n(S),F=n(),I=n(o),L=Is(u),R=n(!1),ee=n(!1);Ds(()=>{let e=ys.init();return e.then(e=>(A.current=e)&&k(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>j.current?B():e.cancel()}),$(()=>{let t=As(A.current,e||o||``,r||l||``,u||i||``);t!==j.current?.getModel()&&(g&&Ls.set(L,j.current?.saveViewState()),j.current?.setModel(t),g&&j.current?.restoreViewState(Ls.get(u)))},[u],E),$(()=>{j.current?.updateOptions(m)},[m],E),$(()=>{!j.current||o===void 0||(j.current.getOption(A.current.editor.EditorOption.readOnly)?j.current.setValue(o):o!==j.current.getValue()&&(ee.current=!0,j.current.executeEdits(``,[{range:j.current.getModel().getFullModelRange(),text:o,forceMoveMarkers:!0}]),j.current.pushUndoStop(),ee.current=!1))},[o],E),$(()=>{let e=j.current?.getModel();e&&l&&A.current?.editor.setModelLanguage(e,l)},[l],E),$(()=>{f!==void 0&&j.current?.revealLine(f)},[f],E),$(()=>{A.current?.editor.setTheme(d)},[d],E);let z=a(()=>{if(!(!M.current||!A.current)&&!R.current){P.current(A.current);let t=u||i,n=As(A.current,o||e||``,r||l||``,t||``);j.current=A.current?.editor.create(M.current,{model:n,automaticLayout:!0,...m},h),g&&j.current.restoreViewState(Ls.get(t)),A.current.editor.setTheme(d),f!==void 0&&j.current.revealLine(f),D(!0),R.current=!0}},[e,r,i,o,l,u,m,h,g,d,f]);s(()=>{E&&N.current(j.current,A.current)},[E]),s(()=>{!O&&!E&&z()},[O,E,z]),I.current=o,s(()=>{E&&w&&(F.current?.dispose(),F.current=j.current?.onDidChangeModelContent(e=>{ee.current||w(j.current.getValue(),e)}))},[E,w]),s(()=>{if(E){let e=A.current.editor.onDidChangeMarkers(e=>{let t=j.current.getModel()?.uri;if(t&&e.find(e=>e.path===t.path)){let e=A.current.editor.getModelMarkers({resource:t});T?.(e)}});return()=>{e?.dispose()}}return()=>{}},[E,T]);function B(){F.current?.dispose(),_?g&&Ls.set(u,j.current.saveViewState()):j.current.getModel()?.dispose(),j.current.dispose()}return t.createElement(Ts,{width:v,height:y,isEditorReady:E,loading:p,_ref:M,className:b,wrapperProps:x})}var zs=i(Rs);u();function Bs(e,t){let n=[];for(let[r,i]of Object.entries(e))r!==t&&(n.push({filePath:`file:///${r}`,content:i}),r.endsWith(`.ts`)&&n.push({filePath:`file:///${r.slice(0,-3)}.js`,content:i}));return n}var Vs={target:99,module:99,moduleResolution:2,strict:!0,noImplicitAny:!0,strictNullChecks:!0,allowNonTsExtensions:!0,isolatedModules:!0};function Hs(e,t){let n=e.languages.typescript.typescriptDefaults;n.setCompilerOptions({...n.getCompilerOptions(),...Vs}),n.setExtraLibs(t.map(e=>({filePath:e.filePath,content:e.content})))}function Us({value:e,onChange:t,extraLibs:r=[],path:i=`file:///block.ts`,onDiagnostics:c,readOnly:l=!1,heightPx:u=420,dark:d=!0}){let f=n(null),p=a((e,t)=>{if(f.current=t,Hs(t,r),c===void 0)return;let n=e.getModel();if(n===null)return;let i=()=>{c(t.editor.getModelMarkers({resource:n.uri}).map(e=>({line:e.startLineNumber,column:e.startColumn,message:e.message,severity:e.severity})))};t.editor.onDidChangeMarkers(i),i()},[r,c]);return s(()=>{let e=f.current;e!==null&&Hs(e,r)},[r]),o(zs,{height:u,defaultLanguage:`typescript`,path:i,theme:d?`vs-dark`:`vs`,value:e,onChange:e=>t(e??``),onMount:p,options:{readOnly:l,minimap:{enabled:!1},fontSize:12,lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,tabSize:2,renderWhitespace:`selection`}})}function Ws(e){return e.some(e=>e.severity>=8)}var Gs=[{id:`blank`,name:`Blank script`,get description(){return J.t(`helpers.buildExamples.blankDescription`)},entry:`main.ts`,files:{"main.ts":`import type { AddonContext } from '@camstack/types'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A core block. Runs in its own process, with the same \`ctx\` an addon gets.
|
|
18
|
+
* Return a function to release whatever you took (timers, sockets, listeners).
|
|
19
|
+
*
|
|
20
|
+
* Declaring devices: import { reconcileBlockDevices, exposeBlockDevices } from
|
|
21
|
+
* '@camstack/types' and hang them off the shared Blocks integration.
|
|
22
|
+
*/
|
|
23
|
+
export default function block(ctx: AddonContext) {
|
|
24
|
+
ctx.logger.info('hello from a core block')
|
|
25
|
+
|
|
26
|
+
const timer = setInterval(() => {
|
|
27
|
+
ctx.logger.info('tick')
|
|
28
|
+
}, 60_000)
|
|
29
|
+
|
|
30
|
+
return () => {
|
|
31
|
+
clearInterval(timer)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
`}}];function Ks(e){let t=e instanceof Set?e:new Set(e);if(!t.has(`file.ts`))return`file.ts`;let n=2;for(;t.has(`file-${String(n)}.ts`);)n+=1;return`file-${String(n)}.ts`}var qs=Gs.find(e=>e.id===`blank`)?.files[`main.ts`]??`import type { AddonContext } from '@camstack/types'
|
|
35
|
+
|
|
36
|
+
export default function block(ctx: AddonContext) {
|
|
37
|
+
ctx.logger.info('hello from a core block')
|
|
38
|
+
return () => undefined
|
|
39
|
+
}
|
|
40
|
+
`;function Js({existing:e,dirty:t,saving:n,restarting:r}){return e===null?J.t(`helpers.restartGate.saveFirstNoProcess`):n?J.t(`helpers.restartGate.saving`):r?J.t(`helpers.restartGate.restarting`):t?J.t(`helpers.restartGate.saveFirstDirty`):e.enabled?null:J.t(`helpers.restartGate.disabled`)}u();var Ys=5e3;function Xs(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(typeof n!=`object`||!n)continue;let e=Reflect.get(n,`id`),r=Reflect.get(n,`name`),i=Reflect.get(n,`type`),a=Reflect.get(n,`stableId`);typeof e!=`number`||typeof r!=`string`||typeof i!=`string`||t.push({id:e,name:r,type:i,...typeof a==`string`?{stableId:a}:{}})}return t}function Zs({blockId:t}){let{t:n}=Y(),i=ae(t),a=Se({addonId:i,projection:`slim`},{refetchInterval:Ys}),s=r(()=>Xs(a.data),[a.data]);return a.isLoading?e(`p`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[o(T,{className:`h-3.5 w-3.5 animate-spin`}),` `,n(`build.scriptDevicesPanel.loading`)]}):a.isError?e(`p`,{className:`text-xs text-danger`,children:[n(`build.scriptDevicesPanel.couldNotListDevices`,`Could not list devices:`),` `,a.error instanceof Error?a.error.message:String(a.error)]}):e(`section`,{className:`space-y-3 rounded border border-border p-3`,"data-testid":`script-devices-panel`,children:[e(`div`,{className:`flex items-center justify-between gap-2`,children:[e(`div`,{children:[o(`h4`,{className:`text-sm font-medium`,children:n(`build.scriptDevicesPanel.devices`,`Devices`)}),o(`p`,{className:`text-xs text-foreground-subtle`,children:o(X,{i18nKey:`build.scriptDevicesPanel.declaredBy`,values:{addonId:i},components:{code:o(`code`,{className:`text-[11px]`})}})})]}),o(q,{variant:`default`,children:s.length})]}),s.length===0?o(`p`,{className:`text-xs text-foreground-subtle`,children:o(X,{i18nKey:`build.scriptDevicesPanel.noDevices`,components:{code:o(`code`,{})}})}):o(`ul`,{className:`space-y-3`,children:s.map(t=>o(`li`,{className:`rounded border border-border/80 px-3 py-2`,"data-testid":`script-device-${t.id}`,children:e(`div`,{className:`flex flex-wrap items-baseline gap-2`,children:[o(Et,{to:`/devices/${String(t.id)}`,className:`text-sm font-medium hover:underline`,title:n(`build.scriptDevicesPanel.openDeviceDetail`,`Open device detail`),children:o(Pe,{device:{id:t.id,name:t.name,type:t.type,stableId:t.stableId??``,parentDeviceId:null},form:`compact`})}),o(q,{variant:`info`,style:`outline`,children:t.type}),t.stableId!==void 0&&e(`span`,{className:`text-[11px] text-foreground-subtle`,children:[`stableId `,o(`code`,{children:t.stableId})]}),e(`span`,{className:`text-[11px] text-foreground-subtle`,children:[`#`,t.id]})]})},t.id))})]})}u();function Qs(e){return e===`refresh-channel-catalog`||e===`send-tv-schedule-now`||e===`refresh-nordvpn-catalog`||e===`probe-nordvpn-italy`||e===`test-nordvpn-endpoint`||e===`refresh-unifi-catalog`}function $s(e){let t=Date.now();switch(e){case`refresh-channel-catalog`:return{channelCatalogRefreshAt:t};case`send-tv-schedule-now`:return{sendNowAt:t};case`refresh-nordvpn-catalog`:return{nordVpnCatalogRefreshAt:t};case`probe-nordvpn-italy`:return{nordVpnProbeAt:t};case`test-nordvpn-endpoint`:return{nordVpnTestAt:t};case`refresh-unifi-catalog`:return{unifiCatalogRefreshAt:t}}}function ec(e){switch(e){case`refresh-channel-catalog`:return J.t(`build.scriptSettingsPanel.enableChannel`);case`send-tv-schedule-now`:return J.t(`build.scriptSettingsPanel.enableTv`);case`refresh-nordvpn-catalog`:return J.t(`build.scriptSettingsPanel.enableNord`);case`probe-nordvpn-italy`:return J.t(`build.scriptSettingsPanel.enableItaly`);case`test-nordvpn-endpoint`:return J.t(`build.scriptSettingsPanel.enableVpn`);case`refresh-unifi-catalog`:return J.t(`build.scriptSettingsPanel.enableUnifi`)}}function tc(e){if(typeof e!=`object`||!e||!(`key`in e))return null;let t=Reflect.get(e,`key`);return typeof t==`string`?t:null}function nc(e){if(!(typeof e!=`object`||!e||!(`value`in e)))return Reflect.get(e,`value`)}function rc(e){let t={};for(let n of e.sections)for(let e of n.fields){let n=tc(e);n!==null&&(t[n]=nc(e))}return t}function ic(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function ac({blockId:t}){let{t:n}=Y(),i=w(),s=je({blockId:t},{retry:!1}),l=ze({blockId:t},{refetchInterval:1e4,retry:!1}),u=ke({onSuccess:()=>{l.refetch()}}),d=We(),f=Te(),[p,m]=c(null),[h,g]=c(null),[_,v]=c(null),[y,b]=c(!1),x=ic(l.data)?l.data:null,S=r(()=>x===null?{}:rc(x),[x]),C=p??S,E=a(e=>{m(e)},[]),D=p!==null,O=a(()=>{p!==null&&(g(null),u.mutate({blockId:t,patch:p},{onSuccess:()=>m(null),onError:e=>g(e instanceof Error?e.message:String(e))}))},[t,p,u]),k=a(async(e,n)=>{if(Qs(e)){b(!0),g(null),v(null);try{p!==null&&(await i.trpcClient.coreBlocks.updateBlockSettings.mutate({blockId:t,patch:p}),m(null)),await i.trpcClient.coreBlocks.updateBlockSettings.mutate({blockId:t,patch:$s(e)}),s.data?.block?.enabled!==!0&&(await f.mutateAsync({blockId:t,enabled:!0}),v(ec(e))),await d.mutateAsync({blockId:t}),await l.refetch(),e===`send-tv-schedule-now`?v(`Sending tonight’s schedule now…`):e===`probe-nordvpn-italy`?v(`Probing NordVPN Italy stations (no UniFi change)…`):e===`test-nordvpn-endpoint`?v(`Testing VPN endpoint on UniFi…`):e===`refresh-nordvpn-catalog`?v(`Refreshing NordVPN Italy catalog…`):e===`refresh-unifi-catalog`&&v(`Refreshing UniFi ID catalogs…`)}catch(e){g(e instanceof Error?e.message:String(e))}finally{b(!1)}}},[t,s.data?.block?.enabled,p,d,f,l,i.trpcClient.coreBlocks]);return l.isLoading?e(`p`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[o(T,{className:`h-3.5 w-3.5 animate-spin`}),` `,n(`build.scriptSettingsPanel.loading`)]}):l.isError?e(`p`,{className:`text-xs text-danger`,"data-testid":`script-settings-error`,children:[n(`build.scriptSettingsPanel.couldNotLoadSettings`,`Could not load settings:`),` `,l.error instanceof Error?l.error.message:String(l.error)]}):x===null?null:e(`section`,{className:`space-y-3 rounded border border-border p-3`,"data-testid":`script-settings-panel`,children:[e(`div`,{className:`flex items-center justify-between gap-2`,children:[e(`div`,{children:[o(`h4`,{className:`text-sm font-medium`,children:n(`build.scriptSettingsPanel.settings`,`Settings`)}),o(`p`,{className:`text-xs text-foreground-subtle`,children:o(X,{i18nKey:`build.scriptSettingsPanel.declaredBy`,components:{code:o(`code`,{})}})})]}),e(W,{size:`sm`,variant:`primary`,onClick:O,disabled:!D||u.isPending||y,children:[u.isPending&&o(T,{className:`h-3.5 w-3.5 animate-spin`}),n(`build.scriptSettingsPanel.saveSettings`,`Save settings`)]})]}),o(bt,{schema:x,values:C,onChange:E,onAction:k}),h===null?null:o(`p`,{className:`text-xs text-danger`,"data-testid":`script-settings-save-error`,children:h}),_===null?null:o(`p`,{className:`text-xs text-foreground-subtle`,"data-testid":`script-settings-info`,children:_})]})}u();var oc=`hub`;function sc({existing:t,typeDefs:n,typeDefsLoading:i,saving:a,saveError:s,restarting:l,restartError:u,onRestart:d,onSave:m,onCancel:h}){let{t:g}=Y(),_=w(),v=k(),{resolvedMode:y}=mt(),b=oe({code:t?.code??qs,files:t?.files,entry:t?.entry}),[x,S]=c(t?.name??``),[C,E]=c(b.files),[D,O]=c(b.entry),[A,F]=c(b.entry),[I,L]=c(t?.placement??oc),[R,ee]=c(t?.integrationId??``),[z,B]=c([]),[te,ne]=c(!1),[re,ie]=c(`blank`),[V,se]=c(null),[ce,le]=c(``),ue=C[A]??``,de=e=>{E(t=>({...t,[A]:e}))},fe=Object.keys(C).toSorted(),pe=Gs.length>1,me=r(()=>[...n?.libs??[],...Bs(C,A)],[n?.libs,C,A]),H=f({mutationFn:()=>_.trpcClient.coreBlocks.compile.mutate({files:C,entry:D})}),he=r(()=>z.filter(e=>e.severity>=8),[z]),ge=Ws(z),_e=x.trim()===``,ve=t===null?null:oe(t),ye=t===null||ve===null||JSON.stringify(C)!==JSON.stringify(ve.files)||D!==ve.entry||x.trim()!==t.name||I!==t.placement||(R.trim()===``?void 0:R.trim())!==t.integrationId,be=()=>{H.reset(),m({name:x.trim(),files:C,entry:D,enabled:t?.enabled??!0,placement:I,...R.trim()===``?{}:{integrationId:R.trim()}})},xe=()=>{let e=Ks(Object.keys(C));E(t=>({...t,[e]:``})),F(e),se(e),le(e)},Se=e=>{se(e),le(e)},Ce=()=>{if(V===null)return;let e=V,t=ce.trim();if(se(null),!(t===``||t===e)){if(C[t]!==void 0){F(t);return}E(n=>{let r={};for(let[i,a]of Object.entries(n))r[i===e?t:i]=a;return r}),D===e&&O(t),F(t)}},we=async e=>{let t=Gs.find(t=>t.id===e);if(t===void 0)return;let n=Gs.find(e=>e.id===`blank`);!(n!==void 0&&JSON.stringify(C)===JSON.stringify(n.files)&&D===n.entry)&&!await v({title:g(`build.blockEditor.loadExample`,`Load example`),message:g(`build.blockEditor.replaceTheCurrentEditorContents`,`Replace the current editor contents with this example?`),confirmLabel:g(`build.blockEditor.replace`,`Replace`),variant:`warning`})||(ie(e),E({...t.files}),O(t.entry),F(t.entry),(x.trim()===``||re===`blank`)&&S(t.id===`blank`?``:t.name))},Te=t===null?null:ha(t),Ee=Js({existing:t,dirty:ye,saving:a,restarting:l});return e(`div`,{className:`space-y-4`,children:[Te!==null&&o(`div`,{className:`flex flex-wrap items-center gap-2`,children:o(q,{variant:ga(Te.tone),children:Te.label})}),e(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[e(`label`,{className:`block text-sm`,children:[o(`span`,{className:`text-foreground-subtle`,children:g(`build.blockEditor.name`,`Name`)}),o(K,{className:`mt-1`,value:x,onChange:e=>S(e.target.value),placeholder:g(`build.blockEditor.whatThisScriptDoes`,`What this script does`)})]}),e(`label`,{className:`block text-sm`,children:[o(`span`,{className:`text-foreground-subtle`,children:g(`build.blockEditor.integrationOptional`,`Integration (optional)`)}),o(K,{className:`mt-1`,value:R,onChange:e=>ee(e.target.value),placeholder:g(`build.blockEditor.leaveEmptyForTheShared`,`Leave empty for the shared system integration`)})]})]}),t===null&&pe&&e(`label`,{className:`block text-sm`,children:[o(`span`,{className:`text-foreground-subtle`,children:g(`build.blockEditor.startFrom`,`Start from`)}),o(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1.5 text-sm`,value:re,onChange:e=>void we(e.target.value),"data-testid":`script-example-select`,children:Gs.map(t=>e(`option`,{value:t.id,children:[t.name,` — `,t.description]},t.id))})]}),e(`div`,{children:[o(yt,{selectedNodeId:I,onSelect:L,label:g(`build.blockEditor.runsOn`,`Runs on`),alwaysShow:!0}),I!==oc&&e(`p`,{className:`mt-2 flex items-start gap-2 text-xs text-warning`,children:[o(P,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),o(`span`,{children:o(X,{i18nKey:`build.blockEditor.hubOnlyWarning`,components:{strong:o(`strong`,{})}})})]})]}),e(`div`,{className:`flex min-h-[56vh] flex-col rounded border border-border`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border px-2 py-1.5`,children:[fe.map(t=>V===t?o(K,{value:ce,onChange:e=>le(e.target.value),onBlur:()=>Ce(),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),Ce()),e.key===`Escape`&&(e.preventDefault(),se(null))},className:`h-7 w-36 px-2 py-0 text-xs`,autoFocus:!0,"data-testid":`script-file-rename`,"aria-label":g(`build.blockEditor.renameFile`,`Rename file`)},t):e(`button`,{type:`button`,className:`rounded px-2 py-1 text-xs ${t===A?`bg-muted font-medium text-foreground`:`text-foreground-subtle hover:text-foreground`}`,onClick:()=>F(t),onDoubleClick:()=>Se(t),title:g(`build.blockEditor.doubleClickToRename`,`Double-click to rename`),"data-testid":`script-file-tab-${t}`,children:[t,t===D?` · ${g(`build.blockEditor.entry`)}`:``]},t)),o(`button`,{type:`button`,className:`ml-1 rounded px-2 py-1 text-xs text-foreground-subtle hover:text-foreground`,onClick:xe,"data-testid":`script-file-add`,children:g(`build.blockEditor.file`,`+ file`)}),A!==D&&o(`button`,{type:`button`,className:`rounded px-2 py-1 text-xs text-foreground-subtle hover:text-foreground`,onClick:()=>O(A),title:g(`build.blockEditor.useThisFileAsThe`,`Use this file as the compile entry`),children:g(`build.blockEditor.setAsEntry`,`Set as entry`)})]}),i?o(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:g(`build.blockEditor.loadingTheNodeSType`,`Loading the node's type definitions…`)}):o(Us,{value:ue,onChange:de,path:`file:///${A}`,extraLibs:me,onDiagnostics:B,dark:y===`dark`,heightPx:560})]}),n!==void 0&&n.libs.length===0&&o(`p`,{className:`text-xs text-warning`,children:g(`build.blockEditor.theNodeReturnedNoType`,`The node returned no type definitions, so this code is NOT being checked against the system's types. The server-side compile still applies on save.`)}),he.length>0&&e(`div`,{className:`space-y-1 rounded border border-danger/40 bg-danger/10 p-3 text-xs`,children:[o(`p`,{className:`font-medium text-danger`,children:g(`build.blockEditor.errorsCannotSave`,{count:he.length})}),he.slice(0,5).map(e=>o(`p`,{className:`text-danger`,children:g(`build.blockEditor.diagnosticLine`,{line:e.line,message:e.message})},`${String(e.line)}:${String(e.column)}:${e.message}`)),he.length>5&&o(`p`,{className:`text-foreground-subtle`,children:g(`build.blockEditor.moreErrors`,{count:he.length-5})})]}),H.data!==void 0&&(H.data.ok?e(`p`,{className:`flex items-center gap-2 text-xs text-success`,children:[o(M,{className:`h-3.5 w-3.5`}),` `,g(`build.blockEditor.compiledOk`)]}):e(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[H.data.line!==void 0&&o(`span`,{className:`mr-1`,children:g(`build.blockEditor.errorLine`,{line:String(H.data.line)})}),H.data.error??g(`build.blockEditor.theCodeDoesNotCompile`,`the code does not compile`)]})),H.error!==null&&e(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[g(`build.blockEditor.couldNotReachTheCompiler`,`Could not reach the compiler:`),` `,cc(H.error)]}),s!==null&&o(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:s}),u!==null&&o(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:u}),t!==null&&e(`div`,{className:`space-y-3`,children:[o(ac,{blockId:t.id}),o(Zs,{blockId:t.id})]}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(W,{variant:`outline`,onClick:()=>H.mutate(),disabled:H.isPending||a,title:g(`build.blockEditor.typeCheckOnTheNode`,`Type-check on the node without saving`),children:[H.isPending&&o(T,{className:`h-4 w-4 animate-spin`}),` `,g(`common.compile`)]}),e(W,{onClick:be,disabled:a||ge||_e,children:[a&&o(T,{className:`h-4 w-4 animate-spin`}),` `,g(`common.save`)]}),e(W,{variant:`outline`,onClick:()=>d?.(),disabled:Ee!==null||d===void 0,title:Ee??g(`build.blockEditor.stopTheProcessAndLet`,`Stop the process and let the supervisor bring it back`),children:[l?o(j,{className:`h-4 w-4 animate-spin`}):o(j,{className:`h-4 w-4`}),` `,g(`build.blockEditor.restart`,`Restart`)]}),e(W,{variant:`ghost`,onClick:()=>ne(!te),title:g(`build.blockEditor.showThisScriptSProcess`,`Show this script's process logs`),"data-testid":`script-logs-toggle`,children:[o(N,{className:`h-4 w-4`}),` `,g(`common.logs`),` `,te?`▾`:`▸`]}),o(W,{variant:`ghost`,onClick:h,disabled:a,children:g(`common.close`,`Close`)}),e(`span`,{className:`ml-auto text-xs text-foreground-subtle`,children:[g(`build.blockEditor.errorsCount`,{count:he.length}),ye&&t!==null?` · ${g(`build.blockEditor.unsavedChanges`)}`:``]}),_e&&o(q,{variant:`warning`,children:g(`build.blockEditor.nameRequired`,`Name required`)})]}),te&&e(`div`,{className:`rounded border border-border`,"data-testid":`script-logs-panel`,children:[o(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:t===null?g(`build.blockEditor.logsAppearOnceTheScript`,`Logs appear once the script has been saved and started.`):o(p,{children:o(X,{i18nKey:`build.blockEditor.logsOf`,values:{id:ae(t.id)},components:{code:o(`code`,{})}})})}),t!==null&&o($e,{addonId:ae(t.id),maxHeight:`max-h-[560px]`,showFilters:!1})]})]})}function cc(e){return e instanceof Error?e.message:String(e)}u();var lc=[`coreBlocks`,`list`],uc=[`coreBlocks`,`getTypeDefs`],dc=5e3;function fc(e){return e instanceof Error?e.message:String(e)}function pc({initialBlockId:t,onBlockIdChange:i,createRequested:a=!1,onCreateConsumed:u}={}){let d=D(),{t:p}=Y(),m=w(),{state:h,openNew:g,openEdit:_,close:y}=tt({editKey:`block`,newKey:`new`}),[b,x]=c(null),S=k(),[C,T]=c(null),E=l({queryKey:lc,refetchInterval:dc,queryFn:async()=>(await m.trpcClient.coreBlocks.list.query({})).blocks}),O=h.mode!==`closed`,A=l({queryKey:uc,enabled:O,staleTime:1/0,gcTime:1/0,queryFn:()=>m.trpcClient.coreBlocks.getTypeDefs.query({})}),M=()=>{E.refetch()},P=n(null),F=E.data;s(()=>{t===void 0||P.current===t||F?.find(e=>e.id===t&&se(e)===`code`)!==void 0&&(P.current=t,_(t),i?.(t))},[t,F,_,i]),s(()=>{a&&(x(null),g(),i?.(null),u?.())},[a,u,i,g]);let I=f({mutationFn:e=>m.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{x(e.block),_(e.block.id),i?.(e.block.id),M()}}),L=f({mutationFn:e=>m.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{x(e.block),_(e.block.id),i?.(e.block.id),M()}}),R=f({mutationFn:e=>m.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:M}),ee=f({mutationFn:e=>m.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:M}),z=f({mutationFn:e=>m.trpcClient.coreBlocks.restart.mutate({blockId:e}),onSuccess:M}),B=va((E.data??[]).filter(e=>se(e)===`code`)),te=E.data!==void 0&&B.length===0,ne=I.isPending||L.isPending,re=I.error===null?L.error===null?null:fc(L.error):fc(I.error),ie=h.mode===`edit`?B.find(e=>e.id===h.id)??(b!==null&&b.id===h.id?b:null):null,V=h.mode===`new`||ie===null?null:_a(B,ie),oe=r(()=>[{key:`name`,header:p(`build.scriptsTab.name`,`Name`),render:t=>{let n=ha(t),r=Ae(t.updatedAt,d);return e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(`span`,{className:`truncate font-medium`,children:t.name}),o(q,{variant:ga(n.tone),children:n.label}),o(q,{variant:`info`,children:t.placement}),r!==null&&o(`span`,{className:`text-xs text-foreground-subtle`,children:p(`common.edited`,{when:r})})]}),o(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:n.detail}),C===t.id&&e(`div`,{className:`mt-2 rounded border border-border`,children:[o(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:o(X,{i18nKey:`common.logsOf`,values:{id:ae(t.id)},components:{code:o(`code`,{})}})}),o($e,{addonId:ae(t.id),maxHeight:`max-h-64`,showFilters:!1})]})]})},sortValue:e=>e.name,nowrap:!1},{key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,render:t=>{let n=ee.isPending||R.isPending,r=z.isPending&&z.variables===t.id;return e(`div`,{className:`flex justify-end gap-1`,children:[o(W,{variant:`ghost`,onClick:e=>{e.stopPropagation(),x(t),_(t.id),i?.(t.id)},title:p(`common.edit`,`Edit`),children:p(`common.edit`,`Edit`)}),o(W,{variant:`ghost`,onClick:e=>{e.stopPropagation(),z.mutate(t.id)},disabled:n||r||!t.enabled,title:t.enabled?p(`build.scriptsTab.restart`,`Restart`):p(`build.scriptsTab.enableItInsteadADisabled`,`Enable it instead — a disabled script has no process`),children:o(j,{className:`h-4 w-4${r?` animate-spin`:``}`})}),o(W,{variant:`ghost`,onClick:e=>{e.stopPropagation(),T(C===t.id?null:t.id)},title:p(`build.scriptsTab.logs`,`Logs`),children:o(N,{className:`h-4 w-4`})}),o(W,{variant:`ghost`,onClick:e=>{e.stopPropagation(),ee.mutate({blockId:t.id,enabled:!t.enabled})},disabled:n,title:t.enabled?p(`common.disable`,`Disable`):p(`common.enable`,`Enable`),children:t.enabled?p(`common.disable`,`Disable`):p(`common.enable`,`Enable`)}),o(W,{variant:`ghost`,onClick:e=>{e.stopPropagation(),S({title:p(`build.scriptsTab.deleteThisScript`,`Delete this script?`),message:p(`build.scriptsTab.deleteMessage`,`{{name}} and its source will be deleted. This cannot be undone.`,{name:t.name}),confirmLabel:p(`common.delete`,`Delete`),variant:`danger`}).then(e=>{e&&R.mutate(t.id)})},title:p(`common.delete`,`Delete`),children:o(v,{className:`h-4 w-4`})})]})}}],[S,C,i,_,R,z.isPending,z.variables,ee,p]);return e(`div`,{className:`space-y-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:E.data===void 0?``:ya(B)}),E.error!=null&&o(U,{title:p(`build.scriptsTab.couldNotReadTheScripts`,`Could not read the scripts`),message:fc(E.error),onRetry:M}),o(Be,{columns:oe,rows:B,rowKey:e=>e.id,pageSize:25,maxBodyHeight:be,emptyMessage:te?p(`build.scriptsTab.noScriptsYetAScript`,`No scripts yet. A script is TypeScript the hub runs in its own process.`):E.data===void 0?p(`build.scriptsTab.loadingScripts`,`Loading scripts…`):p(`build.scriptsTab.noScriptsYet`,`No scripts yet.`),onRowClick:e=>{x(e),_(e.id),i?.(e.id)}}),o(dt,{open:O,onClose:()=>{I.reset(),L.reset(),z.reset(),x(null),y(),i?.(null)},title:V===null?p(`build.scriptsTab.newScript`,`New script`):p(`build.scriptsTab.edit`,`Edit {{name}}`,{name:V.name}),icon:ge,width:`xl`,testId:`script-editor-panel`,children:o(sc,{existing:V,typeDefs:A.data,typeDefsLoading:A.isLoading,saving:ne,saveError:re,restarting:z.isPending,restartError:z.error===null?null:fc(z.error),onRestart:V===null?void 0:()=>z.mutate(V.id),onSave:e=>{let t=V;t===null?I.mutate(e):L.mutate({blockId:t.id,block:e})},onCancel:()=>{I.reset(),L.reset(),z.reset(),x(null),y(),i?.(null)}})}),R.error!=null&&o(U,{message:fc(R.error)}),ee.error!=null&&o(U,{message:fc(ee.error)}),z.error!=null&&o(U,{message:fc(z.error)})]})}var mc=[`automations`,`actions`,`scripts`,`custom-device`];function hc(e){return e!==null&&mc.some(t=>t===e)}var gc=[`coreBlocks`,`list`,`build-counts`],_c=[`actions`,`list`,`build-counts`],vc=[`block`,`action`,`create`,`new`];function yc(e){return e.filter(e=>se(e)===`code`).length}function bc(e){return e.filter(e=>Vt(e.code)).length}function xc(e,t){return t===null?e:`${e} (${String(t)})`}function Sc(){let{t}=Y(),n=w(),[r,i]=Dt(),a=r.get(`tab`),s=hc(a)?a:`automations`,c=r.get(`create`)===`1`,u=l({queryKey:gc,refetchInterval:5e3,queryFn:async()=>(await n.trpcClient.coreBlocks.list.query({})).blocks}).data,d=u===void 0?null:yc(u),f=u===void 0?null:bc(u),p=l({queryKey:_c,refetchInterval:1e4,queryFn:async()=>n.trpcClient.actions.list.query({})}),m=p.data===void 0?null:p.data.length,g=l({queryKey:[`coreBlocks`,`listCompositions`,`build-counts`],refetchInterval:1e4,queryFn:async()=>n.trpcClient.coreBlocks.listCompositions.query({})}),v=g.data?.state===`loaded`?g.data.views.length:null,y=e=>{i(t=>{let n=new URLSearchParams(t);return n.set(`tab`,`scripts`),n.delete(`create`),e===void 0?n.delete(`block`):n.set(`block`,e),n},{replace:!0})},b=e=>{i(t=>{let n=new URLSearchParams(t);return n.set(`tab`,`automations`),n.delete(`create`),e===null?n.delete(`block`):n.set(`block`,e),n},{replace:!0})},x=e=>{i(t=>{let n=new URLSearchParams(t);return n.set(`tab`,`scripts`),n.delete(`create`),e===null?n.delete(`block`):n.set(`block`,e),n},{replace:!0})},S=()=>{i(e=>{let t=new URLSearchParams(e);return t.set(`create`,`1`),t.delete(`block`),t},{replace:!0})},C=e=>{i(()=>{let t=new URLSearchParams(window.location.search);return t.set(`tab`,`custom-device`),t.delete(`block`),t.delete(`create`),t.set(`new`,e),t},{replace:!0})},T=()=>{i(()=>{let e=new URLSearchParams(window.location.search);return e.delete(`create`),e},{replace:!0})},E=s===`automations`?t(`build.newAutomation`,`New automation`):s===`actions`?t(`build.newAction`,`New action`):t(`build.newScript`,`New script`),D=xt(`/build`,{t,isAdmin:!0})??{icon:h,title:t(`nav.build`,`Build-your-self`)};return o(Ot,{icon:D.icon,title:D.title,subtitle:t(`build.automationsScriptsAndComposedDevices`,`Automations, scripts and composed devices — what this installation does on its own.`),defaultSection:`automations`,sectionsLabel:`${D.title} sections`,fill:!0,actions:s===`custom-device`?e(W,{type:`button`,onClick:()=>C(`helper`),"data-testid":`build-new-composed`,children:[o(_,{className:`h-4 w-4`}),` `,t(`helper.newComposed`)]}):e(W,{type:`button`,onClick:S,"data-testid":`build-new`,children:[o(_,{className:`h-4 w-4`}),` `,E]}),sections:[{id:`automations`,label:xc(t(`build.tabAutomations`,`Automations`),f),ownedParams:vc,content:o(Ta,{onOpenScripts:y,initialBlockId:s===`automations`?r.get(`block`)??void 0:void 0,onBlockIdChange:b,createRequested:s===`automations`&&c,onCreateConsumed:T})},{id:`actions`,label:xc(t(`build.tabActions`,`Actions`),m),ownedParams:vc,content:o(Hr,{createRequested:s===`actions`&&c,onCreateConsumed:T})},{id:`scripts`,label:xc(t(`build.tabCode`,`Code`),d),ownedParams:vc,content:o(pc,{initialBlockId:s===`scripts`?r.get(`block`)??void 0:void 0,onBlockIdChange:x,createRequested:s===`scripts`&&c,onCreateConsumed:T})},{id:`custom-device`,label:xc(t(`build.tabCustomDevice`,`Custom Device`),v),ownedParams:vc,content:o(no,{createRequested:s===`custom-device`&&c,onCreateConsumed:T})}]})}export{Sc as BuildPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as e,K as t,R as n,S as r,Y as i,et as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Ei as s,Ti as c}from"./player-overlays-g9d3qYrr.js";import{fr as l,pr as u}from"./client-CwJGlpR9.js";import{h as d}from"./video-BFmrpvc7.js";import{Ma as f,Na as p,Pa as m,Yr as h,_r as g,dr as _,fr as v,gr as y,hr as b,ja as x,pr as S}from"./src-DwNoxp86.js";import{t as C}from"./i18n-9jE1YKjd.js";import{t as w}from"./useTranslation-BJr-n0es.js";import{mr as T,pr as E}from"./index-DG07MiZm.js";import{t as D}from"./AdminPage-DlYf-2bp.js";a();var O=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`];function k(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function A(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function j(e){let t=e.getDay();return k(A(e,t===0?-6:1-t))}function M(e,t){if(t===`day`){let t=k(e);return{startMs:t.getTime(),endMs:A(t,1).getTime()}}if(t===`week`){let t=j(e);return{startMs:t.getTime(),endMs:A(t,7).getTime()}}let n=new Date(e.getFullYear(),e.getMonth(),1),r=new Date(e.getFullYear(),e.getMonth()+1,0),i=j(n),a=A(j(r),7);return{startMs:i.getTime(),endMs:a.getTime()}}function N(e,t){if(t===`day`)return e.toLocaleDateString(void 0,{weekday:`long`,year:`numeric`,month:`long`,day:`numeric`});if(t===`week`){let t=j(e),n=A(t,6),r={month:`short`,day:`numeric`};return`${t.toLocaleDateString(void 0,r)} – ${n.toLocaleDateString(void 0,{...r,year:`numeric`})}`}return e.toLocaleDateString(void 0,{month:`long`,year:`numeric`})}function P(e,t,n){return t===`day`?A(e,n):t===`week`?A(e,n*7):new Date(e.getFullYear(),e.getMonth()+n,1)}function F(e,t){if(t===void 0)return e;let n=t.calendars[e.id];return n===void 0?e:{...e,visible:n.visible??e.visible,color:n.color??e.defaultColor}}function I(e){return e.providerAddonId!==void 0&&e.providerAddonId.length>0?e.providerAddonId:e.source===`ha`?`Home Assistant`:e.source}function L(e){if(e.allDay===!0)return C.t(`systemPage.calendars.allDay`);let t=new Date(e.startMs),n=new Date(e.endMs),r={hour:`2-digit`,minute:`2-digit`};return`${t.toLocaleTimeString([],r)} – ${n.toLocaleTimeString([],r)}`}function R(e){let t=l(e),n=new Date(t.startMs),r=new Date(t.endMs),i={weekday:`short`,year:`numeric`,month:`short`,day:`numeric`};if(e.allDay===!0){let e=k(n),t=A(k(r),-1);return H(e,t)?C.t(`systemPage.calendars.dayAllDay`,{date:n.toLocaleDateString(void 0,i)}):C.t(`systemPage.calendars.rangeAllDay`,{from:n.toLocaleDateString(void 0,i),to:t.toLocaleDateString(void 0,i)})}let a={hour:`2-digit`,minute:`2-digit`};return H(n,r)?`${n.toLocaleDateString(void 0,i)} · ${n.toLocaleTimeString([],a)} – ${r.toLocaleTimeString([],a)}`:`${n.toLocaleString(void 0,{...i,...a})} – ${r.toLocaleString(void 0,{...i,...a})}`}function z({label:t,children:n}){return e(`div`,{className:`grid grid-cols-[7rem_minmax(0,1fr)] gap-x-3 gap-y-1 text-sm`,children:[r(`dt`,{className:`text-foreground-subtle`,children:t}),r(`dd`,{className:`min-w-0 break-words text-foreground`,children:n})]})}function B({ev:t,calendarName:n,color:i,onClose:a}){let{t:o}=w();return r(_,{open:!0,onOpenChange:e=>!e&&a(),children:e(S,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`calendars-event-detail`,children:[r(y,{children:e(`div`,{className:`flex min-w-0 items-start gap-2.5`,children:[r(`span`,{className:`mt-1.5 h-3 w-3 shrink-0 rounded-full`,style:{backgroundColor:i},"aria-hidden":!0}),r(g,{className:`min-w-0 break-words`,children:t.title})]})}),r(v,{children:e(`dl`,{className:`space-y-3`,children:[r(z,{label:o(`systemPage.calendars.when`,`When`),children:R(t)}),r(z,{label:o(`systemPage.calendars.calendar`,`Calendar`),children:n}),t.location!==void 0&&t.location.length>0?r(z,{label:o(`systemPage.calendars.location`,`Location`),children:t.location}):null,t.description!==void 0&&t.description.length>0?r(z,{label:o(`systemPage.calendars.description`,`Description`),children:r(`span`,{className:`whitespace-pre-wrap`,children:t.description})}):null]})}),r(b,{children:r(h,{type:`button`,size:`sm`,variant:`secondary`,onClick:a,children:o(`common.close`,`Close`)})})]})})}function V(e,t){return e.filter(e=>u(e,t))}function H(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function U({mode:e,onChange:t}){let{t:n}=w(),i=[{id:`month`,label:n(`systemPage.calendars.month`,`Month`)},{id:`week`,label:n(`systemPage.calendars.week`,`Week`)},{id:`day`,label:n(`systemPage.calendars.day`,`Day`)}];return r(`div`,{className:`inline-flex rounded-lg border border-border bg-surface p-0.5`,role:`group`,"aria-label":n(`systemPage.calendars.calendarView`,`Calendar view`),children:i.map(n=>r(`button`,{type:`button`,className:e===n.id?`rounded-md bg-primary px-2.5 py-1 text-xs font-medium text-primary-foreground`:`rounded-md px-2.5 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground`,"aria-pressed":e===n.id,onClick:()=>t(n.id),"data-testid":`calendars-view-${n.id}`,children:n.label},n.id))})}function W({calendars:t,onToggleVisible:n,onColorChange:i,busy:a}){let{t:o}=w();return e(`aside`,{className:`w-full shrink-0 space-y-2 lg:w-56 xl:w-64`,"data-testid":`calendars-legend`,children:[r(`h2`,{className:`text-xs font-medium text-foreground-subtle`,children:o(`systemPage.calendars.calendars`,`Calendars`)}),r(`ul`,{className:`space-y-1`,children:t.map(t=>e(`li`,{className:`flex items-start gap-2 rounded-md px-1.5 py-1.5 hover:bg-surface`,children:[r(`input`,{type:`checkbox`,className:`mt-1 h-3.5 w-3.5 shrink-0 accent-primary`,checked:t.visible,disabled:a,onChange:e=>n(t.id,e.target.checked),"aria-label":o(`systemPage.calendars.show`,`Show {{name}}`,{name:t.name}),"data-testid":`calendars-visible-${t.id}`}),r(`input`,{type:`color`,className:`mt-0.5 h-6 w-6 shrink-0 cursor-pointer rounded border border-border bg-transparent p-0`,value:t.color,disabled:a,onChange:e=>i(t.id,e.target.value.toUpperCase()),"aria-label":o(`systemPage.calendars.colourFor`,`Colour for {{name}}`,{name:t.name}),"data-testid":`calendars-color-${t.id}`}),e(`div`,{className:`min-w-0 flex-1`,children:[r(`div`,{className:`truncate text-sm font-medium ${t.visible?`text-foreground`:`text-foreground-subtle`}`,children:t.name}),e(`div`,{className:`truncate text-[11px] text-foreground-subtle`,children:[I(t),t.enabled?``:` · ${o(`systemPage.calendars.unavailableAtSource`)}`]})]})]},t.id))})]})}function G({ev:t,color:n,compact:i,onSelect:a}){return r(`button`,{type:`button`,className:i?`block w-full truncate rounded px-1 py-0.5 text-left text-[10px] leading-tight text-white hover:brightness-110`:`block w-full rounded-md px-2 py-1.5 text-left text-xs text-white hover:brightness-110`,style:{backgroundColor:n},title:t.title,onClick:()=>a(t),"data-testid":`calendars-event-${t.id}`,children:i?t.title:e(o,{children:[r(`div`,{className:`font-medium`,children:t.title}),r(`div`,{className:`opacity-90`,children:L(t)})]})})}function K({anchor:t,events:n,colorById:i,today:a,onSelectEvent:o}){let{t:s}=w(),{startMs:c,endMs:l}=M(t,`month`),u=[];for(let e=new Date(c);e.getTime()<l;e=A(e,1))u.push(e);let d=t.getMonth();return e(`div`,{"data-testid":`calendars-month`,children:[r(`div`,{className:`mb-1 grid grid-cols-7 gap-px`,children:O.map(e=>r(`div`,{className:`px-1 py-1 text-center text-[11px] font-medium text-foreground-subtle`,children:e},e))}),r(`div`,{className:`grid grid-cols-7 gap-px overflow-hidden rounded-lg border border-border bg-border`,children:u.map(t=>{let c=k(t).getTime(),l=V(n,c),u=t.getMonth()!==d,f=H(t,a);return e(`div`,{className:`min-h-[5.5rem] bg-background p-1 ${u?`opacity-45`:``}`,children:[r(`div`,{className:f?`mb-1 inline-flex h-5 w-5 items-center justify-center rounded-full bg-primary text-[11px] font-semibold text-primary-foreground`:`mb-1 text-[11px] font-medium text-foreground-subtle`,children:t.getDate()}),e(`div`,{className:`space-y-0.5`,children:[l.slice(0,3).map(e=>r(G,{ev:e,color:i.get(e.calendarId)??`#64748B`,compact:!0,onSelect:o},e.id)),l.length>3?r(`div`,{className:`text-[10px] text-foreground-subtle`,children:s(`common.moreCount`,{count:l.length-3})}):null]})]},c)})})]})}function q({anchor:t,events:n,colorById:i,today:a,onSelectEvent:o}){let s=j(t);return r(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-7 sm:gap-px sm:overflow-hidden sm:rounded-lg sm:border sm:border-border sm:bg-border`,"data-testid":`calendars-week`,children:Array.from({length:7},(e,t)=>A(s,t)).map(t=>{let s=k(t).getTime(),c=V(n,s);return e(`div`,{className:`min-h-[8rem] bg-background p-2 sm:min-h-[12rem]`,children:[r(`div`,{className:H(t,a)?`mb-2 text-xs font-semibold text-primary`:`mb-2 text-xs font-medium text-foreground-subtle`,children:t.toLocaleDateString(void 0,{weekday:`short`,day:`numeric`})}),r(`div`,{className:`space-y-1`,children:c.length===0?r(`p`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):c.map(e=>r(G,{ev:e,color:i.get(e.calendarId)??`#64748B`,onSelect:o},e.id))})]},s)})})}function J({anchor:t,events:n,colorById:i,calName:a,onSelectEvent:o}){let{t:s}=w(),c=V(n,k(t).getTime());return c.length===0?r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-day-empty`,children:s(`systemPage.calendars.noEventsOnThisDay`,`No events on this day.`)}):r(`ul`,{className:`divide-y divide-border rounded-lg border border-border`,"data-testid":`calendars-day`,children:c.map(t=>r(`li`,{children:e(`button`,{type:`button`,className:`flex w-full items-start gap-3 px-3 py-3 text-left hover:bg-surface`,onClick:()=>o(t),"data-testid":`calendars-event-${t.id}`,children:[r(`span`,{className:`mt-1 h-2.5 w-2.5 shrink-0 rounded-full`,style:{backgroundColor:i.get(t.calendarId)??`#64748B`}}),e(`div`,{className:`min-w-0`,children:[r(`div`,{className:`font-medium text-sm text-foreground`,children:t.title}),e(`div`,{className:`text-xs text-foreground-subtle`,children:[L(t),` · `,a.get(t.calendarId)??t.calendarId]}),t.location!==void 0&&t.location.length>0?r(`div`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:t.location}):null]})]})},t.id))})}function Y(){let{t:a}=w(),o=f(),l=x({}),u=m(),[h,g]=i(`month`),[_,v]=i(()=>k(new Date)),[y,b]=i(null),S=t(()=>k(new Date),[]),C=o.isSuccess,O=l.isSuccess&&l.data!==void 0?l.data:void 0,A=t(()=>!C||o.data===void 0?[]:o.data.map(e=>F(e,O)),[C,o.data,O]),j=t(()=>A.filter(e=>e.visible),[A]),I=t(()=>j.map(e=>e.id),[j]),L=t(()=>M(_,h),[_,h]),R=p({startMs:L.startMs,endMs:L.endMs,calendarIds:[...I]},{enabled:C&&I.length>0}),z=R.data??[],V=t(()=>{let e=new Map;for(let t of A)e.set(t.id,t.color);return e},[A]),H=t(()=>{let e=new Map;for(let t of A)e.set(t.id,t.name);return e},[A]),G=n((e,t)=>{u.mutateAsync({calendarId:e,visible:t}).then(()=>l.refetch())},[l,u]),Y=n((e,t)=>{/^#[0-9A-Fa-f]{6}$/.test(t)&&u.mutateAsync({calendarId:e,color:t}).then(()=>l.refetch())},[l,u]),X=n(()=>v(k(new Date)),[]),Z=n(()=>v(e=>P(e,h,-1)),[h]),ee=n(()=>v(e=>P(e,h,1)),[h]),Q=`inline-flex h-8 w-8 items-center justify-center rounded-lg border border-border bg-surface text-foreground hover:bg-primary/5 disabled:opacity-50`,$;return $=o.isPending?r(`p`,{className:`text-sm text-foreground-subtle`,children:a(`systemPage.calendars.loadingCalendars`,`Loading calendars…`)}):o.isError?e(`p`,{className:`text-sm text-destructive`,children:[a(`systemPage.calendars.couldNotListCalendars`,`Could not list calendars:`),` `,o.error.message]}):A.length===0?r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-sources`,children:r(E,{i18nKey:`systemPage.calendars.emptySources`,components:{link:r(T,{to:`/system/integrations?tab=calendars`,className:`text-accent underline-offset-2 hover:underline`})}})}):I.length===0?e(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[r(W,{calendars:A,onToggleVisible:G,onColorChange:Y,busy:u.isPending}),r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-hidden`,children:a(`systemPage.calendars.allCalendarsAreHiddenTurn`,`All calendars are hidden. Turn one on in the legend to see events.`)})]}):e(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[r(W,{calendars:A,onToggleVisible:G,onColorChange:Y,busy:u.isPending}),e(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(U,{mode:h,onChange:g}),e(`div`,{className:`flex items-center gap-1`,children:[r(`button`,{type:`button`,className:Q,onClick:Z,"aria-label":a(`systemPage.calendars.previous`,`Previous`),"data-testid":`calendars-prev`,children:r(s,{className:`h-4 w-4`})}),r(`button`,{type:`button`,className:`inline-flex items-center rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5`,onClick:X,"data-testid":`calendars-today`,children:a(`systemPage.calendars.today`,`Today`)}),r(`button`,{type:`button`,className:Q,onClick:ee,"aria-label":a(`common.next`,`Next`),"data-testid":`calendars-next`,children:r(c,{className:`h-4 w-4`})})]}),r(`span`,{className:`text-sm font-medium text-foreground`,"data-testid":`calendars-period`,children:N(_,h)})]}),R.isPending?r(`p`,{className:`text-sm text-foreground-subtle`,children:a(`systemPage.calendars.loadingEvents`,`Loading events…`)}):R.isError?e(`p`,{className:`text-sm text-destructive`,children:[a(`systemPage.calendars.couldNotListEvents`,`Could not list events:`),` `,R.error.message]}):h===`month`?r(K,{anchor:_,events:z,colorById:V,today:S,onSelectEvent:b}):h===`week`?r(q,{anchor:_,events:z,colorById:V,today:S,onSelectEvent:b}):r(J,{anchor:_,events:z,colorById:V,calName:H,onSelectEvent:b})]})]}),e(D,{icon:d,title:a(`systemPage.calendars.calendars`,`Calendars`),subtitle:a(`systemPage.calendars.calendarsFromConnectedSourcesUsed`,`Calendars from connected sources. Used by Calendar events notification rules.`),children:[$,y===null?null:r(B,{ev:y,calendarName:H.get(y.calendarId)??y.calendarId,color:V.get(y.calendarId)??`#64748B`,onClose:()=>b(null)})]})}export{Y as CalendarsPage,Y as default};
|
|
1
|
+
import{C as e,K as t,R as n,S as r,Y as i,et as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Ei as s,Ti as c}from"./player-overlays-B5FSaids.js";import{fr as l,pr as u}from"./client-JLEP7nv7.js";import{h as d}from"./video-2nOnVl_R.js";import{Ma as f,Na as p,Pa as m,Yr as h,_r as g,dr as _,fr as v,gr as y,hr as b,ja as x,pr as S}from"./src-IQsaq5W-.js";import{t as C}from"./i18n-CXGP1uaw.js";import{t as w}from"./useTranslation-BJr-n0es.js";import{mr as T,pr as E}from"./index-lH9UKmhf.js";import{t as D}from"./AdminPage-CVSTxsAk.js";a();var O=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`];function k(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function A(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function j(e){let t=e.getDay();return k(A(e,t===0?-6:1-t))}function M(e,t){if(t===`day`){let t=k(e);return{startMs:t.getTime(),endMs:A(t,1).getTime()}}if(t===`week`){let t=j(e);return{startMs:t.getTime(),endMs:A(t,7).getTime()}}let n=new Date(e.getFullYear(),e.getMonth(),1),r=new Date(e.getFullYear(),e.getMonth()+1,0),i=j(n),a=A(j(r),7);return{startMs:i.getTime(),endMs:a.getTime()}}function N(e,t){if(t===`day`)return e.toLocaleDateString(void 0,{weekday:`long`,year:`numeric`,month:`long`,day:`numeric`});if(t===`week`){let t=j(e),n=A(t,6),r={month:`short`,day:`numeric`};return`${t.toLocaleDateString(void 0,r)} – ${n.toLocaleDateString(void 0,{...r,year:`numeric`})}`}return e.toLocaleDateString(void 0,{month:`long`,year:`numeric`})}function P(e,t,n){return t===`day`?A(e,n):t===`week`?A(e,n*7):new Date(e.getFullYear(),e.getMonth()+n,1)}function F(e,t){if(t===void 0)return e;let n=t.calendars[e.id];return n===void 0?e:{...e,visible:n.visible??e.visible,color:n.color??e.defaultColor}}function I(e){return e.providerAddonId!==void 0&&e.providerAddonId.length>0?e.providerAddonId:e.source===`ha`?`Home Assistant`:e.source}function L(e){if(e.allDay===!0)return C.t(`systemPage.calendars.allDay`);let t=new Date(e.startMs),n=new Date(e.endMs),r={hour:`2-digit`,minute:`2-digit`};return`${t.toLocaleTimeString([],r)} – ${n.toLocaleTimeString([],r)}`}function R(e){let t=l(e),n=new Date(t.startMs),r=new Date(t.endMs),i={weekday:`short`,year:`numeric`,month:`short`,day:`numeric`};if(e.allDay===!0){let e=k(n),t=A(k(r),-1);return H(e,t)?C.t(`systemPage.calendars.dayAllDay`,{date:n.toLocaleDateString(void 0,i)}):C.t(`systemPage.calendars.rangeAllDay`,{from:n.toLocaleDateString(void 0,i),to:t.toLocaleDateString(void 0,i)})}let a={hour:`2-digit`,minute:`2-digit`};return H(n,r)?`${n.toLocaleDateString(void 0,i)} · ${n.toLocaleTimeString([],a)} – ${r.toLocaleTimeString([],a)}`:`${n.toLocaleString(void 0,{...i,...a})} – ${r.toLocaleString(void 0,{...i,...a})}`}function z({label:t,children:n}){return e(`div`,{className:`grid grid-cols-[7rem_minmax(0,1fr)] gap-x-3 gap-y-1 text-sm`,children:[r(`dt`,{className:`text-foreground-subtle`,children:t}),r(`dd`,{className:`min-w-0 break-words text-foreground`,children:n})]})}function B({ev:t,calendarName:n,color:i,onClose:a}){let{t:o}=w();return r(_,{open:!0,onOpenChange:e=>!e&&a(),children:e(S,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`calendars-event-detail`,children:[r(y,{children:e(`div`,{className:`flex min-w-0 items-start gap-2.5`,children:[r(`span`,{className:`mt-1.5 h-3 w-3 shrink-0 rounded-full`,style:{backgroundColor:i},"aria-hidden":!0}),r(g,{className:`min-w-0 break-words`,children:t.title})]})}),r(v,{children:e(`dl`,{className:`space-y-3`,children:[r(z,{label:o(`systemPage.calendars.when`,`When`),children:R(t)}),r(z,{label:o(`systemPage.calendars.calendar`,`Calendar`),children:n}),t.location!==void 0&&t.location.length>0?r(z,{label:o(`systemPage.calendars.location`,`Location`),children:t.location}):null,t.description!==void 0&&t.description.length>0?r(z,{label:o(`systemPage.calendars.description`,`Description`),children:r(`span`,{className:`whitespace-pre-wrap`,children:t.description})}):null]})}),r(b,{children:r(h,{type:`button`,size:`sm`,variant:`secondary`,onClick:a,children:o(`common.close`,`Close`)})})]})})}function V(e,t){return e.filter(e=>u(e,t))}function H(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function U({mode:e,onChange:t}){let{t:n}=w(),i=[{id:`month`,label:n(`systemPage.calendars.month`,`Month`)},{id:`week`,label:n(`systemPage.calendars.week`,`Week`)},{id:`day`,label:n(`systemPage.calendars.day`,`Day`)}];return r(`div`,{className:`inline-flex rounded-lg border border-border bg-surface p-0.5`,role:`group`,"aria-label":n(`systemPage.calendars.calendarView`,`Calendar view`),children:i.map(n=>r(`button`,{type:`button`,className:e===n.id?`rounded-md bg-primary px-2.5 py-1 text-xs font-medium text-primary-foreground`:`rounded-md px-2.5 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground`,"aria-pressed":e===n.id,onClick:()=>t(n.id),"data-testid":`calendars-view-${n.id}`,children:n.label},n.id))})}function W({calendars:t,onToggleVisible:n,onColorChange:i,busy:a}){let{t:o}=w();return e(`aside`,{className:`w-full shrink-0 space-y-2 lg:w-56 xl:w-64`,"data-testid":`calendars-legend`,children:[r(`h2`,{className:`text-xs font-medium text-foreground-subtle`,children:o(`systemPage.calendars.calendars`,`Calendars`)}),r(`ul`,{className:`space-y-1`,children:t.map(t=>e(`li`,{className:`flex items-start gap-2 rounded-md px-1.5 py-1.5 hover:bg-surface`,children:[r(`input`,{type:`checkbox`,className:`mt-1 h-3.5 w-3.5 shrink-0 accent-primary`,checked:t.visible,disabled:a,onChange:e=>n(t.id,e.target.checked),"aria-label":o(`systemPage.calendars.show`,`Show {{name}}`,{name:t.name}),"data-testid":`calendars-visible-${t.id}`}),r(`input`,{type:`color`,className:`mt-0.5 h-6 w-6 shrink-0 cursor-pointer rounded border border-border bg-transparent p-0`,value:t.color,disabled:a,onChange:e=>i(t.id,e.target.value.toUpperCase()),"aria-label":o(`systemPage.calendars.colourFor`,`Colour for {{name}}`,{name:t.name}),"data-testid":`calendars-color-${t.id}`}),e(`div`,{className:`min-w-0 flex-1`,children:[r(`div`,{className:`truncate text-sm font-medium ${t.visible?`text-foreground`:`text-foreground-subtle`}`,children:t.name}),e(`div`,{className:`truncate text-[11px] text-foreground-subtle`,children:[I(t),t.enabled?``:` · ${o(`systemPage.calendars.unavailableAtSource`)}`]})]})]},t.id))})]})}function G({ev:t,color:n,compact:i,onSelect:a}){return r(`button`,{type:`button`,className:i?`block w-full truncate rounded px-1 py-0.5 text-left text-[10px] leading-tight text-white hover:brightness-110`:`block w-full rounded-md px-2 py-1.5 text-left text-xs text-white hover:brightness-110`,style:{backgroundColor:n},title:t.title,onClick:()=>a(t),"data-testid":`calendars-event-${t.id}`,children:i?t.title:e(o,{children:[r(`div`,{className:`font-medium`,children:t.title}),r(`div`,{className:`opacity-90`,children:L(t)})]})})}function K({anchor:t,events:n,colorById:i,today:a,onSelectEvent:o}){let{t:s}=w(),{startMs:c,endMs:l}=M(t,`month`),u=[];for(let e=new Date(c);e.getTime()<l;e=A(e,1))u.push(e);let d=t.getMonth();return e(`div`,{"data-testid":`calendars-month`,children:[r(`div`,{className:`mb-1 grid grid-cols-7 gap-px`,children:O.map(e=>r(`div`,{className:`px-1 py-1 text-center text-[11px] font-medium text-foreground-subtle`,children:e},e))}),r(`div`,{className:`grid grid-cols-7 gap-px overflow-hidden rounded-lg border border-border bg-border`,children:u.map(t=>{let c=k(t).getTime(),l=V(n,c),u=t.getMonth()!==d,f=H(t,a);return e(`div`,{className:`min-h-[5.5rem] bg-background p-1 ${u?`opacity-45`:``}`,children:[r(`div`,{className:f?`mb-1 inline-flex h-5 w-5 items-center justify-center rounded-full bg-primary text-[11px] font-semibold text-primary-foreground`:`mb-1 text-[11px] font-medium text-foreground-subtle`,children:t.getDate()}),e(`div`,{className:`space-y-0.5`,children:[l.slice(0,3).map(e=>r(G,{ev:e,color:i.get(e.calendarId)??`#64748B`,compact:!0,onSelect:o},e.id)),l.length>3?r(`div`,{className:`text-[10px] text-foreground-subtle`,children:s(`common.moreCount`,{count:l.length-3})}):null]})]},c)})})]})}function q({anchor:t,events:n,colorById:i,today:a,onSelectEvent:o}){let s=j(t);return r(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-7 sm:gap-px sm:overflow-hidden sm:rounded-lg sm:border sm:border-border sm:bg-border`,"data-testid":`calendars-week`,children:Array.from({length:7},(e,t)=>A(s,t)).map(t=>{let s=k(t).getTime(),c=V(n,s);return e(`div`,{className:`min-h-[8rem] bg-background p-2 sm:min-h-[12rem]`,children:[r(`div`,{className:H(t,a)?`mb-2 text-xs font-semibold text-primary`:`mb-2 text-xs font-medium text-foreground-subtle`,children:t.toLocaleDateString(void 0,{weekday:`short`,day:`numeric`})}),r(`div`,{className:`space-y-1`,children:c.length===0?r(`p`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):c.map(e=>r(G,{ev:e,color:i.get(e.calendarId)??`#64748B`,onSelect:o},e.id))})]},s)})})}function J({anchor:t,events:n,colorById:i,calName:a,onSelectEvent:o}){let{t:s}=w(),c=V(n,k(t).getTime());return c.length===0?r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-day-empty`,children:s(`systemPage.calendars.noEventsOnThisDay`,`No events on this day.`)}):r(`ul`,{className:`divide-y divide-border rounded-lg border border-border`,"data-testid":`calendars-day`,children:c.map(t=>r(`li`,{children:e(`button`,{type:`button`,className:`flex w-full items-start gap-3 px-3 py-3 text-left hover:bg-surface`,onClick:()=>o(t),"data-testid":`calendars-event-${t.id}`,children:[r(`span`,{className:`mt-1 h-2.5 w-2.5 shrink-0 rounded-full`,style:{backgroundColor:i.get(t.calendarId)??`#64748B`}}),e(`div`,{className:`min-w-0`,children:[r(`div`,{className:`font-medium text-sm text-foreground`,children:t.title}),e(`div`,{className:`text-xs text-foreground-subtle`,children:[L(t),` · `,a.get(t.calendarId)??t.calendarId]}),t.location!==void 0&&t.location.length>0?r(`div`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:t.location}):null]})]})},t.id))})}function Y(){let{t:a}=w(),o=f(),l=x({}),u=m(),[h,g]=i(`month`),[_,v]=i(()=>k(new Date)),[y,b]=i(null),S=t(()=>k(new Date),[]),C=o.isSuccess,O=l.isSuccess&&l.data!==void 0?l.data:void 0,A=t(()=>!C||o.data===void 0?[]:o.data.map(e=>F(e,O)),[C,o.data,O]),j=t(()=>A.filter(e=>e.visible),[A]),I=t(()=>j.map(e=>e.id),[j]),L=t(()=>M(_,h),[_,h]),R=p({startMs:L.startMs,endMs:L.endMs,calendarIds:[...I]},{enabled:C&&I.length>0}),z=R.data??[],V=t(()=>{let e=new Map;for(let t of A)e.set(t.id,t.color);return e},[A]),H=t(()=>{let e=new Map;for(let t of A)e.set(t.id,t.name);return e},[A]),G=n((e,t)=>{u.mutateAsync({calendarId:e,visible:t}).then(()=>l.refetch())},[l,u]),Y=n((e,t)=>{/^#[0-9A-Fa-f]{6}$/.test(t)&&u.mutateAsync({calendarId:e,color:t}).then(()=>l.refetch())},[l,u]),X=n(()=>v(k(new Date)),[]),Z=n(()=>v(e=>P(e,h,-1)),[h]),ee=n(()=>v(e=>P(e,h,1)),[h]),Q=`inline-flex h-8 w-8 items-center justify-center rounded-lg border border-border bg-surface text-foreground hover:bg-primary/5 disabled:opacity-50`,$;return $=o.isPending?r(`p`,{className:`text-sm text-foreground-subtle`,children:a(`systemPage.calendars.loadingCalendars`,`Loading calendars…`)}):o.isError?e(`p`,{className:`text-sm text-destructive`,children:[a(`systemPage.calendars.couldNotListCalendars`,`Could not list calendars:`),` `,o.error.message]}):A.length===0?r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-sources`,children:r(E,{i18nKey:`systemPage.calendars.emptySources`,components:{link:r(T,{to:`/system/integrations?tab=calendars`,className:`text-accent underline-offset-2 hover:underline`})}})}):I.length===0?e(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[r(W,{calendars:A,onToggleVisible:G,onColorChange:Y,busy:u.isPending}),r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-hidden`,children:a(`systemPage.calendars.allCalendarsAreHiddenTurn`,`All calendars are hidden. Turn one on in the legend to see events.`)})]}):e(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[r(W,{calendars:A,onToggleVisible:G,onColorChange:Y,busy:u.isPending}),e(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(U,{mode:h,onChange:g}),e(`div`,{className:`flex items-center gap-1`,children:[r(`button`,{type:`button`,className:Q,onClick:Z,"aria-label":a(`systemPage.calendars.previous`,`Previous`),"data-testid":`calendars-prev`,children:r(s,{className:`h-4 w-4`})}),r(`button`,{type:`button`,className:`inline-flex items-center rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5`,onClick:X,"data-testid":`calendars-today`,children:a(`systemPage.calendars.today`,`Today`)}),r(`button`,{type:`button`,className:Q,onClick:ee,"aria-label":a(`common.next`,`Next`),"data-testid":`calendars-next`,children:r(c,{className:`h-4 w-4`})})]}),r(`span`,{className:`text-sm font-medium text-foreground`,"data-testid":`calendars-period`,children:N(_,h)})]}),R.isPending?r(`p`,{className:`text-sm text-foreground-subtle`,children:a(`systemPage.calendars.loadingEvents`,`Loading events…`)}):R.isError?e(`p`,{className:`text-sm text-destructive`,children:[a(`systemPage.calendars.couldNotListEvents`,`Could not list events:`),` `,R.error.message]}):h===`month`?r(K,{anchor:_,events:z,colorById:V,today:S,onSelectEvent:b}):h===`week`?r(q,{anchor:_,events:z,colorById:V,today:S,onSelectEvent:b}):r(J,{anchor:_,events:z,colorById:V,calName:H,onSelectEvent:b})]})]}),e(D,{icon:d,title:a(`systemPage.calendars.calendars`,`Calendars`),subtitle:a(`systemPage.calendars.calendarsFromConnectedSourcesUsed`,`Calendars from connected sources. Used by Calendar events notification rules.`),children:[$,y===null?null:r(B,{ev:y,calendarName:H.get(y.calendarId)??y.calendarId,color:V.get(y.calendarId)??`#64748B`,onClose:()=>b(null)})]})}export{Y as CalendarsPage,Y as default};
|