import { STATUS_DANGEROUS, STATUS_NORMAL, STATUS_WARNING } from "@/constants"; import { useAppTheme } from "@/hooks/use-app-theme"; import { useI18n } from "@/hooks/use-i18n"; import { formatRelativeTime } from "@/services/time_service"; import { convertToDMS, kmhToKnot } from "@/utils/geom"; import { Ionicons } from "@expo/vector-icons"; import { ScrollView, Text, View } from "react-native"; import { ThemedText } from "../themed-text"; interface ShipInfoProps { thingMetadata?: Model.ThingMetadata; } const ShipInfo = ({ thingMetadata }: ShipInfoProps) => { const { t } = useI18n(); const { colors, utils } = useAppTheme(); const isDark = utils.isDark; // Định nghĩa màu sắc theo trạng thái - hỗ trợ cả light và dark theme const statusConfig = { normal: { dotColor: colors.success, badgeColor: isDark ? "rgba(52, 199, 89, 0.2)" : "#dcfce7", badgeTextColor: isDark ? "#30D158" : "#15803d", badgeText: "Bình thường", }, warning: { dotColor: colors.warning, badgeColor: isDark ? "rgba(255, 102, 0, 0.2)" : "#fef3c7", badgeTextColor: isDark ? "#ff9500" : "#b45309", badgeText: "Cảnh báo", }, danger: { dotColor: colors.error, badgeColor: isDark ? "rgba(255, 69, 58, 0.2)" : "#fee2e2", badgeTextColor: isDark ? "#FF453A" : "#b91c1c", badgeText: "Nguy hiểm", }, }; const getThingStatus = () => { switch (thingMetadata?.state_level) { case STATUS_NORMAL: return "normal"; case STATUS_WARNING: return "warning"; case STATUS_DANGEROUS: return "danger"; default: return "normal"; } }; const gpsData: Model.GPSResponse = JSON.parse(thingMetadata?.gps || "{}"); const currentStatus = statusConfig[getThingStatus()]; // Format tọa độ const formatCoordinate = (lat: number, lon: number) => { const latDir = lat >= 0 ? "N" : "S"; const lonDir = lon >= 0 ? "E" : "W"; return `${Math.abs(lat).toFixed(4)}°${latDir}, ${Math.abs(lon).toFixed( 4 )}°${lonDir}`; }; return ( {/* Header: Tên tàu và trạng thái */} {/* Status dot */} {/* Tên tàu */} {thingMetadata?.ship_name} {/* Badge trạng thái */} {currentStatus.badgeText} {/* Tốc độ và hướng */} {kmhToKnot(gpsData.s || 0)} {t("home.speed_units")} {gpsData.h}° {/* Tọa độ */} {convertToDMS(gpsData.lat || 0, true)}, {convertToDMS(gpsData.lon || 0, false)} {formatRelativeTime(gpsData.t)} {/* Trạng thái */} {thingMetadata?.state !== "" && ( Trạng thái: {thingMetadata?.state || "-"} )} ); }; export default ShipInfo;