<template>
    <div class="app-header">
        <div class="app-header__left">
            <slot name="left"></slot>
            <el-breadcrumb :separator-icon="ArrowRight" v-show="!state.isMobile">
                <template v-for="(item, index) in $route.matched" :key="index">
                    <el-breadcrumb-item :to="{ path: item.path }">
                        <!--<i :class="item.meta.icon" v-if="item.meta.icon"></i>-->
                        <span>{{ item.meta.title ?? 'item.name' }}</span>
                    </el-breadcrumb-item>
                </template>
            </el-breadcrumb>
        </div>
        <div class="app-header__right">
            <slot name="right"></slot>
            <div class="iconbar">
                <el-badge type="danger" is-dot>
                    <span class="g-icon--notice"></span>
                </el-badge>
                <span class="g-icon--minimize" @click="exitFullSreen" v-if="fullScreen"></span>
                <span class="g-icon--maximize" @click="setFullSreen" v-else></span>
            </div>
            <el-dropdown class="user-dropdown" trigger="click">
                <span class="user-dropdown__link">
                    <img class="g-image--avatar" :src="admin.avatar" :title="admin.realName" />
                    <span v-if="!state.isMobile">{{ admin.realName }}</span>
                    <el-icon class="el-icon--right">
                        <arrow-down />
                    </el-icon>
                </span>
                <template #dropdown>
                    <el-dropdown-menu>
                        <el-dropdown-item :icon="Key">修改密码</el-dropdown-item>
                        <el-dropdown-item :icon="SwitchButton" @click="logout">退出登录</el-dropdown-item>
                    </el-dropdown-menu>
                </template>
            </el-dropdown>
        </div>
    </div>
</template>

<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import { ArrowRight, Key, SwitchButton, ArrowDown } from '@element-plus/icons-vue'
import client from '@/utils/client'
import { useAdmin } from '@/business/admin'

const { state } = client;
const { admin, logout } = useAdmin();
const fullScreen = ref(false);

// 全屏
const setFullSreen = () => {
    document.documentElement.requestFullscreen();
}

// 退出全屏
const exitFullSreen = () => {
    document.exitFullscreen();
}

onMounted(() => {
    // 监听全屏变化
    window.addEventListener('fullscreenchange', () => {
        if (document.fullscreenElement) {
            fullScreen.value = true;
        } else {
            fullScreen.value = false;
        }
    })
})
</script>

<style lang="less" scoped>
@import './index.less';
</style>