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"; 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 { 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; 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: { backgroundColor: "#FFFFFF", borderRadius: 12, padding: 16, marginBottom: 12, shadowColor: "#000", shadowOffset: { width: 0, height: 2, }, shadowOpacity: 0.05, shadowRadius: 8, elevation: 2, borderWidth: 1, borderColor: "#F3F4F6", }, header: { flexDirection: "row", justifyContent: "space-between", alignItems: "flex-start", marginBottom: 16, }, headerLeft: { flexDirection: "row", alignItems: "center", flex: 1, }, titleContainer: { marginLeft: 12, flex: 1, }, title: { fontSize: 16, fontWeight: "600", color: "#111827", marginBottom: 2, fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, badge: { paddingHorizontal: 12, paddingVertical: 4, borderRadius: 12, }, badgeText: { fontSize: 12, fontWeight: "500", fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, infoGrid: { gap: 12, }, infoRow: { flexDirection: "row", justifyContent: "space-between", alignItems: "center", }, label: { fontSize: 14, color: "#6B7280", fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, value: { fontSize: 14, color: "#111827", fontWeight: "500", textAlign: "right", fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, divider: { height: 1, backgroundColor: "#F3F4F6", marginTop: 16, }, actionsContainer: { flexDirection: "row", justifyContent: "space-around", paddingTop: 12, }, actionButton: { flexDirection: "row", alignItems: "center", gap: 6, paddingVertical: 8, paddingHorizontal: 12, }, actionText: { fontSize: 14, color: "#6B7280", fontWeight: "500", fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, deleteText: { color: "#EF4444", }, });