import{d as me,f as C,a as O,s as m}from"../chunks/DktbhmWA.js";import{p as xe,d as D,e as B,u as J,b as v,s as l,c,t as M,a as ge,g as e,r as o,h as ye,n as K}from"../chunks/CPWcrcMP.js";import{i as Q}from"../chunks/0jvM7PZf.js";import{S as w,s as I,e as ke,a as V,b as W,r as X,i as De,A as we}from"../chunks/CNDZS43m.js";import{b as Ie}from"../chunks/CX78IQmC.js";import{G as Se}from"../chunks/hnRDlRMB.js";import{g as ze}from"../chunks/DyeZe3S9.js";import{D as Ze,a as Ae}from"../chunks/CD4kt3n5.js";var $e=C('<a class="btn btn-primary btn-sm">Add Device</a>'),je=(i,d)=>v(d,!0),He=(i,d)=>d(i.target.checked),Ne=(i,d)=>ze("/devices/"+e(d).Id),Le=i=>i.stopPropagation(),Oe=(i,d,S)=>d(e(S).Id,i.target.checked),Me=i=>i.stopPropagation(),Ce=C('<tr class="hover:bg-base-300 cursor-pointer"><td class="px-2 py-2"><input type="checkbox" class="checkbox checkbox-sm"/></td><td class="px-2 py-2"><span> </span></td><td class="px-2 py-2"><a class="badge badge-ghost"> </a></td><td class="px-2 py-2 max-w-48"> </td><td class="px-2 py-2"> </td></tr>'),Ge=C('<section><div class="container mx-auto"><div class="flex items-center gap-2 sticky bg-base-100 z-40" style="top:4.11rem"><!></div> <div class="flex justify-between text-left mb-2"><h2 class="text-4xl font-semibold">Devices</h2> <a class="btn btn-primary btn-sm">Scan for devices</a> <!></div> <div><span class="text-sm opacity-70"> </span> <button class="btn btn-sm btn-error">Delete selected</button> <button class="btn btn-sm btn-ghost">More actions here...</button></div> <table class="table table-sm w-full"><thead><tr><th class="px-2 py-2 w-10"><input type="checkbox" class="checkbox checkbox-sm" aria-label="Select all devices"/></th><th class="px-2 py-2 text-xs">ID</th><th class="px-2 py-2 text-xs">Zone</th><th class="px-2 py-2 text-xs">Name</th><th class="px-2 py-2 text-xs">Location</th></tr></thead><tbody></tbody></table></div> <!></section>');function Je(i,d){xe(d,!0);const S=new w(["Devices/+/Health"]),Y=new w(["Devices/+/Settings/Name"]),ee=new w(["Devices/+/Settings/Zone"]),te=new w(["Devices/+/Settings/Location"]);let f=D(B({}));J(()=>{const t={},a=[{data:S.getData(),apply:(s,n)=>s.Health=parseInt(n)},{data:Y.getData(),apply:(s,n)=>s.Name=n},{data:te.getData(),apply:(s,n)=>s.Location=n},{data:ee.getData(),apply:(s,n)=>s.Zone=parseInt(n)}],p=s=>{const n=s.split("/");if(n.length<2)return null;const b=n[1];return/^\d+$/.test(b)?b:null},_=s=>{const n=t[s]??(t[s]={});return n.Id===void 0&&(n.Id=parseInt(s)),n};for(const{data:s,apply:n}of a)for(const[b,N]of Object.entries(s)){const h=p(b);if(!h)continue;const u=_(h);n(u,String(N))}v(G,Math.max(0,...Object.keys(t).map(Number))+1),v(f,t,!0)});let G=D(0),r=D(B(new Set)),x=null;const P=()=>Object.keys(e(f)).length,ae=()=>e(r).size>0&&e(r).size===P();J(()=>{x&&(x.indeterminate=e(r).size>0&&e(r).size<P())});function se(t,a){t!==void 0&&(a?e(r).add(t):e(r).delete(t),v(r,new Set(e(r)),!0))}function ne(t){if(t){const a=new Set;for(const p of Object.values(e(f)))p.Id!==void 0&&a.add(p.Id);v(r,a,!0)}else v(r,new Set,!0)}async function oe(){var t;if(e(r).size!==0){for(const a of e(r))((t=e(f)[`${a}`])==null?void 0:t.Zone)!==void 0&&Ae(a,e(f)[`${a}`].Zone.toString());v(r,new Set,!0)}}let g=D(!1);const ce=ye(()=>!we.canEditDevices);var z=Ge(),Z=c(z),A=c(Z),re=c(A);Se(re,{}),o(A);var $=l(A,2),R=l(c($),2);I(R,"href","/discover");var le=l(R,2);{var ie=t=>{var a=$e();M(()=>I(a,"href","/devices/new_"+e(G)+"/edit")),O(t,a)};Q(le,t=>{e(ce)||t(ie)})}o($);var y=l($,2),j=c(y),de=c(j);o(j);var pe=l(j,2);pe.__click=[je,g],K(2),o(y);var E=l(y,2),H=c(E),F=c(H),T=c(F),k=c(T);X(k),k.__change=[He,ne],Ie(k,t=>x=t,()=>x),o(T),K(4),o(F),o(H);var U=l(H);ke(U,21,()=>Object.values(e(f)),De,(t,a)=>{var p=Ce();p.__click=[Ne,a];var _=c(p);_.__click=[Le];var s=c(_);X(s),s.__change=[Oe,se,a],o(_);var n=l(_),b=c(n),N=c(b,!0);o(b),o(n);var h=l(n),u=c(h);u.__click=[Me];var fe=c(u,!0);o(u),o(h);var L=l(h),_e=c(L,!0);o(L);var q=l(L),he=c(q,!0);o(q),o(p),M(ue=>{W(s,ue),I(s,"aria-label",`Select device ${e(a).Id}`),V(b,1,"badge "+(e(a).Health===1?"badge-ghost":e(a).Health===3?"badge-error":"badge-warning")),m(N,e(a).Id),I(u,"href",`/zones/${e(a).Zone??""}`),m(fe,e(a).Zone),m(_e,e(a).Name),m(he,e(a).Location)},[()=>e(a).Id?e(r).has(e(a).Id):!1]),O(t,p)}),o(U),o(E),o(Z);var ve=l(Z,2);{var be=t=>{Ze(t,{deviceId:0,onClose:()=>{v(g,!1)},onDelete:()=>{oe(),v(g,!1)}})};Q(ve,t=>{e(g)&&t(be)})}o(z),M(t=>{V(y,1,`mb-3 flex flex-wrap items-center gap-2 ${e(r).size?"":"opacity-0"}`),m(de,`${e(r).size??""} selected`),W(k,t)},[ae]),O(i,z),ge()}me(["click","change"]);export{Je as component};
