import _slicedToArray from"@babel/runtime/helpers/slicedToArray";import _objectWithoutProperties from"@babel/runtime/helpers/objectWithoutProperties";var _excluded=["steps","direction","size","className","activeStepIndex","onItemClick","getItemContent","getItemLabel","getItemPoint","getItemProgress","getItemStatus","getItemTooltipContent","getItemLineStatus","getItemOnClick","style"];import"./ProgressStepBar.css";import{IconArrowLeft}from"@consta/icons/IconArrowLeft";import{IconArrowRight}from"@consta/icons/IconArrowRight";import React,{createRef,forwardRef,useEffect,useLayoutEffect,useMemo,useRef,useState}from"react";import{cnMixScrollBar}from"../../mixs/MixScrollBar";import{useComponentSize}from"../../hooks/useComponentSize/useComponentSize";import{useForkRef}from"../../hooks/useForkRef/useForkRef";import{useOverflow}from"../../hooks/useOverflow/useOverflow";import{useScrollElements}from"../../hooks/useScrollElements/useScrollElements";import{Button}from"../Button/Button";import{usePropsHandler}from"../EventInterceptor/usePropsHandler";import{calculateLines,cnProgressStepBar,getItemPosition,progressStepBarPropDirectionDefault,progressStepBarPropSizeDefault,withDefaultGetters}from"./helpers";import{ProgressStepBarItem}from"./ProgressStepBarItem/ProgressStepBarItem";import{ProgressStepBarLine}from"./ProgressStepBarLine/ProgressStepBarLine";export var COMPONENT_NAME="ProgressStepBar";function ProgressStepBarRender(a,b){var c=useRef(null),d=usePropsHandler(COMPONENT_NAME,withDefaultGetters(a),c),e=d.steps,f=void 0===e?[]:e,g=d.direction,h=void 0===g?progressStepBarPropDirectionDefault:g,i=d.size,j=void 0===i?progressStepBarPropSizeDefault:i,k=d.className,l=d.activeStepIndex,m=d.onItemClick,n=d.getItemContent,o=d.getItemLabel,p=d.getItemPoint,q=d.getItemProgress,r=d.getItemStatus,s=d.getItemTooltipContent,t=d.getItemLineStatus,u=d.getItemOnClick,v=d.style,w=_objectWithoutProperties(d,_excluded),x=useState(l||0),y=_slicedToArray(x,2),z=y[0],A=y[1],B=useState([]),C=_slicedToArray(B,2),D=C[0],E=C[1],F=useRef(null),G=useComponentSize(c),H=G.width,I=G.height,J=useScrollElements(f),K=J.refs,L=J.scrollTo,M=useMemo(function(){return Array(f.length).fill(null).map(function(){return createRef()})},[f.length]);useLayoutEffect(function(){var a=[],b=calculateLines(K,h);f.forEach(function(c,d){var e;d!==f.length-1&&a.push({status:t(c)||"normal",size:null!==(e=b[d])&&void 0!==e?e:0})}),E(a)},[l,f,h,j,H,I]),useEffect(function(){A(l||0)},[l]),useEffect(function(){L(z)},[z]);var N=function(a){a&&0!==z&&A(z-1),a||z===f.length-1||A(z+1)},O=function(a,b){var c=u(a),d=m?function(d){m(a,{e:d,index:b}),null===c||void 0===c?void 0:c(d)}:void 0;return{content:n(a),label:o(a),point:p(a),progress:q(a),status:"number"==typeof l&&l>=b?r(a)||"normal":"system",tooltipContent:s(a),size:j,position:getItemPosition(b,f.length),pointRef:M[b],direction:h,className:cnProgressStepBar("Item"),onClick:c||d,key:cnProgressStepBar({index:b}),tooltipZIndex:"number"==typeof(null===v||void 0===v?void 0:v.zIndex)?v.zIndex+1:void 0}},P=useOverflow({currentRef:F});return React.createElement("div",Object.assign({},w,{style:v,className:cnProgressStepBar({isOverflow:P},[k,cnMixScrollBar()]),ref:useForkRef([b,c])}),P&&"vertical"!==h&&React.createElement(Button,{iconLeft:function iconLeft(){return React.createElement(IconArrowLeft,{size:"xs"})},view:"clear",onlyIcon:!0,type:"button",size:"xs",className:cnProgressStepBar("Button",{side:"left"}),onClick:function onClick(){return N(!0)}}),React.createElement("div",{ref:F,className:cnProgressStepBar("List",{direction:h,overflow:P})},React.createElement(ProgressStepBarLine,{lines:D,size:j,direction:h,activeStepIndex:l}),f.map(function(a,b){return React.createElement(ProgressStepBarItem,Object.assign({ref:K[b]},O(a,b)))})),P&&"vertical"!==h&&React.createElement(Button,{iconLeft:function iconLeft(){return React.createElement(IconArrowRight,{size:"xs"})},view:"clear",onlyIcon:!0,size:"xs",type:"button",className:cnProgressStepBar("Button",{side:"right"}),onClick:function onClick(){return N(!1)}}))}export var ProgressStepBar=forwardRef(ProgressStepBarRender);
//# sourceMappingURL=ProgressStepBar.js.map