// Toggle mobile menu
function toggleMenu() {
    var x = document.getElementById("mobileNav");
    if (x.className.indexOf("w3-show") == -1) {
        x.className += " w3-show";
    } else { 
        x.className = x.className.replace(" w3-show", "");
    }
}

// Game modal content switcher
function changeGameInfo(game) {
    var infoDiv = document.getElementById("gameInfo");
    
    if (game === 'ml') {
        infoDiv.innerHTML = `
            <h3>Mobile Legends</h3>
            <p><strong>Rank Tertinggi:</strong> Mythical Immortal (1200 star)</p>
            <p><strong>Role Utama:</strong> Explane</p>
            <p><strong>Hero Favorit:</strong> Phoveus, Badang, Gloo</p>
            <p><strong>Win Rate:</strong> 72.5% (Season 36)</p>
            <button onclick="window.location.href='skills.html'" class="w3-button w3-red">Lihat Skill Saya</button>
        `;
    } else if (game === 'lol') {
        infoDiv.innerHTML = `
            <h3>League of Legends</h3>
            <p><strong>Rank Tertinggi:</strong> Diamond II</p>
            <p><strong>Role Utama:</strong> ADC</p>
            <p><strong>Champion Favorit:</strong> Jhin, Ezreal, Kai'Sa</p>
            <p><strong>Win Rate:</strong> 58% (Season 12)</p>
            <button onclick="window.location.href='skills.html'" class="w3-button w3-red">Lihat Skill Saya</button>
        `;
    } else if (game === 'pubg') {
        infoDiv.innerHTML = `
            <h3>PUBG Mobile</h3>
            <p><strong>Rank Tertinggi:</strong> Conqueror (S10)</p>
            <p><strong>Role Utama:</strong> Sniper/Assaulter</p>
            <p><strong>K/D Ratio:</strong> 4.2 (Squad)</p>
            <p><strong>Headshot Rate:</strong> 35%</p>
            <button onclick="window.location.href='skills.html'" class="w3-button w3-red">Lihat Skill Saya</button>
        `;
    }
}

// Show gaming history
function showGamingHistory() {
    var x = document.getElementById("gamingHistory");
    if (x.className.indexOf("w3-show") == -1) {
        x.className += " w3-show";
    } else { 
        x.className = x.className.replace(" w3-show", "");
    }
}

// Game tabs switcher
function openGameTab(gameName) {
    var i;
    var x = document.getElementsByClassName("gameTab");
    for (i = 0; i < x.length; i++) {
        x[i].style.display = "none";  
    }
    document.getElementById(gameName).style.display = "block";  
    
    // Update tab buttons
    var buttons = document.querySelectorAll('.w3-row button');
    buttons.forEach(function(button) {
        if (button.textContent.includes(gameName.replace('ml', 'Mobile Legends').replace('lol', 'League of Legends').replace('pubg', 'PUBG Mobile'))) {
            button.className = button.className.replace(" w3-dark-grey", " w3-red");
        } else {
            button.className = button.className.replace(" w3-red", " w3-dark-grey");
        }
    });
}

// Show achievement details
function showAchievementDetails(id) {
    var x = document.getElementById(id);
    if (x.className.indexOf("w3-show") == -1) {
        x.className += " w3-show";
    } else { 
        x.className = x.className.replace(" w3-show", "");
    }
}

// Form validation
function validateForm() {
    var name = document.getElementById("name").value;
    var email = document.getElementById("email").value;
    var message = document.getElementById("message").value;
    
    if (name == "" || email == "" || message == "") {
        alert("Harap isi semua field yang diperlukan");
        return false;
    }
    
    // Show success message
    document.getElementById("formSuccess").classList.remove("w3-hide");
    
    // Reset form
    document.querySelector("form").reset();
    
    // Prevent form submission (for demo)
    return false;
}

// Initialize skill circles
document.addEventListener("DOMContentLoaded", function() {
    var circles = document.querySelectorAll('.skill-circle');
    circles.forEach(function(circle) {
        var percent = circle.getAttribute('data-percent');
        var deg = 360 * percent / 100;
        circle.style.setProperty('--rotation', deg + 'deg');
    });
});