import { View, Text, TouchableOpacity, Modal, Platform } from 'react-native'; import { useState } from 'react'; import { Calendar } from 'lucide-react-native'; interface Props { label?: string; value: number | null; onChange: (timestamp: number) => void; } export function DatePicker({ label, value, onChange }: Props) { const [show, setShow] = useState(false); // Build a simple date selector (year/month/day dropdowns) const selected = value ? new Date(value * 1000) : new Date(); const today = new Date(); const [year, setYear] = useState(selected.getFullYear()); const [month, setMonth] = useState(selected.getMonth()); const [day, setDay] = useState(selected.getDate()); const years = Array.from({ length: 3 }, (_, i) => today.getFullYear() - 1 + i); const months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']; const daysInMonth = new Date(year, month + 1, 0).getDate(); const days = Array.from({ length: daysInMonth }, (_, i) => i + 1); function handleConfirm() { const d = new Date(year, month, day, 12, 0, 0); onChange(Math.floor(d.getTime() / 1000)); setShow(false); } const displayDate = value ? new Date(value * 1000).toLocaleDateString('en-PH', { year: 'numeric', month: 'short', day: 'numeric' }) : 'Select date'; return ( {label && {label}} setShow(true)} className="flex-row items-center border border-gray-200 rounded-xl px-4 py-3 bg-white" > {displayDate} setShow(false)}> Select Date {/* Month */} Month {months.map((m, i) => ( setMonth(i)} className={`py-2 px-3 ${month === i ? 'bg-primary' : ''}`}> {m} ))} {/* Day */} Day {days.filter((_, i) => i < 10 || Math.abs(i - (day - 1)) < 3).map((d) => ( setDay(d)} className={`py-2 ${day === d ? 'bg-primary' : ''}`}> {d} ))} {/* Year */} Year {years.map((y) => ( setYear(y)} className={`py-3 ${year === y ? 'bg-primary' : ''}`}> {y} ))} Confirm ); }