import React from "react"; import { View, Text, StyleSheet, TouchableOpacity, Platform, } from "react-native"; import { Ionicons } from "@expo/vector-icons"; import { useTripStatusConfig } from "./types"; import { useThings } from "@/state/use-thing"; import dayjs from "dayjs"; import { useI18n } from "@/hooks/use-i18n"; import { useThemeContext } from "@/hooks/use-theme-context"; interface TripCardProps { trip: Model.Trip; onPress?: () => void; onView?: () => void; onEdit?: () => void; onTeam?: () => void; onSend?: () => void; onDelete?: () => void; } export default function TripCard({ trip, onPress, onView, onEdit, onTeam, onSend, onDelete, }: TripCardProps) { const { t } = useI18n(); const { colors } = useThemeContext(); const { things } = useThings(); const TRIP_STATUS_CONFIG = useTripStatusConfig(); // Tìm thing có id trùng với vms_id của trip const thingOfTrip: Model.Thing | undefined = things?.find( (thing) => thing.id === trip.vms_id ); // Lấy config status từ trip_status (number) const statusKey = trip.trip_status as keyof typeof TRIP_STATUS_CONFIG; const statusConfig = TRIP_STATUS_CONFIG[statusKey] || { label: "-", bgColor: "#eee", textColor: "#333", icon: "help", }; // Determine which actions to show based on status const showEdit = trip.trip_status === 0 || trip.trip_status === 1; const showSend = trip.trip_status === 0; const showDelete = trip.trip_status === 1; const themedStyles = { card: { backgroundColor: colors.card, borderColor: colors.border, }, title: { color: colors.text, }, label: { color: colors.textSecondary, }, value: { color: colors.text, }, divider: { backgroundColor: colors.separator, }, actionText: { color: colors.textSecondary, }, }; return ( {/* Header */} {trip.name} {statusConfig.label} {/* Info Grid */} {t("diary.tripCard.shipCode")} {thingOfTrip?.metadata?.ship_reg_number /* hoặc trip.ship_id */} {t("diary.tripCard.departure")} {trip.departure_time ? dayjs(trip.departure_time).format("DD/MM/YYYY HH:mm") : "-"} {t("diary.tripCard.return")} {/* FIXME: trip.returnDate không có trong dữ liệu API, cần mapping từ trip.arrival_time */} {trip.arrival_time ? dayjs(trip.arrival_time).format("DD/MM/YYYY HH:mm") : "-"} {/* Action Buttons */} {t("diary.tripCard.view")} {showEdit && ( {t("diary.tripCard.edit")} )} {t("diary.tripCard.team")} {showSend && ( {t("diary.tripCard.send")} )} {showDelete && ( {t("diary.tripCard.delete")} )} ); } const styles = StyleSheet.create({ card: { borderRadius: 8, padding: 12, marginBottom: 8, shadowColor: "#000", shadowOffset: { width: 0, height: 1, }, shadowOpacity: 0.05, shadowRadius: 4, elevation: 2, borderWidth: 1, }, header: { flexDirection: "row", justifyContent: "space-between", alignItems: "flex-start", marginBottom: 8, }, headerLeft: { flexDirection: "row", alignItems: "center", flex: 1, }, titleContainer: { marginLeft: 8, flex: 1, }, title: { fontSize: 16, fontWeight: "600", marginBottom: 2, fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, badge: { paddingHorizontal: 8, paddingVertical: 2, borderRadius: 8, }, badgeText: { fontSize: 12, fontWeight: "500", fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, infoGrid: { gap: 6, marginBottom: 8, }, infoRow: { flexDirection: "row", justifyContent: "space-between", paddingVertical: 4, }, label: { fontSize: 14, fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, value: { fontSize: 14, fontWeight: "500", fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, divider: { height: 1, marginVertical: 8, }, actionsContainer: { flexDirection: "row", justifyContent: "space-around", alignItems: "center", }, actionButton: { flexDirection: "row", alignItems: "center", gap: 4, paddingVertical: 4, }, actionText: { fontSize: 14, fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, deleteText: { color: "#EF4444", }, });