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 FishingLogsSectionProps { fishingLogs?: Model.FishingLog[] | null; } export default function FishingLogsSection({ fishingLogs = [] }: FishingLogsSectionProps) { const { t } = useI18n(); const { colors } = useThemeContext(); const logs = fishingLogs || []; const formatDateTime = (date?: Date) => { if (!date) return "--"; const d = new Date(date); return d.toLocaleString("vi-VN", { day: "2-digit", month: "2-digit", year: "numeric", hour: "2-digit", minute: "2-digit", }); }; const formatCoord = (lat?: number, lon?: number) => { if (lat === undefined || lon === undefined) return "--"; return `${lat.toFixed(4)}°N, ${lon.toFixed(4)}°E`; }; const getStatusLabel = (status?: number) => { switch (status) { case 0: return { label: t("diary.tripDetail.logStatusPending"), color: "#FEF3C7", textColor: "#92400E" }; case 1: return { label: t("diary.tripDetail.logStatusActive"), color: "#DBEAFE", textColor: "#1E40AF" }; case 2: return { label: t("diary.tripDetail.logStatusCompleted"), color: "#D1FAE5", textColor: "#065F46" }; default: return { label: t("diary.tripDetail.logStatusUnknown"), color: "#F3F4F6", textColor: "#4B5563" }; } }; return ( {logs.length === 0 ? ( {t("diary.tripDetail.noFishingLogs")} ) : ( {logs.map((log, index) => { const status = getStatusLabel(log.status); const catchCount = log.info?.length || 0; return ( {/* Header */} #{index + 1} {status.label} {/* Time Info */} {t("diary.tripDetail.startTime")}: {formatDateTime(log.start_at)} {t("diary.tripDetail.endTime")}: {formatDateTime(log.end_at)} {/* Location Info */} {t("diary.tripDetail.startLocation")}: {formatCoord(log.start_lat, log.start_lon)} {t("diary.tripDetail.haulLocation")}: {formatCoord(log.haul_lat, log.haul_lon)} {/* Catch Info */} {catchCount > 0 && ( {t("diary.tripDetail.catchInfo")} ({catchCount} {t("diary.tripDetail.species")}) {log.info?.slice(0, 3).map((fish, fishIndex) => ( {fish.fish_name || t("diary.tripDetail.unknownFish")} {fish.catch_number} {fish.catch_unit} ))} {catchCount > 3 && ( +{catchCount - 3} {t("diary.tripDetail.more")} )} )} {/* Weather */} {log.weather_description && ( {log.weather_description} )} ); })} )} ); } 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: 16, }, logItem: { borderWidth: 1, borderRadius: 10, padding: 12, }, logHeader: { flexDirection: "row", alignItems: "center", justifyContent: "space-between", marginBottom: 10, }, logIndex: { paddingHorizontal: 10, paddingVertical: 4, borderRadius: 4, backgroundColor: "rgba(59, 130, 246, 0.1)", }, logIndexText: { fontSize: 14, fontWeight: "700", fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, statusBadge: { paddingHorizontal: 10, paddingVertical: 4, borderRadius: 4, }, statusText: { fontSize: 12, fontWeight: "600", fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, timeRow: { gap: 6, marginBottom: 10, }, timeItem: { flexDirection: "row", alignItems: "center", gap: 6, }, timeLabel: { fontSize: 12, fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, timeValue: { fontSize: 12, fontWeight: "500", fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, locationContainer: { padding: 10, borderRadius: 6, gap: 6, marginBottom: 10, }, locationItem: { flexDirection: "row", alignItems: "center", gap: 6, }, locationLabel: { fontSize: 11, fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, locationValue: { fontSize: 11, fontWeight: "500", fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, catchContainer: { marginBottom: 10, }, catchHeader: { flexDirection: "row", alignItems: "center", gap: 6, marginBottom: 6, }, catchLabel: { fontSize: 13, fontWeight: "600", fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, catchList: { gap: 4, paddingLeft: 22, }, catchItem: { flexDirection: "row", justifyContent: "space-between", }, fishName: { fontSize: 12, fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, fishAmount: { fontSize: 12, fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, moreText: { fontSize: 12, fontWeight: "500", fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, weatherRow: { flexDirection: "row", alignItems: "center", gap: 6, }, weatherText: { fontSize: 12, fontStyle: "italic", fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, });