import React from 'react' import { BellRing, Loader2 } from 'lucide-react' import { useAdminNotificationMatrix } from '../../components/Admin/useAdminNotificationMatrix' import { useToast } from '../../components/shared/Toast' import ToggleSwitch from '../../components/Settings/ToggleSwitch' import { SettingsCard, SettingsHint } from '../../components/Settings/settingsKit' import { fs } from '../../components/shared/DialogShell' import { ADMIN_EVENT_LABEL_KEYS, ADMIN_CHANNEL_LABEL_KEYS } from './AdminPage.constants' const EYEBROW = 'text-center font-geist font-bold uppercase tracking-[.08em] text-content-faint' // Per-event × per-channel admin notification preference matrix. // Loads its own data and auto-saves each toggle. export default function AdminNotificationsPanel({ t, toast }: { t: (k: string) => string; toast: ReturnType }) { const { matrix, saving, visibleChannels, toggle } = useAdminNotificationMatrix(t, toast) const card = (children: React.ReactNode) => ( {children} ) if (!matrix) { return card(
{t('common.loading')}
, ) } if (matrix.event_types.length === 0) { return card({t('settings.notificationPreferences.noChannels')}) } const columns = `minmax(0, 1fr) ${visibleChannels.map(() => '76px').join(' ')}` const channelName = (ch: string) => t(ADMIN_CHANNEL_LABEL_KEYS[ch]) || ch const eventName = (evt: string) => t(ADMIN_EVENT_LABEL_KEYS[evt]) || evt return card(
{/* The channel names over their columns */}
{saving ? t('common.saving') : null} {visibleChannels.map(ch => ( {channelName(ch)} ))}
{/* One row per event, a switch per channel that implements it */}
{matrix.event_types.map(eventType => { const implementedForEvent = matrix.implemented_combos[eventType] ?? [] return (
{eventName(eventType)} {visibleChannels.map(ch => { if (!implementedForEvent.includes(ch)) { return — } const isOn = matrix.preferences[eventType]?.[ch] ?? true return (
{ void toggle(eventType, ch) }} />
) })}
) })}
, ) }