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

import { h as helper } from '../_chunks/dep-a4bd011a.js';
import _typeof from '@babel/runtime/helpers/typeof';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, ref, computed } from '@vue/composition-api';
import isFunction from 'lodash/isFunction';
import { getColumnFixedStyles } from './hooks/useFixed.js';
import useClassName from './hooks/useClassName.js';
import { useConfig } from '../config-provider/useConfig.js';
import { renderTitle } from './hooks/useTableHeader.js';
import TEllipsis from './ellipsis.js';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/get';
import 'lodash/debounce';
import '../_common/js/log/index.js';
import '../_common/js/log/log.js';
import '../_common/js/utils/getScrollbarWidth.js';
import '../_common/js/utils/helper.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../utils/dom.js';
import 'vue';
import 'raf';
import 'lodash/isString';
import '../utils/easing.js';
import '../config-provider/context.js';
import 'lodash/merge';
import 'lodash/mergeWith';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../config-provider/type.js';
import './hooks/useMultiHeader.js';
import '../utils/render-tnode.js';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../tooltip/index.js';
import '../tooltip/tooltip.js';
import '../tooltip/props.js';
import '../popup/props.js';
import '../popup/popup.js';
import '@popperjs/core';
import '../utils/helper.js';
import '../_common/js/utils/set-style.js';
import '../popup/container.js';
import '../config-provider/config-receiver.js';
import '../utils/mixins.js';
import '../utils/map-props.js';
import '../utils/withInstall.js';
import 'lodash/capitalize';
import './style/css.js';
import '../tooltip/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; }
var THead = defineComponent({
  name: "THead",
  props: {
    isFixedHeader: Boolean,
    rowAndColFixedPosition: Map,
    thWidthList: Object,
    bordered: Boolean,
    isMultipleHeader: Boolean,
    resizable: Boolean,
    spansAndLeafNodes: Object,
    thList: Array,
    columnResizeParams: Object
  },
  setup: function setup(props, _ref) {
    var slots = _ref.slots;
    var theadRef = ref();
    var classnames = useClassName();
    var tableHeaderClasses = classnames.tableHeaderClasses,
        tableBaseClass = classnames.tableBaseClass;

    var _useConfig = useConfig(),
        classPrefix = _useConfig.classPrefix;

    var theadClasses = computed(function () {
      var _ref2;

      return [tableHeaderClasses.header, (_ref2 = {}, _defineProperty(_ref2, tableHeaderClasses.fixed, props.isFixedHeader), _defineProperty(_ref2, tableBaseClass.bordered, props.bordered && props.isMultipleHeader), _defineProperty(_ref2, tableHeaderClasses.multipleHeader, props.isMultipleHeader), _ref2)];
    });
    return _objectSpread(_objectSpread({}, classnames), {}, {
      theadRef: theadRef,
      theadClasses: theadClasses,
      classPrefix: classPrefix,
      slots: slots
    });
  },
  render: function render(h) {
    var _this = this;

    var renderThNodeList = function renderThNodeList(h2, rowAndColFixedPosition, thWidthList) {
      var thBorderMap = /* @__PURE__ */new Map();
      var thRowspanAndColspan = _this.spansAndLeafNodes.rowspanAndColspanMap;
      return _this.thList.map(function (row, rowIndex) {
        var thRow = row.map(function (col, index) {
          var _ref3, _col$children;

          var rowspanAndColspan = thRowspanAndColspan.get(col);

          if (index === 0 && rowspanAndColspan.rowspan > 1) {
            for (var j = rowIndex + 1; j < rowIndex + rowspanAndColspan.rowspan; j++) {
              thBorderMap.set(_this.thList[j][0], true);
            }
          }

          var thStyles = getColumnFixedStyles(col, index, rowAndColFixedPosition, _this.tableColFixedClasses);
          var colParams = {
            col: col,
            colIndex: index,
            row: {},
            rowIndex: -1
          };
          var customClasses = isFunction(col.className) ? col.className(_objectSpread(_objectSpread({}, colParams), {}, {
            type: "th"
          })) : col.className;
          var thClasses = [thStyles.classes, customClasses, (_ref3 = {}, _defineProperty(_ref3, _this.tableHeaderClasses.thBordered, thBorderMap.get(col)), _defineProperty(_ref3, "".concat(_this.classPrefix, "-table__th-").concat(col.colKey), col.colKey), _defineProperty(_ref3, _this.tdAlignClasses[col.align], col.align && col.align !== "left"), _ref3)];
          var withoutChildren = !((_col$children = col.children) !== null && _col$children !== void 0 && _col$children.length);
          var width = withoutChildren && thWidthList !== null && thWidthList !== void 0 && thWidthList[col.colKey] ? "".concat(thWidthList === null || thWidthList === void 0 ? void 0 : thWidthList[col.colKey], "px") : void 0;

          var styles = _objectSpread(_objectSpread({}, thStyles.style || {}), {}, {
            width: width
          });

          var innerTh = renderTitle(h2, _this.slots, col, index);
          var resizeColumnListener = _this.resizable ? {
            mousedown: function mousedown(e) {
              var _this$columnResizePar, _this$columnResizePar2;

              return (_this$columnResizePar = _this.columnResizeParams) === null || _this$columnResizePar === void 0 ? void 0 : (_this$columnResizePar2 = _this$columnResizePar.onColumnMousedown) === null || _this$columnResizePar2 === void 0 ? void 0 : _this$columnResizePar2.call(_this$columnResizePar, e, col);
            },
            mousemove: function mousemove(e) {
              var _this$columnResizePar3, _this$columnResizePar4;

              return (_this$columnResizePar3 = _this.columnResizeParams) === null || _this$columnResizePar3 === void 0 ? void 0 : (_this$columnResizePar4 = _this$columnResizePar3.onColumnMouseover) === null || _this$columnResizePar4 === void 0 ? void 0 : _this$columnResizePar4.call(_this$columnResizePar3, e);
            }
          } : {};
          var content = isFunction(col.ellipsisTitle) ? col.ellipsisTitle(h2, {
            col: col,
            colIndex: index
          }) : void 0;
          return h("th", helper([{
            "key": col.colKey,
            "attrs": {
              "data-colkey": col.colKey
            },
            "class": thClasses,
            "style": styles
          }, {
            "attrs": _objectSpread({}, rowspanAndColspan)
          }, {}, {
            "on": resizeColumnListener
          }]), [h("div", {
            "class": _this.tableBaseClass.thCellInner
          }, [col.ellipsisTitle !== false && col.ellipsisTitle !== null ? h(TEllipsis, {
            "attrs": {
              "placement": "bottom",
              "attach": _this.theadRef ? function () {
                return _this.theadRef;
              } : void 0,
              "tooltipContent": content && function () {
                return content;
              },
              "tooltipProps": _typeof(col.ellipsisTitle) === "object" ? col.ellipsisTitle : void 0
            }
          }, [innerTh]) : innerTh])]);
        });
        return h("tr", {
          "key": rowIndex
        }, [thRow]);
      });
    };

    return h("thead", {
      "ref": "theadRef",
      "class": this.theadClasses
    }, [renderThNodeList(h, this.rowAndColFixedPosition, this.thWidthList)]);
  }
});

export { THead as default };
//# sourceMappingURL=thead.js.map
