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

'use strict';

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

var _typeof = require('@babel/runtime/helpers/typeof');
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var isString = require('lodash/isString');
var isFunction = require('lodash/isFunction');
var table_ellipsis = require('../ellipsis.js');
var table_hooks_useClassName = require('./useClassName.js');
var table_hooks_useMultiHeader = require('./useMultiHeader.js');
require('lodash/debounce');
require('../../utils/render-tnode.js');
require('lodash/isEmpty');
require('lodash/isObject');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../../utils/dom.js');
require('../../_chunks/dep-f4db2590.js');
require('lodash/isArray');
require('../../utils/easing.js');
require('../../tooltip/index.js');
require('../../utils/withInstall.js');
require('../../tooltip/tooltip.js');
require('lodash/omit');
require('../../popup/props.js');
require('../../popup/index.js');
require('../../popup/popup.js');
require('@popperjs/core');
require('../../hooks/useConfig.js');
require('../../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('../../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('../../_common/js/global-config/default-config.js');
require('../../_common/js/global-config/locale/zh_CN.js');
require('dayjs');
require('../../_common/js/utils/set-style.js');
require('../../hooks/useVModel.js');
require('../../popup/container.js');
require('@babel/runtime/helpers/toConsumableArray');
require('lodash/isUndefined');
require('../../hooks/useResizeObserver.js');
require('../../hooks/tnode.js');
require('../../tooltip/util.js');
require('../../tooltip/props.js');

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

var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
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 _isSlot(s) {
  return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !vue.isVNode(s);
}
function renderTitle(slots, col, index) {
  var params = {
    col: col,
    colIndex: index
  };
  if (isFunction__default["default"](col.title)) return col.title(vue.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(vue.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 = vue.computed(function () {
    return table_hooks_useMultiHeader.getThRowspanAndColspan(props.columns);
  });
  var thList = vue.computed(function () {
    return table_hooks_useMultiHeader.getThList(props.columns);
  });
  var isMultipleHeader = vue.computed(function () {
    return thList.value.length > 1;
  });
  var renderTitleWidthIcon = function renderTitleWidthIcon(_ref, col, colIndex, ellipsisTitle, attach, extra) {
    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);
    var content = isFunction__default["default"](ellipsisTitle) ? ellipsisTitle(vue.h, {
      col: col,
      colIndex: colIndex
    }) : void 0;
    var isEllipsis = ellipsisTitle !== void 0 ? Boolean(ellipsisTitle) : Boolean(col.ellipsis);
    return vue.createVNode("div", {
      "class": classes
    }, [vue.createVNode("div", {
      "class": tableSortClasses.title
    }, [isEllipsis ? vue.createVNode(table_ellipsis["default"], {
      "placement": "bottom",
      "attach": props.attach || (attach ? function () {
        return attach;
      } : void 0),
      "tooltipContent": content && function () {
        return content;
      },
      "tooltipProps": _typeof__default["default"](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];
      }
    }) : vue.createVNode("div", null, [title]), Boolean(sortIcon || filterIcon) && vue.createVNode("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
