<script setup>
/**
 * name：
 * user：sa0ChunLuyu
 * date：2022-05-24 14:48:31
 */
import {useStore, useConfig} from "~/store";
import {isDark, toggleDark, isFull, toggleFull} from '~/composables'
import $router from "~/router";
import {$image} from '~/api'

const $store = useStore()
const $config = useConfig()
const layout_header_wrapper_height = computed(() => {
  return `${$config.value.layout.header}px`
})
const options = [{
  label: '个人设置',
  key: 'set',
  props: {
    onClick: () => {
      $router.push({
        name: 'admin-info'
      })
    }
  }
}, {
  label: '退出登录',
  key: "quit",
  props: {
    onClick: () => {
      $router.push({
        name: 'login'
      })
    }
  }
}]
</script>
<template>
  <div class="user_wrapper">
    <n-button text @click="toggleFull()" mr-5>
      <Icon v-if="isFull" type="off-screen"></Icon>
      <Icon v-else type="full-screen"></Icon>
    </n-button>
    <n-button text @click="toggleDark()" mr-5>
      <Icon v-if="isDark" type="sun-one"></Icon>
      <Icon v-else type="moon"></Icon>
    </n-button>
    <div mr-5>
      <n-dropdown trigger="hover" :options="options">
        <n-space align="center">
          <n-avatar round :size="40" class="avatar_wrapper" :src="$image($store.config['Logo'])"
                    :fallback-src="$image($store.config['Logo'])"/>
          <span>{{ $store.admin_info ? $store.admin_info.nickname : $store.config['网站名称'] }}</span>
        </n-space>
      </n-dropdown>
    </div>
  </div>
</template>
<style scoped>
.avatar_wrapper {
  background: #ffffff;
}

.user_wrapper {
  position: absolute;
  right: 0;
  top: 0;
  height: v-bind(layout_header_wrapper_height);
  display: flex;
  align-items: center;
}
</style>
