"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _modal = _interopRequireDefault(require("antd/lib/modal"));
var _icons = require("@ant-design/icons");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return 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, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : 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; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } 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.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
var styles = {
  normal: 'vtx-ui-modal-normal',
  maxClass: 'vtx-ui-modal-maxClass',
  title: 'vtx-ui-modal-title',
  title_name: 'vtx-ui-modal-title_name',
  close: 'vtx-ui-modal-close',
  maximizeIcon: 'vtx-ui-modal-maximizeIcon'
};
var VtxModal = /*#__PURE__*/function (_React$Component) {
  _inherits(VtxModal, _React$Component);
  var _super = _createSuper(VtxModal);
  function VtxModal(props) {
    var _this;
    _classCallCheck(this, VtxModal);
    _this = _super.call(this, props);
    _this.classId = new Date().getTime() + Math.random();
    _this.isInit = false;
    _this.isCreate = props.visible;
    _this.state = {
      maximizable: false,
      maximizeClass: '',
      init_x: 0,
      init_y: 0,
      x_move: 0,
      y_move: 0,
      documentMouseMove: null,
      documentMouseUp: null
    };
    _this.startDrag = _this.startDrag.bind(_assertThisInitialized(_this));
    return _this;
  }
  _createClass(VtxModal, [{
    key: "componentWillReceiveProps",
    value: function componentWillReceiveProps(nextProps) {
      if (nextProps.visible && !this.isCreate) {
        this.isCreate = true;
      }
      if (!this.props.visible && nextProps.visible) {
        this.setState({
          x_move: 0,
          y_move: 0
        });
      }
    }
  }, {
    key: "componentDidUpdate",
    value: function componentDidUpdate() {
      var t = this;
      if (!this.props.isNotMoving) {
        if (this.isCreate && !this.isInit) {
          this.isInit = true;
          try {
            this.timer = setTimeout(function () {
              var modalHead = document.getElementsByClassName(t.classId)[0].getElementsByClassName('ant-modal-header')[0];
              modalHead.style.cursor = 'move';
              modalHead.onmousedown = t.startDrag;
            }, 200);
          } catch (error) {
            console.error('VtxModal拖动功能异常,未获取到头部dom对象!');
          }
        }
      }
    }
  }, {
    key: "componentWillUnmount",
    value: function componentWillUnmount() {
      if (this.timer) {
        clearTimeout(this.timer);
      }
    }
  }, {
    key: "startDrag",
    value: function startDrag(e) {
      var _this2 = this;
      e.preventDefault();
      if (!this.state.maximizable) {
        this.setState({
          documentMouseUp: document.onmouseup,
          documentMouseMove: document.onmousemove,
          init_x: e.clientX - this.state.x_move,
          init_y: e.clientY - this.state.y_move
        });
        document.onmousemove = function (e) {
          _this2.setState({
            x_move: e.clientX - _this2.state.init_x,
            y_move: e.clientY - _this2.state.init_y
          });
        };
        document.onmouseup = function (e) {
          document.onmousemove = _this2.state.documentMouseMove;
          document.onmouseup = _this2.state.documentMouseUp;
        };
      }
    }
  }, {
    key: "render",
    value: function render() {
      var t = this;
      var _this$props = this.props,
        _this$props$closable = _this$props.closable,
        closable = _this$props$closable === void 0 ? true : _this$props$closable,
        _this$props$maximize = _this$props.maximize,
        maximize = _this$props$maximize === void 0 ? true : _this$props$maximize,
        _this$props$wrapClass = _this$props.wrapClassName,
        wrapClassName = _this$props$wrapClass === void 0 ? '' : _this$props$wrapClass,
        _this$props$title = _this$props.title,
        title = _this$props$title === void 0 ? '' : _this$props$title;
      var _this$state = this.state,
        maximizable = _this$state.maximizable,
        maximizeClass = _this$state.maximizeClass;
      wrapClassName = "".concat(styles.normal, " ").concat(wrapClassName, " ").concat(maximizeClass, " ").concat(this.classId);
      var transformStyle = {
        transform: "translate(".concat(this.state.x_move, "px,").concat(this.state.y_move, "px)")
      };
      title = function renderTitle() {
        return /*#__PURE__*/_react["default"].createElement("div", {
          className: styles.title,
          style: {
            paddingRight: closable ? '32px' : '0px'
          }
        }, /*#__PURE__*/_react["default"].createElement("div", {
          className: styles.title_name
        }, title), maximize ? /*#__PURE__*/_react["default"].createElement("div", {
          className: styles.maximizeIcon
        }, /*#__PURE__*/_react["default"].createElement("p", {
          onClick: function onClick() {
            var maximizeClass = '';
            if (!maximizable) {
              maximizeClass = styles.maxClass;
            }
            t.setState({
              maximizable: !maximizable,
              maximizeClass: maximizeClass
            }, function () {
              if (t.timer) {
                clearTimeout(t.timer);
              }
              t.timer = setTimeout(function () {
                if (window.onModalResize && typeof window.onModalResize == 'function') {
                  window.onModalResize();
                }
              }, 100);
            });
          }
        }, maximizable ? /*#__PURE__*/_react["default"].createElement(_icons.ShrinkOutlined, null) : /*#__PURE__*/_react["default"].createElement(_icons.ArrowsAltOutlined, null))) : null, closable ? /*#__PURE__*/_react["default"].createElement("div", {
          className: styles.close
        }, /*#__PURE__*/_react["default"].createElement("p", {
          onClick: t.props.onCancel
        }, /*#__PURE__*/_react["default"].createElement(_icons.CloseOutlined, null))) : null);
      }();
      var bodyStyle = _objectSpread({}, this.props.bodyStyle);
      if (!maximizable) {
        bodyStyle = _objectSpread({
          maxHeight: "".concat(window.innerHeight * 0.7, "px")
        }, bodyStyle);
      }
      var props = _objectSpread(_objectSpread({
        closable: closable,
        maskClosable: false,
        width: 700
      }, this.props), {}, {
        closable: false,
        title: title,
        wrapClassName: wrapClassName,
        bodyStyle: bodyStyle,
        style: _objectSpread(_objectSpread({}, this.props.style), maximizable ? {} : transformStyle)
      });
      return this.props.visible ? /*#__PURE__*/_react["default"].createElement(_modal["default"], props, this.props.children) : null;
    }
  }]);
  return VtxModal;
}(_react["default"].Component);
VtxModal.info = _modal["default"].info;
VtxModal.success = _modal["default"].success;
VtxModal.error = _modal["default"].error;
VtxModal.warning = _modal["default"].warning;
VtxModal.confirm = _modal["default"].confirm;
var _default = exports["default"] = VtxModal;
//# sourceMappingURL=VtxModal.js.map
