import { ArrowDown, ArrowUp, ArrowUpDown } from "lucide-react"; import type { ComponentProps, ReactNode } from "react"; import { useTranslation } from "react-i18next"; import { TableHead } from "@/components/ui/table"; import { cn } from "@/shared/lib/cn"; import type { SortOrder } from "@/shared/lib/table-sort"; type SortableTableHeadProps = Omit, "children" | "onChange"> & { children: ReactNode; field: string; sortBy: string; sortOrder: SortOrder; initialOrder?: SortOrder; align?: "left" | "center" | "right"; onSort: (field: string, initialOrder: SortOrder) => void; }; export function SortableTableHead({ children, field, sortBy, sortOrder, initialOrder = "asc", align = "left", className, onSort, ...props }: SortableTableHeadProps) { const { t } = useTranslation(); const active = sortBy === field; const nextOrder = active && sortOrder === "asc" ? "desc" : active ? "asc" : initialOrder; const Icon = active ? sortOrder === "asc" ? ArrowUp : ArrowDown : ArrowUpDown; return ( ); }