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=["items","anchorRef","position","direction","possibleDirections","offset","onClickOutside","getItemKey","getItemLabel","getItemSubMenu","style","spareDirection","subMenuDirection","isMobile","isOpen","setComponentSize","enableAnimationBack","disableAnimationBack"];function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}import React,{Fragment,useEffect,useState}from"react";import{Transition,TransitionGroup}from"react-transition-group";import{useClickOutside}from"../../../hooks/useClickOutside";import{useMutableRef}from"../../../hooks/useMutableRef";import{useRefs}from"../../../hooks/useRefs";import{animateTimeout}from"../../../mixs/MixPopoverAnimate";import{setRef}from"../../../utils/setRef";import{clearTimers,ContextMenuLevel}from"../ContextMenuLevel";import{getLevels,withDefaultGetters}from"../helpers";import{contextMenuPropDefaultSubMenuDirection,contextMenuPropSubMenuDirections}from"../types";import{useSize}from"./useSize";var ContextMenuLevelsRender=function(a){var b=withDefaultGetters(a),c=b.items,d=b.anchorRef,e=b.position,f=b.direction,g=b.possibleDirections,h=b.offset,i=b.onClickOutside,j=b.getItemKey,k=b.getItemLabel,l=b.getItemSubMenu,m=b.style,n=b.spareDirection,o=b.subMenuDirection,p=void 0===o?contextMenuPropDefaultSubMenuDirection:o,q=b.isMobile,r=b.isOpen,s=b.setComponentSize,t=b.enableAnimationBack,u=b.disableAnimationBack,v=_objectWithoutProperties(b,_excluded),w=useMutableRef(r),x=[{items:c,anchorRef:d,position:e,direction:f,possibleDirections:g,offset:h}],y=useState(q?x:[]),z=_slicedToArray(y,2),A=z[0],B=z[1],C=useState(p),D=_slicedToArray(C,2),E=D[0],F=D[1],G=useState(-1),H=_slicedToArray(G,2),I=H[0],J=H[1],K=useRefs(A.length),L=function(a){var c=a.level,d=a.items,e=a.anchorRef,f=a.activeItem,g=a.parent,h=_toConsumableArray(A),i=h[c]&&1<h.length-c?h[c].direction:void 0;h[c]&&1<h.length-c&&i&&F(i),h[c-1].activeItem=f,h.splice(c),h.push({items:d,anchorRef:q?b.anchorRef:e,direction:q?b.direction:i||E,possibleDirections:q?b.possibleDirections:contextMenuPropSubMenuDirections,position:q?b.position:void 0,offset:q?b.offset:void 0,parent:g}),w.current?B(h):B([])},M=function(a){if(0<a){t();var b=_toConsumableArray(A);b.splice(a),b[a-1]=_objectSpread(_objectSpread({},b[a-1]),{},{activeItem:void 0}),B(b),u()}};return useClickOutside({isActive:i&&r,ignoreClicksInsideRefs:[].concat(_toConsumableArray(K),[d||{current:null}]),handler:i}),useEffect(function(){return clearTimers(),B(getLevels({levels:A,items:c,getItemKey:j,getItemSubMenu:l})),function(){return clearTimers()}},[c]),useEffect(function(){B(x)},[e]),useEffect(function(){B(r?x:[])},[r]),useSize(K,s,q),React.createElement(TransitionGroup,{component:Fragment},A.map(function(a,c){var d="".concat(c,"-").concat(a.parent?j(a.parent):""),e=c!==A.length-1;return q&&e?React.createElement(Fragment,{key:c}):React.createElement(Transition,{key:d,timeout:animateTimeout,nodeRef:K[c]},function(d){return React.createElement(ContextMenuLevel,Object.assign({},v,a,{key:"".concat(c,"-").concat(a.parent?j(a.parent):""),isMobile:q,isOpen:r,style:_objectSpread(_objectSpread({},m),{zIndex:"number"==typeof(null===m||void 0===m?void 0:m.zIndex)?m.zIndex+1:void 0}),activeLevelDepth:A.length-1,levelDepth:c,getItemLabel:k,addLevel:L,deleteLevel:M,onSetDirection:0<c?F:b.onSetDirection,hoveredParenLevel:I,setHoveredParenLevel:J,getItemSubMenu:l,getItemKey:j,ref:function ref(a){return setRef(K[c],a)},spareDirection:0===c?n:"rightStartUp",parent:q?a.parent:void 0,animate:d}))})}))};export var ContextMenuLevels=React.forwardRef(ContextMenuLevelsRender);
//# sourceMappingURL=ContextMenuLevels.js.map