<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Log Transaksi</title>
    <style>
        @media print {
            @page {
                size: A4 portrait;
                margin: 15mm;
            }
        }
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body {
            font-family: Arial, sans-serif;
            font-size: 10px;
            line-height: 1.4;
            background: white;
            padding: 20px;
        }
        .header {
            text-align: center;
            margin-bottom: 20px;
            padding-bottom: 15px;
            border-bottom: 2px solid #333;
        }
        .header h1 {
            font-size: 18px;
            font-weight: bold;
            margin-bottom: 5px;
        }
        .header h2 {
            font-size: 14px;
            font-weight: normal;
            color: #666;
        }
        .header .period {
            font-size: 12px;
            margin-top: 10px;
        }
        .summary-section {
            display: flex;
            justify-content: space-around;
            margin-bottom: 20px;
            padding: 15px;
            background: #f9f9f9;
            border-radius: 5px;
        }
        .summary-box {
            text-align: center;
        }
        .summary-box .label {
            font-size: 10px;
            color: #666;
            text-transform: uppercase;
        }
        .summary-box .value {
            font-size: 16px;
            font-weight: bold;
            color: #333;
        }
        .section-title {
            font-size: 12px;
            font-weight: bold;
            margin: 20px 0 10px;
            padding-bottom: 5px;
            border-bottom: 1px solid #ddd;
        }
        .detail-table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
        }
        .detail-table th, .detail-table td {
            border: 1px solid #ddd;
            padding: 6px 8px;
            text-align: left;
            font-size: 9px;
        }
        .detail-table th {
            background: #f5f5f5;
            font-weight: bold;
            text-transform: uppercase;
        }
        .text-right {
            text-align: right;
        }
        .text-center {
            text-align: center;
        }
        .badge {
            display: inline-block;
            padding: 2px 6px;
            border-radius: 3px;
            font-size: 8px;
            font-weight: bold;
        }
        .badge-success {
            background: #d4edda;
            color: #155724;
        }
        .badge-warning {
            background: #fff3cd;
            color: #856404;
        }
        .badge-info {
            background: #cce5ff;
            color: #004085;
        }
        .badge-secondary {
            background: #e2e3e5;
            color: #383d41;
        }
        .grand-total-row {
            background: #333;
            color: white;
            font-weight: bold;
        }
        .footer {
            margin-top: 30px;
            padding-top: 15px;
            border-top: 1px solid #ddd;
            display: flex;
            justify-content: space-between;
            font-size: 9px;
            color: #666;
        }
        @media screen {
            body {
                max-width: 210mm;
                margin: 20px auto;
                border: 1px solid #ccc;
                box-shadow: 0 0 10px rgba(0,0,0,0.1);
            }
        }
    </style>
</head>
<body onload="window.print()">
    <div class="header">
        @if($shopLogo ?? false)
        <img src="{{ $shopLogo }}" alt="{{ $shopName }}" style="max-height: 50px; margin-bottom: 10px;">
        @endif
        <h1>{{ $shopName }}</h1>
        @if($shopAddress)
        <p>{{ $shopAddress }}</p>
        @endif
        <h2>LOG TRANSAKSI</h2>
        <div class="period">
            Periode: {{ \Carbon\Carbon::parse($startDate)->format('d M Y') }} - {{ \Carbon\Carbon::parse($endDate)->format('d M Y') }}
        </div>
    </div>

    <div class="summary-section">
        <div class="summary-box">
            <div class="label">Total Order</div>
            <div class="value">{{ $summary['total_orders'] }}</div>
        </div>
        <div class="summary-box">
            <div class="label">Order Lunas</div>
            <div class="value">{{ $summary['paid_orders'] }}</div>
        </div>
        <div class="summary-box">
            <div class="label">Order Selesai</div>
            <div class="value">{{ $summary['completed_orders'] }}</div>
        </div>
    </div>

    <div class="section-title">Riwayat Transaksi</div>
    <table class="detail-table">
        <thead>
            <tr>
                <th>No</th>
                <th>Waktu</th>
                <th>Invoice</th>
                <th>Pelanggan</th>
                <th class="text-center">Bayar</th>
                <th class="text-center">Produksi</th>
                <th>Designer</th>
                <th>Operator</th>
                <th class="text-right">Total</th>
            </tr>
        </thead>
        <tbody>
            @forelse($orders as $index => $order)
            <tr>
                <td class="text-center">{{ $index + 1 }}</td>
                <td>{{ $order->created_at->format('d/m/Y H:i') }}</td>
                <td>{{ $order->invoice_number }}</td>
                <td>{{ $order->customer_name }}</td>
                <td class="text-center">
                    @if($order->payment_status === 'paid')
                        <span class="badge badge-success">Lunas</span>
                    @else
                        <span class="badge badge-warning">Belum</span>
                    @endif
                </td>
                <td class="text-center">
                    @if($order->production_status === 'selesai')
                        <span class="badge badge-success">Selesai</span>
                    @elseif($order->production_status === 'proses')
                        <span class="badge badge-info">Proses</span>
                    @else
                        <span class="badge badge-secondary">Antri</span>
                    @endif
                </td>
                <td>{{ $order->designer->name ?? '-' }}</td>
                <td>{{ $order->operator->name ?? '-' }}</td>
                <td class="text-right">Rp {{ number_format($order->total_price, 0, ',', '.') }}</td>
            </tr>
            @empty
            <tr>
                <td colspan="9" class="text-center">Tidak ada data</td>
            </tr>
            @endforelse
        </tbody>
        @if($orders->count() > 0)
        <tfoot>
            <tr class="grand-total-row">
                <td colspan="8" class="text-right">TOTAL</td>
                <td class="text-right">Rp {{ number_format($orders->sum('total_price'), 0, ',', '.') }}</td>
            </tr>
        </tfoot>
        @endif
    </table>

    <div class="footer">
        <div>Dicetak pada: {{ now()->format('d M Y H:i:s') }}</div>
        <div>Halaman 1 dari 1</div>
    </div>
</body>
</html>
