<script setup lang="ts">
import appStore from "@/stores"
import apis from "@a"
const router = useRouter()
const user = appStore.authStore.user
const dynamic = computed(() => {
	return appStore.tenantStore.isDynamic()
})
function clearCache() {
	appStore.dictStore.cleanDict().then(() => {
		message.msgSuccess("清除成功")
	})
}
function refreshConfig() {
	apis.system.configApi.refreshCache().then(() => {
		message.msgSuccess("刷新成功")
	})
}
function signOut() {
	appStore.authStore.logout().then(() => {
		location.href = import.meta.env.VITE_APP_CONTEXT_PATH + "home"
	})
}
</script>

<template>
	<div class="app-navbar-item ms-1 ms-md-3">
		<div
			class="cursor-pointer symbol symbol-30px symbol-md-40px"
			data-vb-menu-trigger="click"
			data-vb-menu-attach="parent"
			data-vb-menu-placement="bottom-end">
			<VbSymbol
				url="/resource/oss"
				:src="user.avatar"
				:text="user.userName"
				:size="40"
				alt="user" />
		</div>
		<div
			class="menu menu-sub menu-sub-dropdown menu-column menu-rounded menu-gray-600 menu-state-bg-light-primary py-4 fs-6 w-275px"
			data-vb-menu="true">
			<div class="menu-item px-3">
				<div class="menu-content d-flex align-items-center px-3">
					<div class="symbol symbol-50px me-5">
						<VbSymbol url="/resource/oss" :src="user.avatar" :text="user.userName" alt="user" />
					</div>

					<div class="d-flex flex-column">
						<div class="fw-bold d-flex align-items-center fs-5">
							{{ user.nickName }}
							<span
								v-if="user.orgName"
								class="badge badge-light-success fw-bold fs-8 px-2 py-1 ms-2">
								{{ user.orgName }}
							</span>
						</div>
						<a href="#" class="text-muted text-hover-primary fs-7">{{ user.email }}</a>
					</div>
				</div>
			</div>

			<div class="separator my-2"></div>

			<div class="menu-item px-5" v-if="!dynamic">
				<router-link to="/profile" class="menu-link px-5">
					<VbIcon icon-name="user" icon-type="duotone" class="me-2 fs-3"></VbIcon>
					个人中心
				</router-link>
			</div>
			<div class="menu-item px-5">
				<span @click="clearCache" class="menu-link px-5">
					<VbIcon icon-name="eraser" icon-type="duotone" class="me-2 fs-3"></VbIcon>
					清除缓存
				</span>
			</div>
			<div class="menu-item px-5">
				<span @click="refreshConfig" class="menu-link px-5">
					<VbIcon icon-name="arrows-circle" icon-type="duotone" class="me-2 fs-3"></VbIcon>
					刷新配置
				</span>
			</div>
			<div class="separator my-2"></div>

			<div class="menu-item px-5">
				<a @click="signOut()" class="menu-link px-5">
					<VbIcon icon-name="power" icon-type="duotone" class="me-2 fs-3"></VbIcon>
					退出登录
				</a>
			</div>
		</div>
	</div>
</template>
