import "./index.css";
/* script */
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
import { createComponentName, componentMixin } from '../_utils/component';
import Icon from '../Icon';
import popupManager from '../_utils/popup-manager';
const __vue_script__ = {
  name: createComponentName('modal'),
  components: {
    Icon
  },
  mixins: [componentMixin],
  props: {
    // 是否可见
    visible: {
      type: Boolean,
      default: false
    },
    // 显示遮罩层
    mask: {
      type: Boolean,
      default: true
    },
    transitionName: {
      type: String,
      default: 'gd-modal-fade'
    },
    transitionOn: {
      type: Object
    },
    transitionDuration: {
      type: Object
    },
    // 是否支持键盘esc关闭
    keyborad: {
      type: Boolean,
      default: true
    },
    // 标题
    title: {
      type: String
    },
    appendBody: {
      type: Boolean,
      default: true
    },
    // modal 宽度
    width: {
      type: String,
      default: '350px'
    },
    top: {
      type: String,
      default: '15%'
    },
    theme: {
      type: String,
      default: 'light' // light or dark

    },
    bottom: {
      type: String,
      default: 'auto'
    },
    // 显示关闭按钮
    showClose: {
      type: Boolean,
      default: true
    },
    // 自定义关闭按钮文笔
    closeText: {
      type: String
    },
    // 确认按钮文字
    okText: {
      type: String
    },
    // 取消按钮文字
    cancelText: {
      type: String
    },
    // 点击遮罩层是否允许关闭
    maskClosable: {
      type: Boolean,
      default: true
    },
    onCancel: {
      type: Function
    },
    afterClose: {
      type: Function
    },
    // 居中
    centered: {
      type: Boolean,
      default: false
    },
    onOk: {
      type: Function
    }
  },

  data() {
    return {
      zIndex: popupManager.getZindex(),
      mounted: false
    };
  },

  computed: {
    dialogStyle() {
      return {
        marginTop: this.top,
        width: this.width
      };
    },

    hasFooter() {
      return this.okText || this.noText || this.$slots.footer;
    }

  },
  watch: {
    visible(value) {
      if (value) {
        popupManager.pushStack(this);
      } else if (!value) {
        popupManager.popStack(this);
      }
    }

  },

  mounted() {
    this.mounted = true;
    if (this.isSSR()) return;
    if (this.visible) popupManager.pushStack(this);
  },

  beforeDestroy() {
    if (this.appendBody && this.$el.parentElement) {
      this.$el.parentElement.removeChild(this.$el);
    }

    popupManager.popStack(this);
  },

  methods: {
    close(e) {
      if (this.maskClosable && e.target === this.$refs.wrapper) {
        this.cancel();
      }
    },

    async confirm() {
      this.$emit('update:visible', false);
      if (this.onOk) await this.onOk();
    },

    async cancel() {
      // visible.sync
      this.$emit('update:visible', false);
      if (this.onCancel) await this.onCancel();
    },

    onClickOverlay() {
      if (this.showClose) {
        this.cancel();
      }
    },

    afterLeave() {
      if (this.afterClose) this.afterClose();
    }

  }
};
/* template */

var __vue_render__ = function () {
  var _vm = this;

  var _h = _vm.$createElement;

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

  return _c("transition", _vm._g({
    attrs: {
      name: _vm.transitionName,
      duration: _vm.transitionDuration
    },
    on: {
      "after-leave": _vm.afterLeave
    }
  }, _vm.transitionOn), [_vm.mounted && _vm.visible ? _c("div", {
    ref: "wrapper",
    class: _vm.bem("wrapper", {
      centered: _vm.centered
    }),
    style: {
      zIndex: _vm.zIndex,
      position: _vm.appendBody ? "fixed" : "absolute"
    },
    on: {
      click: _vm.close
    }
  }, [_c("div", {
    class: _vm.bem([_vm.theme]),
    style: {
      width: _vm.width,
      top: _vm.centered ? "0" : _vm.top,
      bottom: _vm.bottom
    }
  }, [_c("div", {
    class: _vm.bem("header")
  }, [_vm._t("header", [_vm.title ? _c("span", {
    class: _vm.bem("title")
  }, [_vm._v(_vm._s(_vm.title))]) : _vm._e()]), _vm._v(" "), _vm.showClose && !_vm.closeText ? _c("icon", {
    class: _vm.bem("close"),
    attrs: {
      name: "close",
      color: "#AAA"
    },
    nativeOn: {
      click: function ($event) {
        _vm.onClickOverlay(false);
      }
    }
  }) : _vm._e(), _vm._v(" "), _vm.showClose && _vm.closeText ? _c("span", {
    class: _vm.bem("close"),
    on: {
      click: function ($event) {
        _vm.onClickOverlay(false);
      }
    }
  }, [_vm._v(_vm._s(_vm.closeText))]) : _vm._e()], 2), _vm._v(" "), _c("div", {
    class: _vm.bem("body")
  }, [_vm._t("default")], 2), _vm._v(" "), _vm.hasFooter ? _c("div", {
    class: _vm.bem("footer")
  }, [_vm._t("footer", [_c("div", {
    class: _vm.bem("buttons")
  }, [_vm.okText ? _c("gd-button", {
    attrs: {
      rect: "",
      type: "primary"
    },
    on: {
      click: _vm.confirm
    }
  }, [_vm._v("\n                            " + _vm._s(_vm.okText) + "\n                        ")]) : _vm._e(), _vm._v(" "), _vm.cancelText ? _c("gd-button", {
    attrs: {
      rect: ""
    },
    on: {
      click: _vm.cancel
    }
  }, [_vm._v("\n                            " + _vm._s(_vm.cancelText) + "\n                        ")]) : _vm._e()], 1)])], 2) : _vm._e()])]) : _vm._e()]);
};

var __vue_staticRenderFns__ = [];
__vue_render__._withStripped = true;
/* style */

const __vue_inject_styles__ = undefined;
/* scoped */

const __vue_scope_id__ = undefined;
/* module identifier */

const __vue_module_identifier__ = undefined;
/* functional template */

const __vue_is_functional_template__ = false;
/* component normalizer */

import __vue_normalize__ from '../_utils/vue-normalize-component.js';
/* style inject */

/* style inject SSR */

export default __vue_normalize__({
  render: __vue_render__,
  staticRenderFns: __vue_staticRenderFns__
}, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, undefined, undefined);