@extends('layouts.main')

@section('breadcrumbs')
    {{ Breadcrumbs::render(request()->route()->getName()) }}
@endsection

@section('content')
    <div class="grid gap-5 mx-auto w-full lg:gap-7.5">
        @if (Auth::user()->hasAnyRole(['senior-officer', 'administrator','DD Appraisal', 'EO Appraisal']) && Request::is('penilai/lampiran'))
            @include('lpj::component.detail-jaminan', [
                'backLink' => 'otorisator.view-laporan',
                'queryParams' => [
                    'permohonanId' => request()->query('permohonanId'),
                    'documentId' => request()->query('documentId'),
                    'inspeksiId' => request()->query('inspeksiId'),
                    'jaminanId' => request()->query('jaminanId'),
                    'statusLpj' => 1,
                    'header' => request('header'),
                ],
                'title' => 'Paparan dokument',
            ])
        @else
            @include('lpj::component.detail-jaminan', [
                'backLink' => 'penilai.show',
                'id' => $permohonan->id,
                'title' => 'Lampiran foto dan dokumen',
            ])
        @endif

        @include('lpj::penilai.components.foto-lampiran')


        @if (isset($formDenah['denahs']) && is_array($formDenah['denahs']) && count($formDenah['denahs']) > 0)
            <div class="card">
                <div class="uppercase card-header bg-agi-50">
                    Denah
                </div>
                @foreach ($formDenah['denahs'] as $index => $denah)
                    <div class="card-body">
                        <div class="grid gap-5 w-full">
                            <!-- Preview Container -->
                            <div class="preview-container-{{ $index }}" class="flex items-center">
                                @if (isset($denah['foto_denah']))
                                    @php
                                        $fileExtension = pathinfo($denah['foto_denah'], PATHINFO_EXTENSION);
                                    @endphp

                                    @if (in_array($fileExtension, ['jpg', 'jpeg', 'png']))
                                        <img src="{{ asset('storage/' . $denah['foto_denah']) }}" class="object-contain max-w-full max-h-screen">
                                    @elseif($fileExtension === 'pdf')
                                        <embed src="{{ asset('storage/' . $denah['foto_denah']) }}" type="application/pdf"
                                            width="100%" height="500px">
                                    @endif
                                @endif
                            </div>
                            <div class="flex flex-wrap gap-4 w-full lg:flex-nowrap text-start">
                                <div class="w-full">
                                    <div class="flex flex-wrap gap-4">
                                        <div class="flex gap-4 justify-start items-center w-full">
                                            <label class="form-label max-w-56">
                                                <span class="form-label">Nama Denah</span>
                                            </label>
                                            <p class="text-gray-700 text-md">
                                                {{ isset($denah['nama_denah']) ? $denah['nama_denah'] : '' }}</p>
                                        </div>
                                    </div>
                                    <div class="flex flex-wrap gap-4">
                                        <div class="flex gap-4 justify-start items-center w-full">
                                            <label class="form-label max-w-56">
                                                <span class="form-label">Total Luas</span>
                                            </label>
                                            <p class="text-gray-700 text-md">
                                                {{ isset($denah['luas_denah']) ? $denah['luas_denah'] . ' m²' : '' }}</p>
                                        </div>
                                    </div>
                                </div>

                            </div>
                        </div>
                        <div class="mt-5 border-b border-b-gray-200"></div>
                    </div>
                @endforeach
            </div>
        @endif

        @if ($penilai && $penilai->kertas_kerja)
            <div class="card">
                <div class="uppercase card-header bg-agi-50">
                    Kertas Kerja
                </div>
                <div class="flex justify-between items-center card-body">

                    @php
                        $url = '';
                        $fileName = '';
                        if ($penilai && $penilai->kertas_kerja) {
                            $url = asset('storage/' . $penilai->kertas_kerja);
                            $fileName = basename($penilai->kertas_kerja);
                        }
                    @endphp

                    @if ($penilai && $penilai->kertas_kerja)
                        <button type="button" class="btn btn-primary"
                            onclick="window.open('{{ $url }}', '_blank')">
                            <i class="ki-outline ki-cloud-download"></i>
                            Lihat Kertas Kerja</button>

                        <p class="text-gray-700 text-2sm">{{ $fileName }}</p>
                    @else
                        <p class="text-gray-700 text-2sm">Belum ada kertas kerja</p>
                    @endif
                </div>
            </div>
        @endif
    </div>
@endsection
