<script setup>
import { ref } from "vue";
import Login from "@/views/Login.vue";

let menuShow = ref(false);
let collegeMenuShow = ref(false);
let dialog = ref(false);

function toggleMenu() {
  collegeMenuShow.value = false;
  menuShow.value = !menuShow.value;
}

function handleClose(value) {
  dialog.value = value;
}
</script>

<template>
  <div class="d-flex justify-space-between align-center navbar">
    <router-link :to="'/'">
      <img src="@/assets/img/logo.png" alt="" />
    </router-link>
    <ul class="menu align-center" :class="{ slider: menuShow }">
      <li>
        <router-link :to="'/news'">最新消息</router-link>
      </li>
      <li>
        <router-link :to="'/course-list'">探索課程</router-link>
      </li>
      <li class="position-relative">
        <a href="javascript:;" @mouseover="collegeMenuShow = true" @mouseleave="collegeMenuShow = false">工藝學群</a>
        <div class="college-slider" :class="{ slider: collegeMenuShow }" @mouseover="collegeMenuShow = true"
          @mouseleave="collegeMenuShow = false">
          <ul>
            <li>
              <router-link :to="'/college-group/generation'">世代工藝</router-link>
            </li>
            <li>
              <router-link :to="'/college-group/future'">未來工藝</router-link>
            </li>
            <li>
              <router-link :to="'/college-group/craft'">生活工藝</router-link>
            </li>
            <li>
              <router-link :to="'/college-group/craft'">技藝工藝</router-link>
            </li>
            <li>
              <router-link :to="'/college-group/teenager'">青年工藝</router-link>
            </li>
            <li>
              <router-link :to="'/college-group/repair'">修護工藝</router-link>
            </li>
            <li>
              <router-link :to="'/college-group/cross'">跨域工藝</router-link>
            </li>
            <li>
              <router-link :to="'/college-group/craft'">線上工藝</router-link>
            </li>
          </ul>
        </div>
      </li>
      <li>
        <router-link :to="'/'">知識文章</router-link>
      </li>
      <li>
        <!-- <router-link :to="'/login'">
          學員登入
        </router-link> -->
        <v-dialog v-model="dialog" max-width="450">
          <template v-slot:activator="{ props }">
            <a href="javascript:;" v-bind="props">學員登入</a>
          </template>
          <Login @close="handleClose" />
        </v-dialog>
      </li>
      <!-- <li>EN</li> -->
      <li class="d-none d-lg-block">
        <v-icon icon="mdi-magnify"></v-icon>
      </li>
      <li class="d-none d-lg-block">
        <v-icon icon="mdi-menu"></v-icon>
      </li>
    </ul>

    <a href="javascript:;" class="icon" @click="toggleMenu()">
      <v-icon icon="mdi-menu" class="mx-2"></v-icon>
    </a>
  </div>
</template>

<style lang="scss" scoped>
.navbar {
  width: 90%;
  max-width: 1300px;
  margin: 0 auto 40px;
  padding: 0 35px 0 15px;
  border: 1px solid;
  position: relative;
  z-index: 1000;
  background: transparent;
  top: 40px;
  left: 0;
  right: 0;

  @media (max-width: 1280px) {
    padding: 10px 20px 10px 10px;
  }

  @media (max-width: 767px) {
    top: 20px;
  }

  img {
    width: 100%;
    max-width: 370px;
    margin-top: 5px;
  }

  .menu {
    display: flex;
    align-items: center;
    list-style: none;

    @media (max-width: 1280px) {
      position: absolute;
      top: 80.5px;
      left: 0;
      right: 0;
      z-index: 100;
      overflow: hidden;
      flex-direction: column;
      box-shadow: 1px 1px 4px #ccc;
      max-height: 0;
      transition: max-height 0.3s ease-in-out;
    }

    &.slider {
      max-height: 700px;
      overflow: initial;
    }

    &>li {
      margin-left: 28px;
      font-weight: 400;

      @media (max-width: 1280px) {
        width: 100%;
        margin-left: 0;
        background: #fff;
        border-bottom: 1px solid #f0f0f0;
        font-weight: 500;
        text-align: center;
      }

      a {
        width: 100%;
        display: block;
        padding: 40px 0;
        color: #000;
        text-decoration: none;
        transition: all 0.3s;

        &:hover {
          opacity: 0.8;
        }

        @media (max-width: 1280px) {
          padding: 20px 0;
        }
      }
    }

    .college-slider {
      position: absolute;
      top: 80px;
      left: -30px;
      width: 130px;
      background: #fff;
      text-align: center;
      box-shadow: 1px 1px 4px #ccc;
      opacity: 0;
      transition: all 0.3s;

      @media (max-width: 1280px) {
        top: 30px;
        left: 50vw;
      }

      @media (max-width: 600px) {
        left: 58vw;
        width: 100px;
      }

      &.slider {
        opacity: 1;
      }

      li {
        &:last-child {
          border-bottom: none;
        }

        &:hover {
          background-color: #eeeeee;
        }

        a {
          display: block;
          width: 100%;
          padding: 15px 10px;
        }
      }
    }
  }

  .icon {
    display: none;
    transition: all 0.3s;

    @media (max-width: 1280px) {
      display: block;
    }

    &:hover {
      opacity: 0.8;
    }

    .v-icon {
      font-size: 2rem;
    }
  }

  &::before {
    content: "";
    position: absolute;
    top: 6px;
    left: 6px;
    width: 99%;
    height: 88%;
    background-color: rgba(255, 255, 255, 0.5);
    z-index: -1;

    @media (max-width: 960px) {
      top: 7px;
      left: 1.3vw;
      width: 97%;
      height: 83%;
    }
  }
}
</style>
