import { Group, Stack, Text } from '@mantine/core'; import { WeatherModal } from 'components'; import { useEffect, useState } from 'react'; import { textClasses } from 'styles'; function Header({ greet, date, isMobile, current, setCurrent, weather, basicWeather, outlook, hourly, weatherModalOpened, closeWeatherModal, openWeatherModal, setValue, setProviderLabel, setProviderURL, }: any) { const [time, setTime] = useState(new Date()); function fixDigits(k: any) { if (k < 10) { return `0${k}`; } return k; } useEffect(() => { setInterval(() => { const nwDate = new Date(); setTime(nwDate); }, 1000); }, []); useEffect(() => { if (weather && basicWeather) { setCurrent({ icon: weather.features[0].properties.icon?.replace('medium', 'large') || '', temperature: Math.round( (weather.features[0].properties.temperature.value * 9) / 5 + 32, ), highTemp: Math.round( (basicWeather.properties.maxTemperature.values[0].value * 9) / 5 + 32, ), lowTemp: Math.round( (basicWeather.properties.minTemperature.values[0].value * 9) / 5 + 32, ), precipitation: weather.features[0].properties.precipitationLastHour.value || 'N/A', humidity: Math.round(weather.features[0].properties.relativeHumidity.value), heatIndex: Math.round( (weather.features[0].properties.heatIndex.value * 9) / 5 + 32, ), windSpeed: Math.round(weather.features[0].properties.windSpeed.value / 1.60934), windDirection: weather.features[0].properties.windDirection.value, }); } }, [weather, basicWeather]); return ( {greet} {date} {current.temperature}°F {current.highTemp}°F/{current.lowTemp}°F {`${ time.getHours() === 0 ? 12 : time.getHours() > 12 ? time.getHours() - 12 : time.getHours() }:${fixDigits(time.getMinutes())} ${time.getHours() >= 12 ? 'PM' : 'AM'}`} ); } export default Header;