<template>
  <header class="topbar">
    <div class="profile" @click="goAbout">
      <div class="avatar">
        <img src="@/assets/profile-avatar.jpg" alt="Brad Stein" />
      </div>
      <div>
        <div class="name">Brad Stein</div>
        <div class="role">Software Development Engineer</div>
      </div>
    </div>
    <nav class="links">
      <RouterLink to="/" class="nav-link">Home</RouterLink>
      <RouterLink to="/about" class="nav-link">About</RouterLink>

      <template v-if="auth.enabled">
        <template v-if="auth.authenticated">
          <RouterLink to="/apps" class="nav-link">Apps</RouterLink>
          <RouterLink to="/account" class="nav-link">Account</RouterLink>
          <button class="nav-link button" type="button" @click="doLogout">Logout</button>
        </template>
        <template v-else>
          <button class="nav-link button" type="button" @click="doLogin">Login</button>
          <RouterLink to="/request-access" class="nav-link">Request Access</RouterLink>
          <a v-if="auth.resetUrl" :href="auth.resetUrl" class="nav-link" target="_blank" rel="noreferrer">Reset Password</a>
        </template>
      </template>
    </nav>
  </header>
</template>

<script setup>
import { useRouter, RouterLink } from "vue-router";
import { auth, login, logout } from "@/auth";

const router = useRouter();
const goAbout = () => router.push("/about");

const doLogin = () => login();
const doLogout = () => logout();
</script>

<style scoped>
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: rgba(5, 9, 20, 0.92);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px);
}

.profile {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.avatar {
  width: 44px;
  height: 44px;
  aspect-ratio: 1 / 1;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.14);
  overflow: hidden;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, rgba(0, 229, 197, 0.5), rgba(127, 124, 255, 0.45));
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 50%;
}

.name {
  color: var(--text-strong);
  font-weight: 700;
}

.role {
  color: var(--text-muted);
  font-size: 13px;
}

.links {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.nav-link {
  color: var(--text-primary);
  font-weight: 600;
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
}

.button {
  background: transparent;
  cursor: pointer;
}

.nav-link.strong {
  border-color: rgba(255, 255, 255, 0.14);
  color: var(--accent-cyan);
}

.nav-link:hover {
  border-color: rgba(255, 255, 255, 0.14);
  color: var(--accent-cyan);
}
</style>
