<div class="mb-3">
    <div class="d-flex align-items-center justify-content-between">
        <div class="">
            <div class="d-block">
                <h6>BATCH NUMBER {{ $batch?->batch_no ?? '' }}</h6>
            </div>
            <div class="d-block">
                {{-- <h6>{{ $batch?->chart_of_account?->code ?? '' }}</h6> --}}
            </div>
        </div>

        <div class="">
            <h4>BATCH TRACKING REPORT</h4>
        </div>

        <div class="">
            <div class="d-block">
                <h6>BATCH SIZE:- {{ $batch?->batch_size ?? '' }}</h6>
            </div>
            <div class="d-block">
                <h6>ACTUAL PROD:-
                    {{-- {{ number_format(collect($reportItems)->sum(fn($i) => $i['actual_qty']), 2) ?? 0 }} --}}
                </h6>
            </div>
            <div class="d-block">
                <h6>GRNs {{ $batch?->status == 'completed' ? 'Completed' : 'In-Process' }}</h6>
            </div>
        </div>
    </div>
</div>

<div class="table-responsive">
    {{-- <table
        class="border-top border-start border-end table table-bordered table-hover text-center "> --}}
    <table class="table table-excel table-bordered table-hover text-center text-black">

        <thead class="border-top">
            <tr>
                <th>#</th>
                <th>Date</th>
                <th>Document</th>
                <th>Code</th>
            </tr>
        </thead>

        <tbody>
            @if (isset($allDocuments) && count($allDocuments) > 0)
                @foreach ($allDocuments as $doc)
                    @php
                        $docType = isset($doc['code']) ? strtok($doc['code'], '0123456789') : '';
                        $docTypeUrl = match ($docType) {
                            'SIR' => 'store-issue-requisitions.show',
                            'RRN' => 'rejection-return-notes.show',
                            'LON' => 'left-over-notes.show',
                            default => 'javascript:void(0);',
                        };
                    @endphp
                    <tr>
                        <td>{{ $loop->iteration }}</td>
                        <td>
                            @if (array_key_exists('created_at', $doc) && $doc['created_at'])
                                {{ \Carbon\Carbon::parse($doc['created_at'])->format('d/m/Y') }}
                            @else
                                N/A
                            @endif
                        </td>
                        <td>{{ $docType }}</td>
                        <td>
                            <a href="{{ route($docTypeUrl, $doc['id']) }}" target="_blank">
                                {{ $doc['code'] ?? '-' }}
                            </a>

                        </td>
                    </tr>
                @endforeach
            @else
                <tr class="text-center">
                    <td colspan="4">No data found for selected batch</td>
                </tr>
            @endif
        </tbody>
    </table>
</div>
