/**
 * Beispiel für die Verwendung des globalen Debug-Loggers
 * Kann als Referenz für andere Komponenten dienen
 */

import debugLogger from '../utils/debugLogger';

// Beispiel: Verwendung in einer API-Service
class ExampleService {
  async fetchData() {
    debugLogger.api('Fetching data from API...');
    
    try {
      debugLogger.time('API Request');
      const response = await fetch('/api/data');
      debugLogger.timeEnd('API Request');
      
      if (!response.ok) {
        debugLogger.error('API request failed:', response.status);
        throw new Error('API Error');
      }
      
      const data = await response.json();
      debugLogger.success('Data fetched successfully:', data);
      return data;
      
    } catch (error) {
      debugLogger.error('Error fetching data:', error);
      throw error;
    }
  }
}

// Beispiel: Verwendung in einer React-Komponente
function ExampleComponent() {
  const [data, setData] = useState(null);
  
  useEffect(() => {
    debugLogger.group('ExampleComponent Mount');
    debugLogger.routing('Component mounted with props:', { data });
    
    const loadData = async () => {
      try {
        const result = await new ExampleService().fetchData();
        setData(result);
        debugLogger.success('Component state updated');
      } catch (error) {
        debugLogger.error('Failed to load component data:', error);
      }
    };
    
    loadData();
    debugLogger.groupEnd();
  }, []);

  // Authentifizierung prüfen
  const checkAuth = () => {
    const token = localStorage.getItem('jwt');
    debugLogger.auth('Checking authentication status');
    
    if (!token) {
      debugLogger.warn('No authentication token found');
      return false;
    }
    
    debugLogger.auth('Authentication token present');
    return true;
  };

  return (
    <div>
      {/* Component JSX */}
    </div>
  );
}

export { ExampleService, ExampleComponent };
