<template>
    <div class="row">
        <div class="col">
            <div class="row">
                <div class="col">
                    <div class="row m-b-10">
                        <div class="col">
                            <h3 class="all-caps m-b-5 bold no-margin">Edit Booking Amount</h3>
                        </div>
                    </div>
                    <div class="row m-b-10">
                        <div class="col">
                            <validation-wrapper-component :validator="$v.fix_amount">
                                <label class="muted">Booking Amount ({{data.fixed_currency.short_code}})</label>
                                <input type="text" class="form-control" v-model="fix_amount" v-money="money">
                            </validation-wrapper-component>
                        </div>
                    </div>
                    <div class="row m-b-5 animate__animated animate__fadeInUpBig animate__fast" v-if="error">
                        <div class="col">
                            <small class="bold fs-10 text-danger">{{error}}</small>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col p-r-5">
                            <div class="btn btn-sm btn-default bg-master-lightest btn-block b-rad-none" data-dismiss="modal">Cancel</div>
                        </div>
                        <div class="col p-l-5">
                            <div class="btn btn-sm btn-success btn-block b-rad-none" @click="submitForm()">Update</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
    import { required } from "vuelidate/lib/validators";
    import FormHandler from '../../../general/mixins/formHandler';

    export default {
        data(){
            return {
                error: '',
                fix_amount: (Math.round((this.data.amount + Number.EPSILON) * 100) / 100).toFixed(2)
            }
        },
        validations: {
            fix_amount: { required }
        },
        watch: {
            'data': function() {
                this.fix_amount = (Math.round((this.data.amount + Number.EPSILON) * 100) / 100).toFixed(2);
            }
        },
        methods: {
            submitForm(){
                this.parameters = {fix_amount : parseFloat((this.fix_amount).toString().replace(',', ''))}
                this.submit(this.route('api.booking.booking_amount.update', this.data.id), 'put', this.section, true, true)
            },
            successHandler(){
                this.closeModal();
                this.formHandler('');
            },
        },
        mixins: [FormHandler]
    }
</script>