<template>
	<div class="row m-l-0 m-r-0 m-b-10 parentContainer">
        <div class="col-auto">
            <div class="row h-100 align-items-center justify-content-center bg-master-lighter hint-text">
                <div class="col p-r-20 p-l-20">
                    <i class="fa fa-map-marker muted hint-text fs-16"></i>
                </div>
            </div>
        </div>
		<div class="col bg-white parentConatiner">
			<div class="row align-items-center justify-content-center p-t-10 p-b-10">
				<div class="col">
                    <div class="row">
                        <div class="col">
                            <span class="fs-10 muted">{{address.street_one}} {{address.street_two}} {{address.city}} {{address.state}} {{address.post_code}} {{address.country}}</span>
                        </div>
                    </div>
				</div>
				<div class="col-auto b-l b-grey">
					<div class="row h-100">
						<div class="col">
							<div class="row no-margin">
                                <div class="col-auto text-right p-t-10 p-b-10 bg-master-lightest m-r-5 ml-auto" v-if="!address.default">
                                    <a class="requestModal pointer" data-type="delete" @click="submit(route('api.address.delete', data.id), 'delete', 'addressSection', true, true)">
                                        <div data-toggle="tooltip" title="" data-placement="bottom" class="row link align-items-center justify-content-center" data-original-title="Delete">
                                            <div class="col">
                                                <i class="fa fa-times text-danger"></i>
                                            </div>
                                        </div>
                                    </a>
                                </div>
                                <div class="col-auto text-right p-t-10 p-b-10 bg-master-lightest">
                                    <a class="pointer requestModal" data-type="editModal">
                                        <div data-toggle="tooltip" title="" data-placement="bottom" class="row link align-items-center justify-content-center" data-original-title="Delete">
                                            <div class="col">
                                                <i class="fa fa-pencil text-info"></i>
                                            </div>
                                        </div>
                                    </a>
                                </div>
                                <modal-form-component section="addressSection" :data="address">
                                    <template slot="form" slot-scope="{section}">
                                        <address-form-component section="section" :id="address.company_id" :data="address"></address-form-component>
                                    </template>
                                </modal-form-component>
                            </div>
						</div>
					</div>
				</div>
			</div>
		</div>
        <div class="col-4 m-l-15 d-flex align-items-center">
            <div class="row align-items-center" v-if="!address.default" :class="[{'requestModal': !address.default}, {'pointer': !address.default}, {'link': !address.default}]" @click="submit(route('api.address.default', data.id), 'post', 'addressSection', true, true)" data-type="setDefault">
                <div class="col-auto text-right p-t-5 p-b-5" :class="[{'bg-warning-lighter': address.default}, {'bg-master-light': !address.default}]">
                    <div data-toggle="tooltip" class="row align-items-center justify-content-center" :class="{'link': !address.default}">
                        <div class="col">
                            <i class="fa fa-star" :class="[{'text-warning': address.default}, {'text-master': !address.default}]"></i>
                        </div>
                    </div>
                </div>
                <div class="col bg-white p-t-5 p-b-5">
                    <small class="fs-12 all-caps bold" :class="[{'text-warning': address.default}, {'text-master': !address.default}]">Default Address</small>
                </div>
            </div>
        </div>
	</div>
</template>

<script>
    export default {
        props: {
            'data': {
                type: Object,
                required: true
            }
        },
        data() {
            return {
                section: 'addressSection',
                address: this.data
            }
        },
        watch: {
            'data': function() {
                this.address = this.data;
            }
        },
        methods:{
            successHandler(){
                this.crudSuccess();
                EventBus.$emit('updateAddress')
            }
        }

    }
</script>