<template>
    <v-sheet tile>

        <template v-if="action != 'delete'">
            <v-row dense>
                <v-col cols="12">
                    <customer-autocomplete-selector 
                        :errors="errorsManager.ByField('customer_id')"
                        @focus="errorsManager.ResetField('customer_id')"
                        @blur="errorsManager.Validate('customer_id')"
                        v-model="activeRecord.customer_id"
                    />
                </v-col>

                <v-col cols="12">
                    <contract-autocomplete-selector 
                        :disabled="! activeRecord.customer_id"
                        :customer_id="activeRecord.customer_id"
                        :errors="errorsManager.ByField('contract_id')"
                        @focus="errorsManager.ResetField('contract_id')"
                        @blur="errorsManager.Validate('contract_id')"
                        v-model="activeRecord.contract_id"
                    />
                </v-col>

                <v-col cols="12">
                    <comanda-autocomplete-selector 
                        :disabled="! activeRecord.contract_id"
                        :contract_id="activeRecord.contract_id"
                        :errors="errorsManager.ByField('order_id')"
                        @focus="errorsManager.ResetField('order_id')"
                        @blur="errorsManager.Validate('order_id')"
                        v-model="activeRecord.order_id"
                    />
                </v-col>

                <v-col cols="12">
                    <nomenclator-servicii-autocomplete-selector 
                        :errors="errorsManager.ByField('service_id')"
                        @focus="errorsManager.ResetField('service_id')"
                        @blur="errorsManager.Validate('service_id')"
                        v-model="activeRecord.service_id"
                        @inputrecord="OnInputRecord"
                    />
                </v-col>

            </v-row>
        </template>

        <cs-info-alert 
            v-else-if="true"
            color="red"
            icon="mdi-alert"
            :message="__('Sunteți sigur că doriți ștergerea contractului :name?', {
                name: 'xxx'
            })"
        />

        <cs-info-alert 
            v-else
            color="red"
            icon="mdi-alert"
            :message="__('Departamentul :name nu se poate șterge. Conține conturi asociate.', {
                name: activeRecord.departament
            })"
        />
    </v-sheet>
</template>

<script>

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

    export default {

        props: {
            controls: {default: () => ({})},
            activeRecord: {required: true},
            errorsManager: {required: true},
            action: {required: true},
            currentAction: {required: true},
        },

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

        // computed: {

        //     services() {
        //         return this.dataprovider.items;
        //     }
        // },

        methods: {
            OnInputRecord(e) {
            },

            Focus() {
                
                // this.$refs.First.Focus();
            }
        },

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

        mounted() {
            if(this.action != 'delete')
            {
                setTimeout( () => {
                    this.Focus();
                }, 150);
            }    
        },

        components: {
            CsTextBox: require('@CsVueComp/controls/texts/CsTextBox').default, 
            // CsEditBox: require('@CsVueComp/controls/texts/CsEditBox').default, 
            // CitySelector: require('@MyDpoComp/Entities/City/Controls/Selector/CitySelector').default,
            // TipOrganizatieSelector: require('@MyDpoComp/Entities/TipOrganizatie/Controls/Selector/TipOrganizatieSelector').default,
            CsInfoAlert: require('@CsVueComp/sheets/CsInfoAlert').default,
        },

        name: 'ServiciuComandatInput',
    }
</script>