import { Modal, Text, Button, Group, Stack } from "@mantine/core"; import { useNavigationGuard } from "../../contexts/NavigationContext"; import { useTranslation } from "react-i18next"; import ArrowBackIcon from "@mui/icons-material/ArrowBack"; import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline"; import CheckCircleOutlineIcon from "@mui/icons-material/CheckCircleOutline"; interface NavigationWarningModalProps { onApplyAndContinue?: () => Promise; onExportAndContinue?: () => Promise; } const NavigationWarningModal = ({ onApplyAndContinue, onExportAndContinue }: NavigationWarningModalProps) => { const { t } = useTranslation(); const { showNavigationWarning, hasUnsavedChanges, cancelNavigation, confirmNavigation, setHasUnsavedChanges } = useNavigationGuard(); const handleKeepWorking = () => { cancelNavigation(); }; const handleDiscardChanges = () => { setHasUnsavedChanges(false); confirmNavigation(); }; const handleApplyAndContinue = async () => { if (onApplyAndContinue) { await onApplyAndContinue(); } setHasUnsavedChanges(false); confirmNavigation(); }; const _handleExportAndContinue = async () => { if (onExportAndContinue) { await onExportAndContinue(); } setHasUnsavedChanges(false); confirmNavigation(); }; const BUTTON_WIDTH = "10rem"; if (!hasUnsavedChanges) { return null; } return ( {t("unsavedChanges", "You have unsaved changes to your PDF.")} {t("areYouSure", "Are you sure you want to leave?")} {/* Desktop layout: 2 groups side by side */} {onApplyAndContinue && ( )} {/* Mobile layout: centered stack of 4 buttons */} {onApplyAndContinue && ( )} ); }; export default NavigationWarningModal;