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

'use strict';

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

var VueCompositionAPI = require('@vue/composition-api');
var isString = require('lodash/isString');
var isFunction = require('lodash/isFunction');
var log = require('../../../chunks/log.js');
var components_table_core_ellipsis = require('../core/ellipsis.js');
var components_table_hooks_useClassName = require('./useClassName.js');
var components_table_hooks_useMultiHeader = require('./useMultiHeader.js');
require('../../../chunks/_commonjsHelpers-2e6815bd.js');
require('../../../chunks/helper.js');
require('lodash/debounce');
require('../../../utils/render-node.js');
require('vue');
require('lodash');
require('../../../utils/dom.js');
require('raf');
require('../../../utils/easing.js');
require('../../tooltip/index.js');
require('../../../utils/map-props.js');
require('../../../utils/with-install.js');
require('../../../config.js');
require('../../tooltip/tooltip.js');
require('../../popup/props.js');
require('../../popup/popup.js');
require('@popperjs/core');
require('../../../chunks/set-style.js');
require('../../../utils/helper.js');
require('lodash/camelCase');
require('../../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../../config-provider/context.js');
require('../../../chunks/zh_CN.js');
require('../../../utils/mixins.js');
require('../../popup/container.js');
require('../../tooltip/props.js');
require('../../config-provider/useConfig.js');

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

var isString__default = /*#__PURE__*/_interopDefaultLegacy(isString);
var isFunction__default = /*#__PURE__*/_interopDefaultLegacy(isFunction);

function renderTitle(h, slots, col, index) {
  const params = {
    col,
    colIndex: index
  };
  if (isFunction__default["default"](col.title)) return col.title(h, params);
  if (isString__default["default"](col.title) && slots[col.title]) {
    if (col.colKey === col.title) {
      log.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__default["default"](col.render)) {
    return col.render(h, {
      ...params,
      type: "title",
      row: {},
      rowIndex: -1
    }) || col.title;
  }
  return col.title;
}
function useTableHeader(props) {
  const {
    tableSortClasses,
    tableFilterClasses
  } = components_table_hooks_useClassName["default"]();
  const spansAndLeafNodes = VueCompositionAPI.computed(() => components_table_hooks_useMultiHeader.getThRowspanAndColspan(props.columns));
  const thList = VueCompositionAPI.computed(() => components_table_hooks_useMultiHeader.getThList(props.columns));
  const isMultipleHeader = VueCompositionAPI.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__default["default"](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(components_table_core_ellipsis["default"], {
      "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
  };
}

exports["default"] = useTableHeader;
exports.renderTitle = renderTitle;
//# sourceMappingURL=useTableHeader.js.map
