import type { ReactNode } from "react";
import {
	AlertDialog,
	AlertDialogAction,
	AlertDialogCancel,
	AlertDialogContent,
	AlertDialogDescription,
	AlertDialogFooter,
	AlertDialogHeader,
	AlertDialogTitle,
	AlertDialogTrigger,
} from "~/components/ui/alert-dialog";
import { buttonVariants } from "~/components/ui/button";
import { cn } from "~/lib/utils";
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?.()}>
						{cancelText || "Annulla"}
					</AlertDialogCancel>
					<AlertDialogAction
						className={cn(buttonVariants({ variant: "destructive" }))}
						onClick={() => onConfirm()}
					>
						{confirmText || "Conferma"}
					</AlertDialogAction>
				</AlertDialogFooter>
			</AlertDialogContent>
		</AlertDialog>
	);
};
