<template>
    <v-sheet tile>

        <template v-if="action != 'delete'">
            <v-row dense>
                <v-col cols="12">
                    <cs-text-box 
                        ref="First"
                        :control="controls.departament"
                        :errors="errorsManager.ByField('departament')"
                        v-model="activeRecord.departament"
                        @focus="errorsManager.ResetField('departament')"
                        @blur="errorsManager.Validate('departament')"
                    />
                </v-col>

                <v-col cols="7">
                    <cs-text-box 
                        :control="controls.nume_responsabil"
                        :errors="errorsManager.ByField('nume_responsabil')"
                        v-model="activeRecord.nume_responsabil"
                        @focus="errorsManager.ResetField('nume_responsabil')"
                        @blur="errorsManager.Validate('nume_responsabil')"
                    />
                </v-col>

                <v-col cols="5">
                    <cs-text-box 
                        :control="controls.numar_angajati"
                        :errors="errorsManager.ByField('numar_angajati')"
                        v-model="activeRecord.numar_angajati"
                        @focus="errorsManager.ResetField('numar_angajati')"
                        @blur="errorsManager.Validate('numar_angajati')"
                    />
                </v-col>

                <v-col cols="5">
                    <cs-text-box 
                        :control="controls.telefon"
                        :errors="errorsManager.ByField('telefon')"
                        v-model="activeRecord.telefon"
                        @focus="errorsManager.ResetField('telefon')"
                        @blur="errorsManager.Validate('telefon')"
                    />
                </v-col>

                <v-col cols="7">
                    <cs-text-box 
                        :control="controls.email"
                        :errors="errorsManager.ByField('email')"
                        v-model="activeRecord.email"
                        @focus="errorsManager.ResetField('email')"
                        @blur="errorsManager.Validate('email')"
                    />
                </v-col>

            </v-row>
        </template>

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

        <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>
    export default {

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

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

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

        components: {
            CsTextBox: require('@CsVueComp/controls/texts/CsTextBox').default, 
            CsInfoAlert: require('@CsVueComp/sheets/CsInfoAlert').default,
        },

        name: 'DepartamentInput',
    }
</script>