<template>
    <div class="row" @keyup.enter="submitForm">
        <div class="col">
            <div class="row">
                <div class="col">
                    <div class="row m-b-20">
                        <div class="col">
                            <h3 class="all-caps m-b-5 bold no-margin">Edit Bank Account</h3>
                        </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 :validator="$v.parameters.reference">
                                <label>Reference</label>
                                <input type="text" class="form-control" v-model="parameters.reference">
                            </validation-wrapper-component>
                        </div>
                    </div>
                    <div class="row m-b-10">
                        <div class="col">
                            <validation-wrapper-component :validator="$v.parameters.holder_name">
                                <label>Account Holder Name / Company Name</label>
                                <input type="text" class="form-control" v-model="parameters.holder_name">
                            </validation-wrapper-component>
                        </div>
                    </div>
                    <div class="row m-b-10">
                        <div class="col">
                            <validation-wrapper-component :validator="$v.parameters.account_no">
                                <label>Account No.</label>
                                <input type="text" class="form-control" v-model="parameters.account_no">
                            </validation-wrapper-component>
                        </div>
                    </div>
                    <div class="row" v-if="parameters.type === 2">
                        <div class="col">
                            <div class="row m-b-10">
                                <div class="col">
                                    <validation-wrapper-component :validator="$v.parameters.bank_name">
                                        <label>Bank Name</label>
                                        <input type="text" class="form-control" v-model="parameters.bank_name">
                                    </validation-wrapper-component>
                                </div>
                            </div>
                            <div class="row m-b-10">
                                <div class="col">
                                    <validation-wrapper-component :validator="$v.parameters.bank_branch">
                                        <label>Bank Branch / 所在地</label>
                                        <input type="text" class="form-control" v-model="parameters.bank_branch">
                                    </validation-wrapper-component>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row m-b-20" v-if="parameters.type !== 2">
                        <div class="col">
                            <validation-wrapper-component selectable :validator="$v.parameters.bank_name">
                                <label>Bank Name</label>
                                <selectable-component endpoint="malaysian_banks.json" section="banksListSection" valueColumn="name" :labelColumn="['name']" v-model="parameters.bank_name"></selectable-component>
                            </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 } from "vuelidate/lib/validators";
    export default {
        props : {
            company_id: {
                type: Number,
                required: true
            },
        },
        created() {
            this.parameters.company_id = this.company_id;
            this.parameters.account_type = this.data.type;
        },
        watch: {
            'data': function() {
                this.parameters = this.data;
                this.parameters.company_id = this.company_id;
                this.parameters.account_type = this.data.type;
            }
        },
        data(){
            return {
                parameters: {
                    company_id: this.company_id
                }
            }
        },
        validations: {
            parameters: {
                holder_name: {
                    required
                },
                account_no: {
                    required
                },
                bank_branch: {
                    // required
                },
                swift: {
                    // required
                },
                snap: {
                    // required
                },
                bank_name: {
                    required
                },
                reference: {
                    // required
                }
            }
        },
        methods: {
            submitForm(){
                this.submit(route('api.bank.update', this.data.id), 'put', this.section, true, true);
            },
        },
        mixins: [modalFormHandler]

    }
</script>
