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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var vue = require('vue');
var isArray = require('lodash/isArray');
var hooks_tnode = require('../hooks/tnode.js');
var hooks_useConfig = require('../hooks/useConfig.js');
var hooks_useVModel = require('../hooks/useVModel.js');
var tabs_tabPanel = require('./tab-panel.js');
var tabs_tabNav = require('./tab-nav.js');
var tabs_props = require('./props.js');
require('lodash/isFunction');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../utils/render-tnode.js');
require('lodash/isEmpty');
require('lodash/isString');
require('lodash/isObject');
require('../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('../config-provider/context.js');
require('lodash/mergeWith');
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-f4db2590.js');
require('dayjs');
require('../hooks/useDestroyOnClose.js');
require('./tab-panel-props.js');
require('lodash/debounce');
require('@ldesign/icons-vue-next');
require('../_common/js/tabs/base.js');
require('../hooks/useListener.js');
require('../hooks/useGlobalIcon.js');
require('../hooks/useDragSort.js');
require('./tab-nav-item.js');
require('../hooks/useRipple.js');
require('../utils/set-style.js');
require('../hooks/useKeepAnimation.js');
require('./tab-nav-bar.js');
require('../utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('lodash/isUndefined');
require('lodash/isNull');
require('lodash/isNumber');

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

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);

var _Tabs = vue.defineComponent({
  name: "TTabs",
  props: tabs_props["default"],
  setup: function setup(props2) {
    var COMPONENT_NAME = hooks_useConfig.usePrefixClass("tabs");
    var classPrefix = hooks_useConfig.usePrefixClass();
    var renderTNodeJSX = hooks_tnode.useTNodeJSX();
    var _toRefs = vue.toRefs(props2),
      value = _toRefs.value,
      modelValue = _toRefs.modelValue;
    var _useVModel = hooks_useVModel["default"](value, modelValue, props2.defaultValue || "", props2.onChange),
      _useVModel2 = _slicedToArray__default["default"](_useVModel, 2),
      tabValue = _useVModel2[0],
      setTabValue = _useVModel2[1];
    vue.provide("tabs", {
      value: tabValue
    });
    var onTabAdd = function onTabAdd(context) {
      var _props2$onAdd;
      (_props2$onAdd = props2.onAdd) === null || _props2$onAdd === void 0 ? void 0 : _props2$onAdd.call(props2, {
        e: context.e
      });
    };
    var onTabChange = function onTabChange(value2) {
      setTabValue(value2);
    };
    var onTabRemove = function onTabRemove(_ref) {
      var e = _ref.e,
        value2 = _ref.value,
        index = _ref.index;
      props2.onRemove({
        value: value2,
        index: index,
        e: e
      });
    };
    var getSlotPanels = function getSlotPanels() {
      var content = renderTNodeJSX("default");
      if (!content) return [];
      content = content.map(function (item) {
        if (item.children && isArray__default["default"](item.children)) return item.children;
        return item;
      }).flat().filter(function (item) {
        return item.type.name === "TTabPanel";
      });
      return content;
    };
    var renderHeader = function renderHeader() {
      var _props2$list, _ref2;
      var panels = ((_props2$list = props2.list) !== null && _props2$list !== void 0 && _props2$list.length ? props2.list : getSlotPanels()) || [];
      var panelsData = panels.map(function (item) {
        var selfItem = item;
        if (item.props) {
          Object.keys(item.props).forEach(function (key) {
            selfItem[key] = item.props[key];
          });
        }
        return selfItem;
      });
      var tabNavProps = {
        theme: props2.theme,
        value: tabValue.value,
        size: props2.size,
        disabled: props2.disabled,
        placement: props2.placement,
        addable: props2.addable,
        panels: panelsData,
        dragSort: props2.dragSort
      };
      return vue.createVNode("div", {
        "class": (_ref2 = {}, _defineProperty__default["default"](_ref2, "".concat(classPrefix.value, "-tabs__header"), true), _defineProperty__default["default"](_ref2, "".concat(classPrefix.value, "-is-").concat(props2.placement), true), _ref2),
        "style": {
          position: "relative"
        }
      }, [vue.createVNode(tabs_tabNav["default"], vue.mergeProps(tabNavProps, {
        "onDragSort": props2.onDragSort,
        "onChange": onTabChange,
        "onAdd": onTabAdd,
        "onRemove": onTabRemove
      }), null), vue.createVNode("div", {
        "style": {
          position: "absolute",
          right: "0px",
          top: "0px",
          height: "100%",
          display: "flex",
          alignItems: "center"
        }
      }, [renderTNodeJSX("action")])]);
    };
    var renderContent = function renderContent() {
      var _props2$list2;
      var panels = getSlotPanels();
      if ((_props2$list2 = props2.list) !== null && _props2$list2 !== void 0 && _props2$list2.length) return props2.list.map(function (item) {
        return vue.createVNode(tabs_tabPanel["default"], vue.mergeProps(item, {
          "onRemove": onTabRemove
        }), null);
      });
      if (panels && panels.length) return vue.createVNode("div", {
        "class": ["".concat(classPrefix.value, "-tabs__content")]
      }, [panels]);
    };
    return function () {
      return vue.createVNode("div", {
        "class": [COMPONENT_NAME.value]
      }, [props2.placement !== "bottom" ? [renderHeader(), renderContent()] : [renderContent(), renderHeader()]]);
    };
  }
});

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