import _defineProperty from"@babel/runtime/helpers/defineProperty";import _toConsumableArray from"@babel/runtime/helpers/toConsumableArray";import _slicedToArray from"@babel/runtime/helpers/slicedToArray";import _objectWithoutProperties from"@babel/runtime/helpers/objectWithoutProperties";var _excluded=["item","attributes","as"],_excluded2=["items","value","onCreate","getItemKey","getItemLabel","getItemLeftIcon","getItemRightIcon","getItemAs","getItemRef","getItemAttributes","getItemFixed","onChange","onRemove","renderItem","size","form","view","withNavigationButtons","onMouseLeave","className","id"];import"./BookmarkTabs.css";import{IconAdd}from"@consta/icons/IconAdd";import{IconArrowLeft}from"@consta/icons/IconArrowLeft";import{IconArrowRight}from"@consta/icons/IconArrowRight";import React,{forwardRef,useMemo,useState}from"react";import{useComponentSize}from"../../hooks/useComponentSize";import{useForkRef}from"../../hooks/useForkRef";import{cn}from"../../utils/bem";import{Button}from"../Button";import{BookmarkTabsTab}from"./BookmarkTabsTab";import{withDefaultGetters}from"./helper";import{bookmarkTabsPropFormDefault,bookmarkTabsPropSizeDefault,bookmarkTabsPropViewDefault}from"./types";import{useBookmarkTabs}from"./useBookmarkTabs";export var cnBookmarkTabs=cn("BookmarkTabs");var renderItemDefault=function(a){var b=a.item,c=a.attributes,d=void 0===c?{}:c,e=a.as,f=_objectWithoutProperties(a,_excluded);return React.createElement(BookmarkTabsTab,Object.assign({},d,f,{as:e}))},BookmarkTabsRender=function(a,b){var c=withDefaultGetters(a),d=c.items,e=void 0===d?[]:d,f=c.value,g=c.onCreate,h=c.getItemKey,i=c.getItemLabel,j=c.getItemLeftIcon,k=c.getItemRightIcon,l=c.getItemAs,m=c.getItemRef,n=c.getItemAttributes,o=c.getItemFixed,p=c.onChange,q=c.onRemove,r=c.renderItem,s=void 0===r?renderItemDefault:r,t=c.size,u=void 0===t?bookmarkTabsPropSizeDefault:t,v=c.form,w=void 0===v?bookmarkTabsPropFormDefault:v,x=c.view,y=void 0===x?bookmarkTabsPropViewDefault:x,z=c.withNavigationButtons,A=c.onMouseLeave,B=c.className,C=c.id,D=_objectWithoutProperties(c,_excluded2),E=useState(null),F=_slicedToArray(E,2),G=F[0],H=F[1],I=function(a){return!!f&&h(a)===h(f)},J=useBookmarkTabs({items:e,getItemFixed:o,size:u,withNavigationButtons:z,withAddButton:!!g}),K=J.refs,L=J.fixedTabs,M=J.fixedTabsRef,N=J.otherTabs,O=J.otherTabsRef,P=J.showControls,Q=J.wrapperRef,R=J.containerRef,S=J.controlsRef,T=J.addButtonRef,U=J.navigate,V=J.sizes,W=useComponentSize(M),X=W.width,Y=function(a,b,c,d,e,f){var g;return React.createElement("div",{className:cnBookmarkTabs("Tab"),onMouseEnter:function onMouseEnter(){return H(e)},onFocus:function onFocus(){return H(e)},ref:c},s({item:a,onClick:function onClick(b){return null===p||void 0===p?void 0:p(a,{e:b})},active:I(a),label:i(a),leftIcon:j(a),rightIcon:k(a),as:null!==(g=l(a))&&void 0!==g?g:"div",attributes:n(a),tabRef:m(a),fixed:b,bordered:d,onClose:q?function(b){return q(a,{e:b})}:void 0,size:u,view:y,hovered:G===e,form:w,tabWidth:f}))},Z=useMemo(function(){var a=[].concat(_toConsumableArray(L),_toConsumableArray(N)),b=f?a.indexOf(f):-1;return Array.from(Array(a.length-1).keys()).filter(function(a){return"round"!==w||a!==b&&a!==b-1})},[L,N,f,w]);return React.createElement("div",Object.assign({className:cnBookmarkTabs({size:u,view:y,form:w},[B]),ref:useForkRef([b,R]),id:C,onMouseLeave:function onMouseLeave(a){null===A||void 0===A?void 0:A(a),H(null)}},D),P&&React.createElement("div",{ref:S,className:cnBookmarkTabs("ScrollControls")},React.createElement("div",{className:cnBookmarkTabs("Button")},React.createElement(Button,{view:"clear",size:"xs",type:"button",onClick:function onClick(){return U("prev")},iconLeft:IconArrowLeft,onlyIcon:!0})),React.createElement("div",{className:cnBookmarkTabs("Button")},React.createElement(Button,{view:"clear",size:"xs",type:"button",onClick:function onClick(){return U("next")},iconLeft:IconArrowRight,onlyIcon:!0}))),React.createElement("div",{ref:Q,className:cnBookmarkTabs("Wrapper")},React.createElement("div",{style:_defineProperty({},"--bookmarks-list-width","max-content"),ref:M,className:cnBookmarkTabs("List")},L.map(function(a,b){return React.createElement(React.Fragment,{key:h(a)},Y(a,!0,K[b],Z.includes(b),b))})),React.createElement("div",{style:_defineProperty({},"--bookmarks-list-width","calc(100% - ".concat(X,"px)")),className:cnBookmarkTabs("List"),ref:O},N.map(function(a,b){var c=L.length;return React.createElement(React.Fragment,{key:h(a)},Y(a,!1,K[c+b],Z.includes(c+b),c+b,V[b]))}))),g&&React.createElement("div",{ref:T,className:cnBookmarkTabs("Button",{type:"add"})},React.createElement(Button,{view:"clear",size:"xs",type:"button",onClick:g,iconLeft:IconAdd,onlyIcon:!0})),React.createElement("div",{className:cnBookmarkTabs("Empty")}))};export var BookmarkTabs=forwardRef(BookmarkTabsRender);
//# sourceMappingURL=BookmarkTabs.js.map