@extends('layouts.main')

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

@section('content')
    <div class="w-full grid gap-5 lg:gap-7.5 mx-auto">
        <form action="{{ route('tender.penawaran.updatePenawaran', $noreg) }}" method="POST">
            @csrf
            @method('PUT')

            <div class="card border border-agi-100 pb-2.5">
                <div class="card-header bg-agi-50" id="basic_settings">
                    <h3 class="card-title">
                        Penawaran Ulang
                    </h3>
                    <div class="flex items-center gap-2">
                        <a href="{{ route('tender.penawaran.show', $noreg) }}" class="btn btn-xs btn-primary" title="Detail">
                            <i class="ki-outline ki-abstract-26"></i> Detail
                        </a>
                        <a href="{{ route('tender.penawaran.ulang.index') }}" class="btn btn-xs btn-info">
                            <i class="ki-filled ki-exit-left"></i> Back
                        </a>
                    </div>
                </div>
                <div class="card-body grid gap-5">
                    <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                        <label class="form-label max-w-56">
                            Nomor Registrasi
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <input class="flex w-full text-gray-600 font-medium text-sm input-custom" type="text"
                                name="nomor_registrasi" readonly value="{{ $permohonan->nomor_registrasi ?? '-' }}">
                        </div>
                    </div>
                    <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                        <label class="form-label max-w-56">
                            Nama KJPP Sebelumnya
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            @php
                                $nama_kjpp = $penawaran->nama_kjpp_sebelumnya;
                                $nama = explode(' - ', $nama_kjpp)[1] ?? '';
                            @endphp

                            <input class="flex w-full text-gray-600 font-medium text-sm input-custom" type="text"
                                name="nama_kjpp_sebelumnya" readonly value="{{ $nama !== null ? $nama : '' }}">
                        </div>
                    </div>
                    <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                        <label class="form-label max-w-56">
                            Biaya KJPP Sebelumnya
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <input type="hidden" name="biaya_kjpp_sebelumnya"
                                value="{{ $penawaran->biaya_kjpp_sebelumnya !== null ? $penawaran->biaya_kjpp_sebelumnya : '' }}">
                            <input class="flex w-full text-gray-600 font-medium text-sm input-custom" type="text" readonly
                                value="{{ $penawaran->biaya_kjpp_sebelumnya !== null ? formatRupiah($penawaran->biaya_kjpp_sebelumnya) : '' }}">
                        </div>
                        <label class="form-label max-w-56">
                            Tanggal Penilaian Sebelumnya
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <input class="flex w-full text-gray-600 font-medium text-sm input-custom" type="text"
                                name="tanggal_penilaian_sebelumnya" readonly
                                value="{{ $penawaran->tanggal_penilaian_sebelumnya !== null ? formatTanggalIndonesia($penawaran->tanggal_penilaian_sebelumnya) : '' }}">
                        </div>
                    </div>
                    <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                        <label class="form-label max-w-56">
                            Nomor Penawaran
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <input class="input border-warning bg-warning-light @error('code') border-danger  @enderror"
                                type="text" name="code" value="{{ old('code', $penawaran->code) }}" readonly>
                            @error('code')
                                <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">
                            Data KJPP
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <!-- Multi-select for KJPP -->
                            <select name="kjpp[]" multiple="multiple"
                                class="input tomselect w-full @error('kjpp') border-danger @enderror" id="kjpp_select">
                                <option value="">Pilih Nama KJPP</option>
                                @foreach ($kjpp as $row)
                                    @if ($row->status == 1)
                                        <option value="{{ $row->id }}"
                                            {{ in_array($row->id, old('kjpp', $kjpps ?? [])) ? 'selected' : '' }}>
                                            {{ $row->name }} | {{ $row->jenis_kantor }}
                                            @if($row->jenis_kantor == 'Kantor Cabang')
                                                {{ str_replace(['KOTA','KAB.','KAB'],'',$row->city->name) }}
                                            @endif
                                        </option>
                                    @endif
                                @endforeach
                            </select>
                            @error('kjpp')
                                <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">
                            Tujuan Penilaian KJPP
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <select id="tujuan_penilaian_kjpp_id"
                                class="select w-full @error('tujuan_penilaian_kjpp_id') border-danger  @enderror"
                                name="tujuan_penilaian_kjpp_id">
                                <option value="">Pilih Tujuan Penilaian KJPP</option>
                                @if (isset($tujuan_penilaian_kjpp))
                                    @foreach ($tujuan_penilaian_kjpp as $tp)
                                        <option value="{{ $tp->id }}"
                                            {{ old('tujuan_penilaian_kjpp_id', $penawaran->tujuan_penilaian_kjpp_id) == $tp->id ? 'selected' : '' }}>
                                            {{ $tp->name }}
                                        </option>
                                    @endforeach
                                @endif
                            </select>
                            @error('tujuan_penilaian_kjpp_id')
                                <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 Batas Waktu
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <input class="input  @error('start_date') border-danger  @enderror" type="date"
                                name="start_date" value="{{ old('start_date', $penawaran->start_date) }}">
                            @error('start_date')
                                <em class="alert text-danger text-sm">{{ $message }}</em>
                            @enderror
                        </div>
                        -
                        <div class="flex flex-wrap items-baseline w-full">
                            <input class="input @error('end_date') border-danger @enderror" type="date" name="end_date"
                                value="{{ old('end_date', $penawaran->end_date ? date('Y-m-d', strtotime($penawaran->end_date)) : '') }}">
                            @error('end_date')
                                <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
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <textarea class="textarea  @error('catatan') border-danger  @enderror" name="catatan" rows="3" id="address">{{ old('catatan', $penawaran->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">
                            Jenis Laporan
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <select id="jenis_laporan_id"
                                class="select w-full @error('jenis_laporan_id') border-danger  @enderror"
                                name="jenis_laporan_id">
                                <option value="">Pilih Jenis Laporan</option>
                                @if (isset($jenis_laporan))
                                    @foreach ($jenis_laporan as $jl)
                                        <option value="{{ $jl->id }}"
                                            {{ old('jenis_laporan_id', $penawaran->jenis_laporan_id) == $jl->id ? 'selected' : '' }}>
                                            {{ $jl->name }}
                                        </option>
                                    @endforeach
                                @endif
                            </select>
                            @error('jenis_laporan_id')
                                <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 status-custom">
                        <label class="form-label max-w-56">
                            Status
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <select class="select w-full @error('status') border-danger  @enderror" name="status">
                                <option value="">Pilih Status</option>
                                @if (isset($status))
                                    @foreach ($status as $s)
                                        <option value="{{ strtolower($s->name) }}"
                                            {{ $penawaran->status == strtolower($s->name) ? 'selected' : '' }}>
                                            {{ $s->name }}
                                        </option>
                                    @endforeach
                                @endif
                            </select>
                            @error('status')
                                <em class="alert text-danger text-sm">{{ $message }}</em>
                            @enderror
                        </div>
                    </div>

                    <div class="flex justify-end gap-1.5">
                        @if (isset($penawaran->nomor_registrasi))
                            <a href="{{ route('tender.penawaran.showSuratTender', $noreg) }}" class="btn btn-primary">
                                Surat Tender
                            </a>
                        @endif
                        <button type="submit" class="btn btn-primary">
                            Penawaran Ulang
                        </button>
                    </div>
                </div>
            </div>
        </form>
    </div>
@endsection

@push('styles')
    <style>
        input.input-custom:focus {
            outline: none;
            box-shadow: none;
        }

        @media (prefers-color-scheme: dark) {
            input.input-custom {
                background: none;
                color: var(--tw-gray-600);
            }
        }

        .status-custom {
            display: none
        }
    </style>
@endpush
