import PropTypes from 'prop-types';
import React from 'react';
import moment from 'moment-timezone';
import { DATE_FORMAT_DISPLAY_FULL_TIME } from '../../constants/dateTimeFormats';
import { jss } from '../../utils/styles';

import { createStyles } from './styles/Confirmation';
import emailConfirm from '../assets/email-confirm.png';

export default class ConfirmationAppointment extends React.Component {
    componentWillMount () {
        this.styleSheet = jss.createStyleSheet(createStyles(), { named: false });
        this.styleSheet.attach();
    }

    componentWillUnmount () {
        this.styleSheet.detach();
    }

    render () {
        const { appointment, confirmationEmail } = this.props;
        const { expiration_date: confirmationDate , location: appointmentLocation } = appointment;

        const hasLocation = !!appointmentLocation;
        const confirmByDate = confirmationDate ? moment(confirmationDate).tz(moment.tz.guess()).format(DATE_FORMAT_DISPLAY_FULL_TIME) : null;

        return (
            <div className="cheryl__confirmation">
                <h2 className="cheryl__title">Just one more step...</h2>
                <div>
                    <img src={emailConfirm} />
                </div>

                <p>
                    Please confirm your appointment{hasLocation && <span> at <strong>{appointmentLocation}</strong></span>}.{' '}
                    An email was sent to <strong className="cheryl__confirmation-email">{confirmationEmail}</strong>.
                </p>
                <p className="cheryl__one-hour-warn">
                    After ONE HOUR {confirmByDate && <span><strong>({confirmByDate})</strong></span>}{' '}
                    if you have not confirmed, your appointment will not be reserved.
                </p>
            </div>
        );
    }
}

ConfirmationAppointment.propTypes = {
    confirmationEmail: PropTypes.string.isRequired,
    appointment: PropTypes.shape({
        start: PropTypes.string,
        expiration_date: PropTypes.string,
        location: PropTypes.string,
    }).isRequired
};
