"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const constants = require("../constants.js");
const _private = require("../private.js");
const utils = require("../utils.js");
const headerCell = require("../components/header-cell.js");
const sortIcon = require("../components/sort-icon.js");
const Vue = require("vue");
const HeaderCellRenderer = (props, { slots }) => {
  const { column, ns, t, style, onColumnSorted } = props;
  const cellStyle = utils.enforceUnit(style);
  if (column.placeholderSign === _private.placeholderSign) return Vue.createVNode("div", {
    "class": ns.em("header-row-cell", "placeholder"),
    "style": cellStyle
  }, null);
  const { headerCellRenderer, headerClass, sortable } = column;
  const cellProps = {
    ...props,
    class: ns.e("header-cell-text")
  };
  const columnCellRenderer = utils.componentToSlot(headerCellRenderer);
  const Cell = columnCellRenderer ? columnCellRenderer(cellProps) : Vue.renderSlot(slots, "default", cellProps, () => [Vue.createVNode(headerCell.default, cellProps, null)]);
  const { sortBy, sortState, headerCellProps } = props;
  let sorting, sortOrder, ariaSort;
  if (sortState) {
    const order = sortState[column.key];
    sorting = Boolean(constants.oppositeOrderMap[order]);
    sortOrder = sorting ? order : constants.SortOrder.ASC;
  } else {
    sorting = column.key === sortBy.key;
    sortOrder = sorting ? sortBy.order : constants.SortOrder.ASC;
  }
  if (sortOrder === constants.SortOrder.ASC) ariaSort = "ascending";
  else if (sortOrder === constants.SortOrder.DESC) ariaSort = "descending";
  else ariaSort = void 0;
  const cellKls = [
    ns.e("header-cell"),
    utils.tryCall(headerClass, props, ""),
    column.align === constants.Alignment.CENTER && ns.is("align-center"),
    column.align === constants.Alignment.RIGHT && ns.is("align-right"),
    sortable && ns.is("sortable")
  ];
  return Vue.createVNode("div", Vue.mergeProps({
    ...utils.tryCall(headerCellProps, props),
    onClick: column.sortable ? onColumnSorted : void 0,
    ariaSort: sortable ? ariaSort : void 0,
    class: cellKls,
    style: cellStyle,
    ["data-key"]: column.key
  }, { "role": "columnheader" }), [Cell, sortable && Vue.createVNode(sortIcon.default, {
    "class": [ns.e("sort-icon"), sorting && ns.is("sorting")],
    "sortOrder": sortOrder,
    "ariaLabel": t("el.table.sortLabel", { column: column.title || "" })
  }, null)]);
};
exports.default = HeaderCellRenderer;
