<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Ruta Ticket</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            font-size: 12px;
            line-height: 1.2;
            margin: 0;
            padding: 0;
        }
        .ticket {
            width: 100%;
            text-align: left;
            padding: 10px;
            box-sizing: border-box;
        }
        .title {
            font-weight: bold;
            font-size: 16px;
            text-align: center;
            margin-bottom: 10px;
        }
        .section {
            margin-bottom: 10px;
        }
        .section-header {
            font-weight: bold;
            margin-bottom: 5px;
        }
        .product-table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 10px;
        }
        .product-table th,
        .product-table td {
            border-bottom: 1px solid #ccc;
            text-align: left;
            padding: 5px;
        }
        .details-list {
            margin: 5px 0 10px 15px;
            padding: 0;
        }
        .details-list li {
            list-style: none;
            font-size: 11px;
        }
        .total {
            font-weight: bold;
            text-align: right;
            margin-top: 10px;
        }
    </style>
</head>
<body>
    <div class="ticket">
        <div class="title">TICKET DE RUTA</div>
        
        <!-- Información general -->
        <div class="section">
            <p><strong>Número de Ruta:</strong> {{ $route->n_route }}</p>
            <p><strong>Fecha:</strong> {{ $route->date }}</p>
            <p><strong>Conductor:</strong> {{ $route->driver }}</p>
            <p><strong>Patente:</strong> {{ $route->patente }}</p>
            <p><strong>Observaciones:</strong> {{ $route->observations }}</p>
        </div>

        <!-- Productos -->
        <div class="section">
            <table class="product-table">
                <thead>
                    <tr>
                        <th>Producto</th>
                        <th>Cantidad</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach ($route->dispatchGuides as $guide)
                        <tr>
                            <td>{{ $guide->product->name ?? 'Producto desconocido' }}</td>
                            <td>{{ $guide->quantity }}</td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <ul class="details-list">
                                    @foreach ($guide->details as $detail)
                                        <li>
                                            <strong>Pedido:</strong> {{ $detail->ticket->nro_ticket ?? 'N/A' }} - 
                                            <strong>Cantidad:</strong> {{ $detail->quantity }}
                                        </li>
                                    @endforeach
                                </ul>
                            </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>

        <!-- Total -->
        <div class="total">
            Total de Productos: {{ $route->dispatchGuides->sum('quantity') }}
        </div>
    </div>
</body>
</html>
