import { BRAND } from "./brand"; export type SortKey = "newest" | "oldest" | "az" | "za" | "code-az" | "code-za"; export const SORT_OPTIONS: ReadonlyArray<{ value: SortKey; label: string }> = [ { value: "newest", label: "Newest First" }, { value: "oldest", label: "Oldest First" }, { value: "az", label: "Title A → Z" }, { value: "za", label: "Title Z → A" }, { value: "code-az", label: "Code A → Z" }, { value: "code-za", label: "Code Z → A" }, ]; export const DEFAULT_SORT: SortKey = "newest"; export const SORT_COOKIE = `${BRAND.storagePrefix}-default-sort`; const VALID = new Set(["newest", "oldest", "az", "za", "code-az", "code-za"]); export function isValidSort(v: string | undefined | null): v is SortKey { return !!v && VALID.has(v as SortKey); } export function labelFor(sort: SortKey): string { return SORT_OPTIONS.find((o) => o.value === sort)?.label ?? sort; }