/**
 * tdesign v0.39.1-alpha.1
 * (c) 2022 tdesign
 * @license MIT
 */

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 '../../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';

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) {
    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);
    return h("div", {
      "class": classes
    }, [h("div", {
      "class": tableSortClasses.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
