// ==================== ADMIN FUNCTIONS ====================

function initializeAdminCharts() {
    // User Growth Chart
    const ctx = document.getElementById('userGrowthChart');
    if (ctx) {
        const userGrowthChart = new Chart(ctx.getContext('2d'), {
            type: 'line',
            data: {
                labels: ['Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun', 'Jul', 'Agu', 'Sep', 'Okt', 'Nov', 'Des'],
                datasets: [{
                    label: 'Total Pengguna',
                    data: [850, 920, 980, 1050, 1120, 1200, 1254, 1300, 1350, 1400, 1450, 1500],
                    borderColor: '#4361ee',
                    backgroundColor: 'rgba(67, 97, 238, 0.1)',
                    tension: 0.4,
                    fill: true
                }, {
                    label: 'Anggota Aktif',
                    data: [600, 650, 700, 750, 800, 820, 856, 880, 900, 920, 940, 960],
                    borderColor: '#10b981',
                    backgroundColor: 'rgba(16, 185, 129, 0.1)',
                    tension: 0.4,
                    fill: true
                }]
            },
            options: {
                responsive: true,
                maintainAspectRatio: false,
                plugins: {
                    legend: {
                        position: 'top',
                    }
                },
                scales: {
                    y: {
                        beginAtZero: false
                    }
                }
            }
        });
    }
}

function setAdminTheme(theme) {
    if (theme === 'auto') {
        const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
        theme = prefersDark ? 'dark' : 'light';
    }
    
    document.documentElement.setAttribute('data-theme', theme);
    localStorage.setItem('admin_theme', theme);
    
    // Update active theme card
    document.querySelectorAll('.theme-card').forEach(card => {
        card.classList.remove('active');
    });
    event.target.closest('.theme-card')?.classList.add('active');
}

function addNewUser() {
    alert('Fitur tambah pengguna akan segera hadir!');
}

function createSeminar() {
    alert('Fitur buat seminar akan segera hadir!');
}

function generateReport() {
    alert('Mengunduh laporan sistem...');
}

function backupSystem() {
    if (confirm('Buat backup sistem sekarang?')) {
        alert('Backup sistem sedang diproses...');
    }
}

function clearCache() {
    if (confirm('Hapus semua cache sistem?')) {
        alert('Cache berhasil dihapus!');
    }
}

function resetStatistics() {
    if (confirm('Reset semua statistik ke nilai default?')) {
        alert('Statistik berhasil direset!');
    }
}

function deleteAllData() {
    if (confirm('PERINGATAN: Tindakan ini akan menghapus SEMUA data sistem. Lanjutkan?')) {
        if (prompt('Ketik "HAPUS" untuk konfirmasi:') === 'HAPUS') {
            alert('Permintaan penghapusan data telah dikirim.');
        }
    }
}

// ==================== EVENT LISTENERS ====================
document.addEventListener('DOMContentLoaded', function() {
    // Inisialisasi icons
    if (typeof lucide !== 'undefined') {
        lucide.createIcons();
    }
    
    // Set theme dari localStorage
    const savedTheme = localStorage.getItem('admin_theme');
    if (savedTheme) {
        setAdminTheme(savedTheme);
    }
});