<template>
    <autocomplete-selector 
        :value="value"
        :errors="errors"
        label="Serviciu"
        :dataprovider="dataprovider"

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

<script>

    import DataProvider from 'APPS/Dataproviders/Nomenclatorservicii/Nomenclatorservicii';

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

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

        methods: {
            ServiceById(id) {
                if(! id )
                {
                    return null;
                }
                let service = _.find(this.dataprovider.items, item => item.id == id);
                return {...service};
            }
        },

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

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

        name: 'NomenclatorServiciiAutocompleteSelector',
    }
</script>