<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 text-center">
                    <h3>Edit Company Details</h3>
                </div>
            </div>
            <div class="row">
                <div class="col">
                    <validation-wrapper-component class="m-b-15" :validator="$v.parameters.name">
                        <label class="text-primary">Name</label>
                        <input class="form-control" v-model="parameters.name">
                    </validation-wrapper-component>
                </div>
            </div>
            <div class="row">
                <div class="col">
                    <validation-wrapper-component class="m-b-15" :validator="$v.parameters.debtor">
                        <label class="text-primary">Debtor Code</label>
                        <input class="form-control" v-model="parameters.debtor">
                    </validation-wrapper-component>
                </div>
            </div>
            <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, minLength } from "vuelidate/lib/validators";

    export default {
        data() {
            return {
                parameters: {
                    id: this.data.id, 
                    name: this.data.name, 
                    debtor: this.data.debtor, 
                    reference: this.data.reference, 
                    type: this.data.type, 
                }
            };
        },
        validations: {
            parameters: {
                name: { 
                    required,
                    // minLength: minLength(8)
                },
                debtor: { 
                },
            }
        },
        methods: {
            successHandler(response) {
                window.location.replace(this.route('customers', response.payload.data.reference));
            },
            submitForm() {
                this.submit(this.route('api.company.update.nameAndDebtor', this.data.id), 'put', this.section, true, true)
            }
        },
        mixins: [modalFormHandler]
    }

</script>