"use strict";

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

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

require("./index.css");

var _vueNormalizeComponent = _interopRequireDefault(require("../../utils/vue-normalize-component.js"));

/* script */
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
var isEditable = function isEditable(elem) {
  var nodeName = elem && elem.nodeName;

  if (!nodeName) {
    return false;
  }

  var rInput = /(?:input|button|textarea)/i;

  if (rInput.test(nodeName) || String(elem.contentEditable) === 'true') {
    return true;
  }

  return false;
};

var __vue_script__ = {
  name: 'GdDialog',
  props: {
    closeBtnText: {
      type: String,
      default: 'X'
    },
    visible: {
      type: Boolean,
      default: false
    },
    showCloseButton: {
      type: Boolean,
      default: false
    },
    esc: {
      type: Boolean,
      default: true
    },
    clickMaskHide: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    innerVisible: {
      get() {
        return this.visible;
      },

      set(visible) {
        this.$emit('update:visible', visible);
      }

    }
  },

  mounted() {
    this.initEscKey();
  },

  beforeDestroy() {
    this.$emit('destroy');
  },

  methods: {
    show() {
      this.innerVisible = true;
    },

    hide() {
      this.innerVisible = false;
    },

    onMaskHide() {
      if (this.$props.clickMaskHide) {
        this.hide();
      }
    },

    initEscKey() {
      var _this = this;

      var handler = function handler(e) {
        if (_this.esc && _this.showCloseButton && !isEditable(window.document.activeElement) && e.keyCode === 27 && !e.ctrlKey && !e.metaKey && !e.altKey) {
          _this.hide();
        }
      };

      window.document.addEventListener('keydown', handler, false);
      this.$on('destroy', function () {
        window.document.removeEventListener('keydown', handler, false);
      });
    }

  }
};
/* template */

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

  var _h = _vm.$createElement;

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

  return _c("transition", {
    attrs: {
      name: "fade"
    }
  }, [_c("div", {
    directives: [{
      name: "show",
      rawName: "v-show",
      value: _vm.visible,
      expression: "visible"
    }],
    staticClass: "gd-dialog"
  }, [_c("div", {
    staticClass: "gd-dialog-inner"
  }, [_vm.showCloseButton ? _c("button", {
    staticClass: "gd-dialog-close",
    class: {
      "show-close-text": _vm.closeBtnText !== "X"
    },
    on: {
      click: function click($event) {
        _vm.hide();
      }
    }
  }, [_vm._v(_vm._s(_vm.closeBtnText))]) : _vm._e(), _vm._v(" "), _c("div", {
    staticClass: "gd-dialog-header"
  }, [_vm._t("header")], 2), _vm._v(" "), _c("div", {
    staticClass: "gd-dialog-main"
  }, [_vm._t("default")], 2), _vm._v(" "), _c("div", {
    staticClass: "gd-dialog-footer"
  }, [_vm._t("footer")], 2)]), _vm._v(" "), _c("div", {
    staticClass: "gd-dialog-mask",
    on: {
      click: _vm.onMaskHide
    }
  })])]);
};

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

var __vue_inject_styles__ = undefined;
/* scoped */

var __vue_scope_id__ = undefined;
/* module identifier */

var __vue_module_identifier__ = undefined;
/* functional template */

var __vue_is_functional_template__ = false;
/* component normalizer */

/* style inject */

/* style inject SSR */
var _default = (0, _vueNormalizeComponent.default)({
  render: __vue_render__,
  staticRenderFns: __vue_staticRenderFns__
}, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, undefined, undefined);

exports.default = _default;