import React, {Component} from 'react';
import {FormGroup, Input} from 'reactstrap';

class SelectBillingAddress extends Component {
    constructor(props) {
        super(props);

        this.handleOptionChange = this.handleOptionChange.bind(this);
    }

    handleOptionChange(){
        this.props.handleBillingChange(this.props.billingAddress);
    }

    render() {
        const {billingAddress, openAddressDialog, idSelectedBillingAddress} = this.props;

        return (
            <div className="address-row">
                <FormGroup check>
                       <div>
                           <div className="address-text">
                               <Input id={'billing-addres-check-' + billingAddress.id} checked={idSelectedBillingAddress === billingAddress.id} type="radio" onChange={this.handleOptionChange} name="billingAddress" />
                               <div className="small-address-title">
                                   {billingAddress.firstName} {billingAddress.lastName}
                                   {
                                       billingAddress.invoiceMail &&
                                       <span>( {billingAddress.invoiceMail} )</span>
                                   }
                                </div>
                                <div>
                                    {billingAddress.countryName}, {billingAddress.city}, {billingAddress.detailedAddress}, {billingAddress.zipCode}
                                </div>
                           </div>
                           <div className="address-icons">
                               <i className="fa fa-pencil control-icon edit-address-btn"
                                        onClick={()=> {openAddressDialog('edit', billingAddress)}}
                                        id="edit-address-btn"
                                        aria-hidden="true"></i>
                           </div>
                       </div>


                </FormGroup>
            </div>
        );
    }
}

export default SelectBillingAddress;
