<template>
  <div class="navbar1" :style="{'backgroundColor' : background}">
    <!-- <top-nav id="topmenu-container" class="topmenu-container" v-if="settingsStore.topNav" /> -->
    <div class="left">
      <!-- <img src="@/assets/logo/logo.png" alt="dark" /> -->
      <span>
        百威BIM管理系统
      </span>
    </div>
    <div class="middle">
      BIM运维管理系统{{ test }}
    </div>
    <div class="right-menu">
      <template v-if="appStore.device !== 'mobile'">
        <p class="time">
          <font class="mr10"> {{ time }} </font><div class="mr10">{{ currentTime }}</div> <div class="mr10">{{ week }}</div>
        
        </p>
        <!-- <header-search id="header-search" class="right-menu-item" />

        <el-tooltip content="源码地址" effect="dark" placement="bottom">
          <ruo-yi-git id="ruoyi-git" class="right-menu-item hover-effect" />
        </el-tooltip>

        <el-tooltip content="文档地址" effect="dark" placement="bottom">
          <ruo-yi-doc id="ruoyi-doc" class="right-menu-item hover-effect" />
        </el-tooltip> -->
        <el-icon size="28" @click="goHome"><HomeFilled /></el-icon>
        <screenfull id="screenfull" class="right-menu-item hover-effect" />

        <el-tooltip content="布局大小" effect="dark" placement="bottom">
          <size-select id="size-select" class="right-menu-item hover-effect" />
        </el-tooltip>
      </template>
      <div class="avatar-container">
        <el-dropdown @command="handleCommand" class="right-menu-item hover-effect" trigger="click">
          <div class="avatar-wrapper">
            <img :src="userStore.avatar" class="user-avatar" />
            <el-icon><caret-bottom /></el-icon>
          </div>
          <template #dropdown>
            <el-dropdown-menu>
              <router-link to="/user/profile">
                <el-dropdown-item>个人中心</el-dropdown-item>
              </router-link>
              <el-dropdown-item command="setLayout" v-if="settingsStore.showSettings">
                <span>布局设置</span>
              </el-dropdown-item>
              <el-dropdown-item divided command="logout">
                <span>退出登录</span>
              </el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ElMessageBox } from 'element-plus'
import Breadcrumb from '@/components/Breadcrumb'
import TopNav from '@/components/TopNav'
import Hamburger from '@/components/Hamburger'
import Screenfull from '@/components/Screenfull'
import SizeSelect from '@/components/SizeSelect'
import HeaderSearch from '@/components/HeaderSearch'
import RuoYiGit from '@/components/RuoYi/Git'
import RuoYiDoc from '@/components/RuoYi/Doc'
import useAppStore from '@/store/modules/app'
import useUserStore from '@/store/modules/user'
import useSettingsStore from '@/store/modules/settings'
import dayjs from "dayjs";
import { computed } from 'vue'
const router = useRouter();
import bimStore from '@/store/modules/bim';

const appStore = useAppStore()
const userStore = useUserStore()
const settingsStore = useSettingsStore()

const data = reactive({
  interval: "",
  currentTime: "",
  time: "",
  week: "",
  background: ''
});
const { interval, currentTime, time, week,background } = toRefs(data);

onMounted(() => {
  interval.value = setInterval(updateTime, 1000);
});
onUnmounted(() => {
   clearInterval(interval.value);
});


watch(() => bimStore().activateMenu, value => background.value = value.background);
function toggleSideBar() {
  appStore.toggleSideBar()
}

function handleCommand(command) {
  switch (command) {
    case "setLayout":
      setLayout();
      break;
    case "logout":
      logout();
      break;
    default:
      break;
  }
}

function logout() {
  ElMessageBox.confirm('确定注销并退出系统吗？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    userStore.logOut().then(() => {
      location.href = '/index';
    })
  }).catch(() => { });
}

function goHome() {
  router.push('/index');
}
const updateTime = () => {
  currentTime.value = dayjs().format("YYYY年 MM月 DD日");
  time.value = dayjs().format("HH:mm");
  week.value = format(dayjs().day());
};
const format = (week) => {
  switch (week) {
    case 1:
      return '星期一';
      break;
    case 2:
      return '星期二';
      break;
    case 3:
      return '星期三';
      break;
    case 4:
      return '星期四';
      break;
    case 5:
      return '星期五';
      break;
    case 6:
      return '星期六';
      break;
    case 0:
      return '星期日';
      break;

  }
}
const emits = defineEmits(['setLayout'])
function setLayout() {
  emits('setLayout');
}
</script>

<style lang='scss' scoped>
.navbar1 {
  height: 70px;
  overflow: hidden;
  position: relative;
  // background: #202a60;
  display: flex;
  justify-content: space-between;
  background: url('@/assets/images/top_banner_deep.png') no-repeat #000000;
  background-size: 100% 100%;

  .left {
    width: 33%;
    // display: flex;
    // align-items: center;
    padding-left: 20px;
    color: #fff;
    font-size: 20px;
    line-height: 50px;
    height: 100%;
    img {
      height: 98%;
    }
  }

  .middle {
    width: 33%;
    // border: 1px solid red;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 30px;
  }

  .right-menu {
    width: 33%;
    // border: 1px solid red;
    display: flex;
    align-items: center;
    justify-content: end;

    .time {
      display: flex;
      align-items: center;
      height: 100%;
      font {
        font-size: 30px;
      }

      .currentTime-week {
        height: 70%;
        margin: 0 10px;

        >div {
          width: 100%;
          height: 40% !important;
          display: flex !important;
          align-items: center !important;
          justify-content: center;
        }
      }
    }
  }

  .hamburger-container {
    line-height: 46px;
    height: 100%;
    float: left;
    cursor: pointer;
    transition: background 0.3s;
    -webkit-tap-highlight-color: transparent;

    &:hover {
      background: rgba(0, 0, 0, 0.025);
    }
  }

  .breadcrumb-container {
    float: left;
  }

  .topmenu-container {
    position: absolute;
    left: 50px;
  }

  .errLog-container {
    display: inline-block;
    vertical-align: top;
  }

  .right-menu {
    float: right;
    height: 100%;
    display: flex;
    color: #fff;
    &:focus {
      outline: none;
    }

    .right-menu-item {
      display: inline-block;
      padding: 0 8px;
      height: 100%;
      font-size: 18px;
      color: #fff;
      vertical-align: text-bottom;
      display: flex;
      align-items: center;
      &.hover-effect {
        cursor: pointer;
        transition: background 0.3s;

        &:hover {
          background: rgba(0, 0, 0, 0.025);
        }
      }
    }

    .avatar-container {
      margin-right: 10px;

      .avatar-wrapper {
        margin-top: 5px;
        position: relative;

        .user-avatar {
          cursor: pointer;
          width: 40px;
          height: 40px;
          border-radius: 10px;
        }

        i {
          cursor: pointer;
          position: absolute;
          right: -20px;
          top: 25px;
          font-size: 12px;
        }
      }
    }
    :deep(.size-icon--style) {
      color: #fff;
    }
  }
}</style>
