<template>
  <div class="container">
    <div class="branding">
      <img src="/assets/logo.svg" alt="Snatch Game Logo" class="logo" />
      <h1>Snatch Game</h1>
    </div>

    <div class="buttons">
      <button @click="onJoin" :disabled="isConnecting">
        {{ isConnecting ? 'Conectando...' : 'Unirse a partida' }}
      </button>
      <button @click="onSettings">Configuración</button>
      <button @click="onLogin">Iniciar sesión</button>
    </div>

    <div v-if="connectionStatus" class="connection-status">
      {{ connectionStatus }}
    </div>

    <div class="footer">NucleoServices</div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useGameClient } from '~/composables/useGameClient'

const emit = defineEmits<{
  'join-game': [client: any]
  'show-settings': []
}>()

const gameClient = useGameClient()
const isConnecting = ref(false)
const connectionStatus = computed(() => gameClient.connectionStatus.value)

const onJoin = async () => {
  if (isConnecting.value) return
  
  isConnecting.value = true
  
  try {
    await gameClient.connect('Jugador Test', 'classic')
    console.log('Connected successfully')
    
    // Emit the join-game event with the game client
    emit('join-game', gameClient)
  } catch (error) {
    console.error('Error connecting:', error)
  } finally {
    isConnecting.value = false
  }
}

const onSettings = () => {
  emit('show-settings')
}

const onLogin = () => {
  console.log('Login clicked')
  // TODO: implement login logic
}
</script>

<style scoped>
.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 2rem;
}

.branding {
  text-align: center;
  margin-bottom: 3rem;
}

.logo {
  width: 120px;
  height: 120px;
  margin-bottom: 1rem;
}

h1 {
  font-size: 3rem;
  font-weight: 700;
  margin: 0;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.buttons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 300px;
}

button {
  padding: 1rem 2rem;
  font-size: 1.1rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
}

button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.5);
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.connection-status {
  margin-top: 2rem;
  padding: 0.75rem 1.5rem;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  backdrop-filter: blur(10px);
  font-size: 0.9rem;
  text-align: center;
}

.footer {
  position: absolute;
  bottom: 2rem;
  font-size: 0.9rem;
  opacity: 0.7;
}

@media (max-width: 768px) {
  h1 {
    font-size: 2rem;
  }
  
  .logo {
    width: 80px;
    height: 80px;
  }
  
  button {
    font-size: 1rem;
    padding: 0.75rem 1.5rem;
  }
}
</style>