<template>
  <transition name="slide">
    <div
      v-click-outside="close"
      class="profile-sidebar"
      v-if="sidebar.profile">
      <a
        class="profile-sidebar__close-link"
        @click="close">
        <cross class="profile-sidebar__close-icon"/>
      </a>
      <div class="profile-sidebar__section">
        <profile-widget class="profile-sidebar__item"/>
        <div
          class="profile-sidebar__item"
          @click="close">
          <router-link
            to="/me/activity"
            class="profile-sidebar__link">Meine Aktivitäten
          </router-link>
        </div>
      </div>
      <div class="profile-sidebar__section">
        <div class="profile-sidebar__item">
          <class-selection-widget/>
          <div @click="close">
            <router-link
              :to="{name: 'my-class'}"
              data-cy="class-list-link"
              class="profile-sidebar__link">Klassenliste
            </router-link>
          </div>
        </div>
      </div>
      <div class="profile-sidebar__section">
        <div
          class="profile-sidebar__item"
          @click="close">
          <router-link
            :to="{name:'join-class'}"
            data-cy="join-class-link"
            class="profile-sidebar__link">Zugangscode
          </router-link>
        </div>
        <div class="profile-sidebar__item">
          <logout-widget/>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
  import ProfileWidget from '@/components/profile/ProfileWidget';
  import Cross from '@/components/icons/Cross';

  import ClassSelectionWidget from '@/components/school-class/ClassSelectionWidget';

  import sidebarMixin from '@/mixins/sidebar';
  import LogoutWidget from '@/components/LogoutWidget';

  export default {

    mixins: [sidebarMixin],

    components: {
      LogoutWidget,
      ClassSelectionWidget,
      ProfileWidget,
      Cross
    },

    methods: {
      close() {
        this.closeSidebar('profile')
      }
    },
  }
</script>

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

  $desktop-width: 333px;

  .profile-sidebar {
    padding: $large-spacing 0;
    box-sizing: border-box;
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    height: 100vh;
    background-color: $color-white;
    z-index: 15;
    box-shadow: 0 3px 9px 0 rgba(0, 0, 0, 0.12);
    overflow-y: scroll;

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

    display: flex;
    flex-direction: column;
    justify-content: flex-start;

    &__section {
      margin-bottom: $large-spacing;

      &:last-of-type {
        margin-top: auto;
      }
    }

    &__item {
      padding: $small-spacing $medium-spacing;
    }

    &__subtitle {
      @include small-text;
      margin: 0;
      margin-bottom: $small-spacing;
    }

    &__link {
      @include default-link;
      display: block;
    }

    &__close-link {
      position: absolute;
      right: $small-spacing;
      top: $small-spacing;
      cursor: pointer;
    }
  }

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

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