<div class="p-4">
    <h2 class="text-lg font-bold mb-4 text-gray-700 uppercase tracking-wider">
        PRODUCTION PLAN TABLE:
    </h2>
    <div class="overflow-x-auto rounded-lg shadow">
        <table class="w-full divide-y divide-gray-200 text-sm text-center">
            <thead class="bg-gray-100 text-s font-semibold uppercase text-gray-700">
                <tr>
                    <th class="border px-4 py-2" rowspan="4">No</th>
                    <th class="border px-4 py-2 whitespace-nowrap" rowspan="3">Plant</th>
                    <th class="border px-4 py-2 whitespace-nowrap" rowspan="3">Line</th>
                    <th class="border px-4 py-2 whitespace-nowrap" rowspan="3">Item Code</th>
                    <th class="border px-4 py-2 whitespace-nowrap" rowspan="3">Category</th>

                    <th class="border px-4 py-2 whitespace-nowrap" colspan="{{ count($dates) * 3 }}" class="text-center">
                        Production Plan Dates
                    </th>
                </tr>
                <tr>
                    @foreach($dates as $date)
                        {{-- <th colspan="3" class="text-center">
                            {{ $date }}
                        </th> --}}
                        <th colspan="3" class="text-center border-r-4 border-gray-400">
                            {{ $date }}
                        </th>
                    @endforeach
                </tr>
                <tr>
                    @foreach($dates as $date)
                        <th class="border px-4 py-2 whitespace-nowrap">Item Quantity</th>
                        <th class="border px-4 py-2 whitespace-nowrap">Target Plan</th>
                        <th class="border px-4 py-2 whitespace-nowrap border-r-4 border-gray-400">
                            Produced Quantity
                        </th>

                        {{-- <th class="border px-4 py-2 whitespace-nowrap">Produced Quantity</th> --}}
                    @endforeach
                </tr>
            </thead>

            <tbody class="divide-y divide-gray-100">
                @forelse ($records as $index => $record)
                    <tr class="hover:bg-gray-50">
                            <td class="border px-4 py-2">{{ $index + 1 }}</td>
                            <td class="border px-4 py-2 whitespace-nowrap">{{ $record['plant_name'] }}</td>
                            <td class="border px-4 py-2 whitespace-nowrap">{{ $record['line_name'] }}</td>
                            <td class="border px-4 py-2 whitespace-nowrap">{{ $record['item_code'] }}</td>
                            <td class="border px-4 py-2 whitespace-nowrap">{{ $record['category'] }}</td>

                            {{-- @foreach($dates as $date)
                                <td class="border px-4 py-2 whitespace-nowrap">{{ $record['target_plan'][$date] ?? '-' }}</td>
                                <td class="border px-4 py-2 whitespace-nowrap">{{ $record['production_plan'][$date] ?? '-' }}</td>
                            @endforeach --}}

                            @foreach($dates as $date)
                                @if(in_array($date, $leaveDates))
                                    <td class="border px-4 py-2 whitespace-nowrap">-</td>
                                    <td class="border px-4 py-2 whitespace-nowrap">-</td>
                                    <td class="border px-4 py-2 whitespace-nowrap">-</td>
                                @else
                                    {{-- <td class="border px-4 py-2 whitespace-nowrap">{{ $record['daily_target'] ?? '-' }}</td> --}}
                                    <td class="border px-4 py-2 whitespace-nowrap">
                                        {{ $record['daily_hourly_quantity'][$date] ?? '-' }}
                                    </td>
                                    <td class="border px-4 py-2 whitespace-nowrap">
                                        {{ $record['daily_target_dynamic'][$date] ?? '-' }}
                                    </td>
                                    <td class="border px-4 py-2 whitespace-nowrap">
                                        {{ $record['produced_quantity'][$date] ?? '-' }}
                                    </td>
                                    {{-- <td class="border px-4 py-2 whitespace-nowrap">{{ $record['produced_quantity'] ?? '-' }}</td> --}}
                                @endif
                            @endforeach
                    </tr>
                @empty
                    <tr>
                        <td colspan="10" class="px-4 py-4 text-center text-gray-500">
                            No production plan data found.
                        </td>
                    </tr>
                @endforelse
            </tbody>
        </table>
    </div>
</div>


