"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.default = void 0;

var _create = _interopRequireDefault(require("../utils/create"));

var _button = _interopRequireDefault(require("../button"));

var _popup = _interopRequireDefault(require("../mixins/popup"));

var _default = (0, _create.default)({
  render: function render() {
    var _obj;

    var _vm = this;

    var _h = _vm.$createElement;

    var _c = _vm._self._c || _h;

    return _c('transition', {
      attrs: {
        "name": "vm-dialog-bounce"
      }
    }, [_c('div', {
      directives: [{
        name: "show",
        rawName: "v-show",
        value: _vm.value,
        expression: "value"
      }],
      class: [_vm.b(), _vm.className]
    }, [_vm.title ? _c('div', {
      class: _vm.b('-header', {
        isolated: !_vm.message && !_vm.$slots.default
      }),
      domProps: {
        "textContent": _vm._s(_vm.title)
      }
    }) : _vm._e(), _vm.message || _vm.$slots.default ? _c('div', {
      class: _vm.b('content')
    }, [_vm._t("default", [_vm.message ? _c('div', {
      class: _vm.b('message', (_obj = {
        'has-title': _vm.title
      }, _obj[_vm.messageAlign] = _vm.messageAlign, _obj)),
      domProps: {
        "innerHTML": _vm._s(_vm.message)
      }
    }) : _vm._e()])], 2) : _vm._e(), _c('div', {
      staticClass: "vm-hairline-top",
      class: _vm.b('footer', {
        buttons: _vm.showCancelButton && _vm.showConfirmButton
      })
    }, [_c('vm-button', {
      directives: [{
        name: "show",
        rawName: "v-show",
        value: _vm.showCancelButton,
        expression: "showCancelButton"
      }],
      class: [_vm.b('cancel'), 'bg-white'],
      attrs: {
        "size": "lg",
        "loading": _vm.loading.cancel,
        "text": _vm.cancelButtonText || '取消'
      },
      on: {
        "click": function click($event) {
          return _vm.handleAction('cancel');
        }
      }
    }), _c('vm-button', {
      directives: [{
        name: "show",
        rawName: "v-show",
        value: _vm.showConfirmButton,
        expression: "showConfirmButton"
      }],
      class: [_vm.b('confirm'), 'bg-white', {
        'vm-hairline-left': _vm.showCancelButton && _vm.showConfirmButton
      }],
      attrs: {
        "size": "lg",
        "block": "",
        "loading": _vm.loading.confirm,
        "text": _vm.confirmButtonText || '确定'
      },
      on: {
        "click": function click($event) {
          return _vm.handleAction('confirm');
        }
      }
    })], 1)])]);
  },
  name: "dialog",
  components: {
    MmButton: _button.default
  },
  mixins: [_popup.default],
  props: {
    title: String,
    message: String,
    callback: Function,
    className: [String, Object, Array],
    beforeClose: Function,
    messageAlign: String,
    confirmButtonText: String,
    cancelButtonText: String,
    showCancelButton: Boolean,
    showConfirmButton: {
      type: Boolean,
      default: true
    },
    overlay: {
      type: Boolean,
      default: true
    },
    closeOnClickOverlay: {
      type: Boolean,
      default: false
    }
  },
  data: function data() {
    return {
      loading: {
        confirm: false,
        cancel: false
      }
    };
  },
  methods: {
    handleAction: function handleAction(action) {
      var _this = this;

      if (this.beforeClose) {
        this.loading[action] = true;
        this.beforeClose(action, function (state) {
          if (state !== false) {
            _this.onClose(action);
          }

          _this.loading[action] = false;
        });
      } else {
        this.onClose(action);
      }
    },
    onClose: function onClose(action) {
      this.$emit("input", false);
      this.$emit(action);
      this.callback && this.callback(action);
    }
  }
});

exports.default = _default;