"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));

var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));

var _react = _interopRequireWildcard(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _Modal = _interopRequireDefault(require("./Modal"));

var _button = _interopRequireDefault(require("../button"));

var _locale = require("./locale");

var _ConfigContext = _interopRequireDefault(require("../config-provider/ConfigContext"));

function isFixedWidth(width) {
  switch ((0, _typeof2["default"])(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) {
  (0, _inherits2["default"])(Sidebar, _Component);

  var _super = (0, _createSuper2["default"])(Sidebar);

  function Sidebar(props, context) {
    var _this;

    (0, _classCallCheck2["default"])(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 = (0, _locale.getConfirmLocale)();
      var okText = props.okText || (okCancel ? runtimeLocale.okText : runtimeLocale.justOkText);
      var cancelText = props.cancelText || runtimeLocale.cancelText;
      var cancalBtn = okCancel ? /*#__PURE__*/_react["default"].createElement(_button["default"], {
        className: "".concat(prefixCls, "-btn-cancel"),
        disabled: !alwaysCanCancel && confirmLoading,
        funcType: funcType,
        onClick: onCancel
      }, cancelText) : null;
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(prefixCls, "-btns")
      }, /*#__PURE__*/_react["default"].createElement(_button["default"], {
        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;
  }

  (0, _createClass2["default"])(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 = (0, _classnames["default"])(prefixCls, (_classNames = {}, (0, _defineProperty2["default"])(_classNames, "".concat(prefixCls, "-sidebar"), true), (0, _defineProperty2["default"])(_classNames, "".concat(prefixCls, "-sidebar-open"), open), (0, _defineProperty2["default"])(_classNames, "".concat(prefixCls, "-sidebar-fixed-width"), fixedWidth), _classNames), className);
      return /*#__PURE__*/_react["default"].createElement(_Modal["default"], (0, _extends2["default"])({}, props, {
        prefixCls: prefixCls,
        animationEnd: this.handleStatus,
        className: classString,
        footer: footer,
        closable: 'closable' in props ? props.closable : false
      }));
    }
  }], [{
    key: "contextType",
    get: function get() {
      return _ConfigContext["default"];
    }
  }]);
  return Sidebar;
}(_react.Component);

exports["default"] = Sidebar;
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
