<template>
  <div class="navbar">
    <div class="left-side">
      <a-space>
        <div class="logo">
          <!-- <img alt="logo" :src="logo" width="30" height="30" /> -->
          <div class="logo-container">
            <div class="logo-text">
              <!-- <img alt="logo" :src="bannerImage" width="30" height="30" /> -->
              <span>Logo</span>
            </div>
          </div>
        </div>
        <a-typography-title
          :style="{ margin: 0, fontSize: '20px' }"
          :heading="5"
        >
          项目管理系统
        </a-typography-title>
        <icon-menu-fold
          v-if="appStore.device === 'mobile'"
          style="font-size: 22px; cursor: pointer"
          @click="toggleDrawerMenu"
        />
      </a-space>
    </div>
    <ul class="right-side">
      <li>
        <a-tooltip :content="theme === 'light' ? '暗黑模式' : '明亮模式'">
          <a-button
            class="nav-btn"
            type="outline"
            :shape="'circle'"
            @click="handleToggleTheme"
          >
            <template #icon>
              <icon-moon-fill v-if="theme === 'dark'" />
              <icon-sun-fill v-else />
            </template>
          </a-button>
        </a-tooltip>
      </li>
      <li>
        <a-tooltip :content="isFullscreen ? '退出全屏' : '全屏'">
          <a-button
            class="nav-btn"
            type="outline"
            :shape="'circle'"
            @click="toggleFullScreen"
          >
            <template #icon>
              <icon-fullscreen-exit v-if="isFullscreen" />
              <icon-fullscreen v-else />
            </template>
          </a-button>
        </a-tooltip>
      </li>
      <!-- <li>
        <a-tooltip content="设置">
          <a-button
            class="nav-btn"
            type="outline"
            :shape="'circle'"
            @click="setVisible"
          >
            <template #icon>
              <icon-settings />
            </template>
          </a-button>
        </a-tooltip>
      </li> -->
      <li>
        <a-dropdown trigger="hover" position="bl">
          <a-avatar
            :size="32"
            :style="{
              cursor: 'pointer',
              backgroundColor: 'rgb(var(--primary-6))'
            }"
          >
            <IconUser />
          </a-avatar>
          <template #content>
            <a-doption>
              <a-space @click="$router.push({ name: 'Self' })">
                <icon-user />
                <span> 个人中心 </span>
              </a-space>
            </a-doption>
            <a-doption>
              <a-space @click="handleLogout">
                <icon-export />
                <span> 退出 </span>
              </a-space>
            </a-doption>
          </template>
        </a-dropdown>
      </li>
    </ul>
  </div>
</template>

<script lang="ts" setup>
import { computed, inject } from 'vue'
import { useDark, useToggle, useFullscreen } from '@vueuse/core'
import { useAppStore, useUserStore } from '@/store'
import useUser from '@/hooks/user'
import { IconUser } from '@arco-design/web-vue/es/icon'
// import logo from '@/assets/images/logo.png'
// import bannerImage from '@/assets/images/logo.png'

const userStore = useUserStore()
const { getRouter } = userStore

const appStore = useAppStore()
const { logout } = useUser(getRouter)
const { isFullscreen, toggle: toggleFullScreen } = useFullscreen()
const theme = computed(() => {
  return appStore.theme
})
const isDark = useDark({
  selector: 'body',
  attribute: 'arco-theme',
  valueDark: 'dark',
  valueLight: 'light',
  storageKey: 'arco-theme',
  onChanged(dark: boolean) {
    // overridden default behavior
    appStore.toggleTheme(dark)
  }
})
const toggleTheme = useToggle(isDark)
const handleToggleTheme = () => {
  toggleTheme()
}
// const setVisible = () => {
//   appStore.updateSettings({ globalSettings: true })
// }
const handleLogout = () => {
  logout()
}
const toggleDrawerMenu: any = inject('toggleDrawerMenu')
</script>

<style scoped lang="less">
.navbar {
  display: flex;
  justify-content: space-between;
  height: 100%;
  background-color: var(--color-bg-2);
  border-bottom: 1px solid var(--color-border);
}

.left-side {
  display: flex;
  align-items: center;
  padding-left: 15px;
  .logo {
    width: 40px;
    height: 40px;
    border-radius: 5px;
    .logo-container {
      width: 100%;
      height: 100%;
      .logo-text {
        display: flex;
        border-radius: 6px;
        align-items: center;
        justify-content: center;
        box-sizing: border-box;
        width: 100%;
        height: 100%;
        overflow: hidden;
        text-align: center;
        white-space: pre-wrap;
        background-color: #adddf3;
        span {
          font-size: 14px;
          color: #fff;
          font-weight: 700;
          line-height: 16px;
          padding: 2px;
        }
      }
    }
    // border: 1px solid #ebeef5;
    // background: #fff;
  }
}

.right-side {
  display: flex;
  padding-right: 20px;
  list-style: none;

  :deep(.locale-select) {
    border-radius: 20px;
  }

  li {
    display: flex;
    align-items: center;
    padding: 0 10px;
  }

  a {
    color: var(--color-text-1);
    text-decoration: none;
  }

  .nav-btn {
    border-color: rgb(var(--gray-2));
    color: rgb(var(--gray-8));
    font-size: 16px;
  }

  .trigger-btn,
  .ref-btn {
    position: absolute;
    bottom: 14px;
  }

  .trigger-btn {
    margin-left: 14px;
  }
}
</style>
