<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { useI18n } from 'vue-i18n'
import LoginForm from '../components/auth/LoginForm.vue'
import RegisterForm from '../components/auth/RegisterForm.vue'

const { t } = useI18n()
const router = useRouter()
const isLogin = ref(true)

const toggleAuth = () => {
  isLogin.value = !isLogin.value
}
</script>

<template>
  <div class="auth-page">
    <!-- Fondo Decorativo -->
    <div class="bg-decoration">
      <div class="circle circle-1"></div>
      <div class="circle circle-2"></div>
    </div>

    <!-- Contenido Principal -->
    <div class="auth-container">
      <!-- Botón Volver -->
      <button @click="router.push('/')" class="back-btn">
        <span class="material-icons">arrow_back</span>
        <span>{{ t('auth.back') }}</span>
      </button>

      <div class="auth-card">
        <!-- Header con Logo -->
        <header class="auth-header">
          <img src="@/assets/logo.png" alt="SIBU Logo" class="auth-logo" />
          <p class="auth-subtitle">{{ t('auth.brandingSubtitle') }}</p>
        </header>

        <!-- Selector de Pestañas -->
        <nav class="auth-tabs">
          <button 
            class="tab-btn" 
            :class="{ active: isLogin }" 
            @click="isLogin = true"
          >
            {{ t('auth.loginTab') }}
          </button>
          <button 
            class="tab-btn" 
            :class="{ active: !isLogin }" 
            @click="isLogin = false"
          >
            {{ t('auth.registerTab') }}
          </button>
          <div class="tab-indicator" :class="{ 'on-right': !isLogin }"></div>
        </nav>

        <!-- Contenido de Formularios -->
        <div class="auth-body">
          <div v-if="isLogin" class="form-wrapper">
            <LoginForm @toggle="toggleAuth" />
          </div>
          <div v-else class="form-wrapper">
            <RegisterForm @toggle="toggleAuth" @success="isLogin = true" />
          </div>
        </div>

        <!-- Footer -->
        <footer class="auth-footer">
          <p>{{ t('auth.footer') }}</p>
        </footer>
      </div>
    </div>
  </div>
</template>

<style scoped>
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  padding: 1rem;
  position: relative;
  overflow: hidden;
}

.bg-decoration {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 0;
  pointer-events: none;
}

.circle {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.15;
}

.circle-1 {
  width: 400px;
  height: 400px;
  background: var(--active-color);
  top: -100px;
  right: -100px;
}

.circle-2 {
  width: 300px;
  height: 300px;
  background: #3b82f6;
  bottom: -50px;
  left: -50px;
}

.auth-container {
  width: 100%;
  max-width: 420px;
  position: relative;
  z-index: 1;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 1.5rem;
  padding: 0.5rem;
  border-radius: 8px;
  transition: all 0.2s;
}

.back-btn:hover {
  color: var(--text-primary);
  background: rgba(255,255,255,0.05);
}

.auth-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 2rem;
  box-shadow: 0 20px 50px rgba(0,0,0,0.2);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.auth-header {
  padding: 2rem 2rem 1rem;
  text-align: center;
}

.auth-logo {
  height: 60px;
  margin-bottom: 0.5rem;
}

.auth-subtitle {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 0;
}

.auth-tabs {
  position: relative;
  display: flex;
  margin: 0 1.5rem;
  background: var(--bg-primary);
  padding: 0.35rem;
  border-radius: 1rem;
  border: 1px solid var(--border-color);
}

.tab-btn {
  flex: 1;
  padding: 0.75rem;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 800;
  cursor: pointer;
  z-index: 1;
  transition: color 0.3s;
}

.tab-btn.active {
  color: #101820;
}

.tab-indicator {
  position: absolute;
  top: 0.35rem;
  bottom: 0.35rem;
  left: 0.35rem;
  width: calc(50% - 0.35rem);
  background: var(--active-color);
  border-radius: 0.75rem;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.tab-indicator.on-right {
  transform: translateX(100%);
}

.auth-body {
  min-height: 200px;
}

.form-wrapper {
  animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.auth-footer {
  padding: 1.5rem;
  text-align: center;
  border-top: 1px solid var(--border-color);
}

.auth-footer p {
  font-size: 0.75rem;
  color: var(--text-secondary);
  opacity: 0.6;
  margin: 0;
}
</style>
