/**
 * Screen Reader Support Module
 * Provides enhanced screen reader support
 */

(function() {
    'use strict';

    /**
     * Initialize screen reader support
     */
    function initScreenReaderSupport() {
        setupLiveRegions();
        setupNavigationAnnouncements();
        console.log('[Screen Reader Support] Initialized');
    }

    /**
     * Setup live regions for dynamic content
     */
    function setupLiveRegions() {
        // Create global live region if it doesn't exist
        if (!document.getElementById('sr-live-region')) {
            const liveRegion = document.createElement('div');
            liveRegion.id = 'sr-live-region';
            liveRegion.className = 'sr-only';
            liveRegion.setAttribute('role', 'status');
            liveRegion.setAttribute('aria-live', 'polite');
            liveRegion.setAttribute('aria-atomic', 'true');
            document.body.appendChild(liveRegion);
        }
    }

    /**
     * Setup navigation announcements
     */
    function setupNavigationAnnouncements() {
        // Announce page navigation
        const pageTitle = document.title;
        announceToScreenReader(`Page loaded: ${pageTitle}`);
    }

    /**
     * Announce message to screen readers
     */
    function announceToScreenReader(message) {
        const liveRegion = document.getElementById('sr-live-region');
        if (liveRegion) {
            liveRegion.textContent = message;
        }
    }

    // Export functions
    window.ScreenReader = {
        announce: announceToScreenReader
    };

    // Initialize on DOM ready
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', initScreenReaderSupport);
    } else {
        initScreenReaderSupport();
    }

})();
