'use strict';require('./es.array.includes-3990bfec.js'),require('./es.number.constructor-daccdeab.js');var index=require('./index-9dadef01.js'),i18n=require('./i18n-68e039d3.js'),BaseIcon=require('./BaseIcon-ddd3aaa0.js'),normalizeComponent=require('./normalize-component-d9981c57.js');require('./export-61511812.js'),require('./object-keys-12f2c5e5.js'),require('./object-set-prototype-of-dfa14cf5.js'),require('./regexp-exec-abstract-216cd44a.js'),require('./string-multibyte-a2dff6e3.js'),require('./regexp-flags-abc49c4a.js'),require('./es.string.split-98e29ede.js'),require('./is-regexp-d6f1551e.js'),require('./function-bind-context-e4685306.js'),require('./es.object.to-string-f27a75a8.js'),require('./classof-819fc780.js'),require('./array-iteration-f8b4483d.js'),require('./array-species-create-c414c2ec.js'),require('./es.object.keys-c57f02bd.js'),require('./es.array.concat-bb8715dc.js'),require('./create-property-240c71a5.js'),require('./array-method-has-species-support-983ac207.js'),require('./es.array.join-88750c41.js'),require('./array-method-is-strict-99341ee3.js');/**
 * Accessible drop down component
 */

var script = {
  name: 'BaseDropDown',
  components: {
    BaseIcon: BaseIcon["default"]
  },
  directives: {
    ClickOutside: index.v
  },
  mixins: [i18n.i],
  model: {
    prop: 'selectedOption',
    event: 'value-selected'
  },
  props: {
    /**
     * specify options to choose from <br>
     *   needs to be an array with label and value properties
     */
    options: {
      type: Array,
      default: function _default() {
        return [];
      }
    },

    /**
     * label for the drop down, recommended to define for accessibility
     */
    label: {
      type: String,
      default: 'Drop Down'
    },

    /**
     * placeholder appearing in select when no option was
     * selected
     */
    placeholder: {
      type: String,
      default: 'Select'
    },

    /**
     * @model
     *
     * the selected value
     */
    selectedOption: {
      type: Object,
      default: function _default() {
        return {
          value: '',
          label: ''
        };
      }
    },

    /**
     * define if label should be shown
     */
    showLabel: {
      type: Boolean,
      default: false
    },

    /**
     * set the background color of drop down head
     */
    headerBackgroundColor: {
      type: String,
      default: 'inherit'
    },

    /**
     * set a language ()
     */
    language: {
      type: String,
      default: ''
    },

    /**
     * set the name of the property that holds the value
     */
    valueProp: {
      type: String,
      default: 'value'
    },

    /**
     * flag to set drop down inactive
     */
    isDisabled: {
      type: Boolean,
      default: false
    },

    /**
     * flag to disable spacing left and right
     * (needed for sidebar drop downs)
     */
    withSpacing: {
      type: Boolean,
      default: true
    },

    /**
     * align drop down with left or right border
     */
    alignDropDown: {
      type: String,
      default: 'left',
      validator: function validator(val) {
        return ['left', 'right'].includes(val);
      }
    },

    /**
     * set id if drop down with this label appears more than once
     */
    id: {
      type: [String, Number],
      default: ''
    }
  },
  data: function data() {
    return {
      showDropDown: false,
      keySelectedIndex: -1,
      showFadeOut: false,
      maxDropDownHeight: '0',
      resizeObserver: null
    };
  },
  computed: {
    selectedOptionInt: function selectedOptionInt() {
      return this.getLangLabel(this.selectedOption.label, true) || this.placeholder || '';
    }
  },
  watch: {
    showDropDown: function showDropDown(val) {
      if (val) {
        // dont let drop down size be larger than window
        var maxHeight = window.innerHeight - this.$el.offsetTop - 120;
        this.maxDropDownHeight = "".concat(maxHeight < 300 ? maxHeight : 300, "px");
      } // reset index on close


      if (!val) {
        this.keySelectedIndex = -1;
      }
    }
  },
  mounted: function mounted() {
    this.initObserver();
  },
  beforeDestroy: function beforeDestroy() {
    if (this.resizeObserver) this.resizeObserver.unobserve(this.$refs.baseDropdown);
  },
  methods: {
    initObserver: function initObserver() {
      var _this = this;

      // create an observer with the set overflow calc function
      var resizeObserver = new ResizeObserver(function () {
        return _this.setOverflow();
      }); // put it on the relevant element

      resizeObserver.observe(this.$refs.baseDropdown); // store it

      this.resizeObserver = resizeObserver;
    },
    // event triggered by clicking on option or Enter after
    // selecting via keys
    selectValue: function selectValue(option) {
      this.showDropDown = false;
      /**
       * Event emitted when an option is selected
       *
       * @event value-selected
       * @type { Object }
       */

      this.$emit('value-selected', option);
    },
    // adding key navigation for accessibility
    selectByKey: function selectByKey(event) {
      if (event.key === 'ArrowDown') {
        this.showDropDown = true;

        if (this.keySelectedIndex < this.options.length - 1) {
          this.keySelectedIndex += 1;
        }
      } else if (event.key === 'ArrowUp') {
        if (this.keySelectedIndex > 0) {
          this.keySelectedIndex -= 1;
        }
      } else if (event.key === 'Enter') {
        if (this.showDropDown && this.keySelectedIndex >= 0) {
          this.selectValue(this.options[this.keySelectedIndex]);
        } else if (!this.showDropDown) {
          this.showDropDown = true;
        }
      } else if (event.key === 'Escape' || event.key === 'Tab') {
        this.showDropDown = false;
      }

      if (this.$refs.option && this.$refs.option[this.keySelectedIndex] && this.$refs.dropdownContainer.scrollHeight !== this.$refs.dropdownContainer.clientHeight) {
        this.$refs.option[this.keySelectedIndex].scrollIntoView({
          block: 'nearest',
          inline: 'nearest'
        });
      }
    },
    setOverflow: function setOverflow() {
      // eslint-disable-next-line max-len
      var headerWidth = this.$refs.dropDownButton ? this.$refs.dropDownButton.getBoundingClientRect().width : 0;
      var textWidth = this.$refs.headText ? this.$refs.headText.getBoundingClientRect().width : 0;
      this.showFadeOut = textWidth > headerWidth;
    }
  }
};/* script */
var __vue_script__ = script;
/* template */

var __vue_render__ = function __vue_render__() {
  var _obj;

  var _vm = this;

  var _h = _vm.$createElement;

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

  return _c('div', {
    directives: [{
      name: "click-outside",
      rawName: "v-click-outside",
      value: function value() {
        return _vm.showDropDown = false;
      },
      expression: "() => showDropDown = false"
    }],
    ref: "baseDropdown",
    staticClass: "base-drop-down"
  }, [_vm._ssrNode("<div" + _vm._ssrClass(null, ['base-drop-down-label-wrapper', {
    'hide': !_vm.getLangLabel(_vm.label, true) || !_vm.showLabel
  }]) + " data-v-092522b2><label" + _vm._ssrAttr("for", _vm.getLangLabel(_vm.label) + '-' + _vm.id) + " class=\"base-drop-down-label\" data-v-092522b2>" + _vm._ssrEscape("\n      " + _vm._s(_vm.getLangLabel(_vm.label, true)) + "\n    ") + "</label></div> "), _vm._ssrNode("<button" + _vm._ssrAttr("id", _vm.getLangLabel(_vm.label) + '-' + _vm.id) + _vm._ssrAttr("aria-expanded", String(_vm.showDropDown)) + _vm._ssrAttr("disabled", _vm.isDisabled) + " aria-haspopup=\"listbox\" type=\"button\"" + _vm._ssrClass(null, ['base-drop-down-head', {
    'base-drop-down-head-spacing': _vm.withSpacing
  }]) + _vm._ssrStyle(null, {
    'background-color': _vm.headerBackgroundColor
  }, null) + " data-v-092522b2>", "</button>", [_vm._ssrNode("<div" + _vm._ssrClass(null, ['base-drop-down-head-text-wrapper', {
    'base-drop-down-head-text-fade-out': _vm.showFadeOut
  }]) + " data-v-092522b2><span class=\"base-drop-down-head-text\" data-v-092522b2>" + _vm._ssrEscape("\n        " + _vm._s(_vm.selectedOptionInt) + "\n      ") + "</span></div> "), _vm._t("header-right", function () {
    return [_c('base-icon', {
      class: ['base-drop-down-icon', {
        'base-drop-down-icon-rotated': _vm.showDropDown
      }],
      attrs: {
        "name": "drop-down"
      }
    })];
  })], 2), _vm._ssrNode(" "), _vm.showDropDown ? _vm._ssrNode("<div class=\"base-drop-down-body\"" + _vm._ssrStyle(null, (_obj = {}, _obj[_vm.alignDropDown] = 0, _obj['max-height'] = _vm.maxDropDownHeight, _obj), null) + " data-v-092522b2>", "</div>", [_vm._t("default", function () {
    return [_c('ul', {
      staticClass: "base-drop-down-body-list",
      attrs: {
        "tabindex": "-1",
        "role": "listbox"
      }
    }, _vm._l(_vm.options, function (option, index) {
      return _c('li', {
        key: option[_vm.valueProp],
        ref: "option",
        refInFor: true,
        class: ['base-drop-down-option', {
          'base-drop-down-option-selected': _vm.selectedOption && option[_vm.valueProp] === _vm.selectedOption[_vm.valueProp]
        }, {
          'base-drop-down-option-key-selected': _vm.keySelectedIndex === index
        }],
        attrs: {
          "role": "option"
        },
        on: {
          "click": function click($event) {
            return _vm.selectValue(option);
          }
        }
      }, [_vm._v("\n          " + _vm._s(_vm.getLangLabel(option.label, true)) + "\n        ")]);
    }), 0)];
  })], 2) : _vm._e()], 2);
};

var __vue_staticRenderFns__ = [];
/* style */

var __vue_inject_styles__ = undefined;
/* scoped */

var __vue_scope_id__ = "data-v-092522b2";
/* module identifier */

var __vue_module_identifier__ = "data-v-092522b2";
/* functional template */

var __vue_is_functional_template__ = false;
/* style inject */

/* style inject SSR */

/* style inject shadow dom */

var __vue_component__ = /*#__PURE__*/normalizeComponent.n({
  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 BaseDropDown = __vue_component__;exports["default"]=BaseDropDown;