53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
import { clsx, type ClassValue } from "clsx";
|
|
import { twMerge } from "tailwind-merge";
|
|
|
|
export function cn(...inputs: ClassValue[]) {
|
|
return twMerge(clsx(inputs));
|
|
}
|
|
|
|
export function formatDate(date?: string | null): string {
|
|
if (!date) return "—";
|
|
return new Date(date).toLocaleDateString("en-US", {
|
|
year: "numeric",
|
|
month: "short",
|
|
day: "numeric",
|
|
});
|
|
}
|
|
|
|
export function billLabel(billType: string, billNumber: number): string {
|
|
const labels: Record<string, string> = {
|
|
hr: "H.R.",
|
|
s: "S.",
|
|
hjres: "H.J.Res.",
|
|
sjres: "S.J.Res.",
|
|
hconres: "H.Con.Res.",
|
|
sconres: "S.Con.Res.",
|
|
hres: "H.Res.",
|
|
sres: "S.Res.",
|
|
};
|
|
return `${labels[billType?.toLowerCase()] ?? billType?.toUpperCase()} ${billNumber}`;
|
|
}
|
|
|
|
export function partyColor(party?: string): string {
|
|
if (!party) return "text-muted-foreground";
|
|
const p = party.toLowerCase();
|
|
if (p.includes("democrat") || p === "d") return "text-blue-500";
|
|
if (p.includes("republican") || p === "r") return "text-red-500";
|
|
return "text-yellow-500";
|
|
}
|
|
|
|
export function partyBadgeColor(party?: string): string {
|
|
if (!party) return "bg-muted text-muted-foreground";
|
|
const p = party.toLowerCase();
|
|
if (p.includes("democrat") || p === "d") return "bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200";
|
|
if (p.includes("republican") || p === "r") return "bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200";
|
|
return "bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200";
|
|
}
|
|
|
|
export function trendColor(score?: number): string {
|
|
if (!score) return "text-muted-foreground";
|
|
if (score >= 70) return "text-red-500";
|
|
if (score >= 40) return "text-yellow-500";
|
|
return "text-green-500";
|
|
}
|