/**
 * tdesign v0.41.7
 * (c) 2022 tdesign
 * @license MIT
 */

import _typeof from '@babel/runtime/helpers/typeof';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { computed } from '@vue/composition-api';
import isString from 'lodash/isString';
import isFunction from 'lodash/isFunction';
import { getThRowspanAndColspan, getThList } from './useMultiHeader.js';
import useClassName from './useClassName.js';
import TEllipsis from '../ellipsis.js';
import '../../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import 'lodash/mergeWith';
import '../../config-provider/context.js';
import 'lodash/merge';
import '../../_common/js/global-config/default-config.js';
import '../../_common/js/global-config/locale/zh_CN.js';
import '../../config-provider/type.js';
import '../../_chunks/dep-37d5b9c4.js';
import 'lodash/debounce';
import '../../utils/render-tnode.js';
import 'vue';
import '../../utils/dom.js';
import 'raf';
import '../../utils/easing.js';
import '../../popup/index.js';
import '../../popup/popup.js';
import '@popperjs/core';
import '../../config.js';
import '../../utils/classnames.js';
import '../../utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import 'lodash/camelCase';
import '../../_common/js/utils/set-style.js';
import '../../popup/props.js';
import '../../popup/container.js';
import '../../utils/map-props.js';
import '../../utils/withInstall.js';
import 'lodash/capitalize';
import './style/index.js';
import '../../popup/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 renderTitle(h, 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(h, _ref, col, colIndex, ellipsisTitle, attach) {
    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;
    return h("div", {
      "class": classes
    }, [h("div", {
      "class": tableSortClasses.title
    }, [col.ellipsis && ellipsisTitle !== false && ellipsisTitle !== null ? h(TEllipsis, {
      "attrs": {
        "placement": "bottom-right",
        "attach": attach ? function () {
          return attach;
        } : void 0,
        "popupContent": content && function () {
          return content;
        },
        "popupProps": _typeof(ellipsisTitle) === "object" ? ellipsisTitle : void 0
      }
    }, [title]) : h("div", [title]), Boolean(sortIcon || filterIcon) && h("div", {
      "class": tableFilterClasses.iconWrap
    }, [sortIcon, filterIcon])])]);
  };

  return {
    thList: thList,
    isMultipleHeader: isMultipleHeader,
    spansAndLeafNodes: spansAndLeafNodes,
    renderTitleWidthIcon: renderTitleWidthIcon
  };
}

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