import { IconSymbol } from "@/components/ui/icon-symbol"; import { useI18n } from "@/hooks/use-i18n"; import { useFishes } from "@/state/use-fish"; import { useTrip } from "@/state/use-trip"; import React, { useEffect, useMemo, useRef, useState } from "react"; import { Animated, Text, TouchableOpacity, View } from "react-native"; import CreateOrUpdateHaulModal from "./modal/CreateOrUpdateHaulModal"; import { useAppTheme } from "@/hooks/use-app-theme"; import { useThemeContext } from "@/hooks/use-theme-context"; import { createTableStyles } from "./ThemedTable"; const NetListTable: React.FC = () => { const [collapsed, setCollapsed] = useState(true); const [contentHeight, setContentHeight] = useState(0); const animatedHeight = useRef(new Animated.Value(0)).current; const [modalVisible, setModalVisible] = useState(false); const [selectedNet, setSelectedNet] = useState(null); const { t } = useI18n(); const { colorScheme } = useAppTheme(); const { colors } = useThemeContext(); const styles = useMemo(() => createTableStyles(colorScheme), [colorScheme]); const { trip } = useTrip(); const { fishSpecies, getFishSpecies } = useFishes(); useEffect(() => { getFishSpecies(); }, []); const handleToggle = () => { const toValue = collapsed ? contentHeight : 0; Animated.timing(animatedHeight, { toValue, duration: 300, useNativeDriver: false, }).start(); setCollapsed((prev) => !prev); }; const handleStatusPress = (id: string) => { const net = trip?.fishing_logs?.find((item) => item.fishing_log_id === id); if (net) { setSelectedNet(net); setModalVisible(true); } }; return ( {/* Header toggle */} {t("trip.netList.title")} {collapsed && ( {trip?.fishing_logs?.length} )} {/* Nội dung ẩn để đo chiều cao */} { const height = event.nativeEvent.layout.height; // Update measured content height whenever it actually changes. if (height > 0 && height !== contentHeight) { setContentHeight(height); // If the panel is currently expanded, animate to the new height so // newly added/removed rows become visible immediately. if (!collapsed) { Animated.timing(animatedHeight, { toValue: height, duration: 200, useNativeDriver: false, }).start(); } } }} > {/* Header */} {t("trip.netList.sttHeader")} {t("trip.netList.statusHeader")} {/* Body */} {trip?.fishing_logs?.map((item, index) => ( {/* Cột STT */} {t("trip.netList.haulPrefix")} {index + 1} {/* Cột Trạng thái */} handleStatusPress(item.fishing_log_id)} > {item.status ? t("trip.netList.completed") : t("trip.netList.pending")} ))} {/* Bảng hiển thị với animation */} {/* Header */} {t("trip.netList.sttHeader")} {t("trip.netList.statusHeader")} {/* Body */} {trip?.fishing_logs?.map((item, index) => ( {/* Cột STT */} {t("trip.netList.haulPrefix")} {index + 1} {/* Cột Trạng thái */} handleStatusPress(item.fishing_log_id)} > {item.status ? t("trip.netList.completed") : t("trip.netList.pending")} ))} { console.log("OnCLose"); setModalVisible(false); }} fishingLog={selectedNet} fishingLogIndex={ selectedNet ? trip!.fishing_logs!.findIndex( (item) => item.fishing_log_id === selectedNet.fishing_log_id ) + 1 : undefined } /> {/* Modal chi tiết */} {/* { console.log("OnCLose"); setModalVisible(false); }} netData={selectedNet} /> */} ); }; export default NetListTable;