<template>
    <v-sheet tile>
        <template v-if="action != 'delete'">
          
            <v-row dense>
                <v-col cols="12">
                    <customer-selector 
                        :customers="customers"
                        :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">
                    <account-user-control
                        :users="users"
                        :errors="errorsManager.ByField('user_id')"
                        @focus="errorsManager.ResetField('user_id')"
                        @blur="errorsManager.Validate('user_id')"

                        v-model="activeRecord"

                        @show-user-insert-form="$emit('show-user-insert-form', $event)"
                    />
                </v-col>

                <v-col cols="6">
                    <account-department-control 
                        :departamente="departamente"
                        :errors="errorsManager.ByField('department_id')"
                        :disabled="! activeRecord.customer_id"
                        @focus="errorsManager.ResetField('department_id')"
                        @blur="errorsManager.Validate('department_id')"
                        v-model="activeRecord"
                    />
                </v-col>

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

                <v-col cols="12">
                    <account-role-control 
                        :errors="errorsManager.ByField('user.role_id')"
                        @focus="errorsManager.ResetField('user.role_id')"
                        @blur="errorsManager.Validate('user.role_id')"
                        v-model="activeRecord"
                    />
                </v-col>

                <v-col cols="12">
                    <account-newsletter-control 

                        v-model="activeRecord"
                    />
                </v-col>

            </v-row>

        </template>

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

<script>
    export default {

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

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

        name: 'CustomerAccountInput',
    }
</script>