<template>
    <v-form>
        <v-text-field :label="l.email" disabled v-model="user.email" type="email" required></v-text-field>
        <v-text-field :label="l.passwordChange" v-model="form.password" type="password" required></v-text-field>
        <v-text-field :label="l.passwordRetype" v-model="form.passConfirm" type="password" required></v-text-field>
        <v-btn @click="update" color="green">{{ l.update }}</v-btn>
        <v-btn @click="signout" color="grey" class="float-right">{{ l.signout }}</v-btn>
    </v-form>
</template>

<script>

export default {
    data() {
        return {
            form:{
                password: '',
                passConfirm: ''
            },
        }
    },
    methods: {
        async signout() {
            await this.$api.user.signout();
            await this.loadUser();
        },
        async update() {
            let response = await this.$api.user.update({...this.form, _id: this.user._id});
            if(response.data.status === 'OK') {
                this.toast('Profile updated successfully', 'green');
            } else {
                this.toast(this.getErrorText(response.data), 'red');
            }
        }
    }
}
</script>