/* Dependencies */ import React from 'react' import { Platform, StyleSheet, Text, TouchableOpacity, useColorScheme, View } from 'react-native' /* Libraries */ import { dtoc } from '@hproinformatica/functions' import DateTimePickerModal from 'react-native-modal-datetime-picker' import Icon from 'react-native-vector-icons/FontAwesome' /* Types */ interface DefaultProps { selectedDate: string setSelectedDate: React.Dispatch> visible: boolean setVisible: React.Dispatch> alwaysConfirm?: boolean iconColor?: string isDark?: boolean maximumDate?: Date minimumDate?: Date onConfirm?: (date: string) => void text?: string textColor?: string tip?: string useToday?: boolean } type Props = DefaultProps const PickerDate = ({ iconColor = '#00a099', isDark = false, maximumDate, minimumDate, onConfirm, alwaysConfirm = false, selectedDate, setSelectedDate, setVisible, textColor = '#00a099', text = '', tip = '(Clique para alterar)', useToday, visible }: Props) => { let colorScheme = useColorScheme() function toggleVisible() { setVisible((value) => !value) } return ( {`${text}${selectedDate} ${selectedDate && tip}`} { toggleVisible() let dDat = new Date() if (selectedDate) { dDat = new Date([ selectedDate.substring(3, 5), selectedDate.substring(0, 2), selectedDate.substring(6, 10) ].join('/')) } if (alwaysConfirm || (dtoc(dDat) !== dtoc(date))) { setSelectedDate?.(dtoc(date)) onConfirm?.(dtoc(date)) } }} /> ) } PickerDate.displayName = 'Picker.Date' const styles = StyleSheet.create({ container: { alignItems: 'center', flexDirection: 'row', height: 40, justifyContent: 'center' }, view: { flexDirection: 'row' }, text: { fontSize: 20, fontWeight: 'bold', marginLeft: 15 } }) export default PickerDate