<template>
	<div class="row m-l-0 m-r-0 m-b-10 bg-white 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-user-circle-o muted hint-text fs-16"></i>
                </div>
            </div>
        </div>
		<div class="col">
			<div class="row align-items-center justify-content-center p-t-10 p-b-10">
				<div class="col">
                    <div class="row">
                        <div class="col-auto p-r-10">
                            <span class="fs-12 bold">{{contact.name}}</span>
                        </div>
                        <div class="col no-padding">
                            <span class="fs-12 muted b-l b-grey p-l-10">{{contact.designation}}</span>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col">
                            <span class="fs-12"><i class="fa fa-phone-square hint-text m-r-5 p-r-5 b-r b-grey"></i> {{contact.contact}}</span>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col">
                            <span class="fs-12"><i class="fa fa-envelope hint-text m-r-5 p-r-5 b-r b-grey"></i> {{contact.email}}</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">
                                    <a class="requestModal pointer" data-type="delete">
                                        <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-trash 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" @click="toggleEdit()" v-show="!isEditing">
                                        <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>
                                    <a class="pointer" @click="closeEdit()" v-show="isEditing">
                                        <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-info"></i>
                                            </div>
                                        </div>
                                    </a>
                                </div>
                            </div>
						</div>
					</div>
				</div>
			</div>
			<div class="row bg-white no-margin">
				<div class="col no-padding">
					<slide-up-down :active="isEditing" :duration="700">
						<div class="row">
							<div class="col no-padding b-t b-grey">
								<contact-form-component v-on:collapseEdit="closeEdit()" :data="contact" :type="type" :reference="contact.reference_id"></contact-form-component>
							</div>
						</div>
					</slide-up-down>
				</div>
			</div>
			<confirm-modal-component
					title="Remove Address"
					:message="'Are you sure you want to remove <strong>'+contact.name+'</strong>?'"
					type="delete"
                    danger
					v-on:confirm="deleteContact()"></confirm-modal-component>
		</div>
	</div>
</template>

<script>
    export default {
        props: {
            'type': {
                type: String,
                required: true
            },
            'data': {
                type: Object,
                required: true
            }
        },
        data() {
            return {
                contact: this.data,
                isEditing: false
            }
        },
        mounted() {
            Event.$on('collapseEdit', () => {
                this.closeEdit();
            });
        },
        methods: {
            deleteContact(){
                fetch(route('api.contact.delete', {'id': this.contact.id}), {
                    method: 'delete'
                }).then(response => response.json())
                    .then(data => {
                        Event.$emit('updateContactsList');
                    })
                    .catch(error => console.log(error))
            },
            closeEdit(){
                this.isEditing = false;
            },
            toggleEdit(){
                Event.$emit('collapseEdit');
                this.isEditing = !this.isEditing;
            }
        }
    }
</script>