@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">
        <div class="pb-2.5 border card border-agi-100">
            <div class="card-header bg-agi-50" id="basic_settings">
                <div class="flex flex-row gap-1.5 card-title">
                    Persetujuan Penawaranan KJPP
                </div>
                <div class="flex gap-2 items-center">
                    <a href="{{ route('persetujuan-penawaran.index') }}" class="btn btn-xs btn-info"><i
                            class="ki-filled ki-exit-left"></i> Back</a>
                </div>
            </div>
            <div class="card-body">
                <form action="{{ route('persetujuan-penawaran.store') }}" method="POST" class="grid gap-5"
                    enctype="multipart/form-data">
                    @csrf
                    <input type="hidden" name="permohonan_id" value="{{ $permohonan->id }}">
                    <input type="hidden" name="penawaran_id"
                        value="{{ $permohonan->penawaran->id ?? old('penawaran_id') }}">
                    <input type="hidden" name="nomor_proposal_penawaran"
                        value="{{ $permohonan->penawaran->detail->no_proposal ?? old('nomor_proposal_penawaran') }}">
                    <input type="hidden" name="tanggal_proposal_penawaran"
                        value="{{ $permohonan->penawaran->detail->tgl_proposal ?? old('tanggal_proposal_penawaran') }}">
                    <input type="hidden" name="biaya_final"
                        value="{{ $permohonan->penawaran->detail->biaya_penawaran ?? old('biaya_final') }}">


                    <div class="flex hidden flex-wrap gap-2.5 items-baseline lg:flex-nowrap">
                        <label class="form-label max-w-56">
                            Status Bayar
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <select
                                class="input tomselect w-full @error('status_bayar') border-danger bg-danger-light @enderror"
                                name="status_bayar" id="status_bayar">
                                <option value="">Pilih Status Bayar</option>
                                <option value="sudah_bayar"
                                    {{ old('status_bayar') == 'sudah_bayar' || (isset($permohonan) && $permohonan->status_bayar == 'sudah_bayar') ? 'selected' : '' }}>
                                    Sudah Bayar</option>
                                <option value="belum_bayar"
                                    {{ old('status_bayar') == 'belum_bayar' || (isset($permohonan) && $permohonan->status_bayar == 'belum_bayar') ? 'selected' : '' }}>
                                    Belum Bayar</option>
                            </select>
                            @error('status_bayar')
                                <em class="text-sm alert text-danger">{{ $message }}</em>
                            @enderror
                        </div>
                    </div>
                    <div class="flex flex-wrap gap-2.5 items-baseline lg:flex-nowrap">
                        <label class="form-label max-w-56">
                            File Persetujuan Penawaran
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <input type="file" name="file_persetujuan_penawaran" id="file_persetujuan_penawaran"
                                class="file-input w-full @error('file_persetujuan_penawaran') border-danger bg-danger-light @enderror"
                                accept=".pdf,.doc,.docx">

                            @if (isset($persetujuanPenawaran->file_persetujuan_penawaran) &&
                                    !empty($persetujuanPenawaran->file_persetujuan_penawaran))
                                <div class="flex items-center mt-2">
                                    <a href="{{ Storage::url($persetujuanPenawaran->file_persetujuan_penawaran) }}"
                                        target="_blank" class="badge badge-sm badge-outline badge-warning">
                                        <i class="mr-2 ki-filled ki-eye"></i> Lihat File
                                    </a>
                                </div>
                            @endif

                            @error('file_persetujuan_penawaran')
                                <em class="text-sm alert text-danger">{{ $message }}</em>
                            @enderror
                        </div>
                    </div>

                    <div class="flex flex-wrap gap-2.5 items-baseline lg:flex-nowrap">
                        <label class="form-label max-w-56">
                            Surat Representasi
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <input type="file" name="surat_representasi" id="surat_representasi"
                                class="file-input w-full @error('surat_representasi') border-danger bg-danger-light @enderror"
                                accept=".pdf,.doc,.docx">

                            @if (isset($persetujuanPenawaran->surat_representasi) && !empty($persetujuanPenawaran->surat_representasi))
                                <div class="flex items-center mt-2">
                                    <a href="{{ Storage::url($persetujuanPenawaran->surat_representasi) }}" target="_blank"
                                        class="badge badge-sm badge-outline badge-warning">
                                        <i class="mr-2 ki-filled ki-eye"></i> Lihat File
                                    </a>
                                </div>
                            @endif

                            @error('surat_representasi')
                                <em class="text-sm alert text-danger">{{ $message }}</em>
                            @enderror
                        </div>
                    </div>

                    <div class="flex flex-wrap gap-2.5 items-baseline lg:flex-nowrap">
                        <label class="form-label max-w-56">
                            Nominal Bayar
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <input type="number" name="nominal_bayar" id="nominal_bayar"
                                class="input w-full @error('nominal_bayar') border-danger bg-danger-light @enderror"
                                value="{{ old('nominal_bayar', $persetujuanPenawaran->nominal_bayar ?? ($persetujuanPenawaran->biaya_final ?? '')) }}"
                                placeholder="Masukkan nominal bayar">
                            @error('nominal_bayar')
                                <em class="text-sm alert text-danger">{{ $message }}</em>
                            @enderror
                        </div>
                    </div>

                    <div class="flex flex-wrap gap-2.5 items-baseline lg:flex-nowrap">
                        <label class="form-label max-w-56">
                            Bukti Bayar
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <input type="file" name="bukti_bayar" id="bukti_bayar"
                                class="file-input w-full @error('bukti_bayar') border-danger bg-danger-light @enderror"
                                accept=".pdf,.jpg,.jpeg,.png">

                            @if (isset($persetujuanPenawaran->bukti_bayar) && !empty($persetujuanPenawaran->bukti_bayar))
                                <div class="flex items-center mt-2">
                                    <a href="{{ Storage::url($persetujuanPenawaran->bukti_bayar) }}" target="_blank"
                                        class="badge badge-sm badge-outline badge-warning">
                                        <i class="mr-2 ki-filled ki-eye"></i> Lihat File
                                    </a>
                                </div>
                            @endif

                            @error('bukti_bayar')
                                <em class="text-sm alert text-danger">{{ $message }}</em>
                            @enderror
                        </div>
                    </div>

                    <div class="flex flex-wrap gap-2.5 items-baseline lg:flex-nowrap">
                        <label class="form-label max-w-56">
                            Catatan
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <textarea name="catatan" id="catatan" rows="4"
                                class="textarea w-full @error('catatan') border-danger bg-danger-light @enderror" placeholder="Masukkan catatan">{{ old('catatan', $persetujuanPenawaran->catatan ?? '') }}</textarea>
                            @error('catatan')
                                <em class="text-sm alert text-danger">{{ $message }}</em>
                            @enderror
                        </div>
                    </div>

                    <div class="flex justify-end">
                        <button type="submit" class="btn btn-primary">
                            Proses
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
@endsection
