import _defineProperty from"babel-runtime/helpers/defineProperty";import _extends from"babel-runtime/helpers/extends";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*as React from"react";import{findDOMNode}from"react-dom";import RcMenu,{Divider,ItemGroup}from"rc-menu";import*as PropTypes from"prop-types";import classNames from"classnames";import animation from"../_util/openAnimation";import warning from"../_util/warning";import SubMenu from"./SubMenu";import Item from"./MenuItem";var Menu=function(e){function n(e){_classCallCheck(this,n);var i=_possibleConstructorReturn(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e));i.inlineOpenKeys=[],i.handleClick=function(e){i.handleOpenChange([]);var n=i.props.onClick;n&&n(e)},i.handleOpenChange=function(e){i.setOpenKeys(e);var n=i.props.onOpenChange;n&&n(e)},warning(!("onOpen"in e||"onClose"in e),"`onOpen` and `onClose` are removed, please use `onOpenChange` instead, see: #"),warning(!("inlineCollapsed"in e&&"inline"!==e.mode),"`inlineCollapsed` should only be used when Menu's `mode` is inline.");var t=void 0;return"defaultOpenKeys"in e?t=e.defaultOpenKeys:"openKeys"in e&&(t=e.openKeys),i.state={openKeys:t||[]},i}return _inherits(n,e),_createClass(n,[{key:"getChildContext",value:function(){return{inlineCollapsed:this.getInlineCollapsed(),dtdMenuTheme:this.props.theme}}},{key:"componentWillReceiveProps",value:function(e,n){var i=this.props.prefixCls;if("inline"===this.props.mode&&"inline"!==e.mode&&(this.switchModeFromInline=!0),"openKeys"in e)this.setState({openKeys:e.openKeys});else{if(e.inlineCollapsed&&!this.props.inlineCollapsed||n.siderCollapsed&&!this.context.siderCollapsed){var t=findDOMNode(this);this.switchModeFromInline=!!this.state.openKeys.length&&!!t.querySelectorAll("."+i+"-submenu-open").length,this.inlineOpenKeys=this.state.openKeys,this.setState({openKeys:[]})}(!e.inlineCollapsed&&this.props.inlineCollapsed||!n.siderCollapsed&&this.context.siderCollapsed)&&(this.setState({openKeys:this.inlineOpenKeys}),this.inlineOpenKeys=[])}}},{key:"setOpenKeys",value:function(e){"openKeys"in this.props||this.setState({openKeys:e})}},{key:"getRealMenuMode",value:function(){var e=this.getInlineCollapsed();if(this.switchModeFromInline&&e)return"inline";var n=this.props.mode;return e?"vertical":n}},{key:"getInlineCollapsed",value:function(){var e=this.props.inlineCollapsed;return void 0!==this.context.siderCollapsed?this.context.siderCollapsed:e}},{key:"getMenuOpenAnimation",value:function(e){var n=this,i=this.props,t=i.openAnimation,s=i.openTransitionName,o=t||s;if(void 0===t&&void 0===s)switch(e){case"horizontal":o="slide-up";break;case"vertical":case"vertical-left":case"vertical-right":this.switchModeFromInline?(o="",this.switchModeFromInline=!1):o="zoom-big";break;case"inline":o=_extends({},animation,{leave:function(e,i){return animation.leave(e,function(){n.switchModeFromInline=!1,n.setState({}),"vertical"!==n.getRealMenuMode()&&i()})}})}return o}},{key:"render",value:function(){var e=this.props,n=e.prefixCls,i=e.className,t=e.theme,s=this.getRealMenuMode(),o=this.getMenuOpenAnimation(s),l=classNames(i,n+"-"+t,_defineProperty({},n+"-inline-collapsed",this.getInlineCollapsed())),r={openKeys:this.state.openKeys,onOpenChange:this.handleOpenChange,className:l,mode:s};"inline"!==s?(r.onClick=this.handleClick,r.openTransitionName=o):r.openAnimation=o;var p=this.context.collapsedWidth;return!this.getInlineCollapsed()||0!==p&&"0"!==p&&"0px"!==p?React.createElement(RcMenu,_extends({},this.props,r)):null}}]),n}(React.Component);export default Menu;Menu.Divider=Divider,Menu.Item=Item,Menu.SubMenu=SubMenu,Menu.ItemGroup=ItemGroup,Menu.defaultProps={prefixCls:"dt-menu",className:"",theme:"light"},Menu.childContextTypes={inlineCollapsed:PropTypes.bool,dtdMenuTheme:PropTypes.string},Menu.contextTypes={siderCollapsed:PropTypes.bool,collapsedWidth:PropTypes.oneOfType([PropTypes.number,PropTypes.string])};