import{l as y,D as u,a as b,d as o,e as g,h as x,u as D,f as S,p as V,g as q,j as w,q as k}from"./C9jiJh7I.js";function j(e,f,r=f){var d=new WeakSet;y(e,"input",async l=>{u&&e.type==="checkbox"&&b();var v=l?e.defaultValue:e.value;if(v=i(e)?h(v):v,r(v),o!==null&&d.add(o),await g(),v!==(v=f())){var c=e.selectionStart,s=e.selectionEnd,_=e.value.length;if(e.value=v??"",s!==null){var a=e.value.length;c===s&&s===_&&a>_?(e.selectionStart=a,e.selectionEnd=a):(e.selectionStart=c,e.selectionEnd=Math.min(s,a))}}}),(x&&e.defaultValue!==e.value||D(f)==null&&e.value)&&(r(i(e)?h(e.value):e.value),o!==null&&d.add(o)),S(()=>{u&&e.type==="checkbox"&&b();var l=f();if(e===document.activeElement){var v=V??o;if(d.has(v))return}i(e)&&l===h(e.value)||e.type==="date"&&!l&&!e.value||l!==e.value&&(e.value=l??"")})}const n=new Set;function C(e,f,r,d,l=d){var v=r.getAttribute("type")==="checkbox",c=e;let s=!1;if(f!==null)for(var _ of f)c=c[_]??=[];c.push(r),y(r,"change",()=>{var a=r.__value;v&&(a=m(c,a,r.checked)),l(a)},()=>l(v?[]:null)),S(()=>{var a=d();if(x&&r.defaultChecked!==r.checked){s=!0;return}v?(a=a||[],r.checked=a.includes(r.__value)):r.checked=q(r.__value,a)}),w(()=>{var a=c.indexOf(r);a!==-1&&c.splice(a,1)}),n.has(c)||(n.add(c),k(()=>{c.sort((a,t)=>a.compareDocumentPosition(t)===4?-1:1),n.delete(c)})),k(()=>{if(s){var a;if(v)a=m(c,a,r.checked);else{var t=c.find(E=>E.checked);a=t?.__value}l(a)}})}function m(e,f,r){for(var d=new Set,l=0;l<e.length;l+=1)e[l].checked&&d.add(e[l].__value);return r||d.delete(f),Array.from(d)}function i(e){var f=e.type;return f==="number"||f==="range"}function h(e){return e===""?null:+e}export{C as a,j as b};
