import { desc } from "drizzle-orm"; import { getTranslations } from "next-intl/server"; import { deleteShout } from "@/actions/admin-radio-moderation"; import { StatusCard } from "@/components/admin/dashboard"; import { Button } from "@/components/ui/button"; import { db, RadioApplications, RadioSchedules, RadioShouts } from "@/lib/db"; import { formatDate } from "@/lib/format-date"; type Shout = { id: bigint; userId: bigint; message: string; createdAt: Date | null; }; type Application = { id: bigint; userId: bigint; realName: string; age: number; status: string; musicStyle: string | null; discordUsername: string | null; createdAt: Date | null; }; type Schedule = { id: bigint; userId: bigint; day: string; startTime: Date; endTime: Date; showName: string | null; isActive: boolean; }; function formatTime(d: Date | null): string { return d ? d.toISOString().slice(11, 16) : "\u2014"; } function statusBadgeClass(status: string): string { const s = status.toLowerCase(); if (s === "approved" || s === "accepted") return "ok"; if (s === "rejected" || s === "denied") return "danger"; return ""; } export default async function AdminRadioPage() { const t = await getTranslations("pages.admin.radio"); let shouts: Shout[] = []; let applications: Application[] = []; let schedules: Schedule[] = []; try { shouts = await db .select({ id: RadioShouts.id, userId: RadioShouts.userId, message: RadioShouts.message, createdAt: RadioShouts.createdAt, }) .from(RadioShouts) .orderBy(desc(RadioShouts.id)) .limit(25); } catch { shouts = []; } try { applications = await db .select({ id: RadioApplications.id, userId: RadioApplications.userId, realName: RadioApplications.realName, age: RadioApplications.age, status: RadioApplications.status, musicStyle: RadioApplications.musicStyle, discordUsername: RadioApplications.discordUsername, createdAt: RadioApplications.createdAt, }) .from(RadioApplications) .orderBy(desc(RadioApplications.id)) .limit(25); } catch { applications = []; } try { schedules = await db .select({ id: RadioSchedules.id, userId: RadioSchedules.userId, day: RadioSchedules.day, startTime: RadioSchedules.startTime, endTime: RadioSchedules.endTime, showName: RadioSchedules.showName, isActive: RadioSchedules.isActive, }) .from(RadioSchedules) .orderBy(desc(RadioSchedules.id)) .limit(25); } catch { schedules = []; } const pendingApps = applications.filter( (a) => a.status.toLowerCase() === "pending", ).length; const activeSchedules = schedules.filter((sc) => sc.isActive).length; return (
0 ? "warn" : "ok"} icon="📝" /> 0 ? "ok" : "neutral"} icon="🎙️" />

{t("shouts")} ({shouts.length})

{shouts.length === 0 ? (

{t("noShouts")}

) : (
{shouts.map((s) => ( ))}
ID {t("user")} {t("message")} {t("posted")}
{String(s.id)} {String(s.userId)} {s.message} {formatDate(s.createdAt, "datetime", "\u2014")}
)}

{t("applications")} ({applications.length})

{applications.length === 0 ? (

{t("noApplications")}

) : (
{applications.map((a) => ( ))}
ID {t("user")} {t("realName")} {t("age")} {t("style")} Discord {t("status")} {t("applied")}
{String(a.id)} {String(a.userId)} {a.realName} {a.age} {a.musicStyle ?? "\u2014"} {a.discordUsername ?? "\u2014"} {a.status} {formatDate(a.createdAt, "datetime", "\u2014")}
)}

{t("schedules")} ({schedules.length})

{schedules.length === 0 ? (

{t("noSchedules")}

) : (
{schedules.map((sc) => ( ))}
ID {t("user")} {t("day")} {t("start")} {t("end")} {t("show")} {t("active")}
{String(sc.id)} {String(sc.userId)} {sc.day} {formatTime(sc.startTime)} {formatTime(sc.endTime)} {sc.showName ?? "\u2014"} {sc.isActive ? t("active") : t("inactive")}
)}
); }