import { _ as _defineProperty } from './defineProperty-18999f8e.js';
import './es.array.map-2dfef513.js';
import './es.array.concat-669570ef.js';
import './es.object.to-string-9e0d4e1d.js';
import './es.regexp.to-string-71ed70dc.js';
import { n as normalizeComponent } from './normalize-component-1b2cdbb6.js';
import './well-known-symbol-6e9136be.js';
import './array-iteration-ec419780.js';
import './function-bind-context-b3fabf77.js';
import './array-species-create-6fc0b2c4.js';
import './array-method-has-species-support-4ec91b65.js';
import './create-property-2fc26c80.js';
import './classof-2816ca36.js';
import './regexp-flags-e2ab70ab.js';

//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//

/**
 * accessible tab switch buttons
 */
var script = {
  name: 'BaseSwitchButton',
  model: {
    prop: 'activeTab',
    event: 'switch'
  },
  props: {
    /**
     * specify the tabs as array of object with value and label properties
     */
    options: {
      type: Array,
      default: function _default() {
        return [{
          label: 'tab',
          value: 'tab'
        }];
      }
    },

    /**
     * set the currently active tab (specify the value of the object not the label)
     *
     * @model
     */
    activeTab: {
      type: String,
      default: function _default() {
        return this.options[0] ? this.options[0].value : 'tab';
      }
    },

    /**
     * set a label for the switches, not visible but needed for accessibility
     */
    label: {
      type: String,
      required: true
    }
  },
  data: function data() {
    return {
      selectedOption: this.activeTab
    };
  },
  computed: {
    // to ensure a unique id (made problems on field duplication)
    optionIds: function optionIds() {
      var _this = this;

      return this.options.map(function (option) {
        return _this.generateId(option.value);
      });
    }
  },
  watch: {
    selectedOption: function selectedOption(val) {
      /**
       * Event emitted on options switch, value of options object is emitted
       *
       * @event switch
       * @type { string }
       */
      this.$emit('switch', val);
    },
    activeTab: function activeTab(val) {
      if (val !== this.selectedOption) {
        this.selectedOption = val;
      }
    }
  },
  methods: {
    generateId: function generateId(value) {
      return "".concat(value).concat(Math.floor(Math.random() * 1000000).toString());
    }
  }
};

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 _c('fieldset', {
    staticClass: "base-switch-buttons"
  }, [_c('legend', {
    staticClass: "hide"
  }, [_vm._v("\n    " + _vm._s(_vm.label) + "\n  ")]), _vm._v(" "), _vm._l(_vm.options, function (option, index) {
    return [_c('input', {
      directives: [{
        name: "model",
        rawName: "v-model",
        value: _vm.selectedOption,
        expression: "selectedOption"
      }],
      key: option.value + 'input',
      class: ['hide', 'base-switch-button-input', {
        'base-switch-button-input-active': option.value === _vm.selectedOption
      }],
      attrs: {
        "id": _vm.optionIds[index],
        "tabindex": option.value === _vm.selectedOption ? 0 : -1,
        "aria-checked": option.value === _vm.selectedOption,
        "name": _vm.label,
        "type": "radio"
      },
      domProps: _defineProperty({
        "checked": option.value === _vm.selectedOption,
        "value": option.value
      }, "checked", _vm._q(_vm.selectedOption, option.value)),
      on: {
        "keydown": function keydown($event) {
          if (!$event.type.indexOf('key') && _vm._k($event.keyCode, "enter", 13, $event.key, "Enter")) {
            return null;
          }

          $event.preventDefault();
        },
        "change": function change($event) {
          _vm.selectedOption = option.value;
        }
      }
    }), _vm._v(" "), _c('label', {
      key: option.value + 'label',
      staticClass: "base-switch-button-label",
      attrs: {
        "for": _vm.optionIds[index]
      }
    }, [_vm._v("\n      " + _vm._s(option.label) + "\n      "), _vm._v(" "), _vm._t("right-of-text", null, {
      "value": option.value
    })], 2)];
  })], 2);
};

var __vue_staticRenderFns__ = [];
/* style */

var __vue_inject_styles__ = undefined;
/* scoped */

var __vue_scope_id__ = "data-v-d6b32f4e";
/* 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 BaseSwitchButton = __vue_component__;

export { BaseSwitchButton as default };
