import { useMemo, useState } from "react"; import Box from "@mui/material/Box"; import Stack from "@mui/material/Stack"; import { useTranslation } from "react-i18next"; import type { Monitor } from "@/Types/Monitor"; import type { StatusPage } from "@/Types/StatusPage"; import { getMonitorTypeLabel } from "@/Types/StatusPage"; import { ThemedHeatmap } from "../shared/ThemedHeatmap"; import { ThemedHistogram } from "../shared/ThemedHistogram"; import { ThemedInfrastructure } from "../shared/ThemedInfrastructure"; import { monitorBadgeTone, monoFirstChar, resolveOverallStatus, statusBadgeKey, } from "../shared/overallStatus"; import { useStatusPageTheme } from "../StatusPageThemeProvider"; import { refinedStyles } from "./styles"; type StatusPageMonitor = Monitor & { checks?: Monitor["recentChecks"] }; interface Props { statusPage: StatusPage; monitors: StatusPageMonitor[]; } export const RefinedStatusPage = ({ statusPage, monitors }: Props) => { const { t } = useTranslation(); const { tokens } = useStatusPageTheme(); const styles = useMemo(() => refinedStyles(tokens), [tokens]); const [chartMode, setChartMode] = useState<"heatmap" | "histogram">("heatmap"); const overall = resolveOverallStatus(monitors, t); const logoSrc = statusPage.logo?.data ? `data:${statusPage.logo.contentType};base64,${statusPage.logo.data}` : null; return ( {logoSrc ? ( ) : ( {monoFirstChar(statusPage.companyName)} )} {statusPage.companyName} {overall.message} {t("pages.statusPages.statusBar.monitoringSummary", { count: monitors.length, })} {overall.icon} {statusPage.showCharts && ( setChartMode("heatmap")} sx={styles.chartSwitchButton(chartMode === "heatmap")} > {t("pages.statusPages.monitorsList.chartTypeHeatmap")} setChartMode("histogram")} sx={styles.chartSwitchButton(chartMode === "histogram")} > {t("pages.statusPages.monitorsList.chartTypeHistogram")} )} {monitors.map((monitor) => { const isHardware = monitor.type === "hardware"; const showInfra = isHardware && statusPage.showInfrastructure !== false; const showChart = !isHardware && statusPage.showCharts !== false; const badgeTone = monitorBadgeTone(monitor.status); return ( {monitor.name} {getMonitorTypeLabel(monitor.type, t)} {monitor.url && ( {monitor.url} )} {t(statusBadgeKey[monitor.status])} {showInfra && ( )} {showChart && (chartMode === "heatmap" ? ( ) : ( ))} ); })} {t("pages.statusPages.footer.poweredBy")}{" "} Checkmate ); };