<template>
    <div class="row">
        <div class="col">
            <div class="row">
                <div class="col">
                    <div class="row m-b-10">
                        <div class="col">
                            <h5 class="all-caps m-b-5 bold no-margin">Edit Transaction Group</h5>
                        </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 m-b-10">
                        <div class="col">
                            <validation-wrapper-component selectable :validator="$v.parameters.supplier_id">
                                <label>Supplier</label>
                                <selectable-component :endpoint="route('api.company.list') + '?filters=' + JSON.stringify({'business_type': 3, 'status_in': [2, 0]})" section="supplierListSection" valueColumn="id" :labelColumn="['name']" v-model="parameters.supplier_id"></selectable-component>
                            </validation-wrapper-component>
                        </div>
                    </div>
                    <div class="row m-b-10">
                        <div class="col">
                            <validation-wrapper-component :validator="$v.parameters.rate">
                                <label class="all-caps">Purchase Rate</label>
                                <input type="text" class="form-control" v-model.lazy="parameters.rate" v-money="exchangeRate">
                            </validation-wrapper-component>
                        </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 ModalFormHandler from '../../../general/mixins/modalFormHandler';

    export default {
        props: {
            currency_rate:{
                type: Number,
                required: true
            },
            supplier_id: {
                type: Number,
                required: true
            },
            id: {
                type: Number,
                required: true
            }
        },
        data(){
            return {
                error: '',
                suppliers: [],
                selectedSupplier: {
                    id: '',
                    name: '',
                    status: false
                },
                parameters: {
                    supplier_id: this.supplier_id,
                    rate: (Math.round((this.currency_rate + Number.EPSILON) * 10000) / 10000).toFixed(5)
                },
            }
        },
        validations: {
            parameters: {
                supplier_id: { },
                rate: { },
            },
        },
        methods: {
            submitForm() {
                this.submit(route('api.transaction.group.update', this.id), 'put', this.section, true, true);
            }
        },
        mixins: [ModalFormHandler]
    }
</script>
