<template>
  <div class="header">
    <div class="logo" :title="name">{{name}}</div>
    <ul>
      <li @click="onClick(item)" :class="{active: (currentTab && currentTab.indexOf(item.id)>-1)}"
        v-for="(item,i) in menu" :key="i">
        <div>{{item.name}}</div>
      </li>
    </ul>
  </div>
</template>

<script setup>
import { ref, onMounted, computed, nextTick, provide } from "vue";
import { Loading } from "@/components/UI";
import { useRouter, useRoute } from "vue-router";

import { getConfig } from "@/config/api";



const router = useRouter();
const route = useRoute();

const name = ref('')

const menu = ref([
  {
    name: '首页',
    id: 'home',
  },
  {
    name: '广东省博物馆',
    id: 'gdmuseum',
  },
  {
    name: '热门展览',
    id: 'exhibition',
  },
  {
    name: '精品典藏',
    id: 'collection',
  },
  // {
  //   name: '展馆概况',
  //   id: 'overview',
  // },
])

const currentTab = computed(() => route.name)

const onClick = data => {
  setTimeout(() => {
    router.push({ name: data.id })
  });

}

onMounted(() => {
  getConfig(data=>{
    name.value = data.data.name
  })
})

</script>

<style lang="scss" scoped>
.header {
  background: var(--main-color);
  width: 100%;
  padding: 0 60px;
  height: 80px;
  display: flex;
  justify-content: space-between;
  align-items: center;

  .logo {
    flex-shrink: 0;
    font-size: 30px;
    font-weight: bold;
    flex: 1 1 auto;
    min-width: 200px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  >ul {
    flex: 1 0 auto;
    display: flex;
    height: 100%;
    justify-content: space-between;
    >li {
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;
      height: 100%;
      cursor: pointer;
      white-space: nowrap;
      margin-left: 10px;
      >div {
        font-size: 20px;
      }

      &.active {
        color: var(--font-active);
        font-weight: bold;

        &::after {
          position: absolute;
          content: '';
          bottom: 0;
          left: 50%;
          transform: translateX(-50%);
          border: 10px solid transparent;
          border-bottom-color: var(--font-active);

        }
      }
    }
  }
}
</style>