'use client';

import { useCurrentUser } from '@/features/auth/CurrentUser';
import { deleteContact, permanentlyDeleteContact } from '@/features/contacts/api.client';
import { DeleteRecordDialog } from '@/features/record-tools/ui/DeleteRecordDialog';

/**
 * LD4: the design's "Delete Contact?" dialog (record-popups.js:324-390). Restorable delete
 * soft-deletes (DELETE /contacts/:id); Permanent delete, offered to admins only (the API's
 * `manage records`), then removes it for good (DELETE /contacts/:id/permanent).
 */
export function DeleteContactDialog({
  open,
  onClose,
  contactId,
  contactName,
  onDeleted,
}: {
  open: boolean;
  onClose: () => void;
  contactId: string;
  contactName: string;
  onDeleted: () => void;
}) {
  const me = useCurrentUser();
  return (
    <DeleteRecordDialog
      open={open}
      onClose={onClose}
      object="contact"
      recordName={contactName}
      onSoftDelete={() => deleteContact(contactId)}
      onPermanent={me.role === 'admin' ? () => permanentlyDeleteContact(contactId) : undefined}
      onDeleted={onDeleted}
    />
  );
}
