<!DOCTYPE html>
<html>

<head>
    <title>Laporan Penjualan - INTERIA</title>
    <style>
        body {
            font-family: 'Helvetica', 'Arial', sans-serif;
            color: #334155;
            line-height: 1.5;
            margin: 0;
            padding: 20px;
        }

        .header {
            text-align: center;
            margin-bottom: 30px;
            border-bottom: 2px solid #fbbf24;
            padding-bottom: 10px;
        }

        .header h1 {
            color: #92400e;
            margin: 0;
            font-size: 24px;
            text-transform: uppercase;
            letter-spacing: 2px;
        }

        .header p {
            margin: 5px 0 0;
            color: #64748b;
            font-size: 12px;
        }

        .report-info {
            margin-bottom: 25px;
        }

        .report-info table {
            width: 100%;
        }

        .report-info td {
            font-size: 13px;
        }

        .summary-grid {
            width: 100%;
            margin-bottom: 30px;
            border-collapse: collapse;
        }

        .summary-card {
            background-color: #fffbeb;
            border: 1px solid #fef3c7;
            padding: 15px;
            text-align: center;
        }

        .summary-label {
            display: block;
            font-size: 10px;
            font-weight: bold;
            color: #92400e;
            text-transform: uppercase;
            margin-bottom: 5px;
        }

        .summary-value {
            display: block;
            font-size: 18px;
            font-weight: bold;
            color: #1e293b;
        }

        .table-container {
            width: 100%;
        }

        table.main-table {
            width: 100%;
            border-collapse: collapse;
            font-size: 11px;
        }

        table.main-table th {
            background-color: #f8fafc;
            color: #475569;
            font-weight: bold;
            text-transform: uppercase;
            padding: 10px;
            border-bottom: 1px solid #e2e8f0;
            text-align: left;
        }

        table.main-table td {
            padding: 10px;
            border-bottom: 1px solid #f1f5f9;
        }

        .text-right {
            text-align: right;
        }

        .font-bold {
            font-weight: bold;
        }

        .footer {
            margin-top: 40px;
            text-align: center;
            font-size: 10px;
            color: #94a3b8;
            border-top: 1px solid #f1f5f9;
            padding-top: 10px;
        }

        /* Payment Method Badges */
        .badge {
            display: inline-block;
            padding: 3px 10px;
            border-radius: 20px;
            font-size: 10px;
            font-weight: 600;
        }

        .badge.cash {
            background: #dcfce7;
            color: #15803d;
            border: 1px solid #bbf7d0;
        }

        .badge.transfer {
            background: #eef2ff;
            color: #1d4ed8;
            border: 1px solid #c7d2fe;
        }

        .badge.qris {
            background: #f3e8ff;
            color: #6b21a5;
            border: 1px solid #e9d5ff;
        }

        .badge.ewallet {
            background: #fce7f3;
            color: #be185d;
            border: 1px solid #fbcfe8;
        }

        .badge.card {
            background: #e0f2fe;
            color: #0369a1;
            border: 1px solid #bae6fd;
        }

        .badge.unknown {
            background: #f1f5f9;
            color: #64748b;
            border: 1px solid #e2e8f0;
        }
    </style>
</head>

<body>
    <div class="header">
        <h1>INTERIA</h1>
        <p>Laporan Penjualan Resmi</p>
    </div>

    <div class="report-info">
        <table>
            <tr>
                <td width="50%">
                    <strong>Periode Laporan:</strong><br>
                    {{ \Carbon\Carbon::parse($startDate)->translatedFormat('d F Y') }} - {{ \Carbon\Carbon::parse($endDate)->translatedFormat('d F Y') }}
                </td>
                <td width="50%" align="right">
                    <strong>Dicetak Pada:</strong><br>
                    {{ \Carbon\Carbon::now()->translatedFormat('d F Y, H:i') }}
                </td>
            </tr>
        </table>
    </div>

    <table class="summary-grid">
        <tr>
            <td width="33.33%" class="summary-card">
                <span class="summary-label">Total Pendapatan</span>
                <span class="summary-value" style="color: #d97706;">Rp {{ number_format($totalRevenue, 0, ',', '.') }}</span>
            </td>
            <td width="33.33%" class="summary-card" style="border-left: 0; border-right: 0;">
                <span class="summary-label">Total Pesanan</span>
                <span class="summary-value">{{ number_format($totalOrders) }}</span>
            </td>
            <td width="33.33%" class="summary-card">
                <span class="summary-label">Rata-rata Pesanan</span>
                <span class="summary-value" style="color: #2563eb;">Rp {{ number_format($avgOrderValue, 0, ',', '.') }}</span>
            </td>
        </tr>
    </table>

    <div class="table-container">
        <h3 style="font-size: 14px; margin-bottom: 10px; color: #1e293b;">Rincian Transaksi</h3>
        <table class="main-table">
            <thead>
                <tr>
                    <th>Order ID</th>
                    <th>Tanggal</th>
                    <th>Pelanggan</th>
                    <th>Metode</th>
                    <th class="text-right">Total</th>
                </tr>
            </thead>
            <tbody>
                @foreach($orders as $o)
                @php
                $pm = strtolower($o->payment->payment_method ?? '');
                if ($pm == 'cash') { $bc = 'cash'; $label = 'Cash'; }
                elseif ($pm == 'transfer') { $bc = 'transfer'; $label = 'Transfer Bank'; }
                elseif ($pm == 'qris') { $bc = 'qris'; $label = 'QRIS'; }
                elseif ($pm == 'ewallet') { $bc = 'ewallet'; $label = 'E-Wallet'; }
                elseif ($pm == 'card') { $bc = 'card'; $label = 'Kartu Debit'; }
                else { $bc = 'unknown'; $label = 'N/A'; }
                @endphp
                <tr>
                    <td class="font-bold">#{{ $o->order_id }}</td>
                    <td>{{ $o->created_at->translatedFormat('d M Y, H:i') }}</td>
                    <td>{{ $o->user->name ?? 'User Biasa' }}</td>
                    <td><span class="badge {{ $bc }}">{{ $label }}</span></td>
                    <td class="text-right font-bold">Rp {{ number_format($o->total_price, 0, ',', '.') }}</td>
                </tr>
                @endforeach
            </tbody>
        </table>
    </div>

    <div class="footer">
        <p>Laporan ini dibuat secara otomatis oleh sistem INTERIA pada {{ \Carbon\Carbon::now()->translatedFormat('d F Y') }}.</p>
        <p>&copy; {{ date('Y') }} INTERIA - Furniture & Home Decor.</p>
    </div>
</body>

</html>