<div class="grid grid-cols-1 lg:grid-cols-2 gap-5 lg:gap-7.5">
    @foreach ($permohonan->documents as $dokumen)
        @php

            $jaminanId = $dokumen->id;

            $currentInspeksi = $inspeksiData[$jaminanId] ?? null;

            $tanahBangunanTypes = ['KAPAL', 'PESAWAT', 'KENDARAAN', 'ALAT BERAT', 'MESIN'];

            $href = [
                [
                    'label' => 'form inspeksi',
                    'url' =>
                        route('surveyor.inspeksi', [
                            'id' => $permohonan->id,
                        ]) . "?documentId={$jaminanId}&jenis_jaminan={$dokumen->jenisJaminan->id}",
                    'show' => true,
                    'icon' => !empty($currentInspeksi['data_form']),
                ],
            ];

            if (!in_array(strtoupper($dokumen->jenisJaminan->name), $tanahBangunanTypes)) {
                $denahLabel = strtoupper($dokumen->jenisJaminan->name);
                $href[] = [
                    'label' => 'denah ' . $denahLabel,
                    'url' =>
                        route('surveyor.denah', [
                            'id' => $permohonan->id,
                        ]) . "?documentId={$jaminanId}&jenis_jaminan={$dokumen->jenisJaminan->id}",
                    'show' => true,
                    'icon' => !empty($currentInspeksi['denah_form']),
                ];
            }

            $href = array_merge($href, [
                [
                    'label' => 'foto',
                    'url' =>
                        route('surveyor.foto', [
                            'id' => $permohonan->id,
                        ]) . "?documentId={$jaminanId}&jenis_jaminan={$dokumen->jenisJaminan->id}",
                    'show' => true,
                    'icon' => !empty($currentInspeksi['foto_form']),
                ],
                [
                    'label' => 'data pembanding',
                    'url' =>
                        route('surveyor.data-pembanding', [
                            'id' => $permohonan->id,
                        ]) . "?documentId={$jaminanId}&jenis_jaminan={$dokumen->jenisJaminan->id}",
                    'show' => true,
                    'icon' => !empty($currentInspeksi['data_pembanding']),
                ],
            ]);
        @endphp
        <div class="card border border-agi-100 border-2 border-dashed border-brand-clarity bg-center bg-[length:600px] bg-no-repeat add-new-bg grid gap-5"
            style="padding: 20px">
            <div class="card-group flex items-center flex-wrap sm:flex-nowrap justify-between py-4 gap-2.5">
                <div class="flex items-center gap-3.5">
                    <div class="relative size-[50px] shrink-0">
                        <svg class="w-full h-full stroke-brand-clarity fill-light" fill="none" height="48"
                            viewBox="0 0 44 48" width="44" xmlns="http://www.w3.org/2000/svg">
                            <path
                                d="M16 2.4641C19.7128 0.320509 24.2872 0.320508 28 2.4641L37.6506 8.0359C41.3634 10.1795 43.6506 14.141 43.6506 18.4282V29.5718C43.6506 33.859 41.3634 37.8205 37.6506 39.9641L28 45.5359C24.2872 47.6795 19.7128 47.6795 16 45.5359L6.34937 39.9641C2.63655 37.8205 0.349365 33.859 0.349365 29.5718V18.4282C0.349365 14.141 2.63655 10.1795 6.34937 8.0359L16 2.4641Z"
                                fill=""></path>
                            <path
                                d="M16.25 2.89711C19.8081 0.842838 24.1919 0.842837 27.75 2.89711L37.4006 8.46891C40.9587 10.5232 43.1506 14.3196 43.1506 18.4282V29.5718C43.1506 33.6804 40.9587 37.4768 37.4006 39.5311L27.75 45.1029C24.1919 47.1572 19.8081 47.1572 16.25 45.1029L6.59937 39.5311C3.04125 37.4768 0.849365 33.6803 0.849365 29.5718V18.4282C0.849365 14.3196 3.04125 10.5232 6.59937 8.46891L16.25 2.89711Z"
                                stroke=""></path>
                        </svg>
                        <div class="absolute leading-none left-2/4 top-2/4 -translate-y-2/4 -translate-x-2/4">
                            <i class="ki-filled ki-additem text-2xl text-brand"></i>
                        </div>
                    </div>
                </div>
                <div class="flex items-center gap-2.5">
                    <span class="flex items-center gap-1.5 leading-none font-medium text-sm text-gray-900">
                        {{ $dokumen->jenisJaminan->name ?? '' }}
                    </span>
                </div>
            </div>

            @if (strtolower($permohonan->tujuanPenilaian->name) == 'rap')
                <a href="{{ route('surveyor.inspeksi', ['id' => $permohonan->id]) .
                    '?' .
                    http_build_query([
                        'documentId' => $jaminanId,
                        'jenis_jaminan' => $dokumen->jenisJaminan->id,
                    ]) }}"
                    class="flex items-center justify-between border border-gray-200 rounded-xl gap-2 px-4 py-4 btn-outline {{ !empty($currentInspeksi['data_form']) ? 'btn-success' : 'btn-primary' }} hover:btn-light">
                    <div class="flex items-center gap-3.5">
                        <div class="flex flex-col">
                            <h1 class="text-sm font-medium text-gray-900 mb-px uppercase">
                                Form Inspeksi RAP
                            </h1>
                        </div>

                    </div>
                    <div class="flex items-center gap-5">
                        <div class="flex gap-0.5">
                            <div
                                class="btn btn-sm btn-icon btn-clear {{ !empty($currentInspeksi['data_form']) ? '' : 'btn-light' }}">
                                <i
                                    class="ki-filled {{ !empty($currentInspeksi['data_form']) ? 'ki-check-circle' : 'ki-notepad-edit' }}"></i>
                            </div>
                        </div>
                    </div>
                </a>
                <a href="{{ route('surveyor.foto', ['id' => $permohonan->id]) .
                    '?' .
                    http_build_query([
                        'documentId' => $jaminanId,
                        'jenis_jaminan' => $dokumen->jenisJaminan->id,
                    ]) }}"
                    class="flex items-center justify-between border border-gray-200 rounded-xl gap-2 px-4 py-4 btn-outline {{ !empty($currentInspeksi['foto_form']) ? 'btn-success' : 'btn-primary' }} hover:btn-light">
                    <div class="flex items-center gap-3.5">
                        <div class="flex flex-col">
                            <h1 class="text-sm font-medium text-gray-900 mb-px uppercase">
                                Foto
                            </h1>
                        </div>
                    </div>
                    <div class="flex items-center gap-5">
                        <div class="flex gap-0.5">
                            <div
                                class="btn btn-sm btn-icon btn-clear {{ !empty($currentInspeksi['foto_form']) ? '' : 'btn-light' }}">
                                <i
                                    class="ki-filled {{ !empty($currentInspeksi['foto_form']) ? 'ki-check-circle' : 'ki-notepad-edit' }}"></i>
                            </div>
                        </div>
                    </div>
                </a>
            @else
                @foreach ($href as $item)
                    @if ($item['show'])
                        <a href="{{ $item['url'] }}"
                            class="flex items-center justify-between border border-gray-200 rounded-xl gap-2 px-4 py-4 btn-outline {{ $item['icon'] ? 'btn-success' : 'btn-primary' }} hover:btn-light">
                            <div class="flex items-center gap-3.5">
                                <div class="flex flex-col">
                                    <h1 class="text-sm font-medium text-gray-900 mb-px uppercase">
                                        {{ $item['label'] }}
                                    </h1>
                                </div>
                            </div>
                            <div class="flex items-center gap-5">
                                <div class="flex gap-0.5">
                                    <div class="btn btn-sm btn-icon btn-clear {{ $item['icon'] ? '' : 'btn-light' }}">
                                        <i
                                            class="ki-filled {{ $item['icon'] ? 'ki-check-circle' : 'ki-notepad-edit' }}"></i>
                                    </div>
                                </div>
                            </div>
                        </a>
                    @endif
                @endforeach
            @endif
        </div>
    @endforeach
</div>
