@extends('layouts.app')
@section('title', 'Registro Exitoso — Set ' . $set->codigo_set)

@section('content')
<div class="min-h-screen bg-gray-50 p-4 md:p-8">
    <div class="max-w-2xl mx-auto space-y-6">

        {{-- ── Tarjeta de éxito ─────────────────────────────────── --}}
        <div class="bg-white rounded-2xl shadow-lg p-8 text-center border-t-8 border-green-500">

            <div class="mx-auto flex items-center justify-center h-20 w-20 rounded-full bg-green-100 mb-5">
                <svg class="h-12 w-12 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                          d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
                </svg>
            </div>

            <h2 class="text-2xl font-bold text-gray-900 mb-1">¡Registro Guardado!</h2>
            <p class="text-gray-500 text-sm mb-1">
                Set <strong class="text-gray-700">{{ $set->codigo_set }}</strong>
            </p>
            <p class="text-gray-400 text-xs mb-6">
                {{ $set->created_at->setTimezone('America/Bogota')->format('d/m/Y — H:i') }} hrs
            </p>

            {{-- Resumen del registro --}}
            <div class="bg-gray-50 rounded-xl p-4 text-left text-sm text-gray-700 space-y-2 mb-6">
                <div class="flex justify-between">
                    <span class="text-gray-500">Código Set</span>
                    <span class="font-medium">{{ $set->codigo_set }}</span>
                </div>
                <div class="flex justify-between">
                    <span class="text-gray-500">Referencia</span>
                    <span class="font-medium">{{ $set->referencia }}</span>
                </div>
                <div class="flex justify-between gap-4">
                    <span class="text-gray-500 shrink-0">Descripción</span>
                    <span class="font-medium text-right">{{ $set->descripcion_referencia ?? '—' }}</span>
                </div>
                <div class="flex justify-between">
                    <span class="text-gray-500">Sucursal</span>
                    <span class="font-medium">{{ $set->sucursal }}</span>
                </div>
                <div class="flex justify-between">
                    <span class="text-gray-500">Operador</span>
                    <span class="font-medium">{{ $set->user->name }}</span>
                </div>
            </div>

            {{-- Notificación correo enviado --}}
            <div class="bg-blue-50 border border-blue-200 rounded-xl px-4 py-3 text-sm text-blue-700
                        flex items-center gap-2 mb-6">
                <svg class="h-5 w-5 shrink-0 text-blue-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                          d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7
                             a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/>
                </svg>
                Reporte enviado automáticamente al equipo de logística.
            </div>

            <a href="{{ route('sets.create') }}"
               class="block w-full bg-blue-600 hover:bg-blue-700 text-white font-bold py-3 px-4
                      rounded-xl transition shadow text-center">
                + Registrar otro set
            </a>
        </div>

        {{-- ── Mis últimos registros ────────────────────────────── --}}
        <div class="bg-white rounded-2xl shadow-lg overflow-hidden">
            <div class="px-6 py-4 border-b border-gray-100 flex items-center justify-between">
                <h3 class="font-bold text-gray-800">Mis últimos registros</h3>
                <a href="{{ route('sets.index') }}"
                   class="text-blue-600 hover:underline text-xs font-medium">
                    Ver todos →
                </a>
            </div>

            @php
                $ultimos = Auth::user()->sets()->latest()->take(5)->get();
            @endphp

            @if ($ultimos->isEmpty())
                <p class="px-6 py-4 text-gray-400 text-sm">Sin registros anteriores.</p>
            @else
                <div class="divide-y divide-gray-100">
                    @foreach ($ultimos as $item)
                    <div class="px-6 py-3 flex items-center justify-between hover:bg-gray-50 transition">
                        <div>
                            <p class="text-sm font-semibold text-blue-700">{{ $item->codigo_set }}</p>
                            <p class="text-xs text-gray-500">
                                {{ $item->referencia }} —
                                {{ $item->created_at->setTimezone('America/Bogota')->format('d/m/Y H:i') }}
                            </p>
                        </div>
                        <span class="text-xs text-gray-400 bg-gray-100 px-2 py-1 rounded-lg">
                            {{ $item->sucursal }}
                        </span>
                    </div>
                    @endforeach
                </div>
            @endif
        </div>

    </div>
</div>
@endsection