"use client" import * as React from "react" import { cn } from "../../lib/utils" import { runWithPreservedPageScroll } from "../../lib/preserve-page-scroll" import { railTriggerProps } from "../ui/floating-sheet-panel" import { Input } from "../ui/input" import { Tip } from "../ui/tip" import { resolveColumnFilter } from "../../lib/column-filter" import { Checkbox } from "../ui/checkbox" import { ROW_DRAG_COLUMN_KEY } from "./row-reorder-handle" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuShortcut, DropdownMenuSeparator, DropdownMenuTrigger } from "../ui/dropdown-menu" import type { ColumnDef } from "./types" import { defaultColumnHeaderLabel, isControlColumn, resolvedColumnLabel, SortChevron } from "./table-helpers" import type { useTableState } from "./use-table-state" export interface ColumnHeaderCellContentProps> { col: ColumnDef /** When false, exclude from Tab order (floating sticky clone). */ tabbable?: boolean state: ReturnType> columns: ColumnDef[] selectable: boolean allSelected: boolean someSelected: boolean visibleRowIds: (string | number)[] filteredColumnKeys: ReadonlySet conditionalRuleColumnKeys: ReadonlySet bumpHeaderMenuOpen: (open: boolean) => void columnMenuPendingActionRef: React.MutableRefObject<(() => void) | null> sortRuleIdRef: React.MutableRefObject moveColumnBy: (col: ColumnDef, delta: -1 | 1, rtl?: boolean) => void reorderTargetFor: (key: string, delta: -1 | 1) => string | null } type AppliedIndicator = { icon: string; label: string } /** * What is applied to this column, so a filtered / grouped / conditionally * formatted column is legible without opening the ⋯ menu or the rail. * Solid weight reads as "on" against the light-weight header chrome. */ function getAppliedIndicators( colKey: string, columnLabel: string, flags: { filtered: boolean; grouped: boolean; conditional: boolean }, ): AppliedIndicator[] { if (isControlColumn(colKey)) return [] const candidates: [boolean, AppliedIndicator][] = [ [flags.filtered, { icon: "fa-filter", label: `Filtered by ${columnLabel}` }], [flags.grouped, { icon: "fa-layer-group", label: `Grouped by ${columnLabel}` }], [flags.conditional, { icon: "fa-palette", label: `Conditional formatting on ${columnLabel}` }], ] return candidates.filter(([on]) => on).map(([, entry]) => entry) } function shouldShowColumnMenu>( col: ColumnDef, columns: ColumnDef[], lockedPins: Record, ): boolean { if (col.key === "select" || col.key === ROW_DRAG_COLUMN_KEY) return false if (lockedPins[col.key]?.includes("right")) return false return col.key !== columns.find(c => c.lockPin && c.defaultPin === "right")?.key } /** Plain-text header fallback label (sr-only when the column has no visible label). */ function renderStaticHeaderLabel>(col: ColumnDef): React.ReactNode { if (col.label?.trim()) return col.label const fallback = defaultColumnHeaderLabel(col.key) || col.key return {fallback} } function AppliedIndicatorList({ indicators, tabbable }: { indicators: AppliedIndicator[]; tabbable: boolean }) { if (indicators.length === 0) return null return ( {indicators.map(indicator => (