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

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import { defineComponent, toRefs, provide, createVNode, mergeProps } from 'vue';
import isArray from 'lodash/isArray';
import { useTNodeJSX } from '../hooks/tnode.js';
import { usePrefixClass } from '../hooks/useConfig.js';
import useVModel from '../hooks/useVModel.js';
import _TabPanel from './tab-panel.js';
import TTabNav from './tab-nav.js';
import props from './props.js';
import 'lodash/isFunction';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../utils/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/isString';
import 'lodash/isObject';
import '../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import '../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import '../_chunks/dep-e041f5b0.js';
import 'dayjs';
import '../hooks/useDestroyOnClose.js';
import './tab-panel-props.js';
import 'lodash/debounce';
import '@ldesign/icons-vue-next';
import '../_common/js/tabs/base.js';
import '../hooks/useListener.js';
import '../hooks/useGlobalIcon.js';
import '../hooks/useDragSort.js';
import './tab-nav-item.js';
import '../hooks/useRipple.js';
import '../utils/set-style.js';
import '../hooks/useKeepAnimation.js';
import './tab-nav-bar.js';
import '../utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import 'lodash/isUndefined';
import 'lodash/isNull';
import 'lodash/isNumber';

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(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.js.map
