import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _extends from "@babel/runtime/helpers/extends";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _createSuper from "@babel/runtime/helpers/createSuper";
var _excluded = ["prefixCls", "className", "children"],
    _excluded2 = ["prefixCls", "className", "children", "hasSider"];
import React, { PureComponent } from 'react';
import classNames from 'classnames';
import ConfigContext from '../config-provider/ConfigContext';
import { LayoutContextProvider } from './LayoutContext';

function generator(_ref) {
  var displayName = _ref.displayName,
      suffixCls = _ref.suffixCls;
  return function (BasicComponent) {
    var _a;

    return _a = /*#__PURE__*/function (_PureComponent) {
      _inherits(Adapter, _PureComponent);

      var _super = _createSuper(Adapter);

      function Adapter() {
        _classCallCheck(this, Adapter);

        return _super.apply(this, arguments);
      }

      _createClass(Adapter, [{
        key: "render",
        value: function render() {
          var customizePrefixCls = this.props.prefixCls;
          var getPrefixCls = this.context.getPrefixCls;
          return /*#__PURE__*/React.createElement(BasicComponent, _extends({
            prefixCls: getPrefixCls(suffixCls, customizePrefixCls)
          }, this.props));
        }
      }], [{
        key: "contextType",
        get: function get() {
          return ConfigContext;
        }
      }]);

      return Adapter;
    }(PureComponent), _a.displayName = displayName, _a;
  };
}

function Basic(props) {
  var prefixCls = props.prefixCls,
      className = props.className,
      children = props.children,
      others = _objectWithoutProperties(props, _excluded);

  var divCls = classNames(className, prefixCls);
  return /*#__PURE__*/React.createElement("div", _extends({
    className: divCls
  }, others), children);
}

var BasicLayout = /*#__PURE__*/function (_PureComponent2) {
  _inherits(BasicLayout, _PureComponent2);

  var _super2 = _createSuper(BasicLayout);

  function BasicLayout() {
    var _this;

    _classCallCheck(this, BasicLayout);

    _this = _super2.apply(this, arguments);
    _this.state = {
      siders: []
    };
    return _this;
  }

  _createClass(BasicLayout, [{
    key: "getContextValue",
    value: function getContextValue() {
      var _this2 = this;

      var siders = this.state.siders;
      var getPrefixCls = this.context.getPrefixCls;
      return {
        siderHook: {
          addSider: function addSider(id) {
            _this2.setState({
              siders: [].concat(_toConsumableArray(siders), [id])
            });
          },
          removeSider: function removeSider(id) {
            _this2.setState({
              siders: siders.filter(function (currentId) {
                return currentId !== id;
              })
            });
          }
        },
        getPrefixCls: getPrefixCls
      };
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props = this.props,
          prefixCls = _this$props.prefixCls,
          className = _this$props.className,
          children = _this$props.children,
          hasSider = _this$props.hasSider,
          others = _objectWithoutProperties(_this$props, _excluded2);

      var siders = this.state.siders;
      var divCls = classNames(className, prefixCls, _defineProperty({}, "".concat(prefixCls, "-has-sider"), hasSider || siders.length > 0));
      return /*#__PURE__*/React.createElement(LayoutContextProvider, _extends({}, this.getContextValue()), /*#__PURE__*/React.createElement("div", _extends({
        className: divCls
      }, others), children));
    }
  }], [{
    key: "contextType",
    get: function get() {
      return ConfigContext;
    }
  }]);

  return BasicLayout;
}(PureComponent);

BasicLayout.displayName = 'BasicLayout';
var Layout = generator({
  suffixCls: 'layout',
  displayName: 'Layout'
})(BasicLayout);
var Header = generator({
  suffixCls: 'layout-header',
  displayName: 'Header'
})(Basic);
var Footer = generator({
  suffixCls: 'layout-footer',
  displayName: 'Footer'
})(Basic);
var Content = generator({
  suffixCls: 'layout-content',
  displayName: 'Content'
})(Basic);
Layout.Header = Header;
Layout.Footer = Footer;
Layout.Content = Content;
export default Layout;
//# sourceMappingURL=layout.js.map
