@extends('layouts.app')

@section('title', 'Unite - OnAPB')

@section('styles')
<link rel="stylesheet" href="{{ asset('static/asociate.css?v=5') }}">
@endsection

@section('content')
<div class="container-fluid py-5" style="background: var(--surface);">
    <div class="container py-4">
        <div class="mb-5 text-center">
            <span class="text-primary fw-bold tracking-widest text-uppercase d-block mb-2">Comunidad OnAPB</span>
            <h1 class="display-1 fw-bold mb-3" style="line-height: 0.9;">Unite al Juego<span class="text-primary">.</span></h1>
            <p class="fs-4 text-muted mx-auto" style="max-width: 700px;">Formá parte de la comunidad del básquet entrerriano y accedé a beneficios exclusivos.</p>
        </div>

        <div class="row justify-content-center">
            <div class="col-lg-10">
                <!-- Tab Navigation Editorial -->
                <div class="d-flex justify-content-center mb-5">
                    <div class="bg-white p-2 shadow-sm d-inline-flex" style="border: 1px solid var(--primary-container);">
                        <button class="nav-link px-5 py-3 fw-bold text-uppercase border-0 @if(!isset($tab) || $tab != 'jugador') active bg-primary text-white @else bg-white text-muted @endif" 
                                id="aficionado-tab" data-bs-toggle="pill" data-bs-target="#aficionado" type="button" style="transition: 0.3s; width: 250px;">
                            Aficionado
                        </button>
                        <button class="nav-link px-5 py-3 fw-bold text-uppercase border-0 @if(isset($tab) && $tab == 'jugador') active bg-primary text-white @else bg-white text-muted @endif" 
                                id="jugador-tab" data-bs-toggle="pill" data-bs-target="#jugador" type="button" style="transition: 0.3s; width: 250px;">
                            Jugador
                        </button>
                    </div>
                </div>

                <div class="tab-content" id="asociateTabContent">
                    <!-- Formulario Aficionado -->
                    <div class="tab-pane fade @if(!isset($tab) || $tab != 'jugador') show active @endif" id="aficionado" role="tabpanel">
                        <div class="bg-white p-5 shadow-lg" style="border-top: 10px solid var(--primary);">
                            <div class="row g-5">
                                <div class="col-md-4 border-end border-light">
                                    <h2 class="fw-bold mb-4">Registro de Aficionado</h2>
                                    <p class="text-muted">Como aficionado, podés seguir tus equipos favoritos y acceder a descuentos en clubes y comercios adheridos.</p>
                                    <div class="mt-5 p-4 bg-light">
                                        <h5 class="fw-bold text-primary mb-3">Beneficios</h5>
                                        <ul class="list-unstyled small fw-bold text-uppercase">
                                            <li class="mb-2"><i class="bi bi-check2 text-primary"></i> QRs de acceso</li>
                                            <li class="mb-2"><i class="bi bi-check2 text-primary"></i> Mapa de beneficios</li>
                                            <li class="mb-2"><i class="bi bi-check2 text-primary"></i> Noticias exclusivas</li>
                                        </ul>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    @if($errors->any())
                                        <div class="alert alert-danger mb-4">
                                            <ul class="mb-0 small">
                                                @foreach($errors->all() as $error)
                                                    <li>{{ $error }}</li>
                                                @endforeach
                                            </ul>
                                        </div>
                                    @endif

                                    <form method="POST" action="{{ route('registro.aficionado') }}">
                                        @csrf
                                        <input type="hidden" name="tipo" value="aficionado">
                                        <div class="row g-4">
                                            <div class="col-md-6">
                                                <label class="small fw-bold text-muted text-uppercase mb-2 d-block">Nombre *</label>
                                                <input type="text" name="nombre" class="form-control border-0 bg-light p-3" required style="border-radius: 0;">
                                            </div>
                                            <div class="col-md-6">
                                                <label class="small fw-bold text-muted text-uppercase mb-2 d-block">Apellido *</label>
                                                <input type="text" name="apellido" class="form-control border-0 bg-light p-3" required style="border-radius: 0;">
                                            </div>
                                            <div class="col-md-6">
                                                <label class="small fw-bold text-muted text-uppercase mb-2 d-block">DNI *</label>
                                                <input type="text" name="dni" class="form-control border-0 bg-light p-3" required style="border-radius: 0;">
                                            </div>
                                            <div class="col-md-6">
                                                <label class="small fw-bold text-muted text-uppercase mb-2 d-block">Fecha de Nacimiento</label>
                                                <input type="date" name="fecha_nacimiento" class="form-control border-0 bg-light p-3" style="border-radius: 0;">
                                            </div>
                                            <div class="col-md-6">
                                                <label class="small fw-bold text-muted text-uppercase mb-2 d-block">Email *</label>
                                                <input type="email" name="email" class="form-control border-0 bg-light p-3" required style="border-radius: 0;">
                                            </div>
                                            <div class="col-md-6">
                                                <label class="small fw-bold text-muted text-uppercase mb-2 d-block">Teléfono (Opcional)</label>
                                                <input type="text" name="telefono" class="form-control border-0 bg-light p-3" style="border-radius: 0;">
                                            </div>
                                            <div class="col-12">
                                                <label class="small fw-bold text-muted text-uppercase mb-2 d-block">Localidad</label>
                                                <input type="text" name="localidad" class="form-control border-0 bg-light p-3" style="border-radius: 0;">
                                            </div>
                                            
                                            <div class="col-12"><hr class="my-4"></div>
                                            
                                            <div class="col-md-6">
                                                <label class="small fw-bold text-muted text-uppercase mb-2 d-block">Contraseña *</label>
                                                <input type="password" name="password" class="form-control border-0 bg-light p-3" required style="border-radius: 0;">
                                            </div>
                                            <div class="col-md-6">
                                                <label class="small fw-bold text-muted text-uppercase mb-2 d-block">Confirmar Contraseña *</label>
                                                <input type="password" name="password_confirmation" class="form-control border-0 bg-light p-3" required style="border-radius: 0;">
                                            </div>
                                            <div class="col-12">
                                                <div class="cf-turnstile mt-2" data-sitekey="{{ config('services.turnstile.site_key') }}"></div>
                                            </div>
                                            <div class="col-12 mt-4">
                                                <button type="submit" class="btn-kinetic-primary w-100 py-3">CREAR MI CUENTA</button>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Formulario Jugador -->
                    <div class="tab-pane fade @if(isset($tab) && $tab == 'jugador') show active @endif" id="jugador" role="tabpanel">
                        <div class="bg-white p-5 shadow-lg" style="border-top: 10px solid var(--primary);">
                            <div class="row g-5">
                                <div class="col-md-4 border-end border-light">
                                    <h2 class="fw-bold mb-4">Portal de Jugador</h2>
                                    <p class="text-muted">Si estás fichado en un club de la APB, activá tu cuenta para gestionar tus datos y acceder a beneficios únicos para deportistas.</p>
                                    <div class="mt-5 p-4 bg-dark text-white">
                                        <h5 class="fw-bold text-primary mb-3">Verificación</h5>
                                        <p class="small mb-0">Usamos tu DNI para validar tu ficha técnica actual en el sistema de la asociación.</p>
                                    </div>
                                </div>
                                <div class="col-md-8">
                                    @if(isset($jugador_encontrado))
                                        <div class="p-4 bg-success text-white mb-4">
                                            <h4 class="fw-bold mb-1"><i class="bi bi-check-circle-fill"></i> ¡Jugador Encontrado!</h4>
                                            <p class="mb-0 small">Validamos tus datos en {{ $jugador_encontrado['club'] }}. Completá tu perfil abajo.</p>
                                        </div>
                                        
                                        <form method="POST" action="{{ route('registro.jugador.completar') }}">
                                            @csrf
                                            <input type="hidden" name="dni" value="{{ $jugador_encontrado['documento'] }}">
                                            <div class="row g-4">
                                                <div class="col-md-6">
                                                    <label class="small fw-bold text-muted text-uppercase mb-2 d-block">Nombre</label>
                                                    <div class="fs-5 fw-bold p-3 bg-light">{{ $jugador_encontrado['nombre'] }}</div>
                                                </div>
                                                <div class="col-md-6">
                                                    <label class="small fw-bold text-muted text-uppercase mb-2 d-block">Apellido</label>
                                                    <div class="fs-5 fw-bold p-3 bg-light">{{ $jugador_encontrado['apellido'] }}</div>
                                                </div>
                                                <div class="col-12">
                                                    <label class="small fw-bold text-muted text-uppercase mb-2 d-block">Email de Contacto *</label>
                                                    <input type="email" name="email" class="form-control border-0 bg-light p-3" required style="border-radius: 0;">
                                                </div>
                                                <div class="col-md-6">
                                                    <label class="small fw-bold text-muted text-uppercase mb-2 d-block">Contraseña *</label>
                                                    <input type="password" name="password" class="form-control border-0 bg-light p-3" required style="border-radius: 0;">
                                                </div>
                                                <div class="col-md-6">
                                                    <label class="small fw-bold text-muted text-uppercase mb-2 d-block">Confirmar Contraseña *</label>
                                                    <input type="password" name="password_confirmation" class="form-control border-0 bg-light p-3" required style="border-radius: 0;">
                                                </div>
                                                <div class="col-12">
                                                    <div class="form-check p-3 bg-light border">
                                                        <input type="checkbox" class="form-check-input ms-1" id="aceptoJug" name="acepto" required>
                                                        <label class="form-check-label ms-2 small fw-bold" for="aceptoJug">ACEPTO LOS TÉRMINOS Y CONDICIONES</label>
                                                    </div>
                                                </div>
                                                <div class="col-12">
                                                    <div class="cf-turnstile mt-2" data-sitekey="{{ config('services.turnstile.site_key') }}"></div>
                                                </div>
                                                <div class="col-12 mt-4">
                                                    <button type="submit" class="btn-kinetic-primary w-100 py-3">FINALIZAR ACTIVACIÓN</button>
                                                </div>
                                            </div>
                                        </form>
                                    @else
                                        <form method="POST" action="{{ route('registro.jugador.buscar') }}">
                                            @csrf
                                            <h3 class="fw-bold mb-4">Buscá tus datos</h3>
                                            <div class="row g-4">
                                                <div class="col-md-6">
                                                    <label class="small fw-bold text-muted text-uppercase mb-2 d-block">Nombre *</label>
                                                    <input type="text" name="nombre" class="form-control border-0 bg-light p-3" required style="border-radius: 0;">
                                                </div>
                                                <div class="col-md-6">
                                                    <label class="small fw-bold text-muted text-uppercase mb-2 d-block">Apellido *</label>
                                                    <input type="text" name="apellido" class="form-control border-0 bg-light p-3" required style="border-radius: 0;">
                                                </div>
                                                <div class="col-12">
                                                    <label class="small fw-bold text-muted text-uppercase mb-2 d-block">DNI *</label>
                                                    <input type="text" name="dni" class="form-control border-0 bg-light p-3" placeholder="Sin puntos" required style="border-radius: 0;">
                                                </div>
                                                <div class="col-12">
                                                    <div class="form-check p-3 bg-light border">
                                                        <input type="checkbox" class="form-check-input ms-1" id="aceptoBusq" name="acepto" required>
                                                        <label class="form-check-label ms-2 small fw-bold" for="aceptoBusq">ACEPTO LA VALIDACIÓN DE DATOS ASOCIATIVOS</label>
                                                    </div>
                                                </div>
                                                <div class="col-12 mt-4">
                                                    <button type="submit" class="btn-kinetic-primary w-100 py-3">BUSCAR MI FICHA <i class="bi bi-search ms-2"></i></button>
                                                </div>
                                            </div>
                                        </form>
                                    @endif
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@section('scripts')
<script>
document.addEventListener('DOMContentLoaded', function() {
    const tabs = document.querySelectorAll('[data-bs-toggle="pill"]');
    const panes = document.querySelectorAll('.tab-pane');

    tabs.forEach(tab => {
        tab.addEventListener('click', function(e) {
            e.preventDefault();
            const targetId = this.getAttribute('data-bs-target').replace('#', '');

            // Update Tabs
            tabs.forEach(t => {
                t.classList.remove('active', 'bg-primary', 'text-white');
                t.classList.add('bg-white', 'text-muted');
            });
            this.classList.add('active', 'bg-primary', 'text-white');
            this.classList.remove('bg-white', 'text-muted');

            // Update Panes
            panes.forEach(pane => {
                pane.classList.remove('show', 'active');
                if (pane.id === targetId) {
                    pane.classList.add('show', 'active');
                }
            });
        });
    });
});
</script>
@endsection
@endsection
