// import { useTheme } from "@/hooks/theme-context"; import { MaterialCommunityIcons } from "@expo/vector-icons"; import DateTimePicker, { AndroidNativeProps, DateTimePickerAndroid, DateTimePickerEvent, } from "@react-native-community/datetimepicker"; import React, { useState } from "react"; import { Modal, Platform, StyleSheet, Text, TouchableOpacity, View, } from "react-native"; import { useTheme, MyText } from "common-ui"; interface Props { value: Date | null; setValue: (date: Date | null) => void; showLabels?: boolean; // Optional prop to control label visibility timeOnly?: boolean; // Optional prop to show only time picker } type Mode = "date" | "time" | "datetime"; function DateTimePickerMod(props: Props) { const { value, setValue, showLabels = true, timeOnly = false } = props; const [show, setShow] = useState(false); const [mode, setMode] = useState("date"); const onChange = (event: DateTimePickerEvent, selectedDate?: Date) => { const currentDate = selectedDate || value; if (Platform.OS === "ios") setShow(false); setValue(currentDate); }; const showMode = (currentMode: Mode) => { if (Platform.OS === "android") { DateTimePickerAndroid.open({ value: value || new Date(), onChange: onChange, mode: currentMode, is24Hour: true, display: "default", } as AndroidNativeProps); } else { setShow(true); setMode(currentMode); } }; const showDatepicker = () => { showMode("date"); }; const showTimepicker = () => { showMode("time"); }; const { theme } = useTheme(); return ( {timeOnly ? ( {showLabels && Select Time} {value?.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", }) || "Select Time"} ) : ( {showLabels && Select Date} {value?.toLocaleDateString() || "Select Date"} {showLabels && Select Time} {value?.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", }) || "Select Time"} )} {/* Conditional rendering for iOS, as it uses the declarative API */} {show && Platform.OS === "ios" && ( setShow(false)} > setShow(false)} style={styles.doneButton} > Done )} ); } export default DateTimePickerMod; const styles = StyleSheet.create({ container: { // flex: 1, // Remove flex to avoid taking up extra space justifyContent: "center", alignItems: "flex-start", padding: 0, // Reduce padding for compactness marginBottom: 16, // Add margin for spacing in forms }, iconRow: { flexDirection: "row", alignItems: "center", justifyContent: "center", marginBottom: 20, }, iconRowSingleLine: { flexDirection: "row", alignItems: "center", justifyContent: "center", marginBottom: 0, }, iconNoBg: { backgroundColor: "transparent", borderRadius: 0, padding: 0, elevation: 0, }, spacerHorizontal: { width: 30, }, spacerHorizontalSmall: { width: 8, }, spacer: { height: 20, // Add some space between buttons }, selectedText: { marginTop: 30, fontSize: 18, fontWeight: "bold", textAlign: "center", }, timeTextContainer: { justifyContent: "center", alignItems: "center", }, timeText: { fontSize: 15, fontWeight: "500", color: "#333", marginLeft: 2, }, dateText: { fontSize: 15, fontWeight: "500", color: "#333", marginLeft: 2, marginRight: 2, }, modalOverlay: { flex: 1, justifyContent: "center", alignItems: "center", backgroundColor: "rgba(0, 0, 0, 0.5)", }, pickerContainer: { width: "80%", backgroundColor: "white", borderRadius: 10, padding: 20, elevation: 5, }, doneButton: { marginTop: 10, backgroundColor: "#007bff", borderRadius: 5, padding: 10, alignItems: "center", }, doneButtonText: { color: "white", fontWeight: "bold", }, });