"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),_classnames=require("classnames"),_classnames2=_interopRequireDefault(_classnames),_sidebarContext=require("./sidebar-context"),_reactDom=require("react-dom"),ReactDOM=_interopRequireWildcard(_reactDom);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,i){var s,a=arguments.length,n=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"===("undefined"==typeof Reflect?"undefined":(0,_typeof3.default)(Reflect))&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,r,i);else for(var l=e.length-1;0<=l;l--)(s=e[l])&&(n=(a<3?s(n):3<a?s(t,r,n):s(t,r))||n);return 3<a&&n&&Object.defineProperty(t,r,n),n},Item=function(e){function t(e){(0,_classCallCheck3.default)(this,t);var o=(0,_possibleConstructorReturn3.default)(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return o.onClickHandler=function(e){var t=o.props,r=t.setParentState,i=t.onSidebarItemClick,s=t.subDrawerStore,a=t.openKeys;if(o.isSubDrawer){for(var n in s)if(s.hasOwnProperty(n))for(var l=0;l<s[n].inner.props.children.length;l++)s[n].inner.props.children[l].key==o.itemKey&&r&&r({selectedDrawer:n});r&&r({selectedKey:o.itemKey})}else{Object.keys(s).forEach(function(e){-1<a.indexOf(e)&&a.splice(a.indexOf(e),1)}),r&&r({selectedKey:o.itemKey,openKeys:a,isDrawerOpen:!1,drawerContent:null,selectedDrawer:""})}setTimeout(function(){i&&i({key:o.itemKey||"",keyPath:o.keyPath||[],openKeys:a||[],item:o,domEvent:e})},200)},o.setSelectedState=function(e){o.setState({selected:e})},o.state={selected:!1},o.itemKey=o.props.itemKey,o}return(0,_inherits3.default)(t,e),(0,_createClass3.default)(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,i=t===this.itemKey;this.setSelectedState(i);try{if(ReactDOM&&ReactDOM.findDOMNode&&ReactDOM.findDOMNode(this)){var s=ReactDOM.findDOMNode(this);this.isSubDrawer=-1<s.parentNode.parentNode.className.indexOf("dt-is-sub-drawer")}}catch(e){}var a=ReactDOM.findDOMNode(this),n=[];!function e(t){var r=t.dataset?t.dataset.key:t.getAttribute("data-key");r&&"root"!==r&&(n.unshift(r),e(t.parentNode.parentNode))}(a),this.keyPath=n,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,i=t.itemKey,s=t.style,a=t.className;return React.createElement("li",{"data-key":i,style:s,onClick:this.onClickHandler,className:(0,_classnames2.default)(a,"dt-sidebar-item",{"dt-sidebar-item-selected":e})},r,React.createElement("div",{className:"dt-sidebar-item-detail"},r))}}]),t}(React.PureComponent);Item=__decorate([(0,_sidebarContext.withContext)("Item")],Item),exports.default=Item,module.exports=exports.default;