import moment from 'moment';
import React, {useState} from 'react';
import DatePicker from 'react-native-date-picker';

interface TaggDatePickerProps {
  handleDateUpdate: (_: Date) => void;
  maxDate: Date;
  textColor: string;
  date: Date | undefined;
}

const TaggDatePicker: React.FC<TaggDatePickerProps> = (props) => {
  const [date, setDate] = useState(
    props.date
      ? new Date(moment(props.date).add(1, 'day').format('YYYY-MM-DD'))
      : undefined,
  );
  return (
    <DatePicker
      date={date ? date : props.maxDate}
      textColor={props.textColor}
      mode={'date'}
      maximumDate={props.maxDate}
      onDateChange={(newDate) => {
        setDate(newDate);
        props.handleDateUpdate(newDate);
      }}
    />
  );
};

export default TaggDatePicker;
