"use strict";

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

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

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

var _rcDialog = _interopRequireDefault(require("rc-dialog"));

require("rc-dialog/assets/index.css");

require("./index.css");

var _excluded = ["children", "visible", "type", "className"];

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var preCls = 'titaui-dialog-confirm';

function CancelButton(props) {
  var onClick = props.onClick,
      children = props.children;
  return /*#__PURE__*/_react["default"].createElement("span", {
    key: "cancel",
    className: (0, _classnames["default"])("".concat(preCls, "__btn-cancel"), "".concat(preCls, "__btn")),
    onClick: onClick
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("".concat(preCls, "__btn-cancel-text"))
  }, children));
}

function SureButton(props) {
  var onClick = props.onClick,
      children = props.children;
  return /*#__PURE__*/_react["default"].createElement("span", {
    key: "sure",
    className: (0, _classnames["default"])("".concat(preCls, "__btn-sure"), "".concat(preCls, "__btn")),
    onClick: onClick
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("".concat(preCls, "__btn-sure-text"))
  }, children));
}

function WarningButton(props) {
  var onClick = props.onClick,
      children = props.children,
      disabled = props.disabled;

  var onClickHandler = function onClickHandler(e) {
    e.stopPropagation();

    if (!disabled) {
      onClick();
    }
  };

  return /*#__PURE__*/_react["default"].createElement("span", {
    key: "warning",
    className: (0, _classnames["default"])("".concat(preCls, "__btn-warning"), "".concat(preCls, "__btn"), _defineProperty({}, "".concat(preCls, "__btn-warning--disabled"), disabled)),
    onClick: onClickHandler
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("".concat(preCls, "__btn-warning-text"))
  }, children));
}

function DialogConfirm(props) {
  var children = props.children,
      visible = props.visible,
      type = props.type,
      _props$className = props.className,
      className = _props$className === void 0 ? '' : _props$className,
      restProps = _objectWithoutProperties(props, _excluded);

  var footer = [];
  var titleInstance;
  var contentInstance;

  _react["default"].Children.forEach(children, function (child) {
    if (child) {
      if (child.props.type == 'button') footer.push(child);
      if (child.props.type == 'title') titleInstance = child;
      if (child.props.type == 'content') contentInstance = child;
    }
  });

  var getConfirmIcon = function getConfirmIcon(type) {
    switch (type) {
      case 'warning':
        return /*#__PURE__*/_react["default"].createElement("span", {
          className: "tu-icon-tishi",
          style: {
            color: '#FFBC00',
            fontSize: '18px',
            verticalAlign: '-2px'
          }
        });

      case 'success':
        return /*#__PURE__*/_react["default"].createElement("span", {
          className: "tu-icon-check",
          style: {
            color: '#5AD8A6'
          }
        });

      case 'error':
        return /*#__PURE__*/_react["default"].createElement("span", {
          className: "tu-icon-cross",
          style: {
            color: '#F05E5E'
          }
        });

      case 'confirm':
        return /*#__PURE__*/_react["default"].createElement("span", {
          className: "tu-icon-tishi"
        });

      case 'info':
        return /*#__PURE__*/_react["default"].createElement("span", {
          className: "tu-icon-warning"
        });

      default:
    }
  };

  return /*#__PURE__*/_react["default"].createElement(_rcDialog["default"], _extends({
    className: (0, _classnames["default"])(preCls, "".concat(preCls, "--no-bottom-line"), className),
    visible: visible,
    width: 360,
    closeIcon: /*#__PURE__*/_react["default"].createElement("span", null),
    animation: "slide-fade",
    maskAnimation: "fade",
    footer: footer,
    zIndex: 1299,
    maskClosable: false
  }, restProps), /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("".concat(preCls, "__body"))
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("".concat(preCls, "__body-title"))
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("".concat(preCls, "__body-title-icon"))
  }, getConfirmIcon(type)), /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("".concat(preCls, "__body-title-text"))
  }, titleInstance)), /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("".concat(preCls, "__body-content"))
  }, contentInstance)));
}

DialogConfirm.Confirm = DialogConfirm;
DialogConfirm.CancelButton = CancelButton;
DialogConfirm.SureButton = SureButton;
DialogConfirm.WarningButton = WarningButton;
var _default = DialogConfirm;
exports["default"] = _default;