import { useState, useEffect } from 'react';
import { t } from '../i18n/t';

export function OfflineIndicator() {
  const [isOffline, setIsOffline] = useState(!navigator.onLine);

  useEffect(() => {
    const handleOnline = () => setIsOffline(false);
    const handleOffline = () => setIsOffline(true);
    window.addEventListener('online', handleOnline);
    window.addEventListener('offline', handleOffline);
    return () => { window.removeEventListener('online', handleOnline); window.removeEventListener('offline', handleOffline); };
  }, []);

  if (!isOffline) return null;
  return <div className="offline-indicator"><span>⚠️</span><span>{t('offline.message')}</span></div>;
}
