<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" v-if="item.owner.contact">+{{item.owner.contact.country_code}} {{parseInt(item.owner.contact.phone, 10)}}</div>
                                    <div class="muted bold fs-10" v-else></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" v-if="item.owner.contact">{{item.owner.contact.wechat_id}}</div>
                                            <div class="fs-11 bold" v-else></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">Company Name</div>
                                        </div>
                                    </div>
                                    <div class="row" v-if="isEditCompanyName === false">
                                        <div class="col">
                                            <div class="fs-11 text-primary">{{item.owner.name}} <i class="fa fa-edit pointer fa-fw m-l-5" v-if="$store.getters.isSuperAdmin" @click="isEditCompanyName = !isEditCompanyName"></i></div>
                                        </div>
                                    </div>
                                    <div class="row" v-if="isEditCompanyName === true">
                                        <div class="col">
                                            <update-company-name-form-component :section="section" :data="item.owner" v-on:submit="isEditCompanyName=false"></update-company-name-form-component>
                                        </div>
                                        <div class="col-auto d-flex align-items-center">
                                            <div class="row">
                                                 <div class="col b-none btn btn-sm btn-danger" @click="isEditCompanyName = !isEditCompanyName">
                                                    <i class="fa fa-times"></i>
                                                </div>
                                            </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" v-if="isEditIdentificationNumber === false">
                                        <div class="col">
                                            <div class="fs-11 text-primary bold">{{item.reference}}  <i class="fa fa-edit pointer fa-fw m-l-5" v-if="$store.getters.isSuperAdmin" @click="isEditIdentificationNumber = !isEditIdentificationNumber"></i></div>
                                        </div>
                                    </div>
                                    <div class="row" v-if="isEditIdentificationNumber === true">
                                        <div class="col">
                                            <update-identification-number-form-component :section="section" :data="{identification_number: item.reference}" :id="item.id" v-on:submit="isEditIdentificationNumber=false"></update-identification-number-form-component>
                                        </div>
                                            <div class="col-auto d-flex align-items-center">
                                            <div class="row">
                                                 <div class="col b-none btn btn-sm btn-danger" @click="isEditIdentificationNumber = !isEditIdentificationNumber">
                                                    <i class="fa fa-times"></i>
                                                </div>
                                            </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">
                                            <reject-identification-verification-form-component :section="section" :data="item"></reject-identification-verification-form-component>
                                        </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,
                isEditIdentificationNumber: false,
                isEditCompanyName: 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>
