@camstack/addon-admin-ui 1.2.499 → 1.2.501
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 +13 -0
- package/dist/assets/{AddonAssetIcon-DjkuwW5K.js → AddonAssetIcon-B_mf6RWm.js} +1 -1
- package/dist/assets/{Addons-PTfAXTcl.js → Addons-Cb6acpoY.js} +1 -1
- package/dist/assets/{AdminPage-CdqsBsG5.js → AdminPage-CV0QlJ3B.js} +1 -1
- package/dist/assets/{AdminSectionedPage-BYs8ku8k.js → AdminSectionedPage-BBzHFRdX.js} +1 -1
- package/dist/assets/AiProfiles-8TF3xjgg.js +3 -0
- package/dist/assets/{BrokerEditorDialog-CONeUoQZ.js → BrokerEditorDialog-B0caFBKZ.js} +1 -1
- package/dist/assets/Build-Xnlo6o_D.js +40 -0
- package/dist/assets/{Calendars-Cr9FOfbM.js → Calendars-DUeEHzYQ.js} +1 -1
- package/dist/assets/{Cluster-CaDZt6wf.js → Cluster-C94n--nx.js} +1 -1
- package/dist/assets/{CompositionBlockEditor-Cu_GMMSI.js → CompositionBlockEditor-ym4ZV8sX.js} +1 -1
- package/dist/assets/{CompositionEditorPage-DHmZe045.js → CompositionEditorPage-BJvn56ZF.js} +1 -1
- package/dist/assets/{Data-CLUboL1k.js → Data-DlzonlmW.js} +1 -1
- package/dist/assets/{DeviceDetail-PeXgC7D7.js → DeviceDetail-DyLsUAqL.js} +1 -1
- package/dist/assets/{DeviceDoActionFields-CTqHC6sW.js → DeviceDoActionFields-cDGcUl-R.js} +1 -1
- package/dist/assets/{Devices-72RGQIZG.js → Devices-CMNofKy8.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-Ba0hOImQ.js → EmbedPlayerPage-BVOyRHsA.js} +1 -1
- package/dist/assets/{HelperWizard-pM6WaJkS.js → HelperWizard-C88ULCYq.js} +1 -1
- package/dist/assets/{History-Dw72vHO6.js → History-t_uoaPpG.js} +1 -1
- package/dist/assets/{Identity-CPnY-pTg.js → Identity-DiBBudOW.js} +1 -1
- package/dist/assets/{IntegrationDetail-DCuJRrDX.js → IntegrationDetail-B8gBda81.js} +1 -1
- package/dist/assets/{IntegrationHub-AlH87vBq.js → IntegrationHub-GrzjNslW.js} +1 -1
- package/dist/assets/{Integrations-UhKXHXBR.js → Integrations-D6KthXEF.js} +1 -1
- package/dist/assets/{Integrations-CEyrrglP.js → Integrations-DCLPgkRU.js} +1 -1
- package/dist/assets/{Library-BGe2f4pB.js → Library-CywHGHiE.js} +1 -1
- package/dist/assets/{Locations-BjT72gvn.js → Locations-BjRSPp5J.js} +1 -1
- package/dist/assets/{Logs-C_7aqJhI.js → Logs-CNNOSCVp.js} +1 -1
- package/dist/assets/{MaskShapeCanvas-BfY6UgU8.js → MaskShapeCanvas-95iTn7i0.js} +1 -1
- package/dist/assets/{MotionZonesSettings-Dn5IgvFT.js → MotionZonesSettings-CaCqDalH.js} +1 -1
- package/dist/assets/{MyAccess-Bo_FOLPs.js → MyAccess-C3uzlk10.js} +1 -1
- package/dist/assets/{Network-BX6Y8dwk.js → Network-CZ4xHzLW.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-2TqELGQC.js → NodeAddonsSettingsPanel-BfighMS8.js} +1 -1
- package/dist/assets/{Notifications-T_G8vhSu.js → Notifications-BdmCmJ2W.js} +1 -1
- package/dist/assets/{Pipeline-BRYPZ_2h.js → Pipeline-DG-vcE0_.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-BCqWKR8b.js → PrivacyMaskSettings-CRWyEMXU.js} +1 -1
- package/dist/assets/{Recordings-CqsVLa2F.js → Recordings-BpwE9JN_.js} +1 -1
- package/dist/assets/{ScanNetworkModal-DAFJTCNh.js → ScanNetworkModal-wDrkbkgj.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-DOi8VJsT.js → SceneMonitorEditor-BVY8z5nP.js} +1 -1
- package/dist/assets/{SessionsList-zyzKyjyE.js → SessionsList-DI5IhzU9.js} +1 -1
- package/dist/assets/{Showroom-DHXru4Aa.js → Showroom-B7W2AkOm.js} +1 -1
- package/dist/assets/{System-qySy6YJm.js → System-Cpe7wkVv.js} +1 -1
- package/dist/assets/{Terminal-B6xVGljU.js → Terminal-DD8pjpg-.js} +1 -1
- package/dist/assets/{Viewer-X0_CVWn_.js → Viewer-gI0qsTA2.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-D7ATU8Xn.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CRywONZ3.js} +1 -1
- package/dist/assets/{addon-icons-context-BOriiEsT.js → addon-icons-context-Cti7cTZ4.js} +1 -1
- package/dist/assets/{archive-BXVJNilF.js → archive-PRZmhl9-.js} +1 -1
- package/dist/assets/{assignment-candidates-DXAO7Cbf.js → assignment-candidates-BgsEkAFx.js} +1 -1
- package/dist/assets/{authed-media-DH0VgksC.js → authed-media-HL5k5ZI9.js} +1 -1
- package/dist/assets/{bell-off-Cje1_WzG.js → bell-off-Wp9nXhK0.js} +1 -1
- package/dist/assets/{board-model-DjKb-Uu4.js → board-model-C9x5MlfE.js} +1 -1
- package/dist/assets/{boxes-Bmx0I9xI.js → boxes-EVKxMyl3.js} +1 -1
- package/dist/assets/circle-slash-xh1tUz_M.js +1 -0
- package/dist/assets/client-Rf8T-Qxy.js +674 -0
- package/dist/assets/{cloud-upload-DOZOWIaX.js → cloud-upload-D1rJHyyL.js} +1 -1
- package/dist/assets/crop-6qnHQHCf.js +1 -0
- package/dist/assets/{device-integration-icon-DeM12QWn.js → device-integration-icon-BN3tz8Fb.js} +1 -1
- package/dist/assets/device-picker-model-DL02cGAU.js +1 -0
- package/dist/assets/{dist-DjoKQtup.js → dist-BtSMcY1H.js} +1 -1
- package/dist/assets/dist-KDpN_XDi.js +674 -0
- package/dist/assets/{eraser-CVudvbRZ.js → eraser-yP8-Qrpb.js} +1 -1
- package/dist/assets/{format-bLJqYfjk.js → format-B2NBW7cS.js} +1 -1
- package/dist/assets/{hard-drive-download-D7rFyG82.js → hard-drive-download-DR6ciRuk.js} +1 -1
- package/dist/assets/{hostInit-DI-nfbwk.js → hostInit-DSbl59EP.js} +1 -1
- package/dist/assets/i18n-BDPAB47Q.js +1 -0
- package/dist/assets/{icons-DHFi8jjf.js → icons-CvkjwiJn.js} +1 -1
- package/dist/assets/{index-D_AGxR1C.js → index-DUGfFMf0.js} +3 -3
- package/dist/assets/{key-Bx56zYph.js → key-DtVIVyHw.js} +1 -1
- package/dist/assets/{key-round-Dzh0-Y90.js → key-round-_CfxOK2a.js} +1 -1
- package/dist/assets/{layers-6nDyzJGk.js → layers-DhmA7JNn.js} +1 -1
- package/dist/assets/{linked-devices-model-C3vv05kt.js → linked-devices-model-CwgRN3Vm.js} +1 -1
- package/dist/assets/{list-ordered-CT5RBbXf.js → list-ordered-Bj8Zr-Wv.js} +1 -1
- package/dist/assets/{location-owned-usage-Bx1OkT8H.js → location-owned-usage-CFSvary3.js} +1 -1
- package/dist/assets/{log-in-CANFQKog.js → log-in-l36ik9Wr.js} +1 -1
- package/dist/assets/{memory-stick-CRaTDBUV.js → memory-stick-DbUkE9Fa.js} +1 -1
- package/dist/assets/{message-square-plus-BxGpiezi.js → message-square-plus-jm9v9hN-.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-6afad399.js → mf-entry-bootstrap-0-ac5e508a.js} +2 -2
- package/dist/assets/{mic-off-DyTS6uuu.js → mic-off-BjaY8dq2.js} +1 -1
- package/dist/assets/{monitor-off-BgwnbqXX.js → monitor-off-T1bFmYrx.js} +1 -1
- package/dist/assets/{monitor-smartphone-Bv0ribmJ.js → monitor-smartphone-DMpXo7Ar.js} +1 -1
- package/dist/assets/mount-DL02cGAU.js +1 -0
- package/dist/assets/{player-overlays-DmlN4sZb.js → player-overlays-BFb5SWA9.js} +1 -1
- package/dist/assets/{recycle-DHY8PHbW.js → recycle-CRzk0gFj.js} +1 -1
- package/dist/assets/remoteEntry-DIlhbTG-.js +1 -0
- package/dist/assets/{scan-eye-BhtfT2TC.js → scan-eye-DkFdWjWi.js} +1 -1
- package/dist/assets/{scissors-Dj546Wu-.js → scissors-V4FufEMU.js} +1 -1
- package/dist/assets/{search-x-De3-l_vz.js → search-x-DXTPMB2A.js} +1 -1
- package/dist/assets/{send-DC9n_ItK.js → send-D-vjMUJY.js} +1 -1
- package/dist/assets/{settings-2-N6ClOXOl.js → settings-2-DUxYPsEJ.js} +1 -1
- package/dist/assets/{sigma-deG3J-yB.js → sigma-D8LyGcav.js} +1 -1
- package/dist/assets/{speaker-DGGo7wtR.js → speaker-CKpoIyB7.js} +1 -1
- package/dist/assets/{src-DWX1wfhS.js → src-BfkcE2yV.js} +3 -3
- package/dist/assets/{step-inspector-model-BxKcZWYu.js → step-inspector-model-DNorKN85.js} +1 -1
- package/dist/assets/{table-2-3euQhw5E.js → table-2-uZMmLo6a.js} +1 -1
- package/dist/assets/{timer-reset-BdIAmvAS.js → timer-reset-BWav2Kmp.js} +1 -1
- package/dist/assets/{ungroup-CbtqPFVa.js → ungroup-BhcUGbr2.js} +1 -1
- package/dist/assets/{unlink-aJqh9mCl.js → unlink-Dse438EC.js} +1 -1
- package/dist/assets/{usb-CYLx4jAF.js → usb-SlY_Gb57.js} +1 -1
- package/dist/assets/{use-scenes-feed-C_iMGuNF.js → use-scenes-feed-Cz0AwuYh.js} +1 -1
- package/dist/assets/{use-stationary-objects-h9SgJ5H7.js → use-stationary-objects-B67ttHhM.js} +1 -1
- package/dist/assets/useEventInvalidation-DL02cGAU.js +1 -0
- package/dist/assets/{useNodeUrlSelection-CO3V-rVN.js → useNodeUrlSelection-Bxfo2t0-.js} +1 -1
- package/dist/assets/user-round-C4iC5VEd.js +1 -0
- package/dist/assets/{user-x-DuE_Nzjl.js → user-x-BrW6KRXD.js} +1 -1
- package/dist/assets/{video-TyyuRVZ9.js → video-B6REUv1P.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DHSRAP7h.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DT2p44li.js} +2 -2
- package/dist/index.html +9 -9
- package/dist/server/addon.js +27 -6
- package/package.json +1 -1
- package/dist/assets/AiProfiles-BaIX3xlW.js +0 -3
- package/dist/assets/Build-64GFrVBv.js +0 -40
- package/dist/assets/circle-slash-CV1_3oBt.js +0 -1
- package/dist/assets/client-Gv3pB3LY.js +0 -648
- package/dist/assets/crop-BPFdBdvk.js +0 -1
- package/dist/assets/device-picker-model-Bf0X4ydS.js +0 -1
- package/dist/assets/dist-CBReFtub.js +0 -648
- package/dist/assets/i18n-D0vRhk5m.js +0 -1
- package/dist/assets/mount-Bf0X4ydS.js +0 -1
- package/dist/assets/remoteEntry-BXlJ18mT.js +0 -1
- package/dist/assets/useEventInvalidation-Bf0X4ydS.js +0 -1
- package/dist/assets/user-round-DORzQt2o.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,t as d,x as f}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 p,Ar as m,Di as h,Fn as g,Ht as _,In as v,Ti as y,Vn as b,dt as x,fr as S,pa as C,ra as w,st as T,vt as E,wn as D,yi as O,yn as k,zt as A}from"./player-overlays-BFb5SWA9.js";import{Di as j,Ji as M,Mi as N,Va as P,Xi as F,Yi as I,Zi as L,aa as R,di as ee,fi as z,ji as B,li as V,no as te,oa as ne,qi as re,un as ie,wi as ae,xi as oe}from"./client-Rf8T-Qxy.js";import{t as se}from"./boxes-EVKxMyl3.js";import{n as ce,r as le,t as ue}from"./ungroup-BhcUGbr2.js";import{s as de}from"./video-B6REUv1P.js";import{Cn as fe,Da as pe,Ea as me,Fa as H,Ia as he,Ir as ge,Kt as _e,Na as ve,Nr as ye,Oa as be,Pa as xe,Ro as Se,Sn as Ce,So as we,Tr as U,Un as Te,Yr as W,Zt as Ee,_o as De,ad as G,bd as Oe,br as ke,ed as K,en as Ae,ft as je,gn as Me,id as Ne,ka as Pe,mt as Fe,nd as Ie,ni as q,po as Le,rd as Re,rn as ze,vd as Be,vt as Ve}from"./src-BfkcE2yV.js";import{t as J}from"./i18n-BDPAB47Q.js";import{t as Y}from"./useTranslation-BJr-n0es.js";import{P as He,S as Ue,dr as We,gr as Ge,h as Ke,m as qe,mr as Je,or as Ye,ur as X}from"./index-DUGfFMf0.js";import{t as Xe}from"./AdminSectionedPage-BBzHFRdX.js";import{t as Ze}from"./DeviceDoActionFields-cDGcUl-R.js";import{V as Qe,p as $e,t as et,u as tt}from"./HelperWizard-C88ULCYq.js";import{t as nt}from"./CompositionBlockEditor-ym4ZV8sX.js";var rt=`const AUTOMATION_RECIPE =`,it=`// 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 at(e){return e.includes(rt)}function ot(e){let t=e.indexOf(rt);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 st(e){let t=ot(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=M.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 ct(e){let t=ot(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)}${it}${e.slice(i)}`}u();var lt=6e4;function ut(){let e=De({projection:`slim`});return r(()=>(e.data??[]).filter(e=>ie(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 dt(e){let t=x();return l({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:lt,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function ft(e,t){return e.find(e=>e.cap===t)?.fields??[]}function Z({children:e}){return o(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function pt(e){let t=dt(e.deviceId);if(t.data!==void 0)return ft(t.data,e.cap).find(t=>t.path===e.fieldPath)}function mt({value:t,devices:n,onChange:r}){let{t:i}=Y(),a=dt(t.deviceId),s=a.data??[],c=ft(s,t.cap);return e(f,{children:[e(`label`,{className:`min-w-[10rem] flex-1`,children:[o(Z,{children:i(`automation.fieldPicker.device`,`Device`)}),o(K,{value:String(t.deviceId),onChange:e=>r({deviceId:Number(e.target.value),cap:``,fieldPath:``}),options:[{value:`0`,label:i(`automation.fieldPicker.selectADevice`,`Select a device…`)},...n.map(e=>({value:String(e.id),label:e.name}))]})]}),e(`label`,{className:`min-w-[9rem] flex-1`,children:[o(Z,{children:i(`automation.fieldPicker.capability`,`Capability`)}),o(K,{value:t.cap,disabled:t.deviceId===0,onChange:e=>r({...t,cap:e.target.value,fieldPath:``}),options:[{value:``,label:ht(t.deviceId,s.length,a.isLoading)},...s.map(e=>({value:e.cap,label:e.cap}))]})]}),e(`label`,{className:`min-w-[9rem] flex-1`,children:[o(Z,{children:i(`automation.fieldPicker.field`,`Field`)}),o(K,{value:t.fieldPath,disabled:t.cap===``,onChange:e=>r({...t,fieldPath:e.target.value}),options:[{value:``,label:c.length===0?i(`automation.fieldPicker.noReadableFields`,`No readable fields`):i(`automation.fieldPicker.selectAField`,`Select a field…`)},...c.map(e=>({value:e.path,label:`${e.path} (${e.kind})`}))]})]})]})}function ht(e,t,n){return e===0?J.t(`automation.fieldPicker.pickDeviceFirst`):n?J.t(`automation.fieldPicker.readingDevice`):t===0?J.t(`automation.fieldPicker.noReadableCaps`):J.t(`automation.fieldPicker.selectCap`)}var gt=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function _t(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 gt}}function vt(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 yt(e){return _t(e).map(e=>({value:e,label:vt(e)}))}function bt(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(`automation.readOnly.stationaryTrigger`);case`detection`:case`interval`:return J.t(`automation.readOnly.otherTrigger`);default:return J.t(`helpers.recipeParts.trigger_manual`)}}var xt={triggers:[],actions:[]};function St(e){switch(e){case`device-state`:return{kind:e,deviceId:0,cap:``,fieldPath:``};case`device-event`:return{kind:e,category:``};case`schedule`:return{kind:e,cron:`0 30 23 * * *`};default:return{kind:`manual`}}}function Ct(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
|
+
`};default:return{kind:`cap`,deviceId:0,cap:``,method:``}}}function wt(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function Tt(){return{kind:`expression`,expr:``,bindings:{}}}function Et(e,t,n){return e.map((e,r)=>r===t?n:e)}function Dt(e,t){return e.filter((e,n)=>n!==t)}function Ot(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=Dt(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function kt(e,t){return{...e,triggers:[...t]}}function At(e,t){return{...e,actions:[...t]}}var jt=[{value:`cap`,labelKey:`automation.actionList.kindCap`},{value:`wait`,labelKey:`automation.actionList.kindWait`},{value:`code`,labelKey:`automation.actionList.kindCode`}];function Mt({actions:t,devices:n,devicesState:r=`answered`,onChange:i}){let{t:a}=Y();return e(`div`,{className:`space-y-2`,children:[t.length===0&&o(`p`,{className:`text-xs text-warning`,children:a(`automation.actionList.noActionsYetAnAutomation`,`No actions yet. An automation that does nothing is not an automation.`)}),t.map((s,c)=>e(`div`,{className:`rounded border border-border p-3 space-y-2`,children:[e(`div`,{className:`flex flex-wrap items-end gap-2`,children:[o(q,{variant:`default`,children:c+1}),e(`label`,{className:`w-40`,children:[o(Z,{children:a(`automation.actionList.step`,`Step`)}),o(K,{value:s.kind,onChange:e=>i(Et(t,c,Ct(Nt(e.target.value)))),options:jt.map(e=>({value:e.value,label:a(e.labelKey)}))})]}),e(`div`,{className:`ml-auto flex items-center gap-1`,children:[o(W,{variant:`ghost`,disabled:c===0,onClick:()=>i(Ot(t,c,c-1)),title:a(`automation.actionList.runThisStepEarlier`,`Run this step earlier`),children:o(p,{className:`h-3.5 w-3.5`})}),o(W,{variant:`ghost`,disabled:c===t.length-1,onClick:()=>i(Ot(t,c,c+1)),title:a(`automation.actionList.runThisStepLater`,`Run this step later`),children:o(w,{className:`h-3.5 w-3.5`})}),o(W,{variant:`ghost`,onClick:()=>i(Dt(t,c)),title:a(`automation.actionList.removeThisStep`,`Remove this step`),children:o(_,{className:`h-3.5 w-3.5`})})]})]}),s.kind===`wait`&&e(`label`,{className:`block w-32`,children:[o(Z,{children:a(`automation.actionList.seconds`,`Seconds`)}),o(G,{type:`number`,min:0,max:300,value:String(s.seconds),onChange:e=>i(Et(t,c,{kind:`wait`,seconds:Number(e.target.value)}))})]}),s.kind===`code`&&e(`label`,{className:`block`,children:[o(Z,{children:a(`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:s.code,spellCheck:!1,onChange:e=>i(Et(t,c,{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`,{})}})})]}),s.kind===`cap`&&o(Ft,{action:s,devices:n,devicesState:r,onChange:e=>i(Et(t,c,e))})]},`${s.kind}-${String(c)}`)),e(`div`,{className:`flex items-center gap-2`,children:[e(W,{variant:`outline`,onClick:()=>i([...t,Ct(`cap`)]),children:[o(g,{className:`h-4 w-4`}),` `,a(`automation.actionList.addStep`)]}),t.length>1&&o(`span`,{className:`text-xs text-foreground-subtle`,children:a(`automation.actionList.stepsRunInOrderAnd`,`Steps run in order and stop at the first failure.`)})]})]})}function Nt(e){return jt.find(t=>t.value===e)?.value??`cap`}function Pt(e){return typeof e==`number`?e:typeof e==`object`&&e&&`$var`in e?{$var:e.$var}:[...e]}function Ft({action:e,devices:t,devicesState:n,onChange:r}){return o(Ze,{value:e,allowTriggerDevice:!0,allowMultiSameFamily:!0,devices:t,listState:n,onChange:e=>r({kind:`cap`,deviceId:Pt(e.deviceId),cap:e.cap,method:e.method,...e.args===void 0?{}:{args:{...e.args}}})})}function It({value:t,field:n,deviceId:r,cap:i,onChange:a}){let{t:s}=Y(),c=Ht(n,r,i);if(n?.kind===`boolean`)return o(K,{value:t===!0?`true`:`false`,onChange:e=>a(e.target.value===`true`),options:[{value:`true`,label:s(`common.true`)},{value:`false`,label:s(`common.false`)}]});if(n?.kind===`enum`&&n.enumValues!==void 0&&n.enumValues.length>0)return o(K,{value:String(t),onChange:e=>a(e.target.value),options:n.enumValues.map(e=>({value:e,label:e}))});if(n?.kind===`number`){let n=typeof t==`number`&&c?c.toDisplayValue(t):t;return e(`span`,{className:`inline-flex items-center gap-1`,children:[o(G,{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(G,{value:String(t),placeholder:s(`common.valueWord`),onChange:e=>a(e.target.value)})}function Lt({value:e,field:t,deviceId:n,cap:r,onChange:i}){let{t:a}=Y(),s=Ht(t,n,r);return o(G,{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 Rt(e){return typeof e==`object`}function zt(e){return Rt(e)?e[0]??``:e}function Bt(e){return Rt(e)?e:typeof e==`boolean`?[]:[e]}function Vt(e,t){if(!(e===void 0||e===`none`)){if(e!==`device`)return e;if(!(t===void 0||t===`device`||t===`none`))return t}}function Ht(e,t,n){let r=t??0,i=e?.kind===`number`&&e.quantity!==void 0,{data:a}=Le({deviceId:r},{enabled:i&&r>0}),o=a?.sourceInfo?.quantity,s=P(o)?o:void 0,c=Vt(e?.quantity,s);if(c===void 0)return;let l=a?.display;return Ee({quantity:c,display:l,capName:n})}function Ut({leaf:t,devices:n,onChange:r}){let{t:i}=Y(),a={deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath},s=pt(a),c=yt(s?.kind),l=t.operator===`in`,u=e=>{r({...t,deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath})},d=e=>{let n=Wt(e,c);r({...t,operator:n,value:n===`in`?Bt(t.value):zt(t.value)})};return e(`div`,{className:`flex flex-wrap items-end gap-2`,children:[o(mt,{value:a,devices:n,onChange:u}),e(`label`,{className:`min-w-[8rem]`,children:[o(Z,{children:i(`automation.conditionRow.comparison`,`Comparison`)}),o(K,{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(Lt,{value:Bt(t.value),field:s,deviceId:t.deviceId,cap:t.cap,onChange:e=>r({...t,value:e})}):o(It,{value:zt(t.value),field:s,deviceId:t.deviceId,cap:t.cap,onChange:e=>r({...t,value:e})})]})]})}function Wt(e,t){return t.find(t=>t.value===e)?.value??`eq`}var Gt={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function Kt({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(G,{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(qt,{alias:e,source:r,devices:n,onRename:n=>s($t(t.bindings,e,n)),onChange:n=>s({...t.bindings,[e]:n}),onRemove:()=>s(en(t.bindings,e))},e)),e(W,{variant:`ghost`,onClick:()=>s({...t.bindings,[Qt(t.bindings)]:Gt}),children:[o(g,{className:`h-3.5 w-3.5`}),` `,i(`common.name`)]})]})]})}function qt({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:Xt(r,Yt(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(G,{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(K,{value:l?`literal`:`global`,onChange:e=>a(e.target.value===`literal`?{kind:`literal`,value:``}:Gt),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(G,{value:n.value===null?``:String(n.value),placeholder:`5`,onChange:e=>a({kind:`literal`,value:Jt(e.target.value)})})]}):o(mt,{value:u,devices:r,onChange:e=>a({kind:`global`,sourceStableId:Zt(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(_,{className:`h-3.5 w-3.5`})})]})}function Jt(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function Yt(e){return e.kind===`global`?e.sourceStableId:``}function Xt(e,t){return e.find(e=>e.stableId===t)?.id??0}function Zt(e,t){return e.find(e=>e.id===t)?.stableId??``}function Qt(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 $t(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function en(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function tn(e,t){return e.map(e=>t.find(t=>t.id===e)?.name??`#${String(e)}`)}function nn({lines:t}){let{t:n}=Y();return o(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-foreground-subtle`,children:t.map(t=>e(`span`,{children:[o(`span`,{className:`font-medium`,children:t.label}),` `,t.values.length===0?n(`automation.readOnly.any`):t.values.join(`, `)]},t.label))})}function rn({leaf:t,devices:n}){let{t:r}=Y();return e(`div`,{className:`space-y-1`,children:[o(q,{variant:`default`,children:r(`automation.readOnly.stationaryPresent`)}),o(nn,{lines:[{label:r(`automation.readOnly.cameras`),values:tn([t.deviceId],n)},{label:r(`automation.readOnly.classes`),values:t.classes??[]},{label:r(`automation.readOnly.zones`),values:t.zones??[]}]}),o(`p`,{className:`text-xs text-foreground-subtle`,children:r(`automation.readOnly.editInCode`)})]})}function an({trigger:t,devices:n}){let{t:r}=Y();return t.kind===`stationary`?e(`div`,{className:`space-y-1`,children:[o(nn,{lines:[{label:r(`automation.readOnly.stationaryTrigger`),values:[t.phase===`appeared`?r(`automation.readOnly.phaseAppeared`):r(`automation.readOnly.phaseDeparted`)]},{label:r(`automation.readOnly.cameras`),values:tn(t.deviceIds,n)},{label:r(`automation.readOnly.classes`),values:t.classes??[]},{label:r(`automation.readOnly.zones`),values:t.zones??[]}]}),o(`p`,{className:`text-xs text-foreground-subtle`,children:r(`automation.readOnly.editInCode`)})]}):o(`p`,{className:`text-xs text-foreground-subtle`,children:r(`automation.readOnly.editInCode`)})}function on(e){return e.kind===`all`||e.kind===`any`}function Q(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:on(t)?t:{kind:`all`,children:[t]}}function sn(e,t){return t===null||on(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function cn(e){return sn(e,Q(e))}function ln(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?ln(e.child,r):null;if(!on(e))return null;let i=e.children[n];return i===void 0?null:ln(i,r)}function un(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=un(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!on(e))return e;let a=e.children[r];if(a===void 0)return e;let o=un(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 dn(e){return e===null?null:L({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function fn(e){let t=Q(e);return{depth:t.children.length===0?0:I(t),leaves:t.children.length===0?0:F(t),depthLimit:3,leafLimit:32}}function pn(e,t){let n=dn(t);return n===null?{ok:!0,recipe:sn(e,t)}:{ok:!1,reason:n}}function mn(e,t){let n=Q(e);return pn(e,{kind:n.kind,children:[...n.children,t]})}function hn(e,t,n){return sn(e,un(Q(e),t,()=>n))}function gn(e,t){return sn(e,un(Q(e),t,()=>null))}function _n(e,t,n){return sn(e,un(Q(e),t,e=>on(e)?{kind:n,children:e.children}:e))}function vn(e,t){return ln(Q(e),t)===null?{ok:!1,reason:J.t(`helpers.recipeOps.rowGone`)}:pn(e,un(Q(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function yn(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 bn(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=yn(t[0]??[]);if(r===null)return{ok:!1,reason:J.t(`helpers.recipeOps.rootGroup`)};let i=Q(e),a=ln(i,r.path);if(a===null||!on(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 pn(e,un(i,r.path,()=>d))}function xn(e,t){if(t.length===0)return{ok:!1,reason:J.t(`helpers.recipeOps.outerNotGroup`)};let n=Q(e),r=ln(n,t);if(r===null)return{ok:!1,reason:J.t(`helpers.recipeOps.groupGone`)};if(r.kind===`not`)return pn(e,un(n,t,()=>r.child));if(!on(r))return{ok:!1,reason:J.t(`helpers.recipeOps.rowIsCondition`)};let i=yn(t);if(i===null)return{ok:!1,reason:J.t(`helpers.recipeOps.noParent`)};let a=ln(n,i.path);if(a===null||!on(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 pn(e,un(n,i.path,()=>o))}u();var Sn=[{value:`all`,labelKey:`automation.conditionTree.allOf`},{value:`any`,labelKey:`automation.conditionTree.anyOf`}];function Cn(e){return e.join(`/`)}function wn(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function Tn({recipe:t,devices:n,onChange:i}){let{t:a}=Y(),[s,l]=c([]),[u,d]=c(null),f=Q(t),p=fn(t),m=r(()=>s.map(wn),[s]),h=e=>{if(!e.ok){d(e.reason);return}d(null),l([]),i(e.recipe)},_=bn(t,m,`all`),v=bn(t,m,`any`),y=m.length===1?vn(t,m[0]??[]):{ok:!1,reason:a(`automation.conditionTree.selectOneNegate`)},b={devices:n,selected:new Set(s),onToggleSelect:e=>l(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),onUpdate:(e,n)=>i(hn(t,e,n)),onRemove:e=>{l([]),i(gn(t,e))},onSetKind:(e,n)=>i(_n(t,e,n)),onUngroup:e=>h(xn(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(K,{value:f.kind,onChange:e=>i(_n(t,[],En(e.target.value))),options:Sn.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(Dn,{container:f,path:[],handlers:b}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(W,{variant:`outline`,onClick:()=>h(mn(t,wt())),title:a(`automation.conditionTree.compareOneDeviceFieldTo`,`Compare one device field to a value`),children:[o(g,{className:`h-4 w-4`}),` `,a(`automation.conditionTree.addCondition`)]}),e(W,{variant:`outline`,onClick:()=>h(mn(t,Tt())),title:a(`automation.conditionTree.arithmeticAcrossDeviceFieldsThe`,`Arithmetic across device fields — the bounded expression engine`),children:[o(le,{className:`h-4 w-4`}),` `,a(`automation.conditionTree.addExpression`)]}),o(`span`,{className:`mx-1 h-5 w-px bg-border`}),o(W,{variant:`ghost`,disabled:!_.ok,onClick:()=>h(_),title:_.ok?a(`automation.conditionTree.allSelectedRowsMustBe`,`All selected rows must be true`):_.reason,children:a(`automation.conditionTree.groupAsAll`,`Group as ALL`)}),o(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 En(e){return e===`any`?`any`:`all`}function Dn({container:e,path:t,handlers:n}){return o(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>o(On,{node:e,path:[...t,r],handlers:n},Cn([...t,r])))})}function On({node:t,path:n,handlers:r}){let{t:i}=Y(),a=Cn(n),s=o(Te,{checked:r.selected.has(a),onChange:()=>r.onToggleSelect(a),"aria-label":i(`automation.conditionTree.selectThisRowForGrouping`,`Select this row for grouping`)});return on(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(K,{value:t.kind,onChange:e=>r.onSetKind(n,En(e.target.value)),options:Sn.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(ue,{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(_,{className:`h-3.5 w-3.5`})})]}),o(`div`,{className:`pl-4`,children:o(Dn,{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(ue,{className:`h-3.5 w-3.5`}),` `,i(`automation.conditionTree.removeNot`)]})]}),o(`div`,{className:`pl-4`,children:o(On,{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(Ut,{leaf:t,devices:r.devices,onChange:e=>r.onUpdate(n,e)}):t.kind===`expression`?o(Kt,{leaf:t,devices:r.devices,onChange:e=>r.onUpdate(n,e)}):o(rn,{leaf:t,devices:r.devices})}),o(W,{variant:`ghost`,onClick:()=>r.onRemove(n),title:i(`automation.conditionTree.removeThisCondition`,`Remove this condition`),children:o(_,{className:`h-3.5 w-3.5`})})]})}u();function kn({code:t,error:n,canEject:r,ejecting:i,onEject:a}){let{t:s}=Y(),[l,u]=c(!1),d=T(),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?h:y,{className:`h-4 w-4`}),s(`automation.generatedCodePanel.generatedCode`,`Generated code`)]}),o(`span`,{className:`text-xs text-foreground-subtle`,children:s(`automation.generatedCodePanel.derivedFromTheRecipeAbove`,`Derived from the recipe above — regenerated on every save, never edited here.`)}),e(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(de,{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(Me,{maxHeight:420,children:t})})]})}var An=[`device-state`,`device-event`,`schedule`,`manual`],jn=Object.values(te).sort((e,t)=>e.localeCompare(t));function Mn({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(Nn,{trigger:e,devices:n,position:i,onChange:e=>r(Et(t,i,e)),onRemove:()=>r(Dt(t,i))},`${e.kind}-${String(i)}`)),e(W,{variant:`outline`,onClick:()=>r([...t,St(`device-state`)]),title:i(`automation.triggerEditor.addAnotherWayThisAutomation`,`Add another way this automation can start`),children:[o(g,{className:`h-4 w-4`}),` `,i(`automation.triggerEditor.trigger`)]})]})}function Nn({trigger:t,devices:n,position:r,onChange:i,onRemove:a}){let{t:s}=Y();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`)}),Pn(t.kind)?e(`label`,{className:`min-w-[13rem] flex-1`,children:[o(Z,{children:s(`automation.triggerEditor.trigger`,`Trigger`)}),o(K,{value:t.kind,onChange:e=>i(St(Fn(e.target.value))),options:An.map(e=>({value:e,label:bt(e)}))})]}):o(`div`,{className:`min-w-[13rem] flex-1`,children:o(q,{variant:`default`,children:bt(t.kind)})}),o(W,{variant:`ghost`,onClick:a,title:s(`automation.triggerEditor.removeThisTrigger`,`Remove this trigger`),children:o(_,{className:`h-4 w-4`})})]}),e(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:[t.kind===`device-state`&&o(Ln,{trigger:t,devices:n,onChange:i}),t.kind===`device-event`&&o(zn,{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(G,{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`,{})}})})]}),!Pn(t.kind)&&o(an,{trigger:t,devices:n}),t.kind===`manual`&&o(`p`,{className:`text-xs text-foreground-subtle`,children:o(X,{i18nKey:`automation.triggerEditor.manualHint`,components:{b:o(`strong`,{})}})})]})]})}function Pn(e){return An.some(t=>t===e)}function Fn(e){return An.find(t=>t===e)??`manual`}function In(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 Ln({trigger:t,devices:n,onChange:r}){let{t:i}=Y(),a={deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath},s=pt(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(f,{children:[o(mt,{value:a,devices:n,onChange:e=>r(In(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(Te,{checked:t.becomes===void 0,onChange:e=>r(In(a,{...c,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),i(`automation.triggerEditor.anyChange`,`any change`)]}),t.becomes!==void 0&&o(It,{value:t.becomes,field:s,deviceId:a.deviceId,cap:a.cap,onChange:e=>r(In(a,{...c,becomes:e}))})]})]}),e(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[o(Te,{checked:t.edge===!0,onChange:e=>r(In(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(G,{type:`number`,min:0,value:t.forMs===void 0?``:String(t.forMs/1e3),placeholder:`0`,onChange:e=>r(In(a,{...c,forMs:Rn(e.target.value)}))})]}),e(`label`,{className:`w-28`,children:[o(Z,{children:i(`automation.triggerEditor.debounceS`,`Debounce (s)`)}),o(G,{type:`number`,min:0,value:t.debounceMs===void 0?``:String(t.debounceMs/1e3),placeholder:`0`,onChange:e=>r(In(a,{...c,debounceMs:Rn(e.target.value)}))})]})]})}function Rn(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function zn({trigger:t,devices:n,onChange:r}){let{t:i}=Y();return e(f,{children:[e(`label`,{className:`min-w-[15rem] flex-1`,children:[o(Z,{children:i(`automation.triggerEditor.eventCategory`,`Event category`)}),o(K,{value:t.category,onChange:e=>r({kind:`device-event`,category:e.target.value,...t.deviceId===void 0?{}:{deviceId:t.deviceId}}),options:[{value:``,label:i(`automation.triggerEditor.selectAnEvent`,`Select an event…`)},...jn.map(e=>({value:e,label:e}))]})]}),e(`label`,{className:`min-w-[11rem] flex-1`,children:[o(Z,{children:i(`automation.triggerEditor.fromDevice`,`From device`)}),o(K,{value:t.deviceId===void 0?``:String(t.deviceId),onChange:e=>r({kind:`device-event`,category:t.category,...e.target.value===``?{}:{deviceId:Number(e.target.value)}}),options:[{value:``,label:i(`automation.triggerEditor.anyDevice`,`Any device`)},...n.map(e=>({value:String(e.id),label:e.name}))]})]})]})}u();var Bn=`hub`;function Vn({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(()=>cn(n)),[_,v]=c(!1),y=ut(),b=L(h),x=r(()=>Un(h),[h]),C=r(()=>Wn(p.trim()===``?`Untitled automation`:p.trim(),h),[p,h]),w=p.trim()===``,T=w||b!==null||x!==null||C.code===null;return 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(G,{className:`mt-1`,value:p,onChange:e=>m(e.target.value),placeholder:f(`automation.automationEditor.whatThisAutomationDoes`,`What this automation does`)})]}),o(Hn,{step:`1`,title:f(`automation.automationEditor.when`,`When`),subtitle:f(`automation.automationEditor.anyOneOfTheseStarts`,`Any one of these starts a run.`),children:o(Mn,{triggers:h.triggers,devices:y,onChange:e=>g(kt(h,e))})}),o(Hn,{step:`2`,title:f(`automation.automationEditor.andOnlyIf`,`And only if`),subtitle:f(`automation.automationEditor.checkedAfterATriggerFires`,`Checked after a trigger fires. Nothing runs unless this is true.`),children:o(Tn,{recipe:h,devices:y,onChange:g})}),o(Hn,{step:`3`,title:f(`automation.automationEditor.then`,`Then`),subtitle:f(`automation.automationEditor.inThisOrderStoppingAt`,`In this order, stopping at the first failure.`),children:o(Mt,{actions:h.actions,devices:y,onChange:e=>g(At(h,e))})}),o(kn,{code:C.code,error:C.error,canEject:t!==null,ejecting:s,onEject:u}),b!==null&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:b}),b===null&&x!==null&&o(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:x}),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:()=>{C.code!==null&&l({name:p.trim(),code:C.code,enabled:t?.enabled??!0,placement:Bn})},disabled:i||T,children:[i&&o(S,{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(k,{className:`h-4 w-4`}),` `,f(`common.logs`),` `,_?`▾`:`▸`]}),o(W,{variant:`ghost`,onClick:d,disabled:i,children:f(`common.close`,`Close`)}),w&&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:V(t.id)},components:{code:o(`code`,{})}})}),o(Ae,{addonId:V(t.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function Hn({step:t,title:n,subtitle:r,children:i}){return e(`section`,{className:`border-l-2 border-border pl-4`,children:[e(`div`,{className:`mb-2 flex flex-wrap items-baseline gap-2`,children:[o(`span`,{className:`text-xs font-mono text-foreground-subtle`,children:t}),o(`h4`,{className:`text-sm font-medium uppercase tracking-wide`,children:n}),o(`span`,{className:`text-xs text-foreground-subtle`,children:r})]}),i]})}function Un(e){let t=M.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 Wn(e,t){try{return{code:re({name:e,recipe:t}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function Gn(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 Kn(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function qn(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function Jn(e){let t=e=>{let t=Gn(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 Yn(e){if(e.length===0)return J.t(`helpers.coreBlockStatus.noBlocks`);let t=e.filter(e=>Gn(e).tone===`error`).length,n=e.filter(e=>Gn(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 Xn({block:t,busy:n,logsOpen:r,unreadable:i,onEdit:a,onToggle:s,onToggleLogs:c,onDelete:l}){let u=C(),{t:d}=Y(),f=Gn(t),p=_e(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:Kn(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(b,{className:`h-4 w-4`})}),e(Ie,{children:[o(Ne,{children:o(W,{variant:`ghost`,disabled:!0,title:d(`automation.automationList.runActions`,`Run actions`),children:o(v,{className:`h-4 w-4`})})}),o(Re,{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(k,{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(_,{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:V(t.id)},components:{code:o(`code`,{})}})}),o(Ae,{addonId:V(t.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function Zn({onCreate:t}){let{t:n}=Y();return o(ke,{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 Qn=[`coreBlocks`,`list`],$n=5e3;function er(e){return e instanceof Error?e.message:String(e)}function tr({onOpenScripts:t,initialBlockId:i,onBlockIdChange:a,createRequested:u=!1,onCreateConsumed:f}){let{t:p}=Y(),m=x(),{state:h,openNew:g,openEdit:_,close:v}=je({editKey:`block`,newKey:`new`}),[y,b]=c(null),S=T(),[C,w]=c(null),D=n(null),O=h.mode!==`closed`;s(()=>{u&&(b(null),g(),a?.(null),f?.())},[u,f,a,g]);let k=l({queryKey:Qn,refetchInterval:$n,queryFn:async()=>(await m.trpcClient.coreBlocks.list.query({})).blocks}),A=()=>{k.refetch()},j=k.data;s(()=>{i===void 0||D.current===i||j?.find(e=>e.id===i&&at(e.code))!==void 0&&(D.current=i,_(i),a?.(i))},[i,j,_,a]);let M=d({mutationFn:e=>m.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{b(e.block),_(e.block.id),a?.(e.block.id),A()}}),N=d({mutationFn:e=>m.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{b(e.block),_(e.block.id),a?.(e.block.id),A()}}),P=d({mutationFn:e=>m.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:A}),F=d({mutationFn:e=>m.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:A}),I=d({mutationFn:e=>m.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:ct(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:e=>{v(),b(null),A(),t(e.block.id)}}),L=k.data,R=Jn((L??[]).filter(e=>at(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:qn(R,z),V=B===null?null:st(B.code),te=M.error===null?N.error===null?I.error===null?null:er(I.error):er(N.error):er(M.error),ne=r(()=>[{key:`row`,header:p(`build.automationsTab.automation`,`Automation`),nowrap:!1,notSortableReason:`Composite status row`,render:e=>{let t=st(e.code);return o(`ul`,{className:`list-none`,children:o(Xn,{block:e,busy:F.isPending||P.isPending,logsOpen:C===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:()=>w(C===e.id?null:e.id),onDelete:()=>{S({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}],[S,C,a,_,P,F,p]);return e(`div`,{className:`space-y-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:L===void 0?``:Yn(R)}),k.error!=null&&o(U,{title:p(`build.automationsTab.couldNotReadTheAutomations`,`Could not read the automations`),message:er(k.error),onRetry:A}),ee?o(Zn,{onCreate:()=>{b(null),g(),a?.(null)}}):o(Ce,{columns:ne,rows:R,rowKey:e=>e.id,pageSize:25,maxBodyHeight:fe,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)}}),o(Fe,{open:O,onClose:()=>{M.reset(),N.reset(),I.reset(),b(null),v(),a?.(null)},title:B===null?p(`build.automationsTab.newAutomation`,`New automation`):p(`build.automationsTab.edit`,`Edit {{name}}`,{name:B.name}),icon:E,width:`xl`,testId:`automation-editor-panel`,children:o(Vn,{existing:B,initialRecipe:V!==null&&V.ok?V.recipe:xt,saving:M.isPending||N.isPending,saveError:te,ejecting:I.isPending,onSave:e=>{B===null?M.mutate(e):N.mutate({blockId:B.id,block:e})},onEject:()=>{B!==null&&I.mutate(B)},onCancel:()=>{M.reset(),N.reset(),I.reset(),b(null),v(),a?.(null)}},B?.id??`new`)}),P.error!=null&&o(U,{message:er(P.error)}),F.error!=null&&o(U,{message:er(F.error)})]})}u();function nr({mode:e,onTitle:t}){return o(e===`helper`?rr:ir,{onTitle:t})}function rr({onTitle:e}){let{t}=Y(),n=Je(),r=me(),i=Se(),a=we({addonId:`composer`}),[l,u]=c(null),d=or(l,t);return s(()=>{e(d)},[e,d]),o(`div`,{className:`flex flex-col gap-3`,"data-testid":`composition-create-form`,children:o(et,{purpose:`create`,initial:null,start:`template`,saving:r.isPending,onDraftChange:u,onSave:async(e,o)=>{let s=null,c=await $e(e,async(e,c)=>{let{block:l}=await r.mutateAsync({block:{...c===``?{}:{name:c},enabled:!0,composition:e}}),u=await sr(l.id,async()=>(await a.refetch()).data??a.data);if(u===null)throw Error(t(`helper.devicePending`));s=u,c!==``&&await i.mutateAsync({deviceId:u,name:c}),o===`open`&&n(Ke(u),{replace:!0})}),l=s;return c.length>0||l===null?{kind:`refused`,lines:cr(c,t)}:{kind:`saved`,deviceId:l}}})})}function ir({onTitle:t}){let{t:n}=Y(),r=C(),i=Je(),a=me(),l=Se(),u=we({addonId:`composer`}),[d,f]=c(ne.Sensor),[p,m]=c(R.TemperatureSensor),[h,g]=c(``),[_,v]=c(null),y=Qe({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(K,{value:d,onChange:e=>{let t=Object.values(ne).find(t=>t===e.target.value);t!==void 0&&f(t)},options:Object.values(ne).map(e=>({value:e,label:Oe(e,r).label}))})]}),e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[n(`customize.identity.role`),o(K,{value:p??``,onChange:e=>m(Object.values(R).find(t=>t===e.target.value)??null),options:[{value:``,label:n(`customize.identity.noRole`)},...Object.values(R).map(e=>({value:e,label:Be(e,r).label}))]})]}),e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[n(`compositionEditor.name`),o(G,{"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&&ar({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(qe(e),{replace:!0}),pending:n(`helper.devicePending`)})},children:n(`compositionEditor.save`)})]})}async function ar(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 sr(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 or(e,t){if(e===null)return t(`helper.newHelper`);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.newHelper`);let n=oe(e.templateId);return t(n===null?`helper.newHelper`:`helper.newTitle.${n.id}`)}async function sr(e,t){let n=`${ae}${e}`;return(await t())?.find(e=>e.stableId===n)?.id??null}function cr(e,t){return e.length>0?e:tt(t(`helper.devicePending`))}function lr(e){return{state:`answered`,byRef:new Map(e.map(e=>[B(e),e]))}}function ur(e,t){if(e.state!==`unanswered`)return e.byRef.get(B(t))??null}function dr(e){return e===void 0?`unknown`:e===null?`missing`:`present`}function fr(e){return N(e).map(e=>e.source)}function pr(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(...fr(t));for(let t of Object.values(e.items??{}))for(let e of Object.values(t.fields))n.push(...fr(e))}let r=new Set;return n.filter(e=>{let t=B(e);return r.has(t)?!1:(r.add(t),!0)})}function mr(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 hr(e,t){let n=e.reason??t??null;switch(e.status){case`running`:return mr(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 gr(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 hr(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 _r(e){return B(e)}function vr(e,t){let n=ur(t,e);return{key:B(e),label:n?n.name:_r(e),presence:dr(n),deviceId:n?n.id:null}}function yr(e){return e.state.kind===`answered`&&e.state.state!==null?e.state.state.deviceId:null}function br(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:j(e.block.id),a=B(i),o=pr(e).filter(e=>B(e)!==a).map(e=>vr(e,t)),s=n.features.map(e=>e.enabled===!1?J.t(`helpers.compositionRows.featureOff`,{cap:e.cap}):e.cap),c=ur(t,i),l=yr(e),u=gr(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}`,features:s,state:u,sources:o,reportedDeviceId:l};let d=dr(c);return{blockId:e.block.id,kind:`customization`,name:c?c.name:_r(r.device),namePresence:d,type:c?c.type:null,features:s,state:u,sources:o,reportedDeviceId:l}}function xr(e){return e.state.tone===`error`?0:e.state.tone===`pending`?1:e.state.tone===`ok`?2:3}function Sr(e,t){return xr(e)-xr(t)||e.name.localeCompare(t.name)}function Cr(e,t){let n=e.flatMap(e=>{let n=br(e,t);return n===null?[]:[n]});return{composed:n.filter(e=>e.kind===`composed`).toSorted(Sr),customizations:n.filter(e=>e.kind===`customization`).toSorted(Sr)}}u();var wr=1e4;function Tr(e){return e instanceof Error?e.message:typeof e==`object`&&e&&`message`in e?String(e.message):String(e)}function Er(){let e=Ye();return e.data===void 0?{state:`unanswered`,reason:e.error==null?J.t(`build.customDeviceTab.deviceListPending`):J.t(`build.customDeviceTab.deviceListUnreadable`,{error:Tr(e.error)})}:lr(e.data)}function Dr(e,t){return e===`blank`?`blank`:e===`helper`||e===`1`||t?`helper`:null}function Or({createRequested:t=!1,onCreateConsumed:n}={}){let{t:r}=Y(),[i,a]=Ge(),s=ve({},{refetchInterval:wr}),l=Er(),u=je({editKey:`block`,newKey:`new`}),d=u.state.mode===`edit`?u.state.id:null,p=d===null?Dr(i.get(`new`),t):null,m=p!==null,[h,g]=c(``),_=T(),v=pe(),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(f,{children:[Ar(b,s.error,()=>void s.refetch(),l,{onEditComposed:e=>u.openEdit(e),deleting:v.isPending,onDelete:e=>{_({title:r(`build.customDeviceTab.deleteThisComposedDevice`,`Delete this composed device?`),message:r(`build.customDeviceTab.deleteMessage`,`{{name}} will be deleted. This cannot be undone.`,{name:e.name}),confirmLabel:r(`common.delete`,`Delete`),variant:`danger`}).then(t=>{t&&v.mutate({blockId:e.blockId},{onSuccess:()=>void s.refetch()})})}}),o(Fe,{open:m||d!==null,onClose:y,title:m?h||r(p===`blank`?`helper.newComposition`:`helper.newHelper`):r(`build.customDeviceTab.editComposedDevice`,`Edit composed device`),icon:se,width:`xl`,testId:`composed-device-editor`,children:m&&p!==null?o(nr,{mode:p,onTitle:g},p):d===null?null:o(nt,{blockId:d})}),v.error!=null&&o(U,{message:Tr(v.error)})]})}function kr(t){return o(ke,{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 Ar(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:Tr(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 kr(e.reason);let a=t==null?null:Tr(t);return o(jr,{lists:Cr(e.views,r),fleet:r,refreshError:a,handlers:i})}function jr({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(Mr,{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(Mr,{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 Mr({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(Ce,{columns:Nr(i,s,c,l),rows:r,rowKey:e=>e.blockId,pageSize:25,maxBodyHeight:fe,emptyMessage:a,onRowClick:s===`composed`?e=>c.onEditComposed(e.blockId):void 0})]})}function Nr(t,n,r,i){let a=[{key:`name`,header:t,sortValue:e=>e.name.toLowerCase(),render:e=>o(Pr,{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`)})},{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:Kn(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(Ir,{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(_,{className:`h-4 w-4`})})]})}),a}function Pr({row:t}){let{t:n}=Y();return e(`div`,{className:`space-y-0.5`,children:[o(Fr,{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 Fr({row:e}){let{t}=Y(),n=ge(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(We,{to:e.kind===`composed`?Ke(e.reportedDeviceId):qe(e.reportedDeviceId),className:`text-xs font-medium text-foreground hover:underline`,onClick:e=>e.stopPropagation(),children:r})}function Ir({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(We,{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 Lr(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 Rr(e){if(Array.isArray(e))return e}function zr(e,t,n){return(t=Jr(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Br(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 Vr(){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 Hr(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 Ur(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Hr(Object(n),!0).forEach(function(t){zr(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Hr(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Wr(e,t){if(e==null)return{};var n,r,i=Gr(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 Gr(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 Kr(e,t){return Rr(e)||Br(e,t)||Yr(e,t)||Vr()}function qr(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 Jr(e){var t=qr(e,`string`);return typeof t==`symbol`?t:t+``}function Yr(e,t){if(e){if(typeof e==`string`)return Lr(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)?Lr(e,t):void 0}}function Xr(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Zr(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 Qr(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Zr(Object(n),!0).forEach(function(t){Xr(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Zr(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function $r(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}}function ei(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 ti(e){return{}.toString.call(e).includes(`Object`)}function ni(e){return!Object.keys(e).length}function ri(e){return typeof e==`function`}function ii(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function ai(e,t){return ti(t)||ui(`changeType`),Object.keys(t).some(function(t){return!ii(e,t)})&&ui(`changeField`),t}function oi(e){ri(e)||ui(`selectorType`)}function si(e){ri(e)||ti(e)||ui(`handlerType`),ti(e)&&Object.values(e).some(function(e){return!ri(e)})&&ui(`handlersType`)}function ci(e){e||ui(`initialIsRequired`),ti(e)||ui(`initialType`),ni(e)&&ui(`initialContent`)}function li(e,t){throw Error(e[t]||e.default)}var ui=ei(li)({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"}),di={changes:ai,selector:oi,handler:si,initial:ci};function fi(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};di.initial(e),di.handler(t);var n={current:e},r=ei(hi)(n,t),i=ei(mi)(n),a=ei(di.changes)(e),o=ei(pi)(n);function s(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(e){return e};return di.selector(e),e(n.current)}function c(e){$r(r,i,a,o)(e)}return[s,c]}function pi(e,t){return ri(t)?t(e.current):t}function mi(e,t){return e.current=Qr(Qr({},e.current),t),t}function hi(e,t,n){return ri(t)?t(e.current):Object.keys(n).forEach(function(n){return t[n]?.call(t,e.current[n])}),n}var gi={create:fi},_i={paths:{vs:`https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs`}};function vi(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 yi(e){return{}.toString.call(e).includes(`Object`)}function bi(e){return e||wi(`configIsRequired`),yi(e)||wi(`configType`),e.urls?(xi(),{paths:{vs:e.urls.monacoBase}}):e}function xi(){console.warn(Ci.deprecation)}function Si(e,t){throw Error(e[t]||e.default)}var Ci={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
|
+
`},wi=vi(Si)(Ci),Ti={config:bi},Ei=function(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}};function Di(e,t){return Object.keys(t).forEach(function(n){t[n]instanceof Object&&e[n]&&Object.assign(t[n],Di(e[n],t[n]))}),Ur(Ur({},e),t)}var Oi={type:`cancelation`,msg:`operation is manually canceled`};function ki(e){var t=!1,n=new Promise(function(n,r){e.then(function(e){return t?r(Oi):n(e)}),e.catch(r)});return n.cancel=function(){return t=!0},n}var Ai=[`monaco`],ji=Kr(gi.create({config:_i,isInitialized:!1,resolve:null,reject:null,monaco:null}),2),Mi=ji[0],Ni=ji[1];function Pi(e){var t=Ti.config(e),n=t.monaco,r=Wr(t,Ai);Ni(function(e){return{config:Di(e.config,r),monaco:n}})}function Fi(){var e=Mi(function(e){return{monaco:e.monaco,isInitialized:e.isInitialized,resolve:e.resolve}});if(!e.isInitialized){if(Ni({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),ki(Hi);if(window.monaco&&window.monaco.editor)return Bi(window.monaco),e.resolve(window.monaco),ki(Hi);Ei(Ii,Ri)(zi)}return ki(Hi)}function Ii(e){return document.body.appendChild(e)}function Li(e){var t=document.createElement(`script`);return e&&(t.src=e),t}function Ri(e){var t=Mi(function(e){return{config:e.config,reject:e.reject}}),n=Li(`${t.config.paths.vs}/loader.js`);return n.onload=function(){return e()},n.onerror=t.reject,n}function zi(){var e=Mi(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;Bi(n),e.resolve(n)},function(t){e.reject(t)})}function Bi(e){Mi().monaco||Ni({monaco:e})}function Vi(){return Mi(function(e){return e.monaco})}var Hi=new Promise(function(e,t){return Ni({resolve:e,reject:t})}),Ui={config:Pi,init:Fi,__getMonacoInstance:Vi};u();var Wi={wrapper:{display:`flex`,position:`relative`,textAlign:`initial`},fullWidth:{width:`100%`},hide:{display:`none`}},Gi={container:{display:`flex`,height:`100%`,width:`100%`,justifyContent:`center`,alignItems:`center`}};function Ki({children:e}){return t.createElement(`div`,{style:Gi.container},e)}var qi=Ki;function Ji({width:e,height:n,isEditorReady:r,loading:i,_ref:a,className:o,wrapperProps:s}){return t.createElement(`section`,{style:{...Wi.wrapper,width:e,height:n},...s},!r&&t.createElement(qi,null,i),t.createElement(`div`,{ref:a,style:{...Wi.fullWidth,...!r&&Wi.hide},className:o}))}var Yi=i(Ji);function Xi(e){s(e,[])}var Zi=Xi;function Qi(e,t,r=!0){let i=n(!0);s(i.current||!r?()=>{i.current=!1}:e,t)}var $=Qi;function $i(){}function ea(e,t,n,r){return ta(e,r)||na(e,t,n,r)}function ta(e,t){return e.editor.getModel(ra(e,t))}function na(e,t,n,r){return e.editor.createModel(t,n,r?ra(e,r):void 0)}function ra(e,t){return e.Uri.parse(t)}function ia({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=$i,onMount:S=$i}){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);Zi(()=>{let e=Ui.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=ea(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=ea(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=ea(O.current,e||``,o||i||`text`,u||``),n=ea(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(Yi,{width:v,height:_,isEditorReady:C,loading:h,_ref:k,className:y,wrapperProps:b})}i(ia);function aa(e){let t=n();return s(()=>{t.current=e},[e]),t.current}var oa=aa,sa=new Map;function ca({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=$i,onMount:C=$i,onChange:w,onValidate:T=$i}){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=oa(u),R=n(!1),ee=n(!1);Zi(()=>{let e=Ui.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=ea(A.current,e||o||``,r||l||``,u||i||``);t!==j.current?.getModel()&&(g&&sa.set(L,j.current?.saveViewState()),j.current?.setModel(t),g&&j.current?.restoreViewState(sa.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=ea(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(sa.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&&sa.set(u,j.current.saveViewState()):j.current.getModel()?.dispose(),j.current.dispose()}return t.createElement(Yi,{width:v,height:y,isEditorReady:E,loading:p,_ref:M,className:b,wrapperProps:x})}var la=i(ca);u();function ua(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 da={target:99,module:99,moduleResolution:2,strict:!0,noImplicitAny:!0,strictNullChecks:!0,allowNonTsExtensions:!0,isolatedModules:!0};function fa(e,t){let n=e.languages.typescript.typescriptDefaults;n.setCompilerOptions({...n.getCompilerOptions(),...da}),n.setExtraLibs(t.map(e=>({filePath:e.filePath,content:e.content})))}function pa({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,fa(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&&fa(e,r)},[r]),o(la,{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 ma(e){return e.some(e=>e.severity>=8)}var ha=[{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 ga(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 _a=ha.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 va({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 ya=5e3;function ba(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 xa({blockId:t}){let{t:n}=Y(),i=V(t),a=De({addonId:i,projection:`slim`},{refetchInterval:ya}),s=r(()=>ba(a.data),[a.data]);return a.isLoading?e(`p`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[o(S,{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(We,{to:`/devices/${String(t.id)}`,className:`text-sm font-medium hover:underline`,title:n(`build.scriptDevicesPanel.openDeviceDetail`,`Open device detail`),children:o(ye,{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 Sa(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 Ca(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 wa(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 Ta(e){if(typeof e!=`object`||!e||!(`key`in e))return null;let t=Reflect.get(e,`key`);return typeof t==`string`?t:null}function Ea(e){if(!(typeof e!=`object`||!e||!(`value`in e)))return Reflect.get(e,`value`)}function Da(e){let t={};for(let n of e.sections)for(let e of n.fields){let n=Ta(e);n!==null&&(t[n]=Ea(e))}return t}function Oa(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function ka({blockId:t}){let{t:n}=Y(),i=x(),s=be({blockId:t},{retry:!1}),l=Pe({blockId:t},{refetchInterval:1e4,retry:!1}),u=he({onSuccess:()=>{l.refetch()}}),d=xe(),f=H(),[p,m]=c(null),[h,g]=c(null),[_,v]=c(null),[y,b]=c(!1),C=Oa(l.data)?l.data:null,w=r(()=>C===null?{}:Da(C),[C]),T=p??w,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(Sa(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:Ca(e)}),s.data?.block?.enabled!==!0&&(await f.mutateAsync({blockId:t,enabled:!0}),v(wa(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(S,{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)]}):C===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(S,{className:`h-3.5 w-3.5 animate-spin`}),n(`build.scriptSettingsPanel.saveSettings`,`Save settings`)]})]}),o(He,{schema:C,values:T,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 Aa=`hub`;function ja({existing:t,typeDefs:n,typeDefsLoading:i,saving:a,saveError:s,restarting:l,restartError:u,onRestart:p,onSave:m,onCancel:h}){let{t:g}=Y(),_=x(),v=T(),{resolvedMode:y}=ze(),b=z({code:t?.code??_a,files:t?.files,entry:t?.entry}),[C,w]=c(t?.name??``),[E,j]=c(b.files),[M,N]=c(b.entry),[P,F]=c(b.entry),[I,L]=c(t?.placement??Aa),[R,ee]=c(t?.integrationId??``),[B,te]=c([]),[ne,re]=c(!1),[ie,ae]=c(`blank`),[oe,se]=c(null),[ce,le]=c(``),ue=E[P]??``,de=e=>{j(t=>({...t,[P]:e}))},fe=Object.keys(E).toSorted(),pe=ha.length>1,me=r(()=>[...n?.libs??[],...ua(E,P)],[n?.libs,E,P]),H=d({mutationFn:()=>_.trpcClient.coreBlocks.compile.mutate({files:E,entry:M})}),he=r(()=>B.filter(e=>e.severity>=8),[B]),ge=ma(B),_e=C.trim()===``,ve=t===null?null:z(t),ye=t===null||ve===null||JSON.stringify(E)!==JSON.stringify(ve.files)||M!==ve.entry||C.trim()!==t.name||I!==t.placement||(R.trim()===``?void 0:R.trim())!==t.integrationId,be=()=>{H.reset(),m({name:C.trim(),files:E,entry:M,enabled:t?.enabled??!0,placement:I,...R.trim()===``?{}:{integrationId:R.trim()}})},xe=()=>{let e=ga(Object.keys(E));j(t=>({...t,[e]:``})),F(e),se(e),le(e)},Se=e=>{se(e),le(e)},Ce=()=>{if(oe===null)return;let e=oe,t=ce.trim();if(se(null),!(t===``||t===e)){if(E[t]!==void 0){F(t);return}j(n=>{let r={};for(let[i,a]of Object.entries(n))r[i===e?t:i]=a;return r}),M===e&&N(t),F(t)}},we=async e=>{let t=ha.find(t=>t.id===e);if(t===void 0)return;let n=ha.find(e=>e.id===`blank`);!(n!==void 0&&JSON.stringify(E)===JSON.stringify(n.files)&&M===n.entry)&&!await v({title:g(`build.blockEditor.loadExample`,`Load example`),message:g(`build.blockEditor.replaceTheCurrentEditorContents`,`Replace the current editor contents with this example?`),confirmLabel:g(`build.blockEditor.replace`,`Replace`),variant:`warning`})||(ae(e),j({...t.files}),N(t.entry),F(t.entry),(C.trim()===``||ie===`blank`)&&w(t.id===`blank`?``:t.name))},U=t===null?null:Gn(t),Te=va({existing:t,dirty:ye,saving:a,restarting:l});return e(`div`,{className:`space-y-4`,children:[U!==null&&o(`div`,{className:`flex flex-wrap items-center gap-2`,children:o(q,{variant:Kn(U.tone),children:U.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(G,{className:`mt-1`,value:C,onChange:e=>w(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(G,{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:ie,onChange:e=>void we(e.target.value),"data-testid":`script-example-select`,children:ha.map(t=>e(`option`,{value:t.id,children:[t.name,` — `,t.description]},t.id))})]}),e(`div`,{children:[o(Ve,{selectedNodeId:I,onSelect:L,label:g(`build.blockEditor.runsOn`,`Runs on`),alwaysShow:!0}),I!==Aa&&e(`p`,{className:`mt-2 flex items-start gap-2 text-xs text-warning`,children:[o(A,{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=>oe===t?o(G,{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===P?`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===M?` · ${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`)}),P!==M&&o(`button`,{type:`button`,className:`rounded px-2 py-1 text-xs text-foreground-subtle hover:text-foreground`,onClick:()=>N(P),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(pa,{value:ue,onChange:de,path:`file:///${P}`,extraLibs:me,onDiagnostics:te,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(O,{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:`),` `,Ma(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(ka,{blockId:t.id}),o(xa,{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(S,{className:`h-4 w-4 animate-spin`}),` `,g(`common.compile`)]}),e(W,{onClick:be,disabled:a||ge||_e,children:[a&&o(S,{className:`h-4 w-4 animate-spin`}),` `,g(`common.save`)]}),e(W,{variant:`outline`,onClick:()=>p?.(),disabled:Te!==null||p===void 0,title:Te??g(`build.blockEditor.stopTheProcessAndLet`,`Stop the process and let the supervisor bring it back`),children:[l?o(D,{className:`h-4 w-4 animate-spin`}):o(D,{className:`h-4 w-4`}),` `,g(`build.blockEditor.restart`,`Restart`)]}),e(W,{variant:`ghost`,onClick:()=>re(!ne),title:g(`build.blockEditor.showThisScriptSProcess`,`Show this script's process logs`),"data-testid":`script-logs-toggle`,children:[o(k,{className:`h-4 w-4`}),` `,g(`common.logs`),` `,ne?`▾`:`▸`]}),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`)})]}),ne&&e(`div`,{className:`rounded border border-border`,"data-testid":`script-logs-panel`,children:[o(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:t===null?g(`build.blockEditor.logsAppearOnceTheScript`,`Logs appear once the script has been saved and started.`):o(f,{children:o(X,{i18nKey:`build.blockEditor.logsOf`,values:{id:V(t.id)},components:{code:o(`code`,{})}})})}),t!==null&&o(Ae,{addonId:V(t.id),maxHeight:`max-h-[560px]`,showFilters:!1})]})]})}function Ma(e){return e instanceof Error?e.message:String(e)}u();var Na=[`coreBlocks`,`list`],Pa=[`coreBlocks`,`getTypeDefs`],Fa=5e3;function Ia(e){return e instanceof Error?e.message:String(e)}function La({initialBlockId:t,onBlockIdChange:i,createRequested:a=!1,onCreateConsumed:u}={}){let f=C(),{t:p}=Y(),m=x(),{state:h,openNew:g,openEdit:v,close:y}=je({editKey:`block`,newKey:`new`}),[b,S]=c(null),w=T(),[E,O]=c(null),A=l({queryKey:Na,refetchInterval:Fa,queryFn:async()=>(await m.trpcClient.coreBlocks.list.query({})).blocks}),j=h.mode!==`closed`,M=l({queryKey:Pa,enabled:j,staleTime:1/0,gcTime:1/0,queryFn:()=>m.trpcClient.coreBlocks.getTypeDefs.query({})}),N=()=>{A.refetch()},P=n(null),F=A.data;s(()=>{t===void 0||P.current===t||F?.find(e=>e.id===t&&ee(e)===`code`)!==void 0&&(P.current=t,v(t),i?.(t))},[t,F,v,i]),s(()=>{a&&(S(null),g(),i?.(null),u?.())},[a,u,i,g]);let I=d({mutationFn:e=>m.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{S(e.block),v(e.block.id),i?.(e.block.id),N()}}),L=d({mutationFn:e=>m.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{S(e.block),v(e.block.id),i?.(e.block.id),N()}}),R=d({mutationFn:e=>m.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:N}),z=d({mutationFn:e=>m.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:N}),B=d({mutationFn:e=>m.trpcClient.coreBlocks.restart.mutate({blockId:e}),onSuccess:N}),te=Jn((A.data??[]).filter(e=>ee(e)===`code`)),ne=A.data!==void 0&&te.length===0,re=I.isPending||L.isPending,ie=I.error===null?L.error===null?null:Ia(L.error):Ia(I.error),ae=h.mode===`edit`?te.find(e=>e.id===h.id)??(b!==null&&b.id===h.id?b:null):null,oe=h.mode===`new`||ae===null?null:qn(te,ae),se=r(()=>[{key:`name`,header:p(`build.scriptsTab.name`,`Name`),render:t=>{let n=Gn(t),r=_e(t.updatedAt,f);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:Kn(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}),E===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:V(t.id)},components:{code:o(`code`,{})}})}),o(Ae,{addonId:V(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=z.isPending||R.isPending,r=B.isPending&&B.variables===t.id;return e(`div`,{className:`flex justify-end gap-1`,children:[o(W,{variant:`ghost`,onClick:e=>{e.stopPropagation(),S(t),v(t.id),i?.(t.id)},title:p(`common.edit`,`Edit`),children:p(`common.edit`,`Edit`)}),o(W,{variant:`ghost`,onClick:e=>{e.stopPropagation(),B.mutate(t.id)},disabled:n||r||!t.enabled,title:t.enabled?p(`build.scriptsTab.restart`,`Restart`):p(`build.scriptsTab.enableItInsteadADisabled`,`Enable it instead — a disabled script has no process`),children:o(D,{className:`h-4 w-4${r?` animate-spin`:``}`})}),o(W,{variant:`ghost`,onClick:e=>{e.stopPropagation(),O(E===t.id?null:t.id)},title:p(`build.scriptsTab.logs`,`Logs`),children:o(k,{className:`h-4 w-4`})}),o(W,{variant:`ghost`,onClick:e=>{e.stopPropagation(),z.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(),w({title:p(`build.scriptsTab.deleteThisScript`,`Delete this script?`),message:p(`build.scriptsTab.deleteMessage`,`{{name}} and its source will be deleted. This cannot be undone.`,{name:t.name}),confirmLabel:p(`common.delete`,`Delete`),variant:`danger`}).then(e=>{e&&R.mutate(t.id)})},title:p(`common.delete`,`Delete`),children:o(_,{className:`h-4 w-4`})})]})}}],[w,E,i,v,R,B.isPending,B.variables,z,p]);return e(`div`,{className:`space-y-3`,children:[o(`p`,{className:`text-xs text-foreground-subtle`,children:A.data===void 0?``:Yn(te)}),A.error!=null&&o(U,{title:p(`build.scriptsTab.couldNotReadTheScripts`,`Could not read the scripts`),message:Ia(A.error),onRetry:N}),o(Ce,{columns:se,rows:te,rowKey:e=>e.id,pageSize:25,maxBodyHeight:fe,emptyMessage:ne?p(`build.scriptsTab.noScriptsYetAScript`,`No scripts yet. A script is TypeScript the hub runs in its own process.`):A.data===void 0?p(`build.scriptsTab.loadingScripts`,`Loading scripts…`):p(`build.scriptsTab.noScriptsYet`,`No scripts yet.`),onRowClick:e=>{S(e),v(e.id),i?.(e.id)}}),o(Fe,{open:j,onClose:()=>{I.reset(),L.reset(),B.reset(),S(null),y(),i?.(null)},title:oe===null?p(`build.scriptsTab.newScript`,`New script`):p(`build.scriptsTab.edit`,`Edit {{name}}`,{name:oe.name}),icon:ce,width:`xl`,testId:`script-editor-panel`,children:o(ja,{existing:oe,typeDefs:M.data,typeDefsLoading:M.isLoading,saving:re,saveError:ie,restarting:B.isPending,restartError:B.error===null?null:Ia(B.error),onRestart:oe===null?void 0:()=>B.mutate(oe.id),onSave:e=>{let t=oe;t===null?I.mutate(e):L.mutate({blockId:t.id,block:e})},onCancel:()=>{I.reset(),L.reset(),B.reset(),S(null),y(),i?.(null)}})}),R.error!=null&&o(U,{message:Ia(R.error)}),z.error!=null&&o(U,{message:Ia(z.error)}),B.error!=null&&o(U,{message:Ia(B.error)})]})}var Ra=[`automations`,`scripts`,`custom-device`];function za(e){return e!==null&&Ra.some(t=>t===e)}var Ba=[`coreBlocks`,`list`,`build-counts`],Va=[`block`,`create`,`new`];function Ha(e){return e.filter(e=>ee(e)===`code`).length}function Ua(e){return e.filter(e=>at(e.code)).length}function Wa(e,t){return t===null?e:`${e} (${String(t)})`}function Ga(){let{t}=Y(),n=x(),[r,i]=Ge(),a=r.get(`tab`),s=za(a)?a:`automations`,c=r.get(`create`)===`1`,u=l({queryKey:Ba,refetchInterval:5e3,queryFn:async()=>(await n.trpcClient.coreBlocks.list.query({})).blocks}).data,d=u===void 0?null:Ha(u),f=u===void 0?null:Ua(u),p=l({queryKey:[`coreBlocks`,`listCompositions`,`build-counts`],refetchInterval:1e4,queryFn:async()=>n.trpcClient.coreBlocks.listCompositions.query({})}),h=p.data?.state===`loaded`?p.data.views.length:null,_=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})},v=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})},y=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})},b=()=>{i(e=>{let t=new URLSearchParams(e);return t.set(`create`,`1`),t.delete(`block`),t},{replace:!0})},S=e=>{i(()=>{let t=new URLSearchParams(window.location.search);return t.set(`tab`,`custom-device`),t.delete(`block`),t.delete(`create`),t.set(`new`,e),t},{replace:!0})},C=()=>{i(()=>{let e=new URLSearchParams(window.location.search);return e.delete(`create`),e},{replace:!0})},w=s===`automations`?`New automation`:`New script`,T=Ue(`/build`,{t,isAdmin:!0})??{icon:m,title:t(`nav.build`,`Build-your-self`)};return o(Xe,{icon:T.icon,title:T.title,subtitle:t(`build.automationsScriptsAndComposedDevices`,`Automations, scripts and composed devices — what this installation does on its own.`),defaultSection:`automations`,sectionsLabel:`${T.title} sections`,fill:!0,actions:s===`custom-device`?e(`div`,{className:`flex flex-wrap gap-2`,children:[e(W,{type:`button`,variant:`outline`,onClick:()=>S(`blank`),"data-testid":`build-new-composition`,children:[o(g,{className:`h-4 w-4`}),` `,t(`helper.newComposition`)]}),e(W,{type:`button`,onClick:()=>S(`helper`),"data-testid":`build-new-helper`,children:[o(g,{className:`h-4 w-4`}),` `,t(`helper.newHelper`)]})]}):e(W,{type:`button`,onClick:b,"data-testid":`build-new`,children:[o(g,{className:`h-4 w-4`}),` `,w]}),sections:[{id:`automations`,label:Wa(`Automations`,f),ownedParams:Va,content:o(tr,{onOpenScripts:_,initialBlockId:s===`automations`?r.get(`block`)??void 0:void 0,onBlockIdChange:v,createRequested:s===`automations`&&c,onCreateConsumed:C})},{id:`scripts`,label:Wa(`Scripts`,d),ownedParams:Va,content:o(La,{initialBlockId:s===`scripts`?r.get(`block`)??void 0:void 0,onBlockIdChange:y,createRequested:s===`scripts`&&c,onCreateConsumed:C})},{id:`custom-device`,label:Wa(`Custom Device`,h),ownedParams:Va,content:o(Or,{createRequested:s===`custom-device`&&c,onCreateConsumed:C})}]})}export{Ga 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-DmlN4sZb.js";import{dr as l,ur as u}from"./client-Gv3pB3LY.js";import{h as d}from"./video-TyyuRVZ9.js";import{Ca as f,Sa as p,Ta as m,Yr as h,_r as g,dr as _,fr as v,gr as y,hr as b,pr as x,wa as S}from"./src-DWX1wfhS.js";import{t as C}from"./i18n-D0vRhk5m.js";import{t as w}from"./useTranslation-BJr-n0es.js";import{dr as T,ur as E}from"./index-D_AGxR1C.js";import{t as D}from"./AdminPage-CdqsBsG5.js";a();var O=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`];function k(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function A(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function j(e){let t=e.getDay();return k(A(e,t===0?-6:1-t))}function M(e,t){if(t===`day`){let t=k(e);return{startMs:t.getTime(),endMs:A(t,1).getTime()}}if(t===`week`){let t=j(e);return{startMs:t.getTime(),endMs:A(t,7).getTime()}}let n=new Date(e.getFullYear(),e.getMonth(),1),r=new Date(e.getFullYear(),e.getMonth()+1,0),i=j(n),a=A(j(r),7);return{startMs:i.getTime(),endMs:a.getTime()}}function N(e,t){if(t===`day`)return e.toLocaleDateString(void 0,{weekday:`long`,year:`numeric`,month:`long`,day:`numeric`});if(t===`week`){let t=j(e),n=A(t,6),r={month:`short`,day:`numeric`};return`${t.toLocaleDateString(void 0,r)} – ${n.toLocaleDateString(void 0,{...r,year:`numeric`})}`}return e.toLocaleDateString(void 0,{month:`long`,year:`numeric`})}function P(e,t,n){return t===`day`?A(e,n):t===`week`?A(e,n*7):new Date(e.getFullYear(),e.getMonth()+n,1)}function F(e,t){if(t===void 0)return e;let n=t.calendars[e.id];return n===void 0?e:{...e,visible:n.visible??e.visible,color:n.color??e.defaultColor}}function I(e){return e.providerAddonId!==void 0&&e.providerAddonId.length>0?e.providerAddonId:e.source===`ha`?`Home Assistant`:e.source}function L(e){if(e.allDay===!0)return C.t(`systemPage.calendars.allDay`);let t=new Date(e.startMs),n=new Date(e.endMs),r={hour:`2-digit`,minute:`2-digit`};return`${t.toLocaleTimeString([],r)} – ${n.toLocaleTimeString([],r)}`}function R(e){let t=u(e),n=new Date(t.startMs),r=new Date(t.endMs),i={weekday:`short`,year:`numeric`,month:`short`,day:`numeric`};if(e.allDay===!0){let e=k(n),t=A(k(r),-1);return H(e,t)?C.t(`systemPage.calendars.dayAllDay`,{date:n.toLocaleDateString(void 0,i)}):C.t(`systemPage.calendars.rangeAllDay`,{from:n.toLocaleDateString(void 0,i),to:t.toLocaleDateString(void 0,i)})}let a={hour:`2-digit`,minute:`2-digit`};return H(n,r)?`${n.toLocaleDateString(void 0,i)} · ${n.toLocaleTimeString([],a)} – ${r.toLocaleTimeString([],a)}`:`${n.toLocaleString(void 0,{...i,...a})} – ${r.toLocaleString(void 0,{...i,...a})}`}function z({label:t,children:n}){return e(`div`,{className:`grid grid-cols-[7rem_minmax(0,1fr)] gap-x-3 gap-y-1 text-sm`,children:[r(`dt`,{className:`text-foreground-subtle`,children:t}),r(`dd`,{className:`min-w-0 break-words text-foreground`,children:n})]})}function B({ev:t,calendarName:n,color:i,onClose:a}){let{t:o}=w();return r(_,{open:!0,onOpenChange:e=>!e&&a(),children:e(x,{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=>l(e,t))}function H(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function U({mode:e,onChange:t}){let{t:n}=w(),i=[{id:`month`,label:n(`systemPage.calendars.month`,`Month`)},{id:`week`,label:n(`systemPage.calendars.week`,`Week`)},{id:`day`,label:n(`systemPage.calendars.day`,`Day`)}];return r(`div`,{className:`inline-flex rounded-lg border border-border bg-surface p-0.5`,role:`group`,"aria-label":n(`systemPage.calendars.calendarView`,`Calendar view`),children:i.map(n=>r(`button`,{type:`button`,className:e===n.id?`rounded-md bg-primary px-2.5 py-1 text-xs font-medium text-primary-foreground`:`rounded-md px-2.5 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground`,"aria-pressed":e===n.id,onClick:()=>t(n.id),"data-testid":`calendars-view-${n.id}`,children:n.label},n.id))})}function W({calendars:t,onToggleVisible:n,onColorChange:i,busy:a}){let{t:o}=w();return e(`aside`,{className:`w-full shrink-0 space-y-2 lg:w-56 xl:w-64`,"data-testid":`calendars-legend`,children:[r(`h2`,{className:`text-xs font-medium text-foreground-subtle`,children:o(`systemPage.calendars.calendars`,`Calendars`)}),r(`ul`,{className:`space-y-1`,children:t.map(t=>e(`li`,{className:`flex items-start gap-2 rounded-md px-1.5 py-1.5 hover:bg-surface`,children:[r(`input`,{type:`checkbox`,className:`mt-1 h-3.5 w-3.5 shrink-0 accent-primary`,checked:t.visible,disabled:a,onChange:e=>n(t.id,e.target.checked),"aria-label":o(`systemPage.calendars.show`,`Show {{name}}`,{name:t.name}),"data-testid":`calendars-visible-${t.id}`}),r(`input`,{type:`color`,className:`mt-0.5 h-6 w-6 shrink-0 cursor-pointer rounded border border-border bg-transparent p-0`,value:t.color,disabled:a,onChange:e=>i(t.id,e.target.value.toUpperCase()),"aria-label":o(`systemPage.calendars.colourFor`,`Colour for {{name}}`,{name:t.name}),"data-testid":`calendars-color-${t.id}`}),e(`div`,{className:`min-w-0 flex-1`,children:[r(`div`,{className:`truncate text-sm font-medium ${t.visible?`text-foreground`:`text-foreground-subtle`}`,children:t.name}),e(`div`,{className:`truncate text-[11px] text-foreground-subtle`,children:[I(t),t.enabled?``:` · ${o(`systemPage.calendars.unavailableAtSource`)}`]})]})]},t.id))})]})}function G({ev:t,color:n,compact:i,onSelect:a}){return r(`button`,{type:`button`,className:i?`block w-full truncate rounded px-1 py-0.5 text-left text-[10px] leading-tight text-white hover:brightness-110`:`block w-full rounded-md px-2 py-1.5 text-left text-xs text-white hover:brightness-110`,style:{backgroundColor:n},title:t.title,onClick:()=>a(t),"data-testid":`calendars-event-${t.id}`,children:i?t.title:e(o,{children:[r(`div`,{className:`font-medium`,children:t.title}),r(`div`,{className:`opacity-90`,children:L(t)})]})})}function K({anchor:t,events:n,colorById:i,today:a,onSelectEvent:o}){let{t:s}=w(),{startMs:c,endMs:l}=M(t,`month`),u=[];for(let e=new Date(c);e.getTime()<l;e=A(e,1))u.push(e);let d=t.getMonth();return e(`div`,{"data-testid":`calendars-month`,children:[r(`div`,{className:`mb-1 grid grid-cols-7 gap-px`,children:O.map(e=>r(`div`,{className:`px-1 py-1 text-center text-[11px] font-medium text-foreground-subtle`,children:e},e))}),r(`div`,{className:`grid grid-cols-7 gap-px overflow-hidden rounded-lg border border-border bg-border`,children:u.map(t=>{let c=k(t).getTime(),l=V(n,c),u=t.getMonth()!==d,f=H(t,a);return e(`div`,{className:`min-h-[5.5rem] bg-background p-1 ${u?`opacity-45`:``}`,children:[r(`div`,{className:f?`mb-1 inline-flex h-5 w-5 items-center justify-center rounded-full bg-primary text-[11px] font-semibold text-primary-foreground`:`mb-1 text-[11px] font-medium text-foreground-subtle`,children:t.getDate()}),e(`div`,{className:`space-y-0.5`,children:[l.slice(0,3).map(e=>r(G,{ev:e,color:i.get(e.calendarId)??`#64748B`,compact:!0,onSelect:o},e.id)),l.length>3?r(`div`,{className:`text-[10px] text-foreground-subtle`,children:s(`common.moreCount`,{count:l.length-3})}):null]})]},c)})})]})}function q({anchor:t,events:n,colorById:i,today:a,onSelectEvent:o}){let s=j(t);return r(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-7 sm:gap-px sm:overflow-hidden sm:rounded-lg sm:border sm:border-border sm:bg-border`,"data-testid":`calendars-week`,children:Array.from({length:7},(e,t)=>A(s,t)).map(t=>{let s=k(t).getTime(),c=V(n,s);return e(`div`,{className:`min-h-[8rem] bg-background p-2 sm:min-h-[12rem]`,children:[r(`div`,{className:H(t,a)?`mb-2 text-xs font-semibold text-primary`:`mb-2 text-xs font-medium text-foreground-subtle`,children:t.toLocaleDateString(void 0,{weekday:`short`,day:`numeric`})}),r(`div`,{className:`space-y-1`,children:c.length===0?r(`p`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):c.map(e=>r(G,{ev:e,color:i.get(e.calendarId)??`#64748B`,onSelect:o},e.id))})]},s)})})}function J({anchor:t,events:n,colorById:i,calName:a,onSelectEvent:o}){let{t:s}=w(),c=V(n,k(t).getTime());return c.length===0?r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-day-empty`,children:s(`systemPage.calendars.noEventsOnThisDay`,`No events on this day.`)}):r(`ul`,{className:`divide-y divide-border rounded-lg border border-border`,"data-testid":`calendars-day`,children:c.map(t=>r(`li`,{children:e(`button`,{type:`button`,className:`flex w-full items-start gap-3 px-3 py-3 text-left hover:bg-surface`,onClick:()=>o(t),"data-testid":`calendars-event-${t.id}`,children:[r(`span`,{className:`mt-1 h-2.5 w-2.5 shrink-0 rounded-full`,style:{backgroundColor:i.get(t.calendarId)??`#64748B`}}),e(`div`,{className:`min-w-0`,children:[r(`div`,{className:`font-medium text-sm text-foreground`,children:t.title}),e(`div`,{className:`text-xs text-foreground-subtle`,children:[L(t),` · `,a.get(t.calendarId)??t.calendarId]}),t.location!==void 0&&t.location.length>0?r(`div`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:t.location}):null]})]})},t.id))})}function Y(){let{t:a}=w(),o=f(),l=p({}),u=m(),[h,g]=i(`month`),[_,v]=i(()=>k(new Date)),[y,b]=i(null),x=t(()=>k(new Date),[]),C=o.isSuccess,O=l.isSuccess&&l.data!==void 0?l.data:void 0,A=t(()=>!C||o.data===void 0?[]:o.data.map(e=>F(e,O)),[C,o.data,O]),j=t(()=>A.filter(e=>e.visible),[A]),I=t(()=>j.map(e=>e.id),[j]),L=t(()=>M(_,h),[_,h]),R=S({startMs:L.startMs,endMs:L.endMs,calendarIds:[...I]},{enabled:C&&I.length>0}),z=R.data??[],V=t(()=>{let e=new Map;for(let t of A)e.set(t.id,t.color);return e},[A]),H=t(()=>{let e=new Map;for(let t of A)e.set(t.id,t.name);return e},[A]),G=n((e,t)=>{u.mutateAsync({calendarId:e,visible:t}).then(()=>l.refetch())},[l,u]),Y=n((e,t)=>{/^#[0-9A-Fa-f]{6}$/.test(t)&&u.mutateAsync({calendarId:e,color:t}).then(()=>l.refetch())},[l,u]),X=n(()=>v(k(new Date)),[]),Z=n(()=>v(e=>P(e,h,-1)),[h]),ee=n(()=>v(e=>P(e,h,1)),[h]),Q=`inline-flex h-8 w-8 items-center justify-center rounded-lg border border-border bg-surface text-foreground hover:bg-primary/5 disabled:opacity-50`,$;return $=o.isPending?r(`p`,{className:`text-sm text-foreground-subtle`,children:a(`systemPage.calendars.loadingCalendars`,`Loading calendars…`)}):o.isError?e(`p`,{className:`text-sm text-destructive`,children:[a(`systemPage.calendars.couldNotListCalendars`,`Could not list calendars:`),` `,o.error.message]}):A.length===0?r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-sources`,children:r(E,{i18nKey:`systemPage.calendars.emptySources`,components:{link:r(T,{to:`/system/integrations?tab=calendars`,className:`text-accent underline-offset-2 hover:underline`})}})}):I.length===0?e(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[r(W,{calendars:A,onToggleVisible:G,onColorChange:Y,busy:u.isPending}),r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-hidden`,children:a(`systemPage.calendars.allCalendarsAreHiddenTurn`,`All calendars are hidden. Turn one on in the legend to see events.`)})]}):e(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[r(W,{calendars:A,onToggleVisible:G,onColorChange:Y,busy:u.isPending}),e(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(U,{mode:h,onChange:g}),e(`div`,{className:`flex items-center gap-1`,children:[r(`button`,{type:`button`,className:Q,onClick:Z,"aria-label":a(`systemPage.calendars.previous`,`Previous`),"data-testid":`calendars-prev`,children:r(s,{className:`h-4 w-4`})}),r(`button`,{type:`button`,className:`inline-flex items-center rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5`,onClick:X,"data-testid":`calendars-today`,children:a(`systemPage.calendars.today`,`Today`)}),r(`button`,{type:`button`,className:Q,onClick:ee,"aria-label":a(`common.next`,`Next`),"data-testid":`calendars-next`,children:r(c,{className:`h-4 w-4`})})]}),r(`span`,{className:`text-sm font-medium text-foreground`,"data-testid":`calendars-period`,children:N(_,h)})]}),R.isPending?r(`p`,{className:`text-sm text-foreground-subtle`,children:a(`systemPage.calendars.loadingEvents`,`Loading events…`)}):R.isError?e(`p`,{className:`text-sm text-destructive`,children:[a(`systemPage.calendars.couldNotListEvents`,`Could not list events:`),` `,R.error.message]}):h===`month`?r(K,{anchor:_,events:z,colorById:V,today:x,onSelectEvent:b}):h===`week`?r(q,{anchor:_,events:z,colorById:V,today:x,onSelectEvent:b}):r(J,{anchor:_,events:z,colorById:V,calName:H,onSelectEvent:b})]})]}),e(D,{icon:d,title:a(`systemPage.calendars.calendars`,`Calendars`),subtitle:a(`systemPage.calendars.calendarsFromConnectedSourcesUsed`,`Calendars from connected sources. Used by Calendar events notification rules.`),children:[$,y===null?null:r(B,{ev:y,calendarName:H.get(y.calendarId)??y.calendarId,color:V.get(y.calendarId)??`#64748B`,onClose:()=>b(null)})]})}export{Y as CalendarsPage,Y as default};
|
|
1
|
+
import{C as e,K as t,R as n,S as r,Y as i,et as a,x as o}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Ei as s,Ti as c}from"./player-overlays-BFb5SWA9.js";import{dr as l,ur as u}from"./client-Rf8T-Qxy.js";import{h as d}from"./video-B6REUv1P.js";import{Ca as f,Sa as p,Ta as m,Yr as h,_r as g,dr as _,fr as v,gr as y,hr as b,pr as x,wa as S}from"./src-BfkcE2yV.js";import{t as C}from"./i18n-BDPAB47Q.js";import{t as w}from"./useTranslation-BJr-n0es.js";import{dr as T,ur as E}from"./index-DUGfFMf0.js";import{t as D}from"./AdminPage-CV0QlJ3B.js";a();var O=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`];function k(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function A(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function j(e){let t=e.getDay();return k(A(e,t===0?-6:1-t))}function M(e,t){if(t===`day`){let t=k(e);return{startMs:t.getTime(),endMs:A(t,1).getTime()}}if(t===`week`){let t=j(e);return{startMs:t.getTime(),endMs:A(t,7).getTime()}}let n=new Date(e.getFullYear(),e.getMonth(),1),r=new Date(e.getFullYear(),e.getMonth()+1,0),i=j(n),a=A(j(r),7);return{startMs:i.getTime(),endMs:a.getTime()}}function N(e,t){if(t===`day`)return e.toLocaleDateString(void 0,{weekday:`long`,year:`numeric`,month:`long`,day:`numeric`});if(t===`week`){let t=j(e),n=A(t,6),r={month:`short`,day:`numeric`};return`${t.toLocaleDateString(void 0,r)} – ${n.toLocaleDateString(void 0,{...r,year:`numeric`})}`}return e.toLocaleDateString(void 0,{month:`long`,year:`numeric`})}function P(e,t,n){return t===`day`?A(e,n):t===`week`?A(e,n*7):new Date(e.getFullYear(),e.getMonth()+n,1)}function F(e,t){if(t===void 0)return e;let n=t.calendars[e.id];return n===void 0?e:{...e,visible:n.visible??e.visible,color:n.color??e.defaultColor}}function I(e){return e.providerAddonId!==void 0&&e.providerAddonId.length>0?e.providerAddonId:e.source===`ha`?`Home Assistant`:e.source}function L(e){if(e.allDay===!0)return C.t(`systemPage.calendars.allDay`);let t=new Date(e.startMs),n=new Date(e.endMs),r={hour:`2-digit`,minute:`2-digit`};return`${t.toLocaleTimeString([],r)} – ${n.toLocaleTimeString([],r)}`}function R(e){let t=u(e),n=new Date(t.startMs),r=new Date(t.endMs),i={weekday:`short`,year:`numeric`,month:`short`,day:`numeric`};if(e.allDay===!0){let e=k(n),t=A(k(r),-1);return H(e,t)?C.t(`systemPage.calendars.dayAllDay`,{date:n.toLocaleDateString(void 0,i)}):C.t(`systemPage.calendars.rangeAllDay`,{from:n.toLocaleDateString(void 0,i),to:t.toLocaleDateString(void 0,i)})}let a={hour:`2-digit`,minute:`2-digit`};return H(n,r)?`${n.toLocaleDateString(void 0,i)} · ${n.toLocaleTimeString([],a)} – ${r.toLocaleTimeString([],a)}`:`${n.toLocaleString(void 0,{...i,...a})} – ${r.toLocaleString(void 0,{...i,...a})}`}function z({label:t,children:n}){return e(`div`,{className:`grid grid-cols-[7rem_minmax(0,1fr)] gap-x-3 gap-y-1 text-sm`,children:[r(`dt`,{className:`text-foreground-subtle`,children:t}),r(`dd`,{className:`min-w-0 break-words text-foreground`,children:n})]})}function B({ev:t,calendarName:n,color:i,onClose:a}){let{t:o}=w();return r(_,{open:!0,onOpenChange:e=>!e&&a(),children:e(x,{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=>l(e,t))}function H(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function U({mode:e,onChange:t}){let{t:n}=w(),i=[{id:`month`,label:n(`systemPage.calendars.month`,`Month`)},{id:`week`,label:n(`systemPage.calendars.week`,`Week`)},{id:`day`,label:n(`systemPage.calendars.day`,`Day`)}];return r(`div`,{className:`inline-flex rounded-lg border border-border bg-surface p-0.5`,role:`group`,"aria-label":n(`systemPage.calendars.calendarView`,`Calendar view`),children:i.map(n=>r(`button`,{type:`button`,className:e===n.id?`rounded-md bg-primary px-2.5 py-1 text-xs font-medium text-primary-foreground`:`rounded-md px-2.5 py-1 text-xs font-medium text-foreground-subtle hover:text-foreground`,"aria-pressed":e===n.id,onClick:()=>t(n.id),"data-testid":`calendars-view-${n.id}`,children:n.label},n.id))})}function W({calendars:t,onToggleVisible:n,onColorChange:i,busy:a}){let{t:o}=w();return e(`aside`,{className:`w-full shrink-0 space-y-2 lg:w-56 xl:w-64`,"data-testid":`calendars-legend`,children:[r(`h2`,{className:`text-xs font-medium text-foreground-subtle`,children:o(`systemPage.calendars.calendars`,`Calendars`)}),r(`ul`,{className:`space-y-1`,children:t.map(t=>e(`li`,{className:`flex items-start gap-2 rounded-md px-1.5 py-1.5 hover:bg-surface`,children:[r(`input`,{type:`checkbox`,className:`mt-1 h-3.5 w-3.5 shrink-0 accent-primary`,checked:t.visible,disabled:a,onChange:e=>n(t.id,e.target.checked),"aria-label":o(`systemPage.calendars.show`,`Show {{name}}`,{name:t.name}),"data-testid":`calendars-visible-${t.id}`}),r(`input`,{type:`color`,className:`mt-0.5 h-6 w-6 shrink-0 cursor-pointer rounded border border-border bg-transparent p-0`,value:t.color,disabled:a,onChange:e=>i(t.id,e.target.value.toUpperCase()),"aria-label":o(`systemPage.calendars.colourFor`,`Colour for {{name}}`,{name:t.name}),"data-testid":`calendars-color-${t.id}`}),e(`div`,{className:`min-w-0 flex-1`,children:[r(`div`,{className:`truncate text-sm font-medium ${t.visible?`text-foreground`:`text-foreground-subtle`}`,children:t.name}),e(`div`,{className:`truncate text-[11px] text-foreground-subtle`,children:[I(t),t.enabled?``:` · ${o(`systemPage.calendars.unavailableAtSource`)}`]})]})]},t.id))})]})}function G({ev:t,color:n,compact:i,onSelect:a}){return r(`button`,{type:`button`,className:i?`block w-full truncate rounded px-1 py-0.5 text-left text-[10px] leading-tight text-white hover:brightness-110`:`block w-full rounded-md px-2 py-1.5 text-left text-xs text-white hover:brightness-110`,style:{backgroundColor:n},title:t.title,onClick:()=>a(t),"data-testid":`calendars-event-${t.id}`,children:i?t.title:e(o,{children:[r(`div`,{className:`font-medium`,children:t.title}),r(`div`,{className:`opacity-90`,children:L(t)})]})})}function K({anchor:t,events:n,colorById:i,today:a,onSelectEvent:o}){let{t:s}=w(),{startMs:c,endMs:l}=M(t,`month`),u=[];for(let e=new Date(c);e.getTime()<l;e=A(e,1))u.push(e);let d=t.getMonth();return e(`div`,{"data-testid":`calendars-month`,children:[r(`div`,{className:`mb-1 grid grid-cols-7 gap-px`,children:O.map(e=>r(`div`,{className:`px-1 py-1 text-center text-[11px] font-medium text-foreground-subtle`,children:e},e))}),r(`div`,{className:`grid grid-cols-7 gap-px overflow-hidden rounded-lg border border-border bg-border`,children:u.map(t=>{let c=k(t).getTime(),l=V(n,c),u=t.getMonth()!==d,f=H(t,a);return e(`div`,{className:`min-h-[5.5rem] bg-background p-1 ${u?`opacity-45`:``}`,children:[r(`div`,{className:f?`mb-1 inline-flex h-5 w-5 items-center justify-center rounded-full bg-primary text-[11px] font-semibold text-primary-foreground`:`mb-1 text-[11px] font-medium text-foreground-subtle`,children:t.getDate()}),e(`div`,{className:`space-y-0.5`,children:[l.slice(0,3).map(e=>r(G,{ev:e,color:i.get(e.calendarId)??`#64748B`,compact:!0,onSelect:o},e.id)),l.length>3?r(`div`,{className:`text-[10px] text-foreground-subtle`,children:s(`common.moreCount`,{count:l.length-3})}):null]})]},c)})})]})}function q({anchor:t,events:n,colorById:i,today:a,onSelectEvent:o}){let s=j(t);return r(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-7 sm:gap-px sm:overflow-hidden sm:rounded-lg sm:border sm:border-border sm:bg-border`,"data-testid":`calendars-week`,children:Array.from({length:7},(e,t)=>A(s,t)).map(t=>{let s=k(t).getTime(),c=V(n,s);return e(`div`,{className:`min-h-[8rem] bg-background p-2 sm:min-h-[12rem]`,children:[r(`div`,{className:H(t,a)?`mb-2 text-xs font-semibold text-primary`:`mb-2 text-xs font-medium text-foreground-subtle`,children:t.toLocaleDateString(void 0,{weekday:`short`,day:`numeric`})}),r(`div`,{className:`space-y-1`,children:c.length===0?r(`p`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):c.map(e=>r(G,{ev:e,color:i.get(e.calendarId)??`#64748B`,onSelect:o},e.id))})]},s)})})}function J({anchor:t,events:n,colorById:i,calName:a,onSelectEvent:o}){let{t:s}=w(),c=V(n,k(t).getTime());return c.length===0?r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-day-empty`,children:s(`systemPage.calendars.noEventsOnThisDay`,`No events on this day.`)}):r(`ul`,{className:`divide-y divide-border rounded-lg border border-border`,"data-testid":`calendars-day`,children:c.map(t=>r(`li`,{children:e(`button`,{type:`button`,className:`flex w-full items-start gap-3 px-3 py-3 text-left hover:bg-surface`,onClick:()=>o(t),"data-testid":`calendars-event-${t.id}`,children:[r(`span`,{className:`mt-1 h-2.5 w-2.5 shrink-0 rounded-full`,style:{backgroundColor:i.get(t.calendarId)??`#64748B`}}),e(`div`,{className:`min-w-0`,children:[r(`div`,{className:`font-medium text-sm text-foreground`,children:t.title}),e(`div`,{className:`text-xs text-foreground-subtle`,children:[L(t),` · `,a.get(t.calendarId)??t.calendarId]}),t.location!==void 0&&t.location.length>0?r(`div`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:t.location}):null]})]})},t.id))})}function Y(){let{t:a}=w(),o=f(),l=p({}),u=m(),[h,g]=i(`month`),[_,v]=i(()=>k(new Date)),[y,b]=i(null),x=t(()=>k(new Date),[]),C=o.isSuccess,O=l.isSuccess&&l.data!==void 0?l.data:void 0,A=t(()=>!C||o.data===void 0?[]:o.data.map(e=>F(e,O)),[C,o.data,O]),j=t(()=>A.filter(e=>e.visible),[A]),I=t(()=>j.map(e=>e.id),[j]),L=t(()=>M(_,h),[_,h]),R=S({startMs:L.startMs,endMs:L.endMs,calendarIds:[...I]},{enabled:C&&I.length>0}),z=R.data??[],V=t(()=>{let e=new Map;for(let t of A)e.set(t.id,t.color);return e},[A]),H=t(()=>{let e=new Map;for(let t of A)e.set(t.id,t.name);return e},[A]),G=n((e,t)=>{u.mutateAsync({calendarId:e,visible:t}).then(()=>l.refetch())},[l,u]),Y=n((e,t)=>{/^#[0-9A-Fa-f]{6}$/.test(t)&&u.mutateAsync({calendarId:e,color:t}).then(()=>l.refetch())},[l,u]),X=n(()=>v(k(new Date)),[]),Z=n(()=>v(e=>P(e,h,-1)),[h]),ee=n(()=>v(e=>P(e,h,1)),[h]),Q=`inline-flex h-8 w-8 items-center justify-center rounded-lg border border-border bg-surface text-foreground hover:bg-primary/5 disabled:opacity-50`,$;return $=o.isPending?r(`p`,{className:`text-sm text-foreground-subtle`,children:a(`systemPage.calendars.loadingCalendars`,`Loading calendars…`)}):o.isError?e(`p`,{className:`text-sm text-destructive`,children:[a(`systemPage.calendars.couldNotListCalendars`,`Could not list calendars:`),` `,o.error.message]}):A.length===0?r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-sources`,children:r(E,{i18nKey:`systemPage.calendars.emptySources`,components:{link:r(T,{to:`/system/integrations?tab=calendars`,className:`text-accent underline-offset-2 hover:underline`})}})}):I.length===0?e(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[r(W,{calendars:A,onToggleVisible:G,onColorChange:Y,busy:u.isPending}),r(`p`,{className:`text-sm text-foreground-subtle`,"data-testid":`calendars-empty-hidden`,children:a(`systemPage.calendars.allCalendarsAreHiddenTurn`,`All calendars are hidden. Turn one on in the legend to see events.`)})]}):e(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[r(W,{calendars:A,onToggleVisible:G,onColorChange:Y,busy:u.isPending}),e(`div`,{className:`min-w-0 flex-1 space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(U,{mode:h,onChange:g}),e(`div`,{className:`flex items-center gap-1`,children:[r(`button`,{type:`button`,className:Q,onClick:Z,"aria-label":a(`systemPage.calendars.previous`,`Previous`),"data-testid":`calendars-prev`,children:r(s,{className:`h-4 w-4`})}),r(`button`,{type:`button`,className:`inline-flex items-center rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5`,onClick:X,"data-testid":`calendars-today`,children:a(`systemPage.calendars.today`,`Today`)}),r(`button`,{type:`button`,className:Q,onClick:ee,"aria-label":a(`common.next`,`Next`),"data-testid":`calendars-next`,children:r(c,{className:`h-4 w-4`})})]}),r(`span`,{className:`text-sm font-medium text-foreground`,"data-testid":`calendars-period`,children:N(_,h)})]}),R.isPending?r(`p`,{className:`text-sm text-foreground-subtle`,children:a(`systemPage.calendars.loadingEvents`,`Loading events…`)}):R.isError?e(`p`,{className:`text-sm text-destructive`,children:[a(`systemPage.calendars.couldNotListEvents`,`Could not list events:`),` `,R.error.message]}):h===`month`?r(K,{anchor:_,events:z,colorById:V,today:x,onSelectEvent:b}):h===`week`?r(q,{anchor:_,events:z,colorById:V,today:x,onSelectEvent:b}):r(J,{anchor:_,events:z,colorById:V,calName:H,onSelectEvent:b})]})]}),e(D,{icon:d,title:a(`systemPage.calendars.calendars`,`Calendars`),subtitle:a(`systemPage.calendars.calendarsFromConnectedSourcesUsed`,`Calendars from connected sources. Used by Calendar events notification rules.`),children:[$,y===null?null:r(B,{ev:y,calendarName:H.get(y.calendarId)??y.calendarId,color:V.get(y.calendarId)??`#64748B`,onClose:()=>b(null)})]})}export{Y as CalendarsPage,Y as default};
|