'use client';

import { useRouter } from 'next/navigation';

export function AdminDeleteButton({ apiPath, confirmMessage }: { apiPath: string; confirmMessage: string }) {
  const router = useRouter();

  async function handleDelete() {
    if (!confirm(confirmMessage)) return;
    const res = await fetch(apiPath, { method: 'DELETE' });
    if (res.ok) router.refresh();
    else alert('Suppression impossible.');
  }

  return (
    <button onClick={handleDelete} className="ms-4 text-graphite-900/50 hover:text-copper-600">
      Supprimer
    </button>
  );
}
