import { FC, ReactNode } from "react";
import { useTranslation } from "react-i18next";

import {
	AlertDialog,
	AlertDialogAction,
	AlertDialogCancel,
	AlertDialogContent,
	AlertDialogDescription,
	AlertDialogFooter,
	AlertDialogHeader,
	AlertDialogTitle,
} from "@/shared/Shadcn/ui/alert-dialog";

interface ConfirmDialogProps {
	open: boolean;
	onOpenChange: (open: boolean) => void;
	onConfirm: () => void;
	onCancel?: () => void;
	title?: string;
	description?: string;
	cancelText?: string;
	confirmText?: string;
	children?: ReactNode;
}

export const ConfirmDialog: FC<ConfirmDialogProps> = ({
	open,
	onOpenChange,
	onConfirm,
	onCancel,
	title,
	description,
	cancelText,
	confirmText,
	children,
}) => {
	const { t } = useTranslation("translation");

	return (
		<AlertDialog open={open} onOpenChange={onOpenChange}>
			{children}
			<AlertDialogContent>
				<AlertDialogHeader>
					<AlertDialogTitle>
						{title || t("confirmAction")}
					</AlertDialogTitle>
					<AlertDialogDescription>
						{description || t("areYouSureToNextStep")}
					</AlertDialogDescription>
				</AlertDialogHeader>
				<AlertDialogFooter>
					<AlertDialogCancel onClick={onCancel}>
						{cancelText || t("No")}
					</AlertDialogCancel>
					<AlertDialogAction onClick={onConfirm}>
						{confirmText || t("yes")}
					</AlertDialogAction>
				</AlertDialogFooter>
			</AlertDialogContent>
		</AlertDialog>
	);
};
