export function showModal(type, title, message) {
    const modal = document.getElementById('customModal');
    const modalIcon = document.getElementById('modalIcon');
    const modalTitle = document.getElementById('modalTitle');
    const modalMessage = document.getElementById('modalMessage');

    modalIcon.className = 'modal-icon';

    if (type === 'success') {
        modalIcon.classList.add('success');
        modalTitle.textContent = title || 'Login Berhasil!';
    } else {
        modalIcon.classList.add('error');
        modalTitle.textContent = title || 'Login Gagal!';
    }

    modalMessage.textContent = message;
    modal.classList.add('show');
}

export function closeModal() {
    const modal = document.getElementById('customModal');
    modal.classList.remove('show');
}

export function setupModalOk() {
    document.getElementById('modalOkBtn').addEventListener('click', function() {
        const modalIcon = document.getElementById('modalIcon');

        if (modalIcon.classList.contains('success')) {
            window.location.href = 'Homepage.html';
        } else {
            closeModal();
        }
    });
}

export function setupOutsideClose() {
    document.getElementById('customModal').addEventListener('click', function(e) {
        const modalIcon = document.getElementById('modalIcon');

        if (e.target === this) {
            if (modalIcon.classList.contains('success')) {
                window.location.href = 'Homepage.html';
            } else {
                closeModal();
            }
        }
    });
}