import { IconSymbol } from "@/components/ui/icon-symbol"; import { useI18n } from "@/hooks/use-i18n"; import { useAppTheme } from "@/hooks/use-app-theme"; import { useTrip } from "@/state/use-trip"; import { createTableStyles } from "./style/createTableStyles"; import TripCostDetailModal from "./modal/TripCostDetailModal"; import React, { useRef, useState, useMemo } from "react"; import { Animated, Text, TouchableOpacity, View } from "react-native"; import { useThemeContext } from "@/hooks/use-theme-context"; const TripCostTable: React.FC = () => { const [collapsed, setCollapsed] = useState(true); const [contentHeight, setContentHeight] = useState(0); const [modalVisible, setModalVisible] = useState(false); const animatedHeight = useRef(new Animated.Value(0)).current; const { t } = useI18n(); const { colorScheme } = useAppTheme(); const { colors } = useThemeContext(); const { trip } = useTrip(); const styles = useMemo(() => createTableStyles(colorScheme), [colorScheme]); const data: Model.TripCost[] = trip?.trip_cost ?? []; const tongCong = data.reduce((sum, item) => sum + item.total_cost, 0); const handleToggle = () => { const toValue = collapsed ? contentHeight : 0; Animated.timing(animatedHeight, { toValue, duration: 300, useNativeDriver: false, }).start(); setCollapsed((prev) => !prev); }; const handleViewDetail = () => { setModalVisible(true); }; const handleCloseModal = () => { setModalVisible(false); }; return ( {t("trip.costTable.title")} {collapsed && ( {tongCong.toLocaleString()} )} {/* Nội dung ẩn để đo chiều cao */} { const height = event.nativeEvent.layout.height; if (height > 0 && contentHeight === 0) { setContentHeight(height); } }} > {/* Header */} {t("trip.costTable.typeHeader")} {t("trip.costTable.totalCostHeader")} {/* Body */} {data.map((item, index) => ( {item.type} {item.total_cost.toLocaleString()} ))} {/* Footer */} {t("trip.costTable.totalLabel")} {tongCong.toLocaleString()} {/* View Detail Button */} {data.length > 0 && ( {t("trip.costTable.viewDetail")} )} {/* Header */} {t("trip.costTable.typeHeader")} {t("trip.costTable.totalCostHeader")} {/* Body */} {data.map((item, index) => ( {item.type} {item.total_cost.toLocaleString()} ))} {/* Footer */} {t("trip.costTable.totalLabel")} {tongCong.toLocaleString()} {/* View Detail Button */} {data.length > 0 && ( {t("trip.costTable.viewDetail")} )} {/* Modal */} ); }; export default TripCostTable;