<template>
    <div class="row m-b-10 b-a b-primary">
        <div class="col">
            <loading-component style="height: 200px; top: 0;" key="1" color="success" v-show="isLoading"></loading-component>
            <div class="row" v-show="!isLoading">
                <div class="col">
                    <div class="row align-items-center">
                        <div class="col p-t-10 p-b-10">
                            <div class="row">
                                <div class="col">
                                    <div class="text-primary fs-11">{{item.owner.company_module.marking}}</div>
                                </div>
                            </div>
                            <div class="row align-items-center">
                                <div class="col-auto p-r-0">
                                    <i class="fa fa-address-card fs-12 m-b-5 muted"></i>
                                </div>
                                <div class="col p-l-5">
                                    <div class="muted bold fs-10">+{{item.owner.contact.country_code}} {{parseInt(item.owner.contact.phone, 10)}}</div>
                                </div>
                            </div>
                        </div>
                        <div class="col-auto">
                            <button class="btn btn-sm btn-default bg-master-lightest b-rad-none no-border" @click="expanded = !expanded">
                                <i class="fa" :class="[{'fa-times': expanded}, {'text-danger': expanded}, {'fa-angle-down': !expanded}]"></i>
                            </button>
                        </div>
                    </div>
                    <div class="row b-t b-grey" :class="[{'hide': !expanded}]">
                        <div class="col p-t-10">
                            <div class="row m-b-15">
                                <div class="col">
                                    <div class="row m-b-5">
                                        <div class="col">
                                            <div class="fs-8 all-caps muted">Customer Name</div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col">
                                            <div class="fs-11 bold">{{item.owner.employee.name}}</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row m-b-15">
                                <div class="col">
                                    <div class="row m-b-5">
                                        <div class="col">
                                            <div class="fs-8 all-caps muted">WeChat ID</div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col">
                                            <div class="fs-11 bold">{{item.owner.contact.wechat_id}}</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row m-b-15" v-if="item.owner.type === 1">
                                <div class="col">
                                    <div class="row m-b-5">
                                        <div class="col">
                                            <div class="fs-8 all-caps muted">Company Name</div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col">
                                            <div class="fs-11 text-primary">{{item.owner.name}}</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row m-b-10">
                                <div class="col">
                                    <div class="row m-b-5">
                                        <div class="col">
                                            <div class="fs-8 all-caps muted">{{ item.owner.type === 0 ? 'IC' : 'SSM Registration' }} Number</div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col">
                                            <div class="fs-11 text-primary bold">{{item.reference}}</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row m-b-10">
                                <div class="col">
                                    <div class="row m-b-5">
                                        <div class="col">
                                            <div class="fs-8 all-caps muted">{{ item.owner.type === 0 ? 'IC' : 'SSM Registration' }} Document</div>
                                        </div>
                                    </div>
                                    <div class="row no-margin">
                                        <div v-for="file in item.files" v-bind:key="file.id"  class="col-auto no-padding m-r-5">
                                            <document-file-viewer-component :file="file">
                                                <template slot="button">
                                                    <div class="icon-thumbnail fs-11 text-white icon-25 bg-primary btn-rounded float-left m-r-5">
                                                        <i class="fa fa-file-image-o fs-10"></i>
                                                    </div>
                                                </template>
                                            </document-file-viewer-component>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row m-t-20 parentContainer">
                                <div class="col">
                                    <div class="row">
                                        <div class="col no-padding">
                                            <button class="btn btn-md btn-block btn-danger b-rad-none p-t-10 p-b-10 requestModal" data-type="rejectDocument">
                                                <i class="fa fa-times"></i>
                                            </button>
                                        </div>
                                        <modal-component small type="rejectDocument">
                                            <div class="row">
                                                <div class="col text-center">
                                                    <div class="row">
                                                        <div class="col text-center">
                                                            <div class="row m-b-20">
                                                                <div class="col">
                                                                    <h5 class="all-caps">Reject Document</h5>
                                                                    <div class="fs-11">Are you sure you want to reject this customer's identification?</div>
                                                                </div>
                                                            </div>
                                                            <div class="row">
                                                                <div class="col p-r-5">
                                                                    <div data-dismiss="modal" class="btn btn-sm btn-default bg-master-lighter btn-block b-rad-none">Cancel</div>
                                                                </div>
                                                                <div class="col p-l-5">
                                                                    <div data-dismiss="modal" class="btn btn-sm btn-danger btn-block b-rad-none" @click="approveDocument('reject')">Reject</div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </modal-component>
                                        <div class="col no-padding ml-auto">
                                            <button class="btn btn-md btn-block btn-success b-rad-none p-t-10 p-b-10 requestModal" data-type="approveDocument">
                                                <i class="fa fa-check"></i>
                                            </button>
                                        </div>
                                        <modal-component small type="approveDocument">
                                            <div class="row">
                                                <div class="col text-center">
                                                    <div class="row">
                                                        <div class="col text-center">
                                                            <div class="row m-b-20">
                                                                <div class="col">
                                                                    <h5 class="all-caps">Approve Document</h5>
                                                                    <div class="fs-11">Are you sure you want to approve this customer's identification?</div>
                                                                </div>
                                                            </div>
                                                            <div class="row">
                                                                <div class="col p-r-5">
                                                                    <div data-dismiss="modal" class="btn btn-sm btn-default bg-master-lighter btn-block b-rad-none">Cancel</div>
                                                                </div>
                                                                <div class="col p-l-5">
                                                                    <div data-dismiss="modal" class="btn btn-sm btn-success btn-block b-rad-none" @click="approveDocument('approve')">Approve</div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </modal-component>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import componentHandler from '../../../general/mixins/componentHandler';
    import staticFormHandler from '../../../general/mixins/staticFormHandler'
    export default {
        data() {
            return {
                expanded: false
            }
        },
        methods: {
            approveDocument(status){
                this.isLoading = true;
                this.submit(this.route('api.company.identification.approval', this.item.owner.id, this.item.id, status), 'put', 'identificationVerificationSection', true, true);
            },
        },
        mixins: [componentHandler, staticFormHandler]
    }
</script>
