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

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

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

                <v-col cols="12">
                    <departament-autocomplete-selector 
                        :customer_id="activeRecord.customer_id"
                        :disabled="! activeRecord.customer_id"
                        :errors="errorsManager.ByField('departament_id')"
                        :departmentForm="departmentForm"
                        
                        :app="app"

                        @focus="errorsManager.ResetField('departament_id')"
                        @blur="errorsManager.Validate('departament_id')"
                        v-model="activeRecord.departament_id"
                    />
                </v-col>

                <v-col cold="12">
                    <v-radio-group
                        dense
                        hide-details
                        outlined
                        class="mt-0"
                        row
                        :disabled="app.platform == 'b2b'"
                        v-model="activeRecord.status"
                    >
                        <template v-slot:label>
                            <div class="text-body-2 font-weight-bold mb-1" v-html="__('Status')">
                            </div>
                        </template>

                        <v-radio
                            v-for="(option, index) in statuses"
                            :key="'option-' + index"
                            :value="option.value"
                            :label="option.text"
                        >
                        </v-radio>
                        
                    </v-radio-group>
                </v-col>

            </v-row>
        </template>

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

<script>
    export default {

        props: {
            app: {required: true},
            controls: {default: () => ({})},
            activeRecord: {required: true},
            errorsManager: {required: true},
            action: {required: true},
            currentAction: {required: true},
            departmentForm: {default: null},
            statuses: {default: () => ([
                {
                    text: 'Public',
                    value: 'public',
                },

                {
                    text: 'Privat',
                    value: 'protected',
                }
            ])},
        },

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

        name: 'DepartamentInput',
    }
</script>