<div class="row">
    <div class="col-md-6">
        <p><strong>@lang('purchaseRequisition::lang.reference_no'):</strong> {{ $prRequest->ref_no }}</p>
        <p><strong>@lang('purchaseRequisition::lang.date'):</strong> {{ \Carbon\Carbon::parse($prRequest->transaction_date)->format('Y-m-d') }}</p>
        <p><strong>@lang('purchase.business_location'):</strong> {{ $prRequest->location->name ?? '-' }}</p>
    </div>
    <div class="col-md-6">
        <p><strong>@lang('sale.status'):</strong>
            <span class="label label-info">{{ ucfirst(str_replace('_', ' ', $prRequest->status)) }}</span>
        </p>
        <p><strong>@lang('purchaseRequisition::lang.created_by'):</strong> {{ $prRequest->createdBy->username ?? '-' }}</p>
        <p><strong>@lang('purchaseRequisition::lang.notes'):</strong> {{ $prRequest->notes ?? '-' }}</p>
    </div>
</div>

<h4>@lang('purchaseRequisition::lang.products')</h4>
<div class="table-responsive">
    <table class="table table-bordered table-condensed">
        <thead>
            <tr>
                <th>@lang('sale.product')</th>
                <th>@lang('purchaseRequisition::lang.sku')</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>
                <th>@lang('purchaseRequisition::lang.notes')</th>
            </tr>
        </thead>
        <tbody>
            @foreach($prRequest->products as $product)
            @php
                $prod       = $product->product;
                $variation  = $product->variation;
                $varName    = ($prod->type == 'variable' && $variation && !in_array(strtoupper(trim($variation->name)), ['DUMMY', '']))
                              ? ' ' . $variation->name : '';
                $sku        = $variation ? ($variation->sub_sku ?: $prod->sku) : $prod->sku;
                $brand      = $prod->brand->name     ?? null;
                $category   = $prod->category->name  ?? null;
                $subCat     = $prod->sub_category->name ?? null;
                $meta       = implode(' • ', array_filter([$brand, $category, $subCat]));
            @endphp
            <tr>
                <td>
                    {{ $prod->name . $varName }}
                    @if($meta)
                        <br><small class="text-muted">{{ $meta }}</small>
                    @endif
                </td>
                <td>{{ $sku }}</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>
                <td>{{ $product->notes ?? '-' }}</td>
            </tr>
            @endforeach
        </tbody>
    </table>
</div>
