import type { ReactNode } from 'react' import { useQuery } from '@tanstack/react-query' import type { WidgetConfig } from '../../hooks' import { weatherApi } from '../../api' type IconProps = { className?: string } const IconBase = ({ className, children }: IconProps & { children: ReactNode }) => ( {children} ) const SunIcon = ({ className }: IconProps) => ( ) const CloudIcon = ({ className }: IconProps) => ( ) const PartlyCloudyIcon = ({ className }: IconProps) => ( ) const FogIcon = ({ className }: IconProps) => ( ) const RainIcon = ({ className }: IconProps) => ( ) const SnowIcon = ({ className }: IconProps) => ( ) const ThunderIcon = ({ className }: IconProps) => ( ) const ThermometerIcon = ({ className }: IconProps) => ( ) const DropletIcon = ({ className }: IconProps) => ( ) const WindIcon = ({ className }: IconProps) => ( ) const CloudCoverIcon = ({ className }: IconProps) => ( ) const RainDropIcon = ({ className }: IconProps) => ( ) interface WeatherWidgetProps { config: WidgetConfig } export default function WeatherWidget({ config }: WeatherWidgetProps) { // Get city from config or use default const city = (config.visualization as Record)?.city as string || 'Skopje' const { data: weather, isLoading, error } = useQuery({ queryKey: ['weather', city], queryFn: async () => { const response = await weatherApi.getCurrent({ city }) return response.data }, refetchInterval: 300000, // Refresh every 5 minutes staleTime: 240000, // Consider fresh for 4 minutes }) if (isLoading) { return (
) } if (error) { return (

{config.title}

Failed to load weather data

) } if (!weather) return null const getWeatherIcon = (code: number) => { if (code === 0 || code === 1) return if (code === 2) return if (code === 3) return if (code >= 45 && code <= 48) return if (code >= 51 && code <= 55) return if (code >= 61 && code <= 65) return if (code >= 71 && code <= 77) return if (code >= 80 && code <= 82) return if (code >= 85 && code <= 86) return if (code >= 95) return return } return (

{config.title}

{/* Weather Icon */}
{getWeatherIcon(weather.weather_code)}
{/* Temperature */}
{weather.temperature.toFixed(1)}°C
Feels like {weather.apparent_temperature.toFixed(1)}°C
{/* Weather Description */}
{weather.weather_description}
{/* Additional Info */}
{weather.humidity}%
{weather.wind_speed.toFixed(1)} km/h
{weather.cloud_cover}%
{weather.precipitation > 0 && (
{weather.precipitation} mm
)}
{/* Location */}
{weather.location}
) }