"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _classCallCheck2=require("babel-runtime/helpers/classCallCheck"),_classCallCheck3=_interopRequireDefault(_classCallCheck2),_createClass2=require("babel-runtime/helpers/createClass"),_createClass3=_interopRequireDefault(_createClass2),_possibleConstructorReturn2=require("babel-runtime/helpers/possibleConstructorReturn"),_possibleConstructorReturn3=_interopRequireDefault(_possibleConstructorReturn2),_inherits2=require("babel-runtime/helpers/inherits"),_inherits3=_interopRequireDefault(_inherits2),_typeof2=require("babel-runtime/helpers/typeof"),_typeof3=_interopRequireDefault(_typeof2),_react=require("react"),React=_interopRequireWildcard(_react),_sidebarContext=require("./sidebar-context"),_classnames=require("classnames"),_classnames2=_interopRequireDefault(_classnames),_utils=require("./utils");function _interopRequireWildcard(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}var __decorate=function(e,t,r,a){var s,i=arguments.length,n=i<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,r):a;if("object"===("undefined"==typeof Reflect?"undefined":(0,_typeof3.default)(Reflect))&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,r,a);else for(var l=e.length-1;0<=l;l--)(s=e[l])&&(n=(i<3?s(n):3<i?s(t,r,n):s(t,r))||n);return 3<i&&n&&Object.defineProperty(t,r,n),n};if("undefined"!=typeof NodeList&&NodeList.prototype&&!NodeList.prototype.forEach){var forEach=Array.prototype.forEach;NodeList.prototype.forEach=forEach}var SubSidebar=function(e){function n(e){(0,_classCallCheck3.default)(this,n);var c=(0,_possibleConstructorReturn3.default)(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e));c.onClickHandler=function(e){var t=c.state,r=t.isSubDrawer,a=t.subSidebarOpen,s=c.props,i=s.setParentState,n=s.subDrawerStore,l=s.itemKey,o=s.onSubSidebarOpenChange,u=s.onTitleClick,d=s.onSubSidebarClick;r&&l?(i&&i({isDrawerOpen:!0,drawerContent:n[l],selectedDrawer:l,selectedKey:n[l].inner.props.children[0].key}),setTimeout(function(){d&&d({selected:n[l].inner.props.children[0]})},0)):c.setState({subSidebarOpen:!a}),setTimeout(function(){var t=[];if("undefined"!=typeof document&&document.querySelector&&document.querySelectorAll&&(document.querySelectorAll(".dt-sidebar-subSidebar-open").forEach(function(e){t.push(e.dataset?e.dataset.key:e.getAttribute("data-key"))}),c.props.isDrawerOpen)){var e=document.querySelector(".dt-sidebar-drawer .dt-sidebar-subSidebar");t.push(e.dataset?e.dataset.key:e.getAttribute("data-key"))}i&&i({openKeys:t}),o&&o(t,c.props.selectedKey)},100),u&&u({key:l||"",domEvent:e})};var t=c.props,r=t.itemKey,a=t.openKeys,s=t.subDrawerStore,i=Object.keys(s);return c.state={subSidebarOpen:r&&-1<a.indexOf(r)||!1,isSubDrawer:r&&-1<i.indexOf(r)||!1},c}return(0,_inherits3.default)(n,e),(0,_createClass3.default)(n,[{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,n=a.itemKey,l=a.selectedDrawer,o=(t||r)&&s?40*s.length:0;return React.createElement("div",{"data-key":n,className:(0,_classnames2.default)("dt-sidebar-subSidebar",{"dt-sidebar-subSidebar-open":!r&&t,"dt-is-sub-drawer":r})},React.createElement("div",{onClick:this.onClickHandler,className:(0,_classnames2.default)("dt-sidebar-subSidebar-title","dt-sidebar-item",{"dt-sidebar-item-selected":l==n})},this.props.title,React.createElement("i",{className:"dt-sidebar-subSidebar-arrow"})),React.createElement("ul",{className:(0,_classnames2.default)("dt-sidebar-sub"),style:{height:o}},s),!r&&React.createElement("div",{className:"dt-sidebar-sub-detail"},React.createElement("div",{className:"dt-sidebar-sub-detail-title"},i),s))}}]),n}(React.PureComponent);SubSidebar.defaultProps={onTitleClick:_utils.noop},SubSidebar=__decorate([(0,_sidebarContext.withContext)("SubSidebar")],SubSidebar),exports.default=SubSidebar,module.exports=exports.default;