"use client";

import {
  Button,
  Dialog,
  DialogActions,
  DialogContent,
  DialogTitle,
  Typography,
} from "@mui/material";

type Props = {
  open: boolean;
  itemName: string;
  loading?: boolean;
  language?: "en" | "kh";
  fontFamily?: string;
  onClose: () => void;
  onConfirm: () => void;
};

export function MasterDataDeleteDialog({
  open,
  itemName,
  loading = false,
  language = "en",
  fontFamily,
  onClose,
  onConfirm,
}: Props) {
  const isKhmer = language === "kh";

  const handleClose = () => {
    if (loading) {
      return;
    }

    onClose();
  };

  return (
    <Dialog
      open={open}
      onClose={handleClose}
      fullWidth
      maxWidth="xs"
      slotProps={{
        paper: {
          sx: {
            borderRadius: 3,
            border: "1px solid",
            borderColor: "divider",
            backgroundImage: "none",
            fontFamily,

            "& .MuiTypography-root, & .MuiButton-root": {
              fontFamily,
            },
          },
        },
      }}
    >
      <DialogTitle>
        {isKhmer
          ? "តើអ្នកចង់លុបទិន្នន័យនេះឬ?"
          : "Delete item?"}
      </DialogTitle>

      <DialogContent>
        <Typography
          sx={{
            fontWeight: 700,
          }}
        >
          {itemName}
        </Typography>

        <Typography
          color="text.secondary"
          sx={{
            mt: 0.75,
            fontSize: 14,
          }}
        >
          {isKhmer
            ? "សកម្មភាពនេះមិនអាចត្រឡប់វិញបានទេ។"
            : "This action cannot be undone."}
        </Typography>
      </DialogContent>

      <DialogActions
        sx={{
          px: 3,
          pb: 3,
        }}
      >
        <Button
          disabled={loading}
          onClick={handleClose}
          variant="outlined"
          color="inherit"
          sx={{
            textTransform: "none",
          }}
        >
          {isKhmer ? "បោះបង់" : "Cancel"}
        </Button>

        <Button
          disabled={loading}
          onClick={onConfirm}
          variant="contained"
          color="error"
          sx={{
            textTransform: "none",
          }}
        >
          {isKhmer ? "លុប" : "Delete"}
        </Button>
      </DialogActions>
    </Dialog>
  );
}