import React, { useState } from 'react';
import {
Card, Row, Col, Statistic, Table, Select, Input, Tag,
Typography, Button
} from 'antd';
import {
CloudOutlined, CheckCircleOutlined, WarningOutlined,
MinusCircleOutlined, ThunderboltOutlined,
RiseOutlined, SunOutlined, BarChartOutlined
} from '@ant-design/icons';
import { Line, Bar, Pie } from '@ant-design/charts';
const { Option } = Select;
const { Search } = Input;
const { Text, Title } = Typography;
// 模拟数据
const deviceList = [
{ id: 1, name: '摄像头 CAM-01', type: '摄像头', status: '正常', data: '35.2 ℃', communication: '通讯正常', updateTime: '2026-04-28 11:32:45' },
{ id: 2, name: '摄像头 CAM-02', type: '摄像头', status: '离线', data: '-', communication: '通讯离线', updateTime: '2026-04-28 12:10:00' },
{ id: 3, name: '摄像头 CAM-03', type: '摄像头', status: '正常', data: '33.9 ℃', communication: '通讯正常', updateTime: '2026-04-28 11:32:45' },
{ id: 4, name: '汇流箱 CMB-A01', type: '汇流箱', status: '预警', data: '46.3 ℃', communication: '通讯正常', updateTime: '2026-04-28 11:32:45' },
{ id: 5, name: '汇流箱 CMB-A02', type: '汇流箱', status: '正常', data: '41.1 ℃', communication: '通讯正常', updateTime: '2026-04-28 11:32:45' },
{ id: 6, name: '逆变器 INV-A01', type: '逆变器', status: '正常', data: '66.8 kW', communication: '通讯正常', updateTime: '2026-04-28 12:00:00' },
{ id: 7, name: '逆变器 INV-A02', type: '逆变器', status: '预警', data: '54.2 kW', communication: '通讯正常', updateTime: '2026-04-28 12:05:00' },
{ id: 8, name: '逆变器 INV-B01', type: '逆变器', status: '正常', data: '22.4 kW', communication: '通讯正常', updateTime: '2026-04-28 11:32:45' },
{ id: 9, name: '电表 METER-01', type: '电表', status: '正常', data: '66.8 kW', communication: '通讯正常', updateTime: '2026-04-28 11:32:45' }
];
// 👇 改成两天对比数据
const powerTrendData = [
{ time: '00:00', value: 13.4, type: '今日' },
{ time: '00:00', value: 12.1, type: '昨日' },
{ time: '00:00', value: 1000, type: '额定' },
{ time: '04:00', value: 15.7, type: '今日' },
{ time: '04:00', value: 14.3, type: '昨日' },
{ time: '04:00', value: 1000, type: '额定' },
{ time: '08:00', value: 220.5, type: '今日' },
{ time: '08:00', value: 200.8, type: '昨日' },
{ time: '08:00', value: 1000, type: '额定' },
{ time: '12:00', value: 350.2, type: '今日' },
{ time: '12:00', value: 320.5, type: '昨日' },
{ time: '12:00', value: 1000, type: '额定' },
{ time: '16:00', value: 280.7, type: '今日' },
{ time: '16:00', value: 260.3, type: '昨日' },
{ time: '16:00', value: 1000, type: '额定' },
{ time: '20:00', value: 13.4, type: '今日' },
{ time: '20:00', value: 11.9, type: '昨日' },
{ time: '20:00', value: 1000, type: '额定' },
{ time: '24:00', value: 10.2, type: '今日' },
{ time: '24:00', value: 9.8, type: '昨日' },
{ time: '24:00', value: 1000, type: '额定' },
];
const inverterPowerData = [
{ name: 'INV-01', power: 164.2 },
{ name: 'INV-02', power: 166.8 },
{ name: 'INV-03', power: 162.1 },
{ name: 'INV-04', power: 159.7 },
{ name: 'INV-05', power: 159.8 }
];
const heatmapData = [
['#1677ff', '#52c41a', '#1677ff', '#faad14', '#52c41a', '#1677ff', '#faad14', '#1677ff', '#1677ff', '#52c41a', '#1677ff', '#1677ff'],
['#52c41a', '#1677ff', '#faad14', '#52c41a', '#1677ff', '#faad14', '#1677ff', '#1677ff', '#52c41a', '#1677ff', '#1677ff', '#52c41a'],
['#1677ff', '#faad14', '#52c41a', '#1677ff', '#faad14', '#1677ff', '#1677ff', '#52c41a', '#1677ff', '#1677ff', '#1677ff', '#52c41a'],
['#faad14', '#52c41a', '#1677ff', '#faad14', '#1677ff', '#1677ff', '#52c41a', '#1677ff', '#1677ff', '#52c41a', '#1677ff', '#faad14'],
['#52c41a', '#1677ff', '#faad14', '#1677ff', '#1677ff', '#52c41a', '#1677ff', '#1677ff', '#52c41a', '#1677ff', '#faad14', '#52c41a']
];
const OnlineRateData = [
{ type: '在线', value: 12 },
{ type: '离线', value: 1 },
{ type: '告警', value: 2 },
{ type: '总数', value: 13 }
];
const RealTimeMonitorPage = () => {
const [loading, setLoading] = useState(false);
const [filterStatus, setFilterStatus] = useState('all');
const [filterType, setFilterType] = useState(undefined);
const [searchName, setSearchName] = useState('');
const filteredList = deviceList.filter(item => {
if (filterStatus === 'all') return true;
if (filterStatus === 'normal') return item.status === '正常';
if (filterStatus === 'warning') return item.status === '预警';
if (filterStatus === 'offline') return item.status === '离线';
return true;
}).filter(item => !filterType || item.type === filterType)
.filter(item => !searchName || item.name.includes(searchName));
const getStatusTag = (status) => {
switch (status) {
case '正常': return