// Global functions
function showAlert(icon, title, text) {
    Swal.fire({
        icon: icon,
        title: title,
        text: text,
        confirmButtonColor: '#16213e'
    });
}

// Document ready
document.addEventListener('DOMContentLoaded', function() {
    // Inisialisasi tooltip
    const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
    tooltipTriggerList.map(function (tooltipTriggerEl) {
        return new bootstrap.Tooltip(tooltipTriggerEl);
    });
    
    // Tangani pesan flash dari PHP
    if (document.querySelector('.alert-success')) {
        const message = document.querySelector('.alert-success').textContent;
        showAlert('success', 'Sukses', message);
    }
    
    if (document.querySelector('.alert-danger')) {
        const message = document.querySelector('.alert-danger').textContent;
        showAlert('error', 'Error', message);
    }
});