/**
 * View Script for Reviews Block
 * Handles Modal & Load More
 * Fixed: Robust button hiding logic
 */

document.addEventListener('DOMContentLoaded', () => {

    // --- 1. Read More Modal Logic ---
    const modal = document.getElementById('awt-review-modal');
    const modalText = document.getElementById('awt-modal-text');
    const modalClose = document.getElementById('awt-modal-close');
    const modalBackdrop = document.getElementById('awt-modal-backdrop');

    if (modal) {
        document.body.addEventListener('click', (e) => {
            if (e.target.closest('.awt-read-more-btn')) {
                const btn = e.target.closest('.awt-read-more-btn');
                const contentId = btn.getAttribute('data-content-id');
                const template = document.getElementById(contentId);

                if (template && modalText) {
                    modalText.innerHTML = template.innerHTML;
                    modal.classList.remove('hidden');
                    requestAnimationFrame(() => {
                        modal.classList.remove('opacity-0');
                        document.body.style.overflow = 'hidden';
                    });
                }
            }
        });

        const closeModal = () => {
            modal.classList.add('opacity-0');
            setTimeout(() => {
                modal.classList.add('hidden');
                document.body.style.overflow = '';
            }, 300);
        };
        if (modalClose) modalClose.addEventListener('click', closeModal);
        if (modalBackdrop) modalBackdrop.addEventListener('click', closeModal);
    }


});