import { cn } from "~/lib/utils";
import {
  AlertDialog,
  AlertDialogTrigger,
  AlertDialogContent,
  AlertDialogHeader,
  AlertDialogTitle,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogCancel,
  AlertDialogAction,
} from "~/components/ui/alert-dialog";
import { buttonVariants } from "~/components/ui/button";
import type { ReactNode } from "react";
export const Confirm = ({
  children,
  title,
  description,
  onConfirm,
  onCancel,
  open,
  setOpen,
  onlyHedless,
  cancelText,
  confirmText,
}: {
  children: ReactNode;

  title: string;
  description: string;
  onConfirm: () => void;
  onCancel?: () => void;
  open?: boolean;
  setOpen?: (open: boolean) => void;
  onlyHedless?: boolean;
  cancelText?: string;
  confirmText?: string;
}) => {
  return (
    <AlertDialog open={open} onOpenChange={setOpen}>
      {onlyHedless ? null : (
        <AlertDialogTrigger asChild>{children}</AlertDialogTrigger>
      )}
      <AlertDialogContent>
        <AlertDialogHeader>
          <AlertDialogTitle>{title}</AlertDialogTitle>
          <AlertDialogDescription>{description}</AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter>
          <AlertDialogCancel onClick={() => onCancel && onCancel()}>
            {cancelText || "Annulla"}
          </AlertDialogCancel>
          <AlertDialogAction
            className={cn(buttonVariants({ variant: "destructive" }))}
            onClick={() => onConfirm()}
          >
            {confirmText || "Conferma"}
          </AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  );
};
