"use client"; import clsx from "clsx"; import dynamic from "next/dynamic"; import { useEffect } from "react"; import styles from "./Dashboard.module.css"; import detailChromeStyles from "./DetailPanelChrome.module.css"; import modalChromeStyles from "./ModalChrome.module.css"; import { DashboardStoreProvider, useDashboardStore, } from "@/hooks/useDashboardStore"; import { I18nProvider, useI18n } from "@/hooks/useI18n"; import { CitySidebar } from "@/components/dashboard/CitySidebar"; import { DetailPanel } from "@/components/dashboard/DetailPanel"; import { HeaderBar } from "@/components/dashboard/HeaderBar"; const loadHistoryModal = () => import("@/components/dashboard/HistoryModal").then( (module) => module.HistoryModal, ); const loadFutureForecastModal = () => import("@/components/dashboard/FutureForecastModal").then( (module) => module.FutureForecastModal, ); const MapCanvas = dynamic( () => import("@/components/dashboard/MapCanvas").then((module) => module.MapCanvas), { ssr: false, loading: () =>
, }, ); const HistoryModal = dynamic( loadHistoryModal, { ssr: false, loading: () => null, }, ); const FutureForecastModal = dynamic( loadFutureForecastModal, { ssr: false, loading: () => null, }, ); function DashboardScreen() { const store = useDashboardStore(); const { t } = useI18n(); const activeSummary = store.selectedCity ? store.citySummariesByName[store.selectedCity] || null : null; const activeCityName = store.selectedDetail?.display_name || activeSummary?.display_name || store.cities.find((city) => city.name === store.selectedCity)?.display_name || store.selectedCity || ""; useEffect(() => { const onKeyDown = (event: KeyboardEvent) => { if (event.key !== "Escape") return; if (store.futureModalDate) { store.closeFutureModal(); return; } if (store.historyState.isOpen) { store.closeHistory(); return; } if (store.isPanelOpen) { store.closePanel(); } }; window.addEventListener("keydown", onKeyDown); return () => { window.removeEventListener("keydown", onKeyDown); }; }, [store]); // Avoid full-page flashing on initial load; only show this overlay for manual refresh. const showLoading = store.loadingState.cities || store.loadingState.refresh; const showCitySyncToast = store.loadingState.cityDetail && activeCityName && !store.selectedDetail && !activeSummary; return (