import React from "react";
import { useTranslation } from "react-i18next";
import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
} from "@/components/ui/dialog";

interface Props {
  open: boolean;
  onOpenChange: (open: boolean) => void;
  title: string;
  description: string;
  onConfirm: () => void | Promise<void>;
}

export function DeleteSidebarItemDialog({
  open,
  onOpenChange,
  title,
  description,
  onConfirm,
}: Props): React.JSX.Element {
  const { t } = useTranslation();
  return (
    <Dialog open={open} onOpenChange={onOpenChange}>
      <DialogContent>
        <DialogHeader>
          <DialogTitle>{title}</DialogTitle>
          <DialogDescription>{description}</DialogDescription>
        </DialogHeader>
        <DialogFooter>
          <button
            type="button"
            onClick={() => onOpenChange(false)}
            className="px-4 py-2 rounded-md border border-border-subtle text-sm hover:bg-bg-row-hover"
          >
            {t("common.cancel")}
          </button>
          <button
            type="button"
            onClick={() => {
              void onConfirm();
            }}
            className="px-4 py-2 rounded-md bg-danger text-white text-sm hover:opacity-90"
          >
            {t("common.delete")}
          </button>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  );
}
