{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "use-weather",
  "type": "registry:hook",
  "files": [
    {
      "path": "registry/default/hooks/use-weather.ts",
      "content": "import { useState, useEffect } from \"react\";\n\ninterface HourlyData {\n  time: string[];\n  temperature: number[];\n  weatherCode: number[];\n}\n\ninterface DailyData {\n  time: string[];\n  temperatureMax: number[];\n  temperatureMin: number[];\n  weatherCode: number[];\n}\n\ninterface WeatherData {\n  temperature: number;\n  humidity: number;\n  windSpeed: number;\n  feelsLike: number;\n  chanceOfRain: number;\n  weatherCode: number;\n  isDay: boolean;\n  hourly: HourlyData;\n  daily: DailyData;\n}\n\nexport function useWeather(lat: number | null, lon: number | null) {\n  const [data, setData] = useState<WeatherData | null>(null);\n  const [error, setError] = useState<string | null>(null);\n  const [isLoading, setIsLoading] = useState<boolean>(false);\n\n  useEffect(() => {\n    if (lat === null || lon === null) return;\n\n    const fetchWeather = async () => {\n      setIsLoading(true);\n      try {\n        const response = await fetch(\n          `https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}&current=temperature_2m,relative_humidity_2m,apparent_temperature,precipitation,rain,weather_code,wind_speed_10m,is_day&hourly=temperature_2m,weather_code&daily=weather_code,temperature_2m_max,temperature_2m_min&forecast_days=7`,\n        );\n        if (!response.ok) {\n          throw new Error(\"Failed to fetch weather data\");\n        }\n        const result = await response.json();\n\n        setData({\n          temperature: Math.round(result.current.temperature_2m),\n          humidity: result.current.relative_humidity_2m,\n          windSpeed: result.current.wind_speed_10m,\n          feelsLike: Math.round(result.current.apparent_temperature),\n          chanceOfRain: result.current.precipitation,\n          weatherCode: result.current.weather_code,\n          isDay: result.current.is_day === 1,\n          hourly: {\n            time: result.hourly.time,\n            temperature: result.hourly.temperature_2m.map((t: number) =>\n              Math.round(t),\n            ),\n            weatherCode: result.hourly.weather_code,\n          },\n          daily: {\n            time: result.daily.time,\n            temperatureMax: result.daily.temperature_2m_max.map((t: number) =>\n              Math.round(t),\n            ),\n            temperatureMin: result.daily.temperature_2m_min.map((t: number) =>\n              Math.round(t),\n            ),\n            weatherCode: result.daily.weather_code,\n          },\n        });\n      } catch (err: any) {\n        setError(err.message);\n      } finally {\n        setIsLoading(false);\n      }\n    };\n\n    fetchWeather();\n  }, [lat, lon]);\n\n  return { data, error, isLoading };\n}\n",
      "type": "registry:hook"
    }
  ]
}