import { useMemo } from "react"; import { Group, Popover, Stack, Text, UnstyledButton } from "@mantine/core"; import { IconArrowDownRight, IconArrowUpRight, IconDroplets, IconMapPin, IconWind } from "@tabler/icons-react"; import { useCurrentIntlLocale, useI18n } from "@homarr/translation/client"; import { zoomCompensatedSize } from "@homarr/ui"; import type { WidgetProps } from "../definition"; import { AnimatedWeatherIcon } from "./animated-icon"; import classes from "./component.module.css"; import { DailyWeatherDetails } from "./details"; import type { WeatherData } from "./format"; import { getPreferredDate, getPreferredUnit, getPreferredWindSpeed } from "./format"; import { formatWeatherDate, WeatherDescription } from "./icon"; import { getCompactWeatherLayout } from "./layout"; interface CompactWeatherProps { height: number; isEditMode: boolean; options: WidgetProps<"weather">["options"]; weather: WeatherData; width: number; } export const CompactWeather = ({ height, isEditMode, options, weather, width }: CompactWeatherProps) => { const locale = useCurrentIntlLocale(); const t = useI18n("widget.weather"); const tCommon = useI18n("common"); const layout = useMemo( () => getCompactWeatherLayout(width, height, options.hasForecast, options.forecastDayCount), [height, options.forecastDayCount, options.hasForecast, width], ); const today = weather.daily[0]; const speedUnit = options.useImperialSpeed ? tCommon("unit.speed.milesPerHour") : tCommon("unit.speed.kilometersPerHour"); const contentGap = layout.tier === "micro" ? 2 : 4; const contentPadding = layout.tier === "roomy" ? "xs" : 4; return ( {getPreferredUnit( weather.current.temperature, options.isFormatFahrenheit, options.disableTemperatureDecimals, )} {layout.showCondition && } {layout.showHighLow && today && ( {getPreferredUnit(today.maxTemperature, options.isFormatFahrenheit, options.disableTemperatureDecimals)} {getPreferredUnit(today.minTemperature, options.isFormatFahrenheit, options.disableTemperatureDecimals)} )} {layout.showSecondary && !options.hasForecast && ( {options.showHumidity && ( {weather.current.relativeHumidity}% )} {options.showCurrentWindSpeed && ( {getPreferredWindSpeed(weather.current.windSpeed, options.useImperialSpeed)} {speedUnit} )} )} {layout.forecastDays > 0 && ( {weather.daily.slice(0, layout.forecastDays).map((day, index) => ( {getPreferredDate(day.date, locale, { weekday: "short" })} {getPreferredUnit( day.maxTemperature, options.isFormatFahrenheit, options.disableTemperatureDecimals, )} ))} )} {layout.showCity && options.showCity && ( {options.location.name} )} ); };