"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { Switch } from "@/components/ui/switch"; import { updateMinefield } from "@/app/(frontend)/minigames/eod/custom/actions"; export function ExposureRuleToggle({ minefieldId, exposeEdgeMines, }: { minefieldId: number; exposeEdgeMines: boolean; }) { const router = useRouter(); const [checked, setChecked] = useState(exposeEdgeMines); const [pending, setPending] = useState(false); const [error, setError] = useState(null); const onCheckedChange = async (next: boolean) => { setError(null); setPending(true); const result = await updateMinefield({ id: minefieldId, exposeEdgeMines: next }); setPending(false); if (result.success) { setChecked(next); router.refresh(); } else { setError(result.error ?? "Could not update the exposure rule."); } }; return (

{checked ? "Failed runs show mines touching the swept area; everything else stays hidden." : "Failed runs reveal no remaining charges; swept cells turn gray with a question mark."}

{error &&

{error}

}
); }