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

import _typeof from '@babel/runtime/helpers/typeof';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { isVNode, h, computed, createVNode } from 'vue';
import isString from 'lodash/isString';
import isFunction from 'lodash/isFunction';
import TEllipsis from '../ellipsis.js';
import useClassName from './useClassName.js';
import { getThRowspanAndColspan, getThList } from './useMultiHeader.js';
import 'lodash/debounce';
import '../../utils/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/isObject';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../../utils/dom.js';
import '../../_chunks/dep-2e5d8948.js';
import 'lodash/isArray';
import '../../utils/easing.js';
import '../../tooltip/index.js';
import '../../utils/withInstall.js';
import '../../tooltip/tooltip.js';
import 'lodash/omit';
import '../../popup/props.js';
import '../../popup/index.js';
import '../../popup/popup.js';
import '@popperjs/core';
import '../../hooks/index.js';
import '../../hooks/icon.js';
import '../../hooks/slot.js';
import '../../hooks/tnode.js';
import '../../hooks/useConfig.js';
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 'dayjs';
import '../../_chunks/dep-4580aabe.js';
import '../../config-provider/type.js';
import '../../hooks/useCommonClassName.js';
import '../../hooks/useDefaultValue.js';
import '../../hooks/useDestroyOnClose.js';
import '../../hooks/useKeepAnimation.js';
import '../../hooks/useRipple.js';
import '../../utils/set-style.js';
import '../../hooks/useVirtualScroll.js';
import '../../hooks/useVModel.js';
import '../../_common/js/utils/set-style.js';
import '../../popup/container.js';
import '@babel/runtime/helpers/toConsumableArray';
import '../../hooks/useResizeObserver.js';
import '../../popup/style';
import '../../popup/type.js';
import '../../tooltip/util.js';
import '../../tooltip/props.js';
import '../../tooltip/style';
import '../../tooltip/type.js';

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(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; }
function _isSlot(s) {
  return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !isVNode(s);
}
function renderTitle(slots, col, index) {
  var params = {
    col: col,
    colIndex: index
  };
  if (isFunction(col.title)) return col.title(h, params);
  if (isString(col.title) && slots[col.title]) return slots[col.title](params);
  if (isFunction(col.render)) {
    return col.render(h, _objectSpread(_objectSpread({}, params), {}, {
      type: "title",
      row: {},
      rowIndex: -1
    })) || col.title;
  }
  return col.title;
}
function useTableHeader(props) {
  var _useClassName = useClassName(),
    tableSortClasses = _useClassName.tableSortClasses,
    tableFilterClasses = _useClassName.tableFilterClasses;
  var spansAndLeafNodes = computed(function () {
    return getThRowspanAndColspan(props.columns);
  });
  var thList = computed(function () {
    return getThList(props.columns);
  });
  var isMultipleHeader = computed(function () {
    return thList.value.length > 1;
  });
  var renderTitleWidthIcon = function renderTitleWidthIcon(_ref, col, colIndex, ellipsisTitle, attach, extra) {
    var _classes;
    var _ref2 = _slicedToArray(_ref, 3),
      title = _ref2[0],
      sortIcon = _ref2[1],
      filterIcon = _ref2[2];
    var classes = (_classes = {}, _defineProperty(_classes, tableSortClasses.sortable, sortIcon), _defineProperty(_classes, tableFilterClasses.filterable, filterIcon), _classes);
    var content = isFunction(ellipsisTitle) ? ellipsisTitle(h, {
      col: col,
      colIndex: colIndex
    }) : void 0;
    var isEllipsis = ellipsisTitle !== void 0 ? Boolean(ellipsisTitle) : Boolean(col.ellipsis);
    return createVNode("div", {
      "class": classes
    }, [createVNode("div", {
      "class": tableSortClasses.title
    }, [isEllipsis ? createVNode(TEllipsis, {
      "placement": "bottom",
      "attach": props.attach || (attach ? function () {
        return attach;
      } : void 0),
      "tooltipContent": content && function () {
        return 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
    }, _isSlot(title) ? title : {
      "default": function _default() {
        return [title];
      }
    }) : createVNode("div", null, [title]), Boolean(sortIcon || filterIcon) && createVNode("div", {
      "class": tableFilterClasses.iconWrap
    }, [sortIcon, filterIcon])])]);
  };
  return {
    thList: thList,
    isMultipleHeader: isMultipleHeader,
    spansAndLeafNodes: spansAndLeafNodes,
    renderTitleWidthIcon: renderTitleWidthIcon
  };
}

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