"use client"; import dynamic from "next/dynamic"; import { useMemo } from "react"; import { useDashboardStore, useHistoryData } from "@/hooks/useDashboardStore"; import { useI18n } from "@/hooks/useI18n"; import { ProFeaturePaywall } from "@/components/dashboard/ProFeaturePaywall"; import { getHistorySummary } from "@/lib/dashboard-utils"; const HistoryChart = dynamic( () => import("@/components/dashboard/HistoryChart").then( (module) => module.HistoryChart, ), { loading: () =>
, ssr: false, }, ); export function HistoryModal() { const store = useDashboardStore(); const { t, locale } = useI18n(); const { data, error, isLoading, isOpen, isRecordsLoading, meta } = useHistoryData(); const isPro = store.proAccess.subscriptionActive; const isProLoading = store.proAccess.loading; const isNoaaSettlement = store.selectedDetail?.current?.settlement_source === "noaa" || store.selectedDetail?.current?.settlement_source_label === "NOAA"; const noaaStationCode = String( store.selectedDetail?.current?.station_code || store.selectedDetail?.risk?.icao || "NOAA", ) .trim() .toUpperCase(); const noaaStationName = String(store.selectedDetail?.current?.station_name || "").trim() || String(store.selectedDetail?.risk?.airport || "").trim() || noaaStationCode; const summary = useMemo( () => getHistorySummary(data, store.selectedDetail?.local_date), [data, store.selectedDetail?.local_date], ); const settledPeakRows = useMemo( () => summary.recentData .filter( (row) => row.actual != null && row.actual_peak_time && row.deb_at_peak_minus_12h != null, ) .reverse(), [summary.recentData], ); const modelReferenceRows = useMemo( () => summary.recentData .filter( (row) => row.actual != null && row.model_reference?.available && (row.model_reference.models?.length || 0) > 0, ) .slice(-5) .reverse(), [summary.recentData], ); if (!isOpen) return null; return ({t("history.previewDesc")}