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