"use strict";

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

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

var _tslib = require("tslib");

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

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

var _consoleComponents = require("@alicloud/console-components");

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

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }

var IotDialog =
/** @class */
function (_super) {
  (0, _tslib.__extends)(IotDialog, _super);

  function IotDialog(props) {
    var _this = _super.call(this, props) || this;

    _this.getContentAlign = function (key) {
      switch (key) {
        case 'left':
          return 'tl tl';

        case 'right':
          return 'tr tr';

        default:
          return _this.props.align;
      }
    };

    _this.handleOnClose = function (trigger, event) {
      if (_this.props.isQuick) {
        _this.setState({
          visible: false
        });

        _this.props.onClose && _this.props.onClose(trigger, event);
      } else {
        _this.props.onClose && _this.props.onClose(trigger, event);
      }
    };

    _this.handleOnOK = function (event) {
      if (_this.props.isQuick) {
        _this.setState({
          visible: false
        });

        _this.props.onOk && _this.props.onOk(event);
      } else {
        _this.props.onOk && _this.props.onOk(event);
      }
    };

    _this.handleOnCancel = function (event) {
      if (_this.props.isQuick) {
        _this.setState({
          visible: false
        });

        _this.props.onCancel && _this.props.onCancel(event);
      } else {
        _this.props.onCancel && _this.props.onCancel(event);
      }
    };

    _this.state = {
      visible: true
    };
    return _this;
  }

  IotDialog.prototype.render = function () {
    var _a = this.props,
        isQuick = _a.isQuick,
        onOk = _a.onOk,
        onCancel = _a.onCancel,
        onClose = _a.onClose,
        visible = _a.visible,
        content = _a.content,
        children = _a.children,
        className = _a.className,
        contentAlign = _a.contentAlign,
        isNest = _a.isNest,
        config = (0, _tslib.__rest)(_a, ["isQuick", "onOk", "onCancel", "onClose", "visible", "content", "children", "className", "contentAlign", "isNest"]);
    var alignClassname = contentAlign !== 'center' && 'lp-normal-dialog-full';
    var align_ = this.getContentAlign(contentAlign);
    var classname = (0, _classnames["default"])('lp-normal-dialog', alignClassname, {
      "lp-nest-dialog": isNest
    }, className);
    var resultContent = content || children;
    var resultVisible = isQuick ? this.state.visible : visible;
    return /*#__PURE__*/_react["default"].createElement(_consoleComponents.Dialog, (0, _tslib.__assign)({
      align: align_
    }, config, {
      visible: resultVisible,
      onClose: this.handleOnClose,
      onOk: this.handleOnOK,
      onCancel: this.handleOnCancel,
      className: classname
    }), resultContent);
  };

  return IotDialog;
}(_react.Component);

IotDialog.defaultProps = {
  visible: false,
  contentAlign: 'center',
  locale: {
    ok: '确定',
    cancel: '取消'
  }
};
var _default = IotDialog;
exports["default"] = _default;