'use strict';

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

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

var script = {
  name: 'VTabs',
  provide: function provide() {
    return {
      addTab: this.addTab,
      removeTab: this.removeTab
    };
  },
  data: function data() {
    return {
      activeTabIdx: 0,
      tabs: []
    };
  },
  computed: {
    vTabsCssClass: function vTabsCssClass() {
      return ThemeMixin._objectSpread2({}, this.themeCssClass, {
        'v-tabs': true
      });
    }
  },
  methods: {
    addTab: function addTab(tab) {
      this.tabs = this.tabs.concat(tab);
    },
    removeTab: function removeTab(tab) {
      var tabIdx = this.tabs.indexOf(tab);
      if (tabIdx === -1) return;
      this.tabs.splice(tabIdx, 1);
    }
  },
  mounted: function mounted() {
    this.addTab = this.addTab.bind(this);
  },
  mixins: [ThemeMixin.ThemeMixin],
  renderHeader: function renderHeader(h, ctx) {
    var controls = ctx.$slots.default.filter(function ($el) {
      return !!$el.tag;
    }).map(function ($el, i) {
      var componentProps = $el.componentOptions.propsData || {};
      var componentAttrs = $el.data.attrs || {};
      return h('button', {
        class: {
          'v-tabs-control': true,
          'is-active': ctx.activeTabIdx === i
        },
        attrs: componentAttrs,
        on: {
          click: function click() {
            if (ctx.activeTabIdx === i) return; // eslint-disable-next-line

            ctx.activeTabIdx = i;
          }
        }
      }, componentProps.label);
    });
    return h('section', {
      class: 'v-tabs-controls'
    }, controls);
  },
  renderContent: function renderContent(h, ctx) {
    var targetTab = ctx.tabs[ctx.activeTabIdx];
    if (!targetTab) return null;
    return h('section', {
      class: 'v-tabs-content'
    }, targetTab.$slots.default);
  },
  render: function render(h) {
    var isTabsExists = this.$slots.default.length > 0;
    return h('div', {
      class: this.vTabsCssClass
    }, isTabsExists && [this.$slots.default, this.$options.renderHeader(h, this), this.$options.renderContent(h, this)]);
  }
};

/* script */
const __vue_script__ = script;

/* template */

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

  
  var VTabs = normalizeComponent.__vue_normalize__(
    {},
    __vue_inject_styles__,
    __vue_script__,
    __vue_scope_id__,
    __vue_is_functional_template__,
    __vue_module_identifier__,
    undefined,
    undefined
  );

exports.default = VTabs;
