import { AlertItem } from "./Alert";


const setEditingAlert = (editing: boolean, setAlerts: React.Dispatch<React.SetStateAction<AlertItem[]>>) => {
    if (editing) {
        setAlerts(prev => {
            if (!prev.some(alert => alert.variant === "info")) {
                return [...prev, {
                    variant: "info",
                    description: "You have unsaved changes. Don't forget to save your work!",
                    tag: "editing"
                }];
            }
            return prev;
        });
    } else {
        setAlerts([]);
    }
}

export default setEditingAlert;
