<template>
    <div class="row" @keyup.enter="submitForm">
        <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 Customer Profile</h3>
                        </div>
                    </div>
                    <div class="row m-b-10">
                        <div class="col">
                            <validation-wrapper-component selectable :validator="$v.parameters.type">
                                <label>Company Type</label>
                                <selectable-component :endpoint="route('api.company.company_type.list')" section="listCompanyTypeSection" valueColumn="id" :labelColumn="['type']" v-model="parameters.type"></selectable-component>
                            </validation-wrapper-component>
                        </div>
                    </div>
                    <div class="row m-b-10">
                        <div class="col">
                            <validation-wrapper-component :validator="$v.parameters.email">
                                <label>Email</label>
                                <input type="text" class="form-control" v-model="parameters.email">
                            </validation-wrapper-component>
                        </div>
                    </div> 
                    <div class="row m-b-10">
                        <div class="col">
                            <validation-wrapper-component :validator="$v.parameters.phone">
                                <label>Phone</label>
                                <input type="text" class="form-control" v-model="parameters.phone">
                            </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 modalFormHandler from "../../../general/mixins/modalFormHandler";
    import { required, email } from "vuelidate/lib/validators";
    export default {
        props: {
            data: {
                type: Object,
                default: null
            },
        },
        created() {
            this.parameters = {};
            this.parameters.type = [0,1].includes(this.data.type) ? this.data.type: 0; 
            this.parameters.email = this.data.contact ? this.data.contact.email : "";
            this.parameters.phone = this.data.contact ? this.data.contact.phone : "";
        },
        data(){
            return {
                parameters: {},
            }
        },
        validations: {
            parameters: {
                type: {
                    required,
                },
                email: {
                    email,
                },
                phone: {
                    required,
                },
            }
        },
        methods: {
            submitForm(){
                this.submit(route('api.company.profile.update', this.data.id), 'put', this.section, true, true);
            },
        },
        mixins: [modalFormHandler]
    }
</script>