import "./index.css";
/* script */
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
import { componentMixin, createComponentName } from '../../utils/base';
const __vue_script__ = {
  name: createComponentName('tabs'),
  mixins: [componentMixin],

  provide() {
    return {
      rootTabs: this
    };
  },

  model: {
    prop: 'value',
    event: 'change'
  },
  props: {
    defaultValue: {
      type: [String, Number],
      default: ''
    },
    value: {
      type: [String, Number, undefined]
    },
    tabPosition: {
      type: String,
      default: 'top'
    },
    border: {
      type: Boolean,
      default: false
    }
  },

  data() {
    let value = '';

    if (this.$hasProp('value')) {
      value = this.value;
    } else if (this.$hasProp('defaultValue')) {
      value = this.defaultValue;
    }

    return {
      panels: [],
      currentValue: value,
      isMounted: false
    };
  },

  watch: {
    value(v) {
      this.currentValue = v;
    }

  },

  mounted() {
    this.isMounted = true;
  },

  methods: {
    addPanel(vm) {
      let children = vm;
      const childrenComponents = this.$slots.default.map(vnode => vnode.componentInstance);

      while (childrenComponents.indexOf(children) === -1) {
        if (children === this || children === this.$root) return;
        children = children.$parent;
      }

      const index = childrenComponents.indexOf(children);
      this.panels.splice(index, 0, vm);
    },

    getIndex(vm) {
      return this.panels.indexOf(vm);
    },

    removePanel(vm) {
      this.panels = this.panels.filter(panel => panel !== vm);
    },

    changeValue(value) {
      if (!this.$hasProp('value')) {
        this.currentValue = value;
      }

      this.$emit('change', value);
    }

  }
};
/* template */

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

  var _h = _vm.$createElement;

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

  return _c("div", {
    class: _vm.bem([_vm.tabPosition])
  }, [_c("div", {
    ref: "tabList",
    class: _vm.bem("tab-list")
  }, [_vm._l(_vm.panels, function (panel) {
    return [_c("div", {
      key: panel.name,
      class: _vm.bem("tab", {
        active: panel.active
      }),
      attrs: {
        "data-name": panel.name
      },
      on: {
        click: function ($event) {
          _vm.changeValue(panel.name);
        }
      }
    })];
  }), _vm._v(" "), _vm._t("extra")], 2), _vm._v(" "), _c("div", {
    class: _vm.bem("content"),
    attrs: {
      "data-name": _vm.currentValue
    }
  }, [_vm._t("default")], 2)]);
};

var __vue_staticRenderFns__ = [];
__vue_render__._withStripped = true;
/* 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;
/* component normalizer */

import __vue_normalize__ from '../../utils/vue-normalize-component.js';
/* style inject */

/* style inject SSR */

export default __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);