function openProfileModal(){
document.getElementById('profileModal').style.display='flex';
}

function closeProfileModal(){
document.getElementById('profileModal').style.display='none';
}

window.onclick = function(e){
let modal = document.getElementById('profileModal');
if(e.target == modal){
modal.style.display='none';
}
}

function saveSettings() {
    const language = document.getElementById('language').value;
    const darkMode = document.getElementById('dark_mode').checked ? 1 : 0;

    fetch('/settings/update', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content
        },
        body: JSON.stringify({
            language: language,
            dark_mode: darkMode
        })
    })
    .then(res => res.json())
    .then(data => {
        alert(data.message);
        location.reload();
    })
    .catch(err => {
        console.error(err);
        alert('Failed to save settings');
    });
}
