import { AppDatePicker } from '@/components/AppDatePicker'; import PlaceFilter from '@/components/PlaceFilter'; import SupplierFilter from '@/components/SupplierFilter'; import MachineFilter from '@/components/MachineFilter'; import { Machine, Place, Supplier } from '@/types/types'; import { formatPickerDate } from '@/utils/dateTime'; import { X } from 'lucide-react-native'; import React, { useEffect, useState } from 'react'; import { Modal, ScrollView, Text, TouchableOpacity, View } from 'react-native'; interface FilterModalProps { visible: boolean; places?: Place[]; currentRange?: { startDate: string | null; endDate: string | null }; currentPlace?: Place | null; currentSupplier?: Supplier | null; currentMachine?: Machine | null; showDate?: boolean; showPlace?: boolean; showSupplier?: boolean; showMachine?: boolean; onClose: () => void; onApply: (range: { startDate: string | null; endDate: string | null }, place: Place | null, supplier: Supplier | null, machine: Machine | null) => void; onReset: () => void; } export default function FilterModal({ visible, places = [], currentRange = { startDate: null, endDate: null }, currentPlace = null, currentSupplier = null, currentMachine = null, showDate = true, showPlace = true, showSupplier = false, showMachine = false, onClose, onApply, onReset, }: FilterModalProps) { const [localRange, setLocalRange] = useState<{ startDate: string | null; endDate: string | null }>(currentRange); const [localPlace, setLocalPlace] = useState(currentPlace); const [localSupplier, setLocalSupplier] = useState(currentSupplier); const [localMachine, setLocalMachine] = useState(currentMachine); // Sync local state when modal opens useEffect(() => { if (visible) { setLocalRange(currentRange); setLocalPlace(currentPlace); setLocalSupplier(currentSupplier); setLocalMachine(currentMachine); } }, [visible, currentRange, currentPlace, currentSupplier, currentMachine]); const handleApply = () => { onApply(localRange, localPlace, localSupplier, localMachine); }; const handleReset = () => { onReset(); }; return ( {/* Modal Header */} Filtra Risultati {/* Date Range Selection */} {showDate && ( Periodo { setLocalRange({ startDate: params.startDate ? formatPickerDate(params.startDate) : null, endDate: params.endDate ? formatPickerDate(params.endDate) : null }); }} /> )} {/* Place Selection */} {showPlace && ( )} {/* Supplier Selection */} {showSupplier && ( )} {/* Machine Selection */} {showMachine && ( )} {/* Actions */} Reset Applica Filtri ); }