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,s){var i,a=arguments.length,o=a<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,r):s;if("object"===("undefined"==typeof Reflect?"undefined":_typeof(Reflect))&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,r,s);else for(var n=e.length-1;n>=0;n--)(i=e[n])&&(o=(a<3?i(o):a>3?i(t,r,o):i(t,r))||o);return a>3&&o&&Object.defineProperty(t,r,o),o};import*as React from"react";import classNames from"classnames";import{withContext}from"./sidebar-context";import*as ReactDOM from"react-dom";var Item=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return r.onClickHandler=function(e){var t=r.props,s=t.setParentState,i=t.onSidebarItemClick,a=t.subDrawerStore,o=t.openKeys;if(r.isSubDrawer){for(var n in a)if(a.hasOwnProperty(n))for(var c=0;c<a[n].inner.props.children.length;c++)a[n].inner.props.children[c].key==r.itemKey&&s&&s({selectedDrawer:n});s&&s({selectedKey:r.itemKey})}else{Object.keys(a).forEach(function(e){o.indexOf(e)>-1&&o.splice(o.indexOf(e),1)}),s&&s({selectedKey:r.itemKey,openKeys:o,isDrawerOpen:!1,drawerContent:null,selectedDrawer:""})}setTimeout(function(){i&&i({key:r.itemKey||"",keyPath:r.keyPath||[],openKeys:o||[],item:r,domEvent:e})},200)},r.setSelectedState=function(e){r.setState({selected:e})},r.state={selected:!1},r.itemKey=r.props.itemKey,r}return _inherits(t,e),_createClass(t,[{key:"componentWillReceiveProps",value:function(e){this.setState({selected:e.selectedKey===e.itemKey})}},{key:"componentDidMount",value:function(){var e=this.props,t=e.selectedKey,r=e.sidebarItemStore,s=t===this.itemKey;this.setSelectedState(s);try{if(ReactDOM&&ReactDOM.findDOMNode&&ReactDOM.findDOMNode(this)){var i=ReactDOM.findDOMNode(this);this.isSubDrawer=i.parentNode.parentNode.className.indexOf("dt-is-sub-drawer")>-1}}catch(e){}var a=[];!function e(t){var r=t.dataset?t.dataset.key:t.getAttribute("data-key");r&&"root"!==r&&(a.unshift(r),e(t.parentNode.parentNode))}(ReactDOM.findDOMNode(this)),this.keyPath=a,this.itemKey&&(r[this.itemKey]?r[this.itemKey].push(this):r[this.itemKey]=[this])}},{key:"render",value:function(){var e=this.state.selected,t=this.props,r=t.children,s=t.itemKey,i=t.style,a=t.className;return React.createElement("li",{"data-key":s,style:i,onClick:this.onClickHandler,className:classNames(a,"dt-sidebar-item",{"dt-sidebar-item-selected":e})},r,React.createElement("div",{className:"dt-sidebar-item-detail"},r))}}]),t}(React.PureComponent);export default Item=__decorate([withContext("Item")],Item);