import React, { useState } from 'react'; import { Modal, View, TouchableOpacity, Text } from 'react-native'; import DateTimePicker, { DateType, useDefaultStyles } from 'react-native-ui-datepicker'; import { X } from 'lucide-react-native'; import dayjs from 'dayjs'; interface TimePickerModalProps { visible: boolean; initialDate?: DateType; onConfirm: (time: string) => void; onClose: () => void; } export const TimePickerModal = ({ visible, initialDate, onConfirm, onClose }: TimePickerModalProps) => { const defaultStyles = useDefaultStyles(); const [selectedDate, setSelectedDate] = useState(initialDate || new Date()); const formatTime = (date?: DateType | null) => { if (!date) return "00:00"; date = dayjs(date); const hour = date?.hour().toString().padStart(2, "0") ?? "00"; const minute = date?.minute().toString().padStart(2, "0") ?? "00"; return `${hour}:${minute}`; }; const handleConfirm = () => { const time = formatTime(selectedDate); console.log("Selected time:", time); onConfirm(time); onClose(); }; return ( {/* Header con chiusura */} {/* TimePicker */} setSelectedDate(d.date || new Date())} /> {/* Bottone conferma */} Applica ); };