import React from 'react';
import { getWeatherConditionType, shouldShowSun, isPartlyCloudy } from '../services/weatherService';
import Sun from './weather3d/Sun';
import Moon from './weather3d/Moon';
import Clouds from './weather3d/Clouds';
import Rain from './weather3d/Rain';
import Snow from './weather3d/Snow';
import Storm from './weather3d/Storm';
import { Text } from '@react-three/drei';
const WeatherVisualization = ({ weatherData, isLoading, portalMode = false }) => {
// Check if it's nighttime based on local time
const isNightTime = () => {
if (!weatherData?.location?.localtime) return false;
const localTime = weatherData.location.localtime;
const currentHour = new Date(localTime).getHours();
return currentHour >= 19 || currentHour <= 6; // 7 PM to 6 AM is night
};
const isNight = isNightTime();
const currentCondition = weatherData?.current?.condition?.text;
const weatherType = currentCondition ? getWeatherConditionType(currentCondition) : null;
if (isLoading || !weatherData) {
return null;
}
const renderWeatherEffect = () => {
const partlyCloudy = isPartlyCloudy(currentCondition);
if (weatherType === 'sunny') {
if (partlyCloudy) {
return (
<>
{isNight ? : }
>
);
}
return isNight ? : ;
} else if (weatherType === 'cloudy') {
if (partlyCloudy) {
return (
<>
{isNight ? : }
>
);
}
return (
);
} else if (weatherType === 'rainy') {
return (
<>
>
);
} else if (weatherType === 'snowy') {
return (
<>
>
);
} else if (weatherType === 'stormy') {
return ;
} else if (weatherType === 'foggy') {
return ;
} else {
if (partlyCloudy) {
return (
<>
{isNight ? : }
>
);
}
return isNight ? : ;
}
};
return (
{renderWeatherEffect()}
{!portalMode && (
{currentCondition}
)}
);
};
export default WeatherVisualization;