import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from '../../../components/ui/alert-dialog'; import type { Campaign } from '../../../services/CampaignService'; export interface CampaignConfirmation { title: string; consequence: string; confirmLabel: string; keepLabel: string; destructive: boolean; } const people = (count: number): string => (count === 1 ? '1 person' : `${count} people`); export const sendNowConfirmation = (eligible: number): CampaignConfirmation => ({ title: 'Send this campaign now?', consequence: `It starts going to ${people(eligible)} within about 15 minutes when your practice's sending window is open. Sending pauses from 9pm to 8am and during any additional practice quiet hours. A sent message cannot be taken back.`, confirmLabel: 'Send now', keepLabel: 'Not yet', destructive: false, }); export const scheduledWhenLabel = (input: string): string => new Date(input).toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short' }); export const scheduleConfirmation = (eligible: number, whenLabel: string): CampaignConfirmation => ({ title: 'Schedule this campaign?', consequence: `It goes to ${people(eligible)} on ${whenLabel}. You can cancel it before then; ` + 'once a message is sent it cannot be taken back.', confirmLabel: 'Schedule', keepLabel: 'Not yet', destructive: false, }); export const resumeConfirmation = (eligible: number): CampaignConfirmation => ({ title: 'Approve this SMS continuation?', consequence: `This authorizes only unexecuted SMS work for the approved continuation audience of ${people(eligible)}. Previously accepted email and unknown prior SMS effects will not be replayed. Delivery is reported separately from dispatch.`, confirmLabel: 'Approve continuation', keepLabel: 'Not yet', destructive: false, }); export const cancelConfirmation = (campaign: Campaign): CampaignConfirmation => ({ title: `Cancel ${campaign.name}?`, consequence: 'Cancellation stops new dispatch. Messages already in flight may still arrive, and their outcomes remain recorded. A cancelled campaign cannot be restarted.', confirmLabel: 'Cancel campaign', keepLabel: 'Keep campaign', destructive: true, }); interface CampaignConfirmDialogProps { confirmation: CampaignConfirmation | null; onConfirm: () => void; onKeep: () => void; } const CampaignConfirmDialog = ({ confirmation, onConfirm, onKeep }: CampaignConfirmDialogProps) => ( { if (!next) onKeep(); }}> {confirmation && ( {confirmation.title} {confirmation.consequence} {confirmation.keepLabel} {confirmation.confirmLabel} )} ); export default CampaignConfirmDialog;