<template>
    <a-dropdown>
        <div class="header-avatar" style="cursor: pointer">
            <a-avatar class="avatar" size="small" shape="circle" :src="user.avatar" />
            <span class="name">{{user.name}}</span>
        </div>
        <a-menu :class="['avatar-menu']" slot="overlay">
            <a-menu-item>
                <a-icon type="user" />
                <span>{{profile}}</span>
            </a-menu-item>
            <a-menu-item>
                <a-icon type="setting" />
                <span>{{setting}}</span>
            </a-menu-item>
            <a-menu-divider />
            <a-menu-item @click="logout">
                <a-icon style="margin-right: 8px;" type="poweroff" />
                <span>{{loginOut}}</span>
            </a-menu-item>
        </a-menu>
    </a-dropdown>
</template>

<script>
import { mapGetters } from 'vuex';
import { logout } from '@/pages/frame/services/accountService';
import layoutTopHeaderI18n from './i18n';

export default {
    name: 'LayoutTopHeaderAvatar',
    i18n: layoutTopHeaderI18n,
    computed: {
        ...mapGetters('accountModule', ['user']),
        profile() {
            return this.$t('profile');
        },
        setting() {
            return this.$t('setting');
        },
        loginOut() {
            return this.$t('loginOut');
        },
    },
    methods: {
        logout() {
            logout();
            this.$router.push('/login');
        },
    },
};
</script>

<style lang="less">
.header-avatar {
    display: inline-flex;
    .avatar,
    .name {
        align-self: center;
    }
    .avatar {
        margin-right: 8px;
    }
    .name {
        font-weight: 500;
    }
}
.avatar-menu {
    width: 150px;
}
</style>
