import React from 'react'; import { Box, Typography, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Paper, Slider, Checkbox } from '@mui/material'; import { useFeedStore } from '../../store/feedStore'; export const AnomalyTable: React.FC = () => { const { tabs, selectedTabIndex, updateTab } = useFeedStore(); if (tabs.length === 0 || selectedTabIndex < 0) { return Loading feeds...; } const activeTab = tabs[selectedTabIndex]; const anomalies = activeTab.anomalies || []; if (anomalies.length === 0) { return ( No anomalies found for the selected criteria. ); } const handleRowClick = (index: number) => { updateTab(selectedTabIndex, { selectedAnomalyIndex: index }); }; const getRowColor = (index: number, _asset: string) => { // Dark mode colors for table rows const colors = ['rgba(255, 255, 255, 0.03)', 'rgba(255, 255, 255, 0.0)']; return colors[index % colors.length]; }; return ( #ID PLAZA ROAD DATE CHAINAGE LAT/LONG ANOMALY SIDE ANOMALY True/False FEATURES COMMENTS CHECKED AUTO AUDIT {anomalies.map((anomaly: any, index: number) => { const isSelected = activeTab.selectedAnomalyIndex === index; const assetName = anomaly?.Asset?.replace(/_/gi, ' ') || 'Unknown Asset'; const rowColor = getRowColor(index, assetName); // Parse Position let latStr = 'N/A'; let longStr = 'E/A'; if (anomaly?.Pos) { const match = String(anomaly.Pos).match(/([NS][0-9.]+)([EW][0-9.]+)/i); if (match) { latStr = match[1]; longStr = match[2]; } else { latStr = anomaly.Pos; // Fallback longStr = ''; } } return ( handleRowClick(index)} sx={{ bgcolor: isSelected ? 'rgba(59, 130, 246, 0.2)' : rowColor, cursor: 'pointer', '&:hover': { bgcolor: 'rgba(255,255,255,0.08)' }, borderLeft: isSelected ? '4px solid #3b82f6' : '4px solid transparent', mb: 1, }} > #{anomaly.id || anomaly._id?.substring(0, 7) || 'N/A'} {anomaly.Plaza || 'N/A'} {anomaly.road || anomaly.Road || 'N/A'} {anomaly.Created_on ? new Date(anomaly.Created_on).toLocaleDateString() : 'N/A'} {anomaly.Chainage || 'N/A'} {latStr}
{longStr}
{assetName} {anomaly.Side || 'N/A'} {anomaly.Features || 'N/A'} {anomaly.Comments || '-'}
); })}
); };