"use client";
import { useState, useMemo } from "react";
import Link from "next/link";
import { PageHeader } from "@/components/page-header";
import { Card, CardContent } from "@/components/ui/card";
import { Badge } from "@/components/ui/badge";
import { cn } from "@/lib/utils";
import { ChevronRight, Clock, MapPin } from "lucide-react";
import { PlayAudioButton } from "@/app/(app)/transcriptions/[slug]/play-audio-button";
type TranscriptionItem = {
slug: string;
name: string;
type: string;
date: string | null;
year: number | null;
month: number | null;
day: number | null;
place: string | null;
context: string | null;
reference: string | null;
durationMinutes: number | null;
participants: string[];
audioUrl: string | null;
};
const MONTH_NAMES = [
"",
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
];
function MonthSection({
label,
items,
defaultOpen,
}: {
month: number;
label: string;
items: TranscriptionItem[];
defaultOpen: boolean;
}) {
const [open, setOpen] = useState(defaultOpen);
return (
{open && (
{items.map((t) => (
-
{t.name}
{t.type === "lecture" ? "Lecture" : "Conversation"}
{t.place && (
{t.place}
)}
{t.reference && (
{t.reference}
)}
{t.durationMinutes && t.durationMinutes > 0 && (
{t.durationMinutes} min
)}
{t.audioUrl && (
)}
))}
)}
);
}
export function TranscriptionYearBrowser({
transcriptions,
year,
totalCount,
}: {
transcriptions: TranscriptionItem[];
year: number;
totalCount: number;
}) {
const monthGroups = useMemo(() => {
const map = new Map();
for (const t of transcriptions) {
const m = t.month && t.month >= 1 && t.month <= 12 ? t.month : 0;
if (!map.has(m)) map.set(m, []);
map.get(m)!.push(t);
}
const groups: {
month: number;
label: string;
items: TranscriptionItem[];
}[] = [];
for (let m = 1; m <= 12; m++) {
const items = map.get(m);
if (items && items.length > 0) {
groups.push({ month: m, label: MONTH_NAMES[m], items });
}
}
const unknown = map.get(0);
if (unknown && unknown.length > 0) {
groups.push({ month: 0, label: "Unknown Month", items: unknown });
}
return groups;
}, [transcriptions]);
const lectureCount = transcriptions.filter(
(t) => t.type === "lecture",
).length;
const conversationCount = transcriptions.filter(
(t) => t.type === "conversation",
).length;
return (
<>
← Transcriptions
Transcriptions from {year}
{totalCount} transcriptions · {lectureCount} lectures ·{" "}
{conversationCount} conversations
{monthGroups.length === 0 ? (
No transcriptions for this year
) : (
{monthGroups.map((mg, i) => (
))}
)}
>
);
}