function toggleMenu() {
    var nav = document.getElementById("menuList"); // <-- correct ID use karo

    if (nav) {
        nav.classList.toggle("active");
    } else {
        console.error("Element with ID 'menuList' not found.");
    }
}

// Menu band karo jab mouse header se bahar jaye
var headerEl = document.querySelector("header");
if (headerEl) {
    headerEl.addEventListener("mouseleave", function () {
        var nav = document.getElementById("menuList");
        if (nav) nav.classList.remove("active");
    });
}

// Menu band karo jab page scroll ho
window.addEventListener("scroll", function () {
    var nav = document.getElementById("menuList");
    if (nav) nav.classList.remove("active");
});

//Slider/Scroller for Testimonials

document.addEventListener('DOMContentLoaded', () => {

    // Main function to setup a slider
    function setupSlider(containerId, prevBtnId, nextBtnId) {
        const container = document.getElementById(containerId);
        const prevBtn = document.getElementById(prevBtnId);
        const nextBtn = document.getElementById(nextBtnId);

        // Scroll amount: Card width (approx 300px) + Gap (20px)
        const itemWidth = 320;

        // --- 1. Manual Button Logic ---
        nextBtn.addEventListener('click', () => {
            container.scrollLeft += itemWidth;
        });

        prevBtn.addEventListener('click', () => {
            container.scrollLeft -= itemWidth;
        });

        // --- 2. Auto Scroll Logic ---
        let autoScrollInterval;

        function startAutoScroll() {
            autoScrollInterval = setInterval(() => {
                // Calculate the maximum scrollable distance
                const maxScrollLeft = container.scrollWidth - container.clientWidth;

                // Check if we have reached the end of the slider
                if (container.scrollLeft >= maxScrollLeft - 10) { // -10 is a small buffer
                    // If at the end, go back to the start (Loop)
                    container.scrollLeft = 0;
                } else {
                    // Otherwise, scroll to the next card
                    container.scrollLeft += itemWidth;
                }
            }, 3000); // 3000ms = 3 seconds speed
        }

        function stopAutoScroll() {
            clearInterval(autoScrollInterval);
        }

        // --- 3. Pause on Hover Logic ---
        // Stop scrolling when mouse enters the slider area
        container.addEventListener('mouseenter', stopAutoScroll);

        // Resume scrolling when mouse leaves the slider area
        container.addEventListener('mouseleave', startAutoScroll);

        // Start the auto-scroll when page loads
        startAutoScroll();
    }

    // Initialize Services Slider
    setupSlider('service-slider', 'service-prev', 'service-next');

});




//login button

// Button ko select karein
// Button aur Error field ko select karein
document.addEventListener("DOMContentLoaded", function () {
    const loginBtn = document.getElementById("loginBtn");
    const errorDisplay = document.getElementById("error");

    loginBtn.addEventListener("click", function () {
        // Values lena aur extra space hatana
        const user = document.getElementById("Username").value.trim();
        const pass = document.getElementById("password").value.trim();

        // 1. Khali field check
        if (user === "" || pass === "") {
            showMsg("Please enter both fields!", "orange");
            return;
        }

        // 2. Login Logic
        if (user === "raju" && pass === "12345") {
            showMsg("Success! Redirecting...", "green");
            loginBtn.disabled = true; // Baar-baar click rokne ke liye

            setTimeout(() => {
                window.location.href = "cpanel/dashboard.html";
            }, 1200);
        } else {
            showMsg("Invalid username or password!", "red");
        }
    });

    function showMsg(text, color) {
        errorDisplay.textContent = text;
        errorDisplay.style.color = color;
    }
});



// creers form script.js




// 1. Initialize EmailJS
(function () {
    // अपनी Public Key यहाँ डालें
    emailjs.init("YOUR_PUBLIC_KEY_HERE");
})();

document.getElementById("myForm").addEventListener("submit", function (event) {
    event.preventDefault(); // पेज रीलोड रोकें

    // --- 1. बटन Disable करें ---
    var submitBtn = document.querySelector("button[type='submit']");
    submitBtn.disabled = true;
    submitBtn.innerText = "Please Wait...";

    // --- 2. वैल्यू लें ---
    var name = document.getElementById("name").value;
    var email = document.getElementById("email").value;

    // --- ADDRESS FIX (यहाँ हम Address उठा रहे हैं) ---
    // अगर HTML में बॉक्स नहीं मिला तो "N/A" सेव करेगा
    var addressInput = document.getElementById("address");
    var address = addressInput ? addressInput.value : "N/A";

    var rawContact = document.getElementById("contact").value.trim();
    var resumeInput = document.getElementById("resume");
    var msg = document.getElementById("msg");

    // --- 3. VALIDATION (10 Digits) ---
    if (rawContact.length !== 10 || isNaN(rawContact)) {
        alert("Error: Please enter a valid 10-digit Mobile Number.");
        enableButton();
        return;
    }

    var formattedContact = "+91" + rawContact;

    // --- 4. DUPLICATE CHECK ---
    var applicants = JSON.parse(localStorage.getItem("balimeenData")) || [];
    var isDuplicate = applicants.some(function (user) {
        return user.contact === formattedContact;
    });

    if (isDuplicate) {
        alert("Error: Mobile Number already registered!");
        msg.innerHTML = "Error: Already registered!";
        msg.style.color = "red";

        enableButton();
        return;
        // 3 सेकंड बाद गायब करें
        setTimeout(function () {
            msg.style.display = "none"; // पूरा बॉक्स ही छुपा दें
            msg.innerHTML = "";         // टेक्स्ट भी खाली करें
        }, 3);
    }



    // --- 5. FILE PROCESSING ---
    if (resumeInput.files.length > 0) {
        var file = resumeInput.files[0];

        if (file.size > 2000000) {
            alert("File is too big! Max 2MB allowed.");
            enableButton();
            return;
        }

        var reader = new FileReader();
        reader.onload = function (e) {
            var newCandidate = {
                name: name,
                email: email,
                contact: formattedContact,
                address: address, // Address यहाँ सेव होगा
                resumeName: file.name,
                fileData: e.target.result,
                date: new Date().toLocaleDateString() + " " + new Date().toLocaleTimeString()
            };
            saveAndEmail(newCandidate);
        };
        reader.readAsDataURL(file);
    } else {
        var newCandidate = {
            name: name,
            email: email,
            contact: formattedContact,
            address: address,
            resumeName: file.name,
            fileData: null,
            date: new Date().toLocaleDateString() + " " + new Date().toLocaleTimeString()
        };
        saveAndEmail(newCandidate);
    }
});

function saveAndEmail(data) {
    var msg = document.getElementById("msg");

    // Save to LocalStorage
    var applicants = JSON.parse(localStorage.getItem("balimeenData")) || [];
    applicants.push(data);
    localStorage.setItem("balimeenData", JSON.stringify(applicants));

    // Send Email
    var emailParams = {
        to_name: "Admin",
        from_name: data.name,
        contact_number: data.contact,
        user_email: data.email,
        user_address: data.address, // ईमेल में भी Address जाएगा
        message: "New Application Received"
    };

    emailjs.send("YOUR_SERVICE_ID", "YOUR_TEMPLATE_ID", emailParams)
        .then(function () {
            msg.innerHTML = "Success! ✅";
            msg.style.color = "green";
            document.getElementById("myForm").reset();
            enableButton();
        }, function (error) {
            console.log("Email Failed", error);
            msg.innerHTML = "Application Submitted Successfully!";
            enableButton();
        });
}

function enableButton() {
    var submitBtn = document.querySelector("button[type='submit']");
    submitBtn.disabled = false;
    submitBtn.innerText = "Submit";
}