import { ScrollView, View, Text, StyleSheet, Image } from "react-native"; import { SafeAreaView } from "react-native-safe-area-context"; import { Ionicons } from "@expo/vector-icons"; import { Redirect } from "expo-router"; import { COLORS } from "../constants/colors"; import { useApp } from "../context/AppContext"; import type { NotificationType } from "../services/tracking.service"; type Severity = "info" | "attention" | "important" | "critical"; const meta: Record< NotificationType, { severity: Severity; icon: keyof typeof Ionicons.glyphMap; color: string; bg: string; badge: string; } > = { ROUTE_START: { severity: "info", icon: "navigate", color: "#3B82F6", bg: "#EFF6FF", badge: "Informativo", }, TRUCK_PROXIMITY: { severity: "attention", icon: "time-outline", color: "#F59E0B", bg: "#FEF3C7", badge: "Atención", }, TRUCK_ARRIVED: { severity: "important", icon: "notifications", color: "#22C55E", bg: "#ECFDF5", badge: "Importante", }, ROUTE_COMPLETED: { severity: "info", icon: "checkmark-done", color: "#6B7280", bg: "#F3F4F6", badge: "Informativo", }, DELAY: { severity: "critical", icon: "warning-outline", color: "#EF4444", bg: "#FEF2F2", badge: "Crítico", }, MECHANICAL_FAILURE: { severity: "critical", icon: "warning", color: "#EF4444", bg: "#FEF2F2", badge: "Crítico", }, }; const STATUS_LABEL: Record = { EN_RUTA: { label: "ACTIVA", color: "#22C55E" }, DETENIDO: { label: "DETENIDO", color: "#F59E0B" }, FALLA: { label: "FALLA", color: "#EF4444" }, FINALIZADO: { label: "FINALIZADO", color: "#6B7280" }, ESPERA: { label: "EN ESPERA", color: "#6B7280" }, }; export default function AlertsScreen() { const { user, notifications, route } = useApp(); if (!user) return ; const statusInfo = STATUS_LABEL[route?.status ?? "ESPERA"] ?? STATUS_LABEL.ESPERA; return ( {/* Hero con título + count + camion image en banner azul */} Alertas {notifications.length}{" "} {notifications.length === 1 ? "notificación" : "notificaciones"} {/* Estado de ruta */} ESTADO DE RUTA: {statusInfo.label} {statusInfo.label === "ACTIVA" ? "El servicio de recolección sigue en curso." : "Sin servicio activo en este momento."} {/* Timeline de notificaciones */} {notifications.length === 0 ? ( Aún no hay alertas. Las recibirás cuando el camión avance en tu ruta. ) : ( {notifications.map((n, idx) => { const m = meta[n.type]; const isLast = idx === notifications.length - 1; const timeStr = new Date(n.createdAt).toLocaleTimeString( "es-MX", { hour: "2-digit", minute: "2-digit" }, ); return ( {/* Columna izquierda: dot + línea */} {!isLast && ( )} {timeStr} {/* Card */} {n.title} {m.badge} {n.body} ); })} )} {/* Consejo del día */} Consejo del día Separa correctamente tus residuos. Tu acción hace la diferencia. ); } const styles = StyleSheet.create({ heroSection: { backgroundColor: "#DBEAFE", paddingBottom: 0, marginBottom: 20, }, heroTextWrap: { paddingHorizontal: 20, paddingTop: 12, paddingBottom: 8, }, heroBanner: { height: 150, width: "100%", backgroundColor: "#DBEAFE", overflow: "hidden", }, headerTitle: { fontSize: 32, fontWeight: "800", color: "#0F172A", }, headerCount: { fontSize: 14, color: "#6B7280", marginTop: 2, }, truckImage: { width: "100%", height: "100%", }, statusBanner: { flexDirection: "row", alignItems: "center", marginHorizontal: 20, padding: 14, borderRadius: 14, marginBottom: 4, }, statusIcon: { width: 38, height: 38, borderRadius: 19, justifyContent: "center", alignItems: "center", marginRight: 12, }, statusTitle: { fontSize: 13, fontWeight: "800", }, statusBody: { fontSize: 12, color: "#374151", marginTop: 2, }, emptyBox: { alignItems: "center", padding: 40, marginHorizontal: 20, marginTop: 16, backgroundColor: "#FFFFFF", borderRadius: 14, }, emptyText: { fontSize: 13, color: "#6B7280", textAlign: "center", marginTop: 10, }, timelineRow: { flexDirection: "row", marginBottom: 14, }, timelineLeft: { width: 56, alignItems: "center", }, timelineDot: { width: 32, height: 32, borderRadius: 16, justifyContent: "center", alignItems: "center", }, timelineLine: { flex: 1, width: 2, marginTop: 2, marginBottom: 2, }, timelineTime: { fontSize: 10, color: "#9CA3AF", marginTop: 4, }, notifCard: { flex: 1, borderRadius: 14, padding: 14, marginLeft: 4, }, notifHeader: { flexDirection: "row", justifyContent: "space-between", alignItems: "flex-start", marginBottom: 6, }, notifTitle: { fontSize: 14, fontWeight: "800", color: "#0F172A", flex: 1, paddingRight: 8, }, badge: { paddingHorizontal: 8, paddingVertical: 3, borderRadius: 8, }, badgeText: { fontSize: 10, fontWeight: "700", }, notifBody: { fontSize: 13, color: "#374151", lineHeight: 18, }, tipCard: { flexDirection: "row", alignItems: "center", backgroundColor: "#ECFDF5", borderRadius: 16, padding: 14, marginHorizontal: 20, marginTop: 16, }, tipIcon: { width: 42, height: 42, borderRadius: 21, backgroundColor: "#FFFFFF", justifyContent: "center", alignItems: "center", marginRight: 12, }, tipTitle: { fontSize: 14, fontWeight: "800", color: "#065F46", marginBottom: 4, }, tipBody: { fontSize: 12, color: "#065F46", lineHeight: 16, }, tipImage: { width: 70, height: 70, marginLeft: 8, }, });