import { For, Show, Suspense, createSignal } from "solid-js"; import { Button } from "@/components/ui/button"; import { ConfirmDialog } from "@/components/ui/confirm-dialog"; import { IconBell, IconCalendar, IconChevronLeft, IconExam, IconHomework, IconMessage, IconTrash, IconX, } from "@/components/ui/icons"; import { cn } from "@/lib/cn"; import { formatUnreadCount, type NotificationItem, type NotificationType } from "@/lib/notifications"; import type { NotificationFeed } from "@/components/layout/notification-feed"; import { useT } from "@/stores/preferences-context"; /** * The notification list — header with "clear all", grouped rows, and the * preview of one row — for whichever surface hosts it. The preview is local * state, so it resets whenever the host unmounts the list on close. */ export function NotificationList(props: { feed: NotificationFeed; /** Leaves the target page of a previewed notification. */ onNavigate: (url: string) => void; /** The host already names the list (a panel title). */ showTitle?: boolean; /** Height cap of the scrolling list; the popover keeps it short. */ scrollClass?: string; }) { const t = useT(); const [previewNotification, setPreviewNotification] = createSignal(null); // Clearing everything cannot be undone, so it asks first. const [confirmClear, setConfirmClear] = createSignal(false); const totalCount = () => props.feed.groups().reduce((count, group) => count + group.items.length, 0); const notificationGroupLabel = (type: NotificationType) => { if (type === "message") return t("nav.messages"); if (type === "event") return t("events.title"); if (type === "exam") return t("exams.title"); return t("homework.title"); }; const notificationGroupTone = (type: NotificationType) => { if (type === "message") return "border-primary/20 bg-primary/[0.035]"; if (type === "event") return "border-violet-500/20 bg-violet-500/[0.035]"; if (type === "exam") return "border-amber-500/25 bg-amber-500/[0.045]"; return "border-emerald-500/20 bg-emerald-500/[0.035]"; }; const notificationGroupIconTone = (type: NotificationType) => { if (type === "message") return "bg-primary/10 text-primary-text"; if (type === "event") return "bg-violet-500/10 text-violet-700 dark:text-violet-300"; if (type === "exam") return "bg-amber-500/10 text-amber-700 dark:text-amber-300"; return "bg-emerald-500/10 text-emerald-700 dark:text-emerald-300"; }; const dismissOne = (evt: MouseEvent, id: string) => { evt.stopPropagation(); props.feed.dismiss(id); }; // A row with a target page goes straight there (marked read on the way); // only a row with nowhere to go opens the in-list preview. const select = (item: NotificationItem) => { void props.feed.markRead(item); if (item.targetUrl) props.onNavigate(item.targetUrl); else setPreviewNotification(item); }; return ( <> {/* Hosted under a panel title, the header row only earns its place when there is something to clear. */} 0}>

{t("notifications.title")}

0}> {formatUnreadCount(props.feed.unreadCount())}
0}>
{t("common.loading")}
} > 0} fallback={

{t("notifications.empty")}

} >
{(group) => (
{notificationGroupLabel(group.type)}
{group.items.length}
{(item) => (
select(item)} onKeyDown={(event) => { if (event.target !== event.currentTarget) return; if (event.key === "Enter" || event.key === " ") { event.preventDefault(); select(item); } }} class="group relative flex cursor-pointer select-none items-start gap-3 rounded-lg p-2 text-xs outline-hidden transition-colors hover:bg-background/70 focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring" >
{item.title}

{item.description}

)}
)}
} > {(item) => (

{item().title}

{item().preview ?? item().description}

)}
props.feed.dismissAll()} /> ); }