<template>
  <aside class="flex h-full justify-between md:flex-col">
    <nav class="flex flex-nowrap md:flex-col">
      <NuxtLink
        v-for="(navigation, index) in primaryNavigation"
        :key="`navigation-${index}`"
        :to="localePath(navigation.target)"
        class="nav-link"
      >
        <i v-if="navigation.icon" class="material-icons">
          {{ navigation.icon }}
        </i>
        <div v-if="navigation.svg" class="h-4 w-4">
          <SmartIcon :name="navigation.svg" class="svg-icons" />
        </div>
        <span>{{ navigation.title }}</span>
      </NuxtLink>
    </nav>
    <nav
      class="
        flex flex-nowrap
        p-4
        items-center
        justify-center
        md:(flex-col
        space-x-0 space-y-2)
      "
    >
      <TabPrimary
        v-tippy="{ theme: 'tooltip', placement: 'top' }"
        :title="$t('app.invite')"
        icon="person_add_alt"
        @click.native="showShare = true"
      />
      <TabPrimary
        v-tippy="{ theme: 'tooltip', placement: 'top' }"
        :title="`${$t('support.title')} <kbd>?</kbd>`"
        icon="support"
        @click.native="showSupport = true"
      />
    </nav>
    <AppSupport :show="showSupport" @hide-modal="showSupport = false" />
    <AppShare :show="showShare" @hide-modal="showShare = false" />
  </aside>
</template>

<script lang="ts">
import { defineComponent, ref } from "@nuxtjs/composition-api"
import { defineActionHandler } from "~/helpers/actions"

export default defineComponent({
  setup() {
    const showSupport = ref(false)
    const showShare = ref(false)

    defineActionHandler("modals.support.toggle", () => {
      showSupport.value = !showSupport.value
    })

    defineActionHandler("modals.share.toggle", () => {
      showShare.value = !showShare.value
    })

    return {
      showSupport,
      showShare,
    }
  },
  data() {
    return {
      primaryNavigation: [
        {
          target: "index",
          icon: "settings_ethernet",
          title: this.$t("navigation.rest"),
        },
        {
          target: "graphql",
          svg: "graphql",
          title: this.$t("navigation.graphql"),
        },
        {
          target: "realtime",
          icon: "language",
          title: this.$t("navigation.realtime"),
        },
        {
          target: "documentation",
          icon: "book",
          title: this.$t("navigation.doc"),
        },
        {
          target: "settings",
          icon: "settings",
          title: this.$t("navigation.settings"),
        },
      ],
    }
  },
})
</script>

<style scoped lang="scss">
.nav-link {
  @apply p-4;
  @apply flex flex-col flex-1;
  @apply items-center;
  @apply justify-center;
  @apply transition;
  @apply hover:(bg-primaryDark text-secondaryDark);
  @apply focus-visible:(ring ring-inset ring-accent);

  .material-icons,
  .svg-icons {
    @apply opacity-75;
  }

  span {
    @apply mt-2;
    @apply font-semibold;
  }

  &.exact-active-link {
    @apply text-accent;
    @apply hover:text-accent;

    .material-icons,
    .svg-icons {
      @apply opacity-100;
    }
  }
}
</style>
