import _classCallCheck from"babel-runtime/helpers/classCallCheck";import _createClass from"babel-runtime/helpers/createClass";import _possibleConstructorReturn from"babel-runtime/helpers/possibleConstructorReturn";import _inherits from"babel-runtime/helpers/inherits";import _typeof from"babel-runtime/helpers/typeof";var __decorate=this&&this.__decorate||function(e,t,r,a){var s,i=arguments.length,o=i<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,r):a;if("object"===("undefined"==typeof Reflect?"undefined":_typeof(Reflect))&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,r,a);else for(var n=e.length-1;n>=0;n--)(s=e[n])&&(o=(i<3?s(o):i>3?s(t,r,o):s(t,r))||o);return i>3&&o&&Object.defineProperty(t,r,o),o};import*as React from"react";import{withContext}from"./sidebar-context";import classNames from"classnames";import{noop}from"./utils";if("undefined"!=typeof NodeList&&NodeList.prototype&&!NodeList.prototype.forEach){var forEach=Array.prototype.forEach;NodeList.prototype.forEach=forEach}var SubSidebar=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));r.onClickHandler=function(e){var t=r.state,a=t.isSubDrawer,s=t.subSidebarOpen,i=r.props,o=i.setParentState,n=i.subDrawerStore,d=i.itemKey,c=i.onSubSidebarOpenChange,l=i.onTitleClick,u=i.onSubSidebarClick;a&&d?(o&&o({isDrawerOpen:!0,drawerContent:n[d],selectedDrawer:d,selectedKey:n[d].inner.props.children[0].key}),setTimeout(function(){u&&u({selected:n[d].inner.props.children[0]})},0)):r.setState({subSidebarOpen:!s}),setTimeout(function(){var e=[];if("undefined"!=typeof document&&document.querySelector&&document.querySelectorAll&&(document.querySelectorAll(".dt-sidebar-subSidebar-open").forEach(function(t){e.push(t.dataset?t.dataset.key:t.getAttribute("data-key"))}),r.props.isDrawerOpen)){var t=document.querySelector(".dt-sidebar-drawer .dt-sidebar-subSidebar");e.push(t.dataset?t.dataset.key:t.getAttribute("data-key"))}o&&o({openKeys:e}),c&&c(e,r.props.selectedKey)},100),l&&l({key:d||"",domEvent:e})};var a=r.props,s=a.itemKey,i=a.openKeys,o=a.subDrawerStore,n=Object.keys(o);return r.state={subSidebarOpen:s&&i.indexOf(s)>-1||!1,isSubDrawer:s&&n.indexOf(s)>-1||!1},r}return _inherits(t,e),_createClass(t,[{key:"componentDidMount",value:function(){var e=this.props,t=e.itemKey,r=e.subSidebarStore;e.selectedDrawer;t&&(r[t]||(r[t]=[this]),r[t].push(this))}},{key:"render",value:function(){var e=this.state,t=e.subSidebarOpen,r=e.isSubDrawer,a=this.props,s=a.children,i=a.title,o=a.itemKey,n=a.selectedDrawer,d=(t||r)&&s?40*s.length:0;return React.createElement("div",{"data-key":o,className:classNames("dt-sidebar-subSidebar",{"dt-sidebar-subSidebar-open":!r&&t,"dt-is-sub-drawer":r})},React.createElement("div",{onClick:this.onClickHandler,className:classNames("dt-sidebar-subSidebar-title","dt-sidebar-item",{"dt-sidebar-item-selected":n==o})},this.props.title,React.createElement("i",{className:"dt-sidebar-subSidebar-arrow"})),React.createElement("ul",{className:classNames("dt-sidebar-sub"),style:{height:d}},s),!r&&React.createElement("div",{className:"dt-sidebar-sub-detail"},React.createElement("div",{className:"dt-sidebar-sub-detail-title"},i),s))}}]),t}(React.PureComponent);SubSidebar.defaultProps={onTitleClick:noop};export default SubSidebar=__decorate([withContext("SubSidebar")],SubSidebar);