/* ==================================================
   Nuclear Fancy Pants Edition™ — NUCLEAR+++
   File: /assets/js/amai-facebook.js
   Description: Facebook module JavaScript — page picker and dashboard interactions
   Last Edited: 2026-03-25
   ================================================== */

(function () {
    'use strict';

    // ---- Page picker ----
    const cards      = document.querySelectorAll('.amai-fb-page-card');
    const pageIdInput = document.getElementById('amai-selected-page-id');
    const selectBtn  = document.getElementById('amai-fb-select-btn');

    if (cards.length && pageIdInput && selectBtn) {
        cards.forEach(function (card) {
            card.addEventListener('click', function () {
                cards.forEach(function (c) { c.classList.remove('selected'); });
                card.classList.add('selected');
                pageIdInput.value = card.dataset.pageId || '';
                selectBtn.disabled = false;
            });

            card.addEventListener('keydown', function (e) {
                if (e.key === 'Enter' || e.key === ' ') {
                    e.preventDefault();
                    card.click();
                }
            });
        });
    }
})();