<template>
    <autocomplete-selector 
        :value="value"
        :errors="errors"
        :label="'Comanda ' + contract_id"
        :dataprovider="dataprovider"
        :disabled="disabled"
        :noLoadData="true"

        @focus="$emit('focus')"
        @blur="$emit('blur')"
        
        @input="$emit('input', $event)"
    />
</template>

<script>

    import DataProvider from 'APPS/Dataproviders/Customer/Comenzi/Comenzi';

    export default {
        props: {
            value: {required: true},
            errors: {default: null},
            disabled: {default: false},
            contract_id: {default: null},
        },

        data: () => ({
            dataprovider: null,
        }),

        watch: {
            contract_id: function(contract_id) {
                if(contract_id)
                {
                    this.dataprovider.GetByContractId(contract_id);
                }
                else
                {
                    this.$emit('input', null);
                }
            }
        },

        created() {
            this.dataprovider = new DataProvider(null);
            if(this.contract_id)
            {
                this.dataprovider.GetByContractId(this.contract_id)
            }
        },

        components: {
            AutocompleteSelector: require('./../AutocompleteSelector').default,
        },

        name: 'ComandaAutocompleteSelector',
    }
</script>