<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Inventory Report</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            font-size: 12px;
            margin: 0;
            padding: 20px;
        }
        .header {
            text-align: center;
            margin-bottom: 30px;
            border-bottom: 2px solid #333;
            padding-bottom: 20px;
        }
        .header h1 {
            margin: 0;
            font-size: 24px;
            color: #333;
        }
        .header p {
            margin: 5px 0;
            color: #666;
        }
        .stats {
            display: table;
            width: 100%;
            margin-bottom: 30px;
        }
        .stat-box {
            display: table-cell;
            padding: 15px;
            text-align: center;
            border: 1px solid #ddd;
            background-color: #f9f9f9;
        }
        .stat-box h3 {
            margin: 0 0 10px 0;
            font-size: 14px;
            color: #666;
        }
        .stat-box p {
            margin: 0;
            font-size: 20px;
            font-weight: bold;
            color: #333;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }
        th {
            background-color: #f3f4f6;
            padding: 10px;
            text-align: left;
            border: 1px solid #ddd;
            font-weight: bold;
            font-size: 11px;
            text-transform: uppercase;
        }
        td {
            padding: 8px 10px;
            border: 1px solid #ddd;
            font-size: 11px;
        }
        tr:nth-child(even) {
            background-color: #f9f9f9;
        }
        .text-right {
            text-align: right;
        }
        .text-center {
            text-align: center;
        }
        .status {
            padding: 4px 8px;
            border-radius: 4px;
            font-size: 10px;
            font-weight: bold;
        }
        .status-in_stock {
            background-color: #d1fae5;
            color: #065f46;
        }
        .status-low_stock {
            background-color: #fef3c7;
            color: #92400e;
        }
        .status-out_of_stock {
            background-color: #fee2e2;
            color: #991b1b;
        }
        .footer {
            margin-top: 30px;
            padding-top: 20px;
            border-top: 1px solid #ddd;
            text-align: center;
            font-size: 10px;
            color: #666;
        }
    </style>
</head>
<body>
    <div class="header">
        <h1>Inventory Report</h1>
        <p>Generated on: {{ now()->format('M d, Y h:i A') }}</p>
    </div>

    <div class="stats">
        <div class="stat-box">
            <h3>Total Value</h3>
            <p>{{ number_format($totalValue ?? 0, 2) }}</p>
        </div>
    </div>

    <table>
        <thead>
            <tr>
                <th>#</th>
                <th>Product</th>
                <th>Category</th>
                <th>Stock</th>
                <th class="text-right">Unit Price</th>
                <th class="text-right">Total Value</th>
                <th class="text-center">Status</th>
            </tr>
        </thead>
        <tbody>
            @forelse($products as $index => $product)
                @php
                    $totalValue = $product->stock * $product->purchase_price;
                    $status = 'in_stock';
                    $statusLabel = 'In Stock';
                    if ($product->stock == 0) {
                        $status = 'out_of_stock';
                        $statusLabel = 'Out of Stock';
                    } elseif ($product->stock <= ($product->alert_quantity ?? 0)) {
                        $status = 'low_stock';
                        $statusLabel = 'Low Stock';
                    }
                @endphp
                <tr>
                    <td>{{ $index + 1 }}</td>
                    <td>{{ $product->name }}</td>
                    <td>{{ $product->category->name ?? 'N/A' }}</td>
                    <td>{{ $product->stock }}</td>
                    <td class="text-right">{{ number_format($product->purchase_price, 2) }}</td>
                    <td class="text-right">{{ number_format($totalValue, 2) }}</td>
                    <td class="text-center">
                        <span class="status status-{{ $status }}">
                            {{ $statusLabel }}
                        </span>
                    </td>
                </tr>
            @empty
                <tr>
                    <td colspan="7" class="text-center">No inventory data available</td>
                </tr>
            @endforelse
        </tbody>
        @if($products->count() > 0)
        <tfoot>
            <tr>
                <td colspan="5" class="text-right" style="font-weight: bold;">Total Value:</td>
                <td class="text-right" style="font-weight: bold;">{{ number_format($totalValue ?? 0, 2) }}</td>
                <td></td>
            </tr>
        </tfoot>
        @endif
    </table>

    <div class="footer">
        <p>This is a computer-generated report. No signature required.</p>
    </div>
</body>
</html>
