/**
 * Help Improve Modal Handler
 * Simple modal for bug reports, feature suggestions, and community help.
 */

(function() {
    'use strict';

    function init() {
        const reportBtn = document.getElementById('report-issue-btn');
        const modal = document.getElementById('reportIssueModal');

        if (!reportBtn || !modal) return;

        // Open modal when button is clicked
        reportBtn.addEventListener('click', function() {
            if (typeof bootstrap !== 'undefined' && bootstrap.Modal) {
                const bsModal = new bootstrap.Modal(modal);
                bsModal.show();
            } else {
                modal.style.display = 'block';
                modal.classList.add('show');
            }
        });

        // Close modal when clicking outside
        modal.addEventListener('click', function(e) {
            if (e.target === modal) {
                closeModal(modal);
            }
        });
    }

    function closeModal(modal) {
        if (typeof bootstrap !== 'undefined' && bootstrap.Modal) {
            const bsModal = bootstrap.Modal.getInstance(modal);
            if (bsModal) bsModal.hide();
        } else {
            modal.style.display = 'none';
            modal.classList.remove('show');
        }
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }
})();
