/**
 * ldesign v0.2.22
 * (c) 2022/12/7 16:21 built by swimly
 * @license MIT
 */

import { h as helper } from '../../../_chunks/dep-b0f1ed22.js';
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 { renderTitle } from '../hooks/useTableHeader.js';
import { formatClassNames } from '../utils.js';
import TEllipsis from './ellipsis.js';
import 'lodash/get';
import 'lodash/debounce';
import '../../../_chunks/dep-eaa95999.js';
import '../../../_chunks/dep-102361be.js';
import '../../../_chunks/dep-1a6bca30.js';
import '../../../utils/dom.js';
import 'vue';
import 'raf';
import 'lodash/isString';
import '../../../utils/easing.js';
import '../../config-provider/useConfig.js';
import '../../config-provider/context.js';
import 'lodash/merge';
import 'lodash/mergeWith';
import '../../../_chunks/dep-b4fd1955.js';
import '../hooks/useMultiHeader.js';
import '../../../utils/render-node.js';
import 'lodash';
import '../../tooltip/index.js';
import '../../../utils/map-props.js';
import '../../../utils/withInstall.js';
import 'lodash/capitalize';
import '../../../config.js';
import '../../tooltip/tooltip.js';
import '../../popup/props.js';
import '../../popup/popup.js';
import '@popperjs/core';
import '../../../_chunks/dep-c68dc4b6.js';
import '../../../utils/helper.js';
import 'lodash/camelCase';
import '../../config-provider/config-receiver.js';
import '../../../utils/mixins.js';
import '../../popup/container.js';
import '../../tooltip/props.js';
import 'lodash/isObject';

var THead = defineComponent({
  name: "THead",
  props: {
    ellipsisOverlayClassName: String,
    isFixedHeader: Boolean,
    rowAndColFixedPosition: Map,
    thWidthList: Object,
    bordered: Boolean,
    isMultipleHeader: Boolean,
    resizable: Boolean,
    spansAndLeafNodes: Object,
    thList: Array,
    columnResizeParams: Object
  },
  setup(props, _ref) {
    let {
      slots
    } = _ref;
    const theadRef = ref();
    const classnames = useClassName();
    const {
      tableHeaderClasses,
      tableBaseClass
    } = classnames;
    const theadClasses = computed(() => [tableHeaderClasses.header, {
      [tableHeaderClasses.fixed]: props.isFixedHeader,
      [tableBaseClass.bordered]: props.bordered && props.isMultipleHeader,
      [tableHeaderClasses.multipleHeader]: props.isMultipleHeader
    }]);
    const colspanSkipMap = computed(() => {
      const map = {};
      const list = props.thList[0];
      for (let i = 0, len = list.length; i < len; i++) {
        const item = list[i];
        if (item.colspan > 1) {
          for (let j = i + 1; j < i + item.colspan; j++) {
            if (list[j]) map[list[j].colKey] = true;
          }
        }
      }
      return map;
    });
    const getTableNode = thead => {
      let parent = thead;
      while (parent) {
        parent = parent.parentNode;
        if (parent?.classList?.contains(`${props.classPrefix}-table`)) break;
      }
      return parent;
    };
    return {
      ...classnames,
      colspanSkipMap,
      theadRef,
      theadClasses,
      slots,
      getTableNode
    };
  },
  render(h) {
    const renderThNodeList = (h2, rowAndColFixedPosition, thWidthList) => {
      const thBorderMap = /* @__PURE__ */new Map();
      const thRowspanAndColspan = this.spansAndLeafNodes.rowspanAndColspanMap;
      return this.thList.map((row, rowIndex) => {
        const thRow = row.map((col, index) => {
          if (this.colspanSkipMap[col.colKey]) return null;
          const rowspanAndColspan = thRowspanAndColspan.get(col);
          if (index === 0 && rowspanAndColspan.rowspan > 1) {
            for (let j = rowIndex + 1; j < rowIndex + rowspanAndColspan.rowspan; j++) thBorderMap.set(this.thList[j][0], true);
          }
          const thStyles = getColumnFixedStyles(col, index, rowAndColFixedPosition, this.tableColFixedClasses);
          const colParams = {
            col,
            colIndex: index,
            row: {},
            rowIndex: -1
          };
          const customClasses = formatClassNames(col.className, {
            ...colParams,
            type: "th"
          });
          const thClasses = [thStyles.classes, customClasses, {
            [this.tableHeaderClasses.thBordered]: thBorderMap.get(col),
            [`${this.classPrefix}-table__th-${col.colKey}`]: col.colKey,
            [this.tdAlignClasses[col.align]]: col.align && col.align !== "left"
          }];
          const withoutChildren = !col.children?.length;
          const width = withoutChildren && thWidthList?.[col.colKey] ? `${thWidthList?.[col.colKey]}px` : void 0;
          const styles = {
            ...(thStyles.style || {}),
            width
          };
          const innerTh = renderTitle(h2, this.slots, col, index);
          const resizeColumnListener = this.resizable ? {
            mousedown: e => this.columnResizeParams?.onColumnMousedown?.(e, col),
            mousemove: e => this.columnResizeParams?.onColumnMouseover?.(e, col)
          } : {};
          const content = isFunction(col.ellipsisTitle) ? col.ellipsisTitle(h2, {
            col,
            colIndex: index
          }) : void 0;
          const isEllipsis = col.ellipsisTitle !== void 0 ? Boolean(col.ellipsisTitle) : Boolean(col.ellipsis);
          const attrs = (isFunction(col.attrs) ? col.attrs({
            ...colParams,
            type: "th"
          }) : col.attrs) || {};
          if (col.colspan > 1) attrs.colspan = col.colspan;
          return h("th", helper([{
            "key": col.colKey,
            "attrs": {
              "data-colkey": col.colKey
            },
            "class": thClasses,
            "style": styles
          }, {
            "attrs": {
              ...attrs,
              ...rowspanAndColspan
            }
          }, {}, {
            "on": resizeColumnListener
          }]), [h("div", {
            "class": this.tableBaseClass.thCellInner
          }, [isEllipsis ? h(TEllipsis, {
            "attrs": {
              "placement": "bottom",
              "attach": this.theadRef ? () => this.getTableNode(this.theadRef) : void 0,
              "tooltipContent": content && (() => content),
              "tooltipProps": typeof col.ellipsisTitle === "object" ? col.ellipsisTitle : void 0,
              "overlayClassName": this.ellipsisOverlayClassName,
              "classPrefix": this.classPrefix
            }
          }, [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
