import{d as be,f as V,a as T}from"../chunks/8V7BUHOp.js";import{p as _e,b as D,d as q,u as B,e as v,s as i,c,t as E,a as he,g as e,r as o,n as J}from"../chunks/CwuLZfOX.js";import{s as u}from"../chunks/CaaTB9LM.js";import{i as me}from"../chunks/ChcH33Yj.js";import{e as ue,s as L,a as K,b as Q,r as U,i as xe}from"../chunks/_j5m0PhM.js";import{b as ge}from"../chunks/Bn6k3L-0.js";import{S as w}from"../chunks/Bv7jGDQ6.js";import{G as ye}from"../chunks/DbXcF2pW.js";import{g as ke}from"../chunks/NG3eO5Vs.js";import{D as De,a as we}from"../chunks/CAzHP12M.js";var Ie=(l,d)=>v(d,!0),Se=(l,d)=>d(l.target.checked),ze=(l,d)=>ke("/devices/"+e(d).Id),Ze=l=>l.stopPropagation(),$e=(l,d,I)=>d(e(I).Id,l.target.checked),je=l=>l.stopPropagation(),He=V('<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>'),Ne=V('<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">Add Device</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 qe(l,d){_e(d,!0);const I=new w(["Devices/+/Health"]),W=new w(["Devices/+/Settings/Name"]),X=new w(["Devices/+/Settings/Zone"]),Y=new w(["Devices/+/Settings/Location"]);let b=D(q({}));B(()=>{const t={},a=[{data:I.getData(),apply:(s,n)=>s.Health=parseInt(n)},{data:W.getData(),apply:(s,n)=>s.Name=n},{data:Y.getData(),apply:(s,n)=>s.Location=n},{data:X.getData(),apply:(s,n)=>s.Zone=parseInt(n)}],p=s=>{const n=s.split("/");if(n.length<2)return null;const f=n[1];return/^\d+$/.test(f)?f: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[f,N]of Object.entries(s)){const h=p(f);if(!h)continue;const m=_(h);n(m,String(N))}v(O,Math.max(...Object.keys(t).map(Number))+1),v(b,t,!0)});let O=D(0),r=D(q(new Set)),x=null;const M=()=>Object.keys(e(b)).length,ee=()=>e(r).size>0&&e(r).size===M();B(()=>{x&&(x.indeterminate=e(r).size>0&&e(r).size<M())});function te(t,a){t!==void 0&&(a?e(r).add(t):e(r).delete(t),v(r,new Set(e(r)),!0))}function ae(t){if(t){const a=new Set;for(const p of Object.values(e(b)))p.Id!==void 0&&a.add(p.Id);v(r,a,!0)}else v(r,new Set,!0)}async function se(){var t;if(e(r).size!==0){for(const a of e(r))((t=e(b)[`${a}`])==null?void 0:t.Zone)!==void 0&&we(a,e(b)[`${a}`].Zone.toString());v(r,new Set,!0)}}let g=D(!1);var S=Ne(),z=c(S),Z=c(z),ne=c(Z);ye(ne,{}),o(Z);var $=i(Z,2),oe=i(c($),2);o($);var y=i($,2),j=c(y),ce=c(j);o(j);var re=i(j,2);re.__click=[Ie,g],J(2),o(y);var C=i(y,2),H=c(C),G=c(H),P=c(G),k=c(P);U(k),k.__change=[Se,ae],ge(k,t=>x=t,()=>x),o(P),J(4),o(G),o(H);var R=i(H);ue(R,21,()=>Object.values(e(b)),xe,(t,a)=>{var p=He();p.__click=[ze,a];var _=c(p);_.__click=[Ze];var s=c(_);U(s),s.__change=[$e,te,a],o(_);var n=i(_),f=c(n),N=c(f,!0);o(f),o(n);var h=i(n),m=c(h);m.__click=[je];var de=c(m,!0);o(m),o(h);var A=i(h),pe=c(A,!0);o(A);var F=i(A),ve=c(F,!0);o(F),o(p),E(fe=>{Q(s,fe),L(s,"aria-label",`Select device ${e(a).Id}`),K(f,1,"badge "+(e(a).Health===1?"badge-ghost":e(a).Health===3?"badge-error":"badge-warning")),u(N,e(a).Id),L(m,"href",`/zones/${e(a).Zone??""}`),u(de,e(a).Zone),u(pe,e(a).Name),u(ve,e(a).Location)},[()=>e(a).Id?e(r).has(e(a).Id):!1]),T(t,p)}),o(R),o(C),o(z);var le=i(z,2);{var ie=t=>{De(t,{deviceId:0,onClose:()=>{v(g,!1)},onDelete:()=>{se(),v(g,!1)}})};me(le,t=>{e(g)&&t(ie)})}o(S),E(t=>{L(oe,"href","/devices/new_"+e(O)+"/edit"),K(y,1,`mb-3 flex flex-wrap items-center gap-2 ${e(r).size?"":"opacity-0"}`),u(ce,`${e(r).size??""} selected`),Q(k,t)},[ee]),T(l,S),he()}be(["click","change"]);export{qe as component};
