<script setup lang="ts">
import { useData } from "vitepress";
import { computed } from "vue";

import ThemeToggle from "./ThemeToggle.vue";

const { site, theme } = useData();

const socialLinks = computed(() => {
  return theme.value.socialLinks ?? [];
});

const indexList = computed(() => {
  return theme.value.nav ?? [];
});
</script>

<template>
  <div class="TopBar">
    <div class="ProfileImageContainer">
      <img src="/images/me.jpeg" alt="{{ site.title }}" class="ProfileImage" />
    </div>

    <h1 class="title">{{ site.title }}</h1>
    <p class="subtitle">{{ site.description }}</p>

    <div class="RightSideTop">
      <ThemeToggle />
    </div>

    <div class="RightSideBottom">
      <div class="social-icons">
        <a
          v-for="(icon, index) in socialLinks"
          :key="index"
          :href="icon.link"
          target="_blank"
          rel="noopener noreferrer"
        >
          <img :src="icon.icon" :alt="icon.label" class="social-icon" />
        </a>
      </div>
    </div>
  </div>

  <div class="Separator"></div>
  <ul class="IndexList">
    <li v-for="{ text, link } of indexList" :key="title">
      <a :href="link">#{{ text }}</a>
    </li>
  </ul>
</template>

<style>
.TopBar {
  display: grid;
  grid-template-columns: 100px 1fr auto;
  grid-template-rows: auto auto;
  gap: 0 2em;
  align-items: center;
  padding: 1em;
}

.ProfileImageContainer {
  grid-row: 1 / 3;
  grid-column: 1;
  width: 100px;
  height: 100px;
  margin: auto;
  overflow: hidden;
  border: 2px solid var(--outline-color);
  border-radius: 50%;
}

.ProfileImage {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.title {
  grid-column: 2;
  grid-row: 1;
  margin: 0.75em 0 0;
  font-size: 2.5em;
  color: var(--primary-color);
}

.subtitle {
  grid-column: 2;
  grid-row: 2;
  margin: 0.25em 0 0;
  font-size: 1.5em;
  color: var(--text-color);
}

.RightSideTop {
  grid-column: 3;
  grid-row: 1;
  display: flex;
  justify-content: flex-end;
}

.RightSideBottom {
  grid-column: 3;
  grid-row: 2;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.social-icons {
  display: flex;
  margin-left: 1em;
  filter: var(--icon-filter);
}

.social-icon {
  width: 24px;
  height: 24px;
  margin: 0 0.4em;
}

.Separator {
  border-bottom: 1px solid var(--outline-color);
  margin: 0.5em 1em;
}

.IndexList {
  list-style: none;
  margin: 1em 0;
  margin-bottom: 2em;
  padding: 0;
  display: flex;
  justify-content: center;
  gap: 2.5em;
}

.IndexList li a {
  text-decoration: none;
  color: var(--text-color);
  padding: 0 0.5em;
}
</style>
