"use client"; import { useRouter } from "next/navigation"; import { createContext, useContext, useMemo, useRef, useState, type ReactNode } from "react"; import { TriangleAlertIcon } from "lucide-react"; import { cn } from "@/lib/utils"; import { redactText } from "@/lib/redaction"; import { AlertDialog, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog"; import { buttonVariants } from "@/components/ui/button"; const HOLD_CONFIRM_MS = 1000; interface SpoilerAcknowledgment { readonly acknowledged: boolean; readonly acknowledge: () => void; } // Default to acknowledged so consumers outside a gate are never blocked. const SpoilerContext = createContext({ acknowledged: true, acknowledge: () => undefined, }); export function useSpoilerAcknowledgment(): SpoilerAcknowledgment { return useContext(SpoilerContext); } function HoldToConfirmButton({ onConfirm, children, }: { readonly onConfirm: () => void; readonly children: ReactNode; }) { const [holding, setHolding] = useState(false); const timerRef = useRef(null); const doneRef = useRef(false); const cancel = () => { if (timerRef.current !== null) { clearTimeout(timerRef.current); timerRef.current = null; } setHolding(false); }; const begin = () => { if (timerRef.current !== null || doneRef.current) return; setHolding(true); timerRef.current = window.setTimeout(() => { timerRef.current = null; doneRef.current = true; onConfirm(); }, HOLD_CONFIRM_MS); }; return ( ); } export function SpoilerGate({ spoiler, children, }: { readonly spoiler: boolean; readonly children: ReactNode; }) { const router = useRouter(); const [acknowledged, setAcknowledged] = useState(false); const value = useMemo( () => ({ acknowledged: !spoiler || acknowledged, acknowledge: () => setAcknowledged(true), }), [acknowledged, spoiler], ); return ( {children} {spoiler && !acknowledged && ( Potential campaign spoilers This recording page may include, infer, or otherwise expose campaign spoilers. Continue only if you are comfortable with that. Press and hold the confirmation button for one second to continue. router.push("/voiceover")}> Go back I understand )} ); } /** * Renders the script description, redacted until the spoiler gate is * acknowledged (plain text for non-spoiler scripts). */ export function SpoilerDescription({ spoiler, description, }: { readonly spoiler: boolean; readonly description: string | null; }) { const { acknowledged } = useSpoilerAcknowledgment(); const text = spoiler && !acknowledged && description ? redactText(description) : description; if (!text?.trim()) return null; return

{text}

; }