import React from 'react';
import classnames from 'classnames';
import moment from 'moment';
import PropTypes from 'prop-types';
import { DATE_FORMAT_DISPLAY, DATE_FORMAT_NEXT_AVAILABLE_DAY } from '../../constants/dateTimeFormats';

export default function SelectAppointmentNoTimes (props) {
    const { nextAvailableDate, onRequestDate, requestedAppointment } = props;

    const nextDate = moment(nextAvailableDate);
    const selectedDate = moment(requestedAppointment);
    if (nextAvailableDate) {
        return (
            <div className="cheryl__alert" role="region" aria-live="assertive">
                <span>No available appointments on {selectedDate.format(DATE_FORMAT_DISPLAY)}.</span>
                <br/>
                <button
                    className={classnames('cheryl__button-primary', 'next-available-day-button')}
                    type="button"
                    onClick={() => onRequestDate(nextDate)}
                >
                    View next available: {nextDate.format(DATE_FORMAT_NEXT_AVAILABLE_DAY)}
                </button>
            </div>
        );
    }

    return <div className="cheryl__alert" role="region" aria-live="assertive">
        No available appointments on this day.<br />
        Please select a new day above.
    </div>;
};

SelectAppointmentNoTimes.propTypes = {
    nextAvailableDate: PropTypes.string,
    selectedDate: PropTypes.string,
    onRequestDate: PropTypes.func,
    requestedAppointment: PropTypes.string,
};
