"use client"; import { ArrowUpDown, ArrowUp, ArrowDown } from "lucide-react"; import { cn } from "@/lib/utils"; import { ALL_COLUMNS, getColumnStyle, type ColumnConfig } from "@/lib/config/placement-columns"; interface SortOption { field: string; direction: "asc" | "desc"; } interface PlacementsTableHeaderProps { visibleColumns: Set; sort?: SortOption | null; onSort?: (field: string) => void; } const SORT_FIELD_TO_COLUMN: Record = { cost: "cost", date: "planned_date", cpm: "cpm", cpf: "cpf", subscribers: "subscriptions", views: "views", created: "created", }; export function PlacementsTableHeader({ visibleColumns, sort, onSort, }: PlacementsTableHeaderProps) { const visibleColumnConfigs = ALL_COLUMNS.filter((c) => visibleColumns.has(c.id) ); const handleSort = (column: ColumnConfig) => { if (!column.sortable || !onSort) return; const sortField = Object.entries(SORT_FIELD_TO_COLUMN).find( ([, colId]) => colId === column.id )?.[0]; if (sortField) { onSort(sortField); } }; const getSortDirection = (column: ColumnConfig): "asc" | "desc" | null => { if (!sort || !column.sortable) return null; const sortField = Object.entries(SORT_FIELD_TO_COLUMN).find( ([, colId]) => colId === column.id )?.[0]; if (sortField && sort.field === sortField) { return sort.direction; } return null; }; return (
getColumnStyle(c)) .join(" "), }} > {visibleColumnConfigs.map((column) => { const sortDir = getSortDirection(column); return (
handleSort(column)} title={column.sortable ? "Нажмите для сортировки" : undefined} > {column.label} {column.sortable && ( sortDir ? ( sortDir === "asc" ? ( ) : ( ) ) : ( ) )}
); })}
); }