/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

import { computed } from '@vue/composition-api';
import isString from 'lodash/isString';
import isFunction from 'lodash/isFunction';
import { l as log } from '../../../_chunks/dep-70c789e5.js';
import TEllipsis from '../core/ellipsis.js';
import useClassName from './useClassName.js';
import { getThRowspanAndColspan, getThList } from './useMultiHeader.js';
import '../../../_chunks/dep-5210251b.js';
import '../../../_chunks/dep-29915b8e.js';
import 'lodash/debounce';
import '../../../utils/render-node.js';
import 'vue';
import 'lodash';
import '../../../utils/dom.js';
import 'raf';
import '../../../utils/easing.js';
import '../../tooltip/index.js';
import '../../../utils/map-props.js';
import '../../../utils/with-install.js';
import '../../../config.js';
import '../../tooltip/tooltip.js';
import '../../popup/props.js';
import '../../popup/popup.js';
import '@popperjs/core';
import '../../../_chunks/dep-cf772670.js';
import '../../../utils/helper.js';
import 'lodash/camelCase';
import '../../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import '../../config-provider/context.js';
import '../../../_chunks/dep-def4c2ce.js';
import '../../../utils/mixins.js';
import '../../popup/container.js';
import '../../tooltip/props.js';
import '../../config-provider/useConfig.js';

function renderTitle(h, slots, col, index) {
  const params = {
    col,
    colIndex: index
  };
  if (isFunction(col.title)) return col.title(h, params);
  if (isString(col.title) && slots[col.title]) {
    if (col.colKey === col.title) {
      log.error("Table", [`both colKey '${col.colKey}' and title have the same slot name`, "please set a different slot name for col and title."].join(", "));
    }
    return slots[col.title](params);
  }
  if (isFunction(col.render)) {
    return col.render(h, {
      ...params,
      type: "title",
      row: {},
      rowIndex: -1
    }) || col.title;
  }
  return col.title;
}
function useTableHeader(props) {
  const {
    tableSortClasses,
    tableFilterClasses
  } = useClassName();
  const spansAndLeafNodes = computed(() => getThRowspanAndColspan(props.columns));
  const thList = computed(() => getThList(props.columns));
  const isMultipleHeader = computed(() => thList.value.length > 1);
  const renderTitleWidthIcon = (h, _ref, col, colIndex, ellipsisTitle, attach, extra) => {
    let [title, sortIcon, filterIcon] = _ref;
    const classes = {
      [tableSortClasses.sortable]: sortIcon,
      [tableFilterClasses.filterable]: filterIcon
    };
    const content = isFunction(ellipsisTitle) ? ellipsisTitle(h, {
      col,
      colIndex
    }) : void 0;
    const isEllipsis = ellipsisTitle !== void 0 ? Boolean(ellipsisTitle) : Boolean(col.ellipsis);
    return h("div", {
      "class": classes
    }, [h("div", {
      "class": tableSortClasses.title
    }, [isEllipsis ? h(TEllipsis, {
      "attrs": {
        "placement": "bottom",
        "attach": attach ? () => attach : void 0,
        "tooltipContent": content && (() => content),
        "tooltipProps": typeof ellipsisTitle === "object" ? ellipsisTitle : void 0,
        "classPrefix": extra === null || extra === void 0 ? void 0 : extra.classPrefix,
        "overlayClassName": extra === null || extra === void 0 ? void 0 : extra.ellipsisOverlayClassName
      }
    }, [title]) : h("div", [title]), Boolean(sortIcon || filterIcon) && h("div", {
      "class": tableFilterClasses.iconWrap
    }, [sortIcon, filterIcon])])]);
  };
  return {
    thList,
    isMultipleHeader,
    spansAndLeafNodes,
    renderTitleWidthIcon
  };
}

export { useTableHeader as default, renderTitle };
//# sourceMappingURL=useTableHeader.js.map
