<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Laporan Produksi</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;
        }
        .total-row {
            background: #f0f0f0;
            font-weight: bold;
        }
        .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>LAPORAN PRODUKSI</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 Selesai</div>
            <div class="value">{{ $summary['total_completed'] }}</div>
        </div>
        <div class="summary-box">
            <div class="label">Total Qty</div>
            <div class="value">{{ $summary['total_qty'] }} pcs</div>
        </div>
    </div>

    <div class="section-title">Detail Produksi</div>
    <table class="detail-table">
        <thead>
            <tr>
                <th>No</th>
                <th>Invoice</th>
                <th>Pelanggan</th>
                <th>File</th>
                <th>Ukuran</th>
                <th>Bahan</th>
                <th class="text-center">Qty</th>
                <th>Operator</th>
                <th>Tgl Selesai</th>
            </tr>
        </thead>
        <tbody>
            @forelse($orders as $index => $order)
            <tr>
                <td class="text-center">{{ $index + 1 }}</td>
                <td>{{ $order->invoice_number }}</td>
                <td>{{ $order->customer_name }}</td>
                <td><strong>{{ $order->file_name }}</strong></td>
                <td>{{ $order->size }}</td>
                <td>{{ $order->material ?? '-' }}</td>
                <td class="text-center">{{ $order->qty }}</td>
                <td>{{ $order->operator->name ?? '-' }}</td>
                <td>{{ $order->finished_at?->format('d/m/Y H:i') }}</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="6" class="text-right">TOTAL</td>
                <td class="text-center">{{ $summary['total_qty'] }} pcs</td>
                <td colspan="2"></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>
