"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var s=require("../../_virtual/jsx-runtime.js"),p=require("react"),n=require("./styles.js");const q=(u,t)=>Math.ceil(u/t)*t,B=(u,t,o)=>u<t?t:u>t+o?t+o:u;function X({onChange:u,value:t,min:o=0,max:l=100,thumbText:m,minText:W,maxText:h,minMaxTextColor:k,variant:y="primary",stepValue:j,title:P,supportText:b,...g}){const E=p.useRef(null),[C,D]=p.useState(t),v=e=>100*(e-o)/(l-o),[R,f]=p.useState(v(t)),M=e=>(j&&(e=q(e,j)),e<o?o:e>l?l:e),L=(e,r)=>{const i=e.getBoundingClientRect().left,c=B(r,i,e.offsetWidth),d=Math.round((c-i)/e.offsetWidth*100);f(d);const a=Math.round(o+(l-o)*d/100);u(M(a))},S=e=>r=>{if(!r.touches[0])return;const i=r.touches[0].pageX;L(e,i)},T=e=>r=>{L(e,r.pageX)};return p.useEffect(()=>{t!==C&&(f(v(t)),D(M(t)))},[t]),p.useEffect(()=>{const e=E.current;if(e){const r=T(e),i=S(e),c=()=>{document.removeEventListener("mousemove",r),document.removeEventListener("mouseup",c)},d=x=>{x.preventDefault(),document.addEventListener("mousemove",r),document.addEventListener("mouseup",c),T(e)(x)},a=x=>{x.preventDefault(),S(e)(x)};return e.addEventListener("mousedown",d),e.addEventListener("touchmove",i),e.addEventListener("touchstart",a),e.addEventListener("touchend",c),()=>{e.removeEventListener("mousedown",d),e.removeEventListener("touchmove",i),e.removeEventListener("touchstart",a),e.removeEventListener("touchend",c)}}},[]),s.jsxRuntimeExports.jsxs(n.Wrapper,{...g,children:[s.jsxRuntimeExports.jsxs(n.Col,{children:[s.jsxRuntimeExports.jsxs(n.TextWrapper,{children:[s.jsxRuntimeExports.jsx(n.Title,{children:P}),s.jsxRuntimeExports.jsx(n.SupportText,{children:b})]}),s.jsxRuntimeExports.jsxs(n.SliderWrapper,{ref:E,isThumbText:!!m,children:[s.jsxRuntimeExports.jsx(n.Input,{type:"hidden",value:t,"data-testid":"slider-input"}),s.jsxRuntimeExports.jsx(n.Track,{position:R,trackColor:y}),s.jsxRuntimeExports.jsxs(n.ThumbWrapper,{position:R,children:[s.jsxRuntimeExports.jsx(n.Thumb,{}),s.jsxRuntimeExports.jsx(n.ThumbValue,{children:m})]})]})]}),s.jsxRuntimeExports.jsxs(n.MinMaxValuesWrapper,{onlyMax:!!h,children:[s.jsxRuntimeExports.jsx("span",{children:W}),s.jsxRuntimeExports.jsx("span",{children:h})]})]})}exports.Slider=X;
