import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
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";
import _typeof from "@babel/runtime/helpers/typeof";
import React, { Component } from 'react';
import classNames from 'classnames';
import Dialog from './Modal';
import Button from '../button';
import { getConfirmLocale } from './locale';
import ConfigContext from '../config-provider/ConfigContext';

function isFixedWidth(width) {
  switch (_typeof(width)) {
    case 'undefined':
      return false;

    case 'number':
      return true;

    case 'string':
      // width: 100%不是固定宽度
      return width.indexOf('%') === -1;

    default:
      return false;
  }
}

var Sidebar = /*#__PURE__*/function (_Component) {
  _inherits(Sidebar, _Component);

  var _super = _createSuper(Sidebar);

  function Sidebar(props, context) {
    var _this;

    _classCallCheck(this, Sidebar);

    _this = _super.call(this, props, context);

    _this.handleCancel = function (e) {
      var onCancel = _this.props.onCancel;

      if (onCancel) {
        onCancel(e);
      }
    };

    _this.handleOk = function (e) {
      var onOk = _this.props.onOk;

      if (onOk) {
        onOk(e);
      }
    };

    _this.renderFooter = function () {
      var props = _this.props;
      var onCancel = props.onCancel,
          onOk = props.onOk,
          okType = props.okType,
          funcType = props.funcType,
          confirmLoading = props.confirmLoading,
          alwaysCanCancel = props.alwaysCanCancel;

      var prefixCls = _this.getPrefixCls();

      var okCancel = 'okCancel' in props ? props.okCancel : true;
      var runtimeLocale = getConfirmLocale();
      var okText = props.okText || (okCancel ? runtimeLocale.okText : runtimeLocale.justOkText);
      var cancelText = props.cancelText || runtimeLocale.cancelText;
      var cancalBtn = okCancel ? /*#__PURE__*/React.createElement(Button, {
        className: "".concat(prefixCls, "-btn-cancel"),
        disabled: !alwaysCanCancel && confirmLoading,
        funcType: funcType,
        onClick: onCancel
      }, cancelText) : null;
      return /*#__PURE__*/React.createElement("div", {
        className: "".concat(prefixCls, "-btns")
      }, /*#__PURE__*/React.createElement(Button, {
        className: "".concat(prefixCls, "-btn-ok"),
        loading: confirmLoading,
        funcType: funcType,
        type: okType,
        onClick: onOk
      }, okText), cancalBtn);
    };

    _this.handleStatus = function () {
      var open = _this.state.open;

      _this.setState({
        open: !open
      });
    };

    _this.state = {
      open: false
    };
    return _this;
  }

  _createClass(Sidebar, [{
    key: "getPrefixCls",
    value: function getPrefixCls() {
      var prefixCls = this.props.prefixCls;
      var getPrefixCls = this.context.getPrefixCls;
      return getPrefixCls('modal', prefixCls);
    }
  }, {
    key: "render",
    value: function render() {
      var _classNames;

      var props = this.props;
      var _props$footer = props.footer,
          footer = _props$footer === void 0 ? this.renderFooter() : _props$footer,
          width = props.width,
          className = props.className;
      var prefixCls = this.getPrefixCls();
      var open = this.state.open;
      var fixedWidth = isFixedWidth(width);
      var classString = classNames(prefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-sidebar"), true), _defineProperty(_classNames, "".concat(prefixCls, "-sidebar-open"), open), _defineProperty(_classNames, "".concat(prefixCls, "-sidebar-fixed-width"), fixedWidth), _classNames), className);
      return /*#__PURE__*/React.createElement(Dialog, _extends({}, props, {
        prefixCls: prefixCls,
        animationEnd: this.handleStatus,
        className: classString,
        footer: footer,
        closable: 'closable' in props ? props.closable : false
      }));
    }
  }], [{
    key: "contextType",
    get: function get() {
      return ConfigContext;
    }
  }]);

  return Sidebar;
}(Component);

export { Sidebar as default };
Sidebar.displayName = 'Sidebar';
Sidebar.defaultProps = {
  width: '100%',
  transitionName: 'slide-right',
  maskTransitionName: 'fade',
  confirmLoading: false,
  alwaysCanCancel: false,
  visible: false,
  okType: 'primary',
  funcType: 'raised'
};
//# sourceMappingURL=Sidebar.js.map
