import { useState, useEffect } from 'react';
import { fetchCurrentWeather } from '@/services/weatherService';

export function useWeather(lat: number | null, lng: number | null) {
  const [weather, setWeather] = useState({ temp: '--', icon: 'cloud-outline' });
  const [loading, setLoading] = useState(false);

  useEffect(() => {
    if (lat && lng) {
      setLoading(true);
      fetchCurrentWeather(lat, lng)
        .then(setWeather)
        .finally(() => setLoading(false));
    }
  }, [lat, lng]);

  return { weather, loading };
}
