const t=(t,a)=>Math.max(0,Math.min(a,t.width))/t.width*100,a=(t,a)=>{const n=a.minValue+t/100*(a.maxValue-a.minValue);return a.maxValue-a.minValue<1?parseFloat(n.toFixed(2)):Math.floor(n)},n=(t,a)=>(t-a.minValue)/(a.maxValue-a.minValue)*100,o=(n,o,e)=>{const s=n.clientX-o.left,u=t(o,s);e.value=a(u,e),e.emit("nile-change",{value:e.value}),e.buttonOne.style.left=`${u}%`,e.completed.style.width=`${u}%`},e=(n,o,e)=>{const s=n.clientX-o.left,u=t(o,s);e.rangeOneValue=a(u,e),e.rangeOneValue=Math.min(e.rangeOneValue,e.rangeTwoValue),e.emit("nile-button-first-change",{value:e.rangeOneValue}),e.rangeTwoValue>e.rangeOneValue&&(e.buttonOne.style.left=`${u}%`)},s=(n,o,e)=>{const s=n.clientX-o.left,u=t(o,s);e.rangeTwoValue=a(u,e),e.rangeTwoValue=Math.max(e.rangeTwoValue,e.rangeOneValue),e.emit("nile-button-last-change",{value:e.rangeTwoValue}),e.rangeTwoValue>e.rangeOneValue&&(e.buttonTwo.style.left=`${u}%`)},u=t=>{t.range=t.renderRoot.querySelector(".range"),t.buttonOne=t.renderRoot.querySelector(".range-button"),t.buttonTwo=t.renderRoot.querySelector(".range-button-two"),t.completed=t.renderRoot.querySelector(".range-completed"),t.range.addEventListener("mousedown",t.onMouseDown),t.buttonOne?.addEventListener("mousedown",(()=>{t.activeThumb="one",h(t)})),t.buttonTwo?.addEventListener("mousedown",(()=>{t.activeThumb="two",h(t)}))},h=t=>{window.addEventListener("mousemove",t.onMouseMove),window.addEventListener("mouseup",t.onMouseUp)},c=t=>{window.removeEventListener("mousemove",t.onMouseMove),window.removeEventListener("mouseup",t.onMouseUp)},l=(t,a)=>{if(Math.abs(t-a.rangeOneValue)<=Math.abs(t-a.rangeTwoValue)){const n=Math.min(t,a.rangeTwoValue);a.rangeOneValue=a.checkValueValidity(n,a.minValue,a.maxValue)}else{const n=Math.max(t,a.rangeOneValue);a.rangeTwoValue=a.checkValueValidity(n,a.minValue,a.maxValue)}const o=n(a.rangeOneValue,a),e=n(a.rangeTwoValue,a);a.buttonOne.style.left=`${o}%`,a.buttonTwo.style.left=`${e}%`;const s=Math.min(o,e),u=Math.abs(e-o);a.completed.style.left=`${s}%`,a.completed.style.width=`${u}%`,a.emit("nile-button-first-change",{value:a.rangeOneValue}),a.emit("nile-button-last-change",{value:a.rangeTwoValue})};export{e as a,s as b,h as c,l as d,u as g,o as h,c as r,n as v};
