import { useEffect, useState } from "react"; import { motion, useReducedMotion } from "motion/react"; import { ArrowUpRight, CheckCircle2, CircleHelp, Clock3, LoaderCircle, TriangleAlert } from "lucide-react"; import { cn } from "@/shared/ui/cn"; import { StatusIcon, type StatusTone } from "@/shared/ui/status"; import { Button } from "@/shared/ui/button"; import type { ScadaMonitoringResult } from "../api/scada-replay-client"; export function ScadaMonitoringNotice({ result, animationId, processing, onOpenInvestigation }: { result: ScadaMonitoringResult | null | undefined; animationId: string | null; processing: boolean; onOpenInvestigation?: (taskId: string) => void; }) { const reduced = useReducedMotion(); const [animating, setAnimating] = useState(false); useEffect(() => { if (!animationId || reduced) return; setAnimating(true); const timer = window.setTimeout(() => setAnimating(false), 2600); return () => window.clearTimeout(timer); }, [animationId, reduced]); const recovered = result?.incident?.action === "resolved"; const ongoing = result?.incident?.action === "ongoing"; const abnormal = Boolean(result && !recovered && (result.task_id || ["attention", "suspected_burst"].includes(result.status))); const suspectedBurst = abnormal && result?.status === "suspected_burst"; const normal = result?.status === "normal" || recovered; const tone: StatusTone = suspectedBurst ? "danger" : abnormal ? "warning" : normal ? "success" : processing ? "info" : "neutral"; const Icon = !result ? processing ? LoaderCircle : Clock3 : abnormal ? TriangleAlert : normal ? CheckCircle2 : CircleHelp; const title = !result ? processing ? "正在监测" : "监测待机" : recovered ? "异常已恢复" : ongoing ? "异常持续跟踪" : suspectedBurst ? "发现疑似爆管" : abnormal ? "发现指标异常" : normal ? "监测正常" : "监测数据不足"; const note = !result ? processing ? "正在核对本周期数据" : "等待播放或单步监测" : result.task_id ? recovered ? "告警已解除" : ongoing ? "沿用原调查" : "已启动调查" : normal ? "本周期未发现异常" : abnormal ? "请留意后续监测结果" : "暂无法形成监测结论"; const hint = processing ? result ? "正在监测下一周期" : "处理完成后更新结果" : abnormal ? "诊断详情见调查报告" : recovered ? "可回看本次调查" : result && !normal ? "待后续周期继续监测" : "异常时自动启动调查"; const emphasis = animating && abnormal && !reduced; return (
{emphasis ?
); }