<div class="overflow-hidden w-full bg-white rounded-lg border shadow-md card border-agi-100">
    <div class="card-header bg-agi-50">
        <h3 class="uppercase card-title">
            Analisa Unit
        </h3>
    </div>
    <div class="card-body">
        <div class="grid gap-5">

            <!-- Luas tanah -->
            <div class="flex flex-wrap gap-2.5 items-baseline lg:flex-nowrap">
                <label class="form-label max-w-56">Luas Unit</label>
                @if (isset($permohonan->documents))

                    @foreach ($permohonan->documents as $item)
                        @php
                            $total_luas_unit = 0;
                            $jenis_legalitas_jaminan_id = 0;
                            if (isset($item->detail)) {
                                $total_luas_unit = calculateTotalLuas($item->detail, 'luas_bangunan', 1, 27, 3);
                            }
                        @endphp
                        <input type="hidden" id="jenis_legalistas_jaminan_unit_id" name="jenis_legalistas_jaminan_unit_id"
                            class="input" value="{{ $jenis_legalitas_jaminan_id }}">
                        <input type="hidden" name="luas_unit_sesuai" class="input" value="{{ $total_luas_unit }}">

                        <p class="text-gray-700 text-2sm">{{ $total_luas_unit }} m<sup>2</sup></p>
                    @endforeach
                @endif

                <div class="flex flex-wrap items-baseline w-full">
                    <div class="grid grid-cols-2 gap-4 mt-2 md:grid-cols-3">
                        <label class="flex gap-3 items-center form-label text-nowrap">
                            <input
                                onclick="toggleFieldVisibility('luas_unit','luas_unit_tidak_sesuai', ['tidak sesuai'])"
                                type="radio" class="radio" name="luas_unit" value="sesuai"
                                {{ old('luas_unit', isset($forminspeksi['luas_unit']['sesuai'])) ? 'checked' : '' }}>
                            <span class="ml-2">Sesuai</span>
                        </label>
                        <label class="flex gap-2.5 items-center form-label text-nowrap">
                            <input
                                onclick="toggleFieldVisibility('luas_unit','luas_unit_tidak_sesuai', ['tidak sesuai'])"
                                type="radio" class="radio" name="luas_unit" value="tidak sesuai"
                                {{ old('luas_unit', isset($forminspeksi['luas_unit']['tidak sesuai'])) ? 'checked' : '' }}>
                            <span class="ml-2">Tidak Sesuai</span>
                        </label>

                        <div id="luas_unit_tidak_sesuai" class="flex gap-2 items-baseline"
                            style="{{ old('luas_unit', isset($forminspeksi['luas_unit']['tidak sesuai'])) ? '' : 'display: none;' }}">
                            <div class="input">
                                <input id="analisa_luas_unit_tidak_sesuai" type="text" name="luas_unit_tidak_sesuai"
                                    class="w-full number-format" placeholder="Masukan Luas Tanah"
                                    value="{{ old('luas_unit_tidak_sesuai', $forminspeksi['luas_unit']['tidak sesuai'] ?? '') }}">
                                <i>M<sup>2</sup></i>
                            </div>
                            {{-- <button type="button" class="btn btn-md btn-primary"
                                onclick="updateAnalisa('analisa_unit')">Save</button> --}}
                        </div>
                    </div>
                    <em id="error-luas_unit" class="text-sm alert text-danger"></em>
                </div>
            </div>

            <div class="flex flex-wrap gap-2.5 items-baseline lg:flex-nowrap">
                <label class="form-label max-w-56">Kondisi Unit</label>
                <div class="flex flex-wrap items-baseline w-full">
                    <div class="flex-wrap items-stretch">
                        <div class="flex flex-col gap-2 items-start">
                            @if (isset($basicData['kondisiBangunan']))
                                @foreach ($basicData['kondisiBangunan'] as $item)
                                    <label class="flex gap-2.5 items-center form-label text-nowrap">
                                        <input class="checkbox" name="kondisi_unit[]" type="checkbox"
                                            value="{{ $item->name }}"
                                            {{ in_array($item->name, old('kondisi_unit', $forminspeksi['kondisi_unit'] ?? [])) ? 'checked' : '' }} />
                                        {{ $item->name }}
                                    </label>
                                @endforeach
                            @endif
                        </div>
                        <em id="error-kondisi_unit" class="text-sm alert text-danger"></em>
                    </div>
                </div>
            </div>

            <!-- Posisi Unit -->
            <div class="flex flex-wrap gap-2.5 items-baseline lg:flex-nowrap">
                <label class="form-label max-w-56">Posisi Unit</label>
                <div class="flex flex-wrap items-baseline w-full">
                    <div class="flex-wrap items-stretch">
                        <div class="flex flex-col gap-2 items-start">
                            @if (isset($basicData['posisiUnit']))
                                @foreach ($basicData['posisiUnit'] as $item)
                                    <label class="flex gap-2.5 items-center form-label text-nowrap">
                                        <input class="checkbox" name="posisi_unit[]" type="checkbox"
                                            value="{{ $item->name }}"
                                            {{ in_array($item->name, old('posisi_unit', $forminspeksi['posisi_unit'] ?? [])) ? 'checked' : '' }} />
                                        {{ $item->name }}
                                    </label>
                                @endforeach
                            @endif
                        </div>
                        <em id="error-posisi_unit" class="text-sm alert text-danger"></em>
                    </div>
                </div>
            </div>

            <div class="flex flex-wrap gap-2.5 items-baseline lg:flex-nowrap">
                <label class="form-label max-w-56">Lantai</label>
                <div class="flex flex-wrap items-baseline w-full">

                    <div class="flex flex-col gap-4 items-start">
                        @if (isset($basicData['lantai']))
                            @foreach ($basicData['lantai'] as $item)
                                <div class="flex flex-wrap gap-2.5 items-baseline lg:flex-nowrap">
                                    <label class="gap-2.5 form-label max-w-56" style="width: 500px">
                                        <input class="checkbox" name="lantai[]" type="checkbox"
                                            value="{{ $item->name }}"
                                            {{ in_array($item->name, old('lantai', $forminspeksi['lantai'] ?? [])) ? 'checked' : '' }} />
                                        {{ $item->name }}
                                    </label>
                                    <input type="text" name="lantai_input[]" class="w-full input" id="lantaiInput"
                                        placeholder="Masukkan {{ $item->name }}..."
                                        value="{{ old('lantai_input.' . $loop->index, $forminspeksi['lantai_input'][$loop->index] ?? '') }}">
                                </div>
                            @endforeach
                        @endif
                    </div>
                    <em id="error-lantai" class="text-sm alert text-danger"></em>
                </div>
            </div>

            <!-- Kondisi Fisik Tanah -->

            <div class="flex flex-wrap gap-2.5 items-baseline lg:flex-nowrap">
                <label class="form-label max-w-56">View</label>
                <div class="flex flex-wrap items-baseline w-full">
                    <div class="flex-wrap items-stretch">
                        <div class="flex flex-col gap-2 items-start">
                            @if (isset($basicData['viewUnit']))
                                @foreach ($basicData['viewUnit'] as $item)
                                    <label class="flex gap-2.5 items-center form-label text-nowrap">
                                        <input class="checkbox" name="view[]" type="checkbox"
                                            value="{{ $item->name }}"
                                            {{ in_array($item->name, old('view', $forminspeksi['view'] ?? [])) ? 'checked' : '' }} />
                                        {{ $item->name }}
                                    </label>
                                @endforeach
                            @endif
                        </div>
                        <em id="error-view" class="text-sm alert text-danger"></em>
                    </div>
                </div>
            </div>

            <div class="flex flex-wrap gap-2.5 items-baseline lg:flex-nowrap">
                <label class="form-label max-w-56">Bentuk Unit</label>
                <div class="flex flex-wrap items-baseline w-full">
                    <div class="flex-wrap items-stretch">
                        <div class="flex flex-col gap-2 items-start">
                            @if (isset($basicData['bentukUnit']))
                                @foreach ($basicData['bentukUnit'] as $item)
                                    <label class="flex gap-2.5 items-center form-label text-nowrap">
                                        <input class="checkbox" name="bentuk_unit[]" type="checkbox"
                                            value="{{ $item->name }}"
                                            {{ in_array($item->name, old('bentuk_unit', $forminspeksi['bentuk_unit'] ?? [])) ? 'checked' : '' }} />
                                        {{ $item->name }}
                                    </label>
                                @endforeach
                            @endif
                        </div>
                        <em id="error-bentuk_unit" class="text-sm alert text-danger"></em>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
