/**
 * ldesign v0.4.6
 * (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 VueCompositionAPI = require('@vue/composition-api');
var isString = require('lodash/isString');
var isFunction = require('lodash/isFunction');
var table_ellipsis = require('../ellipsis.js');
var _common_js_log_log = require('../../_common/js/log/log.js');
var table_hooks_useClassName = require('./useClassName.js');
var table_hooks_useMultiHeader = require('./useMultiHeader.js');
require('../../_chunks/dep-c3e1ffac.js');
require('lodash/debounce');
require('../../utils/render-tnode.js');
require('vue');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../../utils/dom.js');
require('raf');
require('../../utils/easing.js');
require('../../tooltip/index.js');
require('../../utils/map-props.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('../../utils/withInstall.js');
require('lodash/capitalize');
require('../../tooltip/tooltip.js');
require('../../popup/props.js');
require('../../popup/popup.js');
require('@popperjs/core');
require('../../utils/helper.js');
require('../../_common/js/utils/set-style.js');
require('../../config-provider/config-receiver.js');
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');
require('../../_chunks/dep-7c884501.js');
require('dayjs');
require('../../utils/mixins.js');
require('../../utils/event.js');
require('../../popup/container.js');
require('../../popup/utils.js');
require('../../popup/trigger.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 _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 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]) {
    if (col.colKey === col.title) {
      _common_js_log_log["default"].error("Table", ["both colKey '".concat(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, _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, 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(h, {
      col: col,
      colIndex: colIndex
    }) : void 0;
    var isEllipsis = ellipsisTitle !== void 0 ? Boolean(ellipsisTitle) : Boolean(col.ellipsis);
    return h("div", {
      "class": classes
    }, [h("div", {
      "class": tableSortClasses.title
    }, [isEllipsis ? h(table_ellipsis["default"], {
      "attrs": {
        "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
      }
    }, [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
