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