<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 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.created_at}}
                            </div>
                        </div>
                        <div class="col-auto">
                            <div class="font-heading fs-10 muted all-caps">Currency Rate</div>
                            <div class="font-heading fs-10">
                                {{item.currency_rate}}
                            </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">
                                {{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>
                    <div class="row">
                        <div class="col">
                            <div class="font-heading fs-10 muted all-caps">reference</div>
                            <span class="font-heading fs-10" v-for="transaction in item.transactions">
                                <a :href="route('booking.details', transaction.booking.marking)">{{transaction.booking.marking}}&nbsp;</a>
                            </span>
                        </div>
                        <div class="col-auto">
                            <div class="row parentContainer">
                                <div class="col p-l-0">
                                    <button class="btn btn-xs btn-default bg-warning b-rad-none no-border requestModal" data-type="editTransactionGroup">
                                        <i class="fa fa-pencil text-white"></i>
                                    </button>
                                    <modal-component small type="editTransactionGroup">
                                        <edit-transaction-group-form-component :section="section" :currency_rate="item.currency_rate" :supplier_id ="data.transactions[0].issuer_id" :id="item.id"></edit-transaction-group-form-component>
                                    </modal-component>
                                    <button class="btn btn-xs btn-default bg-danger b-rad-none no-border requestModal" data-type="deleteTransactionGroup">
                                        <i class="fa fa-times text-white"></i>
                                    </button>
                                    <modal-component small type="deleteTransactionGroup">
                                        <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">Delete Transaction Group</h5>
                                                                <div class="fs-11">Are you sure that you want to delete this transaction group?</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="deleteGroupTransaction()">Confirm</div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </modal-component>
                                </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: {
            section:{
                type: String,
                required: true
            }
        },
        methods: {
            deleteGroupTransaction() {
                this.isLoading = true;
                this.submit(this.route('api.transaction.group.delete', this.item.id), 'delete', this.section, true, true);
            }
        },
        mixins: [componentHandler, staticFormHandler]
    }
</script>
