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

import { _ as _defineProperty } from '../_chunks/dep-2db7b3ec.mjs';
import { _ as _slicedToArray } from '../_chunks/dep-84acf3c2.mjs';
import { defineComponent, toRefs, provide, createVNode, mergeProps } from 'vue';
import { i as isArray_1 } from '../_chunks/dep-b57180d0.mjs';
import { useTNodeJSX } from '../hooks/tnode.mjs';
import { usePrefixClass } from '../hooks/useConfig.mjs';
import useVModel from '../hooks/useVModel.mjs';
import _TabPanel from './tab-panel.mjs';
import TTabNav from './tab-nav.mjs';
import props from './props.mjs';
import '../_chunks/dep-255303ba.mjs';
import '../_chunks/dep-b8d7992c.mjs';
import '../_chunks/dep-eba0ea6e.mjs';
import '../_chunks/dep-5717e263.mjs';
import '../_chunks/dep-469b4ae0.mjs';
import '../_chunks/dep-a8bcacea.mjs';
import '../_chunks/dep-406cd044.mjs';
import '../_chunks/dep-42cc3015.mjs';
import '../_chunks/dep-c8d7b6b4.mjs';
import '../_chunks/dep-2bc37d52.mjs';
import '../_chunks/dep-3da99438.mjs';
import '../_chunks/dep-327559e8.mjs';
import '../_chunks/dep-b2235f26.mjs';
import '../_chunks/dep-8b989474.mjs';
import '../_chunks/dep-1372b2d3.mjs';
import '../_chunks/dep-9a85dac1.mjs';
import '../utils/render-tnode.mjs';
import '../_chunks/dep-888e80c4.mjs';
import '../_chunks/dep-334a4f6b.mjs';
import '../_chunks/dep-e5eb9f23.mjs';
import '../_chunks/dep-9fe2ef12.mjs';
import '../_chunks/dep-672e7d1a.mjs';
import '../_chunks/dep-4d7a675b.mjs';
import '../_chunks/dep-2e7f59b1.mjs';
import '../_chunks/dep-1434aa15.mjs';
import '../_chunks/dep-9262ee2f.mjs';
import '../_chunks/dep-876fb3ec.mjs';
import '../config-provider/useConfig.mjs';
import '../_chunks/dep-095107f7.mjs';
import '../_chunks/dep-c989dff3.mjs';
import '../_chunks/dep-9cf86cf1.mjs';
import '../_chunks/dep-bc1d737a.mjs';
import '../_chunks/dep-855db8bc.mjs';
import '../_chunks/dep-a87f3e4c.mjs';
import '../_chunks/dep-1e566bb5.mjs';
import '../_chunks/dep-42a19209.mjs';
import '../_chunks/dep-8d3e9aa3.mjs';
import '../_chunks/dep-40d69a9c.mjs';
import '../_chunks/dep-dcc83161.mjs';
import '../_chunks/dep-0fc02184.mjs';
import '../_chunks/dep-f1994936.mjs';
import '../_chunks/dep-345e1be3.mjs';
import '../_common/js/global-config/default-config.mjs';
import '../_common/js/global-config/locale/zh_CN.mjs';
import '../_chunks/dep-9888611c.mjs';
import '../_chunks/dep-697a1365.mjs';
import '../config-provider/type.mjs';
import '../hooks/useDestroyOnClose.mjs';
import './tab-panel-props.mjs';
import '../_chunks/dep-9b6cf76d.mjs';
import '../_chunks/dep-f709f709.mjs';
import '@ldesign/icons-vue-next';
import '../_common/js/tabs/base.mjs';
import '../hooks/useListener.mjs';
import '../hooks/useGlobalIcon.mjs';
import '../hooks/useDragSort.mjs';
import './tab-nav-item.mjs';
import '../hooks/useRipple.mjs';
import '../utils/set-style.mjs';
import '../hooks/useKeepAnimation.mjs';
import './tab-nav-bar.mjs';
import '../utils/helper.mjs';
import '../_chunks/dep-60fae668.mjs';
import '../_chunks/dep-78847b2e.mjs';
import '../_chunks/dep-ed5ebb35.mjs';
import '../_chunks/dep-3f21269a.mjs';

var _Tabs = defineComponent({
  name: "TTabs",
  props: props,
  setup: function setup(props2) {
    var COMPONENT_NAME = usePrefixClass("tabs");
    var classPrefix = usePrefixClass();
    var renderTNodeJSX = useTNodeJSX();
    var _toRefs = toRefs(props2),
      value = _toRefs.value,
      modelValue = _toRefs.modelValue;
    var _useVModel = useVModel(value, modelValue, props2.defaultValue || "", props2.onChange),
      _useVModel2 = _slicedToArray(_useVModel, 2),
      tabValue = _useVModel2[0],
      setTabValue = _useVModel2[1];
    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_1(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 createVNode("div", {
        "class": (_ref2 = {}, _defineProperty(_ref2, "".concat(classPrefix.value, "-tabs__header"), true), _defineProperty(_ref2, "".concat(classPrefix.value, "-is-").concat(props2.placement), true), _ref2),
        "style": {
          position: "relative"
        }
      }, [createVNode(TTabNav, mergeProps(tabNavProps, {
        "onDragSort": props2.onDragSort,
        "onChange": onTabChange,
        "onAdd": onTabAdd,
        "onRemove": onTabRemove
      }), null), 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 createVNode(_TabPanel, mergeProps(item, {
          "onRemove": onTabRemove
        }), null);
      });
      if (panels && panels.length) return createVNode("div", {
        "class": ["".concat(classPrefix.value, "-tabs__content")]
      }, [panels]);
    };
    return function () {
      return createVNode("div", {
        "class": [COMPONENT_NAME.value]
      }, [props2.placement !== "bottom" ? [renderHeader(), renderContent()] : [renderContent(), renderHeader()]]);
    };
  }
});

export { _Tabs as default };
//# sourceMappingURL=tabs.mjs.map
