import { DOCUMENTS_DATA } from '@/data/data'; import { Download, FileText, MapPin, Plus, Search, CalendarIcon } from 'lucide-react-native'; import React, { useState } from 'react'; import { RangePickerModal } from '@/components/RangePickerModal'; import { ScrollView, Text, TextInput, TouchableOpacity, View } from 'react-native'; import dayjs from 'dayjs'; export default function DocumentsScreen() { const [searchTerm, setSearchTerm] = useState(''); // Gestiamo le date come oggetti Dayjs o null per il datepicker, e stringhe per il filtro const [range, setRange] = useState<{ startDate: any; endDate: any }>({ startDate: null, endDate: null }); const [showRangePicker, setShowRangePicker] = useState(false); // Funzione helper per convertire DD/MM/YYYY in oggetto Date (per il filtro esistente) const parseDate = (dateStr: string) => { if (!dateStr) return new Date(); const [day, month, year] = dateStr.split('/').map(Number); return new Date(year, month - 1, day); }; const filteredDocs = DOCUMENTS_DATA.filter(doc => { // Filtro Testuale const matchesSearch = doc.name.toLowerCase().includes(searchTerm.toLowerCase()) || doc.site.toLowerCase().includes(searchTerm.toLowerCase()); if (!matchesSearch) return false; // Filtro Date Range if (range.startDate || range.endDate) { const docDate = parseDate(doc.date); // doc.date รจ "DD/MM/YYYY" // Controllo Data Inizio if (range.startDate) { // dayjs(range.startDate).toDate() converte in oggetto Date JS standard const start = dayjs(range.startDate).startOf('day').toDate(); if (docDate < start) return false; } // Controllo Data Fine if (range.endDate) { const end = dayjs(range.endDate).endOf('day').toDate(); if (docDate > end) return false; } } return true; }); // Funzione per formattare la visualizzazione const formatDateDisplay = (date: any) => { return date ? dayjs(date).format('DD/MM/YYYY') : 'gg/mm/aaaa'; }; return ( {/* Header */} Documenti Gestione modulistica e schemi {/* Search + Date Row */} {/* Search Bar */} {/* Date Filter Button */} setShowRangePicker(true)} className={`p-4 bg-white rounded-2xl shadow-sm border ${range.startDate ? 'border-[#099499]' : 'border-gray-200'}`} > {/* Modale Unico per il Range */} setShowRangePicker(false)} currentRange={range} onApply={setRange} /> {/* List */} {filteredDocs.map((doc) => ( {doc.name} {doc.site} ))} {/* FAB */} alert('Aggiungi nuovo documento')} className="absolute bottom-8 right-6 w-16 h-16 bg-[#099499] rounded-full shadow-lg items-center justify-center active:scale-90" > ); }