'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var normalizeComponent = require('./normalize-component-6fa50395.js');
var ThemeMixin = require('./ThemeMixin-a2f817cd.js');
var VTabsContent = require('./VTabsContent.js');

var script = {
  name: 'VTabs',
  provide: function provide() {
    return {
      addTab: this.addTab,
      removeTab: this.removeTab,
      setTabAsActive: this.setTabAsActive
    };
  },
  data: function data() {
    return {
      activeTabIdx: 0,
      tabs: []
    };
  },
  computed: {
    vTabsCssClass: function vTabsCssClass() {
      return ThemeMixin._objectSpread2(ThemeMixin._objectSpread2({}, this.themeCssClass), {}, {
        'v-tabs': true
      });
    }
  },
  methods: {
    addTab: function addTab(tab) {
      this.tabs.push(tab);
      if (!tab.$props.isActive) return;
      this.activeTabIdx = this.tabs.findIndex(function (el) {
        return el === tab;
      });
    },
    removeTab: function removeTab(tab) {
      var tabIdx = this.tabs.findIndex(function (el) {
        return el === tab;
      });
      this.tabs.splice(tabIdx, 1);
      var newTabIdx = this.activeTabIdx - 1;
      this.activeTabIdx = newTabIdx >= 0 ? newTabIdx : 0;
    },
    setTabAsActive: function setTabAsActive(tab) {
      var tabIdx = this.tabs.findIndex(function (el) {
        return el === tab;
      });
      if (this.activeTabIdx === tabIdx) return;
      this.activeTabIdx = tabIdx;
    },
    getTabLabel: function getTabLabel(tab) {
      var data = tab.data,
          componentOptions = tab.componentOptions;

      if (componentOptions.propsData && componentOptions.propsData.label) {
        return componentOptions.propsData.label;
      }

      return data.attrs.label;
    },
    onTabClick: function onTabClick(_ref) {
      var event = _ref.event,
          index = _ref.index;
      var _this$tabs$index$$lis = this.tabs[index].$listeners,
          $listeners = _this$tabs$index$$lis === void 0 ? {} : _this$tabs$index$$lis;
      this.activeTabIdx = index;
      if (!$listeners.click) return;
      $listeners.click(event);
    }
  },
  mixins: [ThemeMixin.ThemeMixin],
  components: {
    VTabsContent: VTabsContent.default
  }
};

/* script */
const __vue_script__ = script;

/* template */
var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return (_vm.$slots.default)?_c('div',{class:_vm.vTabsCssClass},[_c('section',{staticClass:"v-tabs-controls-list"},_vm._l((_vm.$slots.default.filter(function ($el) { return !!$el.tag; })),function(tab,index){return _c('a',_vm._b({key:index,class:{
        'v-tabs-control': true,
        'is-active': _vm.activeTabIdx === index,
      },attrs:{"href":"#"},on:{"click":function($event){$event.preventDefault();return _vm.onTabClick({ event: $event, index: index })}}},'a',tab.data.attrs,false),[_vm._v("\n      "+_vm._s(_vm.getTabLabel(tab))+"\n    ")])}),0),_vm._v(" "),_c('v-tabs-content',{staticClass:"v-tabs-content",attrs:{"active-tab-idx":_vm.activeTabIdx}},[_vm._t("default")],2)],1):_vm._e()};
var __vue_staticRenderFns__ = [];

  /* 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;
  /* style inject */
  
  /* style inject SSR */
  

  
  var VTabs = normalizeComponent.__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
  );

exports.default = VTabs;
