"use strict";

var _interopRequireDefault = require("D:/git/\u6211\u7684/opu-components-vue/node_modules/@babel/runtime/helpers/interopRequireDefault.js").default;

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

require("core-js/modules/es.array.concat.js");

var _babelHelperVueJsxMergeProps = _interopRequireDefault(require("@vue/babel-helper-vue-jsx-merge-props"));

var _objectSpread2 = _interopRequireDefault(require("D:/git/\u6211\u7684/opu-components-vue/node_modules/@babel/runtime/helpers/esm/objectSpread2.js"));

var _vxeTable = require("vxe-table");

var _init = require("../../init");

var _default2 = {
  name: "Modal",
  components: {},
  props: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, _vxeTable.Modal.props), {}, {
    value: {
      type: Boolean
    },
    okText: {
      type: String,
      default: "确定"
    },
    cancelText: {
      type: String,
      default: "取消"
    },
    okButtonProps: {
      type: Object,
      default: function _default() {}
    },
    cancelButtonProps: Object,
    confirmLoading: {
      type: Boolean,
      default: false
    },
    showFooter: {
      type: [Boolean, String],
      default: true
    }
  }),
  model: {
    prop: "value",
    event: "update"
  },
  data: function data() {
    return {
      visible: false
    };
  },
  computed: {
    modalProps: function modalProps() {
      var _this = this;

      var h = this.$createElement;
      var $scopedSlots = this.$scopedSlots,
          $listeners = this.$listeners,
          onHide = this.onHide,
          onCancel = this.onCancel,
          okText = this.okText,
          okButtonProps = this.okButtonProps,
          cancelButtonProps = this.cancelButtonProps,
          onSubmit = this.onSubmit,
          cancelText = this.cancelText,
          visible = this.visible,
          confirmLoading = this.confirmLoading,
          showFooter = this.showFooter;
      var propsData = this.$options.propsData;
      var props = {
        props: (0, _objectSpread2.default)((0, _objectSpread2.default)({
          className: "opu-modal"
        }, propsData), {}, {
          value: visible,
          showFooter: showFooter
        })
      };
      props.class = "vxeModal";
      props.ref = "modal";
      props.scopedSlots = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, $scopedSlots), {}, {
        title: function title() {
          return h("div", (0, _babelHelperVueJsxMergeProps.default)([{}, {
            on: {
              mousedown: function mousedown() {
                _this.$refs.hiddenInput.focus();
              }
            },
            class: "modal-title"
          }]), [propsData.title, h("input", {
            "class": "hidden-input",
            "ref": "hiddenInput"
          })]);
        }
      });

      if (showFooter && !$scopedSlots.footer) {
        okButtonProps = okButtonProps || {};
        var okButton = h("a-button", (0, _babelHelperVueJsxMergeProps.default)([{}, {
          props: (0, _objectSpread2.default)((0, _objectSpread2.default)({
            type: "primary"
          }, okButtonProps), {}, {
            loading: confirmLoading
          }),
          style: okButtonProps.style,
          on: {
            click: onSubmit
          }
        }]), [okText]);
        var cancelButton = h("a-button", {
          "props": (0, _objectSpread2.default)({}, (0, _objectSpread2.default)({}, cancelButtonProps)),
          "on": (0, _objectSpread2.default)({}, {
            click: onCancel
          })
        }, [cancelText]);

        props.scopedSlots.footer = function () {
          return h("a-space", [cancelButton, okButton]);
        };
      }

      var ons = {};

      _init.utils.each($listeners, function (cb, type) {
        ons[type] = function () {
          for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
            args[_key] = arguments[_key];
          }

          _this.$emit.apply(_this, [type].concat(args));
        };
      });

      props.on = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ons), {}, {
        hide: onHide
      });
      return props;
    }
  },
  watch: {
    value: function value(val) {
      this.visible = val;
    }
  },
  created: function created() {
    this.visible = this.value;
  },
  methods: {
    onHide: function onHide() {
      this.$emit("update", false);
      this.onCancel();
    },
    onCancel: function onCancel() {
      this.visible = false;
      this.$emit("cancel", false);
    },
    onSubmit: function onSubmit() {
      this.$emit("ok");
    }
  },
  render: function render(h) {
    var modalProps = this.modalProps,
        visible = this.visible;
    return h("vxe-modal", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, modalProps), {
      props: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, modalProps.props), {}, {
        value: visible
      }),
      on: (0, _objectSpread2.default)({}, modalProps.on)
    }));
  }
};
exports.default = _default2;