// setTimeout(function(){
//     document.getElementById("success-alert").style.display = "none";
// }, 2000);

//setTimeout(function(){
//    // document.getElementById("success-alert").style.display = "none";
//    const successAlert = document.getElementById("success-alert");
//    if(successAlert){
//        successAlert.style.display = "none";
//    }
//}, 2000);

//setTimeout(function () {
//    // Select all alerts
//    const alerts = document.querySelectorAll(".alert");
//
//    // Get the last alert
//    const lastAlert = alerts[alerts.length - 1];
//
//    // Hide only the last alert
//    if (lastAlert) {
//        lastAlert.style.display = "none";
//    }
//}, 2000);

//document.addEventListener("DOMContentLoaded", function () {
//    const alerts = document.querySelectorAll(".alert");
//    const seen = new Set();
//
//    alerts.forEach(alert => {
//        const text = alert.textContent.trim();
//
//        if (seen.has(text)) {
//            // Duplicate alert → hide it
//            alert.style.display = "none";
//        } else {
//            // First time this message is seen
//            seen.add(text);
//        }
//    });
//
//    // Auto-hide only the LAST message
//    setTimeout(function () {
//        const visibleAlerts = [...document.querySelectorAll(".alert")].filter(a => a.style.display !== "none");
//        const lastAlert = visibleAlerts[visibleAlerts.length - 1];
//        if (lastAlert) lastAlert.style.display = "none";
//    }, 2000);
//});



document.addEventListener("DOMContentLoaded", function () {
    const alerts = document.querySelectorAll(".alert");
    const seen = new Set();

    // Remove duplicate alerts
    alerts.forEach(alert => {
        const text = alert.textContent.trim();

        if (seen.has(text)) {
            alert.style.display = "none";  // hide duplicate
        } else {
            seen.add(text);  // store unique message
        }
    });

    // Hide all visible alerts after 2 seconds
    setTimeout(function () {
        const visibleAlerts = document.querySelectorAll(".alert");
        visibleAlerts.forEach(alert => {
            if (alert.style.display !== "none") {
                alert.style.display = "none";
            }
        });
    }, 2000);
});