import { useState } from "react"; import { View, Pressable, StyleSheet } from "react-native"; import { Text } from "@/components/ui/Text"; import DateTimePicker, { DateTimePickerEvent, } from "@react-native-community/datetimepicker"; import { format } from "date-fns"; import { MaterialIcons } from "@expo/vector-icons"; import { Colors } from "@/constants/theme"; import { Label } from "@/components/ui/Input"; interface DatePickerProps { label: string; initialDate?: Date; onChange: (date: Date) => void; minimumDate?: Date; maximumDate?: Date; } export const DatePickerField: React.FC = ({ label, initialDate = new Date(), onChange, minimumDate, maximumDate, }) => { const [pickedDate, setPickedDate] = useState(null); const [show, setShow] = useState(false); const date = pickedDate ?? initialDate; const openPicker = () => setShow(true); const handleChange = (event: DateTimePickerEvent, selectedDate?: Date) => { setShow(false); if (selectedDate) { setPickedDate(selectedDate); if (onChange) onChange(selectedDate); } }; const formatted = format(date, "dd/MM/yyyy"); return ( ); }; const styles = StyleSheet.create({ label: { fontWeight: "500", color: Colors.light.textSecondary, fontSize: 12, marginBottom: 8, letterSpacing: 0.5, textTransform: "uppercase", }, container: { flexDirection: "row", alignItems: "center", justifyContent: "space-between", backgroundColor: "#F3F4F6", // light gray pill paddingVertical: 14, paddingHorizontal: 16, borderRadius: 10, borderWidth: 0.5, borderColor: "#E5E7EB", minWidth: 220, }, pressed: { opacity: 0.8, }, dateText: { color: "#111827", fontSize: 16, fontWeight: "600", }, });