/**
 * ------------------------------------------------------------
 * KLTab       子选项卡
 * ------------------------------------------------------------
 */

const Component = require('../../../../ui-base/component');
const _ = require('../../../../ui-base/_');
const template = require('./index.html');
const KLTabs = require('../index');

/**
 * @class KLTab
 * @extend Component
 * @param {object}        [options.data]                      = 绑定属性
 * @param {object}        [options.data.title='']             => 标题
 * @param {string}        [options.data.key=null]             => key 标识
 */
const KLTab = Component.extend({
  name: 'kl-tab',
  template: _.compressHtml(template),
  /**
     * @protected
     */
  config() {
    _.extend(this.data, {
      title: '',
    });
    this.supr();

    if (this.$outer && this.$outer instanceof KLTabs) {
      this.$outer.data.tabs.push(this);
    }

    if (!this.$outer.data.selected) this.$outer.data.selected = this;

    this._setDefaultTab();
  },

  _setDefaultTab() {
    const defaultKey = this.$outer.data.defaultKey;
    const key = this.data.key;

    if (!!defaultKey && !!key && `${defaultKey}` === `${key}`) {
      this.$outer.data.selected = this;
    }
  },
});

module.exports = KLTab;

@@ -990,16 +990,202 @@
 ltTab();
+%0A%0A    this.$on('destroy', function () %7B%0A      const index = this.$outer.data.tabs.indexOf(this);%0A      if (index !== -1) %7B%0A        this.$outer.data.tabs.splice(index, 1);%0A      %7D%0A    %7D);
 %0A  %7D,%0A%0A 

fix #372