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

'use strict';

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

var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var VueCompositionAPI = require('@vue/composition-api');
var isString = require('lodash/isString');
var isFunction = require('lodash/isFunction');
var table_hooks_useMultiHeader = require('./useMultiHeader.js');
var table_hooks_useClassName = require('./useClassName.js');
require('../../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('lodash/mergeWith');
require('../../config-provider/context.js');
require('lodash/merge');
require('../../_common/js/global-config/default-config.js');
require('../../_common/js/global-config/locale/zh_CN.js');

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

var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var isString__default = /*#__PURE__*/_interopDefaultLegacy(isString);
var isFunction__default = /*#__PURE__*/_interopDefaultLegacy(isFunction);

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__default["default"](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__default["default"](col.title)) {
    return col.title(h, params);
  }

  if (isString__default["default"](col.title) && slots[col.title]) {
    return slots[col.title](params);
  }

  if (isFunction__default["default"](col.render)) {
    return col.render(h, _objectSpread(_objectSpread({}, params), {}, {
      type: "title",
      row: {},
      rowIndex: -1
    })) || col.title;
  }

  return col.title;
}
function useTableHeader(props) {
  var _useClassName = table_hooks_useClassName["default"](),
      tableSortClasses = _useClassName.tableSortClasses,
      tableFilterClasses = _useClassName.tableFilterClasses;

  var spansAndLeafNodes = VueCompositionAPI.computed(function () {
    return table_hooks_useMultiHeader.getThRowspanAndColspan(props.columns);
  });
  var thList = VueCompositionAPI.computed(function () {
    return table_hooks_useMultiHeader.getThList(props.columns);
  });
  var isMultipleHeader = VueCompositionAPI.computed(function () {
    return thList.value.length > 1;
  });

  var renderTitleWidthIcon = function renderTitleWidthIcon(h, _ref) {
    var _classes;

    var _ref2 = _slicedToArray__default["default"](_ref, 3),
        title = _ref2[0],
        sortIcon = _ref2[1],
        filterIcon = _ref2[2];

    var classes = (_classes = {}, _defineProperty__default["default"](_classes, tableSortClasses.sortable, sortIcon), _defineProperty__default["default"](_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
  };
}

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