<template>
    <v-card tile flat>
        
        <v-card-text class="py-2">
            <div class="font-weight-bold orange--text text-darken-3 mb-4">
                {{__('Semnătura din email')}}
            </div>

            <v-textarea
                dense
                hide-details
                auto-grow
                no-resize
                rows="3"
                :outlined="false"
                :clearable="true"
                :label="__('Introduceți semnătura de email')"
                v-model="emailSignature"
            >

            </v-textarea>
        </v-card-text>
        
        <v-card-actions class="py-0 d-flex justify-center">
            <cs-orange-btn 
                caption="Salvează"
                icon="mdi-content-save"
                :disabled="actionDisabled"
                :loading="app.requests.SaveUserEmailSignature.processing"
                @click="OnClickSave"
            /> 
        </v-card-actions>
    </v-card>
</template>

<script>
    export default {
        props: {
            app: {required: true},
            user: {required: true},
        },

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

        computed: {

            actionDisabled() {
                if(this.app.requests.SaveUserEmailSignature.processing)
                {
                    return true;
                }

                let s1 = this.emailSignature ? this.emailSignature.replace(/[\r\n]/gm, '') : '';
                let s2 = this.user.my_settings['email-signature'] ? this.user.my_settings['email-signature'].replace(/[\r\n]/gm, '') : '';

                return s1 == s2;
            },
        },

        methods: {
            OnClickSave() {
                this.app.requests.SaveUserEmailSignature
                    .ResetData()
                    .SetData({
                        user_id: this.user.id,
                        platform: this.app.platform,
                        customer_id: null,
                        code: 'email-signature',
                        value: this.emailSignature,
                    })
                    .Request([
                        response => this.app.LoadConfig(false),
                    ])

            }
        },

        created() {
            this.emailSignature = this.user.my_settings['email-signature'];
        },

        components: {
            CsOrangeBtn: require('@CsVueComp/buttons/CsOrangeBtn').default,
        },

        name: 'UserSettingsEmailSignature',
    }
</script>