<template>
    <div class="row" style="width: 450px; margin: auto;" @keyup.enter="submitForm">
        <div class="col bg-white padding-40 b-rad-lg">
            <div class="row m-b-10">
                <div class="col">
                    <h2 class="text-center">{{data.name}}</h2>
                </div>
            </div>
            <validation-wrapper-component class="m-b-15" :validator="$v.parameters.rate.amount">
                <label class="text-primary">Extra Charges (MYR)</label>
                <div class="controls">
                    <input type="text" class="form-control fs-12" v-model.trim="parameters.rate.amount" v-money="money">
                </div>
            </validation-wrapper-component>
            <div class="row m-t-15">
                <div class="col-auto p-r-5">
                    <div class="btn btn-lg btn-default b-rad-none" data-dismiss="modal">Cancel</div>
                </div>
                <div class="col p-l-5">
                    <div class="btn btn-primary w-100 btn-lg" @click="submitForm()">Confirm</div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
    import modalFormHandler from '../../../general/mixins/modalFormHandler';
    import { required } from "vuelidate/lib/validators";

    export default {
        props: {
            data: {
                type: Object,
                required: false
            },
            section: {
                default: ''
            },
        },
        data() {
            return {
                parameters: {
                    reference: 'WAREHOUSE_RATE',
                    id: this.data.id,
                    rate : {
                        amount: this.data.warehouseCharges == null ? 0 : this.data.warehouseCharges.amount,
                    }
                }
            };
        },
        validations: {
            parameters: {
                rate: {
                    amount: { required }
                }
            }
        },
        methods: {
            submitForm(){
                this.submit(this.route('api.segment.constant.update', 1), 'put', this.section, true, true)
            },
        },
        mixins: [modalFormHandler]
    }

</script>