import PropTypes from 'prop-types';
import React from 'react';
import classnames from 'classnames';
import { TIME_FORMAT_DISPLAY } from '../../constants/dateTimeFormats';

export default function SelectAppointmentTimeItem (props) {
    const { time, selectTime, isSelected } = props;

    return (
        <button
            type="button"
            key={time}
            aria-pressed={isSelected}
            className={classnames('cheryl__col-1-3', 'cheryl__button', 'cheryl__time-item', { cheryl__selected: isSelected })}
            onClick={() => selectTime(time)}
        >
            {time.format(TIME_FORMAT_DISPLAY)}
        </button>
    );
}

SelectAppointmentTimeItem.propTypes = {
    time: PropTypes.object.isRequired,
    selectTime: PropTypes.func,
    isSelected: PropTypes.bool,
};
