@camstack/addon-admin-ui 1.2.521 → 1.2.522
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/assets/{Addons-D8e5UEhk.js → Addons-BMftFNTU.js} +1 -1
- package/dist/assets/{AdminSectionedPage-B1FFlzAp.js → AdminSectionedPage-ePUwCKQL.js} +1 -1
- package/dist/assets/{AiProfiles-_jjOpe29.js → AiProfiles-CACYaJ0b.js} +1 -1
- package/dist/assets/{BrokerEditorDialog-CMa1f8kC.js → BrokerEditorDialog-CUIedISr.js} +1 -1
- package/dist/assets/{Build-SkecHiHh.js → Build-CDoXaCVA.js} +1 -1
- package/dist/assets/{Calendars-BncAsHLV.js → Calendars-C4XQpa_i.js} +1 -1
- package/dist/assets/{Cluster-BtPubX4s.js → Cluster-DBLF--XA.js} +1 -1
- package/dist/assets/{ComposedDeviceEditDialog-BHCTUKU-.js → ComposedDeviceEditDialog-ck2hidMF.js} +1 -1
- package/dist/assets/{CompositionBlockEditor-ImrFV2Gk.js → CompositionBlockEditor-HRq0m67C.js} +1 -1
- package/dist/assets/{CompositionEditorPage-D4Sj47wU.js → CompositionEditorPage-ofTerclJ.js} +1 -1
- package/dist/assets/{Data-DGUMhXre.js → Data-C9r_81YQ.js} +1 -1
- package/dist/assets/{DeviceDetail-CwB8tpfD.js → DeviceDetail-K5apsJzR.js} +2 -2
- package/dist/assets/{DeviceDoActionFields-B08_5fN_.js → DeviceDoActionFields-CV-_oMrw.js} +1 -1
- package/dist/assets/{Devices-B-o-SYft.js → Devices-N1YkeiNQ.js} +1 -1
- package/dist/assets/{History-CkZOzm2S.js → History-C0dKdfBD.js} +1 -1
- package/dist/assets/{Identity-D-mKJp3i.js → Identity--_TOjAWM.js} +1 -1
- package/dist/assets/{IntegrationDetail-Ba7jt4aH.js → IntegrationDetail-DxggdnLq.js} +1 -1
- package/dist/assets/{IntegrationHub-D3NNWcI3.js → IntegrationHub-DkYLz05p.js} +1 -1
- package/dist/assets/{Integrations-DfCvoh1h.js → Integrations-ABu-h5-i.js} +1 -1
- package/dist/assets/{Integrations-DzVbMY51.js → Integrations-DaHd5Vd8.js} +1 -1
- package/dist/assets/{Library-CIdnKcUl.js → Library-Fjdy5AxG.js} +1 -1
- package/dist/assets/{Locations-BMUiqhX7.js → Locations-GGj9C5iu.js} +1 -1
- package/dist/assets/{Logs-Cr5Ev4Yn.js → Logs-BD6TfZBm.js} +1 -1
- package/dist/assets/{MyAccess-egWpZOj7.js → MyAccess-SIQg6S5M.js} +1 -1
- package/dist/assets/{Network-DQwRnVG_.js → Network-BodjnB-l.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-B9vvxBEQ.js → NodeAddonsSettingsPanel-CE1Jh62u.js} +1 -1
- package/dist/assets/{Notifications-B7GkPWCE.js → Notifications-BuPf6osG.js} +1 -1
- package/dist/assets/{Pipeline-L7YohUe9.js → Pipeline-7z4wW50e.js} +1 -1
- package/dist/assets/{Recordings-CNhL7oIf.js → Recordings-BigRN2P0.js} +1 -1
- package/dist/assets/RemoteGrid-BI5deYM9.js +1 -0
- package/dist/assets/{ScanNetworkModal-B6vWwCe8.js → ScanNetworkModal-CZGf5C-T.js} +1 -1
- package/dist/assets/{SessionsList--VxRl_LS.js → SessionsList-BDOJmeXy.js} +1 -1
- package/dist/assets/{Showroom-UkIbrPnX.js → Showroom-DqFW96-i.js} +1 -1
- package/dist/assets/{System-QDZtQXm_.js → System-DTyumt9L.js} +1 -1
- package/dist/assets/Templates-dAk_L8cs.js +1 -0
- package/dist/assets/{Terminal-5v2dzxpg.js → Terminal-DIjGMS_3.js} +1 -1
- package/dist/assets/{assignment-candidates-CvlbrbgK.js → assignment-candidates-DRst7VCd.js} +1 -1
- package/dist/assets/{board-model-CZOb3LmO.js → board-model-C9BgTio0.js} +1 -1
- package/dist/assets/{device-integration-icon-CLK4k1ae.js → device-integration-icon-4rilmB_4.js} +1 -1
- package/dist/assets/{format-CvKyF2QM.js → format-BccZ2tds.js} +1 -1
- package/dist/assets/{i18n-C1QctlOB.js → i18n-COiZcYwm.js} +1 -1
- package/dist/assets/{index-D3Yx0Smp.js → index-B0SLrMzs.js} +3 -3
- package/dist/assets/{index-C0TfYmoA.css → index-DnHMM2c9.css} +1 -1
- package/dist/assets/{linked-devices-model-D9TIS2pY.js → linked-devices-model-BGb4eOlL.js} +1 -1
- package/dist/assets/{location-owned-usage-B3nr7gWQ.js → location-owned-usage-Bmczv2-v.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-e1103afa.js → mf-entry-bootstrap-0-2a2a5e72.js} +1 -1
- package/dist/assets/{step-inspector-model-Dm1vwliM.js → step-inspector-model-CNx3I9Xq.js} +1 -1
- package/dist/assets/{useNodeUrlSelection-CW3xhZq4.js → useNodeUrlSelection-DdAqNTrP.js} +1 -1
- package/dist/index.html +4 -4
- package/dist/server/addon.js +1 -1
- package/package.json +2 -1
- package/dist/assets/RemoteGrid-Ttvy6q8V.js +0 -1
- package/dist/assets/Templates-C43xppeu.js +0 -1
package/dist/assets/{CompositionBlockEditor-ImrFV2Gk.js → CompositionBlockEditor-HRq0m67C.js}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,et as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Di as l,Fn as u,Ji as d,Oi as f,Pr as p,T as m,V as h,Vt as g,Wn as _,ca as v,dt as y,er as b,gt as x,ht as S,st as C}from"./player-overlays-C_WpL6a6.js";import{$i as w,$n as T,$t as E,Aa as D,An as O,Bi as k,Ci as A,Da as j,Di as M,Dn as N,Ea as ee,Ei as P,En as F,Fa as I,Fi as L,Fn as R,Gn as te,Hn as z,Ii as ne,In as re,Ji as ie,Jn as ae,Ki as oe,Kn as se,Kt as ce,Li as le,Ln as ue,Mi as de,Mn as fe,Ni as pe,Nn as me,Oa as he,Oi as ge,On as _e,Pi as B,Pn as ve,Qi as ye,Qn as be,Ri as xe,Rn as Se,Tn as Ce,Ui as we,Un as Te,Wi as Ee,Wn as De,Xi as Oe,Xn as ke,Yi as V,Yn as Ae,Zi as je,Zn as Me,aa as Ne,ca as Pe,da as Fe,ea as Ie,en as Le,er as Re,gn as ze,ia as Be,ja as Ve,ji as He,jn as Ue,ka as We,kn as Ge,la as Ke,lr as qe,na as Je,nn as Ye,oa as Xe,qi as Ze,qn as Qe,sa as $e,sr as et,ta as tt,ua as nt,zi as rt}from"./client-Clemlz5W.js";import{c as it,d as at,f as ot,i as st,l as ct,o as lt}from"./__vite-browser-external-BCAtXlNQ.js";import{i as ut,n as dt,r as ft,t as pt}from"./sigma-q5eaqxJ5.js";import{t as mt}from"./boxes-BYgmIZEw.js";import{n as ht}from"./video-DgFhEP51.js";import{Ar as H,B as gt,Bn as _t,Br as vt,Ed as U,Fr as yt,Gr as bt,Ir as xt,Jn as St,Lr as Ct,Md as wt,Mo as Tt,Nt as Et,Pr as Dt,Qa as Ot,Rr as kt,Sr as At,St as jt,Tn as Mt,Ur as Nt,Vn as Pt,Vr as Ft,Wa as It,Xo as Lt,Yd as Rt,_r as zt,br as Bt,ci as Vt,cs as Ht,di as Ut,ei as W,fi as Wt,gr as Gt,hi as Kt,jd as G,jo as qt,js as Jt,ls as Yt,mi as Xt,nf as Zt,pi as Qt,qd as $t,qn as en,s as tn,ui as nn,vr as rn,xr as an,zn as on,zr as sn}from"./src-BuD4BDe3.js";import{t as K}from"./i18n-C1QctlOB.js";import{t as q}from"./useTranslation-BJr-n0es.js";import{h as cn,mr as ln,pr as un}from"./index-D3Yx0Smp.js";import{t as dn}from"./use-device-bound-caps-Di0CbhM4.js";import{n as fn,r as pn,t as mn}from"./assignment-candidates-CvlbrbgK.js";s();function hn(e,t){let n=e===`enum`?`string`:e,r=t.kind===`enum`?`string`:t.kind,i={source:t.source,cap:t.cap,fieldPath:t.fieldPath};return r===n?{kind:`from`,...i}:n===`number`&&r===`string`?{kind:`expression`,expr:`number(x)`,bindings:{x:{kind:`from`,...i}}}:null}function gn(e){return e.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,location:e.location,type:e.type,parentDeviceId:e.parentDeviceId}))}function J(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n||Array.isArray(n))return;n=Object.getOwnPropertyDescriptor(n,e)?.value}return n}function _n(e,t,n,r){return r===null?{kind:`from`,source:e,cap:t,fieldPath:n.path}:hn(r,{source:e,cap:t,fieldPath:n.path,kind:n.kind})}function vn(e,t,n,r){let i={addonId:e.addonId,stableId:e.stableId};return t.caps.flatMap(e=>e.fields.filter(e=>e.item!==!0).map(t=>({cap:e.cap,path:t.path,kind:t.kind,value:n===null?void 0:J(n[e.cap],t.path),source:_n(i,e.cap,t,r)})))}function yn(e,t){return t?e===void 0?`—`:e===null?`null`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e):`…`}function bn({device:t,action:n,onPick:r}){let{t:a}=q(),o=Ft(t.id,`compact`,t.name),s=[t.container===null||o.includes(t.container)?null:a(`customize.suggest.in`,{container:t.container}),t.detail].filter(e=>e!==null&&e!==``).join(` · `);return e(`li`,{className:`${m} flex items-center gap-3`,children:[e(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`text-xs text-foreground break-words`,children:o}),s!==``&&i(`div`,{className:`text-[11px] text-foreground-subtle break-words`,children:s})]}),i(W,{variant:`outline`,size:`sm`,"aria-label":a(n===`add`?`customize.suggest.addNamed`:`customize.suggest.useNamed`,{name:o}),onClick:()=>r(t.id),children:a(n===`add`?`customize.suggest.add`:`customize.suggest.use`)})]})}function xn({location:t,devices:n,action:r,onPick:a,onPickAll:o}){let{t:s}=q();if(n.length===0)return null;let c=s(`customize.suggest.heading`,{location:t});return e(`section`,{"aria-label":c,className:`flex flex-col gap-1`,children:[e(`div`,{className:`flex min-h-7 items-center gap-2`,children:[i(`h3`,{className:`${h} min-w-0 flex-1`,children:c}),o!==void 0&&n.length>1&&i(W,{variant:`ghost`,size:`sm`,onClick:o,children:s(`customize.suggest.addAll`,{count:n.length})})]}),i(`ul`,{className:`flex flex-col divide-y divide-border rounded-md border border-border`,children:n.map(e=>i(bn,{device:e,action:r,onPick:a},e.id))})]})}function Sn(e,t){let n=Zt.useQueries(n=>e.map(e=>n.deviceManager.listDeviceIdsByCaps({capNames:[e]},{enabled:t})));return fn(e.map((e,t)=>{let r=n[t];return{cap:e,query:r===void 0?{status:`pending`}:{status:r.status,data:r.data,error:r.error===null?null:{message:r.error.message}}}}))}function Cn(e){return e===`identity`||e===`invert`||e===`threshold`||e===`linear`}function wn(e){return Object.hasOwn(z,e)}function Tn(e){return wn(e)?z[e].targets:[]}function En(e,t){let n=Tn(e).find(e=>e.id===t);return n?.cardinality===`keyedArray`?n.fields??[]:[]}function Dn(e,t){return Tn(e).find(e=>e.id===t)?.traits??[]}function On(e,t){return e.caps.flatMap(e=>{let n=kn(t,e.cap);return e.fields.filter(e=>e.item!==!0).map(t=>({cap:e.cap,path:t.path,kind:t.kind,unit:n,enumValues:t.enumValues??[]}))})}function kn(e,t){if(e===null)return null;let n=J(e[t],`unit`);return typeof n==`string`&&n.length>0?n:null}function An(e,t){return t.kind===`number`?e.find(e=>e.kind===`numeric`)??null:t.kind===`enum`||t.kind===`string`?e.find(e=>e.kind===`enum`)??null:null}function jn(e,t,n,r){let i=En(e,t).find(e=>e.path===n);if(i===void 0)return{ok:!1,reason:`kind`};let a=An(i.sources,r);if(a===null)return{ok:!1,reason:`kind`};if(a.requiredUnit!==void 0&&r.unit===null)return{ok:!1,reason:`unit-unknown`};if(a.requiredUnit!==void 0&&r.unit!==a.requiredUnit)return{ok:!1,reason:`unit`};if(a.transformKinds.includes(`enum-map`))return{ok:!0,mode:`enum`};let o=a.transformKinds.filter(Cn);return o.length===0||r.kind!==`number`?{ok:!1,reason:`kind`}:{ok:!0,mode:`scalar`,fit:{ok:!0,valueKind:`number`,sourceUnit:a.requiredUnit??null,transforms:o,declared:a.transforms}}}function Mn(e,t,n){return En(e,t).find(e=>e.path===n)?.enumValues??[]}function Nn(e){return e.length===1&&e[0]===`threshold`?`threshold`:e.length===1&&e[0]===`invert`||e.includes(`invert`)&&e.every(e=>e===`identity`||e===`invert`)?`invert`:e.length>1?`choice`:`none`}function Pn(e){if(e.transforms.includes(`identity`))return{kind:`identity`};if(e.transforms.includes(`threshold`)){let t=In(e.declared,`threshold`);if(t!==null)return Fn(t)}if(e.transforms.includes(`linear`)){let t=In(e.declared,`linear`);if(t!==null)return Fn(t)}return{kind:`invert`}}function Fn(e){switch(e.kind){case`identity`:return{kind:`identity`};case`invert`:return{kind:`invert`};case`threshold`:return{kind:`threshold`,comparison:e.comparison,threshold:e.defaultThreshold,startDwellMs:e.defaultStartDwellMs,stopDwellMs:e.defaultStopDwellMs};case`linear`:return Ln(e);case`enum-map`:return{kind:`identity`}}}function In(e,t){return e.find(e=>e.kind===t)??null}function Ln(e){return{kind:`linear`,scale:e.defaultScale,offset:e.defaultOffset,...e.clampMin!==void 0&&e.clampMax!==void 0?{clampMin:e.clampMin,clampMax:e.clampMax}:{}}}function Rn(e){let t=Se({draft:{kind:`scalar`,cap:e.cap,targetId:e.targetId,source:{addonId:e.source.addonId,stableId:e.source.stableId,cap:e.source.cap,fieldPath:e.source.fieldPath},transform:e.transform},device:e.device,apply:e.apply,sourceValueKind:e.source.valueKind,changedAtField:e.source.changedAtField,sourceUnit:e.source.sourceUnit});return t.ok?t.value:null}function zn({control:t,transforms:n,declared:r,unit:a,value:o,onChange:s}){let{t:c}=q();return t===`none`?null:e(`div`,{className:`flex flex-col gap-2`,children:[i(`h3`,{className:`text-[11px] font-medium text-foreground-muted`,children:c(`customize.scalar.stepTransform`)}),t===`choice`&&i(U,{"aria-label":c(`customize.scalar.stepTransform`),value:o.kind,options:n.map(e=>({value:e,label:c(`customize.scalar.transform.${e}`)})),onChange:e=>s(Bn(e.target.value,r))}),o.kind===`invert`||t===`invert`&&o.kind!==`threshold`?e(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground`,children:[i(St,{checked:o.kind===`invert`,onChange:e=>s(e.target.checked?{kind:`invert`}:{kind:`identity`})}),c(`customize.scalar.invert`)]}):null,o.kind===`threshold`&&i(Hn,{declared:r,unit:a,value:o,onChange:s}),o.kind===`linear`&&i(Wn,{declared:r,value:o,onChange:s})]})}function Bn(e,t){let n=In(t,Vn(e));return n===null?e===`invert`?{kind:`invert`}:{kind:`identity`}:Fn(n)}function Vn(e){return e===`invert`||e===`threshold`||e===`linear`||e===`enum-map`?e:`identity`}function Hn({declared:t,unit:n,value:r,onChange:a}){let{t:o}=q(),s=n??``,c=In(t,`threshold`),l=c?.kind===`threshold`?c.comparisons:[];return e(`div`,{className:`flex flex-col gap-2 text-[11px] text-foreground`,children:[l.length>0&&e(`label`,{className:`flex flex-col gap-1`,children:[o(`customize.scalar.comparison`),i(U,{"aria-label":o(`customize.scalar.comparison`),value:r.comparison,options:l.map(e=>({value:e,label:o(`customize.scalar.comparisonValue.${e}`)})),onChange:e=>{let t=l.find(t=>t===e.target.value);t!==void 0&&a({...r,comparison:t})}})]}),i(Gn,{label:o(`customize.scalar.threshold`,{unit:s}),value:r.threshold,onChange:e=>a({...r,threshold:e})}),i(Gn,{label:o(`customize.scalar.startDwell`),value:r.startDwellMs/1e3,onChange:e=>a({...r,startDwellMs:e*1e3})}),i(Gn,{label:o(`customize.scalar.stopDwell`),value:r.stopDwellMs/1e3,onChange:e=>a({...r,stopDwellMs:e*1e3})})]})}function Un(e){return e===null||e.kind!==`linear`||e.clampMin===void 0||e.clampMax===void 0?null:{min:e.clampMin,max:e.clampMax}}function Wn({declared:t,value:n,onChange:r}){let{t:a}=q(),o=Un(In(t,`linear`));return e(`div`,{className:`flex flex-col gap-2 text-[11px] text-foreground`,children:[i(Gn,{label:a(`customize.scalar.scale`),value:n.scale,onChange:e=>r({...n,scale:e})}),i(Gn,{label:a(`customize.scalar.offset`),value:n.offset,onChange:e=>r({...n,offset:e})}),o!==null&&i(Gn,{label:a(`customize.scalar.clampMin`),value:n.clampMin??o.min,onChange:e=>r({...n,clampMin:e,clampMax:n.clampMax??o.max})}),o!==null&&i(Gn,{label:a(`customize.scalar.clampMax`),value:n.clampMax??o.max,onChange:e=>r({...n,clampMin:n.clampMin??o.min,clampMax:e})})]})}function Gn({label:t,value:n,onChange:r}){return e(`label`,{className:`flex flex-col gap-1`,children:[t,i(G,{type:`number`,value:Number.isFinite(n)?n:0,onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&r(t)}})]})}var Kn=`kind`,qn=`unit`,Jn=`unit-unknown`,Yn=`compile`,Xn=`dwell`,Zn=`no-value`,Qn=`empty`;function $n(e){return`customize.scalar.previewFailure.${e}`}function er(e){return e===`compile`||e===`dwell`||e===`no-value`||e===`empty`}function tr(e){return e===`identity`||e===`invert`||e===`threshold`||e===`linear`}function nr(e,t){let n=Object.entries(z).find(([t])=>t===e)?.[1];return n===void 0?null:n.targets.find(e=>e.id===t)??null}function rr(e,t){return nr(e,t)?.path??null}function ir(e,t){return e.caps.flatMap(e=>{let n=or(t,e.cap);return e.fields.filter(e=>e.item!==!0).map(t=>({cap:e.cap,path:t.path,kind:t.kind,unit:ar(n,e.cap,t.path)}))})}function ar(e,t,n){return e??Le(t,n)??null}function or(e,t){if(e===null)return null;let n=J(e[t],`unit`);return typeof n==`string`&&n.length>0?n:null}function sr(e,t){if(t.kind===`boolean`){let n=D[t.cap];return n===void 0||n!==t.path?null:t.cap===`switch`?e.find(e=>e.kind===`switch`)??e.find(e=>e.kind===`binary`)??null:e.find(e=>e.kind===`binary`)??e.find(e=>e.kind===`field`&&e.valueKinds?.includes(`boolean`))??null}return t.kind===`number`?e.find(e=>e.kind===`numeric`)??e.find(e=>e.kind===`field`&&e.valueKinds?.includes(`number`))??null:t.kind===`string`?e.find(e=>e.kind===`field`&&e.valueKinds?.includes(`string`))??null:null}function cr(e,t,n){let r=nr(e,t);if(r===null||r.cardinality!==`scalar`||n.kind===`enum`)return{ok:!1,reason:Kn};let i=sr(r.sources,n);if(i===null)return{ok:!1,reason:Kn};if(i.requiredUnit!==void 0&&n.unit===null)return{ok:!1,reason:Jn};if(i.requiredUnit!==void 0&&n.unit!==i.requiredUnit)return{ok:!1,reason:qn};let a=i.transformKinds.filter(tr);return a.length===0?{ok:!1,reason:Kn}:{ok:!0,valueKind:n.kind,sourceUnit:i.requiredUnit??null,transforms:a,declared:i.transforms}}function lr(e,t){return t.find(t=>t===e)??null}function ur({mode:t,modes:n,name:r,onChange:a}){let{t:o}=q();return n.length===0?null:e(`div`,{className:`flex flex-col gap-1`,children:[i(U,{"aria-label":o(`customize.motion.modeFor`,{name:r}),value:t,options:n.map(e=>({value:e,label:o(`customize.motion.mode.${e}`)})),onChange:e=>{let t=lr(e.target.value,n);t!==null&&a(t)}}),i(`p`,{className:`text-[11px] text-foreground-muted`,children:o(`customize.motion.modeLine.${t}`)})]})}var dr={lastChangedAt:{en:`Last change`,it:`Ultima variazione`},lastFetchedAt:{en:`Last update`,it:`Ultimo aggiornamento`},lastDetectedAt:{en:`Last detection`,it:`Ultimo rilevamento`},lastPressedAt:{en:`Last press`,it:`Ultima pressione`},pressCountSinceStart:{en:`Press count`,it:`Conteggio pressioni`},since:{en:`Since`,it:`Da`}};function fr(e,t){return t.startsWith(`it`)?e.it:e.en}function pr(e){if(!(`unit`in e))return;let t=e.unit;return typeof t==`string`&&t.length>0?t:void 0}function mr(e,t){let n=ze[e]?.noun;return n===void 0?e.split(`-`).filter(e=>e.length>0).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `):fr(n,t)}function Y(e,t,n){let r=ze[e]?.state?.find(e=>e.field===t);if(r!==void 0){let e=fr(r.label,n),t=pr(r);return t===void 0?e:`${e} (${t})`}let i=dr[t];return i===void 0?t:fr(i,n)}function hr(e){return e===`single`?`values`:`devices`}function gr(e){return e<=0?null:`values`}function _r(){return`devices`}function vr(e,t){return!e&&(t.seenDevice||t.step!==`devices`)?{seenDevice:!1,step:`devices`}:e&&!t.seenDevice?{seenDevice:!0,step:`values`}:null}function yr(e,t){return e===t}function br(e,t,n){let r=yr(e,t);return n?r?`flex min-h-0 flex-col`:`hidden min-h-0 flex-col sm:flex`:r?void 0:`hidden sm:block`}function xr({step:t,devices:n,values:r,back:a,onBack:o,done:s,onDone:c,fillHeight:u=!1}){return e(`div`,{"data-testid":`source-selector`,"data-step":t,className:u?`flex min-h-0 flex-1 flex-col gap-3 sm:grid sm:grid-cols-2 sm:grid-rows-[minmax(0,1fr)] sm:gap-4`:`flex flex-col gap-3 sm:grid sm:grid-cols-2 sm:gap-4`,children:[e(`div`,{"data-testid":`source-selector-devices`,className:br(t,`devices`,u),children:[s!==null&&e(`div`,{className:`mb-2 flex items-center justify-between gap-2 sm:hidden`,children:[i(`p`,{"data-testid":`source-selector-picked-count`,className:`text-[11px] text-foreground-muted`,children:s.countLabel}),i(W,{size:`sm`,"data-testid":`source-selector-done`,disabled:s.disabled,onClick:c,children:s.label})]}),n]}),e(`div`,{"data-testid":`source-selector-values`,className:br(t,`values`,u),children:[a!==null&&e(W,{variant:`ghost`,size:`sm`,className:`mb-2 sm:hidden`,"data-testid":`source-selector-back`,"aria-label":a.ariaLabel,onClick:o,children:[i(l,{className:`size-3`}),a.label]}),u?i(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:r}):r]})]})}function Sr(e){return[...new Set(e.accept.map(e=>e.cap))]}function Cr(e,t){let n=new Set(Sr(t)),r=new Set(t.exclude.map(e=>`${e.addonId}/${e.stableId}`)),i=[],a=[];for(let o of e)r.has(`${o.addonId}/${o.stableId}`)||(Nr(o.type,t.deviceTypes)&&o.caps.some(e=>n.has(e))?i.push(o):a.push(o));return{compatible:i,incompatible:a}}function wr(e,t){return e.filter(e=>kr(t,e)&&Ar(t,e))}function Tr(e,t){return t.history.required?e.filter(e=>kr(t,e)&&!jr(e)):[]}function Er(e,t){return e.flatMap(e=>{let n=t.find(t=>t.addonId===e.source.addonId&&t.stableId===e.source.stableId);return n===void 0?[]:[n.id]})}function Dr(e){if(e.selectedIds.length>e.request.max)return{members:e.previous.map(Fr),refused:`max`,needsField:[]};let t=[];return{members:e.selectedIds.flatMap(n=>{let r=e.devices.find(e=>e.id===n);if(r===void 0)return[];let i=Or(r,e);return i===null?(t.push(n),[]):[Pr(r,i.cap,i.fieldPath)]}),refused:null,needsField:t}}function Or(e,t){if(t.choiceDeviceId===e.id&&t.choice!==null&&Mr(t.request,t.choice))return t.choice;let n=t.previous.find(t=>t.source.addonId===e.addonId&&t.source.stableId===e.stableId);if(n!==void 0&&Mr(t.request,n))return n;let r=t.request.fieldChoice===`first-match`?t.request.accept.filter(t=>e.caps.includes(t.cap)):t.request.accept,i=t.request.fieldChoice===`first-match`||r.length===1?r[0]:void 0;return i===void 0?null:{cap:i.cap,fieldPath:i.fieldPath}}function kr(e,t){return e.accept.some(e=>e.cap===t.cap&&e.fieldPath===t.fieldPath&&e.valueKind===t.kind)}function Ar(e,t){return!e.history.required||jr(t)}function jr(e){return He(e.cap)[e.fieldPath]!==void 0}function Mr(e,t){return e.accept.some(e=>e.cap===t.cap&&e.fieldPath===t.fieldPath)}function Nr(e,t){return t.length===0?!0:t.some(t=>t===e)}function Pr(e,t,n){return{source:{addonId:e.addonId,stableId:e.stableId},cap:t,fieldPath:n}}function Fr(e){return{source:{addonId:e.source.addonId,stableId:e.source.stableId},cap:e.cap,fieldPath:e.fieldPath}}function Ir(e){return{id:e.id,name:e.name,type:e.type,stableId:e.stableId,parentDeviceId:e.parentDeviceId??null,...e.location!==void 0&&e.location!==null?{location:e.location}:{},...e.role!==void 0&&e.role!==null?{role:e.role}:{},...e.primaryChildEntityId!==void 0&&e.primaryChildEntityId!==null?{primaryChildEntityId:e.primaryChildEntityId}:{}}}function Lr(e,t,n=Nt(`en`)){return sn(e,`compact`,bt(t),n)}function Rr(e){return e.map(e=>({id:e.id,name:e.name,type:e.type,parentDeviceId:e.parentDeviceId,...e.location===null?{}:{location:e.location}}))}function zr(e,t){return e===`pending`||t.kind===`pending`?`pending`:e===`error`||t.kind===`unknown`?`failed`:`answered`}function Br(e,t){return e.map(e=>({id:e.id,name:e.name,type:e.type,location:e.location,parentDeviceId:e.parentDeviceId,addonId:e.addonId,stableId:e.stableId,caps:t.get(e.id)??[]}))}function Vr(e){return e.caps.flatMap(e=>e.fields.flatMap(t=>t.item===!0?[]:[{cap:e.cap,fieldPath:t.path,kind:t.kind}]))}function Hr(e,t,n){return t?e==null?n:yn(e,!0):`…`}function Ur({device:t,request:n,members:r,onChoose:a}){let{t:o,i18n:s}=q(),c=qt({deviceId:t.id}),l=Yt({deviceId:t.id}),u=c.status===`success`?c.data:{caps:[]},d=wr(Vr(u),n),f=Tr(Vr(u),n),p=`helper-member-value-${t.id}`;return e(`section`,{className:`flex flex-col gap-1`,"data-testid":`helper-member-section-${t.id}`,children:[i(`h3`,{className:`text-[11px] font-medium text-foreground`,children:i(kt,{device:t,form:`compact`})}),c.status===`pending`||l.status===`pending`?i(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:o(`customize.picker.loadingFields`)}):c.status===`error`?i(H,{title:o(`customize.picker.fieldsFailed`),message:c.error?.message??``}):d.length===0?i(`p`,{className:`text-[11px] text-foreground-muted`,children:o(`helper.noUsableValue`)}):i(`ul`,{className:`flex flex-col gap-1`,children:d.map(n=>{let c=r.some(e=>e.source.addonId===t.addonId&&e.source.stableId===t.stableId&&e.cap===n.cap&&e.fieldPath===n.fieldPath),u=l.status===`success`?J(l.data[n.cap],n.fieldPath):void 0;return i(`li`,{children:e(`label`,{className:`flex flex-wrap items-center gap-2 text-[11px] text-foreground`,children:[i(`input`,{type:`radio`,name:p,checked:c,"data-testid":`helper-value-${t.id}-${n.cap}.${n.fieldPath}`,onChange:()=>a(n)}),i(`span`,{children:Y(n.cap,n.fieldPath,s.language)}),i(`span`,{className:`text-foreground-muted`,children:Hr(u,l.status===`success`,o(`helper.valueUnknown`))})]})},`${n.cap}.${n.fieldPath}`)})}),f.length>0&&i(`p`,{className:`text-[11px] text-foreground-muted`,"data-testid":`helper-no-history`,children:o(`helper.noHistory`)})]})}function Wr({request:t,enabled:r,members:a,onMembersChange:s,onRefuse:c,fillHeight:l=!1}){let{t:u,i18n:d}=q(),[f,p]=o([]),[m,h]=o(`devices`),g=Tt({projection:`slim`}),_=n(()=>g.status===`success`?gn(g.data):[],[g.status,g.data]),v=Sn(n(()=>Sr(t),[t]),r),y=n(()=>v.kind===`known`?Cr(Br(_,v.value),t):{compatible:[],incompatible:[]},[v,_,t]),b=zr(g.status,v),x=Er(a,y.compatible),S=[...f,...x.filter(e=>!f.includes(e))].filter(e=>y.compatible.some(t=>t.id===e)),C=n(()=>Rr(y.compatible.map(Gr)),[y.compatible]),w=(e,n,r)=>{if(v.kind!==`known`)return;let i=Dr({request:t,devices:y.compatible,selectedIds:e,previous:a,choiceDeviceId:n,choice:r});if(i.refused===`max`){c({code:`max`,max:t.max});return}c(null),s(i.members)},T=e(`div`,{className:l?`flex min-h-0 flex-1 flex-col gap-2 overflow-y-auto`:`flex max-h-72 min-h-0 flex-col gap-2 overflow-y-auto sm:max-h-[min(24rem,60vh)]`,children:[i(`h3`,{className:`text-[11px] font-medium text-foreground-muted`,children:u(`helper.pickMembers`)}),g.status===`error`?i(H,{title:u(`customize.picker.devicesFailed`),message:g.error?.message??``}):v.kind===`unknown`?i(H,{title:u(`customize.picker.devicesFailed`),message:v.reason}):i(gt,{devices:C,listState:b,value:S,selection:`multiple`,groupBy:`location`,onChange:e=>{p(e),w(e,null,null)},noun:`device`,showAll:!0,testId:`helper-member-picker`})]}),E=S.flatMap(e=>{let t=y.compatible.find(t=>t.id===e);return t===void 0?[]:[t]});return i(xr,{step:m,devices:T,values:i(`div`,{className:`flex min-h-0 flex-col gap-3`,children:E.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:u(`helper.pickMembersHint`)}):E.map(e=>i(Ur,{device:e,request:t,members:a,onChoose:t=>w(Kr(S,e.id),e.id,t)},e.id))}),back:S.length===0?null:{label:u(`customize.sourceSelector.backToDevices`),ariaLabel:u(`customize.sourceSelector.backToDevices`)},onBack:()=>h(_r()),done:{countLabel:u(`customize.sourceSelector.pickedCount`,{count:S.length}),label:u(`customize.sourceSelector.done`),disabled:S.length===0},onDone:()=>{let e=gr(S.length);e!==null&&h(e)},fillHeight:l})}function Gr(e){return{id:e.id,name:e.name,type:e.type,location:e.location,parentDeviceId:e.parentDeviceId,addonId:e.addonId,stableId:e.stableId,caps:e.caps}}function Kr(e,t){return e.includes(t)?e:[...e,t]}function qr(e,t){let n=Ve[t]??null;if(n===null)return null;let r=e.caps.find(e=>e.cap===t);return r===void 0?null:r.fields.some(e=>e.path===n)?n:null}function Jr(e,t,n){let r=D[t];if(r===void 0||r!==n)return!1;let i=e.caps.find(e=>e.cap===t);return i===void 0||!i.fields.some(e=>e.path===n)?!1:qr(e,t)!==null}function Yr(e,t){return t===void 0?null:e.find(e=>e.addonId===t.addonId&&e.stableId===t.stableId)??null}function Xr(e,t,n,r,i){let a=e.find(e=>e.addonId===t.addonId&&e.stableId===t.stableId),o=r===`pulse`?Ve[n.cap]:void 0;if(a!==void 0&&a.deviceId===t.id&&a.cap===n.cap&&a.fieldPath===n.path&&(r!==`pulse`||a.changedAtField===o))return null;let s=e.filter(e=>!(e.addonId===t.addonId&&e.stableId===t.stableId)),c={deviceId:t.id,addonId:t.addonId,stableId:t.stableId,cap:n.cap,fieldPath:n.path,deviceName:t.name,mode:a?.mode??i,...o===void 0?{}:{changedAtField:o}};return[...s,c]}function Zr(e){return`${e.addonId}/${e.stableId}/${e.cap}.${e.fieldPath}`}function Qr(e,t){let n=Zr(t);return e.filter(e=>Zr(e)!==n)}function $r(e,t,n){let r=Zr(t);return e.map(e=>Zr(e)===r?{...e,mode:n}:e)}function ei({edges:t,edge:n,onChange:r}){let{t:a}=q();return t.length===0?null:e(`label`,{className:`flex flex-col gap-1 text-[11px] text-foreground`,children:[a(`customize.event.edge`),i(U,{"aria-label":a(`customize.event.edge`),value:n,options:t.map(e=>({value:e,label:a(`customize.event.edgeValue.${e}`)})),onChange:e=>{let n=t.find(t=>t===e.target.value);n!==void 0&&r(n)}})]})}function ti({label:t,value:n,onChange:r}){return e(`label`,{className:`flex flex-col gap-1 text-[11px] text-foreground`,children:[t,i(G,{type:`number`,"aria-label":t,value:Number.isFinite(n)?n:0,onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&t>=0&&r(t)}})]})}function ni(e){return Object.hasOwn(z,e)}function ri(e,t){return ni(e)?z[e].targets.find(e=>e.id===t)??null:null}function ii(e){let t=ri(e.cap,e.targetId);if(t===null)return[];if(t.cardinality===`keyedArray`){let t=e.fieldPath;return t===void 0?[]:En(e.cap,e.targetId).find(e=>e.path===t)?.sources??[]}return t.sources}function ai(e){return{cap:e.cap,path:e.path,kind:e.kind,unit:e.unit}}function oi(e,t){return t.kind===`number`?e.find(e=>e.kind===`numeric`)??null:t.kind===`enum`||t.kind===`string`?e.find(e=>e.kind===`enum`)??null:null}function si(e){return e===`identity`||e===`invert`||e===`threshold`||e===`linear`}function ci(e,t){if(e.requiredUnit!==void 0&&t.unit===null)return{kind:`incompatible`,reason:`unit-unknown`};if(e.requiredUnit!==void 0&&t.unit!==e.requiredUnit)return{kind:`incompatible`,reason:`unit`};if(e.transformKinds.includes(`enum-map`))return{kind:`conversion`,name:`enum-map`};let n=e.transformKinds.filter(si);return n.length===0?{kind:`incompatible`,reason:`kind`}:n.includes(`identity`)?{kind:`direct`}:n.includes(`threshold`)?{kind:`conversion`,name:`threshold`}:n.includes(`linear`)?{kind:`conversion`,name:`scale`}:n.includes(`invert`)?{kind:`conversion`,name:`invert`}:{kind:`incompatible`,reason:`kind`}}function li(e,t){if(e.pickerTargetKind!==void 0){let n=e.pickerTargetKind,r={addonId:`x`,stableId:`y`};return(n===null?{kind:`from`,source:r,cap:t.cap,fieldPath:t.path}:hn(n,{source:r,cap:t.cap,fieldPath:t.path,kind:t.kind}))===null?{kind:`incompatible`,reason:`kind`}:{kind:`direct`}}if(e.acceptAnyField===!0)return t.kind===`enum`?{kind:`incompatible`,reason:`kind`}:{kind:`direct`};let n=ri(e.cap,e.targetId);if(n?.cardinality===`event`&&t.kind===`boolean`&&sr(ii(e),ai(t))!==null)return{kind:`direct`};let r=ii(e);if(r.length===0)return{kind:`incompatible`,reason:`kind`};let i=n?.cardinality===`keyedArray`&&e.fieldPath!==void 0;if(t.kind===`enum`&&!i)return{kind:`incompatible`,reason:`kind`};let a=i?oi(r,t):sr(r,ai(t));return a===null?{kind:`incompatible`,reason:`kind`}:ci(a,t)}function ui(e,t){let n=Te[e];return n===void 0?!1:Object.values(n).includes(t)}function di(){return Object.keys(Te)}function fi(e,t){if(t.kind===`binary`)return e.some(e=>Object.hasOwn(D,e));if(t.kind===`switch`)return e.includes(`switch`);if(t.kind===`numeric`){let n=t.requiredUnit;return n===void 0?e.some(e=>di().includes(e)||e===`numeric-sensor`):n===`W`?e.some(e=>e===`numeric-sensor`||e===`power-meter`||ui(e,n)):e.some(e=>ui(e,n))}return t.kind===`field`?e.some(e=>di().includes(e)||e===`numeric-sensor`||e===`battery`):t.kind===`enum`?e.includes(`consumables`)||e.some(e=>di().includes(e)):!1}function pi(e,t){if(t.pickerTargetKind!==void 0||t.acceptAnyField===!0)return!0;let n=ii(t);return n.length===0?!1:n.some(t=>fi(e.caps,t))}function mi(e,t,n){let r=[],i=[];for(let a of e)a.id!==n&&(pi(a,t)?r.push(a):i.push(a));return{compatible:r,incompatible:i}}function hi(e,t,n){let r=new Map,i=[];for(let a of e){let e=li(t,a),o=Y(a.cap,a.path,n),s={cap:a.cap,path:a.path,label:o,currentText:a.currentText,compatibility:e};if(e.kind===`incompatible`){i.push(s);continue}let c=r.get(a.cap)??[];c.push(s),r.set(a.cap,c)}return{groups:[...r.entries()].toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({cap:e,title:mr(e,n),rows:t.toSorted((e,t)=>e.label.localeCompare(t.label))})),incompatible:i}}function gi(e){return ri(e.cap,e.targetId)?.cardinality===`keyedArray`&&e.fieldPath!==void 0}function _i(e){if(e.pickerTargetKind!==void 0)return[];if(e.acceptAnyField===!0)return di();let t=ii(e),n=new Set;for(let e of t)if(e.kind===`binary`)for(let e of Object.keys(D))n.add(e);else if(e.kind===`switch`)n.add(`switch`);else if(e.kind===`numeric`){n.add(`numeric-sensor`),n.add(`power-meter`);for(let t of di())(e.requiredUnit===void 0||ui(t,e.requiredUnit))&&n.add(t)}else if(e.kind===`field`){n.add(`battery`),n.add(`numeric-sensor`);for(let e of di())n.add(e)}else if(e.kind===`enum`){n.add(`consumables`);for(let e of di())n.add(e)}return[...n]}function vi(e,t,n,r,i){let a=ii(e);if(a.length===0)return[];let o=ir(t,i).filter(e=>e.kind===`boolean`),s=[];for(let e of o){if(sr(a,e)===null||n===`pulse`&&!Jr(t,e.cap,e.path))continue;let o=i===null?void 0:J(i[e.cap],e.path);s.push({cap:e.cap,path:e.path,kind:`boolean`,unit:null,currentText:yn(o,r)})}return s}function yi(e,t,n,r,i,a=null){return a===null?e.pickerTargetKind!==void 0&&i!==null?vn(i,t,r,e.pickerTargetKind).map(e=>({cap:e.cap,path:e.path,kind:e.kind,unit:null,currentText:yn(e.value,n)})):(gi(e)?On(t,r):ir(t,r)).map(e=>{let t=r===null?void 0:J(r[e.cap],e.path);return{cap:e.cap,path:e.path,kind:e.kind,unit:e.unit,currentText:yn(t,n)}}):vi(e,t,a,n,r)}function bi(e,t,n){return n!==null&&e.parentDeviceId===n?0:e.parentDeviceId===t?1:null}function xi(e,t,n){let r=t.find(e=>e.id===n),i=r?.parentDeviceId??null,a=t.find(e=>e.id===(i??n));if(r===void 0||a===void 0)return null;let o=e.flatMap(e=>{let t=bi(e,n,i);return t===null?[]:[{candidate:e,place:t}]}).toSorted((e,t)=>e.place-t.place||e.candidate.name.localeCompare(t.candidate.name));return o.length===0?null:{container:a.name,devices:o.map(e=>e.candidate)}}s();function Si(e,t){return e===`pending`||t.kind===`pending`?`pending`:e===`error`?`failed`:`answered`}function Ci(e,t){return e.map(e=>({id:e.id,name:e.name,type:e.type,location:e.location,parentDeviceId:e.parentDeviceId,addonId:e.addonId,stableId:e.stableId,caps:t.get(e.id)??[]}))}function wi(e,t){return e.kind===`direct`?t(`customize.sourceSelector.direct`):e.kind===`conversion`?t(`customize.sourceSelector.withConversion`,{name:t(`customize.scalar.transform.${Ti(e.name)}`)}):``}function Ti(e){return e===`scale`?`linear`:e===`enum-map`?`enumMap`:e}function Ei(e){return e.kind===`members`?i(Wr,{...e}):i(Di,{...e})}function Di(t){let{t:r,i18n:s}=q(),[l,u]=o(`devices`),[d,p]=o(!1),m=vr(t.device!==null,{seenDevice:d,step:l});m!==null&&(p(m.seenDevice),u(m.step));let[h,g]=o(!1),[_,v]=o(!1),y=Tt({projection:`slim`}),b=t.kind===`formula`?t.deviceFilter:void 0,x=n(()=>{if(y.status!==`success`)return[];let e=gn(y.data);return b===void 0?e:e.filter(b)},[y.status,y.data,b]),S=Sn(n(()=>_i(t.destination),[t.destination]),t.enabled),{compatible:C,incompatible:w}=n(()=>S.kind===`known`?mi(Ci(x,S.value),t.destination,t.hostId):{compatible:[],incompatible:[]},[S,x,t.destination,t.hostId]),T=n(()=>S.kind===`known`?xi(C,Ci(x,S.value),t.hostId):null,[S,C,x,t.hostId]),E=Si(y.status,S),D=t.device?.id??0,O=qt({deviceId:D}),k=Yt({deviceId:t.device===null?0:D}),A=O.status===`success`?O.data:{caps:[]},j=t.kind===`event`?t.shape:null,M=yi(t.destination,A,k.status===`success`,k.status===`success`?k.data:null,t.device,j),N=t.kind===`event`?t.devicePickerTestId:`source-selector-device-picker`,{groups:ee,incompatible:P}=hi(M,t.destination,s.language),F=ki(t,A,k.status===`success`?k.data:null),I=e=>{let n=e[0];if(n===void 0){t.onDeviceChange(null),t.kind!==`event`&&t.onFieldChange(null),u(_r());return}if(t.device?.id!==n){let e=x.find(e=>e.id===n)??null;t.onDeviceChange(e),t.kind!==`event`&&t.onFieldChange(null)}u(hr(`single`))},L=t.kind===`event`?M[0]??null:null,R=t.kind===`event`?t:null;a(()=>{if(R===null||R.device===null||L===null)return;let e=Xr(R.picked,R.device,{cap:L.cap,path:L.path},R.shape,R.sourceModes[0]??`in-addition`);e!==null&&R.onPickedChange(e)},[R,L]);let te=n(()=>Rr(C),[C]),z=e(`div`,{className:`flex max-h-72 min-h-0 flex-col gap-2 overflow-y-auto sm:max-h-[min(24rem,60vh)]`,children:[i(`h3`,{className:`text-[11px] font-medium text-foreground-muted`,children:r(`customize.sourceSelector.pickDevice`,{title:t.destination.title})}),y.status===`error`?i(H,{title:r(`customize.picker.devicesFailed`),message:y.error?.message??``}):e(c,{children:[T!==null&&i(xn,{location:T.container,devices:T.devices.map(e=>({id:e.id,name:e.name,container:null,detail:null})),action:`use`,onPick:e=>I([e])}),i(gt,{devices:te,listState:E,value:t.device===null?[]:[t.device.id],selection:`single`,groupBy:`location`,onChange:I,noun:`device`,showAll:!0,testId:N})]}),w.length>0&&e(`div`,{"data-testid":`source-incompatible-devices`,children:[e(W,{variant:`ghost`,size:`sm`,className:`h-auto w-full justify-start gap-1 px-0 text-[11px] text-foreground-muted`,onClick:()=>g(e=>!e),children:[i(f,{className:`size-3 transition-transform ${h?`rotate-180`:``}`}),r(`customize.sourceSelector.notCompatibleDevices`,{count:w.length})]}),h&&i(`ul`,{className:`mt-1 flex flex-col gap-0.5 pl-4 text-[11px] text-foreground-subtle`,children:w.map(e=>i(`li`,{children:e.name},e.id))})]})]}),ne=t.kind===`event`&&t.picked.length>0?i(`ul`,{"data-testid":`source-picked-list`,className:`flex flex-col gap-2`,children:t.picked.map(n=>e(`li`,{className:`flex flex-col gap-1 text-xs`,children:[e(`span`,{className:`text-foreground`,children:[n.deviceName,` · `,Y(n.cap,n.fieldPath,s.language)]}),t.shape===`span`&&n.mode!==void 0&&i(ur,{mode:n.mode,modes:t.sourceModes,name:n.stableId,onChange:e=>t.onPickedChange($r(t.picked,n,e))}),i(W,{variant:`ghost`,size:`sm`,onClick:()=>t.onPickedChange(Qr(t.picked,n)),children:r(`customize.event.clear`)})]},`${n.addonId}/${n.stableId}/${n.cap}.${n.fieldPath}`))}):null,re=t.kind===`event`?e(`div`,{className:`flex flex-col gap-2`,children:[t.shape===`pulse`&&e(c,{children:[i(ei,{edges:t.edges,edge:t.edge,onChange:t.onEdgeChange}),e(`label`,{className:`flex flex-col gap-1 text-[11px] text-foreground`,children:[r(`customize.event.debounce`),i(G,{type:`number`,"aria-label":r(`customize.event.debounce`),value:Number.isFinite(t.debounceSec)?t.debounceSec:0,onChange:e=>{let n=Number(e.target.value);Number.isFinite(n)&&n>=0&&t.onDebounceSecChange(n)}})]})]}),t.shape===`span`&&e(c,{children:[i(ti,{label:r(`customize.event.timeout`),value:t.timeoutSec,onChange:t.onTimeoutSecChange}),t.cooldownSec!==null&&i(ti,{label:r(`customize.event.cooldown`),value:t.cooldownSec,onChange:t.onCooldownSecChange})]})]}):null;return i(xr,{step:l,devices:z,values:e(`div`,{className:`flex min-h-0 flex-col gap-2`,children:[ne,t.device!==null&&i(kt,{device:t.device,form:`full`,className:`text-[11px] font-medium text-foreground`}),t.device===null?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`customize.sourceSelector.noDevice`)}):O.status===`pending`?i(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:r(`customize.picker.loadingFields`)}):O.status===`error`?i(H,{title:r(`customize.picker.fieldsFailed`),message:O.error?.message??``}):e(`div`,{className:`flex flex-col gap-3`,children:[t.kind===`event`?i(ji,{fields:L===null?[]:[L],language:s.language,emptyLabel:r(`customize.sourceSelector.noStateField`)}):null,t.kind!==`event`&&ee.map(n=>e(`section`,{"aria-label":n.title,children:[i(`h4`,{className:`text-[10px] font-medium uppercase tracking-wide text-foreground-muted`,children:n.title}),i(`ul`,{className:`mt-1 flex flex-col gap-1`,children:n.rows.map(n=>i(`li`,{children:e(`label`,{className:`flex flex-wrap items-center gap-2 text-[11px] text-foreground`,children:[i(`input`,{type:`radio`,name:`source-value`,checked:t.field?.cap===n.cap&&t.field.path===n.path,"data-testid":`source-value-${n.cap}.${n.path}`,onChange:()=>{if(t.onFieldChange({cap:n.cap,path:n.path}),t.kind===`formula`)return;let e=Oi(t,A,k.status===`success`?k.data:null,n.cap,n.path);e!==null&&e.ok&&t.onTransformChange(Pn(e))}}),i(`span`,{children:n.label}),i(`span`,{className:`text-foreground-muted`,children:n.currentText}),i(`span`,{className:`text-foreground-subtle`,children:wi(n.compatibility,r)})]})},`${n.cap}.${n.path}`))})]},n.cap)),t.kind!==`event`&&P.length>0&&e(`div`,{"data-testid":`source-incompatible-values`,children:[e(W,{variant:`ghost`,size:`sm`,className:`h-auto w-full justify-start gap-1 px-0 text-[11px] text-foreground-muted`,onClick:()=>v(e=>!e),children:[i(f,{className:`size-3 transition-transform ${_?`rotate-180`:``}`}),r(`customize.sourceSelector.otherValues`)]}),_&&i(`ul`,{className:`mt-1 flex flex-col gap-1 pl-4 text-[11px] text-foreground-subtle`,children:P.map(t=>e(`li`,{children:[t.label,` · `,t.currentText]},`${t.cap}.${t.path}`))})]})]}),t.kind===`scalar`&&F!==null&&F.ok&&i(zn,{control:Nn(F.transforms),transforms:F.transforms,declared:F.declared,unit:F.sourceUnit,value:t.transform,onChange:t.onTransformChange}),t.kind===`keyed`&&F!==null&&F.ok&&t.field!==null&&i(zn,{control:Nn(F.transforms),transforms:F.transforms,declared:F.declared,unit:F.sourceUnit,value:t.transform,onChange:t.onTransformChange}),re]}),back:t.device===null?null:{label:i(kt,{device:t.device,form:`compact`}),ariaLabel:r(`customize.sourceSelector.backToDevice`,{name:t.device.name})},onBack:()=>u(_r()),done:null,onDone:()=>void 0})}function Oi(e,t,n,r,i){if(e.kind===`keyed`){let a=t.caps.flatMap(e=>e.fields.filter(e=>e.item!==!0).map(t=>({cap:e.cap,path:t.path,kind:t.kind,unit:Ai(n,e.cap),enumValues:t.enumValues??[]}))).find(e=>e.cap===r&&e.path===i);if(a===void 0)return null;let o=jn(e.destination.cap,e.destination.targetId,e.fieldPath,a);return!o.ok||o.mode!==`scalar`?null:o.fit}let a=t.caps.flatMap(e=>e.fields.filter(e=>e.item!==!0).map(t=>({cap:e.cap,path:t.path,kind:t.kind,unit:ar(Ai(n,e.cap),e.cap,t.path)}))).find(e=>e.cap===r&&e.path===i&&(e.kind===`boolean`||e.kind===`number`||e.kind===`string`));if(a===void 0)return null;let o=cr(e.destination.cap,e.destination.targetId,a);return o.ok?o:null}function ki(e,t,n){return e.kind===`formula`||e.kind===`event`||e.device===null||e.field===null?null:Oi(e,t,n,e.field.cap,e.field.path)}function Ai(e,t){if(e===null)return null;let n=e[t]?.unit;return typeof n==`string`&&n.length>0?n:null}function ji({fields:t,language:n,emptyLabel:r}){return t.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:r}):i(`ul`,{className:`flex flex-col gap-1`,children:t.map(t=>e(`li`,{"data-testid":`source-declared-field`,className:`text-[11px] text-foreground`,children:[i(`span`,{className:`font-medium`,children:mr(t.cap,n)}),` · `,Y(t.cap,t.path,n),` `,i(`span`,{className:`text-foreground-muted`,children:t.currentText})]},`${t.cap}.${t.path}`))})}function Mi({id:e,...t}){return i(Mt,{headingId:`customize-${e}`,...t})}function Ni(e,t){if(e.status===`error`)return{kind:`unknown`,reason:e.error?.message??K.t(`helpers.customize.requestFailed`)};let n=e.data;return e.status===`pending`||n===void 0?{kind:`pending`}:{kind:`known`,value:t(n)}}s();function Pi(e,t){let n=Et(e,t);return n.kind===`resolved`?n.integration.name:null}function Fi(e){let t=Tt({projection:`slim`},{enabled:e}),{data:r}=Jt(void 0,{enabled:e}),i=t.error===null||t.error===void 0?null:t.error.message;return n(()=>Ni({status:t.status,data:t.data,error:i===null?null:{message:i}},e=>e.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,type:e.type,location:e.location,isCamera:e.isCamera,integration:Pi(e,r),parentDeviceId:e.parentDeviceId,primaryChildEntityId:e.primaryChildEntityId??null,role:e.role??null}))),[t.status,t.data,i,r])}function Ii(e){let t=e?.trim()??``;return t.length>0?t:K.t(`helpers.customize.requestFailed`)}function Li(e){let t=e.data;if(t!==void 0){if(t.state===`not-loaded`)return{kind:`not-loaded`,reason:t.reason};if(t.view===null)return{kind:`none`};let e=A(t.view.block);return e===null?{kind:`unknown`,reason:K.t(`helpers.customizationRead.notAComposition`,{id:t.view.block.id})}:{kind:`present`,view:t.view,composition:e}}return e.status===`pending`?{kind:`pending`}:e.status===`error`?{kind:`unknown`,reason:Ii(e.error?.message)}:{kind:`pending`}}function Ri(e){return e.kind===`present`?e.composition:null}function zi(e){return Ye.find(t=>t.name===e)}function Bi(e){return e===`lastFetchedAt`||e.endsWith(`At`)}function Vi(e){let t=F(e.role);if(t===null||zi(t)?.status===void 0)return null;let n={};return{target:{kind:`new`,type:e.type,...e.role===null?{}:{role:e.role}},features:[{kind:`fields`,cap:t,fields:n}]}}function Hi(e){return e===null?`incomplete`:Ce(M(e,{lookupCap:P(Ye),sources:new Map,self:null,blockId:null,target:null,peers:[]}).problems)}function Ui(e,t){let n=zi(e);return n?.status===void 0?[]:k(n.status.schema).filter(e=>!Bi(e)&&!t.has(e))}function Wi(e,t,n){let r=e?.features??[],i=r.findIndex(e=>e.cap===n.cap);return{target:e?.target??{kind:`existing`,device:t},features:i===-1?[...r,n]:r.map((e,t)=>t===i?n:e)}}function Gi(e,t,n,r,i){return Wi(e,t,ve(Ji(e,r),n,r,i))}function Ki(e,t,n){let r=R(Ji(e,t),t,n);return r===null?qi(e,t):{target:e.target,features:e.features.map(e=>e.cap===t?r:e)}}function qi(e,t){let n=e.features.filter(e=>e.cap!==t);return n.length===0?null:{target:e.target,features:n}}function Ji(e,t){let n=e?.features.find(e=>e.cap===t);return n!==void 0&&n.kind===`fields`?n:null}function Yi(e){return Array.isArray(e)?e.map(Yi):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,Yi(t)]))}function Xi(e){return JSON.stringify(Yi(e))}function Zi(e,t){switch(e.kind){case`pending`:return{kind:`refused`,reason:K.t(`helpers.customizationSave.notReadYet`)};case`unknown`:return{kind:`refused`,reason:`the customization could not be read: ${e.reason}`};case`not-loaded`:return{kind:`refused`,reason:`the customizations are not loaded yet: ${e.reason}`};case`none`:return t===null?{kind:`noop`}:{kind:`create`,input:{enabled:!0,composition:t}};case`present`:{let n=e.view.block.id;return t===null?{kind:`delete`,blockId:n}:Xi(t)===Xi(e.composition)?{kind:`noop`}:{kind:`update`,blockId:n,expectedUpdatedAt:e.view.block.updatedAt,composition:t}}}}function Qi(){let{t:e}=q(),t=C();return(n,r)=>t({title:e(`customize.assign.removeConfirm.title`),message:r?`${e(`customize.assign.removeConfirm.message`,{what:n})} ${e(`customize.assign.removeConfirm.last`)}`:e(`customize.assign.removeConfirm.message`,{what:n}),confirmLabel:e(`customize.assign.removeConfirm.confirm`),variant:`danger`})}function $i(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ea(e,t){let n=J(e,t);return n===void 0?{kind:`absent`}:t===`level`&&e.binary===!0?{kind:`value`,value:n,binary:!0}:{kind:`value`,value:n}}function ta(e,t,n){return $i(t)?ea(t,n):e.status===`error`?{kind:`unknown`,reason:e.error?.message??K.t(`helpers.liveValue.unreadable`)}:e.status===`pending`||e.data===void 0?{kind:`pending`}:e.data===null?{kind:`absent`}:ea(e.data,n)}function na(e,t,n){if(t.binary===!0&&n.cap===`battery`&&n.path===`level`){let t=Pt(e);return{text:K.t(t?on:_t),tone:t?`warning`:`normal`}}return{text:n.path===`level`?`${Math.round(e)} %`:String(e),tone:`normal`}}function ra(e,t,n){let r=e?`active`:`muted`;return t.cap===`contact`&&t.path===`entryOpen`?{text:e?n.open:n.closed,tone:r}:D[t.cap]===t.path?{text:e?n.active:n.inactive,tone:r}:{text:String(e),tone:`normal`}}function ia(e,t,n){switch(e.kind){case`pending`:return{text:`…`,tone:`muted`};case`unknown`:return{text:`?`,title:e.reason,tone:`warning`};case`absent`:return{text:`—`,tone:`muted`};case`value`:{let r=e.value;return r===null?{text:`—`,tone:`muted`}:typeof r==`boolean`?ra(r,t,n):typeof r==`number`?na(r,e,t):typeof r==`string`?{text:r,tone:`normal`}:{text:JSON.stringify(r),tone:`normal`}}}}var aa=0;function oa(e){let t=y(),n=Ht({deviceId:e?.deviceId??aa,capName:e?.cap??``},{enabled:e!==null}),r=tn(t.trpcClient,e?.deviceId??null,e?.cap??``);return e===null?{kind:`absent`}:ta({status:n.status,data:n.data,error:n.error===null||n.error===void 0?null:{message:n.error.message}},r,e.path)}var sa={muted:`text-foreground-subtle`,active:`text-success`,normal:`text-foreground`,warning:`text-warning`};function ca({target:e}){let{t}=q(),n=oa(e);return e===null?null:i(la,{display:ia(n,e,{active:t(`customize.assign.value.active`),inactive:t(`customize.assign.value.inactive`),open:t(`customize.assign.value.open`),closed:t(`customize.assign.value.closed`)})})}function la({display:e}){return i(`span`,{className:`text-xs ${sa[e.tone]}`,title:e.title,children:e.text})}function ua(e){return e===`avg-round-1`?`customize.fieldsCard.aggregate.avg`:`customize.fieldsCard.aggregate.latest`}function da(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function fa(e,t,n){let r=RegExp(`(?<![A-Za-z0-9_])${da(t)}(?![A-Za-z0-9_])`,`g`);return e.replace(r,()=>n)}function pa(e,t,n,r,i){let a=Object.keys(t).toSorted((e,t)=>t.length-e.length),o=e;for(let e of a){let a=t[e];if(a===void 0||a.kind!==`from`)continue;let s=n.get(V(a.source))??i,c=Y(a.cap,a.fieldPath,r);o=fa(o,e,`${s} · ${c}`)}return Ca(o)}var ma=1e3,ha=60*ma,ga=60*ha,_a={within:[1],dwell:[1,2],rose:[2]};function va(e){if(!Number.isInteger(e)||e<ma)return null;if(e%ga===0){let t=e/ga;return t===1?`1 h`:`${t} h`}if(e%ha===0){let t=e/ha;return t===1?`1 min`:`${t} min`}if(e%ma===0){let t=e/ma;return t===1?`1 s`:`${t} s`}return null}function ya(e){return/^\d+$/.test(e.trim())?va(Number(e.trim())):null}function ba(e,t){let n=1,r=t+1,i=null,a=[];for(let o=t+1;o<e.length;o+=1){let t=e[o]??``;if(i!==null){if(t===`\\`){o+=1;continue}t===i&&(i=null);continue}if(t===`"`||t===`'`){i=t;continue}if(t===`(`){n+=1;continue}if(t===`)`){if(--n,n===0){let t=e.slice(r,o);return a.length===0&&t.trim()===``||a.push({text:t}),{args:a,close:o}}continue}t===`,`&&n===1&&(a.push({text:e.slice(r,o)}),r=o+1)}return null}function xa(e,t){let n=e[t-1];if(n!==void 0&&/[A-Za-z0-9_]/.test(n))return null;for(let n of Object.keys(_a)){if(!e.startsWith(n,t))continue;let r=t+n.length,i=e[r];if(i!==void 0&&/[A-Za-z0-9_]/.test(i))continue;let a=r;for(;e[a]===` `||e[a]===`
|
|
1
|
+
import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,et as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Di as l,Fn as u,Ji as d,Oi as f,Pr as p,T as m,V as h,Vt as g,Wn as _,ca as v,dt as y,er as b,gt as x,ht as S,st as C}from"./player-overlays-C_WpL6a6.js";import{$i as w,$n as T,$t as E,Aa as D,An as O,Bi as k,Ci as A,Da as j,Di as M,Dn as N,Ea as ee,Ei as P,En as F,Fa as I,Fi as L,Fn as R,Gn as te,Hn as z,Ii as ne,In as re,Ji as ie,Jn as ae,Ki as oe,Kn as se,Kt as ce,Li as le,Ln as ue,Mi as de,Mn as fe,Ni as pe,Nn as me,Oa as he,Oi as ge,On as _e,Pi as B,Pn as ve,Qi as ye,Qn as be,Ri as xe,Rn as Se,Tn as Ce,Ui as we,Un as Te,Wi as Ee,Wn as De,Xi as Oe,Xn as ke,Yi as V,Yn as Ae,Zi as je,Zn as Me,aa as Ne,ca as Pe,da as Fe,ea as Ie,en as Le,er as Re,gn as ze,ia as Be,ja as Ve,ji as He,jn as Ue,ka as We,kn as Ge,la as Ke,lr as qe,na as Je,nn as Ye,oa as Xe,qi as Ze,qn as Qe,sa as $e,sr as et,ta as tt,ua as nt,zi as rt}from"./client-Clemlz5W.js";import{c as it,d as at,f as ot,i as st,l as ct,o as lt}from"./__vite-browser-external-BCAtXlNQ.js";import{i as ut,n as dt,r as ft,t as pt}from"./sigma-q5eaqxJ5.js";import{t as mt}from"./boxes-BYgmIZEw.js";import{n as ht}from"./video-DgFhEP51.js";import{Ar as H,B as gt,Bn as _t,Br as vt,Ed as U,Fr as yt,Gr as bt,Ir as xt,Jn as St,Lr as Ct,Md as wt,Mo as Tt,Nt as Et,Pr as Dt,Qa as Ot,Rr as kt,Sr as At,St as jt,Tn as Mt,Ur as Nt,Vn as Pt,Vr as Ft,Wa as It,Xo as Lt,Yd as Rt,_r as zt,br as Bt,ci as Vt,cs as Ht,di as Ut,ei as W,fi as Wt,gr as Gt,hi as Kt,jd as G,jo as qt,js as Jt,ls as Yt,mi as Xt,nf as Zt,pi as Qt,qd as $t,qn as en,s as tn,ui as nn,vr as rn,xr as an,zn as on,zr as sn}from"./src-BuD4BDe3.js";import{t as K}from"./i18n-COiZcYwm.js";import{t as q}from"./useTranslation-BJr-n0es.js";import{h as cn,mr as ln,pr as un}from"./index-B0SLrMzs.js";import{t as dn}from"./use-device-bound-caps-Di0CbhM4.js";import{n as fn,r as pn,t as mn}from"./assignment-candidates-DRst7VCd.js";s();function hn(e,t){let n=e===`enum`?`string`:e,r=t.kind===`enum`?`string`:t.kind,i={source:t.source,cap:t.cap,fieldPath:t.fieldPath};return r===n?{kind:`from`,...i}:n===`number`&&r===`string`?{kind:`expression`,expr:`number(x)`,bindings:{x:{kind:`from`,...i}}}:null}function gn(e){return e.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,location:e.location,type:e.type,parentDeviceId:e.parentDeviceId}))}function J(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n||Array.isArray(n))return;n=Object.getOwnPropertyDescriptor(n,e)?.value}return n}function _n(e,t,n,r){return r===null?{kind:`from`,source:e,cap:t,fieldPath:n.path}:hn(r,{source:e,cap:t,fieldPath:n.path,kind:n.kind})}function vn(e,t,n,r){let i={addonId:e.addonId,stableId:e.stableId};return t.caps.flatMap(e=>e.fields.filter(e=>e.item!==!0).map(t=>({cap:e.cap,path:t.path,kind:t.kind,value:n===null?void 0:J(n[e.cap],t.path),source:_n(i,e.cap,t,r)})))}function yn(e,t){return t?e===void 0?`—`:e===null?`null`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e):`…`}function bn({device:t,action:n,onPick:r}){let{t:a}=q(),o=Ft(t.id,`compact`,t.name),s=[t.container===null||o.includes(t.container)?null:a(`customize.suggest.in`,{container:t.container}),t.detail].filter(e=>e!==null&&e!==``).join(` · `);return e(`li`,{className:`${m} flex items-center gap-3`,children:[e(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`text-xs text-foreground break-words`,children:o}),s!==``&&i(`div`,{className:`text-[11px] text-foreground-subtle break-words`,children:s})]}),i(W,{variant:`outline`,size:`sm`,"aria-label":a(n===`add`?`customize.suggest.addNamed`:`customize.suggest.useNamed`,{name:o}),onClick:()=>r(t.id),children:a(n===`add`?`customize.suggest.add`:`customize.suggest.use`)})]})}function xn({location:t,devices:n,action:r,onPick:a,onPickAll:o}){let{t:s}=q();if(n.length===0)return null;let c=s(`customize.suggest.heading`,{location:t});return e(`section`,{"aria-label":c,className:`flex flex-col gap-1`,children:[e(`div`,{className:`flex min-h-7 items-center gap-2`,children:[i(`h3`,{className:`${h} min-w-0 flex-1`,children:c}),o!==void 0&&n.length>1&&i(W,{variant:`ghost`,size:`sm`,onClick:o,children:s(`customize.suggest.addAll`,{count:n.length})})]}),i(`ul`,{className:`flex flex-col divide-y divide-border rounded-md border border-border`,children:n.map(e=>i(bn,{device:e,action:r,onPick:a},e.id))})]})}function Sn(e,t){let n=Zt.useQueries(n=>e.map(e=>n.deviceManager.listDeviceIdsByCaps({capNames:[e]},{enabled:t})));return fn(e.map((e,t)=>{let r=n[t];return{cap:e,query:r===void 0?{status:`pending`}:{status:r.status,data:r.data,error:r.error===null?null:{message:r.error.message}}}}))}function Cn(e){return e===`identity`||e===`invert`||e===`threshold`||e===`linear`}function wn(e){return Object.hasOwn(z,e)}function Tn(e){return wn(e)?z[e].targets:[]}function En(e,t){let n=Tn(e).find(e=>e.id===t);return n?.cardinality===`keyedArray`?n.fields??[]:[]}function Dn(e,t){return Tn(e).find(e=>e.id===t)?.traits??[]}function On(e,t){return e.caps.flatMap(e=>{let n=kn(t,e.cap);return e.fields.filter(e=>e.item!==!0).map(t=>({cap:e.cap,path:t.path,kind:t.kind,unit:n,enumValues:t.enumValues??[]}))})}function kn(e,t){if(e===null)return null;let n=J(e[t],`unit`);return typeof n==`string`&&n.length>0?n:null}function An(e,t){return t.kind===`number`?e.find(e=>e.kind===`numeric`)??null:t.kind===`enum`||t.kind===`string`?e.find(e=>e.kind===`enum`)??null:null}function jn(e,t,n,r){let i=En(e,t).find(e=>e.path===n);if(i===void 0)return{ok:!1,reason:`kind`};let a=An(i.sources,r);if(a===null)return{ok:!1,reason:`kind`};if(a.requiredUnit!==void 0&&r.unit===null)return{ok:!1,reason:`unit-unknown`};if(a.requiredUnit!==void 0&&r.unit!==a.requiredUnit)return{ok:!1,reason:`unit`};if(a.transformKinds.includes(`enum-map`))return{ok:!0,mode:`enum`};let o=a.transformKinds.filter(Cn);return o.length===0||r.kind!==`number`?{ok:!1,reason:`kind`}:{ok:!0,mode:`scalar`,fit:{ok:!0,valueKind:`number`,sourceUnit:a.requiredUnit??null,transforms:o,declared:a.transforms}}}function Mn(e,t,n){return En(e,t).find(e=>e.path===n)?.enumValues??[]}function Nn(e){return e.length===1&&e[0]===`threshold`?`threshold`:e.length===1&&e[0]===`invert`||e.includes(`invert`)&&e.every(e=>e===`identity`||e===`invert`)?`invert`:e.length>1?`choice`:`none`}function Pn(e){if(e.transforms.includes(`identity`))return{kind:`identity`};if(e.transforms.includes(`threshold`)){let t=In(e.declared,`threshold`);if(t!==null)return Fn(t)}if(e.transforms.includes(`linear`)){let t=In(e.declared,`linear`);if(t!==null)return Fn(t)}return{kind:`invert`}}function Fn(e){switch(e.kind){case`identity`:return{kind:`identity`};case`invert`:return{kind:`invert`};case`threshold`:return{kind:`threshold`,comparison:e.comparison,threshold:e.defaultThreshold,startDwellMs:e.defaultStartDwellMs,stopDwellMs:e.defaultStopDwellMs};case`linear`:return Ln(e);case`enum-map`:return{kind:`identity`}}}function In(e,t){return e.find(e=>e.kind===t)??null}function Ln(e){return{kind:`linear`,scale:e.defaultScale,offset:e.defaultOffset,...e.clampMin!==void 0&&e.clampMax!==void 0?{clampMin:e.clampMin,clampMax:e.clampMax}:{}}}function Rn(e){let t=Se({draft:{kind:`scalar`,cap:e.cap,targetId:e.targetId,source:{addonId:e.source.addonId,stableId:e.source.stableId,cap:e.source.cap,fieldPath:e.source.fieldPath},transform:e.transform},device:e.device,apply:e.apply,sourceValueKind:e.source.valueKind,changedAtField:e.source.changedAtField,sourceUnit:e.source.sourceUnit});return t.ok?t.value:null}function zn({control:t,transforms:n,declared:r,unit:a,value:o,onChange:s}){let{t:c}=q();return t===`none`?null:e(`div`,{className:`flex flex-col gap-2`,children:[i(`h3`,{className:`text-[11px] font-medium text-foreground-muted`,children:c(`customize.scalar.stepTransform`)}),t===`choice`&&i(U,{"aria-label":c(`customize.scalar.stepTransform`),value:o.kind,options:n.map(e=>({value:e,label:c(`customize.scalar.transform.${e}`)})),onChange:e=>s(Bn(e.target.value,r))}),o.kind===`invert`||t===`invert`&&o.kind!==`threshold`?e(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground`,children:[i(St,{checked:o.kind===`invert`,onChange:e=>s(e.target.checked?{kind:`invert`}:{kind:`identity`})}),c(`customize.scalar.invert`)]}):null,o.kind===`threshold`&&i(Hn,{declared:r,unit:a,value:o,onChange:s}),o.kind===`linear`&&i(Wn,{declared:r,value:o,onChange:s})]})}function Bn(e,t){let n=In(t,Vn(e));return n===null?e===`invert`?{kind:`invert`}:{kind:`identity`}:Fn(n)}function Vn(e){return e===`invert`||e===`threshold`||e===`linear`||e===`enum-map`?e:`identity`}function Hn({declared:t,unit:n,value:r,onChange:a}){let{t:o}=q(),s=n??``,c=In(t,`threshold`),l=c?.kind===`threshold`?c.comparisons:[];return e(`div`,{className:`flex flex-col gap-2 text-[11px] text-foreground`,children:[l.length>0&&e(`label`,{className:`flex flex-col gap-1`,children:[o(`customize.scalar.comparison`),i(U,{"aria-label":o(`customize.scalar.comparison`),value:r.comparison,options:l.map(e=>({value:e,label:o(`customize.scalar.comparisonValue.${e}`)})),onChange:e=>{let t=l.find(t=>t===e.target.value);t!==void 0&&a({...r,comparison:t})}})]}),i(Gn,{label:o(`customize.scalar.threshold`,{unit:s}),value:r.threshold,onChange:e=>a({...r,threshold:e})}),i(Gn,{label:o(`customize.scalar.startDwell`),value:r.startDwellMs/1e3,onChange:e=>a({...r,startDwellMs:e*1e3})}),i(Gn,{label:o(`customize.scalar.stopDwell`),value:r.stopDwellMs/1e3,onChange:e=>a({...r,stopDwellMs:e*1e3})})]})}function Un(e){return e===null||e.kind!==`linear`||e.clampMin===void 0||e.clampMax===void 0?null:{min:e.clampMin,max:e.clampMax}}function Wn({declared:t,value:n,onChange:r}){let{t:a}=q(),o=Un(In(t,`linear`));return e(`div`,{className:`flex flex-col gap-2 text-[11px] text-foreground`,children:[i(Gn,{label:a(`customize.scalar.scale`),value:n.scale,onChange:e=>r({...n,scale:e})}),i(Gn,{label:a(`customize.scalar.offset`),value:n.offset,onChange:e=>r({...n,offset:e})}),o!==null&&i(Gn,{label:a(`customize.scalar.clampMin`),value:n.clampMin??o.min,onChange:e=>r({...n,clampMin:e,clampMax:n.clampMax??o.max})}),o!==null&&i(Gn,{label:a(`customize.scalar.clampMax`),value:n.clampMax??o.max,onChange:e=>r({...n,clampMin:n.clampMin??o.min,clampMax:e})})]})}function Gn({label:t,value:n,onChange:r}){return e(`label`,{className:`flex flex-col gap-1`,children:[t,i(G,{type:`number`,value:Number.isFinite(n)?n:0,onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&r(t)}})]})}var Kn=`kind`,qn=`unit`,Jn=`unit-unknown`,Yn=`compile`,Xn=`dwell`,Zn=`no-value`,Qn=`empty`;function $n(e){return`customize.scalar.previewFailure.${e}`}function er(e){return e===`compile`||e===`dwell`||e===`no-value`||e===`empty`}function tr(e){return e===`identity`||e===`invert`||e===`threshold`||e===`linear`}function nr(e,t){let n=Object.entries(z).find(([t])=>t===e)?.[1];return n===void 0?null:n.targets.find(e=>e.id===t)??null}function rr(e,t){return nr(e,t)?.path??null}function ir(e,t){return e.caps.flatMap(e=>{let n=or(t,e.cap);return e.fields.filter(e=>e.item!==!0).map(t=>({cap:e.cap,path:t.path,kind:t.kind,unit:ar(n,e.cap,t.path)}))})}function ar(e,t,n){return e??Le(t,n)??null}function or(e,t){if(e===null)return null;let n=J(e[t],`unit`);return typeof n==`string`&&n.length>0?n:null}function sr(e,t){if(t.kind===`boolean`){let n=D[t.cap];return n===void 0||n!==t.path?null:t.cap===`switch`?e.find(e=>e.kind===`switch`)??e.find(e=>e.kind===`binary`)??null:e.find(e=>e.kind===`binary`)??e.find(e=>e.kind===`field`&&e.valueKinds?.includes(`boolean`))??null}return t.kind===`number`?e.find(e=>e.kind===`numeric`)??e.find(e=>e.kind===`field`&&e.valueKinds?.includes(`number`))??null:t.kind===`string`?e.find(e=>e.kind===`field`&&e.valueKinds?.includes(`string`))??null:null}function cr(e,t,n){let r=nr(e,t);if(r===null||r.cardinality!==`scalar`||n.kind===`enum`)return{ok:!1,reason:Kn};let i=sr(r.sources,n);if(i===null)return{ok:!1,reason:Kn};if(i.requiredUnit!==void 0&&n.unit===null)return{ok:!1,reason:Jn};if(i.requiredUnit!==void 0&&n.unit!==i.requiredUnit)return{ok:!1,reason:qn};let a=i.transformKinds.filter(tr);return a.length===0?{ok:!1,reason:Kn}:{ok:!0,valueKind:n.kind,sourceUnit:i.requiredUnit??null,transforms:a,declared:i.transforms}}function lr(e,t){return t.find(t=>t===e)??null}function ur({mode:t,modes:n,name:r,onChange:a}){let{t:o}=q();return n.length===0?null:e(`div`,{className:`flex flex-col gap-1`,children:[i(U,{"aria-label":o(`customize.motion.modeFor`,{name:r}),value:t,options:n.map(e=>({value:e,label:o(`customize.motion.mode.${e}`)})),onChange:e=>{let t=lr(e.target.value,n);t!==null&&a(t)}}),i(`p`,{className:`text-[11px] text-foreground-muted`,children:o(`customize.motion.modeLine.${t}`)})]})}var dr={lastChangedAt:{en:`Last change`,it:`Ultima variazione`},lastFetchedAt:{en:`Last update`,it:`Ultimo aggiornamento`},lastDetectedAt:{en:`Last detection`,it:`Ultimo rilevamento`},lastPressedAt:{en:`Last press`,it:`Ultima pressione`},pressCountSinceStart:{en:`Press count`,it:`Conteggio pressioni`},since:{en:`Since`,it:`Da`}};function fr(e,t){return t.startsWith(`it`)?e.it:e.en}function pr(e){if(!(`unit`in e))return;let t=e.unit;return typeof t==`string`&&t.length>0?t:void 0}function mr(e,t){let n=ze[e]?.noun;return n===void 0?e.split(`-`).filter(e=>e.length>0).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `):fr(n,t)}function Y(e,t,n){let r=ze[e]?.state?.find(e=>e.field===t);if(r!==void 0){let e=fr(r.label,n),t=pr(r);return t===void 0?e:`${e} (${t})`}let i=dr[t];return i===void 0?t:fr(i,n)}function hr(e){return e===`single`?`values`:`devices`}function gr(e){return e<=0?null:`values`}function _r(){return`devices`}function vr(e,t){return!e&&(t.seenDevice||t.step!==`devices`)?{seenDevice:!1,step:`devices`}:e&&!t.seenDevice?{seenDevice:!0,step:`values`}:null}function yr(e,t){return e===t}function br(e,t,n){let r=yr(e,t);return n?r?`flex min-h-0 flex-col`:`hidden min-h-0 flex-col sm:flex`:r?void 0:`hidden sm:block`}function xr({step:t,devices:n,values:r,back:a,onBack:o,done:s,onDone:c,fillHeight:u=!1}){return e(`div`,{"data-testid":`source-selector`,"data-step":t,className:u?`flex min-h-0 flex-1 flex-col gap-3 sm:grid sm:grid-cols-2 sm:grid-rows-[minmax(0,1fr)] sm:gap-4`:`flex flex-col gap-3 sm:grid sm:grid-cols-2 sm:gap-4`,children:[e(`div`,{"data-testid":`source-selector-devices`,className:br(t,`devices`,u),children:[s!==null&&e(`div`,{className:`mb-2 flex items-center justify-between gap-2 sm:hidden`,children:[i(`p`,{"data-testid":`source-selector-picked-count`,className:`text-[11px] text-foreground-muted`,children:s.countLabel}),i(W,{size:`sm`,"data-testid":`source-selector-done`,disabled:s.disabled,onClick:c,children:s.label})]}),n]}),e(`div`,{"data-testid":`source-selector-values`,className:br(t,`values`,u),children:[a!==null&&e(W,{variant:`ghost`,size:`sm`,className:`mb-2 sm:hidden`,"data-testid":`source-selector-back`,"aria-label":a.ariaLabel,onClick:o,children:[i(l,{className:`size-3`}),a.label]}),u?i(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:r}):r]})]})}function Sr(e){return[...new Set(e.accept.map(e=>e.cap))]}function Cr(e,t){let n=new Set(Sr(t)),r=new Set(t.exclude.map(e=>`${e.addonId}/${e.stableId}`)),i=[],a=[];for(let o of e)r.has(`${o.addonId}/${o.stableId}`)||(Nr(o.type,t.deviceTypes)&&o.caps.some(e=>n.has(e))?i.push(o):a.push(o));return{compatible:i,incompatible:a}}function wr(e,t){return e.filter(e=>kr(t,e)&&Ar(t,e))}function Tr(e,t){return t.history.required?e.filter(e=>kr(t,e)&&!jr(e)):[]}function Er(e,t){return e.flatMap(e=>{let n=t.find(t=>t.addonId===e.source.addonId&&t.stableId===e.source.stableId);return n===void 0?[]:[n.id]})}function Dr(e){if(e.selectedIds.length>e.request.max)return{members:e.previous.map(Fr),refused:`max`,needsField:[]};let t=[];return{members:e.selectedIds.flatMap(n=>{let r=e.devices.find(e=>e.id===n);if(r===void 0)return[];let i=Or(r,e);return i===null?(t.push(n),[]):[Pr(r,i.cap,i.fieldPath)]}),refused:null,needsField:t}}function Or(e,t){if(t.choiceDeviceId===e.id&&t.choice!==null&&Mr(t.request,t.choice))return t.choice;let n=t.previous.find(t=>t.source.addonId===e.addonId&&t.source.stableId===e.stableId);if(n!==void 0&&Mr(t.request,n))return n;let r=t.request.fieldChoice===`first-match`?t.request.accept.filter(t=>e.caps.includes(t.cap)):t.request.accept,i=t.request.fieldChoice===`first-match`||r.length===1?r[0]:void 0;return i===void 0?null:{cap:i.cap,fieldPath:i.fieldPath}}function kr(e,t){return e.accept.some(e=>e.cap===t.cap&&e.fieldPath===t.fieldPath&&e.valueKind===t.kind)}function Ar(e,t){return!e.history.required||jr(t)}function jr(e){return He(e.cap)[e.fieldPath]!==void 0}function Mr(e,t){return e.accept.some(e=>e.cap===t.cap&&e.fieldPath===t.fieldPath)}function Nr(e,t){return t.length===0?!0:t.some(t=>t===e)}function Pr(e,t,n){return{source:{addonId:e.addonId,stableId:e.stableId},cap:t,fieldPath:n}}function Fr(e){return{source:{addonId:e.source.addonId,stableId:e.source.stableId},cap:e.cap,fieldPath:e.fieldPath}}function Ir(e){return{id:e.id,name:e.name,type:e.type,stableId:e.stableId,parentDeviceId:e.parentDeviceId??null,...e.location!==void 0&&e.location!==null?{location:e.location}:{},...e.role!==void 0&&e.role!==null?{role:e.role}:{},...e.primaryChildEntityId!==void 0&&e.primaryChildEntityId!==null?{primaryChildEntityId:e.primaryChildEntityId}:{}}}function Lr(e,t,n=Nt(`en`)){return sn(e,`compact`,bt(t),n)}function Rr(e){return e.map(e=>({id:e.id,name:e.name,type:e.type,parentDeviceId:e.parentDeviceId,...e.location===null?{}:{location:e.location}}))}function zr(e,t){return e===`pending`||t.kind===`pending`?`pending`:e===`error`||t.kind===`unknown`?`failed`:`answered`}function Br(e,t){return e.map(e=>({id:e.id,name:e.name,type:e.type,location:e.location,parentDeviceId:e.parentDeviceId,addonId:e.addonId,stableId:e.stableId,caps:t.get(e.id)??[]}))}function Vr(e){return e.caps.flatMap(e=>e.fields.flatMap(t=>t.item===!0?[]:[{cap:e.cap,fieldPath:t.path,kind:t.kind}]))}function Hr(e,t,n){return t?e==null?n:yn(e,!0):`…`}function Ur({device:t,request:n,members:r,onChoose:a}){let{t:o,i18n:s}=q(),c=qt({deviceId:t.id}),l=Yt({deviceId:t.id}),u=c.status===`success`?c.data:{caps:[]},d=wr(Vr(u),n),f=Tr(Vr(u),n),p=`helper-member-value-${t.id}`;return e(`section`,{className:`flex flex-col gap-1`,"data-testid":`helper-member-section-${t.id}`,children:[i(`h3`,{className:`text-[11px] font-medium text-foreground`,children:i(kt,{device:t,form:`compact`})}),c.status===`pending`||l.status===`pending`?i(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:o(`customize.picker.loadingFields`)}):c.status===`error`?i(H,{title:o(`customize.picker.fieldsFailed`),message:c.error?.message??``}):d.length===0?i(`p`,{className:`text-[11px] text-foreground-muted`,children:o(`helper.noUsableValue`)}):i(`ul`,{className:`flex flex-col gap-1`,children:d.map(n=>{let c=r.some(e=>e.source.addonId===t.addonId&&e.source.stableId===t.stableId&&e.cap===n.cap&&e.fieldPath===n.fieldPath),u=l.status===`success`?J(l.data[n.cap],n.fieldPath):void 0;return i(`li`,{children:e(`label`,{className:`flex flex-wrap items-center gap-2 text-[11px] text-foreground`,children:[i(`input`,{type:`radio`,name:p,checked:c,"data-testid":`helper-value-${t.id}-${n.cap}.${n.fieldPath}`,onChange:()=>a(n)}),i(`span`,{children:Y(n.cap,n.fieldPath,s.language)}),i(`span`,{className:`text-foreground-muted`,children:Hr(u,l.status===`success`,o(`helper.valueUnknown`))})]})},`${n.cap}.${n.fieldPath}`)})}),f.length>0&&i(`p`,{className:`text-[11px] text-foreground-muted`,"data-testid":`helper-no-history`,children:o(`helper.noHistory`)})]})}function Wr({request:t,enabled:r,members:a,onMembersChange:s,onRefuse:c,fillHeight:l=!1}){let{t:u,i18n:d}=q(),[f,p]=o([]),[m,h]=o(`devices`),g=Tt({projection:`slim`}),_=n(()=>g.status===`success`?gn(g.data):[],[g.status,g.data]),v=Sn(n(()=>Sr(t),[t]),r),y=n(()=>v.kind===`known`?Cr(Br(_,v.value),t):{compatible:[],incompatible:[]},[v,_,t]),b=zr(g.status,v),x=Er(a,y.compatible),S=[...f,...x.filter(e=>!f.includes(e))].filter(e=>y.compatible.some(t=>t.id===e)),C=n(()=>Rr(y.compatible.map(Gr)),[y.compatible]),w=(e,n,r)=>{if(v.kind!==`known`)return;let i=Dr({request:t,devices:y.compatible,selectedIds:e,previous:a,choiceDeviceId:n,choice:r});if(i.refused===`max`){c({code:`max`,max:t.max});return}c(null),s(i.members)},T=e(`div`,{className:l?`flex min-h-0 flex-1 flex-col gap-2 overflow-y-auto`:`flex max-h-72 min-h-0 flex-col gap-2 overflow-y-auto sm:max-h-[min(24rem,60vh)]`,children:[i(`h3`,{className:`text-[11px] font-medium text-foreground-muted`,children:u(`helper.pickMembers`)}),g.status===`error`?i(H,{title:u(`customize.picker.devicesFailed`),message:g.error?.message??``}):v.kind===`unknown`?i(H,{title:u(`customize.picker.devicesFailed`),message:v.reason}):i(gt,{devices:C,listState:b,value:S,selection:`multiple`,groupBy:`location`,onChange:e=>{p(e),w(e,null,null)},noun:`device`,showAll:!0,testId:`helper-member-picker`})]}),E=S.flatMap(e=>{let t=y.compatible.find(t=>t.id===e);return t===void 0?[]:[t]});return i(xr,{step:m,devices:T,values:i(`div`,{className:`flex min-h-0 flex-col gap-3`,children:E.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:u(`helper.pickMembersHint`)}):E.map(e=>i(Ur,{device:e,request:t,members:a,onChoose:t=>w(Kr(S,e.id),e.id,t)},e.id))}),back:S.length===0?null:{label:u(`customize.sourceSelector.backToDevices`),ariaLabel:u(`customize.sourceSelector.backToDevices`)},onBack:()=>h(_r()),done:{countLabel:u(`customize.sourceSelector.pickedCount`,{count:S.length}),label:u(`customize.sourceSelector.done`),disabled:S.length===0},onDone:()=>{let e=gr(S.length);e!==null&&h(e)},fillHeight:l})}function Gr(e){return{id:e.id,name:e.name,type:e.type,location:e.location,parentDeviceId:e.parentDeviceId,addonId:e.addonId,stableId:e.stableId,caps:e.caps}}function Kr(e,t){return e.includes(t)?e:[...e,t]}function qr(e,t){let n=Ve[t]??null;if(n===null)return null;let r=e.caps.find(e=>e.cap===t);return r===void 0?null:r.fields.some(e=>e.path===n)?n:null}function Jr(e,t,n){let r=D[t];if(r===void 0||r!==n)return!1;let i=e.caps.find(e=>e.cap===t);return i===void 0||!i.fields.some(e=>e.path===n)?!1:qr(e,t)!==null}function Yr(e,t){return t===void 0?null:e.find(e=>e.addonId===t.addonId&&e.stableId===t.stableId)??null}function Xr(e,t,n,r,i){let a=e.find(e=>e.addonId===t.addonId&&e.stableId===t.stableId),o=r===`pulse`?Ve[n.cap]:void 0;if(a!==void 0&&a.deviceId===t.id&&a.cap===n.cap&&a.fieldPath===n.path&&(r!==`pulse`||a.changedAtField===o))return null;let s=e.filter(e=>!(e.addonId===t.addonId&&e.stableId===t.stableId)),c={deviceId:t.id,addonId:t.addonId,stableId:t.stableId,cap:n.cap,fieldPath:n.path,deviceName:t.name,mode:a?.mode??i,...o===void 0?{}:{changedAtField:o}};return[...s,c]}function Zr(e){return`${e.addonId}/${e.stableId}/${e.cap}.${e.fieldPath}`}function Qr(e,t){let n=Zr(t);return e.filter(e=>Zr(e)!==n)}function $r(e,t,n){let r=Zr(t);return e.map(e=>Zr(e)===r?{...e,mode:n}:e)}function ei({edges:t,edge:n,onChange:r}){let{t:a}=q();return t.length===0?null:e(`label`,{className:`flex flex-col gap-1 text-[11px] text-foreground`,children:[a(`customize.event.edge`),i(U,{"aria-label":a(`customize.event.edge`),value:n,options:t.map(e=>({value:e,label:a(`customize.event.edgeValue.${e}`)})),onChange:e=>{let n=t.find(t=>t===e.target.value);n!==void 0&&r(n)}})]})}function ti({label:t,value:n,onChange:r}){return e(`label`,{className:`flex flex-col gap-1 text-[11px] text-foreground`,children:[t,i(G,{type:`number`,"aria-label":t,value:Number.isFinite(n)?n:0,onChange:e=>{let t=Number(e.target.value);Number.isFinite(t)&&t>=0&&r(t)}})]})}function ni(e){return Object.hasOwn(z,e)}function ri(e,t){return ni(e)?z[e].targets.find(e=>e.id===t)??null:null}function ii(e){let t=ri(e.cap,e.targetId);if(t===null)return[];if(t.cardinality===`keyedArray`){let t=e.fieldPath;return t===void 0?[]:En(e.cap,e.targetId).find(e=>e.path===t)?.sources??[]}return t.sources}function ai(e){return{cap:e.cap,path:e.path,kind:e.kind,unit:e.unit}}function oi(e,t){return t.kind===`number`?e.find(e=>e.kind===`numeric`)??null:t.kind===`enum`||t.kind===`string`?e.find(e=>e.kind===`enum`)??null:null}function si(e){return e===`identity`||e===`invert`||e===`threshold`||e===`linear`}function ci(e,t){if(e.requiredUnit!==void 0&&t.unit===null)return{kind:`incompatible`,reason:`unit-unknown`};if(e.requiredUnit!==void 0&&t.unit!==e.requiredUnit)return{kind:`incompatible`,reason:`unit`};if(e.transformKinds.includes(`enum-map`))return{kind:`conversion`,name:`enum-map`};let n=e.transformKinds.filter(si);return n.length===0?{kind:`incompatible`,reason:`kind`}:n.includes(`identity`)?{kind:`direct`}:n.includes(`threshold`)?{kind:`conversion`,name:`threshold`}:n.includes(`linear`)?{kind:`conversion`,name:`scale`}:n.includes(`invert`)?{kind:`conversion`,name:`invert`}:{kind:`incompatible`,reason:`kind`}}function li(e,t){if(e.pickerTargetKind!==void 0){let n=e.pickerTargetKind,r={addonId:`x`,stableId:`y`};return(n===null?{kind:`from`,source:r,cap:t.cap,fieldPath:t.path}:hn(n,{source:r,cap:t.cap,fieldPath:t.path,kind:t.kind}))===null?{kind:`incompatible`,reason:`kind`}:{kind:`direct`}}if(e.acceptAnyField===!0)return t.kind===`enum`?{kind:`incompatible`,reason:`kind`}:{kind:`direct`};let n=ri(e.cap,e.targetId);if(n?.cardinality===`event`&&t.kind===`boolean`&&sr(ii(e),ai(t))!==null)return{kind:`direct`};let r=ii(e);if(r.length===0)return{kind:`incompatible`,reason:`kind`};let i=n?.cardinality===`keyedArray`&&e.fieldPath!==void 0;if(t.kind===`enum`&&!i)return{kind:`incompatible`,reason:`kind`};let a=i?oi(r,t):sr(r,ai(t));return a===null?{kind:`incompatible`,reason:`kind`}:ci(a,t)}function ui(e,t){let n=Te[e];return n===void 0?!1:Object.values(n).includes(t)}function di(){return Object.keys(Te)}function fi(e,t){if(t.kind===`binary`)return e.some(e=>Object.hasOwn(D,e));if(t.kind===`switch`)return e.includes(`switch`);if(t.kind===`numeric`){let n=t.requiredUnit;return n===void 0?e.some(e=>di().includes(e)||e===`numeric-sensor`):n===`W`?e.some(e=>e===`numeric-sensor`||e===`power-meter`||ui(e,n)):e.some(e=>ui(e,n))}return t.kind===`field`?e.some(e=>di().includes(e)||e===`numeric-sensor`||e===`battery`):t.kind===`enum`?e.includes(`consumables`)||e.some(e=>di().includes(e)):!1}function pi(e,t){if(t.pickerTargetKind!==void 0||t.acceptAnyField===!0)return!0;let n=ii(t);return n.length===0?!1:n.some(t=>fi(e.caps,t))}function mi(e,t,n){let r=[],i=[];for(let a of e)a.id!==n&&(pi(a,t)?r.push(a):i.push(a));return{compatible:r,incompatible:i}}function hi(e,t,n){let r=new Map,i=[];for(let a of e){let e=li(t,a),o=Y(a.cap,a.path,n),s={cap:a.cap,path:a.path,label:o,currentText:a.currentText,compatibility:e};if(e.kind===`incompatible`){i.push(s);continue}let c=r.get(a.cap)??[];c.push(s),r.set(a.cap,c)}return{groups:[...r.entries()].toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({cap:e,title:mr(e,n),rows:t.toSorted((e,t)=>e.label.localeCompare(t.label))})),incompatible:i}}function gi(e){return ri(e.cap,e.targetId)?.cardinality===`keyedArray`&&e.fieldPath!==void 0}function _i(e){if(e.pickerTargetKind!==void 0)return[];if(e.acceptAnyField===!0)return di();let t=ii(e),n=new Set;for(let e of t)if(e.kind===`binary`)for(let e of Object.keys(D))n.add(e);else if(e.kind===`switch`)n.add(`switch`);else if(e.kind===`numeric`){n.add(`numeric-sensor`),n.add(`power-meter`);for(let t of di())(e.requiredUnit===void 0||ui(t,e.requiredUnit))&&n.add(t)}else if(e.kind===`field`){n.add(`battery`),n.add(`numeric-sensor`);for(let e of di())n.add(e)}else if(e.kind===`enum`){n.add(`consumables`);for(let e of di())n.add(e)}return[...n]}function vi(e,t,n,r,i){let a=ii(e);if(a.length===0)return[];let o=ir(t,i).filter(e=>e.kind===`boolean`),s=[];for(let e of o){if(sr(a,e)===null||n===`pulse`&&!Jr(t,e.cap,e.path))continue;let o=i===null?void 0:J(i[e.cap],e.path);s.push({cap:e.cap,path:e.path,kind:`boolean`,unit:null,currentText:yn(o,r)})}return s}function yi(e,t,n,r,i,a=null){return a===null?e.pickerTargetKind!==void 0&&i!==null?vn(i,t,r,e.pickerTargetKind).map(e=>({cap:e.cap,path:e.path,kind:e.kind,unit:null,currentText:yn(e.value,n)})):(gi(e)?On(t,r):ir(t,r)).map(e=>{let t=r===null?void 0:J(r[e.cap],e.path);return{cap:e.cap,path:e.path,kind:e.kind,unit:e.unit,currentText:yn(t,n)}}):vi(e,t,a,n,r)}function bi(e,t,n){return n!==null&&e.parentDeviceId===n?0:e.parentDeviceId===t?1:null}function xi(e,t,n){let r=t.find(e=>e.id===n),i=r?.parentDeviceId??null,a=t.find(e=>e.id===(i??n));if(r===void 0||a===void 0)return null;let o=e.flatMap(e=>{let t=bi(e,n,i);return t===null?[]:[{candidate:e,place:t}]}).toSorted((e,t)=>e.place-t.place||e.candidate.name.localeCompare(t.candidate.name));return o.length===0?null:{container:a.name,devices:o.map(e=>e.candidate)}}s();function Si(e,t){return e===`pending`||t.kind===`pending`?`pending`:e===`error`?`failed`:`answered`}function Ci(e,t){return e.map(e=>({id:e.id,name:e.name,type:e.type,location:e.location,parentDeviceId:e.parentDeviceId,addonId:e.addonId,stableId:e.stableId,caps:t.get(e.id)??[]}))}function wi(e,t){return e.kind===`direct`?t(`customize.sourceSelector.direct`):e.kind===`conversion`?t(`customize.sourceSelector.withConversion`,{name:t(`customize.scalar.transform.${Ti(e.name)}`)}):``}function Ti(e){return e===`scale`?`linear`:e===`enum-map`?`enumMap`:e}function Ei(e){return e.kind===`members`?i(Wr,{...e}):i(Di,{...e})}function Di(t){let{t:r,i18n:s}=q(),[l,u]=o(`devices`),[d,p]=o(!1),m=vr(t.device!==null,{seenDevice:d,step:l});m!==null&&(p(m.seenDevice),u(m.step));let[h,g]=o(!1),[_,v]=o(!1),y=Tt({projection:`slim`}),b=t.kind===`formula`?t.deviceFilter:void 0,x=n(()=>{if(y.status!==`success`)return[];let e=gn(y.data);return b===void 0?e:e.filter(b)},[y.status,y.data,b]),S=Sn(n(()=>_i(t.destination),[t.destination]),t.enabled),{compatible:C,incompatible:w}=n(()=>S.kind===`known`?mi(Ci(x,S.value),t.destination,t.hostId):{compatible:[],incompatible:[]},[S,x,t.destination,t.hostId]),T=n(()=>S.kind===`known`?xi(C,Ci(x,S.value),t.hostId):null,[S,C,x,t.hostId]),E=Si(y.status,S),D=t.device?.id??0,O=qt({deviceId:D}),k=Yt({deviceId:t.device===null?0:D}),A=O.status===`success`?O.data:{caps:[]},j=t.kind===`event`?t.shape:null,M=yi(t.destination,A,k.status===`success`,k.status===`success`?k.data:null,t.device,j),N=t.kind===`event`?t.devicePickerTestId:`source-selector-device-picker`,{groups:ee,incompatible:P}=hi(M,t.destination,s.language),F=ki(t,A,k.status===`success`?k.data:null),I=e=>{let n=e[0];if(n===void 0){t.onDeviceChange(null),t.kind!==`event`&&t.onFieldChange(null),u(_r());return}if(t.device?.id!==n){let e=x.find(e=>e.id===n)??null;t.onDeviceChange(e),t.kind!==`event`&&t.onFieldChange(null)}u(hr(`single`))},L=t.kind===`event`?M[0]??null:null,R=t.kind===`event`?t:null;a(()=>{if(R===null||R.device===null||L===null)return;let e=Xr(R.picked,R.device,{cap:L.cap,path:L.path},R.shape,R.sourceModes[0]??`in-addition`);e!==null&&R.onPickedChange(e)},[R,L]);let te=n(()=>Rr(C),[C]),z=e(`div`,{className:`flex max-h-72 min-h-0 flex-col gap-2 overflow-y-auto sm:max-h-[min(24rem,60vh)]`,children:[i(`h3`,{className:`text-[11px] font-medium text-foreground-muted`,children:r(`customize.sourceSelector.pickDevice`,{title:t.destination.title})}),y.status===`error`?i(H,{title:r(`customize.picker.devicesFailed`),message:y.error?.message??``}):e(c,{children:[T!==null&&i(xn,{location:T.container,devices:T.devices.map(e=>({id:e.id,name:e.name,container:null,detail:null})),action:`use`,onPick:e=>I([e])}),i(gt,{devices:te,listState:E,value:t.device===null?[]:[t.device.id],selection:`single`,groupBy:`location`,onChange:I,noun:`device`,showAll:!0,testId:N})]}),w.length>0&&e(`div`,{"data-testid":`source-incompatible-devices`,children:[e(W,{variant:`ghost`,size:`sm`,className:`h-auto w-full justify-start gap-1 px-0 text-[11px] text-foreground-muted`,onClick:()=>g(e=>!e),children:[i(f,{className:`size-3 transition-transform ${h?`rotate-180`:``}`}),r(`customize.sourceSelector.notCompatibleDevices`,{count:w.length})]}),h&&i(`ul`,{className:`mt-1 flex flex-col gap-0.5 pl-4 text-[11px] text-foreground-subtle`,children:w.map(e=>i(`li`,{children:e.name},e.id))})]})]}),ne=t.kind===`event`&&t.picked.length>0?i(`ul`,{"data-testid":`source-picked-list`,className:`flex flex-col gap-2`,children:t.picked.map(n=>e(`li`,{className:`flex flex-col gap-1 text-xs`,children:[e(`span`,{className:`text-foreground`,children:[n.deviceName,` · `,Y(n.cap,n.fieldPath,s.language)]}),t.shape===`span`&&n.mode!==void 0&&i(ur,{mode:n.mode,modes:t.sourceModes,name:n.stableId,onChange:e=>t.onPickedChange($r(t.picked,n,e))}),i(W,{variant:`ghost`,size:`sm`,onClick:()=>t.onPickedChange(Qr(t.picked,n)),children:r(`customize.event.clear`)})]},`${n.addonId}/${n.stableId}/${n.cap}.${n.fieldPath}`))}):null,re=t.kind===`event`?e(`div`,{className:`flex flex-col gap-2`,children:[t.shape===`pulse`&&e(c,{children:[i(ei,{edges:t.edges,edge:t.edge,onChange:t.onEdgeChange}),e(`label`,{className:`flex flex-col gap-1 text-[11px] text-foreground`,children:[r(`customize.event.debounce`),i(G,{type:`number`,"aria-label":r(`customize.event.debounce`),value:Number.isFinite(t.debounceSec)?t.debounceSec:0,onChange:e=>{let n=Number(e.target.value);Number.isFinite(n)&&n>=0&&t.onDebounceSecChange(n)}})]})]}),t.shape===`span`&&e(c,{children:[i(ti,{label:r(`customize.event.timeout`),value:t.timeoutSec,onChange:t.onTimeoutSecChange}),t.cooldownSec!==null&&i(ti,{label:r(`customize.event.cooldown`),value:t.cooldownSec,onChange:t.onCooldownSecChange})]})]}):null;return i(xr,{step:l,devices:z,values:e(`div`,{className:`flex min-h-0 flex-col gap-2`,children:[ne,t.device!==null&&i(kt,{device:t.device,form:`full`,className:`text-[11px] font-medium text-foreground`}),t.device===null?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`customize.sourceSelector.noDevice`)}):O.status===`pending`?i(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:r(`customize.picker.loadingFields`)}):O.status===`error`?i(H,{title:r(`customize.picker.fieldsFailed`),message:O.error?.message??``}):e(`div`,{className:`flex flex-col gap-3`,children:[t.kind===`event`?i(ji,{fields:L===null?[]:[L],language:s.language,emptyLabel:r(`customize.sourceSelector.noStateField`)}):null,t.kind!==`event`&&ee.map(n=>e(`section`,{"aria-label":n.title,children:[i(`h4`,{className:`text-[10px] font-medium uppercase tracking-wide text-foreground-muted`,children:n.title}),i(`ul`,{className:`mt-1 flex flex-col gap-1`,children:n.rows.map(n=>i(`li`,{children:e(`label`,{className:`flex flex-wrap items-center gap-2 text-[11px] text-foreground`,children:[i(`input`,{type:`radio`,name:`source-value`,checked:t.field?.cap===n.cap&&t.field.path===n.path,"data-testid":`source-value-${n.cap}.${n.path}`,onChange:()=>{if(t.onFieldChange({cap:n.cap,path:n.path}),t.kind===`formula`)return;let e=Oi(t,A,k.status===`success`?k.data:null,n.cap,n.path);e!==null&&e.ok&&t.onTransformChange(Pn(e))}}),i(`span`,{children:n.label}),i(`span`,{className:`text-foreground-muted`,children:n.currentText}),i(`span`,{className:`text-foreground-subtle`,children:wi(n.compatibility,r)})]})},`${n.cap}.${n.path}`))})]},n.cap)),t.kind!==`event`&&P.length>0&&e(`div`,{"data-testid":`source-incompatible-values`,children:[e(W,{variant:`ghost`,size:`sm`,className:`h-auto w-full justify-start gap-1 px-0 text-[11px] text-foreground-muted`,onClick:()=>v(e=>!e),children:[i(f,{className:`size-3 transition-transform ${_?`rotate-180`:``}`}),r(`customize.sourceSelector.otherValues`)]}),_&&i(`ul`,{className:`mt-1 flex flex-col gap-1 pl-4 text-[11px] text-foreground-subtle`,children:P.map(t=>e(`li`,{children:[t.label,` · `,t.currentText]},`${t.cap}.${t.path}`))})]})]}),t.kind===`scalar`&&F!==null&&F.ok&&i(zn,{control:Nn(F.transforms),transforms:F.transforms,declared:F.declared,unit:F.sourceUnit,value:t.transform,onChange:t.onTransformChange}),t.kind===`keyed`&&F!==null&&F.ok&&t.field!==null&&i(zn,{control:Nn(F.transforms),transforms:F.transforms,declared:F.declared,unit:F.sourceUnit,value:t.transform,onChange:t.onTransformChange}),re]}),back:t.device===null?null:{label:i(kt,{device:t.device,form:`compact`}),ariaLabel:r(`customize.sourceSelector.backToDevice`,{name:t.device.name})},onBack:()=>u(_r()),done:null,onDone:()=>void 0})}function Oi(e,t,n,r,i){if(e.kind===`keyed`){let a=t.caps.flatMap(e=>e.fields.filter(e=>e.item!==!0).map(t=>({cap:e.cap,path:t.path,kind:t.kind,unit:Ai(n,e.cap),enumValues:t.enumValues??[]}))).find(e=>e.cap===r&&e.path===i);if(a===void 0)return null;let o=jn(e.destination.cap,e.destination.targetId,e.fieldPath,a);return!o.ok||o.mode!==`scalar`?null:o.fit}let a=t.caps.flatMap(e=>e.fields.filter(e=>e.item!==!0).map(t=>({cap:e.cap,path:t.path,kind:t.kind,unit:ar(Ai(n,e.cap),e.cap,t.path)}))).find(e=>e.cap===r&&e.path===i&&(e.kind===`boolean`||e.kind===`number`||e.kind===`string`));if(a===void 0)return null;let o=cr(e.destination.cap,e.destination.targetId,a);return o.ok?o:null}function ki(e,t,n){return e.kind===`formula`||e.kind===`event`||e.device===null||e.field===null?null:Oi(e,t,n,e.field.cap,e.field.path)}function Ai(e,t){if(e===null)return null;let n=e[t]?.unit;return typeof n==`string`&&n.length>0?n:null}function ji({fields:t,language:n,emptyLabel:r}){return t.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:r}):i(`ul`,{className:`flex flex-col gap-1`,children:t.map(t=>e(`li`,{"data-testid":`source-declared-field`,className:`text-[11px] text-foreground`,children:[i(`span`,{className:`font-medium`,children:mr(t.cap,n)}),` · `,Y(t.cap,t.path,n),` `,i(`span`,{className:`text-foreground-muted`,children:t.currentText})]},`${t.cap}.${t.path}`))})}function Mi({id:e,...t}){return i(Mt,{headingId:`customize-${e}`,...t})}function Ni(e,t){if(e.status===`error`)return{kind:`unknown`,reason:e.error?.message??K.t(`helpers.customize.requestFailed`)};let n=e.data;return e.status===`pending`||n===void 0?{kind:`pending`}:{kind:`known`,value:t(n)}}s();function Pi(e,t){let n=Et(e,t);return n.kind===`resolved`?n.integration.name:null}function Fi(e){let t=Tt({projection:`slim`},{enabled:e}),{data:r}=Jt(void 0,{enabled:e}),i=t.error===null||t.error===void 0?null:t.error.message;return n(()=>Ni({status:t.status,data:t.data,error:i===null?null:{message:i}},e=>e.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,type:e.type,location:e.location,isCamera:e.isCamera,integration:Pi(e,r),parentDeviceId:e.parentDeviceId,primaryChildEntityId:e.primaryChildEntityId??null,role:e.role??null}))),[t.status,t.data,i,r])}function Ii(e){let t=e?.trim()??``;return t.length>0?t:K.t(`helpers.customize.requestFailed`)}function Li(e){let t=e.data;if(t!==void 0){if(t.state===`not-loaded`)return{kind:`not-loaded`,reason:t.reason};if(t.view===null)return{kind:`none`};let e=A(t.view.block);return e===null?{kind:`unknown`,reason:K.t(`helpers.customizationRead.notAComposition`,{id:t.view.block.id})}:{kind:`present`,view:t.view,composition:e}}return e.status===`pending`?{kind:`pending`}:e.status===`error`?{kind:`unknown`,reason:Ii(e.error?.message)}:{kind:`pending`}}function Ri(e){return e.kind===`present`?e.composition:null}function zi(e){return Ye.find(t=>t.name===e)}function Bi(e){return e===`lastFetchedAt`||e.endsWith(`At`)}function Vi(e){let t=F(e.role);if(t===null||zi(t)?.status===void 0)return null;let n={};return{target:{kind:`new`,type:e.type,...e.role===null?{}:{role:e.role}},features:[{kind:`fields`,cap:t,fields:n}]}}function Hi(e){return e===null?`incomplete`:Ce(M(e,{lookupCap:P(Ye),sources:new Map,self:null,blockId:null,target:null,peers:[]}).problems)}function Ui(e,t){let n=zi(e);return n?.status===void 0?[]:k(n.status.schema).filter(e=>!Bi(e)&&!t.has(e))}function Wi(e,t,n){let r=e?.features??[],i=r.findIndex(e=>e.cap===n.cap);return{target:e?.target??{kind:`existing`,device:t},features:i===-1?[...r,n]:r.map((e,t)=>t===i?n:e)}}function Gi(e,t,n,r,i){return Wi(e,t,ve(Ji(e,r),n,r,i))}function Ki(e,t,n){let r=R(Ji(e,t),t,n);return r===null?qi(e,t):{target:e.target,features:e.features.map(e=>e.cap===t?r:e)}}function qi(e,t){let n=e.features.filter(e=>e.cap!==t);return n.length===0?null:{target:e.target,features:n}}function Ji(e,t){let n=e?.features.find(e=>e.cap===t);return n!==void 0&&n.kind===`fields`?n:null}function Yi(e){return Array.isArray(e)?e.map(Yi):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,Yi(t)]))}function Xi(e){return JSON.stringify(Yi(e))}function Zi(e,t){switch(e.kind){case`pending`:return{kind:`refused`,reason:K.t(`helpers.customizationSave.notReadYet`)};case`unknown`:return{kind:`refused`,reason:`the customization could not be read: ${e.reason}`};case`not-loaded`:return{kind:`refused`,reason:`the customizations are not loaded yet: ${e.reason}`};case`none`:return t===null?{kind:`noop`}:{kind:`create`,input:{enabled:!0,composition:t}};case`present`:{let n=e.view.block.id;return t===null?{kind:`delete`,blockId:n}:Xi(t)===Xi(e.composition)?{kind:`noop`}:{kind:`update`,blockId:n,expectedUpdatedAt:e.view.block.updatedAt,composition:t}}}}function Qi(){let{t:e}=q(),t=C();return(n,r)=>t({title:e(`customize.assign.removeConfirm.title`),message:r?`${e(`customize.assign.removeConfirm.message`,{what:n})} ${e(`customize.assign.removeConfirm.last`)}`:e(`customize.assign.removeConfirm.message`,{what:n}),confirmLabel:e(`customize.assign.removeConfirm.confirm`),variant:`danger`})}function $i(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ea(e,t){let n=J(e,t);return n===void 0?{kind:`absent`}:t===`level`&&e.binary===!0?{kind:`value`,value:n,binary:!0}:{kind:`value`,value:n}}function ta(e,t,n){return $i(t)?ea(t,n):e.status===`error`?{kind:`unknown`,reason:e.error?.message??K.t(`helpers.liveValue.unreadable`)}:e.status===`pending`||e.data===void 0?{kind:`pending`}:e.data===null?{kind:`absent`}:ea(e.data,n)}function na(e,t,n){if(t.binary===!0&&n.cap===`battery`&&n.path===`level`){let t=Pt(e);return{text:K.t(t?on:_t),tone:t?`warning`:`normal`}}return{text:n.path===`level`?`${Math.round(e)} %`:String(e),tone:`normal`}}function ra(e,t,n){let r=e?`active`:`muted`;return t.cap===`contact`&&t.path===`entryOpen`?{text:e?n.open:n.closed,tone:r}:D[t.cap]===t.path?{text:e?n.active:n.inactive,tone:r}:{text:String(e),tone:`normal`}}function ia(e,t,n){switch(e.kind){case`pending`:return{text:`…`,tone:`muted`};case`unknown`:return{text:`?`,title:e.reason,tone:`warning`};case`absent`:return{text:`—`,tone:`muted`};case`value`:{let r=e.value;return r===null?{text:`—`,tone:`muted`}:typeof r==`boolean`?ra(r,t,n):typeof r==`number`?na(r,e,t):typeof r==`string`?{text:r,tone:`normal`}:{text:JSON.stringify(r),tone:`normal`}}}}var aa=0;function oa(e){let t=y(),n=Ht({deviceId:e?.deviceId??aa,capName:e?.cap??``},{enabled:e!==null}),r=tn(t.trpcClient,e?.deviceId??null,e?.cap??``);return e===null?{kind:`absent`}:ta({status:n.status,data:n.data,error:n.error===null||n.error===void 0?null:{message:n.error.message}},r,e.path)}var sa={muted:`text-foreground-subtle`,active:`text-success`,normal:`text-foreground`,warning:`text-warning`};function ca({target:e}){let{t}=q(),n=oa(e);return e===null?null:i(la,{display:ia(n,e,{active:t(`customize.assign.value.active`),inactive:t(`customize.assign.value.inactive`),open:t(`customize.assign.value.open`),closed:t(`customize.assign.value.closed`)})})}function la({display:e}){return i(`span`,{className:`text-xs ${sa[e.tone]}`,title:e.title,children:e.text})}function ua(e){return e===`avg-round-1`?`customize.fieldsCard.aggregate.avg`:`customize.fieldsCard.aggregate.latest`}function da(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function fa(e,t,n){let r=RegExp(`(?<![A-Za-z0-9_])${da(t)}(?![A-Za-z0-9_])`,`g`);return e.replace(r,()=>n)}function pa(e,t,n,r,i){let a=Object.keys(t).toSorted((e,t)=>t.length-e.length),o=e;for(let e of a){let a=t[e];if(a===void 0||a.kind!==`from`)continue;let s=n.get(V(a.source))??i,c=Y(a.cap,a.fieldPath,r);o=fa(o,e,`${s} · ${c}`)}return Ca(o)}var ma=1e3,ha=60*ma,ga=60*ha,_a={within:[1],dwell:[1,2],rose:[2]};function va(e){if(!Number.isInteger(e)||e<ma)return null;if(e%ga===0){let t=e/ga;return t===1?`1 h`:`${t} h`}if(e%ha===0){let t=e/ha;return t===1?`1 min`:`${t} min`}if(e%ma===0){let t=e/ma;return t===1?`1 s`:`${t} s`}return null}function ya(e){return/^\d+$/.test(e.trim())?va(Number(e.trim())):null}function ba(e,t){let n=1,r=t+1,i=null,a=[];for(let o=t+1;o<e.length;o+=1){let t=e[o]??``;if(i!==null){if(t===`\\`){o+=1;continue}t===i&&(i=null);continue}if(t===`"`||t===`'`){i=t;continue}if(t===`(`){n+=1;continue}if(t===`)`){if(--n,n===0){let t=e.slice(r,o);return a.length===0&&t.trim()===``||a.push({text:t}),{args:a,close:o}}continue}t===`,`&&n===1&&(a.push({text:e.slice(r,o)}),r=o+1)}return null}function xa(e,t){let n=e[t-1];if(n!==void 0&&/[A-Za-z0-9_]/.test(n))return null;for(let n of Object.keys(_a)){if(!e.startsWith(n,t))continue;let r=t+n.length,i=e[r];if(i!==void 0&&/[A-Za-z0-9_]/.test(i))continue;let a=r;for(;e[a]===` `||e[a]===`
|
|
2
2
|
`;)a+=1;if(e[a]!==`(`)continue;let o=ba(e,a);return o===null?null:{name:n,close:o.close,args:o.args}}return null}function Sa(e){let t=e.args.map(e=>Ca(e.text)),n=_a[e.name]??[];if(e.name===`within`){let e=t[1],n=e===void 0?null:ya(e);if(n!==null)return`within ${n}`}let r=t.map((e,t)=>n.includes(t)?ya(e)??e.trim():e.trim());return`${e.name}(${r.join(`, `)})`}function Ca(e){let t=``,n=0;for(;n<e.length;){let r=xa(e,n);if(r===null){t+=e[n]??``,n+=1;continue}t+=Sa(r),n=r.close+1}return t}function wa(e){for(let t=1;;t++){let n=`s${t}`;if(!e.includes(n))return n}}var Ta={min:`min(a, b, …)`,max:`max(a, b, …)`,abs:`abs(x)`,floor:`floor(x)`,ceil:`ceil(x)`,sqrt:`sqrt(x)`,round:`round(x, digits?)`,pow:`pow(x, y)`,clamp:`clamp(x, lo, hi)`,avg:`avg(a, b, …)`,sum:`sum(a, b, …)`,coalesce:`coalesce(a, b, …)`,age:`age(now, ts)`,convert:`convert(x, "from", "to")`,any:`any(a, b, …)`,all:`all(a, b, …)`,within:`within(ts, ms)`,number:`number(x)`,latest:`latest(ts, …)`,rose:`rose(level, changedAt, debounceMs?)`,count:`count(x)`,dwell:`dwell(active, onForMs, offForMs)`,latchedAt:`latchedAt(value)`,schmitt:`schmitt(x, high, low, onForMs?, offForMs?)`},Ea=/[A-Za-z_][A-Za-z0-9_]*$/;function Da(e,t,n){let r=Ea.exec(e.slice(0,t))?.[0]??``;if(r===``)return[];let i=n.filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`binding`,label:e,insert:e,hintKey:null})),a=`now`.startsWith(r)?[{kind:`now`,label:`now`,insert:`now`,hintKey:`compositionEditor.now`}]:[],o=[...We].filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`builtin`,label:Ta[e]??e,insert:`${e}(`,hintKey:`compositionEditor.builtins.${e}`}));return[...i,...a,...o].slice(0,8)}function Oa(e,t,n){let r=t-(Ea.exec(e.slice(0,t))?.[0]??``).length;return{text:`${e.slice(0,r)}${n.insert}${e.slice(t)}`,cursor:r+n.insert.length}}s();function ka({label:n,value:r,bindings:a,onChange:s}){let{t:c}=q(),l=t(null),[u,d]=o(r.length),f=Da(r,u,a);return e(`div`,{className:`flex flex-col gap-1`,children:[e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[n,i(`input`,{ref:l,className:`font-mono px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`,value:r,onChange:e=>{s(e.target.value),d(e.target.selectionStart??e.target.value.length)},onSelect:e=>d(e.currentTarget.selectionStart??r.length)})]}),f.length>0&&i(`ul`,{role:`listbox`,"aria-label":c(`compositionEditor.suggestions`),className:`rounded border border-border bg-surface text-[11px]`,children:f.map(t=>e(`li`,{role:`option`,"aria-selected":!1,tabIndex:0,className:`flex justify-between gap-2 px-1 cursor-pointer hover:bg-surface-hover`,onClick:()=>{let e=Oa(r,u,t);s(e.text),d(e.cursor),l.current?.focus()},children:[i(`span`,{className:`font-mono`,children:t.label}),t.hintKey!==null&&i(`span`,{className:`text-foreground-subtle`,children:c(t.hintKey)})]},`${t.kind}:${t.label}`))})]})}function Aa(e){return{addonId:e.addonId,stableId:e.stableId}}function ja(e){return new Map(e.map(e=>[V(Aa(e)),e]))}function Ma(e,t,n){if(e.kind===`code`)return{kind:`unavailable`,reason:K.t(`helpers.fieldPreview.codeFields`)};if(e.kind===`series`||e.kind===`expression`&&(rt(e.expr,`rose`)||rt(e.expr,`count`)))return{kind:`runtime-only`};let r=je(e).filter(e=>t.get(ie(e.source,e.cap))?.kind!==`value`).map(Ze);if(r.length>0)return{kind:`waiting`,missing:r};let i=ae({source:e,now:n,read:e=>{let n=t.get(ie(e.source,e.cap)),r=n?.kind===`value`?J(n.slice,e.fieldPath):void 0,i=r===void 0?void 0:he(r);return i===void 0?{state:`unavailable`,reason:K.t(`helpers.fieldPreview.notReported`,{path:`${e.cap}.${e.fieldPath}`}),fatal:!1}:{state:`fresh`,value:i}}});return i.state===`unavailable`?{kind:`unavailable`,reason:i.reason}:{kind:`value`,value:i.value,stale:i.reason}}s();function Na({sliceKey:e,deviceId:t,capName:n,onReading:r}){let i=tn(y().trpcClient,t,n);return a(()=>{r(e,i===void 0?{kind:`pending`}:{kind:`value`,slice:i})},[e,i,r]),null}function Pa(e,t){return[...new Map(je(e).map(e=>[ie(e.source,e.cap),e]))].map(([e,n])=>({key:e,read:n,device:t.get(V(n.source))}))}function Fa({source:t}){let{t:n}=q(),a=Tt({projection:`slim`}),[s,c]=o(new Map),l=r((e,t)=>{c(n=>new Map([...n,[e,t]]))},[]),u=Pa(t,ja(a.status===`success`?gn(a.data):[])),d=a.status===`success`?u.filter(e=>e.device===void 0).map(e=>V(e.read.source)):[];return e(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[u.map(e=>e.device===void 0?null:i(Na,{sliceKey:e.key,deviceId:e.device.id,capName:e.read.cap,onReading:l},e.key)),i(`span`,{className:`text-foreground-subtle`,children:n(`compositionEditor.preview.label`)}),a.status===`error`?i(`span`,{className:`text-warning`,children:n(`compositionEditor.preview.devicesFailed`,{reason:a.error?.message??``})}):d.length>0?i(`span`,{className:`text-warning`,children:n(`compositionEditor.preview.unknownDevice`,{sources:d.join(`, `)})}):i(Ia,{preview:Ma(t,s,Date.now())})]})}function Ia({preview:t}){let{t:n}=q();switch(t.kind){case`value`:return e(`strong`,{children:[`→ `,yn(t.value,!0),t.stale===null?``:` (${t.stale})`]});case`unavailable`:return i(`span`,{className:`text-warning`,children:t.reason});case`waiting`:return i(`span`,{className:`text-foreground-subtle`,children:n(`compositionEditor.preview.waiting`,{sources:t.missing.join(`, `)})});case`runtime-only`:return i(`span`,{className:`text-foreground-subtle`,children:n(`compositionEditor.preview.runtimeOnly`)})}}function La(e,t,n,r,i,a){let o=vn(e,r,i,a).find(e=>e.cap===t&&e.path===n);return o===void 0||o.source===null?null:{device:e,ref:{addonId:e.addonId,stableId:e.stableId},cap:o.cap,path:o.path,kind:o.kind,source:o.source,value:o.value}}s();var Ra=new Map;function za(e,t,n,r){return e.kind===`from`?`${t.get(V(e.source))??r} · ${Y(e.cap,e.fieldPath,n)}`:``}function Ba({open:t,title:n,fieldPath:r,fieldLabel:a,sourceNames:s=Ra,initial:c,selfNative:l=null,onClose:u,onSave:d}){let{t:f,i18n:p}=q(),[m,h]=o(c.kind===`expression`?c:{kind:`expression`,expr:`null`,bindings:{}}),[g,_]=o(`idle`),[v,y]=o(null),[b,x]=o(null),S=qt({deviceId:v?.id??0}),C=Yt({deviceId:v?.id??0}),w=S.status===`success`?S.data:{caps:[]},T=N(m.expr,m.bindings),E=Object.keys(m.bindings);return i(Gt,{open:t,onOpenChange:e=>{e||u()},children:e(rn,{width:`lg`,scroll:`body`,placement:`sheet-on-mobile`,"data-testid":`formula-dialog`,children:[i(an,{children:i(At,{children:n})}),e(zt,{className:`flex flex-col gap-2`,children:[i(`span`,{className:`text-xs text-foreground`,children:a??Y(``,r,p.language)}),i(ka,{label:f(`compositionEditor.formulaFor`,{path:a??r}),value:m.expr,bindings:E,onChange:e=>h({...m,expr:e})}),i(`ul`,{className:`flex flex-col gap-0.5 text-[11px]`,children:Object.entries(m.bindings).map(([t,n])=>e(`li`,{className:`flex flex-wrap items-center gap-2`,children:[i(`span`,{className:`font-mono`,children:t}),i(`span`,{children:n.kind===`from`?za(n,s,p.language,f(`customize.fieldsCard.unknownDevice`)):JSON.stringify(n.value)}),i(W,{size:`sm`,variant:`ghost`,"aria-label":f(`compositionEditor.removeBinding`,{name:t}),onClick:()=>{let{[t]:e,...n}=m.bindings;h({...m,bindings:n})},children:`×`})]},t))}),e(`div`,{className:`flex flex-wrap gap-2`,children:[l!==null&&i(W,{size:`sm`,variant:`outline`,"data-testid":`formula-self-native`,onClick:()=>{let e=Object.keys(m.bindings),t=m.bindings.v===void 0?`v`:wa(e);h({...m,bindings:{...m.bindings,[t]:{kind:`from`,source:l.source,cap:l.cap,fieldPath:l.fieldPath}}})},children:f(`customize.override.selfNative`)}),i(W,{size:`sm`,variant:`outline`,onClick:()=>_(`add-binding`),children:f(`compositionEditor.addSource`)})]}),T!==null&&i(`p`,{role:`alert`,className:`text-xs text-danger`,children:T}),i(Fa,{source:m}),g===`add-binding`&&e(`div`,{className:`flex flex-col gap-2 border border-border rounded-md p-2`,children:[i(Ei,{kind:`formula`,enabled:t,hostId:-1,destination:{cap:`formula`,targetId:`binding`,title:f(`compositionEditor.addSource`),acceptAnyField:!0},device:v,field:b,onDeviceChange:y,onFieldChange:x}),e(`div`,{className:`flex flex-wrap gap-2`,children:[i(W,{variant:`ghost`,size:`sm`,onClick:()=>_(`idle`),children:f(`customize.picker.cancel`)}),i(W,{size:`sm`,disabled:v===null||b===null,onClick:()=>{if(v===null||b===null)return;let e=La(v,b.cap,b.path,w,C.status===`success`?C.data:null,null);if(e===null)return;let t=wa(E);h({...m,bindings:{...m.bindings,[t]:{kind:`from`,source:e.ref,cap:e.cap,fieldPath:e.path}}}),y(null),x(null),_(`idle`)},children:f(`compositionEditor.addSource`)})]})]})]}),e(Bt,{children:[i(W,{variant:`ghost`,onClick:u,children:f(`compositionEditor.cancel`)}),i(W,{"data-testid":`formula-dialog-save`,disabled:T!==null,onClick:()=>{d(m),u()},children:f(`compositionEditor.save`)})]})]})})}s();function Va({open:t,from:n,initialTo:r,onClose:a,onSave:s}){let{t:c}=q(),l=De(n),[u,d]=o(r??l[0]??``),f=l.includes(u)?u:l[0]??``;return i(Gt,{open:t,onOpenChange:e=>{e||a()},children:e(rn,{width:`sm`,scroll:`body`,placement:`sheet-on-mobile`,"data-testid":`convert-unit-dialog`,children:[i(an,{children:i(At,{children:c(`customize.override.convertTitle`)})}),e(zt,{className:`flex flex-col gap-2`,children:[i(`p`,{className:`text-xs text-foreground`,children:c(`customize.override.convertSummary`,{from:n,to:f})}),l.length>1&&i(U,{"aria-label":c(`customize.override.targetUnit`),value:f,onChange:e=>d(e.target.value),options:l.map(e=>({value:e,label:e}))})]}),e(Bt,{children:[i(W,{variant:`ghost`,onClick:a,children:c(`compositionEditor.cancel`)}),i(W,{"data-testid":`convert-unit-publish`,disabled:f===``||f===n,onClick:()=>{s(f),a()},children:c(`customize.override.publish`)})]})]})})}function Ha(e,t,n,r,i){return{kind:`expression`,expr:`convert(v, ${JSON.stringify(e)}, ${JSON.stringify(t)})`,bindings:{v:{kind:`from`,source:n,cap:r,fieldPath:i}}}}function Ua(e){return{kind:`expression`,expr:JSON.stringify(e),bindings:{}}}function Wa(e,t,n,r,i,a){let o=Ji(e,n)??{kind:`fields`,cap:n,fields:{}},s={...o.fields,[r]:i},c=Object.fromEntries(Object.entries(s).filter(([e])=>!a.includes(e)));return Wi(e,t,{...o,fields:c})}function Ga(e,t,n,r){let i=Qe(t,n);if(i===null||e===null)return[];let a=e.fields[i];return a?.kind===`expression`&&a.expr===JSON.stringify(r)&&i!==n?[i]:[]}function Ka(e,t,n,r){let i=Ji(e,n);if(i===null)return e;let a=new Set(r),o=Object.fromEntries(Object.entries(i.fields).filter(([e])=>!a.has(e))),s=i.commands!==void 0||i.items!==void 0;return Object.keys(o).length===0&&!s?qi(e,n):Wi(e,t,{...i,fields:o})}s();function qa({deviceId:t,self:n,selfName:r,cap:a,fieldPath:s,label:l,unit:u,valueKind:d=null,handle:f,names:p,toFill:m=!1}){let{t:h,i18n:g}=q(),_=Qi(),[v,y]=o(`closed`),b=Ri(f.state),x=Ji(b,a),S=x?.fields[s]??null,C=S===null?null:te(S),w=u===void 0?[]:De(u),T=new Map(p);T.set(V(n),r);let E=()=>y(`closed`),D=(e,t)=>{f.save(Wa(b,n,a,s,e,t))},O=()=>C?.kind===`convert-unit`?Ga(x,a,s,C.to):[];return e(`div`,{className:`flex flex-col gap-1 border-t border-border pt-2 first:border-t-0 first:pt-0`,"data-testid":`override-row-${a}-${s}`,children:[e(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[i(`span`,{className:`text-xs text-foreground`,children:l}),m&&S===null&&i(Vt,{variant:`warning`,children:h(`compositionEditor.toFill`)})]}),e(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2`,children:[i(`span`,{className:`text-xs text-foreground`,children:h(`customize.scalar.effective`)}),i(ca,{target:{deviceId:t,cap:a,path:s}})]}),C===null?i(`p`,{className:`text-xs text-foreground-subtle`,children:h(`customize.override.none`)}):i(Xa,{entry:C,names:T,language:g.language,unknownDevice:h(`customize.fieldsCard.unknownDevice`)}),i(`div`,{className:`flex flex-wrap gap-2`,children:C===null?i(Ya,{cap:a,fieldPath:s,saving:f.saving,convert:w.length>0,onFrom:()=>y(`from`),onFormula:()=>y(`formula`),onConvert:()=>y(`convert`)}):e(c,{children:[i(W,{variant:`outline`,size:`sm`,disabled:f.saving,onClick:()=>y(Ja(C)),children:h(`customize.scalar.change`)}),i(W,{variant:`ghost`,size:`sm`,disabled:f.saving,onClick:()=>{if(b===null)return;let e=Ka(b,n,a,[s,...O()]);_(h(`customize.fieldsCard.removeField`,{field:l}),e===null).then(t=>{t&&f.save(e)})},children:h(`customize.scalar.remove`)})]})}),i(Gt,{open:v===`from`,onOpenChange:e=>{e||E()},children:e(rn,{width:`lg`,scroll:`body`,placement:`sheet-on-mobile`,children:[i(an,{children:i(At,{children:l})}),i(zt,{children:v===`from`&&i(Za,{title:h(`customize.override.fromDevice`),hostId:t,valueKind:d??(u===void 0?null:`number`),onCancel:E,onConfirm:e=>{D(e.source,O()),E()}})})]})}),v===`formula`&&i(Ba,{open:!0,title:h(`compositionEditor.formulaFor`,{path:l}),fieldPath:s,fieldLabel:l,sourceNames:T,initial:S?.kind===`expression`?S:{kind:`expression`,expr:`v`,bindings:{}},selfNative:{source:n,cap:a,fieldPath:s},onClose:E,onSave:e=>{D(e,O()),E()}}),v===`convert`&&u!==void 0&&i(Va,{open:!0,from:u,initialTo:C?.kind===`convert-unit`?C.to:null,onClose:E,onSave:e=>{let t=Qe(a,s),r=Wa(b,n,a,s,Ha(u,e,n,a,s),[]),i=t===null?r:Wa(r,n,a,t,Ua(e),[]);f.save(i),E()}})]})}function Ja(e){return e.kind===`convert-unit`?`convert`:e.kind===`from`?`from`:`formula`}function Ya({cap:t,fieldPath:n,saving:r,convert:a,onFrom:o,onFormula:s,onConvert:c}){let{t:l}=q();return e(Wt,{children:[i(Kt,{className:`h-7 px-2.5 text-xs rounded-md border border-border bg-surface text-foreground`,disabled:r,"data-testid":`override-add-${t}-${n}`,children:l(`customize.override.add`)}),e(Qt,{children:[i(Xt,{onClick:o,children:l(`customize.override.fromDevice`)}),i(Xt,{onClick:s,children:l(`customize.override.formula`)}),a&&i(Xt,{onClick:c,children:l(`customize.override.convertUnit`)})]})]})}function Xa({entry:t,names:n,language:r,unknownDevice:a}){let{t:o}=q();return t.kind===`companion`?i(`span`,{className:`text-xs text-foreground`,children:o(`customize.fieldsCard.now`)}):t.kind===`convert-unit`?e(`p`,{className:`flex flex-wrap items-center gap-1 text-xs text-foreground`,children:[i(`span`,{children:o(`customize.override.convertSummary`,{from:t.from,to:t.to})}),i(Vt,{children:o(`customize.override.convertUnit`)})]}):t.kind===`formula`?e(`p`,{className:`flex flex-wrap items-center gap-1 text-xs text-foreground`,children:[i(`span`,{className:`break-words`,children:pa(t.expr,t.bindings,n,r,a)}),i(Vt,{children:o(`compositionEditor.formula`)})]}):e(`div`,{className:`flex flex-col gap-0.5`,children:[t.sources.map(e=>{let t=V(e.source);return i(`span`,{className:`text-xs text-foreground`,children:o(`customize.fieldsCard.from`,{name:n.get(t)??a,field:Y(e.cap,e.fieldPath,r)})},`${t}:${e.cap}:${e.fieldPath}`)}),t.aggregate!==null&&i(`span`,{className:`text-xs text-foreground-muted`,children:o(ua(t.aggregate))})]})}function Za({title:t,hostId:n,valueKind:r,onCancel:a,onConfirm:s}){let{t:c}=q(),[l,u]=o(null),[d,f]=o(null),p=qt({deviceId:l?.id??0}),m=Yt({deviceId:l?.id??0}),h=p.status===`success`?p.data:{caps:[]};return e(`div`,{className:`flex flex-col gap-2`,children:[i(Ei,{kind:`formula`,enabled:!0,hostId:n,destination:{cap:`override`,targetId:`field`,title:t,pickerTargetKind:r},device:l,field:d,onDeviceChange:u,onFieldChange:f}),e(`div`,{className:`flex flex-wrap gap-2`,children:[i(W,{variant:`ghost`,onClick:a,children:c(`customize.picker.cancel`)}),i(W,{disabled:l===null||d===null,onClick:()=>{if(l===null||d===null)return;let e=La(l,d.cap,d.path,h,m.status===`success`?m.data:null,r);e!==null&&s(e)},children:c(`customize.override.save`)})]})]})}function Qa(e,t){return Le(e,t)}function $a({deviceId:t,selfName:n,card:r,handle:a,names:o}){let{t:s,i18n:c}=q(),l=Qi(),u=Ri(a.state),d=c.language,f=mr(r.cap,d),p=new Set(Object.keys(r.entries)),m=Ui(r.cap,p),h=()=>{if(u===null)return;let e=qi(u,r.cap);l(s(`customize.fieldsCard.removeWhat`,{cap:f}),e===null).then(t=>{t&&a.save(e)})},g=(e,s)=>i(qa,{deviceId:t,self:a.target,selfName:n,cap:r.cap,fieldPath:e,label:Y(r.cap,e,d),unit:Qa(r.cap,e),handle:a,names:o,toFill:s},e);return e(`div`,{className:`flex flex-col gap-3 px-3 py-2 sm:px-4`,children:[m.map(e=>g(e,!0)),Object.keys(r.entries).filter(e=>!m.includes(e)).map(e=>g(e,!1)),i(`div`,{className:`flex flex-wrap gap-2`,children:i(W,{variant:`ghost`,size:`sm`,disabled:a.saving,onClick:h,children:s(`customize.fieldsCard.removeFeature`,{cap:f})})})]})}s();function eo({device:e,handle:t,skipCaps:r}){let{i18n:a}=q(),o=vt(e,`compact`),s=Ri(t.state),l=Fi(s!==null),u=n(()=>l.kind===`known`?new Map(l.value.map(e=>[V({addonId:e.addonId,stableId:e.stableId}),e.name])):new Map,[l]);if(s===null)return null;let{model:d}=_e(s),f=d.cards.filter(e=>e.card.cardKind===`fields`&&!r.has(e.card.cap));return f.length===0?null:i(c,{children:f.map(n=>{if(n.card.cardKind!==`fields`)return null;let r=n.card,s=mr(r.cap,a.language);return i(Mi,{id:r.cap,icon:mt,title:s,testId:`fields-card-${r.cap}`,children:i($a,{deviceId:e.id,selfName:o,card:r,handle:t,names:u})},r.cap)})})}function to(){return Object.entries(z).flatMap(([e,t])=>t.targets.filter(e=>e.cardinality===`event`).map(t=>({cap:e,pulse:no(t),span:ro(t)})).filter(e=>e.pulse!==null||e.span!==null))}function no(e){return e.shape===`pulse`?e.timestampPath===void 0||e.counterPath===void 0||e.debounceMs===void 0||e.edges===void 0||e.defaultEdge===void 0||!e.edges.includes(e.defaultEdge)?null:{id:e.id,timestampPath:e.timestampPath,counterPath:e.counterPath,debounceMs:e.debounceMs,edges:e.edges,defaultEdge:e.defaultEdge,apply:`add`,deviceTypes:e.deviceTypes}:null}function ro(e){return e.shape!==`span`||e.timeoutMs===void 0||e.applyAuthority?.kind!==`camera-sensors`?null:{id:e.id,timeoutMs:e.timeoutMs,cooldownMs:e.cooldownMs??null,sourceModes:e.sourceModes??[`in-addition`],deviceTypes:e.deviceTypes}}function io(e,t){return e===`Native`||e.startsWith(`Native`)?`customize.assign.native`:e===`pending`?`customize.event.checking`:e===`unknown`||e===`unreadable`?`customize.event.badge.unavailable`:`customize.event.badge.${t}`}function ao(e){return new Set(e.filter(e=>{let t=e.nativeAddonId?.trim()??``;return t!==``&&t!==`composer`}).map(e=>e.capName))}function oo(e,t){return{cap:e,apply:t.apply,authority:t.applyAuthority?.kind??`composition-claim`,nativeItemsReadOnly:t.nativeItems===`read-only`}}function so(e){return e.kind===`known`?null:e}function co(e,t){return e.composable.kind===`known`?e.composable.value.has(t)?{kind:`present`,mode:`add`}:{kind:`absent`}:e.composable}function lo(e){if(e.deviceType!==I.Camera)return{kind:`absent`};switch(e.cameraSensors){case`pending`:return{kind:`pending`};case`unknown`:return{kind:`unknown`,reason:K.t(`helpers.assignmentAvailability.sensorsUnchecked`)};case`absent`:return{kind:`absent`};case`present`:return{kind:`present`,mode:`add`}}}function uo(e,t){if(e.authority===`camera-sensors`)return lo(t);let n=so(t.nativeCaps);if(n!==null)return n;let r=t.nativeCaps.kind===`known`?t.nativeCaps.value:new Set;return e.nativeItemsReadOnly?co(t,e.cap):r.has(e.cap)?{kind:`absent`}:co(t,e.cap)}s();var fo=new Map;function po({handle:t,cap:n,fieldPath:r,itemKey:a,label:s,testId:l,sourceNames:u=fo}){let{t:d,i18n:f}=q(),p=Y(n,r,f.language),[m,h]=o(!1),g=Ri(t.state),_=Ji(g,n),v=a===void 0?_?.fields[r]:_?.items?.[a]?.fields[r];if(v===void 0)return null;let y=async e=>{if(_===null)return;let n;if(a===void 0)n={..._,fields:{..._.fields,[r]:e}};else{let t=_.items?.[a];if(t===void 0)return;n={..._,items:{..._.items,[a]:{...t,fields:{...t.fields,[r]:e}}}}}await t.save(Wi(g,t.target,n))};return e(c,{children:[i(W,{variant:`ghost`,size:`sm`,"data-testid":l??`formula-entry-${n}-${r}`,onClick:()=>h(!0),children:s??d(`compositionEditor.formula`)}),i(Ba,{open:m,title:d(`compositionEditor.formulaFor`,{path:p}),fieldPath:r,fieldLabel:p,sourceNames:u,initial:v,onClose:()=>h(!1),onSave:e=>void y(e)})]})}function mo({name:t,detail:n,meta:r,value:a,shown:o,readout:s,problem:c,onRemove:l,removeLabel:u,busy:d=!1}){return e(`li`,{className:`${m} grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 gap-y-1 sm:grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,1fr)_1.75rem]`,children:[e(`div`,{className:`min-w-0`,children:[i(`div`,{className:`text-xs text-foreground break-words`,children:t}),n!==null&&i(`div`,{className:`text-[11px] text-foreground-subtle break-words`,children:n}),c!==void 0&&i(`div`,{role:`alert`,className:`text-[11px] text-warning break-words`,children:c})]}),i(`div`,{className:`row-start-2 col-start-1 text-[11px] text-foreground-subtle empty:hidden sm:row-start-auto sm:col-start-auto sm:empty:block`,children:r}),i(`div`,{className:`row-start-3 col-start-1 empty:hidden sm:row-start-auto sm:col-start-auto sm:empty:block`,children:s===void 0?o===void 0?i(ca,{target:a}):o!==null&&i(la,{display:o}):s}),i(`div`,{className:`row-start-1 col-start-2 flex justify-end sm:row-start-auto sm:col-start-auto`,children:l!==void 0&&i(wt,{icon:x,variant:`ghost`,size:`sm`,"aria-label":u,disabled:d,onClick:l})})]})}function ho(e){return e.toLowerCase().normalize(`NFD`).replace(/[\u0300-\u036f]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,48)}function go({preview:t}){let{t:n}=q();return e(`p`,{className:`text-[11px] text-foreground`,"data-testid":`scalar-preview`,children:[e(`span`,{className:`text-foreground-muted`,children:[n(`customize.scalar.preview`),` `]}),t.kind===`pending`&&i(`span`,{children:`…`}),t.kind===`value`&&i(`span`,{children:t.text}),t.kind===`dwell`&&i(`span`,{children:n(`customize.scalar.previewDwell`,{value:t.sourceText,level:t.active?n(`customize.scalar.thresholdActive`):n(`customize.scalar.thresholdClear`),countdown:n(t.active?`customize.scalar.runningIn`:`customize.scalar.stopsAfter`,{seconds:Math.round(t.countdownMs/1e3)})})}),t.kind===`failed`&&i(`span`,{title:er(t.reason)?n($n(t.reason)):t.reason,className:`text-warning`,children:`?`})]})}function _o(e){return!e.ok||e.mode===`enum`?{kind:`identity`}:Pn(e.fit)}function vo(e,t){return Object.fromEntries(e.map(e=>[e,t.includes(e)?e:null]))}function yo(e){let t={draft:{kind:`keyedArray`,cap:e.cap,targetId:e.targetId,key:e.key,label:e.label.trim(),fieldPath:e.fieldPath,source:{addonId:e.source.addonId,stableId:e.source.stableId,cap:e.source.cap,fieldPath:e.source.fieldPath},transform:e.transform},sourceValueKind:e.source.valueKind,sourceUnit:null,literals:e.literals},n=O({cap:e.cap,targetId:e.targetId,device:e.device,apply:e.apply,items:[t]});return n.ok?n.value:null}function bo(e,t,n){return(En(e,t).find(e=>e.path===n)?.literals??[]).map(e=>e.path)}function xo(e,t,n,r){return En(e,t).find(e=>e.path===n)?.literals?.find(e=>e.path===r)?.values??[]}function So(e,t,n){return Mn(e,t,n)}s();var Co={level:`customize.keyed.field.level`,"remaining.value":`customize.keyed.field.remaining`,status:`customize.keyed.field.status`};function wo(t){let{t:n}=q(),r=t.mode===`change`?n(`customize.keyed.changeTitle`):n(`customize.keyed.addTitle`);return i(Gt,{open:t.open,onOpenChange:e=>e?void 0:t.onClose(),children:e(rn,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":r,children:[i(an,{children:i(At,{children:r})}),t.open&&i(To,{...t,heading:r})]})})}function To(t){let{t:r,i18n:a}=q(),s=Dn(t.cap,t.targetId),l=En(t.cap,t.targetId),[u,d]=o(t.seed?.label??``),[f,p]=o(t.seed?.key??``),[m,h]=o(t.mode===`change`),[g,_]=o(t.seed?.fieldPath??l[0]?.path??``),[v,y]=o(()=>Object.fromEntries(s.map(e=>[e.path,t.seed?.literals.find(t=>t.path===e.path)?.value??e.defaultValue]))),[b,x]=o(t.seed?.literals.find(e=>e.path===`remaining.kind`)?.value??xo(t.cap,t.targetId,`remaining.value`,`remaining.kind`)[0]??``),S=Tt({projection:`slim`}),C=n(()=>S.status===`success`?gn(S.data):[],[S.status,S.data]),w=No(t.seed,C),[T,E]=o(null),[D,O]=o(!1);!D&&w!==null&&(E(w),O(!0));let k=qt({deviceId:T?.id??0}),A=Yt({deviceId:T?.id??0}),j=On(k.status===`success`?k.data:{caps:[]},A.status===`success`?A.data:null),[M,N]=o(t.seed===null?null:`${t.seed.source.cap}.${t.seed.source.fieldPath}`),[ee,P]=o(t.seed?.transform??{kind:`identity`}),[F,I]=o(()=>t.seed?.transform.kind===`enum-map`?t.seed.transform.mapping:{}),L=j.find(e=>`${e.cap}.${e.path}`===M)??null,R=L===null?null:jn(t.cap,t.targetId,g,L),te=m?f:ho(u),z=Do(t.cap,t.targetId,g,v,b),ne=Oo(T,L,R,F,ee),re=ne===null?null:yo({cap:t.cap,targetId:t.targetId,device:t.target,apply:t.apply,key:te,label:u,fieldPath:g,source:ne,transform:ne.transform,literals:z}),ie=ko(re,te,g,L,A.status===`success`?A.data:null),ae=e=>{if(e===null){N(null);return}let n=j.find(t=>t.cap===e.cap&&t.path===e.path);n!==void 0&&se(n,jn(t.cap,t.targetId,g,n))},oe=e=>{d(e),m||p(ho(e))};return e(c,{children:[e(zt,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:[e(`label`,{className:`flex flex-col gap-1 text-xs text-foreground`,children:[r(`customize.keyed.name`),i(G,{value:u,onChange:e=>oe(e.target.value)})]}),e(`label`,{className:`flex flex-col gap-1 text-xs text-foreground`,children:[r(`customize.keyed.key`),i(G,{value:te,disabled:t.mode===`change`,onChange:e=>{h(!0),p(e.target.value)}})]}),e(`label`,{className:`flex flex-col gap-1 text-xs text-foreground`,children:[r(`customize.keyed.assignField`),i(U,{value:g,options:l.map(e=>({value:e.path,label:r(Co[e.path]??e.path)})),onChange:e=>{_(e.target.value),E(null),N(null),P({kind:`identity`})}})]}),s.map(t=>e(`label`,{className:`flex flex-col gap-1 text-xs text-foreground`,children:[r(`customize.keyed.trait.${t.path}`),i(U,{value:v[t.path]??t.defaultValue,options:t.values.map(e=>({value:e,label:r(`customize.keyed.value.${e}`)})),onChange:e=>y(n=>({...n,[t.path]:e.target.value}))})]},t.path)),bo(t.cap,t.targetId,g).map(n=>e(`label`,{className:`flex flex-col gap-1 text-xs text-foreground`,children:[r(`customize.keyed.unit`),i(U,{value:b,options:xo(t.cap,t.targetId,g,n).map(e=>({value:e,label:r(`customize.keyed.value.${e}`)})),onChange:e=>x(e.target.value)})]},n)),i(Ei,{kind:`keyed`,enabled:t.open,hostId:t.host.id,fieldPath:g,destination:{cap:t.cap,targetId:t.targetId,fieldPath:g,title:r(Co[g]??g)},device:T,field:Mo(M),transform:ee,onDeviceChange:e=>{E(e),N(null),P({kind:`identity`})},onFieldChange:ae,onTransformChange:P}),R?.ok===!0&&R.mode===`enum`&&L!==null&&i(Eo,{values:L.enumValues,outputs:So(t.cap,t.targetId,g),mapping:F,onChange:I}),ie!==null&&i(go,{preview:ie})]}),e(Bt,{className:`flex flex-wrap gap-2`,children:[i(W,{variant:`ghost`,onClick:t.onClose,children:r(`customize.scalar.cancel`)}),i(W,{"data-testid":`keyed-save-item`,disabled:!t.canSave||re===null||te===``,onClick:()=>{re!==null&&t.onSave(re,te)},children:r(`customize.keyed.save`)})]})]});function se(e,n){if(n.ok){if(N(`${e.cap}.${e.path}`),n.mode===`enum`){let n=vo(e.enumValues,So(t.cap,t.targetId,g));I(n),P({kind:`enum-map`,mapping:{...n}});return}P(_o(n))}}}function Eo(t){let{t:n}=q();return i(`div`,{className:`flex flex-col gap-1`,children:t.values.map(r=>e(`label`,{className:`flex flex-wrap items-center gap-2 text-xs text-foreground`,children:[r,i(U,{value:t.mapping[r]??``,options:[{value:``,label:n(`customize.keyed.unmapped`)},...t.outputs.map(e=>({value:e,label:n(`customize.keyed.value.${e}`)}))],onChange:e=>t.onChange({...t.mapping,[r]:e.target.value===``?null:e.target.value})})]},r))})}function Do(e,t,n,r,i){let a=Object.entries(r).map(([e,t])=>({path:e,value:t})),o=bo(e,t,n).flatMap(e=>i===``?[]:[{path:e,value:i}]);return[...a,...o]}function Oo(e,t,n,r,i){return e===null||t===null||n===null||!n.ok?null:n.mode===`enum`?Object.keys(r).length===0?null:{addonId:e.addonId,stableId:e.stableId,cap:t.cap,fieldPath:t.path,valueKind:`enum`,transform:{kind:`enum-map`,mapping:{...r}}}:{addonId:e.addonId,stableId:e.stableId,cap:t.cap,fieldPath:t.path,valueKind:`number`,transform:i}}function ko(e,t,n,r,i){if(e===null||r===null)return null;let a=e.items?.[t]?.fields[n];if(a===void 0)return{kind:`failed`,reason:`compile`};if(i===null)return{kind:`pending`};let o=J(i[r.cap],r.path);if(a.kind===`from`)return Ao(o);if(a.kind!==`expression`)return{kind:`failed`,reason:`compile`};let s=jo(o);if(s===void 0)return{kind:`failed`,reason:`no-value`};let c=j(a.expr,{x:s},Date.now());return c.ok?Ao(c.value):{kind:`failed`,reason:c.error}}function Ao(e){return typeof e==`number`&&Number.isFinite(e)?{kind:`value`,text:String(e)}:typeof e==`string`&&e.length>0?{kind:`value`,text:e}:{kind:`failed`,reason:`empty`}}function jo(e){if(typeof e==`number`||typeof e==`string`||typeof e==`boolean`)return e;if(e===null)return null}function Mo(e){if(e===null)return null;let t=e.indexOf(`.`);return t<=0?null:{cap:e.slice(0,t),path:e.slice(t+1)}}function No(e,t){return e===null?null:t.find(t=>t.addonId===e.source.addonId&&t.stableId===e.source.stableId)??null}var Po=`consumables`,Fo=`items`,Io=qe.shape.items;function Lo(e){let t=e.split(`.`).pop()??e,n=t.replace(/Level$/,``);return n===``?t:n}function Ro(e){let t=e.replace(/([a-z0-9])([A-Z])/g,`$1 $2`).toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)}function zo(e,t){return e.caps.filter(e=>t.has(e.cap)&&e.cap!==`consumables`).flatMap(e=>e.fields.filter(e=>e.item!==!0&&xt(e)).map(t=>({kind:`field`,key:Lo(t.path),cap:e.cap,path:t.path})))}function Bo(e){switch(e.kind){case`pending`:return{kind:`pending`};case`unknown`:return{kind:`unknown`,reason:e.reason};case`absent`:return{kind:`known`,value:[]};case`value`:{if(e.value===null)return{kind:`known`,value:[]};let t=Io.safeParse(e.value);return t.success?{kind:`known`,value:t.data.map(e=>({kind:`item`,key:e.key,item:e}))}:{kind:`unknown`,reason:t.error.message}}}}function Vo(e,t,n){if(e.kind!==`known`)return e;if(t.kind!==`known`)return t;let r=zo(t.value,e.value);if(!e.value.has(`consumables`)||n===null)return{kind:`known`,value:r};let i=Bo(n);return i.kind===`known`?{kind:`known`,value:[...r,...i.value]}:i}function Ho(e){return e.defaults.map(t=>t.kind===`field`?i(Uo,{deviceId:e.deviceId,entry:t},`field:${t.cap}.${t.path}`):i(Go,{entry:t},`item:${t.key}`))}function Uo(e){let{t}=q(),n=oa({deviceId:e.deviceId,cap:e.entry.cap,path:e.entry.path});return i(mo,{name:t(`customize.consumables.fields.${e.entry.key}`,{defaultValue:Ro(e.entry.key)}),detail:t(`customize.consumables.builtIn`),meta:t(`customize.assign.native`),value:null,readout:i(Wo,{value:n}),removeLabel:``})}function Wo(e){switch(e.value.kind){case`pending`:return i(la,{display:{text:`…`,tone:`muted`}});case`unknown`:return i(la,{display:{text:`?`,title:e.value.reason,tone:`warning`}});case`absent`:return i(Dt,{level:null,size:`sm`});case`value`:return i(Dt,{level:Ct(e.value.value),size:`sm`})}}function Go(e){let{t}=q(),{item:n}=e.entry,r=n.level===null?n.status===`replace`?t(`uiLibrary.consumablesPanel.replace`):void 0:`${Math.round(n.level)} %`;return i(mo,{name:n.label,detail:t(`customize.consumables.builtIn`),meta:t(`customize.assign.native`),value:null,readout:i(Dt,{level:yt(n),label:r,size:`sm`}),removeLabel:``})}s();var Ko={consumables:_};function qo(){return Object.entries(z).flatMap(([e,t])=>t.targets.filter(e=>e.cardinality===`keyedArray`).map(t=>({cap:e,target:t})))}function Jo(t){let{t:n,i18n:r}=q(),a=Qi(),[s,l]=o(null),[u,d]=o(null),f=Ri(t.handle.state),p=Ji(f,t.cap),m=Zo(t.handle,p),h=m.kind===`known`&&m.value!==null?Ge(m.value,t.cap,t.target.id):null,g=Fi(h!==null),_=Qo(h,g),v=ce({cap:t.cap,targetId:t.target.id,device:t.handle.target,stored:m,sourcePresence:_,sourceUnknownReason:g.kind===`unknown`?g.reason:null});if(!Xo(t,p))return null;let y=t.handle.state.kind===`none`||t.handle.state.kind===`present`,b=t.availability.kind===`present`&&y,x=n(`customize.keyed.title.${t.cap}`),S=ts(n,v.text,v.assignedCount),C=async e=>{let n=await t.handle.save(e);d(n.kind===`refused`?n.reason:null)},w=async e=>{if(f===null||p===null)return;let r=fe(p,e.key),i=r===null?qi(f,t.cap):Wi(f,t.handle.target,r);await a(n(`customize.consumables.removeWhat`,{name:e.label}),i===null)&&await C(i)},T=s!==null&&s!==`add`?es(h,s):null;return e(c,{children:[i(Mi,{id:t.cap,icon:Ko[t.cap],title:x,testId:`keyed-card-${t.cap}`,actions:i(Vt,{children:S}),children:e(`div`,{className:`flex flex-col gap-2 px-3 py-2 sm:px-4`,children:[t.defaults.kind===`known`&&i(Ho,{deviceId:t.device.id,defaults:t.defaults.value}),t.defaults.kind===`unknown`&&i(H,{title:n(`customize.consumables.builtIn`),message:n(`customize.consumables.builtInUnreadable`,{reason:t.defaults.reason})}),h?.items.map(e=>i(Yo,{deviceId:t.device.id,cap:t.cap,item:e,language:r.language,sourceName:$o(e,g),saving:t.handle.saving,onChange:()=>l(e.key),onRemove:()=>void w(e),handle:t.handle},e.key)),u!==null&&i(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:u}),b&&i(W,{variant:`outline`,size:`sm`,"data-testid":`keyed-add-${t.cap}`,disabled:t.handle.saving,onClick:()=>l(`add`),children:n(`customize.keyed.add`)})]})}),i(wo,{open:s!==null,mode:s===`add`?`add`:`change`,cap:t.cap,targetId:t.target.id,host:t.device,target:t.handle.target,apply:`add`,seed:T,canSave:y&&!t.handle.saving,onClose:()=>l(null),onSave:(e,r)=>{if(s===`add`&&p?.items!==void 0&&p.items[r]!==void 0){d(n(`customize.keyed.duplicateKey`,{key:r}));return}let i=Ue(p,e,r);l(null),i!==null&&(d(null),C(Wi(f,t.handle.target,i)))}})]})}function Yo(t){let{t:n}=q(),r=t.item.compile,a=t.item.recognized&&r!==null,o=r===null?``:Y(r.draft.source.cap,r.draft.source.fieldPath,t.language),s=a?[t.sourceName??``,o].filter(e=>e.length>0).join(` · `):n(`customize.consumables.otherFormula`),c=r===null?null:oe(we,t.item.key,r.draft.fieldPath);return e(`div`,{className:`flex flex-col gap-1`,"data-testid":`keyed-row-${t.item.key}`,children:[i(mo,{name:t.item.label,detail:s,meta:a?n(`customize.keyed.assigned`):null,value:c===null?null:{deviceId:t.deviceId,cap:t.cap,path:c},readout:c===null?null:i(ca,{target:{deviceId:t.deviceId,cap:t.cap,path:c}}),removeLabel:``}),e(`div`,{className:`flex flex-wrap gap-2`,children:[a&&i(W,{variant:`outline`,size:`sm`,disabled:t.saving,onClick:t.onChange,children:n(`customize.keyed.change`)}),a&&i(W,{variant:`ghost`,size:`sm`,disabled:t.saving,onClick:t.onRemove,children:n(`customize.keyed.remove`)}),!a&&i(po,{handle:t.handle,cap:t.cap,itemKey:t.item.key,fieldPath:`status`})]})]})}function Xo(e,t){return e.target.deviceTypes.includes(e.device.type)?e.availability.kind!==`absent`||e.defaults.kind!==`known`||e.defaults.value.length>0?!0:t!==null:!1}function Zo(e,t){return e.state.kind===`pending`?{kind:`pending`}:e.state.kind===`unknown`||e.state.kind===`not-loaded`?{kind:`unknown`,reason:e.state.reason}:{kind:`known`,value:t}}function Qo(e,t){let n=(e?.items??[]).filter(e=>e.recognized&&e.compile!==null);return n.length===0?`present`:t.kind===`pending`?`pending`:t.kind===`unknown`?`unknown`:n.every(e=>{let n=e.compile?.draft.source;if(n===void 0)return!1;let r=V(n);return t.value.some(e=>V({addonId:e.addonId,stableId:e.stableId})===r)})?`present`:`absent`}function $o(e,t){let n=e.compile?.draft.source;if(n===void 0||t.kind!==`known`)return null;let r=V(n);return t.value.find(e=>V({addonId:e.addonId,stableId:e.stableId})===r)?.name??null}function es(e,t){let n=e?.items.find(e=>e.key===t),r=n?.compile;return n===void 0||r==null?null:{key:n.key,label:n.label,fieldPath:r.draft.fieldPath,literals:r.literals,source:{addonId:r.draft.source.addonId,stableId:r.draft.source.stableId,cap:r.draft.source.cap,fieldPath:r.draft.source.fieldPath,valueKind:r.sourceValueKind},transform:r.draft.transform}}function ts(e,t,n){return t===`Native`?e(`customize.keyed.badge.native`):t===`pending`?e(`customize.keyed.badge.pending`):t===`unknown`?e(`customize.keyed.badge.unknown`):t.endsWith(`assigned`)?e(`customize.keyed.badge.assigned`,{count:n}):t}function ns(e){return i(c,{children:qo().map(t=>t.target.deviceTypes.includes(e.device.type)?i(Jo,{device:e.device,handle:e.handle,availability:uo(oo(t.cap,t.target),e.facts),cap:t.cap,target:t.target,defaults:e.defaults},t.cap):null)})}function rs(e){let t=Rn(e);if(t===null)return{kind:`failed`,reason:Yn};if(e.transform.kind===`threshold`)return is(e.transform,e);let n=rr(e.cap,e.targetId),r=n===null?void 0:t.fields[n];if(r===void 0)return{kind:`failed`,reason:Yn};if(r.kind===`from`)return os(e.sourceValue);if(r.kind!==`expression`)return{kind:`failed`,reason:Yn};if(r.expr.startsWith(`dwell(`))return{kind:`failed`,reason:Xn};let i=as(e.sourceValue);if(i===void 0)return{kind:`failed`,reason:Zn};let a=j(r.expr,{x:i},e.nowMs);return a.ok?os(a.value):{kind:`failed`,reason:a.error}}function is(e,t){if(typeof t.sourceValue!=`number`||!Number.isFinite(t.sourceValue))return{kind:`failed`,reason:Zn};let n=e.comparison===`gte`?t.sourceValue>=e.threshold:t.sourceValue<=e.threshold,r=t.source.sourceUnit;return{kind:`dwell`,sourceText:r===null?String(t.sourceValue):`${t.sourceValue} ${r}`,active:n,countdownMs:n?e.startDwellMs:e.stopDwellMs}}function as(e){if(typeof e==`number`||typeof e==`string`||typeof e==`boolean`)return e;if(e===null)return null}function os(e){return e==null||typeof e==`number`&&!Number.isFinite(e)?{kind:`failed`,reason:Qn}:typeof e==`number`||typeof e==`string`||typeof e==`boolean`?{kind:`value`,text:String(e)}:{kind:`failed`,reason:Qn}}s();function ss(t){let{t:n}=q(),r=t.mode===`change`?n(`customize.scalar.changeTitle`,{title:t.title}):n(`customize.scalar.addTitle`,{title:t.title});return i(Gt,{open:t.open,onOpenChange:e=>e?void 0:t.onClose(),children:e(rn,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":r,children:[i(an,{children:i(At,{children:r})}),t.open&&i(cs,{...t,heading:r})]})})}function cs(t){let{t:r}=q(),a=Tt({projection:`slim`}),s=n(()=>a.status===`success`?gn(a.data):[],[a.status,a.data]),l=ds(t.seed,s),[u,d]=o(null),[f,p]=o(!1);!f&&l!==null&&(d(l),p(!0));let m=qt({deviceId:u?.id??0}),h=Yt({deviceId:u?.id??0}),g=m.status===`success`?m.data:{caps:[]},_=ir(g,h.status===`success`?h.data:null),[v,y]=o(fs(t.seed)),[b,x]=o(t.seed?.transform??{kind:`identity`}),S=v===null?null:(()=>{let[e,t]=v.split(`.`);return e===void 0||t===void 0?null:{cap:e,path:t}})(),C=_.find(e=>ls(e)===v)??null,w=C===null?null:cr(t.cap,t.targetId,C),T=C===null||w===null||!w.ok?null:us(u,C,w,g),E=T===null?null:Rn({cap:t.cap,targetId:t.targetId,device:t.target,apply:t.apply,source:T,transform:b}),D=C===null||h.status!==`success`||u===null?void 0:J(h.data[C.cap],C.path),O=T===null?null:h.status===`pending`?{kind:`pending`}:rs({cap:t.cap,targetId:t.targetId,device:t.target,apply:t.apply,source:T,transform:b,sourceValue:D,nowMs:Date.now()});return e(c,{children:[e(zt,{className:`flex flex-col gap-3 p-2 sm:p-4`,children:[i(Ei,{kind:`scalar`,enabled:t.open,hostId:t.host.id,destination:{cap:t.cap,targetId:t.targetId,title:t.title},device:u,field:S,transform:b,onDeviceChange:e=>{d(e),y(null),x({kind:`identity`})},onFieldChange:e=>{if(e===null){y(null);return}y(`${e.cap}.${e.path}`)},onTransformChange:x}),O!==null&&i(go,{preview:O})]}),e(Bt,{className:`flex flex-wrap gap-2`,children:[i(W,{variant:`ghost`,onClick:t.onClose,children:r(`customize.scalar.cancel`)}),i(W,{"data-testid":`scalar-save-override`,disabled:!t.canSave||E===null,onClick:()=>{E!==null&&t.onSave(E)},children:r(`customize.scalar.save`)})]})]})}function ls(e){return`${e.cap}.${e.path}`}function us(e,t,n,r){if(e===null||t.kind!==`boolean`&&t.kind!==`number`&&t.kind!==`string`)return null;let i=r.caps.find(e=>e.cap===t.cap),a=t.kind===`boolean`&&i?.fields.some(e=>e.path===`lastChangedAt`)?`lastChangedAt`:null;return{addonId:e.addonId,stableId:e.stableId,cap:t.cap,fieldPath:t.path,valueKind:t.kind,sourceUnit:n.sourceUnit,changedAtField:a}}function ds(e,t){return e===null?null:t.find(t=>t.addonId===e.source.addonId&&t.stableId===e.source.stableId)??null}function fs(e){return e===null?null:`${e.source.cap}.${e.source.fieldPath}`}var ps=`Assigned · `;function ms(e,t){if(e===`Native`)return{kind:`native`};if(e===`Native · source missing`)return{kind:`released`};if(e===`pending`)return{kind:`pending`};if(e===`unknown`)return{kind:`unknown`};if(e.startsWith(ps)){let n=e.slice(11);return{kind:`assigned`,source:t??n}}return{kind:`unknown`}}s();var hs={id:0,name:``,type:`unknown`,stableId:``,parentDeviceId:null},gs={battery:d,"running-state":v,"power-meter":S};function _s(){return Object.entries(z).flatMap(([e,t])=>t.targets.filter(e=>e.cardinality===`scalar`).map(t=>({cap:e,target:t})))}function vs({device:t,handle:n,availability:r,cap:a,target:s}){let{t:l,i18n:u}=q(),d=Qi(),[f,p]=o(!1),[m,h]=o(null),g=re(a)>1,_=s.path??s.id,v=l(`customize.scalar.caps.${a}`),y=g?`${v} · ${Y(a,_,u.language)}`:v,b=g?`${a}.${s.id}`:a,x=Ri(n.state),S=bs(n,ue(Ji(x,a),a,s.id)),C=S.kind===`known`&&S.value!==null?me({feature:S.value,device:n.target,cap:a,targetId:s.id}):null,w=C!==null,T=Fi(w),D=C===null||T.kind!==`known`?null:T.value.find(e=>V({addonId:e.addonId,stableId:e.stableId})===V(C.draft.source))??null,O=vt(D===null?hs:Ir(D),`compact`),k=D===null?null:O,A=vt(t,`full`),j=xs(w,T.kind,D!==null),M=E({cap:a,targetId:s.id,device:n.target,stored:S,sourcePresence:j,sourceUnknownReason:T.kind===`unknown`?T.reason:null}),N=ms(M.text,k),ee=n.state.kind===`none`||n.state.kind===`present`,P=r.kind===`present`?r.mode:null;if(r.kind===`absent`||!s.deviceTypes.includes(t.type))return null;let F=async e=>{let t=await n.save(e);h(t.kind===`refused`?t.reason:null)},I=async()=>{if(x===null)return;let e=Ki(x,a,s.id);await d(l(`customize.scalar.removeWhat`,{name:k??(C===null?A:V(C.draft.source))}),e===null)&&await F(e)},L=C===null?null:{source:{addonId:C.draft.source.addonId,stableId:C.draft.source.stableId,cap:C.draft.source.cap,fieldPath:C.draft.source.fieldPath,valueKind:C.sourceValueKind,sourceUnit:C.sourceUnit,changedAtField:C.changedAtField},transform:C.draft.transform},R=N.kind===`assigned`?l(`customize.scalar.badge.assigned`,{source:N.source}):l(`customize.scalar.badge.${N.kind}`);return e(c,{children:[i(Mi,{id:b,icon:gs[a],title:y,testId:`scalar-card-${b}`,actions:i(Vt,{children:R}),children:i(ys,{availability:r,answered:ee,deviceId:t.id,cap:a,cardKey:b,path:_,recognized:w,stored:S,presence:j,released:M.status.state===`released`,sourceName:k,sourceCap:C?.draft.source.cap??``,sourceField:C===null?``:Y(C.draft.source.cap,C.draft.source.fieldPath,u.language),sourcePath:C?.draft.source.fieldPath??``,sourceDeviceId:D?.id??null,error:m,saving:n.saving,mode:P,onOpen:()=>p(!0),onRemove:()=>void I(),handle:n})}),P!==null&&i(ss,{open:f,mode:L===null?`add`:`change`,title:y,cap:a,targetId:s.id,host:t,target:n.target,apply:P,seed:L,canSave:ee&&!n.saving,onClose:()=>p(!1),onSave:e=>{p(!1),F(Gi(x,n.target,e,a,s.id))}})]})}function ys(t){let{t:n}=q();if(t.availability.kind===`pending`||t.availability.kind===`present`&&!t.answered)return i(`p`,{role:`status`,className:`px-3 py-2 text-xs text-foreground-subtle sm:px-4`,children:n(`customize.scalar.checking`)});if(t.availability.kind===`unknown`)return i(`div`,{className:`px-3 py-2 sm:px-4`,children:i(H,{title:n(`customize.scalar.unreadable`),message:t.availability.reason})});let r=t.stored.kind===`known`&&t.stored.value===null,a=!t.recognized&&t.stored.kind===`known`&&t.stored.value!==null;return e(`div`,{className:`flex flex-col gap-2 px-3 py-2 sm:px-4`,children:[e(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2`,children:[i(`span`,{className:`text-xs text-foreground`,children:n(`customize.scalar.effective`)}),i(ca,{target:{deviceId:t.deviceId,cap:t.cap,path:t.path}})]}),t.released&&i(`p`,{className:`text-xs text-foreground`,children:n(`customize.scalar.released`)}),t.presence===`unknown`&&t.recognized&&i(H,{title:n(`customize.scalar.sourceUnreadable`),message:n(`customize.scalar.sourceHeld`,{name:t.sourceName??t.sourceCap})}),t.recognized&&!t.released&&e(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2`,children:[i(`span`,{className:`text-xs text-foreground`,children:n(`customize.scalar.override`,{name:t.sourceName??`…`,field:t.sourceField})}),t.sourceDeviceId!==null&&i(ca,{target:{deviceId:t.sourceDeviceId,cap:t.sourceCap,path:t.sourcePath}})]}),a&&e(`p`,{className:`text-xs text-foreground flex flex-wrap items-center gap-1`,children:[n(`customize.scalar.otherFormula`),i(po,{handle:t.handle,cap:t.cap,fieldPath:t.path})]}),r&&i(`p`,{className:`text-xs text-foreground-subtle`,children:n(`customize.scalar.noOverride`)}),t.error!==null&&i(`p`,{role:`alert`,className:`text-xs text-danger break-words`,children:t.error}),e(`div`,{className:`flex flex-wrap gap-2`,children:[t.recognized&&i(W,{variant:`outline`,size:`sm`,"data-testid":`scalar-change-${t.cardKey}`,onClick:t.onOpen,disabled:t.saving,children:t.released?n(`customize.scalar.chooseAnother`):n(`customize.scalar.change`)}),t.recognized&&i(W,{variant:`ghost`,size:`sm`,onClick:t.onRemove,disabled:t.saving,children:n(`customize.scalar.remove`)}),r&&i(W,{variant:`outline`,size:`sm`,"data-testid":`scalar-add-${t.cardKey}`,disabled:t.saving||t.mode===null,onClick:t.onOpen,children:n(`customize.scalar.add`)})]})]})}function bs(e,t){return e.state.kind===`pending`?{kind:`pending`}:e.state.kind===`unknown`||e.state.kind===`not-loaded`?{kind:`unknown`,reason:e.state.reason}:{kind:`known`,value:t}}function xs(e,t,n){return e?t===`pending`?`pending`:t===`unknown`?`unknown`:n?`present`:`absent`:`present`}function Ss({device:e,handle:t,facts:n}){return i(c,{children:_s().map(r=>r.target.deviceTypes.includes(e.type)?i(vs,{device:e,handle:t,availability:uo(oo(r.cap,r.target),n),cap:r.cap,target:r.target},`${r.cap}.${r.target.id}`):null)})}var Cs=P(Ye);function ws(e){return Ye.find(t=>t.name===e)??null}function Ts(e,t){let n=t.commands??{},r=le(e),i=e=>{let t=n[e];return t!==void 0&&t.kind===`forward`?t:null},a=r.map(e=>({id:e,kind:`method`,method:e,itemKey:null,command:i(e),orphan:!1})),o=Object.entries(t.items??{}).map(([e,t])=>({id:`items.${e}.reset`,kind:`reset`,method:`reset`,itemKey:e,command:t.reset??null,orphan:!1})),s=Object.keys(n).filter(e=>!r.includes(e)).map(e=>({id:e,kind:`method`,method:e,itemKey:null,command:i(e),orphan:!0}));return[...a,...o,...s]}function Es(e,t,n){if(t.kind===`reset`&&t.itemKey!==null){let r=e.items?.[t.itemKey];if(r===void 0||e.items===void 0)return e;let{reset:i,...a}=r,o=n===null?a:{...a,reset:n};return{...e,items:{...e.items,[t.itemKey]:o}}}let r=e.commands??{};if(n!==null)return{...e,commands:{...r,[t.method]:n}};let i=Object.fromEntries(Object.entries(r).filter(([e])=>e!==t.method));if(Object.keys(i).length>0)return{...e,commands:i};let{commands:a,...o}=e;return o}function Ds(e,t,n){return{at:e.kind===`reset`?`features[${t}].items.${e.itemKey}.reset`:`features[${t}].commands.${e.method}`,method:e.method,...e.itemKey===null?{}:{itemKey:e.itemKey},command:n}}function Os(e,t,n,r,i){let a=r.orphan&&r.kind===`method`?ne(e,t,`features[${n}]`).filter(e=>e.path===`features[${n}].commands.${r.method}`):[];return i===null?a:[...a,...xe(e,Ds(r,n,i),Cs)]}function ks(e,t){return Ts(e,t).filter(e=>e.kind===`method`&&!e.orphan&&e.command===null).map(e=>e.method)}function As(e){return Object.entries(e.methods).filter(([,e])=>e.kind===`mutation`&&e.systemOnly!==!0).map(([e])=>e)}function js(e){let t=new Set(e);return Ye.filter(e=>t.has(e.name)&&As(e).length>0)}function Ms(e){let t=ee(e);return t instanceof st?`boolean`:t instanceof it?`number`:t instanceof at||t instanceof lt?`string`:`structured`}function Ns(e,t){let n=e.methods[t]?.input;if(n===void 0)return[];let r=ee(n);return r instanceof ct?Object.entries(r.shape).filter(([e])=>e!==L).flatMap(([e,t])=>t instanceof ot?[{name:e,required:!t.safeParse(void 0).success,type:Ms(t)}]:[]):[]}function Ps(e){return typeof e==`object`?ye(e)?{kind:`input`,field:e.$input}:{kind:`structured`,value:e}:{kind:`constant`,value:e}}function Fs(e){return e.kind===`input`?{$input:e.field}:e.value}function Is(e,t,n){let r=Object.fromEntries(Object.entries(e).filter(([e])=>e!==t));return n===void 0?r:{...r,[t]:n}}function Ls(e,t){return t.includes(e.name)?{kind:`input`,field:e.name}:e.type===`boolean`?{kind:`constant`,value:!0}:e.type===`number`?{kind:`constant`,value:0}:e.type===`string`?{kind:`constant`,value:``}:{kind:`structured`,value:{}}}function Rs(e){try{let t=JSON.parse(e),n=Ee.safeParse(t);return n.success?n.data:null}catch{return null}}var zs={source:null,cap:``,method:``,args:void 0};function Bs(e){return e===null?zs:{source:e.source,cap:e.cap,method:e.method,args:e.args}}function Vs(e){return e.source===null||e.cap===``||e.method===``?null:{kind:`forward`,source:e.source,cap:e.cap,method:e.method,...e.args===void 0?{}:{args:e.args}}}function Hs(e,t){let n=V(t);return e.find(e=>V({addonId:e.addonId,stableId:e.stableId})===n)??null}function Us(e,t=new Set){return e.filter(e=>e.type!==I.Container&&!t.has(V({addonId:e.addonId,stableId:e.stableId}))).map(e=>({deviceId:e.id,ref:{addonId:e.addonId,stableId:e.stableId},name:e.name,detail:mn(e.integration,e.location),meta:e.type,caps:[],value:null})).toSorted((e,t)=>e.name.localeCompare(t.name))}function Ws(e,t,n){if(t===null)return null;let r=Hs(e,t);if(r===null)return null;let i=new Map(e.map(e=>[e.id,e])),a=r.parentDeviceId===null||r.parentDeviceId===void 0?void 0:i.get(r.parentDeviceId),o=e=>{if(e.type===I.Container)return!1;if(a!==void 0)return e.parentDeviceId===a.id;let t=r.location??``;return t!==``&&e.location===t},s=a?.name??r.location??``,c=new Set(e.filter(e=>o(e)&&(n||e.id!==r.id)).map(e=>e.id));return c.size===0||s===``?null:{location:s,ids:c,containers:new Map([...c].flatMap(e=>{let t=i.get(e)?.parentDeviceId,n=t==null?void 0:i.get(t);return n!==void 0&&n.type===I.Container?[[e,n.name]]:[]}))}}function Gs(e,t){if(e.kind!==`known`||typeof t!=`string`||t.length===0)return null;let n=Ut(e.value,t),r=new Map(e.value.map(e=>[e.id,e])),i=new Map;for(let e of n){let t=r.get(e)?.parentDeviceId,n=t==null?void 0:r.get(t);n!==void 0&&n.type===`container`&&i.set(e,n.name)}return{location:t,ids:n,containers:i}}function Ks(e,t,n){return nn(e,t?.ids??new Set,n)}function qs(e,t){return e?.containers.get(t)??null}function Js(e,t,n){return e.kind===`known`?Ks(e.value,t,n).suggested.length:0}s();function Ys(e){return e.kind===`pending`?`pending`:e.kind===`unknown`?`failed`:`answered`}function Xs(e){return e.map(e=>({id:e.deviceId,name:e.name,...e.meta===null?{}:{type:e.meta},...e.detail===null?{}:{location:e.detail.includes(` · `)?e.detail.split(` · `).at(-1)??null:e.detail},...e.detail===null?{}:{detail:e.detail}}))}function Zs({open:t,title:r,selection:s,candidates:c,filters:l,room:u=null,confirmLabel:d,onConfirm:f,onClose:p}){let{t:m}=q(),[h,g]=o(null),[_,v]=o([]),y=l?.find(e=>e.id===h)??l?.[0]??null,b=c.kind===`known`?c.value:[],x=c.kind===`known`?pn(c.value,``,y):[],S=Ks(b,u,e=>e.deviceId).suggested,C=Ks(x,u,e=>e.deviceId).others,w=n(()=>Xs(C),[C]),T=Ys(c),E=b.filter(e=>_.includes(e.deviceId));a(()=>{t||(v([]),g(null))},[t]);let D=()=>{v([]),g(null),p()},O=e=>{e.length!==0&&(f(e),v([]),g(null))},k=()=>O(E);return i(Gt,{open:t,onOpenChange:e=>e?void 0:D(),children:e(rn,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"aria-label":r,children:[i(an,{children:i(At,{children:r})}),e(zt,{className:`flex flex-col gap-2 p-2 sm:p-4`,children:[l!==void 0&&l.length>0&&i(`div`,{className:`flex flex-wrap gap-1`,role:`tablist`,"aria-label":m(`customize.assign.filtersLabel`),children:l.map(e=>i(`button`,{type:`button`,role:`tab`,"aria-selected":(y?.id??null)===e.id,className:`inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${(y?.id??null)===e.id?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:bg-surface-hover`}`,onClick:()=>g(e.id),children:m(e.labelKey)},e.id))}),u!==null&&i(xn,{location:u.location,devices:S.map(e=>({id:e.deviceId,name:e.name,container:qs(u,e.deviceId),detail:e.detail})),action:`add`,onPick:e=>O(S.filter(t=>t.deviceId===e)),...s===`multi`?{onPickAll:()=>O(S)}:{}}),c.kind===`unknown`?i(`p`,{role:`alert`,className:`text-xs text-warning`,children:m(`customize.assign.unknown`,{reason:c.reason})}):w.length===0&&S.length>0?null:i(gt,{devices:w,listState:T,value:_,onChange:e=>v(s===`single`?e.length>0?[e[e.length-1]]:[]:e),noun:`device`,emptyLabel:m(`customize.assign.none`),showAll:!0,testId:`customize-device-picker`})]}),e(Bt,{children:[i(W,{variant:`ghost`,onClick:D,children:m(`customize.picker.cancel`)}),i(W,{disabled:E.length===0,onClick:k,children:d(E.length)})]})]})})}s();function Qs({builtFields:t,sourceFields:n,args:r,onChange:a,testId:o}){let{t:s}=q();if(n.length===0)return null;let c=r!==void 0,l=()=>Object.fromEntries(n.filter(e=>e.required).map(e=>[e.name,Fs(Ls(e,t))]));return e(`div`,{className:`flex flex-col gap-2`,"data-testid":o,children:[i(en,{checked:!c,onCheckedChange:e=>a(e?void 0:l()),label:s(`commands.args.passThrough`),className:`text-[11px] text-foreground`}),c&&i(`ul`,{className:`flex flex-col gap-2`,"aria-label":s(`commands.args.template`),children:n.map(e=>i($s,{field:e,builtFields:t,arg:r[e.name],onChange:t=>a(Is(r,e.name,t))},e.name))})]})}function $s({field:t,builtFields:n,arg:r,onChange:a}){let{t:o}=q(),s=r===void 0?null:Ps(r),c=s===null?`unset`:s.kind,l=[...t.required?[]:[`unset`],...n.length>0?[`input`]:[],...t.type===`structured`?[]:[`constant`],`structured`],u=e=>{if(e===`unset`)return a(void 0);let r=l.find(t=>t===e);if(r===void 0||r===`unset`)return;let i=Ls(t,n);if(r===i.kind)return a(Fs(i));if(r===`input`)return a({$input:n[0]??``});if(r===`constant`)return a(ec(t));a({})};return e(`li`,{className:`grid grid-cols-1 gap-1 sm:grid-cols-[8rem_10rem_1fr] sm:items-start`,children:[e(`span`,{className:`font-mono text-[11px] text-foreground-muted break-words`,children:[t.name,t.required?` *`:``]}),l.length>1?i(U,{"aria-label":o(`commands.args.kind`,{field:t.name}),value:c,onChange:e=>u(e.target.value),options:l.map(e=>({value:e,label:o(`commands.args.kinds.${e}`)}))}):i(`span`,{className:`text-[11px] text-foreground-muted`,children:o(`commands.args.kinds.${l[0]??`structured`}`)}),i(tc,{field:t,builtFields:n,choice:s,onChange:a})]})}function ec(e){return e.type===`boolean`?!0:e.type===`number`?0:``}function tc({field:e,builtFields:t,choice:n,onChange:r}){let{t:a}=q();return n===null?i(`span`,{className:`text-[11px] text-foreground-subtle`,children:a(`commands.args.omitted`)}):n.kind===`input`?i(U,{"aria-label":a(`commands.args.fromInput`,{field:e.name}),value:n.field,onChange:e=>r({$input:e.target.value}),options:t.map(e=>({value:e,label:e}))}):n.kind===`structured`?i(nc,{field:e,value:n.value,onChange:r}):e.type===`boolean`?i(U,{"aria-label":a(`commands.args.constant`,{field:e.name}),value:String(n.value===!0),onChange:e=>r(e.target.value===`true`),options:[{value:`true`,label:a(`commands.args.true`)},{value:`false`,label:a(`commands.args.false`)}]}):i(G,{"aria-label":a(`commands.args.constant`,{field:e.name}),type:e.type===`number`?`number`:`text`,value:String(n.value),onChange:t=>{if(e.type!==`number`)return r(t.target.value);let n=Number(t.target.value);t.target.value!==``&&!Number.isNaN(n)&&r(n)}})}function nc({field:t,value:n,onChange:r}){let{t:a}=q(),[s,c]=o(JSON.stringify(n)),l=Rs(s)===null;return e(`div`,{className:`flex flex-col gap-1`,children:[i(G,{"aria-label":a(`commands.args.structured`,{field:t.name}),value:s,className:`font-mono`,onChange:e=>{c(e.target.value);let t=Rs(e.target.value);t!==null&&r(t)}}),l&&i(`p`,{role:`alert`,className:`text-[11px] text-danger`,children:a(`commands.args.invalidStructured`)})]})}var rc=[`threshold`,`sum`,`difference`,`ratio`,`expression`,`derivative`],ic=[`threshold`,`difference`,`ratio`,`derivative`];function ac(){return ic}function oc(e){return rc.some(t=>t===e)}function sc(e){return e===`sum`||e===`difference`||e===`ratio`?{kind:`arithmetic`,op:e}:{kind:e}}var cc=[`temperature`,`humidity`,`pressure`,`illuminance`,`power`,`energy`,`battery`,`numeric`],lc=[`motion`,`contact`,`leak`,`smoke`,`occupancy`,`binary`],uc=be,dc=[nt],fc=`was refused — `,pc=/^(.+?) \[([a-z0-9-]+)\]: (.+)$/;function mc(){return[{id:`readings`,templateIds:cc},{id:`binary`,templateIds:lc},{id:`actuators`,templateIds:uc},{id:`appliances`,templateIds:dc}]}var hc={appliance:null,thresholdWatts:0,startDwellMs:0,stopDwellMs:0};function gc(e){if(e===`appliance`){let t=Pe.washer;return{kind:`group`,templateId:e,aggregate:`any`,active:null,appliance:`washer`,thresholdWatts:t.thresholdWatts,startDwellMs:t.startDwellMs,stopDwellMs:t.stopDwellMs,name:``,room:``,members:[]}}let t=B(e);return t===null?null:{kind:`group`,templateId:e,aggregate:t.defaultAggregate,active:t.family===`actuator`?`at-least-one`:null,...hc,name:``,room:``,members:[]}}function _c(e){return e.kind===`group`?gc(e.templateId):e.kind===`appliance`?gc(nt):e.kind===`statistic`?{kind:`statistic`,stat:`mean`,window:{kind:`rolling`,span:`24h`},name:``,room:``,source:null}:e.kind===`threshold`?{kind:`threshold`,high:0,low:0,onForMs:0,offForMs:0,name:``,room:``,source:null}:e.kind===`arithmetic`?{kind:`arithmetic`,op:e.op,name:``,room:``,inputs:[]}:e.kind===`expression`?{kind:`expression`,expr:``,output:`number`,name:``,room:``,inputs:[]}:e.kind===`derivative`?{kind:`derivative`,window:{kind:`rolling`,span:`1h`},per:`hour`,name:``,room:``,source:null}:{kind:`integral`,reset:`daily`,name:``,room:``,source:null}}function vc(e,t,n){if(e.kind===`appliance`)return{kind:`group`,templateId:nt,aggregate:`any`,active:null,appliance:e.appliance,thresholdWatts:e.thresholdWatts,startDwellMs:e.startDwellMs,stopDwellMs:e.stopDwellMs,name:t,room:n,members:[X(e.member)]};if(e.kind===`statistic`)return{kind:`statistic`,stat:e.stat,window:e.window,name:t,room:n,source:X(e.source)};if(e.kind===`integral`)return{kind:`integral`,reset:e.reset,name:t,room:n,source:X(e.source)};if(e.kind===`threshold`)return{kind:`threshold`,high:e.high,low:e.low,onForMs:e.onForMs,offForMs:e.offForMs,name:t,room:n,source:X(e.source)};if(e.kind===`arithmetic`)return{kind:`arithmetic`,op:e.op,name:t,room:n,inputs:e.inputs.map(X)};if(e.kind===`expression`)return{kind:`expression`,expr:e.expr,output:e.output,name:t,room:n,inputs:e.inputs.map(e=>({name:e.name,member:X(e.member)}))};if(e.kind===`derivative`)return{kind:`derivative`,window:tl(e.window),per:e.per,name:t,room:n,source:X(e.source)};let r=B(e.templateId);return r===null||!r.aggregates.includes(e.aggregate)||r.family===`actuator`&&e.active===void 0||r.family!==`actuator`&&e.active!==void 0?null:{kind:`group`,templateId:e.templateId,aggregate:e.aggregate,active:e.active??null,...hc,name:t,room:n,members:e.members.map(X)}}function yc(e){return e.helper!==void 0}function bc(e,t){if(e.templateId===`appliance`)return e;let n=B(e.templateId);return n===null||!n.aggregates.includes(t)?e:{...e,aggregate:t}}function xc(e,t){if(e.templateId===`appliance`)return e;let n=B(e.templateId);return n===null||n.family!==`actuator`?e:{...e,active:t,aggregate:de(t)}}function Sc(e,t){return{...e,name:t}}function Cc(e,t){return t===e.templateId?e:gc(t)??e}function wc(e,t){if(e.templateId!==`appliance`)return e;let n=Pe[t];return{...e,appliance:t,thresholdWatts:n.thresholdWatts,startDwellMs:n.startDwellMs,stopDwellMs:n.stopDwellMs}}function Tc(e){if(e.kind===`statistic`||e.kind===`integral`)return Ae(e.kind);if(e.kind===`threshold`)return ke(`threshold`);if(e.kind===`arithmetic`)return ke(e.op);if(e.kind===`expression`)return ke(`expression`);if(e.kind===`derivative`)return ke(`derivative`);if(e.templateId===`appliance`)return Fe();let t=B(e.templateId);return t===null?null:Me(t)}function Ec(e){return e.kind===`statistic`?Yc(e):e.kind===`integral`?Xc(e):e.kind===`threshold`?Zc(e):e.kind===`arithmetic`?Qc(e):e.kind===`expression`?$c(e):e.kind===`derivative`?el(e):e.templateId===`appliance`?Dc(e):Oc(e)}function Dc(e){let t=e.members[0];return t===void 0||e.appliance===null?null:{kind:`appliance`,templateId:nt,appliance:e.appliance,thresholdWatts:e.thresholdWatts,startDwellMs:e.startDwellMs,stopDwellMs:e.stopDwellMs,member:X(t)}}function Oc(e){if(e.templateId===`appliance`)return null;let t=B(e.templateId)?.family===`actuator`&&e.active!==null;return{kind:`group`,templateId:e.templateId,aggregate:t&&e.active!==null?de(e.active):e.aggregate,...t&&e.active!==null?{active:e.active}:{},members:e.members.map(X)}}var kc={code:`member-constraint`,path:`helper.member`,message:`an appliance helper needs one power reading`},Ac={code:`member-constraint`,path:`helper.source`,message:`pick one reading that declares history`},jc={code:`member-constraint`,path:`helper.source`,message:`pick one reading`},Mc={code:`member-constraint`,path:`helper.inputs`,message:`pick the readings this helper combines`};function Nc(e){return e.kind===`group`?e.templateId===`appliance`?kc:Mc:e.kind===`threshold`?jc:e.kind===`arithmetic`||e.kind===`expression`?Mc:Ac}function Pc(e){let t=Ec(e);return t===null?{ok:!1,problems:[Nc(e)]}:ge(t)}async function Fc(e,t){let n=Pc(e);if(!n.ok)return Lc(n.problems);try{return await t(n.composition,e.name.trim()),[]}catch(e){return Rc(e instanceof Error?e.message:String(e))}}function Ic(e){return e.kind===`statistic`||e.kind===`integral`||e.kind===`derivative`?e.source!==null:e.kind===`threshold`?e.source!==null&&e.low<=e.high:e.kind===`arithmetic`?e.op===`sum`?e.inputs.length>=2:e.inputs.length===2:e.kind===`expression`?e.inputs.length>=1&&e.expr.trim()!==``:e.templateId===`appliance`?e.members.length===1:e.members.length>=1&&e.members.length<=64}function Lc(e){return e.map(e=>({path:e.path,code:e.code,message:e.message}))}function Rc(e){let t=e.indexOf(fc),n=(t===-1?e:e.slice(t+14)).split(/; (?=[^;]*\[[a-z0-9-]+\]:)/).flatMap(ll);return n.length>0?n:[{path:``,code:`refused`,message:e}]}function zc(e,t){if(e.kind===`pending`)return{kind:`pending`};if(e.kind===`error`)return{kind:`unavailable`,message:e.message};let n=e.caps[t.outputCap];if(n===void 0)return{kind:`empty`};let r=n[t.outputField];return typeof r==`number`&&Number.isFinite(r)?{kind:`number`,value:r,unit:t.baseUnit}:typeof r==`boolean`?{kind:`boolean`,value:r}:{kind:`empty`}}function Bc(e){if(e.kind===`pending`)return{kind:`pending`};if(e.kind===`error`)return{kind:`unavailable`,message:e.message};let t=e.caps[`group-status`];if(t===void 0)return{kind:`absent`};let n=cl(t.included),r=cl(t.excluded),i=cl(t.total);return n===null||r===null||i===null?{kind:`absent`}:{kind:`ready`,included:n,excluded:r,total:i}}function Vc(e,t){if(t.length===0||t.some(e=>e.kind===`pending`))return{kind:`pending`};if(t.some(e=>e.kind===`error`)||!Hc(e))return{kind:`unavailable`};let n=t.flatMap(e=>e.kind===`ready`?[e]:[]),r=Re(e,n),i=e===`light`&&r.some(e=>e.cap===`color`)?pe(n.map(e=>e.features)):T(e,n.map(e=>e.features));return{kind:`ready`,methods:r.map(e=>`${e.cap}.${e.method}`),modes:[...i]}}function Hc(e){return be.some(t=>t===e)}function Uc(e){if(e.kind===`pending`)return{kind:`pending`};if(e.kind===`error`)return{kind:`unavailable`,message:e.message};let t=e.caps[`group-commands`];if(t===void 0)return{kind:`none`};let n=et.safeParse(t);return n.success?n.data.results.length===0?{kind:`none`}:{kind:`rows`,rows:n.data.results.map(e=>({deviceId:e.deviceId,cap:e.cap,method:e.method,ok:e.ok,error:e.error??null,at:e.at}))}:{kind:`unavailable`,message:`group-commands`}}function Wc(e,t,n,r,i=!1){if(e===`pending`)return`pending`;if(e===`error`)return`error`;let a=t?.[n];if(a===void 0)return`missing`;let o=a[r];return typeof o==`number`&&Number.isFinite(o)||typeof o==`boolean`||i&&typeof o==`string`&&o!==``?`value`:o===void 0?`missing`:`empty`}function Gc(e){return e.fleet===`answered`?e.deviceOnline===null||e.deviceOnline===!1?`excluded`:e.field===`pending`||e.field===`error`?`unknown`:e.field===`value`?`reporting`:`excluded`:`unknown`}function Kc(e){return e.some(e=>e.presence===`unknown`)?{kind:`pending`}:{kind:`named`,names:e.flatMap(e=>e.presence===`excluded`?[e.name]:[])}}function qc(e){if(!Jc(e))return{};let t={};for(let[n,r]of Object.entries(e))Jc(r)&&(t[n]=r);return t}function Jc(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Yc(e){return e.source===null?null:{kind:`statistic`,stat:e.stat,window:sl(e.window),source:X(e.source)}}function Xc(e){if(e.source===null)return null;let t=e.source.cap===`power-meter`&&e.source.fieldPath===`power`;return{kind:`integral`,reset:e.reset,output:t?`energy`:`meter`,source:X(e.source)}}function Zc(e){return e.source===null?null:{kind:`threshold`,source:X(e.source),high:e.high,low:e.low,onForMs:e.onForMs,offForMs:e.offForMs}}function Qc(e){return e.inputs.length===0?null:{kind:`arithmetic`,op:e.op,inputs:e.inputs.map(X)}}function $c(e){return e.inputs.length===0?null:{kind:`expression`,expr:e.expr.trim(),output:e.output,inputs:e.inputs.map(e=>({name:e.name,member:X(e.member)}))}}function el(e){return e.source===null?null:{kind:`derivative`,window:tl(e.window),per:e.per,source:X(e.source)}}function tl(e){return e.customMinutes===void 0?{kind:`rolling`,span:e.span}:{kind:`rolling`,span:e.span,customMinutes:e.customMinutes}}var nl=`abcdefghijklmnopqrstuvwxyz`;function rl(e){return`${e.source.addonId}/${e.source.stableId}/${e.cap}.${e.fieldPath}`}function il(e){for(let t=0;t<64;t++)for(let n of nl){let r=t===0?n:`${n}${t}`;if(!e.has(r))return r}return`input${e.size+1}`}function al(e){return e.kind===`group`?e.members:e.kind===`arithmetic`?e.inputs:e.kind===`expression`?e.inputs.map(e=>e.member):e.source===null?[]:[e.source]}function ol(e,t){if(e.kind===`group`)return{...e,members:t};if(e.kind===`arithmetic`)return{...e,inputs:t};if(e.kind===`expression`){let n=new Map(e.inputs.map(e=>[rl(e.member),e.name])),r=new Set,i=[],a=new Set(n.values());for(let[e,o]of t.entries()){let t=n.get(rl(o)),s=nl[e]??``,c=t!==void 0&&!r.has(t)?t:s!==``&&!r.has(s)&&!a.has(s)?s:il(new Set([...r,...a]));r.add(c),i.push({name:c,member:o})}return{...e,inputs:i}}return{...e,source:t[0]??null}}function sl(e){return e.kind===`calendar`?{kind:`calendar`,period:e.period}:e.customMinutes===void 0?{kind:`rolling`,span:e.span}:{kind:`rolling`,span:e.span,customMinutes:e.customMinutes}}function X(e){return{source:{addonId:e.source.addonId,stableId:e.source.stableId},cap:e.cap,fieldPath:e.fieldPath}}function cl(e){return typeof e!=`number`||!Number.isInteger(e)||e<0?null:e}function ll(e){let t=pc.exec(e.trim());if(t===null)return[];let n=t[1],r=t[2],i=t[3];return n===void 0||r===void 0||i===void 0?[]:[{path:n,code:r,message:i}]}function ul({lines:t,testId:n=`helper-refusals`}){return t.length===0?null:i(`ul`,{role:`alert`,className:`flex flex-col gap-1`,"data-testid":n,children:t.map(t=>e(`li`,{className:`text-xs text-danger`,children:[i(`span`,{className:`font-medium`,children:t.code}),t.message===``?``:` — ${t.message}`]},`${t.path}:${t.code}:${t.message}`))})}s();function dl(e){return Lc(e)}function fl(t){let{t:n}=q(),{def:r,feature:a,featureIndex:s,row:c,itemLabel:l,names:u,saving:d,onApply:f}=t,[p,m]=o(!1),[h,g]=o(zs),[_,v]=o([]),y=e=>u.get(V(e.source))??e.source.stableId,b=dl(Os(r,a,s,c,c.command)),x=c.kind===`reset`?n(`commands.resetOf`,{item:l??c.itemKey}):c.method;return e(`li`,{className:`flex flex-col gap-2 border-b border-border-subtle pb-3 last:border-b-0 last:pb-0`,"data-testid":`command-row-${c.id}`,children:[e(`div`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[e(`div`,{className:`min-w-0`,children:[i(`div`,{className:`font-mono text-xs text-foreground break-words`,children:x}),i(`div`,{className:`text-[11px] text-foreground-muted break-words`,children:c.command===null?n(`commands.none`):n(`commands.calls`,{device:y(c.command),call:`${c.command.cap}.${c.command.method}`})})]}),!p&&e(`div`,{className:`flex gap-1`,children:[i(W,{variant:`outline`,size:`sm`,disabled:d,onClick:()=>{g(Bs(c.command)),v([]),m(!0)},children:c.command===null?n(`commands.set`):n(`commands.change`)}),c.command!==null&&i(W,{variant:`ghost`,size:`sm`,disabled:d,onClick:()=>{f(c,null).then(e=>{e.kind===`refused`&&v(Rc(e.reason))})},children:n(`commands.remove`)})]})]}),i(ul,{lines:b,testId:`command-refusals-${c.id}`}),!p&&i(ul,{lines:_,testId:`command-server-${c.id}`}),p&&i(pl,{...t,draft:h,onDraft:g,serverLines:_,onClose:()=>m(!1),onServerLines:v})]})}function pl({def:t,feature:n,featureIndex:r,row:a,fleet:s,names:c,candidates:l,room:u,saving:d,onApply:f,draft:p,onDraft:m,serverLines:h,onClose:g,onServerLines:_}){let{t:v,i18n:y}=q(),[b,x]=o(!1),S=dn((p.source===null||s.kind!==`known`?null:Hs(s.value,p.source))?.id??0),C=js(S.data??[]),w=p.cap===``?C.length===1?C[0]?.name??``:``:p.cap,T=w===``?null:ws(w),E=T===null?[]:As(T),D=p.method===``?E.length===1?E[0]??``:``:p.method,O=Vs({...p,cap:w,method:D}),k=dl(Os(t,n,r,a,O)),A=T===null||D===``?[]:Ns(T,D),j=a.kind===`reset`?[]:Ns(t,a.method).map(e=>e.name),M=p.source===null?v(`commands.noDevice`):c.get(V(p.source))??p.source.stableId,N=e=>mr(e,y.language),ee=()=>{O!==null&&f(a,O).then(e=>{e.kind===`refused`?_(Rc(e.reason)):g()})};return e(`div`,{className:`flex flex-col gap-3 rounded-md border border-border-subtle bg-background-elevated p-2 sm:p-3`,"data-testid":`command-editor-${a.id}`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(`span`,{className:`text-[11px] text-foreground-muted`,children:v(`commands.source`)}),i(W,{variant:`outline`,size:`sm`,onClick:()=>x(!0),children:p.source===null?v(`commands.chooseDevice`):M})]}),p.source!==null&&e(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[i(ml,{label:v(`commands.cap`),children:S.isLoading?i(`span`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:v(`commands.loadingCaps`)}):C.length===0?i(`span`,{className:`text-[11px] text-warning`,children:v(`commands.noCaps`)}):C.length===1?i(`span`,{className:`text-xs text-foreground`,children:N(C[0]?.name??``)}):i(U,{"aria-label":v(`commands.cap`),value:w,onChange:e=>m({...p,cap:e.target.value,method:``,args:void 0}),options:[{value:``,label:v(`commands.pickCap`)},...C.map(e=>({value:e.name,label:N(e.name)}))]})}),T!==null&&i(ml,{label:v(`commands.method`),children:E.length===1?i(`span`,{className:`font-mono text-xs text-foreground`,children:E[0]}):i(U,{"aria-label":v(`commands.method`),value:D,onChange:e=>m({...p,cap:w,method:e.target.value,args:void 0}),options:[{value:``,label:v(`commands.pickMethod`)},...E.map(e=>({value:e,label:e}))]})})]}),D!==``&&i(Qs,{testId:`command-args-${a.id}`,builtFields:j,sourceFields:A,args:p.args,onChange:e=>m({...p,cap:w,method:D,args:e})}),i(ul,{lines:k,testId:`command-draft-refusals-${a.id}`}),i(ul,{lines:h,testId:`command-server-${a.id}`}),e(`div`,{className:`flex flex-wrap gap-2`,children:[i(W,{size:`sm`,disabled:O===null||k.length>0||d,onClick:ee,children:v(`commands.apply`)}),i(W,{variant:`ghost`,size:`sm`,onClick:g,children:v(`commands.cancel`)})]}),i(Zs,{open:b,title:v(`commands.pickTitle`,{method:a.method}),selection:`single`,candidates:l,room:u,confirmLabel:()=>v(`commands.pickConfirm`),onConfirm:e=>{let t=e[0];x(!1),t!==void 0&&m({source:t.ref,cap:``,method:``,args:void 0})},onClose:()=>x(!1)}),i(`span`,{hidden:!0,children:c.size})]})}function ml({label:t,children:n}){return e(`label`,{className:`flex flex-col gap-1 text-[11px] text-foreground-muted`,children:[t,n]})}s();function hl(e){let t=Object.values(e.commands??{}).find(e=>e.kind===`forward`);if(t!==void 0)return t.source;let n=Oe(e).flatMap(e=>je(e.source)).at(0);return n===void 0?null:n.source}function gl({composition:t,saving:r,save:a}){let{t:o,i18n:s}=q(),l=Fi(!0),u=n(()=>l.kind===`known`?new Map(l.value.map(e=>[V({addonId:e.addonId,stableId:e.stableId}),e.name])):new Map,[l]),d=n(()=>l.kind===`known`?{kind:`known`,value:Us(l.value)}:l,[l]),f=async(e,n,r)=>{let i=t.features[e];if(i===void 0||i.kind!==`fields`)return{kind:`refused`,reason:`the feature is gone`};let o=t.features.map((t,a)=>a===e?Es(i,n,r):t);return a({...t,features:o})};return i(c,{children:t.features.map((t,n)=>{if(t.kind!==`fields`)return null;let a=ws(t.cap);if(a===null)return null;let c=Ts(a,t);if(c.length===0)return null;let p=ks(a,t),m=l.kind===`known`?Ws(l.value,hl(t),!0):null,h=mr(t.cap,s.language);return i(Mi,{id:`commands-${t.cap}`,icon:ht,title:o(`commands.title`,{cap:h}),testId:`commands-card-${t.cap}`,children:e(`div`,{className:`flex flex-col gap-3 px-3 py-2 sm:px-4`,children:[i(`p`,{className:`text-xs text-foreground-muted`,children:o(`commands.hint`)}),p.length>0&&e(`p`,{role:`alert`,className:`text-xs text-danger`,"data-testid":`commands-has-commands`,children:[i(`span`,{className:`font-medium`,children:`has-commands`}),` — ${o(`commands.unserved`,{methods:p.join(`, `)})}`]}),i(`ul`,{className:`flex flex-col gap-3`,children:c.map(e=>i(fl,{def:a,feature:t,featureIndex:n,row:e,itemLabel:e.itemKey===null?null:t.items?.[e.itemKey]?.label??e.itemKey,fleet:l,names:u,candidates:d,room:m,saving:r,onApply:(e,t)=>f(n,e,t)},e.id))})]})},t.cap)})})}function Z(e,t){return e[t]}var Q=(e,t,n)=>({key:e,labelKey:`preset.petFountain.slot.${e}`,expectedCap:t,...n===void 0?{}:{optionalGroup:n}}),_l=[{id:`pet-fountain`,labelKey:`preset.petFountain.label`,descriptionKey:`preset.petFountain.description`,nameKey:`preset.petFountain.name`,slots:[Q(`waterLevel`,`enum-sensor`),Q(`waterVolume`,`enum-sensor`),Q(`pump`,`switch`),Q(`pumpInterval`,`switch`),Q(`pumpOnMinutes`,`control`),Q(`pumpOffMinutes`,`control`),Q(`lastDrink`,`enum-sensor`),Q(`currentHourDrink`,`enum-sensor`),Q(`last24hDrink`,`enum-sensor`),Q(`todayDrink`,`enum-sensor`),Q(`clearDaily`,`button`),Q(`filterDaysRemaining`,`enum-sensor`,`filter`),Q(`filterChanged`,`button`,`filter`)],build:e=>{let t=Z(e,`waterLevel`),n=Z(e,`waterVolume`),r=Z(e,`pump`),i=Z(e,`pumpInterval`),a=Z(e,`pumpOnMinutes`),o=Z(e,`pumpOffMinutes`),s=Z(e,`lastDrink`),c=Z(e,`currentHourDrink`),l=Z(e,`last24hDrink`),u=Z(e,`todayDrink`),d=Z(e,`clearDaily`),f=Z(e,`filterDaysRemaining`),p=Z(e,`filterChanged`);return t===void 0||n===void 0||r===void 0||i===void 0||a===void 0||o===void 0||s===void 0||c===void 0||l===void 0||u===void 0||d===void 0||f===void 0!=(p===void 0)?null:se({waterLevel:t,waterVolume:n,pump:r,pumpInterval:i,pumpOnMinutes:a,pumpOffMinutes:o,lastDrink:s,currentHourDrink:c,last24hDrink:l,todayDrink:u,clearDaily:d,...f!==void 0&&p!==void 0?{filter:{daysRemaining:f,changed:p}}:{}})}}];function vl(e){return e===null?null:_l.find(t=>t.id===e)??null}function yl(e,t){let n=new Set(e.slots.filter(e=>e.optionalGroup!==void 0&&t[e.key]!==void 0).map(e=>e.optionalGroup));return e.slots.filter(e=>t[e.key]===void 0&&(e.optionalGroup===void 0||n.has(e.optionalGroup)))}function bl(e,t){for(let n of e.slots){let e=t[n.key];if(e!==void 0)return e}return null}var xl=`composition`;function Sl({onPick:e,onFreeComposition:t,onPreset:n}){let{t:r}=q();return i(`div`,{"data-testid":`helper-template-picker`,children:i(jt,{emptyMessage:r(`helper.noTemplates`),onPick:r=>{if(r===xl){t?.();return}let i=_l.find(e=>e.id===r);if(i!==void 0){n?.(i.id);return}if(r===`statistic`||r===`integral`){e({kind:r});return}if(r===`appliance`){e({kind:`appliance`});return}if(oc(r)){e(sc(r));return}Al(r)&&e({kind:`group`,templateId:r})},groups:[...jl(r),...n===void 0||_l.length===0?[]:[{id:`presets`,label:r(`helper.section.presets`),tiles:_l.map(e=>Cl(e,r))}],{id:`calculation`,label:r(`helper.section.calculation`),tiles:[...ac().map(e=>Dl(e,r)),Tl(`statistic`,ft,r),Tl(`integral`,S,r)]},{id:`advanced`,label:r(`helper.section.advanced`),tiles:[...t===void 0?[]:[wl(r)],Dl(`expression`,r)]}]})})}function Cl(e,t){let n=t(e.labelKey);return{key:e.id,label:n,testId:`helper-template-preset-${e.id}`,icon:i(ut,{className:`h-5 w-5 text-foreground-muted`,"aria-hidden":!0}),detailLabel:t(`helper.detailsOf`,{name:n}),detail:i(`div`,{className:`max-w-xs text-xs`,children:i(`p`,{className:`text-foreground-muted`,children:t(e.descriptionKey)})})}}function wl(e){let t=e(`helper.template.composition`);return{key:xl,label:t,testId:`helper-template-composition`,icon:i(ut,{className:`h-5 w-5 text-foreground-muted`,"aria-hidden":!0}),detailLabel:e(`helper.detailsOf`,{name:t}),detail:i(`div`,{className:`max-w-xs text-xs`,children:i(`p`,{className:`text-foreground-muted`,children:e(`helper.detail.composition`)})})}}function Tl(e,t,n){let r=n(`helper.template.${e}`);return{key:e,label:r,testId:`helper-template-${e}`,icon:i(t,{className:`h-5 w-5 text-foreground-muted`,"aria-hidden":!0}),detailLabel:n(`helper.detailsOf`,{name:r}),detail:i(kl,{id:e})}}var El={threshold:p,sum:u,difference:b,ratio:dt,expression:pt,derivative:g};function Dl(e,t){let n=t(`helper.template.${e}`),r=El[e];return{key:e,label:n,testId:`helper-template-${e}`,icon:i(r,{className:`h-5 w-5 text-foreground-muted`,"aria-hidden":!0}),detailLabel:t(`helper.detailsOf`,{name:n}),detail:i(Ol,{id:e})}}function Ol({id:t}){let{t:n}=q();return e(`div`,{className:`max-w-xs space-y-1 text-xs`,children:[i(`p`,{className:`text-foreground-muted`,children:n(`helper.detail.${t}`)}),t===`derivative`&&i(`p`,{className:`text-foreground-subtle`,children:n(`helper.detail.history`)}),t===`expression`&&i(`p`,{className:`text-foreground-subtle`,children:n(`helper.detail.expressionStale`)})]})}function kl({id:t}){let{t:n}=q();return e(`div`,{className:`max-w-xs space-y-1 text-xs`,children:[i(`p`,{className:`text-foreground-muted`,children:n(`helper.detail.${t}`)}),i(`p`,{className:`text-foreground-subtle`,children:n(`helper.detail.history`)})]})}function Al(e){return Je.some(t=>t===e)}function jl(e){return mc().map(t=>({id:t.id,label:`${e(`helper.section.group`)} · ${e(`helper.group.${t.id}`)}`,tiles:Ml(t.templateIds,e)}))}function Ml(e,t){let n=[];for(let r of e){let e=Nl(r,t);e!==null&&n.push(e)}return n}function Nl(e,t){if(e===`appliance`)return Pl(t);if(!Al(e))return null;let n=B(e);if(n===null)return null;let r=t(`helper.template.${e}`),a=n.role===void 0?Rt(n.deviceType).icon:$t(n.role).icon;return{key:e,label:r,testId:`helper-template-${e}`,icon:i(a,{className:`h-5 w-5 text-foreground-muted`,"aria-hidden":!0}),detailLabel:t(`helper.detailsOf`,{name:r}),detail:i(Il,{templateId:e})}}function Pl(e){let t=e(`helper.template.appliance`),n=Rt(I.Washer).icon;return{key:nt,label:t,testId:`helper-template-appliance`,icon:i(n,{className:`h-5 w-5 text-foreground-muted`,"aria-hidden":!0}),detailLabel:e(`helper.detailsOf`,{name:t}),detail:i(Fl,{})}}function Fl(){let{t:e}=q();return i(`div`,{className:`max-w-xs text-xs`,children:i(`p`,{className:`text-foreground-muted`,children:e(`helper.template.applianceSummary`)})})}function Il({templateId:t}){let{t:n}=q(),r=B(t);if(r===null)return null;let a=r.family===`actuator`?w.map(e=>n(`helper.active.${e}`)):r.aggregates.map(e=>n(`helper.aggregate.${e}`)),o=r.commandCaps.filter(e=>e!==`switch`);return e(`div`,{className:`max-w-xs space-y-1 text-xs`,children:[i(`p`,{className:`font-medium text-foreground`,children:n(`helper.supportedOperations`)}),i(`p`,{className:`text-foreground-muted`,children:a.join(`, `)}),o.length>0&&e(c,{children:[i(`p`,{className:`font-medium text-foreground`,children:n(`helper.sharedCaps`)}),i(`p`,{className:`text-foreground-muted`,children:o.map(e=>n(`helper.cap.${e}`)).join(`, `)})]}),r.id===`lock`&&i(`p`,{className:`text-foreground-subtle`,children:n(`helper.detail.lockConfirm`)}),i(`p`,{className:`text-foreground-subtle`,children:n(`helper.offlineCounted`)})]})}s();function Ll({initial:n,start:r,purpose:s,saving:l,onSave:u,onDraftChange:d,onFreeComposition:f,onPreset:p,fillHeight:m=!1}){let{t:h}=q(),[g,_]=o(n===null?`template`:r),[v,y]=o(n),[b,x]=o([]),[S,C]=o(null),T=t(!1),[E,D]=o(null),O=l||E!==null;a(()=>{d?.(v)},[v,d]);let k=e=>{y(t=>e.kind===`group`&&t?.kind===`group`&&t.templateId!==`appliance`?Cc(t,e.templateId):_c(e)),x([]),C(null),_(`parameters`)},A=e=>{if(v===null||T.current)return;T.current=!0,D(e);let t=v;(async()=>{let n;try{n=await u(t,e)}finally{T.current=!1,D(null)}if(n.kind===`refused`){x(n.lines);return}e===`again`&&(C({deviceId:n.deviceId,name:t.name.trim()}),y(null),_(`template`),x([]))})()},j=v===null?null:Tc(v),M=v!==null&&v.kind===`group`&&v.templateId!==`appliance`?B(v.templateId):null,N=v===null?[]:al(v);return e(`div`,{className:m?`flex min-h-0 flex-1 flex-col gap-3`:`flex flex-col gap-3`,"data-testid":`helper-wizard`,children:[S!==null&&i(`p`,{role:`status`,className:`text-xs text-foreground`,"data-testid":`helper-created`,children:i(un,{i18nKey:`helper.created`,values:{name:S.name===``?h(`helper.newHelper`):S.name},components:{device:i(ln,{to:cn(S.deviceId),className:`text-primary hover:underline`})}})}),i(`p`,{className:`text-[11px] text-foreground-muted`,children:h(nu(g,v))}),g===`template`&&i(Sl,{onPick:k,onFreeComposition:f,onPreset:p}),g===`parameters`&&v?.kind===`group`&&v.templateId===`appliance`&&i(zl,{draft:v,onDraft:e=>y(e)}),g===`parameters`&&v?.kind===`group`&&M!==null&&e(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[M.family===`actuator`&&v.active!==null?e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[h(`helper.criterion`),i(U,{"aria-label":h(`helper.criterion`),"data-testid":`helper-criterion`,value:v.active,onChange:e=>{let t=w.find(t=>t===e.target.value);t!==void 0&&y(xc(v,t))},options:w.map(e=>({value:e,label:h(`helper.active.${e}`)}))})]}):e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[h(`helper.reducer`),i(U,{"aria-label":h(`helper.reducer`),"data-testid":`helper-reducer`,value:v.aggregate,onChange:e=>{let t=M.aggregates.find(t=>t===e.target.value);t!==void 0&&y(bc(v,t))},options:M.aggregates.map(e=>({value:e,label:h(`helper.aggregate.${e}`)}))})]}),e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[h(`helper.name`),i(G,{"aria-label":h(`helper.name`),"data-testid":`helper-name`,value:v.name,onChange:e=>y(Sc(v,e.target.value))})]})]}),g===`parameters`&&v?.kind===`statistic`&&i(Wl,{draft:v,onChange:y}),g===`parameters`&&v?.kind===`integral`&&i(Kl,{draft:v,onChange:y}),g===`parameters`&&v?.kind===`threshold`&&i(Jl,{draft:v,onChange:y}),g===`parameters`&&v?.kind===`derivative`&&i(Zl,{draft:v,onChange:y}),g===`parameters`&&v?.kind===`arithmetic`&&i(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,"data-testid":`helper-math-parameters`,children:i(eu,{name:v.name,onChange:e=>y({...v,name:e})})}),g===`parameters`&&v?.kind===`expression`&&i(Ql,{draft:v,onChange:y}),g===`members`&&v!==null&&j!==null&&i(Ei,{kind:`members`,request:j,enabled:!0,fillHeight:m,members:N,onMembersChange:e=>y(ol(v,e)),onRefuse:e=>x(e===null?[]:[{path:`helper.members`,code:`member-constraint`,message:h(`helper.maxMembers`,{max:e.max})}])}),g===`members`&&v?.kind===`expression`&&i($l,{draft:v,onChange:y}),g===`members`&&(v?.kind===`arithmetic`||v?.kind===`threshold`)&&i(`p`,{className:`text-[11px] text-foreground-muted`,"data-testid":`helper-math-hint`,children:h(tu(v))}),i(ul,{lines:b}),e(`div`,{className:m?`mt-auto flex shrink-0 flex-wrap gap-2`:`flex flex-wrap gap-2`,children:[g===`members`&&i(W,{variant:`ghost`,onClick:()=>_(`parameters`),children:h(`helper.back`)}),g===`parameters`&&v!==null&&i(W,{"data-testid":`helper-to-members`,disabled:v.name.trim()===``,onClick:()=>{x([]),_(`members`)},children:h(`helper.next`)}),g===`members`&&v!==null&&s===`edit`&&i(W,{"data-testid":`helper-save`,disabled:!Ic(v)||O,onClick:()=>A(`open`),children:h(E===`open`?`helper.saving`:`helper.save`)}),g===`members`&&v!==null&&s===`create`&&e(c,{children:[i(W,{"data-testid":`helper-save-open`,disabled:!Ic(v)||O,onClick:()=>A(`open`),children:h(E===`open`?`helper.saving`:`helper.saveOpen`)}),i(W,{variant:`outline`,"data-testid":`helper-save-more`,disabled:!Ic(v)||O,onClick:()=>A(`again`),children:h(E===`again`?`helper.saving`:`helper.saveMore`)})]})]})]})}var Rl=6e4;function zl({draft:t,onDraft:n}){let{t:r}=q(),a=t.appliance??`washer`;return 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:[r(`helper.applianceType`),i(U,{"aria-label":r(`helper.applianceType`),"data-testid":`helper-appliance`,value:a,onChange:e=>{let r=Ke.find(t=>t===e.target.value);r!==void 0&&n(wc(t,r))},options:Ke.map(e=>({value:e,label:r(`helper.appliance.${e}`)}))})]}),e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[r(`helper.name`),i(G,{"aria-label":r(`helper.name`),"data-testid":`helper-name`,value:t.name,onChange:e=>n({...t,name:e.target.value})})]}),i(Ul,{label:r(`helper.threshold`),testId:`helper-threshold`,value:String(t.thresholdWatts),onValue:e=>{let r=Hl(e);r!==null&&n({...t,thresholdWatts:r})}}),i(Ul,{label:r(`helper.startDwell`),testId:`helper-start-dwell`,value:Bl(t.startDwellMs),onValue:e=>{let r=Vl(e);r!==null&&n({...t,startDwellMs:r})}}),i(Ul,{label:r(`helper.stopDwell`),testId:`helper-stop-dwell`,value:Bl(t.stopDwellMs),onValue:e=>{let r=Vl(e);r!==null&&n({...t,stopDwellMs:r})}})]})}function Bl(e){return String(e/Rl)}function Vl(e){let t=Number(e);return!Number.isFinite(t)||t<0?null:Math.round(t*Rl)}function Hl(e){let t=Number(e);return!Number.isFinite(t)||t<=0?null:t}function Ul({label:t,testId:n,value:r,onValue:a}){return e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[t,i(G,{type:`number`,min:0,step:`any`,"aria-label":t,"data-testid":n,value:r,onChange:e=>a(e.target.value)})]})}function Wl({draft:t,onChange:n}){let{t:r}=q(),a=t.window.kind===`rolling`;return e(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,"data-testid":`helper-statistic-parameters`,children:[i($,{label:r(`helper.stat`),children:i(U,{"aria-label":r(`helper.stat`),"data-testid":`helper-stat`,value:t.stat,onChange:e=>{let r=$e.find(t=>t===e.target.value);r!==void 0&&n({...t,stat:r})},options:$e.map(e=>({value:e,label:r(`helper.statName.${e}`)}))})}),i($,{label:r(`helper.range`),children:i(U,{"aria-label":r(`helper.range`),"data-testid":`helper-range-kind`,value:t.window.kind,onChange:e=>{e.target.value===`calendar`&&n({...t,window:{kind:`calendar`,period:`today`}}),e.target.value===`rolling`&&n({...t,window:{kind:`rolling`,span:`24h`}})},options:[{value:`rolling`,label:r(`helper.rangeKind.rolling`)},{value:`calendar`,label:r(`helper.rangeKind.calendar`)}]})}),a?i($,{label:r(`helper.span`),children:i(U,{"aria-label":r(`helper.span`),"data-testid":`helper-span`,value:t.window.span,onChange:e=>{let r=Xe.find(t=>t===e.target.value);r!==void 0&&n({...t,window:Gl(r,t)})},options:Xe.map(e=>({value:e,label:r(`helper.spanName.${e}`)}))})}):i($,{label:r(`helper.period`),children:i(U,{"aria-label":r(`helper.period`),"data-testid":`helper-period`,value:t.window.period,onChange:e=>{let r=Be.find(t=>t===e.target.value);r!==void 0&&n({...t,window:{kind:`calendar`,period:r}})},options:Be.map(e=>({value:e,label:r(`helper.periodName.${e}`)}))})}),t.window.kind===`rolling`&&t.window.span===`custom`&&i($,{label:r(`helper.customMinutes`),children:i(G,{"aria-label":r(`helper.customMinutes`),"data-testid":`helper-custom-minutes`,inputMode:`numeric`,value:t.window.customMinutes===void 0?``:String(t.window.customMinutes),onChange:e=>{let r=Number.parseInt(e.target.value,10);n({...t,window:{kind:`rolling`,span:`custom`,...Number.isFinite(r)?{customMinutes:r}:{}}})}})}),i(eu,{name:t.name,onChange:e=>n({...t,name:e})})]})}function Gl(e,t){if(e!==`custom`)return{kind:`rolling`,span:e};let n=t.window.kind===`rolling`?t.window.customMinutes:void 0;return n===void 0?{kind:`rolling`,span:e}:{kind:`rolling`,span:e,customMinutes:n}}function Kl({draft:t,onChange:n}){let{t:r}=q();return e(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,"data-testid":`helper-integral-parameters`,children:[i($,{label:r(`helper.reset`),children:i(U,{"aria-label":r(`helper.reset`),"data-testid":`helper-reset`,value:t.reset,onChange:e=>{let r=Ne.find(t=>t===e.target.value);r!==void 0&&n({...t,reset:r})},options:Ne.map(e=>({value:e,label:r(`helper.resetName.${e}`)}))})}),i(eu,{name:t.name,onChange:e=>n({...t,name:e})})]})}var ql=1e3;function Jl({draft:t,onChange:n}){let{t:r}=q(),a=t.low>t.high;return e(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,"data-testid":`helper-threshold-parameters`,children:[i(Xl,{label:r(`helper.highEdge`),testId:`helper-high`,value:t.high,onValue:e=>n({...t,high:e})}),i(Xl,{label:r(`helper.lowEdge`),testId:`helper-low`,value:t.low,onValue:e=>n({...t,low:e})}),i(Ul,{label:r(`helper.onDelay`),testId:`helper-on-delay`,value:String(t.onForMs/ql),onValue:e=>{let r=Yl(e);r!==null&&n({...t,onForMs:r})}}),i(Ul,{label:r(`helper.offDelay`),testId:`helper-off-delay`,value:String(t.offForMs/ql),onValue:e=>{let r=Yl(e);r!==null&&n({...t,offForMs:r})}}),i(eu,{name:t.name,onChange:e=>n({...t,name:e})}),a&&i(`p`,{role:`alert`,className:`text-xs text-danger sm:col-span-2`,"data-testid":`helper-edges`,children:r(`helper.edgesReversed`)})]})}function Yl(e){let t=Number(e);return!Number.isFinite(t)||t<0?null:Math.round(t*ql)}function Xl({label:t,testId:n,value:r,onValue:a}){return e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[t,i(G,{type:`number`,step:`any`,"aria-label":t,"data-testid":n,value:String(r),onChange:e=>{let t=Number(e.target.value);e.target.value!==``&&Number.isFinite(t)&&a(t)}})]})}function Zl({draft:t,onChange:n}){let{t:r}=q();return e(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,"data-testid":`helper-derivative-parameters`,children:[i($,{label:r(`helper.span`),children:i(U,{"aria-label":r(`helper.span`),"data-testid":`helper-span`,value:t.window.span,onChange:e=>{let r=Xe.find(t=>t===e.target.value);r!==void 0&&n({...t,window:r===`custom`?{kind:`rolling`,span:r,customMinutes:t.window.customMinutes??60}:{kind:`rolling`,span:r}})},options:Xe.map(e=>({value:e,label:r(`helper.spanName.${e}`)}))})}),t.window.span===`custom`&&i($,{label:r(`helper.customMinutes`),children:i(G,{"aria-label":r(`helper.customMinutes`),"data-testid":`helper-custom-minutes`,inputMode:`numeric`,value:t.window.customMinutes===void 0?``:String(t.window.customMinutes),onChange:e=>{let r=Number.parseInt(e.target.value,10);n({...t,window:{kind:`rolling`,span:`custom`,...Number.isFinite(r)?{customMinutes:r}:{}}})}})}),i($,{label:r(`helper.per`),children:i(U,{"aria-label":r(`helper.per`),"data-testid":`helper-per`,value:t.per,onChange:e=>{let r=Ie.find(t=>t===e.target.value);r!==void 0&&n({...t,per:r})},options:Ie.map(e=>({value:e,label:r(`helper.perName.${e}`)}))})}),i(eu,{name:t.name,onChange:e=>n({...t,name:e})})]})}function Ql({draft:t,onChange:n}){let{t:r}=q();return e(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,"data-testid":`helper-expression-parameters`,children:[i($,{label:r(`helper.exprOutput`),children:i(U,{"aria-label":r(`helper.exprOutput`),"data-testid":`helper-expr-output`,value:t.output,onChange:e=>{let r=tt.find(t=>t===e.target.value);r!==void 0&&n({...t,output:r})},options:tt.map(e=>({value:e,label:r(`helper.exprOutputName.${e}`)}))})}),i(eu,{name:t.name,onChange:e=>n({...t,name:e})}),i(`p`,{className:`text-[11px] text-foreground-muted sm:col-span-2`,"data-testid":`helper-stale-note`,children:r(`helper.detail.expressionStale`)})]})}function $l({draft:t,onChange:n}){let{t:r}=q();return t.inputs.length===0?null:e(`div`,{className:`flex flex-col gap-2`,"data-testid":`helper-expression-editor`,children:[i(`ul`,{className:`flex flex-col gap-1`,children:t.inputs.map((a,o)=>e(`li`,{className:`flex items-center gap-2 text-[11px]`,children:[i(G,{className:`w-24 font-mono`,"aria-label":r(`helper.inputName`),"data-testid":`helper-input-name-${o}`,value:a.name,onChange:e=>n({...t,inputs:t.inputs.map((t,n)=>n===o?{...t,name:e.target.value}:t)})}),e(`span`,{className:`truncate text-foreground-muted`,children:[a.member.source.stableId,` · `,a.member.cap,`.`,a.member.fieldPath]})]},`${a.member.source.addonId}/${a.member.source.stableId}/${a.member.cap}.${a.member.fieldPath}`))}),i(ka,{label:r(`helper.expr`),value:t.expr,bindings:t.inputs.map(e=>e.name),onChange:e=>n({...t,expr:e})})]})}function eu({name:e,onChange:t}){let{t:n}=q();return i($,{label:n(`helper.name`),children:i(G,{"aria-label":n(`helper.name`),"data-testid":`helper-name`,value:e,onChange:e=>t(e.target.value)})})}function tu(e){return e.kind===`arithmetic`?`helper.hint.${e.op}`:`helper.hint.threshold`}function nu(e,t){if(t?.kind===`threshold`||t?.kind===`arithmetic`||t?.kind===`expression`||t?.kind===`derivative`){if(e===`parameters`)return`helper.step.math.${t.kind}.parameters`;if(e===`members`)return`helper.step.math.${t.kind}.members`}if(t?.kind===`statistic`||t?.kind===`integral`){if(e===`parameters`)return`helper.step.historyParameters`;if(e===`members`)return`helper.step.historySource`}if(t?.kind===`group`&&t.templateId===`appliance`){if(e===`parameters`)return`helper.step.appliance`;if(e===`members`)return`helper.step.applianceMembers`}return`helper.step.${e}`}function $({label:t,children:n}){return e(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[t,n]})}s();function ru({blockId:t,fillHeight:r=!1}){let{t:a}=q(),o=It({blockId:t}),s=Ot(),c=Lt(),l=n(()=>{let e=new Set;for(let{cap:t}of _s())e.add(t);for(let{cap:t}of qo())e.add(t);for(let{cap:t}of to())e.add(t);return e},[]);if(o.status===`pending`)return i(`p`,{role:`status`,children:a(`compositionEditor.loading`)});if(o.status===`error`)return i(H,{title:a(`compositionEditor.loadFailed`),message:o.error.message});if(o.data.state===`not-loaded`)return i(`p`,{role:`status`,children:a(`customize.status.notLoaded`,{reason:o.data.reason})});let u=o.data.view;if(u===null)return i(`p`,{children:a(`compositionEditor.notFound`,{blockId:t})});let d=A(u.block);if(d===null)return i(`p`,{children:a(`compositionEditor.notComposition`)});if(yc(d)){let e=vc(d.helper,u.block.name,``);if(e===null)return i(`p`,{role:`alert`,children:a(`helper.unreadable`)});let t=u.state.kind===`answered`?u.state.state?.deviceId??null:null;return i(Ll,{fillHeight:r,purpose:`edit`,initial:e,start:`parameters`,saving:s.isPending,onSave:async e=>{let n=await Fc(e,async(n,r)=>{await s.mutateAsync({blockId:u.block.id,expectedUpdatedAt:u.block.updatedAt,block:{composition:n,...r===``?{}:{name:r}}}),t!==null&&e.room.trim()!==``&&await c.mutateAsync({deviceId:t,location:e.room.trim()}),await o.refetch()});return n.length>0?{kind:`refused`,lines:n}:{kind:`saved`,deviceId:t??0}}})}let f=Hi(d),p={id:0,name:u.block.name,addonId:`composer`,stableId:`composed-${t}`,type:d.target.kind===`new`?d.target.type:I.Sensor,location:``,disabled:!1,parentDeviceId:null,role:d.target.kind===`new`?d.target.role:null,online:!0,probed:!0,features:[],isCamera:!1,config:{},secretConfigPaths:[],metadata:{}},m={target:{addonId:`composer`,stableId:p.stableId},state:{kind:`present`,view:u,composition:d},saving:s.isPending,save:async e=>{if(e===null)return{kind:`refused`,reason:`cannot delete here`};try{return await s.mutateAsync({blockId:u.block.id,expectedUpdatedAt:u.block.updatedAt,block:{composition:e}}),await o.refetch(),{kind:`saved`}}catch(e){return{kind:`refused`,reason:e instanceof Error?e.message:String(e)}}}};return e(`div`,{className:`flex flex-col gap-2`,children:[i(Vt,{variant:f===`incomplete`?`warning`:`success`,children:a(`customize.blockStatus.${f===`incomplete`?`incomplete`:u.block.status}`)}),i(eo,{device:p,handle:m,skipCaps:l}),d.target.kind===`new`&&i(gl,{composition:d,saving:s.isPending,save:m.save})]})}export{Yr as $,Fo as A,Qi as B,Us as C,ns as D,_s as E,oo as F,Vi as G,Zi as H,io as I,Li as J,Hi as K,to as L,po as M,uo as N,qo as O,ao as P,Ei as Q,eo as R,Js as S,Ss as T,Wi as U,Ji as V,qi as W,Ni as X,Fi as Y,Mi as Z,Vc as _,vl as a,gn as at,Zs as b,vc as c,Bc as d,Ir as et,yc as f,Rc as g,zc as h,yl as i,J as it,Vo as j,Po as k,al as l,Kc as m,Ll as n,mr as nt,ul as o,Gc as p,Ri as q,bl as r,Y as rt,Uc as s,ru as t,Lr as tt,Wc as u,qc as v,Ws as w,Gs as x,Fc as y,oa as z};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as e,S as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Ci as n}from"./client-Clemlz5W.js";import{t as r}from"./boxes-BYgmIZEw.js";import{Wa as i,ei as a}from"./src-BuD4BDe3.js";import{t as o}from"./useTranslation-BJr-n0es.js";import{_r as s,f as c,hr as l,m as u,mr as d,vr as f}from"./index-
|
|
1
|
+
import{C as e,S as t}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Ci as n}from"./client-Clemlz5W.js";import{t as r}from"./boxes-BYgmIZEw.js";import{Wa as i,ei as a}from"./src-BuD4BDe3.js";import{t as o}from"./useTranslation-BJr-n0es.js";import{_r as s,f as c,hr as l,m as u,mr as d,vr as f}from"./index-B0SLrMzs.js";import{t as p}from"./CompositionBlockEditor-HRq0m67C.js";import{t as m}from"./AdminPage-DPm4iuSn.js";var h=`rounded-lg border border-border bg-surface p-4`,g=`new`;function _(){let{blockId:_}=f(),{t:v}=o(),y=s(),b=_===void 0||_===g,x=i({blockId:_??``},{enabled:!b}),S=e=>t(m,{icon:r,title:v(`compositionEditor.pageTitle`),children:e});if(b)return t(l,{to:`${c}&new=helper`,replace:!0});if(x.status===`success`&&x.data.state===`loaded`&&x.data.view!==null){let e=x.data.view;if(n(e.block)?.target.kind===`existing`){let n=e.state.kind===`answered`?e.state.state?.deviceId??null:null;if(n!==null)return S(t(`section`,{className:h,children:t(d,{className:`text-primary text-sm`,to:u(n),children:v(`compositionEditor.openOnDevice`)})}))}}return S(e(`section`,{className:`${h} flex flex-col gap-2`,children:[t(a,{variant:`ghost`,size:`sm`,onClick:()=>y(c),children:v(`compositionEditor.cancel`)}),t(p,{blockId:_??``})]}))}export{_ as CompositionEditorPage};
|