"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

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

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

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

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

var _loading = _interopRequireDefault(require("./loading.png"));

var _getLocale = require("../../utils/getLocale");

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

require("./index.css");

var _excluded = ["onOk", "onCancel", "okText", "cancelText", "footer", "noFooter", "noHeadLine", "noCloseIcon", "noFooterLine", "visible", "extraClass", "extendFooterBtn", "disabled", "confirmLoading"];

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

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

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 _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

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; }

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; }

var preCls = "titaui-dialog";

function _default(props) {
  var _classNames2;

  var _props$onOk = props.onOk,
      onOk = _props$onOk === void 0 ? function () {
    return true;
  } : _props$onOk,
      _props$onCancel = props.onCancel,
      onCancel = _props$onCancel === void 0 ? function () {
    return true;
  } : _props$onCancel,
      _props$okText = props.okText,
      okText = _props$okText === void 0 ? (0, _getLocale.getLocale)("OKR_MyO_Butt_Determine") : _props$okText,
      _props$cancelText = props.cancelText,
      cancelText = _props$cancelText === void 0 ? (0, _getLocale.getLocale)("Mod_Cancel") : _props$cancelText,
      footer = props.footer,
      noFooter = props.noFooter,
      noHeadLine = props.noHeadLine,
      noCloseIcon = props.noCloseIcon,
      noFooterLine = props.noFooterLine,
      visible = props.visible,
      _props$extraClass = props.extraClass,
      extraClass = _props$extraClass === void 0 ? [] : _props$extraClass,
      extendFooterBtn = props.extendFooterBtn,
      _props$disabled = props.disabled,
      disabled = _props$disabled === void 0 ? false : _props$disabled,
      _props$confirmLoading = props.confirmLoading,
      confirmLoading = _props$confirmLoading === void 0 ? false : _props$confirmLoading,
      restProps = _objectWithoutProperties(props, _excluded);

  var handleOK = function handleOK() {
    if (disabled || confirmLoading) return;
    onOk && onOk();
  };

  var baseFooter = [extendFooterBtn, /*#__PURE__*/_react["default"].createElement("span", {
    key: "cancel",
    className: (0, _classnames["default"])("".concat(preCls, "__btn"), "".concat(preCls, "__btn-cancel")),
    onClick: onCancel
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("".concat(preCls, "__btn-cancel-text"))
  }, cancelText)), /*#__PURE__*/_react["default"].createElement("span", {
    key: "ok",
    className: (0, _classnames["default"])("".concat(preCls, "__btn"), "".concat(preCls, "__btn-ok"), _defineProperty({}, "".concat(preCls, "__btn-ok-not-allowed"), disabled || confirmLoading)),
    onClick: handleOK
  }, confirmLoading ? /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("".concat(preCls, "__btn-ok-loading"))
  }, /*#__PURE__*/_react["default"].createElement("img", {
    className: (0, _classnames["default"])("".concat(preCls, "__btn-ok-loading-icon")),
    src: _loading["default"]
  }), (0, _getLocale.getLocale)("Mod_loading")) : /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("".concat(preCls, "__btn-ok-text"))
  }, okText))];
  return /*#__PURE__*/_react["default"].createElement(_rcDialog["default"], _extends({
    visible: visible,
    className: (0, _classnames["default"])(preCls, _toConsumableArray(extraClass), (_classNames2 = {}, _defineProperty(_classNames2, "".concat(preCls, "-no-head-line"), noHeadLine), _defineProperty(_classNames2, "".concat(preCls, "-no-footer-line"), noFooterLine), _defineProperty(_classNames2, "".concat(preCls, "-no-close"), noCloseIcon), _defineProperty(_classNames2, "".concat(preCls, "-no-footer"), noFooter), _classNames2)),
    closeIcon: /*#__PURE__*/_react["default"].createElement("span", {
      className: "tu-icon-canceled"
    }),
    animation: "slide-fade",
    maskAnimation: "fade",
    maskClosable: false,
    footer: footer || baseFooter,
    zIndex: 1299
  }, restProps));
}