import React, { useState } from 'react'; import { MaterialCommunityIcons } from '@expo/vector-icons'; import { View, TouchableOpacity, FlatList } from 'react-native'; import { AppContainer, MyText, tw, MyFlatList , BottomDialog, MyTouchableOpacity } from 'common-ui'; import { trpc } from '../../../src/trpc-client'; import { useRouter } from 'expo-router'; import dayjs from 'dayjs'; import { LinearGradient } from 'expo-linear-gradient'; interface SlotItemProps { item: any; router: any; setDialogProducts: React.Dispatch>; setDialogOpen: React.Dispatch>; } const SlotItemComponent: React.FC = ({ item: slot, router, setDialogProducts, setDialogOpen, }) => { const slotProducts = slot.products?.map((p: any) => p.name).filter(Boolean) || []; const displayProducts = slotProducts.slice(0, 2).join(', '); const isActive = slot.isActive; const statusColor = isActive ? 'bg-green-100 text-green-700' : 'bg-red-100 text-red-700'; const statusText = isActive ? 'Active' : 'Inactive'; return ( router.push(`/(drawer)/slots/slot-details?slotId=${slot.id}`)} activeOpacity={0.7} > {/* Header: ID and Status */} Slot #{slot.id} ID: {slot.id} router.push(`/edit-slot/${slot.id}` as any)} style={tw`px-3 py-1 rounded-full bg-pink2 mr-2`} > Edit {statusText} {/* Divider */} {/* Details Grid */} {/* Delivery Time */} Delivery {dayjs(slot.deliveryTime).format('DD MMM, h:mm A')} {/* Freeze Time */} Freeze {dayjs(slot.freezeTime).format('DD MMM, h:mm A')} {/* Products */} {slotProducts.length > 0 ? ( Products {displayProducts} {slotProducts.length > 2 && ( { setDialogProducts(slotProducts); setDialogOpen(true); }} > +{slotProducts.length - 2} more )} ) : null} ); }; export default function Slots() { const router = useRouter(); const { data: slotsData, isLoading, refetch } = trpc.admin.slots.getAll.useQuery(); const slots = slotsData?.slots || []; // Dialog state const [dialogOpen, setDialogOpen] = useState(false); const [dialogProducts, setDialogProducts] = useState([]); const [refreshing, setRefreshing] = useState(false); const handleRefresh = async () => { setRefreshing(true); await refetch(); setRefreshing(false); }; if (isLoading) { return ( Loading slots... ); } return ( item.id.toString()} renderItem={({ item }) => ( )} contentContainerStyle={tw`p-4`} onRefresh={handleRefresh} refreshing={refreshing} /> {/* FAB for Add New Slot */} router.push('/add-slot' as any)} activeOpacity={0.95} style={{ position: 'absolute', bottom: 32, right: 24, zIndex: 100 }} > {/* Products Dialog */} setDialogOpen(false)}> All Products index.toString()} renderItem={({ item }) => ( {item} )} showsVerticalScrollIndicator={false} style={tw`max-h-80`} /> ); }