<template>
    <div class="row m-b-10 parentContainer">
        <div class="col">
            <loading-component style="height: 200px; top: 0;" key="1" color="success" v-show="isLoading"></loading-component>
            <div class="row p-b-5 b-b b-grey" v-show="!isLoading">
                <div class="col">
                    <div class="row">
                        <div class="col">
                            <div class="row m-b-10">
                                <div class="col-auto">
                                    <div class="font-heading fs-10 muted all-caps">Date</div>
                                    <div class="font-heading fs-10">
                                        {{ item.updated_at }}
                                    </div>
                                </div>
                                <div class="col-auto">
                                    <div class="font-heading fs-10 muted all-caps">Order</div>
                                    <div class="font-heading fs-10"><a :href="route('order.show' , item.order.reference)" target="_blank">{{item.order.reference}}</a></div>
                                </div>
                                <div class="col-auto">
                                    <div class="font-heading fs-10 muted all-caps">Customer</div>
                                    <div class="font-heading fs-10">
                                        <a :href="route('customer.profile', item.order.company_module.marking)">{{item.order.company_module.marking}}</a>
                                    </div>
                                </div>
                                <div class="col text-right">
                                    <div class="font-heading fs-10 muted all-caps">Amount</div>
                                    <div class="font-heading fs-14 text-success bold">
                                        {{(Math.round((item.amount + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}}
                                    </div>
                                </div>
                            </div>
                            <div class="row m-b-10">
                                <div class="col">
                                    <div class="font-heading fs-10 muted all-caps">Payment Proof</div>
                                    <div class="row no-margin" v-if="item.payment_method !==5 && item.payment_method !==4">
                                        <div v-for="file in item.documents[0].files" v-bind:key="file.id" class="col-auto no-padding">
                                            <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 class="row no-margin" v-if="item.payment_method ===5">
                                        <div class="col no-padding">
                                            <a :href="route('billplz.bill', item.payment_reference)" target="_blank">
                                                <div class="icon-thumbnail fs-11 text-white icon-25 bg-complete btn-rounded float-left m-r-5">
                                                    Bz
                                                </div>
                                            </a>
                                        </div>
                                    </div>
                                    <div class="row no-margin" v-if="item.payment_method ===4">
                                        <div class="col no-padding">
                                            <div class="font-heading fs-10">{{item.payment_reference}}</div>
                                        </div>
                                    </div>
                                </div>
                                <!-- <div class="col-auto">
                                    <div class="font-heading fs-10 muted all-caps">Service</div>
                                    <div class="font-heading fs-10">
                                        {{item.booking.service.name}}
                                    </div>
                                </div> -->
                                <!-- <div class="col">
                                    <div class="font-heading fs-10 muted all-caps">Booking</div>
                                    <div class="font-heading fs-10">
                                        {{item.original_currency.short_code}} {{(Math.round((item.original_amount + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}}
                                    </div>
                                </div> -->
                                <div class="col-auto">
                                    <div class="row">
                                        <div v-if="!no_action" class="col-6 col-md-auto text-right">
                                            <button class="btn btn-xs btn-outline-danger b-rad-none m-r-5 requestModal" data-type="rejectPayment">
                                                <i class="fa fa-times fa-fw"></i>
                                            </button>
                                            <button class="btn btn-xs btn-success b-rad-none requestModal" data-type="approvePayment">
                                                <i class="fa fa-check fa-fw"></i>
                                            </button>
                                            <modal-component small type="rejectPayment">
                                                <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 payment?</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="approvePayment('reject')">Reject</div>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </modal-component>
                                            <modal-component small type="approvePayment">
                                                <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 Payment</h5>
                                                                        <div class="fs-11">Are you sure you want to approve this payment?</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="approvePayment('approve')">Approve</div>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </modal-component>
                                        </div>
                                    </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 {
        props: {
            no_action: Boolean
        },
        methods: {
            approvePayment(status){
                this.isLoading = true;
                this.submit(this.route('api.transaction.payment.approval', this.item.id, status), 'put', 'identificationVerificationSection', true, true);
            },
        },
        mixins: [componentHandler, staticFormHandler]
    }
</script>
