import React from "react"; import { View, Text, StyleSheet, Platform } from "react-native"; import { Ionicons } from "@expo/vector-icons"; import { useThemeContext } from "@/hooks/use-theme-context"; import { useI18n } from "@/hooks/use-i18n"; import SectionCard from "./SectionCard"; interface AlertsSectionProps { alerts?: Model.Alarm[]; } export default function AlertsSection({ alerts = [] }: AlertsSectionProps) { const { t } = useI18n(); const { colors } = useThemeContext(); const getAlertLevelColor = (level?: number) => { const isDark = colors.background === "#1C1C1E" || colors.background === "#000000" || colors.background?.toLowerCase().includes("1c1c1e"); switch (level) { case 0: // Bình thường - Blue/Info return isDark ? { bg: "#172554", text: "#93C5FD" } // Dark blue : { bg: "#DBEAFE", text: "#1E40AF" }; case 1: // Warning - Yellow return isDark ? { bg: "#422006", text: "#FCD34D" } // Dark amber : { bg: "#FEF3C7", text: "#92400E" }; case 2: // Error - Red return isDark ? { bg: "#450A0A", text: "#FCA5A5" } // Dark red : { bg: "#FEE2E2", text: "#991B1B" }; case 3: // SOS - Critical Red return isDark ? { bg: "#7F1D1D", text: "#FFFFFF" } // Dark critical : { bg: "#DC2626", text: "#FFFFFF" }; default: // Default - Gray return isDark ? { bg: "#374151", text: "#D1D5DB" } // Dark gray : { bg: "#F3F4F6", text: "#4B5563" }; } }; const formatTime = (timestamp?: number) => { if (!timestamp) return "--"; const date = new Date(timestamp * 1000); return date.toLocaleString("vi-VN"); }; return ( 0} defaultExpanded > {alerts.length === 0 ? ( {t("diary.tripDetail.noAlerts")} ) : ( {alerts.map((alert, index) => { const levelColor = getAlertLevelColor(alert.level); return ( {alert.name || t("diary.tripDetail.unknownAlert")} {alert.confirmed && ( {t("diary.tripDetail.confirmed")} )} {formatTime(alert.time)} ); })} )} ); } const styles = StyleSheet.create({ emptyContainer: { alignItems: "center", justifyContent: "center", paddingVertical: 24, gap: 8, }, emptyText: { fontSize: 14, fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, list: { gap: 10, }, alertItem: { padding: 12, borderRadius: 8, }, alertHeader: { flexDirection: "row", alignItems: "center", justifyContent: "space-between", marginBottom: 4, }, alertInfo: { flexDirection: "row", alignItems: "center", gap: 8, flex: 1, }, alertName: { fontSize: 14, fontWeight: "600", flex: 1, fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, alertTime: { fontSize: 12, marginLeft: 26, fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, confirmedBadge: { paddingHorizontal: 8, paddingVertical: 2, borderRadius: 4, }, confirmedText: { color: "#FFFFFF", fontSize: 11, fontWeight: "600", fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, });