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";var __rest=this&&this.__rest||function(e,t){var o={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(o[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var l=0;for(s=Object.getOwnPropertySymbols(e);l<s.length;l++)t.indexOf(s[l])<0&&(o[s[l]]=e[s[l]])}return o};if("undefined"!=typeof window){var matchMediaPolyfill=function(e){return{media:e,matches:!1,addListener:function(){},removeListener:function(){}}};window.matchMedia=window.matchMedia||matchMediaPolyfill}import*as React from"react";import classNames from"classnames";import omit from"omit.js";import*as PropTypes from"prop-types";import Icon from"../icon";var dimensionMap={xs:"480px",sm:"576px",md:"768px",lg:"992px",xl:"1200px",xxl:"1600px"},generateId=function(){var e=0;return function(){return""+(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")+(e+=1)}}(),Sider=function(e){function t(e){_classCallCheck(this,t);var o=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));o.responsiveHandler=function(e){o.setState({below:e.matches}),o.state.collapsed!==e.matches&&o.setCollapsed(e.matches,"responsive")},o.setCollapsed=function(e,t){"collapsed"in o.props||o.setState({collapsed:e});var s=o.props.onCollapse;s&&s(e,t)},o.toggle=function(){var e=!o.state.collapsed;o.setCollapsed(e,"clickTrigger")},o.belowShowChange=function(){o.setState({belowShow:!o.state.belowShow})},o.uniqueId=generateId("dt-sider-");var s=void 0;"undefined"!=typeof window&&(s=window.matchMedia),s&&e.breakpoint&&e.breakpoint in dimensionMap&&(o.mql=s("(max-width: "+dimensionMap[e.breakpoint]+")"));var l=void 0;return l="collapsed"in e?e.collapsed:e.defaultCollapsed,o.state={collapsed:l,below:!1},o}return _inherits(t,e),_createClass(t,[{key:"getChildContext",value:function(){return{siderCollapsed:this.state.collapsed,collapsedWidth:this.props.collapsedWidth}}},{key:"componentWillReceiveProps",value:function(e){"collapsed"in e&&this.setState({collapsed:e.collapsed})}},{key:"componentDidMount",value:function(){this.mql&&(this.mql.addListener(this.responsiveHandler),this.responsiveHandler(this.mql)),this.context.siderHook&&this.context.siderHook.addSider(this.uniqueId)}},{key:"componentWillUnmount",value:function(){this.mql&&this.mql.removeListener(this.responsiveHandler),this.context.siderHook&&this.context.siderHook.removeSider(this.uniqueId)}},{key:"render",value:function(){var e,t=this.props,o=t.prefixCls,s=t.className,l=t.collapsible,r=t.reverseArrow,i=t.trigger,a=t.style,n=t.width,p=t.collapsedWidth,d=__rest(t,["prefixCls","className","collapsible","reverseArrow","trigger","style","width","collapsedWidth"]),c=omit(d,["collapsed","defaultCollapsed","onCollapse","breakpoint"]),m=this.state.collapsed?p:n,h=0===p||"0"===p||"0px"===p?React.createElement("span",{onClick:this.toggle,className:o+"-zero-width-trigger"},React.createElement(Icon,{type:"bars"})):null,u={expanded:r?React.createElement(Icon,{type:"right"}):React.createElement(Icon,{type:"left"}),collapsed:r?React.createElement(Icon,{type:"left"}):React.createElement(Icon,{type:"right"})}[this.state.collapsed?"collapsed":"expanded"],f=null!==i?h||React.createElement("div",{className:o+"-trigger",onClick:this.toggle,style:{width:m}},i||u):null,y=_extends({},a,{flex:"0 0 "+m+"px",maxWidth:m+"px",minWidth:m+"px",width:m+"px"}),b=classNames(s,o,(_defineProperty(e={},o+"-collapsed",!!this.state.collapsed),_defineProperty(e,o+"-has-trigger",l&&null!==i&&!h),_defineProperty(e,o+"-below",!!this.state.below),_defineProperty(e,o+"-zero-width",0===m||"0"===m||"0px"===m),e));return React.createElement("div",_extends({className:b},c,{style:y}),React.createElement("div",{className:o+"-children"},this.props.children),l||this.state.below&&h?f:null)}}]),t}(React.Component);export default Sider;Sider.__ANT_LAYOUT_SIDER=!0,Sider.defaultProps={prefixCls:"dt-layout-sider",collapsible:!1,defaultCollapsed:!1,reverseArrow:!1,width:200,collapsedWidth:60,style:{}},Sider.childContextTypes={siderCollapsed:PropTypes.bool,collapsedWidth:PropTypes.oneOfType([PropTypes.number,PropTypes.string])},Sider.contextTypes={siderHook:PropTypes.object};