import React, { useState } from "react"; import { View, Text, TouchableOpacity, StyleSheet, Platform, Modal, } from "react-native"; import { Ionicons } from "@expo/vector-icons"; import DateTimePicker from "@react-native-community/datetimepicker"; import { useI18n } from "@/hooks/use-i18n"; import { useThemeContext } from "@/hooks/use-theme-context"; interface TripDurationPickerProps { startDate: Date | null; endDate: Date | null; onStartDateChange: (date: Date | null) => void; onEndDateChange: (date: Date | null) => void; } export default function TripDurationPicker({ startDate, endDate, onStartDateChange, onEndDateChange, }: TripDurationPickerProps) { const { t } = useI18n(); const { colors, colorScheme } = useThemeContext(); const [showStartPicker, setShowStartPicker] = useState(false); const [showEndPicker, setShowEndPicker] = useState(false); const formatDate = (date: Date | null) => { if (!date) return ""; const day = date.getDate().toString().padStart(2, "0"); const month = (date.getMonth() + 1).toString().padStart(2, "0"); const year = date.getFullYear(); return `${day}/${month}/${year}`; }; const handleStartDateChange = (event: any, selectedDate?: Date) => { setShowStartPicker(Platform.OS === "ios"); if (selectedDate) { onStartDateChange(selectedDate); } }; const handleEndDateChange = (event: any, selectedDate?: Date) => { setShowEndPicker(Platform.OS === "ios"); if (selectedDate) { onEndDateChange(selectedDate); } }; const themedStyles = { label: { color: colors.text }, dateInput: { backgroundColor: colors.card, borderColor: colors.border, }, dateText: { color: colors.text }, placeholder: { color: colors.textSecondary }, pickerContainer: { backgroundColor: colors.card }, pickerHeader: { borderBottomColor: colors.border }, pickerTitle: { color: colors.text }, cancelButton: { color: colors.textSecondary }, }; return ( {t("diary.tripDuration")} {/* Start Date */} {t("diary.startDate")} setShowStartPicker(true)} activeOpacity={0.7} > {startDate ? formatDate(startDate) : t("diary.selectDate")} {/* End Date */} {t("diary.endDate")} setShowEndPicker(true)} activeOpacity={0.7} > {endDate ? formatDate(endDate) : t("diary.selectDate")} {/* Start Date Picker */} {showStartPicker && ( setShowStartPicker(false)}> {t("common.cancel")} {t("diary.selectStartDate")} setShowStartPicker(false)}> {t("common.done")} )} {/* End Date Picker */} {showEndPicker && ( setShowEndPicker(false)}> {t("common.cancel")} {t("diary.selectEndDate")} setShowEndPicker(false)}> {t("common.done")} )} ); } const styles = StyleSheet.create({ container: { marginBottom: 20, }, label: { fontSize: 16, fontWeight: "600", marginBottom: 12, fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, subLabel: { fontSize: 14, marginBottom: 6, fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, dateRangeContainer: { flexDirection: "row", gap: 12, }, dateSection: { flex: 1, }, dateInput: { flexDirection: "row", justifyContent: "space-between", alignItems: "center", borderWidth: 1, borderRadius: 8, paddingHorizontal: 12, paddingVertical: 12, }, dateText: { fontSize: 15, fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, modalOverlay: { flex: 1, backgroundColor: "rgba(0, 0, 0, 0.5)", justifyContent: "flex-end", }, pickerContainer: { borderTopLeftRadius: 20, borderTopRightRadius: 20, paddingBottom: 20, }, pickerHeader: { flexDirection: "row", justifyContent: "space-between", alignItems: "center", paddingHorizontal: 20, paddingVertical: 16, borderBottomWidth: 1, }, pickerTitle: { fontSize: 16, fontWeight: "600", fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, cancelButton: { fontSize: 16, fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, doneButton: { fontSize: 16, fontWeight: "600", color: "#3B82F6", fontFamily: Platform.select({ ios: "System", android: "Roboto", default: "System", }), }, });