From 894e67863dbb89a4819e825fcdf7117021082b2a Mon Sep 17 00:00:00 2001
From: Ariel Costas Guerrero <ariel@costas.dev>
Date: Tue, 24 Jun 2025 13:29:50 +0200
Subject: Replace leaflet for maplibre, use react-router in framework mode

---
 src/frontend/app/components/GroupedTable.tsx | 74 ++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100644 src/frontend/app/components/GroupedTable.tsx

(limited to 'src/frontend/app/components/GroupedTable.tsx')

diff --git a/src/frontend/app/components/GroupedTable.tsx b/src/frontend/app/components/GroupedTable.tsx
new file mode 100644
index 0000000..3a16d89
--- /dev/null
+++ b/src/frontend/app/components/GroupedTable.tsx
@@ -0,0 +1,74 @@
+import { type StopDetails } from "../routes/estimates-$id";
+import LineIcon from "./LineIcon";
+
+interface GroupedTable {
+    data: StopDetails;
+    dataDate: Date | null;
+}
+
+export const GroupedTable: React.FC<GroupedTable> = ({ data, dataDate }) => {
+    const formatDistance = (meters: number) => {
+        if (meters > 1024) {
+            return `${(meters / 1000).toFixed(1)} km`;
+        } else {
+            return `${meters} m`;
+        }
+    }
+
+    const groupedEstimates = data.estimates.reduce((acc, estimate) => {
+        if (!acc[estimate.line]) {
+            acc[estimate.line] = [];
+        }
+        acc[estimate.line].push(estimate);
+        return acc;
+    }, {} as Record<string, typeof data.estimates>);
+
+    const sortedLines = Object.keys(groupedEstimates).sort((a, b) => {
+        const firstArrivalA = groupedEstimates[a][0].minutes;
+        const firstArrivalB = groupedEstimates[b][0].minutes;
+        return firstArrivalA - firstArrivalB;
+    });
+
+    return <table className="table">
+        <caption>Estimaciones de llegadas a las {dataDate?.toLocaleTimeString()}</caption>
+
+        <thead>
+            <tr>
+                <th>Línea</th>
+                <th>Ruta</th>
+                <th>Llegada</th>
+                <th>Distancia</th>
+            </tr>
+        </thead>
+
+        <tbody>
+            {sortedLines.map((line) => (
+                groupedEstimates[line].map((estimate, idx) => (
+                    <tr key={`${line}-${idx}`}>
+                        {idx === 0 && (
+                            <td rowSpan={groupedEstimates[line].length}>
+                                <LineIcon line={line} />
+                            </td>
+                        )}
+                        <td>{estimate.route}</td>
+                        <td>{`${estimate.minutes} min`}</td>
+                        <td>
+                            {estimate.meters > -1
+                                ? formatDistance(estimate.meters)
+                                : "No disponible"
+                            }
+                        </td>
+                    </tr>
+                ))
+            ))}
+        </tbody>
+
+        {data?.estimates.length === 0 && (
+            <tfoot>
+                <tr>
+                    <td colSpan={4}>No hay estimaciones disponibles</td>
+                </tr>
+            </tfoot>
+        )}
+    </table>
+}
-- 
cgit v1.3

