<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>@lang('purchaseRequisition::lang.purchase_requisition') - {{ $prRequest->ref_no }}</title>
    <style>
        body { font-family: Arial, sans-serif; font-size: 12px; }
        .header { text-align: center; margin-bottom: 20px; }
        .info-table { width: 100%; margin-bottom: 20px; }
        .info-table td { padding: 5px; }
        .products-table { width: 100%; border-collapse: collapse; }
        .products-table th, .products-table td { border: 1px solid #ddd; padding: 8px; text-align: left; }
        .products-table th { background-color: #f2f2f2; }
        @media print {
            .no-print { display: none; }
        }
    </style>
</head>
<body>
    <div class="no-print" style="margin-bottom: 20px;">
        <button onclick="window.print()">@lang('messages.print')</button>
        <button onclick="window.close()">@lang('messages.close')</button>
    </div>

    <div class="header">
        <h2>@lang('purchaseRequisition::lang.purchase_requisition')</h2>
        <p>{{ $prRequest->ref_no }}</p>
    </div>

    <table class="info-table">
        <tr>
            <td><strong>@lang('purchaseRequisition::lang.date'):</strong></td>
            <td>{{ \Carbon\Carbon::parse($prRequest->transaction_date)->format('Y-m-d') }}</td>
            <td><strong>@lang('purchase.business_location'):</strong></td>
            <td>{{ $prRequest->location->name ?? '-' }}</td>
        </tr>
        <tr>
            <td><strong>@lang('sale.status'):</strong></td>
            <td>{{ ucfirst(str_replace('_', ' ', $prRequest->status)) }}</td>
            <td><strong>@lang('purchaseRequisition::lang.created_by'):</strong></td>
            <td>{{ $prRequest->createdBy->username ?? '-' }}</td>
        </tr>
        @if($prRequest->notes)
        <tr>
            <td><strong>@lang('purchaseRequisition::lang.notes'):</strong></td>
            <td colspan="3">{{ $prRequest->notes }}</td>
        </tr>
        @endif
    </table>

    <h3>@lang('purchaseRequisition::lang.products')</h3>
    <table class="products-table">
        <thead>
            <tr>
                <th>#</th>
                <th>@lang('sale.product')</th>
                <th>@lang('purchaseRequisition::lang.current_stock')</th>
                <th>@lang('purchaseRequisition::lang.required_quantity')</th>
                <th>@lang('purchaseRequisition::lang.avg_unit_cost')</th>
                <th>@lang('purchaseRequisition::lang.last_purchase_price')</th>
                <th>@lang('sale.unit_price')</th>
            </tr>
        </thead>
        <tbody>
            @foreach($prRequest->products as $index => $product)
            <tr>
                <td>{{ $index + 1 }}</td>
                <td>{{ $product->product->name }}@if($product->product->type == 'variable' && $product->variation && !in_array(strtoupper(trim($product->variation->name)), ['DUMMY', ''])) {{ $product->variation->name }}@endif</td>
                <td>{{ number_format($product->current_stock, 2) }}</td>
                <td>{{ number_format($product->required_quantity, 2) }}</td>
                <td>{{ number_format($product->avg_unit_cost, 2) }}</td>
                <td>{{ number_format($product->last_purchase_price, 2) }}</td>
                <td>{{ number_format($product->selling_price, 2) }}</td>
            </tr>
            @if($product->notes)
            <tr>
                <td colspan="7"><em>@lang('purchaseRequisition::lang.notes'): {{ $product->notes }}</em></td>
            </tr>
            @endif
            @endforeach
        </tbody>
    </table>

    <script>
        window.onload = function() { window.print(); }
    </script>
</body>
</html>
