import{c as q,b as A,n as z,d as G,r as V,u as J,e as B,o as Q,a5 as W,_ as Z,a as S,bC as _,$,s as p,bP as ee,p as te,aC as ae,a0 as ne,k as re}from"./index-869d77fb.js";const[le,g]=q("slider"),ie={min:A(0),max:A(100),step:A(1),range:Boolean,reverse:Boolean,disabled:Boolean,readonly:Boolean,vertical:Boolean,barHeight:z,buttonSize:z,activeColor:String,inactiveColor:String,modelValue:{type:[Number,Array],default:0}};var oe=G({name:le,props:ie,emits:["change","dragEnd","dragStart","update:modelValue"],setup(t,{emit:b,slots:C}){let m,o,c;const N=V(),P=[V(),V()],u=V(),v=J(),f=B(()=>Number(t.max)-Number(t.min)),I=B(()=>{const e=t.vertical?"width":"height";return{background:t.inactiveColor,[e]:Q(t.barHeight)}}),s=e=>t.range&&Array.isArray(e),M=()=>{const{modelValue:e,min:a}=t;return s(e)?`${(e[1]-e[0])*100/f.value}%`:`${(e-Number(a))*100/f.value}%`},R=()=>{const{modelValue:e,min:a}=t;return s(e)?`${(e[0]-Number(a))*100/f.value}%`:"0%"},X=B(()=>{const a={[t.vertical?"height":"width"]:M(),background:t.activeColor};u.value&&(a.transition="none");const n=()=>t.vertical?t.reverse?"bottom":"top":t.reverse?"right":"left";return a[n()]=R(),a}),h=e=>{const a=+t.min,n=+t.max,l=+t.step;e=ne(e,a,n);const r=Math.round((e-a)/l)*l;return ee(a,r)},k=()=>{const e=t.modelValue;s(e)?c=e.map(h):c=h(e)},Y=e=>{var a,n;const l=(a=e[0])!=null?a:Number(t.min),r=(n=e[1])!=null?n:Number(t.max);return l>r?[r,l]:[l,r]},d=(e,a)=>{s(e)?e=Y(e).map(h):e=h(e),_(e,t.modelValue)||b("update:modelValue",e),a&&!_(e,c)&&b("change",e)},D=e=>{if(e.stopPropagation(),t.disabled||t.readonly)return;k();const{min:a,reverse:n,vertical:l,modelValue:r}=t,i=$(N),O=()=>l?n?i.bottom-e.clientY:e.clientY-i.top:n?i.right-e.clientX:e.clientX-i.left,U=l?i.height:i.width,y=Number(a)+O()/U*f.value;if(s(r)){const[T,E]=r,j=(T+E)/2;y<=j?d([y,E],!0):d([T,y],!0)}else d(y,!0)},H=e=>{t.disabled||t.readonly||(v.start(e),o=t.modelValue,k(),u.value="start")},F=e=>{if(t.disabled||t.readonly)return;u.value==="start"&&b("dragStart",e),te(e,!0),v.move(e),u.value="dragging";const a=$(N),n=t.vertical?v.deltaY.value:v.deltaX.value,l=t.vertical?a.height:a.width;let r=n/l*f.value;if(t.reverse&&(r=-r),s(c)){const i=t.reverse?1-m:m;o[i]=c[i]+r}else o=c+r;d(o)},x=e=>{t.disabled||t.readonly||(u.value==="dragging"&&(d(o,!0),b("dragEnd",e)),u.value="")},K=e=>typeof e=="number"?g("button-wrapper",["left","right"][e]):g("button-wrapper",t.reverse?"left":"right"),L=(e,a)=>{const n=u.value==="dragging";if(typeof a=="number"){const l=C[a===0?"left-button":"right-button"];let r;if(n&&Array.isArray(o)&&(r=o[0]>o[1]?m^1:m),l)return l({value:e,dragging:n,dragIndex:r})}return C.button?C.button({value:e,dragging:n}):S("div",{class:g("button"),style:ae(t.buttonSize)},null)},w=e=>{const a=typeof e=="number"?t.modelValue[e]:t.modelValue;return S("div",{ref:P[e!=null?e:0],role:"slider",class:K(e),tabindex:t.disabled?void 0:0,"aria-valuemin":t.min,"aria-valuenow":a,"aria-valuemax":t.max,"aria-disabled":t.disabled||void 0,"aria-readonly":t.readonly||void 0,"aria-orientation":t.vertical?"vertical":"horizontal",onTouchstartPassive:n=>{typeof e=="number"&&(m=e),H(n)},onTouchend:x,onTouchcancel:x,onClick:p},[L(a,e)])};return d(t.modelValue),W(()=>t.modelValue),P.forEach(e=>{Z("touchmove",F,{target:e})}),()=>S("div",{ref:N,style:I.value,class:g({vertical:t.vertical,disabled:t.disabled}),onClick:D},[S("div",{class:g("bar"),style:X.value},[t.range?[w(0),w(1)]:w()])])}});const ce=re(oe);export{ce as S};