<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Invoice #MSN-{{ str_pad($order->id, 5, '0', STR_PAD_LEFT) }}</title>
    <style>
        body { font-family: 'Helvetica', sans-serif; color: #333; line-height: 1.6; }
        .invoice-box { max-width: 800px; margin: auto; padding: 30px; border: 1px solid #eee; }
        .header { display: flex; justify-content: space-between; border-bottom: 2px solid #eee; padding-bottom: 20px; margin-bottom: 20px; }
        .title { font-size: 24px; font-weight: bold; color: #555; }
        table { width: 100%; border-collapse: collapse; }
        th { background: #f8f8f8; padding: 10px; text-align: left; }
        td { padding: 10px; border-bottom: 1px solid #eee; }
        .total { font-weight: bold; font-size: 18px; }
    </style>
</head>
<body>
    <div class="invoice-box">
        <div class="header">
            <div class="title">
                @if(!empty($siteSettings['company_logo']))
                    <!-- Using public_path to ensure the file is accessible to dompdf -->
                    <img src="{{ public_path('storage/' . $siteSettings['company_logo']) }}" alt="{{ $siteSettings['company_name'] ?? 'Company Logo' }}" style="height: 50px; width: auto;">
                @else
                    {{ $siteSettings['company_name'] ?? 'MAISON' }}
                @endif
            </div>
            <div style="text-align: right;">
                <strong>{{ $siteSettings['company_name'] ?? 'MAISON' }}</strong><br>
                {{ $siteSettings['shop_address'] ?? 'Address not set' }}<br>
                Invoice #MSN-{{ str_pad($order->id, 5, '0', STR_PAD_LEFT) }}<br>
                Date: {{ $order->created_at->format('d M, Y') }}
            </div>
        </div>

        <div style="margin-bottom: 30px;">
            <strong>Bill To:</strong><br>
            {{ $order->user->name }}<br>
            {{ $order->user->email }}<br>
            Shipping Address: {{ $order->address }}
        </div>

        <table>
            <thead>
                <tr>
                    <th>Product</th>
                    <th>Price</th>
                    <th>Qty</th>
                    <th>Total</th>
                </tr>
            </thead>
            <tbody>
                @foreach($order->items as $item)
                    <tr>
                        <td>{{ $item->product->name }}</td>
                        <td>৳{{ number_format($item->price, 2) }}</td>
                        <td>{{ $item->quantity }}</td>
                        <td>৳{{ number_format($item->price * $item->quantity, 2) }}</td>
                    </tr>
                @endforeach
            </tbody>
            <tfoot>
                <tr>
                    <td colspan="3" style="text-align: right;"><strong>Grand Total:</strong></td>
                    <td class="total">৳{{ number_format($order->total_amount, 2) }}</td>
                </tr>
            </tfoot>
        </table>
    </div>
</body>
</html>
