<template>
  <!-- Changer le Menu actif
    class="active" sur le <li>
    aria-current="page" sur le <a>
  -->
  <button
    @click="toggleExpand()"
    class="btn btn--white | rounded-lg"
    aria-controls="menu"
    :aria-expanded="isExpanded"
  >
    <svg
      aria-labelledby="menu-toggle"
      class="icon"
      width="20"
      height="20"
      viewBox="0 0 20 20"
      fill="none"
      xmlns="http://www.w3.org/2000/svg"
    >
      <title id="menu-toggle">
        {{ isExpanded ? "Masquer le menu" : "Afficher le menu" }}
      </title>
      <path
        d="M10.6751 2.625L3.00007 10.3125C2.94028 10.3686 2.89263 10.4364 2.86005 10.5116C2.82748 10.5869 2.81067 10.668 2.81067 10.75C2.81067 10.832 2.82748 10.9131 2.86005 10.9884C2.89263 11.0636 2.94028 11.1314 3.00007 11.1875L10.6751 18.875M17.1876 2.625L9.50007 10.3125C9.38555 10.4293 9.32141 10.5864 9.32141 10.75C9.32141 10.9136 9.38555 11.0707 9.50007 11.1875L17.1876 18.875"
        stroke="currentColor"
        stroke-width="1.25"
        stroke-linecap="round"
        stroke-linejoin="round"
      />
    </svg>
  </button>
  <div v-if="isExpanded" id="menu" class="flex | rounded-lg">
    <header class="w-full | flex">
      <p>Nom du service</p>
    </header>
    <nav class="w-full | flow">
      <ul class="flex">
        <li
          v-for="mainItem in mainItems"
          data-icon="calendar"
          :key="mainItem.path"
          :class="{ active: isCurrent(mainItem) }"
        >
          <a :href="mainItem.path" :aria-current="isCurrent(mainItem)">{{
            mainItem.title
          }}</a>
          <span v-if="mainItem.pill" class="pill pill--secondary">{{
            mainItem.pill
          }}</span>
        </li>
      </ul>
      <details open>
        <summary>Projets en cours</summary>
        <ul>
          <li><a href="#" class="new">Miss Dior Blooming Bouquet</a></li>
          <li><a href="#">Dior J’adore</a></li>
          <li><a href="#">Gris Dior</a></li>
          <li><a href="#">Sauvage 60ml</a></li>
        </ul>
      </details>
      <details>
        <summary>Projets archivés</summary>
        <ul>
          <li><a href="#">Titre projet archivé 1</a></li>
          <li><a href="#">Titre projet archivé 2</a></li>
        </ul>
      </details>
    </nav>
    <footer class="w-full">
      <ul class="flex">
        <li data-icon="user">
          <a href="#">Profil</a>
        </li>
        <li data-icon="logout">
          <a href="#">Déconnexion</a>
        </li>
      </ul>
    </footer>
  </div>
</template>

<script setup>
import { ref } from "vue";

const isExpanded = ref(true);

const mainItems = [
  {
    title: "Home",
    path: "/",
    icon: "home",
  },
  {
    title: "Notifications",
    path: "/notifications",
    icon: "megaphone",
  },
  {
    title: "Réunions",
    path: "/reunions",
    icon: "calendar",
    pill: "Dans 2h",
  },
  {
    title: "Inspirations",
    path: "/inspirations",
    icon: "inspirations",
    pill: "Nouveauté",
  },
];

function toggleExpand() {
  isExpanded.value = !isExpanded.value;
}

function isCurrent(navItem) {
  return navItem.path === window.location.pathname;
}
</script>

<style scoped>
button[aria-controls="menu"] {
  position: fixed;
  z-index: 10;
  width: 2.5rem;
  height: 2.5rem;
}
button[aria-controls="menu"] svg {
  width: 100%;
  height: 100%;
}
button[aria-controls="menu"][aria-expanded="true"] {
  margin-top: 1rem;
  padding: 0.625rem; /* 10px */
  left: var(--gutter);
  transform: translateX(calc(var(--sidebar-width) - 100% - 1rem));
}
button[aria-controls="menu"][aria-expanded="false"] {
  width: 3.75rem;
  height: 3.75rem;
  padding: 1.25rem;
  transform: rotate(180deg);
}

/* Menu */

#menu {
  --flow-space: var(--space-32);
  --direction: column;
  --items: flex-start;
  --wrap: no-wrap;
  position: -webkit-sticky;
  position: sticky;
  top: var(--gutter);
  width: var(--sidebar-width);
  height: calc(100vh - var(--gutter) * 2);
  height: calc(100dvh - var(--gutter) * 2);
  padding: var(--gap);
  background: var(--color-background);
  overflow-y: auto;
}

#menu [data-icon]::before {
  background-color: var(--color-grey-700);
}

#menu header {
  --justify: center;
  padding-left: var(--gap);
  min-height: var(--space-40);
  font-family: var(--font-serif);
  font-size: var(--text-md);
  background: var(--color-background);
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 1;
}
#menu header::before {
  content: "";
  display: block;
  position: absolute;
  top: -1rem;
  left: 0;
  right: 0;
  bottom: -2rem;
  z-index: -1;
  background: linear-gradient(
    to bottom,
    var(--color-background) 0%,
    var(--color-background) 75%,
    transparent 100%
  );
}

#menu nav {
  --flow-space: var(--space-32);
  flex: 1 1 0%;
}

#menu ul {
  --direction: column;
  --items: flex-start;
  --row-gap: var(--space-4);
  width: 100%;
}

#menu li,
#menu summary {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 2.5rem; /* 40px */
  padding: 0 var(--space-16);
  gap: var(--space-12);
  border-radius: var(--rounded-md);
}

#menu li {
  position: relative;
  min-height: 2.75rem; /* 44px */
}

#menu li[data-count]::after {
  content: attr(data-count);
  display: inline-block;
  color: var(--color-primary);
  font-size: var(--text-sm);
  font-weight: 500;
  margin-left: auto;
}

#menu li .pill {
  margin-left: auto;
}

#menu li a::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  cursor: pointer;
}

#menu .active,
#menu li:hover {
  background-color: var(--color-grey-50);
}

#menu details {
  font-family: var(--font-serif);
  background-size: 1px 21px;
  background-image: repeating-linear-gradient(
    0deg,
    var(--color-grey-50),
    var(--color-grey-50) 1px,
    transparent 1px,
    transparent
  );
  background-repeat: repeat-x;
}
#menu details > summary {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-grey-700);
  background-color: var(--color-background);
  width: fit-content;
}
#menu details .new::after {
  content: "Nouvelles modifications";
  color: transparent;
  position: relative;
  display: inline-block;
  width: 0.375rem; /* 6px */
  height: 0.375rem; /* 6px */
  border-radius: var(--rounded-full);
  background-color: var(--color-primary-100);
  margin-left: var(--space-8);
  transform: translateY(-0.1em);
  overflow: hidden;
}
</style>
