<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Damage Stock Report</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            font-size: 10px;
            line-height: 1.4;
            margin: 20px;
        }
        h1 {
            text-align: center;
            margin-bottom: 20px;
            font-size: 12px;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 10px;
            font-size: 10px;
        }
        th, td {
            padding: 6px 8px;
            border: 1px solid #ddd;
            text-align: left;
        }
        th {
            background-color: #f0f0f0;
            font-weight: bold;
        }
        .text-right {
            text-align: right;
        }
        .total-row {
            font-weight: bold;
            background-color: #fff3cd;
        }
    </style>
</head>
<body>
    <h1>Damage Stock Report</h1>

    <table>
        <thead>
            <tr>
                <th style="width:6%;">#</th>
                <th style="width:16%;">Date</th>
                <th style="width:30%;">Product Name</th>
                <th style="width:13%;" class="text-right">Qty</th>
                <th style="width:13%;" class="text-right">Total Cost</th>
                <th style="width:22%;">Remark</th>
            </tr>
        </thead>
        <tbody>
            @php
                $totalQty = 0;
                $totalCost = 0;
            @endphp

            @foreach($damageStocks as $index => $damage)
                <tr>
                    <td>{{ $index + 1 }}</td>
                    <td>{{ $damage->date_time ? \Carbon\Carbon::parse($damage->date_time)->format('Y-m-d') : '-' }}</td>
                    <td>{{ $damage->product->product_name ?? '-' }}</td>
                    <td class="text-right">{{ number_format($damage->qty, 2) }}</td>
                    <td class="text-right">{{ number_format($damage->total_cost, 2) }}</td>
                    <td>{{ $damage->remark ?? '-' }}</td>
                </tr>
                @php
                    $totalQty += $damage->qty;
                    $totalCost += $damage->total_cost;
                @endphp
            @endforeach

            <tr class="total-row">
                <td colspan="3"><strong>Total</strong></td>
                <td class="text-right"><strong>{{ number_format($totalQty, 2) }}</strong></td>
                <td class="text-right"><strong>{{ number_format($totalCost, 2) }}</strong></td>
                <td></td>
            </tr>
        </tbody>
    </table>

</body>
</html>