import PropTypes from 'prop-types';
import React from 'react';
import Input from './Input';
import { jss } from '../../utils/styles';
import styles from './styles/BrokerInformation';
import {
EMPLOYEEGROUP_FIELD_CONFIG_CHOICES
} from '../../constants/config';
const { REQUIRED, HIDDEN } = EMPLOYEEGROUP_FIELD_CONFIG_CHOICES;

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

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

    render () {
        const { errors, config } = this.props;
        return (
            <div className="cheryl__broker-information">
                <div className="cheryl__row">
                    <Input
                        name="client[broker_first_name]"
                        labelText="Broker First Name"
                        containerClassName="col-1-2"
                        error={errors.broker_first_name}
                        required
                    />
                </div>

                <div className="cheryl__row">
                    <Input
                        name="client[broker_last_name]"
                        labelText="Broker Last Name"
                        containerClassName="col-1-2"
                        error={errors.broker_last_name}
                        required
                    />
                </div>

                <div className="cheryl__row">
                    <Input
                        name="client[broker_company]"
                        labelText="Brokerage"
                        error={errors.broker_company}
                        required={config['client.broker_company'] == REQUIRED}
                        hidden={config['client.broker_company'] == HIDDEN}
                    />
                </div>

                <div className="cheryl__row">
                    <Input
                        name="client[broker_phone]"
                        labelText="Broker Phone"
                        error={errors.broker_phone}
                        required
                    />
                </div>

                <div className="cheryl__row">
                    <Input
                        name="client[broker_email]"
                        labelText="Broker Email"
                        error={errors.broker_email}
                        required
                    />
                </div>
            </div>
        );
    }
}

BrokerInformation.propTypes = {
    errors: PropTypes.object.isRequired,
    config: PropTypes.object.isRequired
};
