import PropTypes from 'prop-types';
import React from 'react';
import moment from 'moment';
import { ISO_FORMAT } from '../../constants/dateTimeFormats';
import SelectAppointmentTimeItem from './SelectAppointmentTimeItem';

export default function SelectAppointmentTimes (props) {
    return (
        <div className="cheryl__row">
            {props.availableTimes.map(time => {
                const timeObj = moment(time, ISO_FORMAT);
                return (
                    <SelectAppointmentTimeItem
                        key={time}
                        time={timeObj}
                        isSelected={timeObj.isSame(props.selectedTime)}
                        selectTime={props.onSelectTime}
                    />
                );
            })}
        </div>
    );
}

SelectAppointmentTimes.propTypes = {
    availableTimes: PropTypes.array.isRequired,
    selectedTime: PropTypes.object,
    onSelectTime: PropTypes.func.isRequired,
};
