"use client"; import { AlertTriangle } from "lucide-react"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { toast } from "sonner"; import { fixEverythingAction } from "@/actions/furni-maintenance"; import { Button } from "@/components/ui/button"; /** * One-click "fix everything" for the furniture tables. Runs sprite fix, catalog * offer fix, FurnitureData reconciliation, dedup and ID alignment in order, all * inside a single DB transaction on the server. Heavy — guarded by a confirm. */ export function CatalogFixAllButton() { const router = useRouter(); const [busy, setBusy] = useState(false); async function run() { if ( !window.confirm( "Alle meubel-tabellen repareren (sprite-id, offer_id, dubbelen, IDs naar FurnitureData)?\nDit is een zware, niet-omkeerbare actie. Zorg dat er een backup is.", ) ) { return; } setBusy(true); try { const res = await fixEverythingAction(); if (res.ok) { toast.success("Alle reparaties uitgevoerd"); router.refresh(); } else { toast.error(res.error ?? "Mislukt"); } } catch (e) { toast.error(String(e)); } finally { setBusy(false); } } return ( ); }