<template>
	<el-container class="page-user">
		<el-aside style="width: 160px;">
			<el-container>
				<el-header style="height: auto;display: block;">
					<div class="user-info-top">
						<el-avatar :size="70" :src="user.avatar"></el-avatar>
						<h2>{{ user.nickname || user.username }}</h2>
						<p><el-tag effect="dark" round size="large" disable-transitions>{{ user.role }}</el-tag></p>
					</div>
				</el-header>
				<el-main class="nopadding">
					<el-menu class="menu" :default-active="page">
						<el-menu-item-group v-for="group in menu" :key="group.groupName" :title="group.groupName">
							<el-menu-item v-for="item in group.list" :key="item.component" :index="item.component" @click="openPage">
								<el-icon v-if="item.icon"><component :is="item.icon"/></el-icon>
								<template #title>
									<span>{{item.title}}</span>
								</template>
							</el-menu-item>
						</el-menu-item-group>
					</el-menu>
				</el-main>
			</el-container>
		</el-aside>
		<el-main>
			<Suspense>
				<template #default>
					<component :data="user" :is="page"/>
				</template>
				<template #fallback>
					<el-skeleton :rows="3" />
				</template>
			</Suspense>
		</el-main>
	</el-container>
</template>

<script>
	import { defineAsyncComponent } from 'vue'

	export default {
		name: 'userCenter',
		components: {
			account: defineAsyncComponent(() => import('./components/account')),
			seting: defineAsyncComponent(() => import('./components/seting')),
			pushSettings: defineAsyncComponent(() => import('./components/pushSettings')),
			password: defineAsyncComponent(() => import('./components/password')),
			space: defineAsyncComponent(() => import('./components/space')),
			logs: defineAsyncComponent(() => import('./components/logs')),
		},
		props: {
			modelValue: { type: Object, default: () => {} },
			type: { type: String, default: "" }
		},
		data() {
			return {
				menu: [
					{
						groupName: "基本设置",
						list: [
							{
								icon: "el-icon-postcard",
								title: "账号信息",
								component: "account"
							},
							{
								icon: "el-icon-operation",
								title: "个人设置",
								component: "seting"
							},
							{
								icon: "el-icon-lock",
								title: "密码",
								component: "password"
							},
							{
								icon: "el-icon-bell",
								title: "通知设置",
								component: "pushSettings"
							}
						]
					},
					{
						groupName: "数据管理",
						list: [
							{
								icon: "el-icon-coin",
								title: "存储空间信息",
								component: "space"
							},
							{
								icon: "el-icon-clock",
								title: "Offer",
								component: "logs"
							},
							{
								icon: "el-icon-clock",
								title: "租房",
								component: "logs"
							},
							{
								icon: "el-icon-clock",
								title: "我的附件",
								component: "logs"
							}
						]
					},
				],
				user: this.modelValue,
				page: "account"
			}
		},
		created() {

		},
		methods: {
			updateValue(event) {
		      	const newValue = event.target.value;
		      	this.$emit('update:modelValue', newValue);
		    },
			openPage(item){
				this.page = item.index
			}
		}
	}
</script>