"use client" import { useEffect, useRef, useState } from "react" import { Thermometer } from "lucide-react" import { Badge } from "./ui/badge" import { AreaChart, Area, ResponsiveContainer, Tooltip } from "recharts" import { fetchApi } from "@/lib/api-config" import { useDiskTempThresholds } from "@/lib/health-thresholds" interface TempPoint { timestamp: number value: number } interface DiskTemperatureCardProps { diskName: string liveTemperature: number /** Disk class — "HDD" | "SSD" | "NVMe" | "SAS". Drives the threshold colors. */ diskType: string /** Click handler — opens the full timeframe-selector modal as drill-down. */ onOpenDetail?: () => void } // Disk-temperature thresholds come from the user-configurable backend // (lib/health-thresholds.ts). The classifier here takes the resolved // pair so the consumer can read it from the hook once per render. function statusFor(temp: number, t: { warn: number; hot: number }) { if (temp <= 0) return { label: "N/A", className: "bg-gray-500/10 text-gray-500 border-gray-500/20", color: "#6b7280" } if (temp >= t.hot) return { label: "Hot", className: "bg-red-500/10 text-red-500 border-red-500/20", color: "#ef4444" } if (temp >= t.warn) return { label: "Warm", className: "bg-yellow-500/10 text-yellow-500 border-yellow-500/20", color: "#f59e0b" } return { label: "Normal", className: "bg-green-500/10 text-green-500 border-green-500/20", color: "#22c55e" } } const MiniTooltip = ({ active, payload }: any) => { if (active && payload && payload.length) { const ts = payload[0].payload?.timestamp const date = ts ? new Date(ts * 1000) : null return (
{date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" })}
)}{payload[0].value}°C
Temperature
{tempDisplay}