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) => { switch (level) { case 0: return { bg: "#FEF3C7", text: "#92400E" }; // Warning - Yellow case 1: return { bg: "#FEE2E2", text: "#991B1B" }; // Error - Red case 2: return { bg: "#DBEAFE", text: "#1E40AF" }; // Info - Blue default: return { bg: "#F3F4F6", text: "#4B5563" }; // Default - Gray } }; const formatTime = (timestamp?: number) => { if (!timestamp) return "--"; const date = new Date(timestamp * 1000); return date.toLocaleString("vi-VN"); }; return ( 0} > {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", }), }, });