import{toConsumableArray as n,slicedToArray as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import{useCallback as r,useMemo as t,useState as u,useRef as i,useEffect as o}from"react";import l from"../../hooks/useResizeObserver.js";import{NOOP as a}from"../../utils/function-utils.js";import{UPDATE_SLIDER_SIZE_DEBOUNCE as c}from"./SliderConstants.js";import{ensureValueText as f}from"./SliderHelpers.js";function s(u,i,o,l,c,f,s,d,v,m,g,h,p){var V=r((function(n){h(n),"function"==typeof s&&s(n)}),[h,s]),b=r((function(n,e){return""===e||Number.isNaN(Number(e))?1===n?c:f:e>c?c:f>e?f:e}),[f,c]),x=r((function(e){var r=n(l()),t=r[1];return 1===e.index?[r[0],b(e.index,e.newValue)]:[b(e.index,e.newValue),t]}),[b,l]),w=r((function(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:a,t=x(n),u=e(t,2),i=u[0],o=u[1];return o>i?[i,o]:(r(0===n.index?1:0),[o,i])}),[x]),j=r((function(n){v(n),m(n),g(n)}),[v,m,g]),C=r((function(n){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0,r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(d){var t={newValue:n,index:null!=e?e:i},u=r?a:m,o=w(t,u);V(o)}else V(b(null,n))}),[V,w,b,i,d,m]),T=r((function(n){var e;if(d){var r={newValue:n,index:null!==(e=o())&&void 0!==e?e:0},t=w(r,j);V(t)}else V(b(null,n))}),[V,w,j,b,o,d]),N=r((function(n){var e=d?u[i]:u;e!==f&&C(e-(n||p))}),[u,C,i,f,d,p]),S=r((function(n){var e=d?u[i]:u;e!==c&&C(e+(n||p))}),[u,C,i,c,d,p]);return t((function(){return{changeThumbValue:C,decreaseValue:N,drugThumb:T,increaseValue:S,setActive:v,setDragging:g,setFocused:m}}),[C,N,T,S,v,g,m])}function d(){var n=u(null),t=e(n,2),o=t[0],l=t[1],a=i(null);return[o,r((function(n){l(n),a.current=n}),[l,a]),r((function(){return a.current}),[a])]}function v(){var n=i(null),t=u({left:0,right:100,width:100}),a=e(t,2),f=a[0],s=a[1],d=r((function(){if(n.current){var e=n.current.getBoundingClientRect();s({left:e.left,right:e.right,width:e.width})}}),[n,s]);return l({ref:n,callback:d,debounceTime:c}),o((function(){d()}),[d]),{railCoords:f,railRef:n}}function m(n,t,o,l){var c=function(n){var r=u(void 0!==n);return e(r,1)[0]}(t),s=function(n,r,t){var i=u(r?t:n),o=e(i,2);return r?[t,a]:[o[0],o[1]]}(n,c,t),d=e(s,2),v=d[0],m=d[1],g=i(v),h=r((function(n){m(n),g.current=n}),[g,m]),p=r((function(){return g.current}),[g]);return{actualValue:v,actualValueText:f(l,v,o),getSelectedValue:p,isControlled:c,setSelectedValue:h}}export{d as useDragging,s as useSliderActionsContextValue,v as useSliderRail,m as useSliderValues};
