import { IconSymbol } from "@/components/ui/icon-symbol"; import { useI18n } from "@/hooks/use-i18n"; import { useTrip } from "@/state/use-trip"; import React, { useMemo, useRef, useState } from "react"; import { Animated, Text, TouchableOpacity, View } from "react-native"; import { useAppTheme } from "@/hooks/use-app-theme"; import { useThemeContext } from "@/hooks/use-theme-context"; import { createTableStyles } from "./ThemedTable"; const FishingToolsTable: React.FC = () => { const [collapsed, setCollapsed] = useState(true); const [contentHeight, setContentHeight] = useState(0); const animatedHeight = useRef(new Animated.Value(0)).current; const { t } = useI18n(); const { colorScheme } = useAppTheme(); const { colors } = useThemeContext(); const styles = useMemo(() => createTableStyles(colorScheme), [colorScheme]); const { trip } = useTrip(); const data: Model.FishingGear[] = trip?.fishing_gears ?? []; const tongSoLuong = data.reduce((sum, item) => sum + Number(item.number), 0); const handleToggle = () => { const toValue = collapsed ? contentHeight : 0; Animated.timing(animatedHeight, { toValue, duration: 300, useNativeDriver: false, }).start(); setCollapsed((prev) => !prev); }; return ( {/* Header / Toggle */} {t("trip.fishingTools.title")} {collapsed && {tongSoLuong}} {/* Nội dung ẩn để đo chiều cao */} { const height = event.nativeEvent.layout.height; if (height > 0 && contentHeight === 0) { setContentHeight(height); } }} > {/* Table Header */} {t("trip.fishingTools.nameHeader")} {t("trip.fishingTools.quantityHeader")} {/* Body */} {data.map((item, index) => ( {item.name} {item.number} ))} {/* Footer */} {t("trip.fishingTools.totalLabel")} {tongSoLuong} {/* Nội dung mở/đóng */} {/* Table Header */} {t("trip.fishingTools.nameHeader")} {t("trip.fishingTools.quantityHeader")} {/* Body */} {data.map((item, index) => ( {item.name} {item.number} ))} {/* Footer */} {t("trip.fishingTools.totalLabel")} {tongSoLuong} ); }; export default FishingToolsTable;