<template>
    <div class="row bg-white padding-40">
        <div class="col">
            <loading-component style="height: 300px; top: 0;" key="1" color="success" v-show="isLoading" ></loading-component>
            <div class="row justify-content-center" v-show="!isLoading">
                <div class="col">
                    <div class="row m-b-20">
                        <div class="col">
                            <h3 class="all-caps text-center">Please select the supplier.</h3>
                        </div>
                    </div>
                    <div class="row m-b-20">
                        <div class="col">
                            <list-component section="supplierListSection" :endpoint="route('api.company.list')" :options="{business_type: 3}">
                                <template slot="list" slot-scope="{data}">
                                    <div class="row">
                                        <div class="col">
                                            <select-individual-supplier-form-component :data="data" :selectedSupplier="selectedSupplier" v-on:input="updateList($event)"></select-individual-supplier-form-component>
                                        </div>
                                    </div>
                                </template>
                            </list-component>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col">
                            <div class="btn btn-sm btn-success btn-block b-rad-none" @click="submitForm()">Confirm</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import componentHandler from "../../../general/mixins/componentHandler";
import ModalFormHandler from '../../../general/mixins/modalFormHandler';
import { required, minValue} from "vuelidate/lib/validators";
import {VMoney} from 'v-money'

export default {
    data(){
        return {
            selectedSupplier: [],
        }
    },
    methods: {
        submitForm() {
            this.$emit('input', this.selectedSupplier);
            this.closeModal();
        },
        updateList(supplier){
            this.selectedSupplier.includes(supplier) ? this.selectedSupplier.splice(this.selectedSupplier.indexOf(supplier), 1) : this.selectedSupplier.push(supplier);
        },
    },
    mixins: [componentHandler, ModalFormHandler]
};
</script>
