import { Link } from "react-router-dom" import { CalendarClock, CheckCircle2, AlertTriangle, X, Users, Send, XCircle, Smartphone, } from "lucide-react" import { Badge } from "../../../components/ui/badge" import { Button } from "../../../components/ui/button" import { Card, CardContent } from "../../../components/ui/card" import { channelLabel, formatScheduledAtLabel } from "../../../lib/notificationBulk" import { cn } from "../../../lib/utils" import type { NotificationChannel } from "../../../types/notification.types" export type BulkSendSummary = | { kind: "immediate" channel: NotificationChannel audienceLabel: string titlePreview: string messagePreview: string sent: number failed: number total: number targetUsers?: number devicesTargeted?: number pushImage?: string completedAt: string apiMessage?: string } | { kind: "scheduled" channel: NotificationChannel audienceLabel: string titlePreview: string messagePreview: string jobId: number scheduledAt: string status?: string emailTemplateSlug?: string completedAt: string apiMessage?: string } interface BulkSendSummaryPanelProps { summary: BulkSendSummary onDismiss: () => void } function StatBlock({ label, value, tone = "default", }: { label: string value: number | string tone?: "default" | "success" | "danger" | "muted" }) { const valueClass = tone === "success" ? "text-mint-600" : tone === "danger" ? "text-destructive" : tone === "muted" ? "text-grayScale-500" : "text-grayScale-800" return (

{label}

{value}

) } export function BulkSendSummaryPanel({ summary, onDismiss }: BulkSendSummaryPanelProps) { const isImmediate = summary.kind === "immediate" const isPush = summary.channel === "push" const hasFailures = isImmediate && summary.failed > 0 const allFailed = isImmediate && summary.sent === 0 && summary.failed > 0 const borderTone = allFailed ? "border-destructive/30 bg-destructive/5" : hasFailures ? "border-gold-300/60 bg-gold-50/50" : "border-mint-300/60 bg-mint-50/40" const StatusIcon = allFailed ? XCircle : hasFailures ? AlertTriangle : CheckCircle2 const statusIconClass = allFailed ? "text-destructive" : hasFailures ? "text-gold-600" : "text-mint-600" const headline = isImmediate ? allFailed ? "Delivery failed" : hasFailures ? "Sent with some failures" : "Notification sent successfully" : "Notification scheduled" const completedLabel = new Date(summary.completedAt).toLocaleString("en-US", { month: "short", day: "numeric", year: "numeric", hour: "2-digit", minute: "2-digit", second: "2-digit", }) const progressTotal = isImmediate ? Math.max(summary.total, 1) : 1 return (

{headline}

{isImmediate ? "Delivered" : "Scheduled"} {channelLabel(summary.channel)} {!isImmediate && summary.status ? ( {summary.status} ) : null}

{isImmediate ? `Completed at ${completedLabel}` : `Scheduled for ${formatScheduledAtLabel(summary.scheduledAt)} · created ${completedLabel}`}

{summary.apiMessage ? (

{summary.apiMessage}

) : null}

Audience

{summary.audienceLabel}

Content

{summary.titlePreview || "unassigned"}

{summary.messagePreview || "unassigned"}

{!isImmediate && summary.emailTemplateSlug ? (

Template: {summary.emailTemplateSlug}

) : null}
{isImmediate ? ( <> {isPush ? (
0 ? "danger" : "muted"} />
) : (
0 ? "danger" : "muted"} />
)} {summary.total > 0 ? (
{summary.sent > 0 ? (
) : null} {summary.failed > 0 ? (
) : null}

{isPush ? `${summary.sent} of ${summary.devicesTargeted ?? summary.total} device deliveries succeeded` : `${summary.sent} of ${summary.total} delivered`} {summary.failed > 0 ? ` · ${summary.failed} failed` : ""}

) : null} {isPush && summary.pushImage ? (

Image: {summary.pushImage}

) : null} {isPush && (summary.devicesTargeted ?? 0) === 0 && (summary.targetUsers ?? 0) > 0 ? (

Targeted users have no active FCM device tokens. They must register a device from the learner app while logged in.

) : null} ) : (

Scheduled at

{formatScheduledAtLabel(summary.scheduledAt)}

)}

This summary is temporary and clears when you dismiss it or send again.

{!isImmediate ? ( ) : null}
) }