<template>
  <transition name="slide">
    <div
      class="navigation-sidebar"
      v-if="sidebar.navigation"
      v-click-outside="close"
    >
      <content-navigation
        :is-sidebar="true"
        class="navigation-sidebar__main"
      />
      <div
        class="navigation-sidebar__close-button"
        @click="close"
      >
        <cross class="navigation-sidebar__close-icon" />
      </div>
    </div>
  </transition>
</template>

<script>
  import ContentNavigation from '@/components/book-navigation/ContentNavigation';

  import sidebarMixin from '@/mixins/sidebar';
  import {defineAsyncComponent} from 'vue';

  const Cross = defineAsyncComponent(() => import(/* webpackChunkName: "icons" */'@/components/icons/CrossIcon'));

  export default {
    mixins: [sidebarMixin],

    components: {
      ContentNavigation,
      Cross
    },

    methods: {
      close() {
        this.closeSidebar('navigation');
      }
    },

  };
</script>

<style scoped lang="scss">
  @import "@/styles/_variables.scss";
  @import "@/styles/_mixins.scss";

  $desktop-width: 285px;

  .navigation-sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
    background-color: white;
    z-index: 20;

    @include desktop {
      box-shadow: 0px 2px 9px rgba(0, 0, 0, 0.12);
    }

    display: grid;

    grid-template-columns: 1fr 50px;
    grid-template-rows: 50px max-content auto 100px;

    grid-template-areas: "m m" "m m" "s s" "s s";

    &--with-subnavigation {
      grid-template-areas: "m m" "m m" "sub sub" "s s";
    }

    height: 100vh;
    overflow-y: auto;

    @include desktop {
      width: $desktop-width;
    }

    &__main {
      padding: $medium-spacing;
      grid-area: m;
    }

    &__main-link {
    }

    &__close-button {
      grid-row: 1;
      grid-column: 2;
      align-self: center;
      justify-self: center;
      cursor: pointer;
    }
  }

  .slide {
    &-enter-active, &-leave-active {
      transition: left 0.2s;
    }

    &-enter-from, &-leave-to {
      left: -100vw;
      @include desktop {
        left: -$desktop-width;
      }
    }
  }
</style>
