/* ============================================================
   DroidTester — Profile JS
   ============================================================ */

(function () {
    'use strict';

    // ── Collapsible Sections ──
    const sectionHeaders = document.querySelectorAll('.profile-section-header');
    sectionHeaders.forEach(function (header) {
        header.addEventListener('click', function () {
            const body = this.nextElementSibling;
            const isOpen = this.classList.contains('open');

            sectionHeaders.forEach(function (h) {
                h.classList.remove('open');
                const b = h.nextElementSibling;
                if (b && b.classList.contains('profile-section-body')) {
                    b.style.display = 'none';
                }
            });

            if (!isOpen) {
                this.classList.add('open');
                if (body) body.style.display = 'block';
            }
        });
    });

    // ── Open all sections by default ──
    sectionHeaders.forEach(function (header) {
        header.classList.add('open');
        const body = header.nextElementSibling;
        if (body && body.classList.contains('profile-section-body')) {
            body.style.display = 'block';
        }
    });

    // ── Delete Account Modal Trigger ──
    const deleteBtn = document.querySelector('[data-modal="deleteAccount"]');
    if (deleteBtn) {
        deleteBtn.addEventListener('click', function (e) {
            e.preventDefault();
            if (typeof bootstrap !== 'undefined') {
                const modal = new bootstrap.Modal(document.getElementById('deleteAccountModal'));
                if (modal) modal.show();
            }
        });
    }

    // ── Logout Modal Trigger ──
    const logoutBtn = document.querySelector('[data-modal="logout"]');
    if (logoutBtn) {
        logoutBtn.addEventListener('click', function (e) {
            e.preventDefault();
            if (typeof bootstrap !== 'undefined') {
                const modal = new bootstrap.Modal(document.getElementById('logoutModal'));
                if (modal) modal.show();
            }
        });
    }

})();
