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

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

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

    handleOptionChange(){
        this.props.handleDeliveryChange(this.props.profileAddress);
    }

    render() {
        const {profileAddress, openAddressDialog, idSelectedDeliveryAddress} = this.props;

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


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

export default SelectDeliveryAddress;
