import { useCallback } from 'react';

/**
 * Custom hook for managing screen reader announcements
 * Creates temporary live region elements to announce messages to assistive technologies
 */
export function useScreenReaderAnnouncements() {
  const announce = useCallback((message: string) => {
    const announcement = document.createElement('div');
    announcement.setAttribute('aria-live', 'polite');
    announcement.setAttribute('aria-atomic', 'true');
    announcement.setAttribute('class', 'sr-only');
    announcement.textContent = message;

    document.body.appendChild(announcement);
    setTimeout(() => {
      announcement.remove();
    }, 1000);
  }, []);

  return { announce };
}
