@extends('layouts.app')

@section('content')
<section class="content pt-3">

{{-- ================== HEADER ================== --}}
<div class="row mb-3">
    <div class="col-sm-6">
        <h1 class="m-0">Tablero</h1>
    </div>
</div>

{{-- ================== INFO BOXES ================== --}}
<div class="row">

    <div class="col-lg-3 col-6">
        <div class="small-box bg-info">
            <div class="inner">
                <h3>{{ $totalCotizaciones }}</h3>
                <p>Cotizaciones Totales</p>
            </div>
            <div class="icon"><i class="fas fa-file-invoice-dollar"></i></div>
            <a href="{{ route('cotizaciones.index') }}" class="small-box-footer">
                Más info <i class="fas fa-arrow-circle-right"></i>
            </a>
        </div>
    </div>

    <div class="col-lg-3 col-6">
        <div class="small-box bg-success">
            <div class="inner">
                <h3>{{ $totalClientes }}</h3>
                <p>Clientes Registrados</p>
            </div>
            <div class="icon"><i class="fas fa-users"></i></div>
            <a href="{{ route('clientes.index') }}" class="small-box-footer">
                Más info <i class="fas fa-arrow-circle-right"></i>
            </a>
        </div>
    </div>

    <div class="col-lg-3 col-6">
        <div class="small-box bg-warning">
            <div class="inner">
                <h3>{{ $totalProductos }}</h3>
                <p>Productos / Servicios</p>
            </div>
            <div class="icon"><i class="fas fa-box"></i></div>
            <a href="{{ route('productos.index') }}" class="small-box-footer">
                Más info <i class="fas fa-arrow-circle-right"></i>
            </a>
        </div>
    </div>

    <div class="col-lg-3 col-6">
        <div class="small-box bg-danger">
            <div class="inner">
                <h3>${{ number_format($ingresosTotales,2) }}</h3>
                <p>Ingresos Totales</p>
            </div>
            <div class="icon"><i class="fas fa-dollar-sign"></i></div>
            <a href="#" class="small-box-footer">
                Más info <i class="fas fa-arrow-circle-right"></i>
            </a>
        </div>
    </div>

</div>

{{-- ================== CONTENIDO ================== --}}
<div class="row">

{{-- ========== COTIZACIONES RECIENTES ========== --}}
<div class="col-md-12">
    <div class="card">
        <div class="card-header">
           
            <div class="card-tools">
                <a href="{{ route('cotizaciones.create') }}" class="btn btn-primary btn-sm">
                    <i class="fa fa-plus"></i> Nueva Cotización
                </a>
            </div>
             <h3 class="card-title">Cotizaciones Recientes</h3>
        </div>

        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover mb-0">
                    <thead>
                        <tr>
                            <th>Número</th>
                            <th>Cliente</th>
                            <th>Total</th>
                            <th>Estado</th>
                            <th class="d-none d-md-table-cell">Fecha</th>
                            <th class="d-none d-md-table-cell" width="80">Acciones</th>
                        </tr>
                    </thead>
                    <tbody>
                    @forelse($cotizaciones as $cot)
                        <tr>
                            <td>
                                <a href="{{ route('cotizaciones.show', $cot->id) }}">
                                    {{ $cot->folio ?? 'COT-'.$cot->id }}
                                </a>
                            </td>
                            <td>{{ $cot->cliente->nombre ?? '-' }}</td>
                            <td>${{ number_format($cot->total,2) }}</td>
                            <td>
                                <span class="badge
                                    @if($cot->estado=='pendiente') badge-secondary
                                    @elseif($cot->estado=='vista') badge-info
                                    @elseif($cot->estado=='aprobada') badge-success
                                    @else badge-danger @endif">
                                    {{ ucfirst($cot->estado) }}
                                </span>
                            </td>
                            <td class="d-none d-md-table-cell">
                                {{ $cot->created_at->format('d/m/Y') }}
                            </td>
                            <td class="d-none d-md-table-cell">
                                <a href="{{ route('cotizaciones.show', $cot->id) }}"
                                   class="btn btn-info btn-sm">
                                    <i class="fa fa-eye"></i>
                                </a>
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="6" class="text-center text-muted p-3">
                                No hay cotizaciones registradas
                            </td>
                        </tr>
                    @endforelse
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>


</div>
</section>
@endsection
