import{h as t,j as w,k as b,l as C,m as g,q as _}from"./CZBSCAq2.js";import{l as n}from"./DqKNatLn.js";const k=new Set;function S(r,d,e,l,f=l){var s=e.getAttribute("type")==="checkbox",c=r;let o=!1;if(d!==null)for(var v of d)c=c[v]??(c[v]=[]);c.push(e),n(e,"change",()=>{var a=e.__value;s&&(a=m(c,a,e.checked)),f(a)},()=>f(s?[]:null)),b(()=>{var a=l();if(t&&e.defaultChecked!==e.checked){o=!0;return}s?(a=a||[],e.checked=a.includes(e.__value)):e.checked=C(e.__value,a)}),g(()=>{var a=c.indexOf(e);a!==-1&&c.splice(a,1)}),k.has(c)||(k.add(c),_(()=>{c.sort((a,h)=>a.compareDocumentPosition(h)===4?-1:1),k.delete(c)})),_(()=>{if(o){var a;if(s)a=m(c,a,e.checked);else{var h=c.find(u=>u.checked);a=h==null?void 0:h.__value}f(a)}})}function j(r,d,e=d){n(r,"change",l=>{var f=l?r.defaultChecked:r.checked;e(f)}),(t&&r.defaultChecked!==r.checked||w(d)==null)&&e(r.checked),b(()=>{var l=d();r.checked=!!l})}function m(r,d,e){for(var l=new Set,f=0;f<r.length;f+=1)r[f].checked&&l.add(r[f].__value);return e||l.delete(d),Array.from(l)}export{S as a,j as b};
