<script setup lang="ts">
import { ref, onMounted } from "vue";
import GameHistory from "./components/GameHistory.vue";
import GameReview from "./components/GameReview.vue";
import Settings from "./components/Settings.vue";
import type { GameHistoryItem } from "./types/timeline";
import { fetchLatestDdragonVersion } from "./types/ddragon";

// Current view state
const currentView = ref<"history" | "review" | "settings">("history");
const selectedGame = ref<GameHistoryItem | null>(null);

// Navigate to review view
function openReview(game: GameHistoryItem) {
  selectedGame.value = game;
  currentView.value = "review";
}

// Navigate back to history
function closeReview() {
  currentView.value = "history";
  selectedGame.value = null;
}

// Navigate to settings
function openSettings() {
  currentView.value = "settings";
}

// Navigate back from settings
function closeSettings() {
  currentView.value = "history";
}

// Initialize DDragon version on app mount
onMounted(() => {
  fetchLatestDdragonVersion();
});
</script>

<template>
  <div class="app">
    <!-- Navigation bar -->
    <nav v-if="currentView !== 'review'" class="app-nav">
      <div class="nav-left">
        <button
          :class="['nav-tab', { active: currentView === 'history' }]"
          @click="currentView = 'history'"
        >
          <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
            <rect x="3" y="3" width="7" height="7" rx="1" />
            <rect x="14" y="3" width="7" height="7" rx="1" />
            <rect x="3" y="14" width="7" height="7" rx="1" />
            <rect x="14" y="14" width="7" height="7" rx="1" />
          </svg>
          Game History
        </button>
        <button
          :class="['nav-tab', { active: currentView === 'settings' }]"
          @click="openSettings"
        >
          <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
            <circle cx="12" cy="12" r="3" />
            <path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z" />
          </svg>
          Settings
        </button>
      </div>
    </nav>

    <GameHistory
      v-if="currentView === 'history'"
      @open-review="openReview"
    />
    <GameReview
      v-else-if="currentView === 'review' && selectedGame"
      :game="selectedGame"
      @back="closeReview"
    />
    <Settings
      v-else-if="currentView === 'settings'"
      @back="closeSettings"
    />
  </div>
</template>

<style>
/* Global styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

.app {
  min-height: 100vh;
  background: #0a0a13;
}

/* Navigation bar */
.app-nav {
  display: flex;
  align-items: center;
  padding: 0 24px;
  height: 48px;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.nav-left {
  display: flex;
  gap: 4px;
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: none;
  border: none;
  border-radius: 6px;
  color: #94a3b8;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.nav-tab:hover {
  color: #e2e8f0;
  background: rgba(255, 255, 255, 0.06);
}

.nav-tab.active {
  color: #f1f5f9;
  background: rgba(255, 255, 255, 0.08);
}
</style>
