@extends('layouts.main')

@section('breadcrumbs')
    {{ Breadcrumbs::render(request()->route()->getName()) }}
@endsection
@section('content')
    <div class="w-full grid gap-5 lg:gap-7.5 mx-auto">
        <div class="card border border-agi-100 pb-2.5">
            <div class="card-header bg-agi-50" id="basic_settings">
                <div class="card-title flex flex-row gap-1.5">
                    Memo Penyelesaian NOC
                </div>
                <div class="flex items-center gap-2">
                    <a href="{{ route('noc.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('noc.update',$noc) }}" method="POST" class="grid gap-5" enctype="multipart/form-data">
                    @csrf
                    @method('PUT')

                    <input type="hidden" name="persetujuan_penawaran_id" value="{{ $noc->persetujuan_penawaran_id }}">
                    <input type="hidden" name="permohonan_id" value="{{ $noc->permohonan_id }}">

                    <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                        <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_pembayar') border-danger bg-danger-light @enderror" name="status_pembayar" id="status_pembayar" disabled>
                                <option value="">Pilih Status Bayar</option>
                                <option value="sudah_bayar" {{ (old('status_pembayar') == 'sudah_bayar') || ($noc?->permohonan?->status_bayar == 'sudah_bayar') ? 'selected' : '' }}>Sudah Bayar</option>
                                <option value="belum_bayar" {{ (old('status_pembayar') == 'belum_bayar') || ($noc?->permohonan?->status_bayar == 'belum_bayar') ? 'selected' : '' }}>Belum Bayar</option>
                            </select>
                            @error('status_bayar')
                            <em class="alert text-danger text-sm">{{ $message }}</em>
                            @enderror
                        </div>
                    </div>

                    <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                        <label class="form-label max-w-56">
                            Bukti Pembayaran
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            @if(!empty($noc->persetujuanPenawaran->bukti_bayar))
                                <div class="mt-2 flex items-center">
                                    <a href="{{ Storage::url($noc->persetujuanPenawaran->bukti_bayar) }}" target="_blank" class="badge badge-sm badge-outline badge-warning">
                                        <i class="ki-filled ki-eye mr-2"></i> Lihat File
                                    </a>
                                </div>
                            @endif
                        </div>
                    </div>

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

                    <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                        <label class="form-label max-w-56">
                            Nominal Diterima
                        </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', $noc->nominal_bayar ?? '') }}" placeholder="Masukkan nominal bayar" readonly>
                            @error('nominal_bayar')
                            <em class="alert text-danger text-sm">{{ $message }}</em>
                            @enderror
                        </div>
                    </div>

                    <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                        <label class="form-label max-w-56">
                            Tanggal Pembayaran
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <input type="date" name="tanggal_pembayaran" id="tanggal_pembayaran" class="input w-full @error('tanggal_pembayaran') border-danger bg-danger-light @enderror" value="{{ old('tanggal_pembayaran', isset($noc->tanggal_pembayaran) ? date('Y-m-d', strtotime($noc->tanggal_pembayaran)) : '') }}" readonly>
                            @error('tanggal_pembayaran')
                            <em class="alert text-danger text-sm">{{ $message }}</em>
                            @enderror
                        </div>
                    </div>


                    <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                        <label class="form-label max-w-56">
                            Bukti KSL
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            @if(isset($noc->bukti_ksl) && !empty($noc->bukti_ksl))
                                <div class="mt-2 flex items-center">
                                    <a href="{{ Storage::url($noc->bukti_ksl) }}" target="_blank" class="badge badge-sm badge-outline badge-warning">
                                        <i class="ki-filled ki-eye mr-2"></i> Lihat File
                                    </a>
                                </div>
                            @endif
                        </div>
                    </div>

                    <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                        <label class="form-label max-w-56">
                            Memo Penyelesaian
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <input type="hidden" name="is_memo" value="{{ $noc->id }}">
                            <input type="file" name="memo_penyelesaian" id="memo_penyelesaian" class="file-input w-full @error('memo_penyelesaian') border-danger bg-danger-light @enderror" accept=".pdf,.jpg,.jpeg,.png">
                            @error('memo_penyelesaian')
                            <em class="alert text-danger text-sm">{{ $message }}</em>
                            @enderror

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


                    <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                        <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" readonly placeholder="Masukkan catatan">{{ old('catatan', $noc->catatan ?? '') }}</textarea>
                            @error('catatan')
                            <em class="alert text-danger text-sm">{{ $message }}</em>
                            @enderror
                        </div>
                    </div>

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