var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import React, { forwardRef, useContext } from "react";
import { ArrowsUpDownIcon, SortDownIcon, SortUpIcon, } from "@navikt/aksel-icons";
import { consoleWarning } from "../utils/helpers/consoleWarning.js";
import HeaderCell from "./HeaderCell.js";
import { TableContext } from "./context.js";
export const ColumnHeader = forwardRef((_a, ref) => {
    var _b, _c, _d, _e;
    var { children, sortable = false, sortKey } = _a, rest = __rest(_a, ["children", "sortable", "sortKey"]);
    const context = useContext(TableContext);
    if (sortable && !sortKey) {
        consoleWarning("ColumnHeader with `sortable=true` must have a sortKey.");
    }
    return (React.createElement(HeaderCell, Object.assign({ scope: "col", ref: ref, "aria-sort": sortable
            ? ((_b = context === null || context === void 0 ? void 0 : context.sort) === null || _b === void 0 ? void 0 : _b.orderBy) === sortKey
                ? (_c = context === null || context === void 0 ? void 0 : context.sort) === null || _c === void 0 ? void 0 : _c.direction
                : "none"
            : undefined }, rest), sortable ? (React.createElement("button", { type: "button", className: "aksel-table__sort-button", onClick: sortable && sortKey
            ? () => { var _a; return (_a = context === null || context === void 0 ? void 0 : context.onSortChange) === null || _a === void 0 ? void 0 : _a.call(context, sortKey); }
            : undefined },
        children,
        ((_d = context === null || context === void 0 ? void 0 : context.sort) === null || _d === void 0 ? void 0 : _d.orderBy) === sortKey ? (((_e = context === null || context === void 0 ? void 0 : context.sort) === null || _e === void 0 ? void 0 : _e.direction) === "descending" ? (React.createElement(SortDownIcon, { "aria-hidden": true })) : (React.createElement(SortUpIcon, { "aria-hidden": true }))) : (React.createElement(ArrowsUpDownIcon, { "aria-hidden": true })))) : (children)));
});
export default ColumnHeader;
//# sourceMappingURL=ColumnHeader.js.map