"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 _react = _interopRequireDefault(require("react"));

var _reactDom = _interopRequireDefault(require("react-dom"));

var _tabs = _interopRequireDefault(require("./tabs"));

var _result = _interopRequireDefault(require("./result"));

var _mkuiFd = require("mkui-fd");

require("./style");

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

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

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 Search = _mkuiFd.Input.Search;

var SelectModalLayout = /*#__PURE__*/function (_React$Component) {
  _inherits(SelectModalLayout, _React$Component);

  var _super = _createSuper(SelectModalLayout);

  function SelectModalLayout(props) {
    var _this;

    _classCallCheck(this, SelectModalLayout);

    _this = _super.call(this, props);
    _this.state = {};
    _this.modalElement = null;
    _this.modalElementRef = /*#__PURE__*/_react["default"].createRef();
    return _this;
  }

  _createClass(SelectModalLayout, [{
    key: "componentDidMount",
    value: function componentDidMount() {}
  }, {
    key: "onSearch",
    value: function onSearch(value) {
      var onSearch = this.props.onSearch;
      onSearch(value);
    }
  }, {
    key: "open",
    value: function open() {
      this.openModal();
    }
  }, {
    key: "openModal",
    value: function openModal() {
      var _this2 = this;

      var _this$props = this.props,
          root = _this$props.root,
          bodyEle = _this$props.bodyEle,
          prefixCls = _this$props.prefixCls,
          className = _this$props.className,
          title = _this$props.title,
          children = _this$props.children,
          tips = _this$props.tips,
          onSearch = _this$props.onSearch;
      bodyEle.appendChild(root);
      this.modalElement = /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(prefixCls, "-mask")
      }), /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(prefixCls, "-wrap")
      }, /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(prefixCls, " ").concat(className, " ").concat(prefixCls, "-layout"),
        ref: this.modalElementRef
      }, /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(prefixCls, "-content")
      }, /*#__PURE__*/_react["default"].createElement("button", {
        className: "".concat(prefixCls, "-close"),
        onClick: function onClick() {
          return _this2.onCancel();
        }
      }, /*#__PURE__*/_react["default"].createElement("span", {
        className: "".concat(prefixCls, "-close-x")
      }, /*#__PURE__*/_react["default"].createElement("i", {
        className: "mkicon mkicon-close ".concat(prefixCls, "-close-icon")
      }))), /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(prefixCls, "-header")
      }, /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(prefixCls, "-title")
      }, title), onSearch ? /*#__PURE__*/_react["default"].createElement(Search, {
        placeholder: "input search text",
        onSearch: function onSearch(value) {
          return _this2.onSearch(value);
        },
        style: {
          width: '100%'
        }
      }) : null), /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(prefixCls, "-body")
      }, children), tips ? /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(prefixCls, "-tips ").concat(tips && tips.length ? 'show' : '')
      }, tips.forEach(tip = /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(prefixCls, "-tip")
      }, tip))) : null, /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(prefixCls, "-footer")
      }, /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("button", {
        type: "button",
        className: "mkui-btn",
        onClick: function onClick() {
          return _this2.onCancel();
        }
      }, /*#__PURE__*/_react["default"].createElement("span", null, "\u53D6 \u6D88")), /*#__PURE__*/_react["default"].createElement("button", {
        type: "button",
        className: "mkui-btn mkui-btn-primary",
        onClick: function onClick() {
          return _this2.onConfirm();
        }
      }, /*#__PURE__*/_react["default"].createElement("span", null, "\u786E \u5B9A"))))))));

      _reactDom["default"].render(this.modalElement, root);

      this.modalElementRef.current.style.transform = 'scale(1)';
    }
  }, {
    key: "closeModal",
    value: function closeModal() {
      var _this$props2 = this.props,
          root = _this$props2.root,
          bodyEle = _this$props2.bodyEle;
      this.modalElementRef.current.style.transform = 'scale(0.3)';
      setTimeout(function () {
        _reactDom["default"].unmountComponentAtNode(root);

        bodyEle.removeChild(root);
      }, 400);
    }
  }, {
    key: "onCancel",
    value: function onCancel() {
      this.closeModal();
      var onCancel = this.props.onCancel;

      if (onCancel) {
        onCancel();
      }
    }
  }, {
    key: "onConfirm",
    value: function onConfirm() {
      this.closeModal();
      var onConfirm = this.props.onConfirm;

      if (onConfirm) {
        onConfirm();
      }
    }
  }, {
    key: "render",
    value: function render() {
      return null;
    }
  }]);

  return SelectModalLayout;
}(_react["default"].Component);

exports["default"] = SelectModalLayout;

_defineProperty(SelectModalLayout, "defaultProps", {
  root: document.createElement('div'),
  bodyEle: document.getElementsByTagName('body')[0],
  prefixCls: "mkui-modal"
});

SelectModalLayout.Tabs = _tabs["default"];
SelectModalLayout.Result = _result["default"];
//# sourceMappingURL=index.js.map
