<script setup lang="ts">
import { ref } from 'vue'
import { RouterView, useRouter, useRoute } from 'vue-router'
import { Anchor, ShieldAlert, HeartHandshake, Menu, X } from 'lucide-vue-next'

const router = useRouter()
const route = useRoute()
const mobileMenuOpen = ref(false)

const navItems = [
  { name: '메인 홈', path: '/', icon: Anchor },
  { name: '캠페인 소개', path: '/about', icon: ShieldAlert },
  { name: '희망 기부', path: '/donation', icon: HeartHandshake }
]

const navigateTo = (path: string) => {
  router.push(path)
  mobileMenuOpen.value = false
}
</script>

<template>
  <div class="app-layout">
    <!-- Header -->
    <header class="app-header">
      <div class="header-logo" @click="navigateTo('/')">
        <div class="logo-icon-wrapper">
          <Anchor class="logo-icon" />
        </div>
        <div class="logo-text">
          <span class="logo-title">희망의 바다</span>
          <span class="logo-subtitle">수협중앙회</span>
        </div>
      </div>

      <!-- Desktop Nav -->
      <nav class="desktop-nav">
        <button
          v-for="item in navItems"
          :key="item.path"
          :class="['nav-link', { active: route.path === item.path }]"
          @click="navigateTo(item.path)"
        >
          <component :is="item.icon" class="nav-icon" />
          <span>{{ item.name }}</span>
        </button>
      </nav>

      <!-- Mobile Nav Toggle -->
      <button class="mobile-nav-toggle" @click="mobileMenuOpen = !mobileMenuOpen">
        <Menu v-if="!mobileMenuOpen" />
        <X v-else />
      </button>
    </header>

    <!-- Mobile Nav Menu -->
    <transition name="slide-fade">
      <nav v-if="mobileMenuOpen" class="mobile-nav">
        <button
          v-for="item in navItems"
          :key="item.path"
          :class="['mobile-nav-link', { active: route.path === item.path }]"
          @click="navigateTo(item.path)"
        >
          <component :is="item.icon" class="nav-icon" />
          <span>{{ item.name }}</span>
        </button>
      </nav>
    </transition>

    <!-- Main Content Area -->
    <main class="main-content">
      <RouterView v-slot="{ Component }">
        <transition name="fade" mode="out-in">
          <component :is="Component" />
        </transition>
      </RouterView>
    </main>

    <!-- Footer -->
    <footer class="app-footer">
      <div class="footer-content">
        <p class="footer-title">수협중앙회 희망의 바다 만들기 운동본부</p>
        <p class="footer-text">© 2026 수협중앙회. All rights reserved. 깨끗하고 풍요로운 바다, 함께 만들어갑니다.</p>
      </div>
    </footer>
  </div>
</template>

<style>
/* 전역 스코프 및 공통 레이아웃 스타일 정의 */
:root {
  --primary-color: #00d2ff;
  --primary-rgb: 0, 210, 255;
  --secondary-color: #0066ff;
  --accent-color: #ff6b6b;
  --dark-bg: #030814;
  --glass-bg: rgba(6, 17, 38, 0.65);
  --glass-border: rgba(0, 210, 255, 0.15);
  --text-color: #e0f2fe;
}

body {
  background: radial-gradient(circle at center, #061530 0%, #030814 100%) !important;
  color: var(--text-color);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  margin: 0;
  padding: 0 !important; /* Wails 기본 padding 덮어쓰기 */
}

/* Wails default background override */
.bg {
  display: none !important;
}

.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 70px;
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 40px;
  z-index: 100;
  --wails-draggable: drag;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  --wails-draggable: no-drag;
}

.logo-icon-wrapper {
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  padding: 8px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 15px rgba(0, 210, 255, 0.4);
}

.logo-icon {
  color: white;
  width: 20px;
  height: 20px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.logo-text {
  display: flex;
  flex-direction: column;
}

.logo-title {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(to right, #ffffff, var(--primary-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-subtitle {
  font-size: 0.75rem;
  color: #94a3b8;
}

.desktop-nav {
  display: flex;
  gap: 8px;
  --wails-draggable: no-drag;
}

.nav-link {
  background: transparent;
  border: none;
  color: #94a3b8;
  padding: 8px 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.3s ease;
}

.nav-link:hover {
  color: var(--primary-color);
  background: rgba(0, 210, 255, 0.08);
}

.nav-link.active {
  color: white;
  background: linear-gradient(135deg, rgba(0, 210, 255, 0.2), rgba(0, 102, 255, 0.2));
  border: 1px solid var(--primary-color);
  box-shadow: 0 0 15px rgba(0, 210, 255, 0.25);
}

.nav-icon {
  width: 16px;
  height: 16px;
}

.mobile-nav-toggle {
  display: none;
  background: transparent;
  border: none;
  color: white;
  cursor: pointer;
  --wails-draggable: no-drag;
}

.main-content {
  flex: 1;
  margin-top: 70px;
  padding: 40px;
  display: flex;
  flex-direction: column;
}

.app-footer {
  background: #020611;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  padding: 30px 40px;
  text-align: center;
  font-size: 0.85rem;
  color: #64748b;
}

.footer-title {
  font-weight: 700;
  color: #94a3b8;
  margin-bottom: 8px;
}

.footer-text {
  margin: 0;
}

/* Transitions */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

.slide-fade-enter-active,
.slide-fade-leave-active {
  transition: all 0.3s ease;
}

.slide-fade-enter-from,
.slide-fade-leave-to {
  transform: translateY(-20px);
  opacity: 0;
}

/* Responsiveness */
@media (max-width: 768px) {
  .desktop-nav {
    display: none;
  }
  .mobile-nav-toggle {
    display: block;
  }
  .main-content {
    padding: 20px;
  }
  .mobile-nav {
    position: fixed;
    top: 70px;
    left: 0;
    right: 0;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    padding: 15px;
    gap: 8px;
    z-index: 99;
  }
  .mobile-nav-link {
    background: transparent;
    border: none;
    color: #94a3b8;
    padding: 12px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
  }
  .mobile-nav-link.active {
    color: white;
    background: rgba(0, 210, 255, 0.15);
  }
}
</style>
