import{c as Me,a as x,d as Ne,f as $,s as oe,e as we,r as ke}from"../chunks/DktbhmWA.js";import{f as te,p as Ae,d as V,e as Ie,u as Se,c as s,g as e,a as Te,s as n,b as c,r as a,t as de,h as ce,i as Ve}from"../chunks/CPWcrcMP.js";import{i as ie}from"../chunks/0jvM7PZf.js";import{I as Le,h as Oe,d as We,e as he,f as Be,m as f,i as ge,r as le,a as xe,b as je,c as T,A as Fe}from"../chunks/BxBMkMrU.js";import{b as ee}from"../chunks/CFyEX9sq.js";import{p as Ge}from"../chunks/7Hp69y-k.js";import{i as De}from"../chunks/C0fAtm-M.js";import{D as He}from"../chunks/CKzwkw8K.js";import"../chunks/DUxDMF0-.js";import{G as Pe}from"../chunks/BCw68WiA.js";import{a as Re}from"../chunks/CngRAepr.js";import{l as Ce,s as Ee,p as qe}from"../chunks/DBypTyp2.js";import"../chunks/BhDuCDh7.js";import{I as Ze}from"../chunks/Cp1XlDVa.js";function ze(i,t){const h=Ce(t,["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 m=[["path",{d:"M12 5v14"}],["path",{d:"m19 12-7 7-7-7"}]];Le(i,Ee({name:"arrow-down"},()=>h,{get iconNode(){return m},children:(v,o)=>{var u=Me(),g=te(u);Oe(g,t,"default",{}),x(v,u)},$$slots:{default:!0}}))}function $e(i,t){const h=Ce(t,["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 m=[["path",{d:"m5 12 7-7 7 7"}],["path",{d:"M12 19V5"}]];Le(i,Ee({name:"arrow-up"},()=>h,{get iconNode(){return m},children:(v,o)=>{var u=Me(),g=te(u);Oe(g,t,"default",{}),x(v,u)},$$slots:{default:!0}}))}function Ue(i,t){c(t,(e(t)+1)%24)}function Ke(i,t){c(t,(e(t)+23)%24)}function Qe(i,t){c(t,(e(t)+1)%60)}function Xe(i,t){c(t,(e(t)+59)%60)}var Ye=$("<option></option>"),et=$('<label><input type="checkbox" class="hidden"/> </label>'),tt=i=>{!/^\d$/.test(i.key)&&i.key!=="Backspace"&&i.key!=="Tab"&&i.preventDefault()},at=i=>{!/^\d$/.test(i.key)&&i.key!=="Backspace"&&i.key!=="Tab"&&i.preventDefault()},st=$('<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),nt=$('<div class="space-y-4 px-2 border border-base-300 bg-base-100"><div class="py-2"><select><option>Disabled</option><!></select></div> <!></div>');function rt(i,t){Ae(t,!0);let h=qe(t,"sub",7),m=V(0),v=V(Ie(new Set)),o=V(8),u=V(0);Se(()=>{const l=h().value;try{if(!l)return;const r=JSON.parse(l);c(m,typeof r.weeks=="number"?r.weeks:0,!0);const b=Array.isArray(r.days)?r.days.map(p=>Number(p)).filter(p=>p>=0&&p<=6):[];c(v,new Set(b),!0),c(o,typeof r.hours=="number"&&r.hours>=0&&r.hours<=23?r.hours:8,!0),c(u,typeof r.minutes=="number"&&r.minutes>=0&&r.minutes<=59?r.minutes:0,!0)}catch(r){console.warn("Failed to parse sub.value JSON:",r)}});const g=(l,r,b)=>Math.min(Math.max(l,r),b),S=l=>l.toString().padStart(2,"0");let M=ce(()=>S(e(o))),D=ce(()=>S(e(u)));const ve=l=>{e(v).has(l)?e(v).delete(l):e(v).add(l),c(v,new Set(e(v)),!0)},ae=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"];Se(()=>{t.save&&W()});function W(){h().value=JSON.stringify({weeks:e(m),days:Array.from(e(v)).sort(),hours:e(o),minutes:e(u)}),f.publishSub(h())}var j=nt(),q=s(j),F=s(q);We(F,()=>({class:"select 'select-bordered' w-full",...t.disabled?{disabled:!0}:{}}));var L=s(F);L.value=L.__value=0;var ue=n(L);he(ue,16,()=>Array(10),ge,(l,r,b)=>{var p=Ye();p.textContent=`Every ${b+1} week${b===0?"":"s"}`,p.value=p.__value=b+1,x(l,p)}),a(F),a(q);var _=n(q,2);{var U=l=>{var r=st(),b=te(r),p=n(s(b),2);he(p,21,()=>ae,ge,(Z,pe,C)=>{var P=et();let R;var k=s(P);le(k),k.__change=()=>ve(C);var ne=n(k);a(P),de((me,_e)=>{R=xe(P,1,`btn btn-sm ${t.disabled?"btn-ghost":"btn-outline"} cursor-pointer`,null,R,me),k.disabled=t.disabled,je(k,_e),oe(ne,` ${e(pe)??""}`)},[()=>({"btn-active":e(v).has(C)}),()=>e(v).has(C)]),x(Z,P)}),a(p),a(b);var se=n(b,2),K=n(s(se),2),O=s(K),N=s(O);N.__click=[Ue,o];var be=s(N);$e(be,{}),a(N);var y=n(N,2);le(y),y.__keydown=[tt];var A=n(y,2);A.__click=[Ke,o];var G=s(A);ze(G,{}),a(A),a(O);var H=n(O,4),B=s(H);B.__click=[Qe,u];var Q=s(B);$e(Q,{}),a(B);var w=n(B,2);le(w),w.__keydown=[at];var I=n(w,2);I.__click=[Xe,u];var X=s(I);ze(X,{}),a(I),a(H),a(K),a(se),de(()=>{N.disabled=t.disabled,y.disabled=t.disabled,A.disabled=t.disabled,B.disabled=t.disabled,w.disabled=t.disabled,I.disabled=t.disabled}),we("blur",y,()=>{c(o,g(parseInt(e(M))||0,0,23),!0),c(M,S(e(o)),!0)}),ee(y,()=>e(M),Z=>c(M,Z)),we("blur",w,()=>{c(u,g(parseInt(e(D))||0,0,59),!0),c(D,S(e(u)),!0)}),ee(w,()=>e(D),Z=>c(D,Z)),x(l,r)};ie(_,l=>{e(m)!==0&&l(U)})}return a(j),Be(F,()=>e(m),l=>c(m,l)),x(i,j),Te({saveSub:W})}Ne(["change","click","keydown"]);function ot(i,t){c(t,!0)}var it=$('<button class="btn btn-error btn-sm">Delete zone</button>'),lt=$('<button class="btn btn-primary btn-sm">Save</button> <!>',1),dt=$("<option> </option>"),ct=$("--> <!>",1),vt=$('<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"><!> <!></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></select></fieldset> <div class="block text-sm font-medium">Name *</div> <div class="mt-1"><!></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"><!></div> <div class="mt-2 fieldset-legend"> </div> <div class="mt-1"><input type="range" min="0" max="180"/></div> <div class="block text-sm font-medium">Test Schedule</div> <div class="mt-1"><!></div></div> <!></div></div></section>');function Zt(i,t){Ae(t,!0);const h=Ge.params.id;let m=V(!1),v=V(!1),o=0;if(h.includes("new")){c(v,!0);const d=h.split("_");o=d.length>1?parseInt(d[1]):0}else o=parseInt(h);const u=new T("Zones/"+o+"/Mode"),g=new T("Zones/"+o+"/Name"),S=new T("Zones/"+o+"/Description"),M=new T("Zones/"+o+"/Location"),D=new T("Zones/"+o+"/Supplies"),ve=new T("Zones/"+o+"/Status"),ae=new T("Zones/"+o+"/TestSchedule"),W=new T(`Zones/${o}/AlarmDelay`);let j=V(!1);function q(){f.publishSub(u),f.publishSub(g),f.publishSub(S),f.publishSub(M),f.publishSub(D),c(j,!0),history.back()}function F(){o!==1&&(f.publish(g.topic,""),f.publish(S.topic,""),f.publish(M.topic,""),f.publish(D.topic,""),f.publish(ve.topic,""),f.publish(ae.topic,""),history.back())}let L=Ie({id:"",name:""});function ue(){L.id=De.validZoneIdType(o),L.name=De.minLength(g.value,3)}const _=ce(()=>!Fe.canEditZones);var U=vt(),l=s(U),r=s(l),b=s(r);Pe(b);var p=n(b,2);{var se=d=>{var E=lt(),J=te(E);J.__click=q;var Y=n(J,2);{var fe=z=>{var re=it();re.__click=[ot,m],x(z,re)};ie(Y,z=>{!e(v)&&o!==1&&z(fe)})}x(d,E)};ie(p,d=>{e(_)||d(se)})}a(r);var K=n(r,2),O=s(K),N=s(O),be=s(N,!0);a(N),a(O);var y=n(O,2),A=s(y),G=n(s(A),2);he(G,21,()=>Object.entries(Re),ge,(d,E)=>{var J=ce(()=>Ve(e(E),2));let Y=()=>e(J)[0],fe=()=>e(J)[1];var z=dt(),re=s(z,!0);a(z);var ye={};de(()=>{oe(re,Y()+": "+fe()),ye!==(ye=Y())&&(z.value=(z.__value=Y())??"")}),x(d,z)}),a(G),a(A);var H=n(A,4),B=s(H);Ze(B,{type:"text",get value(){return g},placeholder:"Name of zone...",get error(){return L.name},get disabled(){return e(_)},onInput:ue}),a(H);var Q=n(H,4),w=s(Q);ke(w),a(Q);var I=n(Q,4),X=s(I);ke(X),a(I);var Z=n(I,4),pe=s(Z);Ze(pe,{type:"text",get value(){return M},placeholder:"Where is the zone located?",get disabled(){return e(_)}}),a(Z);var C=n(Z,2),P=s(C);a(C);var R=n(C,2),k=s(R);le(k),a(R);var ne=n(R,4),me=s(ne);rt(me,{get save(){return e(j)},get sub(){return ae},get disabled(){return e(_)}}),a(ne),a(y);var _e=n(y,2);{var Je=d=>{var E=ct(),J=n(te(E));He(J,{onClose:()=>{c(m,!1)},onDelete:()=>{F()}}),x(d,E)};ie(_e,d=>{e(m)&&d(Je)})}a(K),a(l),a(U),de(()=>{oe(be,e(_)?"View Zone Details":e(v)?"New Zone Details":"Edit Zone Details"),xe(G,1,`select text-lg ${e(_)?"input-disabled":"input-bordered"} w-full`),w.disabled=e(_),X.disabled=e(_),oe(P,`Alarm Delay: ${W.value??""} seconds`),k.disabled=e(_),xe(k,1,`range range-md ${e(_)?"range-secondary":""}`)}),Be(G,()=>u.value,d=>u.value=d),ee(w,()=>S.value,d=>S.value=d),ee(X,()=>D.value,d=>D.value=d),ee(k,()=>W.value,d=>W.value=d),x(i,U),Te()}Ne(["click"]);export{Zt as component};
