import './es.object.to-string-591fd1f0.js';
import BaseIcon from './BaseIcon-7b5c99e9.js';
import { p as popUpLock } from './popUpLock-5fb46ec6.js';
import { n as normalizeComponent } from './normalize-component-43ce05b9.js';

/**
 * A component as overlay to display messages
 *
 */

var script = {
  name: 'BasePopUp',
  components: {
    BaseIcon: BaseIcon,
    BaseButton: function BaseButton() {
      return import('./BaseButton-9d410cd5.js');
    },
    BaseLoader: function BaseLoader() {
      return import('./BaseLoader-4a2f6b54.js');
    }
  },
  mixins: [popUpLock],
  props: {
    /**
     * could be used to control visibility
     */
    show: {
      type: Boolean,
      default: false
    },

    /**
     * pop up header text
     */
    title: {
      type: String,
      default: 'Pop Up'
    },

    /**
     * specify the id of the element containing a description - for accessibility only
     */
    descriptionElementId: {
      type: String,
      default: ''
    },

    /**
     * text shown in left button
     */
    buttonLeftText: {
      type: String,
      default: 'Cancel'
    },

    /**
     * text shown in right button
     */
    buttonRightText: {
      type: String,
      default: 'Submit'
    },

    /**
     * icon shown in left button
     */
    buttonLeftIcon: {
      type: String,
      default: 'remove'
    },

    /**
     * icon shown in right button
     */
    buttonRightIcon: {
      type: String,
      default: 'check-mark'
    },

    /**
     * disable right button
     */
    buttonRightDisabled: {
      type: Boolean,
      default: false
    },

    /**
     * if true button loader will be shown
     */
    isLoading: {
      type: Boolean,
      default: false
    },

    /**
     * selector to focus if popup is open
     */
    isOpenFocus: {
      type: String,
      default: ''
    },

    /**
     * specify to render component with max height and width
     */
    fullscreenOnMobile: {
      type: Boolean,
      default: false
    }
  },
  data: function data() {
    return {
      showInt: this.show,
      // this is needed for popUpLock mixin!
      targetName: 'popUpBody'
    };
  },
  watch: {
    show: function show(val) {
      if (!this.showInt && !this.prevActiveElement) {
        this.prevActiveElement = document.activeElement;
      }

      this.showInt = val;
    }
  },
  updated: function updated() {
    var _this = this;

    setTimeout(function () {
      if (_this.showInt) {
        if (_this.isOpenFocus !== '' && _this.$el.querySelector(_this.isOpenFocus)) {
          _this.$el.querySelector(_this.isOpenFocus).focus();
        }
      } else if (_this.prevActiveElement) {
        _this.prevActiveElement.focus();

        _this.prevActiveElement = false;
      }
    }, 250);
  },
  mounted: function mounted() {
    document.onkeyup = function (e) {
      var event = e || window.event;

      if (document.querySelector('.popup-box')) {
        if (event.keyCode === 27 || event.key === 'Escape') {
          // 27 === ESC
          var btn = document.querySelector('.popup-box .base-popup__close-button');
          btn.dispatchEvent(new Event('click'));
        }
      }
    };
  },
  methods: {
    close: function close() {
      /**
       * Event triggered on right top corner close action
       *
       * @event close
       * @type { none }
       */
      this.$emit('close');
      this.showInt = false;
    },
    buttonRight: function buttonRight() {
      /**
       * Event triggered with right button
       *
       * @event button-right
       * @type { none }
       */
      this.$emit('button-right');
    },
    buttonLeft: function buttonLeft() {
      /**
       * Event triggered with left button
       *
       * @event button-left
       * @type { none }
       */
      this.$emit('button-left');
    }
  }
};

/* script */
var __vue_script__ = script;
/* template */

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

  var _h = _vm.$createElement;

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

  return _vm.showInt ? _c('div', {
    class: ['base-pop-up', {
      'base-pop-up--fullscreen-on-mobile': _vm.fullscreenOnMobile
    }]
  }, [_c('div', {
    staticClass: "base-pop-up-background"
  }), _vm._v(" "), _c('div', {
    ref: "popUpBody",
    staticClass: "popup-box",
    attrs: {
      "role": "alertdialog",
      "aria-modal": "true",
      "aria-labelledby": "popup-title",
      "aria-describedby": "descriptionElementId"
    }
  }, [_c('div', {
    staticClass: "popup-header"
  }, [_c('div', {
    staticClass: "popup-title",
    attrs: {
      "id": "popup-title"
    }
  }, [_vm._v("\n        " + _vm._s(_vm.title) + "\n      ")]), _vm._v(" "), _c('button', {
    staticClass: "base-popup__close-button",
    attrs: {
      "type": "button",
      "aria-label": "close pop up"
    },
    on: {
      "click": _vm.close
    }
  }, [_c('base-icon', {
    staticClass: "popup-remove",
    attrs: {
      "name": "remove"
    }
  })], 1)]), _vm._v(" "), _c('div', {
    staticClass: "popup-content"
  }, [_vm._t("default"), _vm._v(" "), _c('div', {
    staticClass: "popup-button-row"
  }, [_vm._t("button-row", function () {
    return [_c('BaseButton', {
      staticClass: "base-popup-button",
      attrs: {
        "id": "popup-left-button",
        "text": _vm.buttonLeftText,
        "icon": _vm.buttonLeftIcon,
        "icon-position": 'right',
        "icon-size": 'small'
      },
      on: {
        "clicked": _vm.buttonLeft
      }
    }), _vm._v(" "), _c('BaseButton', {
      staticClass: "base-popup-button",
      attrs: {
        "id": "popup-right-button",
        "text": _vm.buttonRightText,
        "icon": !_vm.isLoading ? _vm.buttonRightIcon : '',
        "icon-position": 'right',
        "icon-size": 'small',
        "disabled": _vm.buttonRightDisabled
      },
      on: {
        "clicked": _vm.buttonRight
      },
      scopedSlots: _vm._u([{
        key: "right-of-text",
        fn: function fn() {
          return [_c('span', {
            directives: [{
              name: "show",
              rawName: "v-show",
              value: _vm.isLoading,
              expression: "isLoading"
            }],
            staticClass: "base-popup-button-loader"
          }, [_c('BaseLoader')], 1)];
        },
        proxy: true
      }], null, false, 288902964)
    })];
  })], 2)], 2)])]) : _vm._e();
};

var __vue_staticRenderFns__ = [];
/* style */

var __vue_inject_styles__ = undefined;
/* scoped */

var __vue_scope_id__ = "data-v-68b401e8";
/* module identifier */

var __vue_module_identifier__ = undefined;
/* functional template */

var __vue_is_functional_template__ = false;
/* style inject */

/* style inject SSR */

/* style inject shadow dom */

var __vue_component__ = /*#__PURE__*/normalizeComponent({
  render: __vue_render__,
  staticRenderFns: __vue_staticRenderFns__
}, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, false, undefined, undefined, undefined);

var BasePopUp = __vue_component__;

export { BasePopUp as B };
