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

'use strict';

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

var helper = require('../_chunks/dep-99705d51.js');
var _typeof = require('@babel/runtime/helpers/typeof');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var VueCompositionAPI = require('@vue/composition-api');
var isFunction = require('lodash/isFunction');
var table_hooks_useFixed = require('./hooks/useFixed.js');
var table_hooks_useClassName = require('./hooks/useClassName.js');
var configProvider_useConfig = require('../config-provider/useConfig.js');
var table_hooks_useTableHeader = require('./hooks/useTableHeader.js');
var table_ellipsis = require('./ellipsis.js');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/get');
require('../_common/js/log/log.js');
require('../_common/js/utils/getScrollbarWidth.js');
require('../utils/dom.js');
require('vue');
require('raf');
require('lodash/isString');
require('../utils/easing.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');
require('./hooks/useMultiHeader.js');
require('lodash/debounce');
require('../utils/render-tnode.js');
require('../popup/index.js');
require('../popup/popup.js');
require('@popperjs/core');
require('../config.js');
require('../utils/classnames.js');
require('../utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('lodash/camelCase');
require('../_common/js/utils/set-style.js');
require('../popup/props.js');
require('../popup/container.js');
require('../utils/map-props.js');
require('../utils/withInstall.js');
require('lodash/capitalize');

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

var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
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; }
var THead = VueCompositionAPI.defineComponent({
  name: "THead",
  props: {
    isFixedHeader: Boolean,
    rowAndColFixedPosition: Map,
    thWidthList: Object,
    bordered: Boolean,
    isMultipleHeader: Boolean,
    allowResizeColumnWidth: Boolean,
    spansAndLeafNodes: Object,
    thList: Array,
    columnResizeParams: Object
  },
  setup: function setup(props, _ref) {
    var slots = _ref.slots;
    var theadRef = VueCompositionAPI.ref();
    var classnames = table_hooks_useClassName["default"]();
    var tableHeaderClasses = classnames.tableHeaderClasses,
        tableBaseClass = classnames.tableBaseClass;

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

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

      return [tableHeaderClasses.header, (_ref2 = {}, _defineProperty__default["default"](_ref2, tableHeaderClasses.fixed, props.isFixedHeader), _defineProperty__default["default"](_ref2, tableBaseClass.bordered, props.bordered && props.isMultipleHeader), _defineProperty__default["default"](_ref2, tableHeaderClasses.multipleHeader, props.isMultipleHeader), _ref2)];
    });
    var _props$columnResizePa = props.columnResizeParams,
        onColumnMouseover = _props$columnResizePa.onColumnMouseover,
        onColumnMousedown = _props$columnResizePa.onColumnMousedown;
    return _objectSpread(_objectSpread({}, classnames), {}, {
      theadRef: theadRef,
      theadClasses: theadClasses,
      classPrefix: classPrefix,
      slots: slots,
      onColumnMouseover: onColumnMouseover,
      onColumnMousedown: onColumnMousedown
    });
  },
  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 = table_hooks_useFixed.getColumnFixedStyles(col, index, rowAndColFixedPosition, _this.tableColFixedClasses);
          var colParams = {
            col: col,
            colIndex: index,
            row: {},
            rowIndex: -1
          };
          var customClasses = isFunction__default["default"](col.className) ? col.className(_objectSpread(_objectSpread({}, colParams), {}, {
            type: "th"
          })) : col.className;
          var thClasses = [thStyles.classes, customClasses, (_ref3 = {}, _defineProperty__default["default"](_ref3, _this.tableHeaderClasses.thBordered, thBorderMap.get(col)), _defineProperty__default["default"](_ref3, "".concat(_this.classPrefix, "-table__th-").concat(col.colKey), col.colKey), _defineProperty__default["default"](_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 = table_hooks_useTableHeader.renderTitle(h2, _this.slots, col, index);
          var resizeColumnListener = _this.allowResizeColumnWidth ? {
            mousedown: function mousedown(e) {
              return _this.onColumnMousedown(e, col);
            },
            mousemove: function mousemove(e) {
              return _this.onColumnMouseover(e);
            }
          } : {};
          var content = isFunction__default["default"](col.ellipsisTitle) ? col.ellipsisTitle(h2, {
            col: col,
            colIndex: index
          }) : void 0;
          return h("th", helper.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.ellipsis && col.ellipsisTitle !== false && col.ellipsisTitle !== null ? h(table_ellipsis["default"], {
            "attrs": {
              "placement": "bottom",
              "attach": _this.theadRef ? function () {
                return _this.theadRef;
              } : void 0,
              "popupContent": content && function () {
                return content;
              },
              "popupProps": _typeof__default["default"](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)]);
  }
});

exports["default"] = THead;
//# sourceMappingURL=thead.js.map
