"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const shared_esmBundler = require("../../../../../../@vue/shared/dist/shared.esm-bundler.js");
const index = require("../../../../hooks/use-namespace/index.js");
const util = require("../util.js");
const tokens = require("../tokens.js");
const vue = require("vue");
function useStyle(props) {
  const parent = vue.inject(tokens.TABLE_INJECTION_KEY);
  const ns = index.useNamespace("table");
  const getHeaderRowStyle = (rowIndex) => {
    const headerRowStyle = parent == null ? void 0 : parent.props.headerRowStyle;
    if (shared_esmBundler.isFunction(headerRowStyle)) return headerRowStyle.call(null, { rowIndex });
    return headerRowStyle;
  };
  const getHeaderRowClass = (rowIndex) => {
    const classes = [];
    const headerRowClassName = parent == null ? void 0 : parent.props.headerRowClassName;
    if (shared_esmBundler.isString(headerRowClassName)) classes.push(headerRowClassName);
    else if (shared_esmBundler.isFunction(headerRowClassName)) classes.push(headerRowClassName.call(null, { rowIndex }));
    return classes.join(" ");
  };
  const getHeaderCellStyle = (rowIndex, columnIndex, row, column) => {
    let headerCellStyles = (parent == null ? void 0 : parent.props.headerCellStyle) ?? {};
    if (shared_esmBundler.isFunction(headerCellStyles)) headerCellStyles = headerCellStyles.call(null, {
      rowIndex,
      columnIndex,
      row,
      column
    });
    const fixedStyle = util.getFixedColumnOffset(columnIndex, column.fixed, props.store, row);
    util.ensurePosition(fixedStyle, "left");
    util.ensurePosition(fixedStyle, "right");
    return Object.assign({}, headerCellStyles, fixedStyle);
  };
  const getHeaderCellClass = (rowIndex, columnIndex, row, column) => {
    const fixedClasses = util.getFixedColumnsClass(ns.b(), columnIndex, column.fixed, props.store, row);
    const classes = [
      column.id,
      column.order,
      column.headerAlign,
      column.className,
      column.labelClassName,
      ...fixedClasses
    ];
    if (!column.children) classes.push("is-leaf");
    if (column.sortable) classes.push("is-sortable");
    const headerCellClassName = parent == null ? void 0 : parent.props.headerCellClassName;
    if (shared_esmBundler.isString(headerCellClassName)) classes.push(headerCellClassName);
    else if (shared_esmBundler.isFunction(headerCellClassName)) classes.push(headerCellClassName.call(null, {
      rowIndex,
      columnIndex,
      row,
      column
    }));
    classes.push(ns.e("cell"));
    return classes.filter((className) => Boolean(className)).join(" ");
  };
  return {
    getHeaderRowStyle,
    getHeaderRowClass,
    getHeaderCellStyle,
    getHeaderCellClass
  };
}
exports.default = useStyle;
