import{c as $e,a as y,d as De,f as z,e as xe,r as ye}from"../chunks/8V7BUHOp.js";import{f as le,p as Ze,b as J,d as ze,u as ge,c as a,g as e,a as Me,s,e as c,r as t,t as pe,h as me,i as Ee}from"../chunks/CwuLZfOX.js";import{s as X}from"../chunks/CaaTB9LM.js";import{i as _e}from"../chunks/ChcH33Yj.js";import{I as Ne,f as Te,e as be,d as Ae,i as fe,r as H,a as Ie,b as Fe}from"../chunks/C4rKWW1g.js";import{b as C}from"../chunks/CR2j1Dvc.js";import{p as Ge}from"../chunks/B2rQdg-F.js";import{m as f,a as Z}from"../chunks/AayJIqEh.js";import{i as we}from"../chunks/CN__mP6c.js";import{D as He}from"../chunks/Bbhvs_oy.js";import"../chunks/DUxDMF0-.js";import{G as Pe}from"../chunks/NRF2uPyL.js";import{a as Re}from"../chunks/CngRAepr.js";import{l as Le,s as Oe,p as Ve}from"../chunks/CNkT2fMe.js";import"../chunks/DVhLRJjn.js";function ke(l,n){const h=Le(n,["children","$$slots","$$events","$$legacy"]);/**
 * @license lucide-svelte v0.511.0 - ISC
 *
 * ISC License
 *
 * Copyright (c) for portions of Lucide are held by Cole Bemis 2013-2022 as part of Feather (MIT). All other copyright (c) for Lucide are held by Lucide Contributors 2022.
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */const _=[["path",{d:"M12 5v14"}],["path",{d:"m19 12-7 7-7-7"}]];Ne(l,Oe({name:"arrow-down"},()=>h,{get iconNode(){return _},children:(u,o)=>{var v=$e(),b=le(v);Te(b,n,"default",{}),y(u,v)},$$slots:{default:!0}}))}function Se(l,n){const h=Le(n,["children","$$slots","$$events","$$legacy"]);/**
 * @license lucide-svelte v0.511.0 - ISC
 *
 * ISC License
 *
 * Copyright (c) for portions of Lucide are held by Cole Bemis 2013-2022 as part of Feather (MIT). All other copyright (c) for Lucide are held by Lucide Contributors 2022.
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */const _=[["path",{d:"m5 12 7-7 7 7"}],["path",{d:"M12 19V5"}]];Ne(l,Oe({name:"arrow-up"},()=>h,{get iconNode(){return _},children:(u,o)=>{var v=$e(),b=le(v);Te(b,n,"default",{}),y(u,v)},$$slots:{default:!0}}))}function qe(l,n){c(n,(e(n)+1)%24)}function Ke(l,n){c(n,(e(n)+23)%24)}function Qe(l,n){c(n,(e(n)+1)%60)}function Ue(l,n){c(n,(e(n)+59)%60)}var Xe=z("<option></option>"),Ye=z('<label><input type="checkbox" class="hidden"/> </label>'),et=l=>{!/^\d$/.test(l.key)&&l.key!=="Backspace"&&l.key!=="Tab"&&l.preventDefault()},tt=l=>{!/^\d$/.test(l.key)&&l.key!=="Backspace"&&l.key!=="Tab"&&l.preventDefault()},at=z('<div><span class="label"><span class="block text-sm font-medium">Select days to run test</span></span> <div class="grid grid-cols-7 gap-2"></div></div> <div class="py-2"><span class="label"><span class="block text-sm font-medium">Time</span></span> <div class="flex items-center gap-4"><div class="flex flex-col items-center"><button class="btn btn-xs"><!></button> <input class="input input-sm w-12 text-center font-mono"/> <button class="btn btn-xs"><!></button></div> <span class="text-xl font-bold">:</span> <div class="flex flex-col items-center"><button class="btn btn-xs"><!></button> <input class="input input-sm w-12 text-center font-mono"/> <button class="btn btn-xs"><!></button></div></div></div>',1),st=z('<div class="space-y-4 px-2 border border-base-300 bg-base-100"><div class="py-2"><select class="select select-bordered w-full"><option>Disabled</option><!></select></div> <!></div>');function nt(l,n){Ze(n,!0);let h=Ve(n,"sub",7),_=J(0),u=J(ze(new Set)),o=J(8),v=J(0);ge(()=>{const d=h().value;try{if(!d)return;const i=JSON.parse(d);c(_,typeof i.weeks=="number"?i.weeks:0,!0);const p=Array.isArray(i.days)?i.days.map(m=>Number(m)).filter(m=>m>=0&&m<=6):[];c(u,new Set(p),!0),c(o,typeof i.hours=="number"&&i.hours>=0&&i.hours<=23?i.hours:8,!0),c(v,typeof i.minutes=="number"&&i.minutes>=0&&i.minutes<=59?i.minutes:0,!0)}catch(i){console.warn("Failed to parse sub.value JSON:",i)}});const b=(d,i,p)=>Math.min(Math.max(d,i),p),g=d=>d.toString().padStart(2,"0");let w=me(()=>g(e(o))),k=me(()=>g(e(v)));const de=d=>{e(u).has(d)?e(u).delete(d):e(u).add(d),c(u,new Set(e(u)),!0)},Y=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"];ge(()=>{n.save&&W()});function W(){h().value=JSON.stringify({weeks:e(_),days:Array.from(e(u)).sort(),hours:e(o),minutes:e(v)}),f.publishSub(h())}var j=st(),P=a(j),R=a(P),D=a(R);D.value=D.__value=0;var ce=s(D);be(ce,16,()=>Array(10),fe,(d,i,p)=>{var m=Xe();m.textContent=`Every ${p+1} week${p===0?"":"s"}`,m.value=m.__value=p+1,y(d,m)}),t(R),t(P);var V=s(P,2);{var ee=d=>{var i=at(),p=le(i),m=s(a(p),2);be(m,21,()=>Y,fe,($,ne,L)=>{var O=Ye();let F;var G=a(O);H(G),G.__change=()=>de(L);var Q=s(G);t(O),pe((re,oe)=>{F=Ie(O,1,"btn btn-sm btn-outline cursor-pointer",null,F,re),Fe(G,oe),X(Q,` ${e(ne)??""}`)},[()=>({"btn-active":e(u).has(L)}),()=>e(u).has(L)]),y($,O)}),t(m),t(p);var te=s(p,2),q=s(a(te),2),M=a(q),N=a(M);N.__click=[qe,o];var ue=a(N);Se(ue,{}),t(N);var S=s(N,2);H(S),S.__keydown=[et];var T=s(S,2);T.__click=[Ke,o];var K=a(T);ke(K,{}),t(T),t(M);var E=s(M,4),x=a(E);x.__click=[Qe,v];var ae=a(x);Se(ae,{}),t(x);var A=s(x,2);H(A),A.__keydown=[tt];var I=s(A,2);I.__click=[Ue,v];var se=a(I);ke(se,{}),t(I),t(E),t(q),t(te),xe("blur",S,()=>{c(o,b(parseInt(e(w))||0,0,23),!0),c(w,g(e(o)),!0)}),C(S,()=>e(w),$=>c(w,$)),xe("blur",A,()=>{c(v,b(parseInt(e(k))||0,0,59),!0),c(k,g(e(v)),!0)}),C(A,()=>e(k),$=>c(k,$)),y(d,i)};_e(V,d=>{e(_)!==0&&d(ee)})}return t(j),Ae(R,()=>e(_),d=>c(_,d)),y(l,j),Me({saveSub:W})}De(["change","click","keydown"]);function rt(l,n){c(n,!0)}var ot=z('<button class="btn btn-error btn-sm">Delete zone</button>'),it=z("<option> </option>"),lt=z("--> <!>",1),dt=z('<section><div class="container mx-auto"><div class="flex items-center gap-2 sticky bg-base-100 z-40 pb-2" style="top:4.11rem"><!> <button class="btn btn-primary btn-sm">Save</button> <!></div> <div class="container mx-auto p-4"><div class="flex justify-between text-left mb-2"><h2 class="text-4xl font-semibold"> </h2></div> <div class="mt-3"><fieldset class="fieldset"><legend class="fieldset-legend">Zone Mode</legend> <select class="select text-lg input-bordered w-full"></select></fieldset> <div class="block text-sm font-medium">Name *</div> <div class="mt-1"><input type="text" placeholder="Name of zone..."/> <p class="text-error text-sm mt-1"> </p></div> <div class="block text-sm font-medium">Description</div> <div class="mt-1"><textarea rows="3" placeholder="Describe the zone..." class="textarea textarea-bordered w-full "> </textarea></div> <div class="block text-sm font-medium">Supplies</div> <div class="mt-1"><textarea rows="3" placeholder="Where does the zone supply air to?" class="textarea textarea-bordered w-full "> </textarea></div> <div class="block text-sm font-medium">Location</div> <div class="mt-1"><input type="text" class="input input-bordered w-full " placeholder="Where is the zone located?"/></div> <div class="mt-2 fieldset-legend"> </div> <div class="mt-1"><input type="range" min="0" max="180" class="range range-md"/></div> <div class="block text-sm font-medium">Test Schedule</div> <div class="mt-1"><!></div></div> <!></div></div></section>');function $t(l,n){Ze(n,!0);const h=Ge.params.id;let _=J(!1),u=J(!1),o=0;if(h.includes("new")){c(u,!0);const r=h.split("_");o=r.length>1?parseInt(r[1]):0}else o=parseInt(h);const v=new Z("Zones/"+o+"/Mode"),b=new Z("Zones/"+o+"/Name"),g=new Z("Zones/"+o+"/Description"),w=new Z("Zones/"+o+"/Location"),k=new Z("Zones/"+o+"/Supplies"),de=new Z("Zones/"+o+"/Status"),Y=new Z("Zones/"+o+"/TestSchedule"),W=new Z(`Zones/${o}/AlarmDelay`);let j=J(!1);function P(){f.publishSub(v),f.publishSub(b),f.publishSub(g),f.publishSub(w),f.publishSub(k),c(j,!0),history.back()}function R(){o!==1&&(f.publish(b.topic,""),f.publish(g.topic,""),f.publish(w.topic,""),f.publish(k.topic,""),f.publish(de.topic,""),f.publish(Y.topic,""),history.back())}let D=ze({id:"",name:""});function ce(){D.id=we.validZoneIdType(o),D.name=we.minLength(b.value,3)}var V=dt(),ee=a(V),d=a(ee),i=a(d);Pe(i);var p=s(i,2);p.__click=P;var m=s(p,2);{var te=r=>{var B=ot();B.__click=[rt,_],y(r,B)};_e(m,r=>{!e(u)&&o!==1&&r(te)})}t(d);var q=s(d,2),M=a(q),N=a(M),ue=a(N,!0);t(N),t(M);var S=s(M,2),T=a(S),K=s(a(T),2);be(K,21,()=>Object.entries(Re),fe,(r,B)=>{var ie=me(()=>Ee(e(B),2));let ve=()=>e(ie)[0],We=()=>e(ie)[1];var U=it(),je=a(U,!0);t(U);var he={};pe(()=>{X(je,ve()+": "+We()),he!==(he=ve())&&(U.value=(U.__value=ve())??"")}),y(r,U)}),t(K),t(T);var E=s(T,4),x=a(E);H(x),x.__input=ce;var ae=s(x,2),A=a(ae,!0);t(ae),t(E);var I=s(E,4),se=a(I);ye(se),t(I);var $=s(I,4),ne=a($);ye(ne),t($);var L=s($,4),O=a(L);H(O),t(L);var F=s(L,2),G=a(F);t(F);var Q=s(F,2),re=a(Q);H(re),t(Q);var oe=s(Q,4),Be=a(oe);nt(Be,{get save(){return e(j)},get sub(){return Y}}),t(oe),t(S);var Ce=s(S,2);{var Je=r=>{var B=lt(),ie=s(le(B));He(ie,{onClose:()=>{c(_,!1)},onDelete:()=>{R()}}),y(r,B)};_e(Ce,r=>{e(_)&&r(Je)})}t(q),t(ee),t(V),pe(()=>{X(ue,e(u)?"New Zone Details":"Edit Zone Details"),Ie(x,1,`input input-bordered w-full ${D.name?"input-error":""}`),X(A,D.name),X(G,`Alarm Delay: ${W.value??""} seconds`)}),Ae(K,()=>v.value,r=>v.value=r),C(x,()=>b.value,r=>b.value=r),C(se,()=>g.value,r=>g.value=r),C(ne,()=>k.value,r=>k.value=r),C(O,()=>w.value,r=>w.value=r),C(re,()=>W.value,r=>W.value=r),y(l,V),Me()}De(["click","input"]);export{$t as component};
