import PropTypes from 'prop-types';
import React from 'react';
import moment from 'moment';
import SingleSelect from '@nestio/pam/lib/components/SingleSelect';

import { DATE_FORMAT_INPUT_DISPLAY, TIME_FORMAT } from '../../constants/dateTimeFormats';
import CalendarInput from '@nestio/pam/lib/components/CalendarInput';

export default function SelectAppointmentNewDate (props) {
    const { appointmentStart, appointmentLocation, maxDaysAhead } = props;

    return (
        <div className="cheryl__new-date">
            <div className="cheryl__new-date-info">
                <span id="new-date-label">
                    Appointment Availability {appointmentLocation ? <span>for <strong>{appointmentLocation}</strong></span> : null} on
                </span>
                <div className="cheryl__select-new-date ">
                    <CalendarInput
                        defaultValue={moment(appointmentStart).format(DATE_FORMAT_INPUT_DISPLAY)}
                        value={moment(appointmentStart).format(DATE_FORMAT_INPUT_DISPLAY)}
                        format={DATE_FORMAT_INPUT_DISPLAY}
                        mask="99/99/9999"
                        maskChar=" "
                        minDate={moment()}
                        maxDate={maxDaysAhead ? moment().add(maxDaysAhead, 'days') : undefined}
                        inputName="date"
                        ariaHidden={true}
                        ariaLabelledBy="new-date-label"
                        onChange={(date) => props.onRequestDate(moment(date, DATE_FORMAT_INPUT_DISPLAY))}
                    />
                </div>
            </div>
            <div className="cheryl__new-date-info">
                <span>around</span>
                <div className="cheryl__select-new-time">
                    <SingleSelect
                        valueLabel="Select time"
                        value={moment(appointmentStart).format(TIME_FORMAT)}
                        options={props.timeChoices}
                        onChange={props.onRequestTime}
                    />
                </div>
            </div>
        </div>
    );
}

SelectAppointmentNewDate.propTypes = {
    appointmentStart: PropTypes.string.isRequired,
    appointmentLocation: PropTypes.string,
    timeChoices: PropTypes.array.isRequired,
    maxDaysAhead: PropTypes.number,
    onRequestDate: PropTypes.func.isRequired,
    onRequestTime: PropTypes.func.isRequired,
};
