@extends('layouts.app')

@section('content')
<div class="max-w-6xl mx-auto py-10 sm:px-6 lg:px-8">
    <h2 class="text-2xl font-semibold mb-6">Cotizaciones</h2>

    <div class="bg-white shadow rounded overflow-x-auto">
        <table class="min-w-full divide-y divide-gray-200 text-sm">
            <thead class="bg-gray-50">
                <tr>
                    <th class="px-4 py-2 text-left">Creado</th>
                    <th class="px-4 py-2 text-left">Cotización</th>
                    <th class="px-4 py-2 text-left">Lead</th>
                    <th class="px-4 py-2 text-left">Propiedad</th>
                    <th class="px-4 py-2 text-left">Mes</th>
                    <th class="px-4 py-2 text-left">Enganche</th>
                    <th class="px-4 py-2 text-left">Mensualidad</th>
                    <th class="px-4 py-2 text-left">Acciones</th>
                </tr>
            </thead>
            <tbody>
                @foreach ($quotes as $quote)
                    <tr class="border-b">
                        <td class="px-4 py-2 text-sm text-gray-700">
                            {{ $quote->created_at->timezone('America/Mexico_City')->format('d/m/Y H:i') }}
                        </td>
                        <td class="px-4 py-2 font-semibold text-indigo-700"><a href="{{ route('quotes.show', $quote) }}">{{ $quote->slug }}</a></td>
                        <td class="px-4 py-2">{{ $quote->lead->form_data['name'] ?? '-' }} {{ $quote->lead->form_data['last_name'] ?? '' }}</td>
                        <td class="px-4 py-2">{{ $quote->property->name ?? 'N/A' }}</td>
                        <td class="px-4 py-2 capitalize">{{ $meses[$quote->month] ?? ucfirst($quote->month) }}</td>
                        <td class="px-4 py-2">${{ number_format($quote->price * ($quote->advance_percentage / 100) + 30000, 2) }}</td>
                        <td class="px-4 py-2">${{ number_format($quote->monthly_payment, 2) }}</td>
                        <td class="px-4 py-2">
                            <a href="{{ route('quotes.show', $quote) }}"
                            class="inline-flex items-center px-3 py-1.5 bg-indigo-600 text-white text-sm rounded hover:bg-indigo-700 transition"
                            title="Ver cotización">
                                <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12H9m12 0a9 9 0 11-18 0 9 9 0 0118 0z" />
                                </svg>
                                Ver
                            </a>

                        </td>
                    </tr>
                @endforeach
            </tbody>
        </table>

        <div class="p-4">
            {{ $quotes->links() }}
        </div>
    </div>
</div>
@endsection
