/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

'use strict';

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

var helper = require('../_chunks/dep-c3e1ffac.js');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var Vue = require('vue');
var kebabCase = require('lodash/kebabCase');
var utils_event = require('../utils/event.js');
var configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_mixins = require('../utils/mixins.js');
var tabs_props = require('./props.js');
var tabs_tabPanel = require('./tab-panel.js');
var tabs_tabNav = require('./tab-nav.js');
require('../utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/camelCase');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('../_chunks/dep-7c884501.js');
require('dayjs');
require('../utils/render-tnode.js');
require('@vue/composition-api');
require('../hooks/useDestroyOnClose.js');
require('./tab-panel-props.js');
require('lodash/debounce');
require('@ldesign/icons-vue');
require('./tab-nav-item.js');
require('../utils/ripple.js');
require('../_common/js/utils/set-style.js');
require('../config.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);
var kebabCase__default = /*#__PURE__*/_interopDefaultLegacy(kebabCase);

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var classPrefixMixins = configProvider_configReceiver.getClassPrefixMixins("tabs");
var _Tabs = utils_mixins["default"](Vue__default["default"], classPrefixMixins).extend(_objectSpread(_objectSpread({
  name: "TTabs",
  model: {
    prop: "value",
    event: "change"
  },
  components: {
    TTabPanel: tabs_tabPanel["default"],
    TTabNav: tabs_tabNav["default"]
  }
}, {
  listPanels: null
}), {}, {
  props: _objectSpread({}, tabs_props["default"]),
  provide: function provide() {
    return {
      parent: this
    };
  },
  data: function data() {
    return {
      panels: []
    };
  },
  watch: {
    list: {
      handler: function handler() {
        this.listPanels = this.createListPanels();
      },
      deep: true
    }
  },
  mounted: function mounted() {
    this.updatePanels();
  },
  updated: function updated() {
    var _this = this;
    this.$nextTick(function () {
      _this.updatePanels();
    });
  },
  methods: {
    updatePanels: function updatePanels() {
      var _this2 = this;
      var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
        _ref$force = _ref.force,
        force = _ref$force === void 0 ? false : _ref$force;
      if (!this.listPanels) {
        this.panels = this.panels || [];
        return;
      }
      var newPanels = this.listPanels.map(function (panel) {
        return panel.componentInstance;
      }).filter(Boolean).filter(function (child) {
        var _child$$vnode;
        return kebabCase__default["default"](child === null || child === void 0 ? void 0 : (_child$$vnode = child.$vnode) === null || _child$$vnode === void 0 ? void 0 : _child$$vnode.tag).endsWith("t-tab-panel");
      });
      var isUnchanged = function isUnchanged() {
        return newPanels.length === _this2.panels.length && _this2.panels.every(function (panel, index) {
          return panel === newPanels[index];
        });
      };
      if (isUnchanged() && !force) return;
      this.panels = newPanels;
    },
    onAddTab: function onAddTab(e) {
      utils_event.emitEvent(this, "add", {
        e: e
      });
    },
    onChangeTab: function onChangeTab(value) {
      utils_event.emitEvent(this, "change", value);
    },
    onRemoveTab: function onRemoveTab(_ref2) {
      var e = _ref2.e,
        value = _ref2.value,
        index = _ref2.index;
      var panel = this.panels[index];
      var eventData = {
        value: value,
        index: index,
        e: e
      };
      utils_event.emitEvent(this, "remove", eventData);
      if (!panel) return;
      utils_event.emitEvent(panel, "remove", eventData);
    },
    renderHeader: function renderHeader() {
      var _ref3;
      var h = this.$createElement;
      var tabNavProps = {
        theme: this.theme,
        value: this.value,
        size: this.size,
        disabled: this.disabled,
        placement: this.placement,
        addable: this.addable,
        panels: this.panels
      };
      return h("div", {
        "class": (_ref3 = {}, _defineProperty__default["default"](_ref3, "".concat(this.componentName, "__header"), true), _defineProperty__default["default"](_ref3, "".concat(this.classPrefix, "-is-").concat(this.placement), true), _ref3)
      }, [h(tabs_tabNav["default"], helper.helper([{}, {
        "props": tabNavProps
      }, {
        "on": {
          "change": this.onChangeTab,
          "add": this.onAddTab,
          "remove": this.onRemoveTab
        }
      }]))]);
    },
    createListPanels: function createListPanels() {
      var h = this.$createElement;
      return this.list.map(function (item) {
        return h(tabs_tabPanel["default"], helper.helper([{}, {
          "props": _objectSpread({}, item)
        }]));
      });
    },
    renderList: function renderList() {
      if (!this.listPanels) return this.createListPanels();
      return this.listPanels;
    },
    renderContent: function renderContent() {
      var _this$$scopedSlots$de, _this$$scopedSlots;
      var h = this.$createElement;
      this.listPanels = this.list ? this.renderList() : ((_this$$scopedSlots$de = (_this$$scopedSlots = this.$scopedSlots)["default"]) === null || _this$$scopedSlots$de === void 0 ? void 0 : _this$$scopedSlots$de.call(_this$$scopedSlots, {})) || [];
      return h("div", {
        "class": ["".concat(this.componentName, "__content")]
      }, [this.listPanels]);
    }
  },
  render: function render() {
    var h = arguments[0];
    return h("div", {
      "class": this.componentName
    }, [this.placement !== "bottom" ? [this.renderHeader(), this.renderContent()] : [this.renderContent(), this.renderHeader()]]);
  }
}));

exports["default"] = _Tabs;
//# sourceMappingURL=tabs.js.map
