@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">
        <form action="{{ isset($kjpp->id) ? route('basicdata.kjpp.update', $kjpp->id) : route('basicdata.kjpp.store') }}"
            method="POST" enctype="multipart/form-data">
            @if (isset($kjpp->id))
                <input type="hidden" name="id" value="{{ $kjpp->id }}">
                @method('PUT')
            @endif
            @csrf

            <div class="card border border-agi-100 pb-2.5">
                <div class="card-header bg-agi-50" id="basic_settings">
                    <h3 class="card-title">
                        {{ isset($kjpp->id) ? 'Edit' : 'Tambah' }} KJPP
                    </h3>
                    <div class="flex items-center gap-2">
                        <a href="{{ route('basicdata.kjpp.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 KJPP
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <input class="input  @error('code') border-danger  @enderror" type="text" name="code"
                                value="{{ isset($kjpp->id) ? $kjpp->code : (empty($kjpp->id) ? $fullKjppNumber : old('code')) }}">
                            @error('code')
                                <em class="alert text-danger text-sm">{{ $message }}</em>
                            @enderror
                        </div>
                        <label class="form-label max-w-56">
                            Nama KJPP
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <input class="input  @error('name') border-danger  @enderror" type="text" name="name"
                                value="{{ $kjpp->name ?? old('name') }}">
                            @error('name')
                                <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 Kantor</label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <select id="jenis_kantor" class="select w-full @error('jenis_kantor') border-danger  @enderror"
                                name="jenis_kantor">
                                @if (isset($kjpp->id))
                                    <option value="">Pilih Jenis Kantor</option>
                                    <option value="Kantor Pusat"
                                        {{ old('jenis_kantor', $kjpp->jenis_kantor) == 'Kantor Pusat' ? 'selected' : '' }}>
                                        Kantor Pusat
                                    </option>
                                    <option value="Kantor Cabang"
                                        {{ old('jenis_kantor', $kjpp->jenis_kantor) == 'Kantor Cabang' ? 'selected' : '' }}>
                                        Kantor Cabang
                                    </option>
                                @else
                                    <option value="">Pilih Jenis Kantor</option>
                                    <option value="Kantor Pusat"
                                        {{ old('jenis_kantor') == 'Kantor Pusat' ? 'selected' : '' }}>Kantor Pusat
                                    </option>
                                    <option value="Kantor Cabang"
                                        {{ old('jenis_kantor') == 'Kantor Cabang' ? 'selected' : '' }}>Kantor
                                        Cabang
                                    </option>
                                @endif
                            </select>
                            @error('jenis_kantor')
                                <em class="alert text-danger text-sm">{{ $message }}</em>
                            @enderror
                        </div>
                        <label class="form-label max-w-56">Nomor Ijin Usaha</label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <input class="input  @error('nomor_ijin_usaha') border-danger  @enderror" type="text"
                                name="nomor_ijin_usaha" value="{{ $kjpp->nomor_ijin_usaha ?? old('nomor_ijin_usaha') }}">
                            @error('nomor_ijin_usaha')
                                <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">
                            Alamat Kantor
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <div class="flex flex-col lg:flex-row gap-2 w-full">
                                <div class="flex flex-wrap items-baseline w-full">
                                    <select id="province_code" name="province_code"
                                        class="select w-full @error('province_code') border-danger  @enderror">
                                        <option value="">Pilih Provinsi</option>
                                        @foreach ($provinces as $province)
                                            @if (isset($kjpp))
                                                <option value="{{ $province->code }}"
                                                    {{ old('province_code', $kjpp->province_code) == $province->code ? 'selected' : '' }}>
                                                    {{ $province->name }}
                                                </option>
                                            @else
                                                <option value="{{ $province->code }}"
                                                    {{ old('province_code') == $province->code ? 'selected' : '' }}>
                                                    {{ $province->name }}
                                                </option>
                                            @endif
                                        @endforeach
                                    </select>
                                    @error('province_code')
                                        <em class="alert text-danger text-sm">{{ $message }}</em>
                                    @enderror
                                </div>
                                <div class="flex flex-wrap items-baseline w-full">
                                    <select id="city_code" name="city_code"
                                        class="select w-full @error('city_code') border-danger  @enderror">
                                        <option value="">Pilih Kota / Kabupaten</option>
                                        @if (isset($cities))
                                            @foreach ($cities as $city)
                                                @if (isset($kjpp))
                                                    <option value="{{ $city->code }}"
                                                        {{ old('city_code', $kjpp->city_code) == $city->code ? 'selected' : '' }}>
                                                        {{ $city->name }}
                                                    </option>
                                                @else
                                                    <option value="{{ $city->code }}"
                                                        {{ old('city_code') == $city->code ? 'selected' : '' }}>
                                                        {{ $city->name }}
                                                    </option>
                                                @endif
                                            @endforeach
                                        @endif
                                    </select>
                                    @error('city_code')
                                        <em class="alert text-danger text-sm">{{ $message }}</em>
                                    @enderror
                                </div>
                            </div>
                            <div class="flex flex-col lg:flex-row gap-2 w-full mt-2 lg:mt-5">
                                <div class="flex flex-wrap items-baseline w-full">
                                    <select id="district_code" name="district_code"
                                        class="select w-full @error('district_code') border-danger  @enderror">
                                        <option value="">Pilih Kecamatan</option>
                                        @if (isset($districts))
                                            @foreach ($districts as $district)
                                                @if (isset($kjpp))
                                                    <option value="{{ $district->code }}"
                                                        {{ old('district_code', $kjpp->district_code) == $district->code ? 'selected' : '' }}>
                                                        {{ $district->name }}
                                                    </option>
                                                @else
                                                    <option value="{{ $district->code }}"
                                                        {{ old('district_code') == $district->code ? 'selected' : '' }}>
                                                        {{ $district->name }}
                                                    </option>
                                                @endif
                                            @endforeach
                                        @endif
                                    </select>
                                    @error('district_code')
                                        <em class="alert text-danger text-sm">{{ $message }}</em>
                                    @enderror
                                </div>
                                <div class="flex flex-wrap items-baseline w-full">
                                    <select id="village_code" name="village_code"
                                        class="select w-full @error('village_code') border-danger  @enderror">
                                        <option value="">Pilih Kelurahan</option>
                                        @if (isset($villages))
                                            @foreach ($villages as $village)
                                                @if (isset($kjpp))
                                                    <option value="{{ $village->code }}"
                                                        {{ old('village_code', $kjpp->village_code) == $village->code ? 'selected' : '' }}>
                                                        {{ $village->name }}
                                                    </option>
                                                @else
                                                    <option value="{{ $village->code }}"
                                                        {{ old('village_code') == $village->code ? 'selected' : '' }}>
                                                        {{ $village->name }}
                                                    </option>
                                                @endif
                                            @endforeach
                                        @endif
                                    </select>
                                    @error('village_code')
                                        <em class="alert text-danger text-sm">{{ $message }}</em>
                                    @enderror
                                </div>
                                <div class="flex flex-wrap items-baseline w-full">
                                    <input class="input  @error('postal_code') border-danger  @enderror" type="number"
                                        id="postal_code" name="postal_code"
                                        value="{{ $kjpp->postal_code ?? old('postal_code') }}" placeholder="Kode Pos">
                                    @error('postal_code')
                                        <em class="alert text-danger text-sm">{{ $message }}</em>
                                    @enderror
                                </div>
                            </div>
                            <div class="flex flex-col w-full mt-2 lg:mt-5">
                                <textarea class="textarea  @error('address') border-danger  @enderror" rows="3" type="number" id="address"
                                    name="address">{{ $kjpp->address ?? old('address') }}</textarea>
                                @error('address')
                                    <em class="alert text-danger text-sm">{{ $message }}</em>
                                @enderror
                            </div>
                        </div>
                    </div>
                    <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                        <label class="form-label max-w-56">
                            Nomor Telepon Kantor
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <input class="input  @error('nomor_telepon_kantor') border-danger  @enderror" type="text"
                                name="nomor_telepon_kantor"
                                value="{{ $kjpp->nomor_telepon_kantor ?? old('nomor_telepon_kantor') }}">
                            @error('nomor_telepon_kantor')
                                <em class="alert text-danger text-sm">{{ $message }}</em>
                            @enderror
                        </div>
                        <label class="form-label max-w-56">
                            Email Kantor
                        </label>
                        <div class="flex flex-wrap items-baseline w-full gap-1.5">
                            <input class="input  @error('email_kantor') border-danger  @enderror" type="text"
                                name="email_kantor" value="{{ $kjpp->email_kantor ?? old('email_kantor') }}">
                            @error('email_kantor')
                                <em class="alert text-danger text-sm">{{ $message }}</em>
                            @enderror
                            <div id="detail_email_kantor" class="flex flex-wrap items-center w-full gap-2">
                                @php
                                    $emails = old(
                                        'detail_email_kantor.email_kantor',
                                        json_decode($detailJoinEmailKantor, true),
                                    ); // Decode as associative array
                                @endphp

                                @if (is_array($emails) && count($emails) > 0)
                                    @foreach ($emails as $index => $email)
                                        @if (!empty($email))
                                            <div
                                                class="flex flex-col lg:flex-row gap-2 items-baseline lg:items-center w-full">
                                                <div class="flex flex-wrap items-baseline w-full">
                                                    <input
                                                        class="input @error('detail_email_kantor.email_kantor.' . $index) border-danger @enderror"
                                                        type="text" name="detail_email_kantor[email_kantor][]"
                                                        value="{{ old('detail_email_kantor.email_kantor.' . $index, is_array($email) ? $email['email_kantor'] : $email->email_kantor ?? '') }}">
                                                    @error('detail_email_kantor.email_kantor.' . $index)
                                                        <em class="alert text-danger text-sm">{{ $message }}</em>
                                                    @enderror
                                                </div>
                                                <button type="button" class="btn btn-danger btn-xs delete-button-edit">
                                                    Hapus
                                                </button>
                                            </div>
                                        @endif
                                    @endforeach
                                @endif
                            </div>
                            <button type="button" id="tambah_email_kantor" class="btn btn-primary btn-xs">Tambah
                                Email Kantor</button>
                        </div>
                    </div>
                    <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                        <label class="form-label max-w-56">
                            Nama Pimpinan
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <input class="input  @error('nama_pimpinan') border-danger  @enderror" type="text"
                                name="nama_pimpinan" value="{{ $kjpp->nama_pimpinan ?? old('nama_pimpinan') }}">
                            @error('nama_pimpinan')
                                <em class="alert text-danger text-sm">{{ $message }}</em>
                            @enderror
                        </div>
                        <label class="form-label max-w-56">
                            Nomor HP Pimpinan
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <input class="input  @error('nomor_hp_pimpinan') border-danger  @enderror" type="text"
                                name="nomor_hp_pimpinan"
                                value="{{ $kjpp->nomor_hp_pimpinan ?? old('nomor_hp_pimpinan') }}">
                            @error('nomor_hp_pimpinan')
                                <em class="alert text-danger text-sm">{{ $message }}</em>
                            @enderror
                        </div>
                    </div>
                    <div class="flex items-baseline flex-wrap lg:flex-nowrap">
                        <div id="detail_nama_pimpinan" class="flex flex-wrap items-baseline w-full gap-2.5">
                            @php
                                $detailNamaPimpinan = old(
                                    'detail_nama_pimpinan.nama_pimpinan',
                                    json_decode($detailJoinPimpinan, true),
                                );
                                $detailNomorHpPimpinan = old(
                                    'detail_nomor_hp_pimpinan.nomor_hp_pimpinan',
                                    json_decode($detailJoinPimpinan, true),
                                );
                            @endphp

                            @if (is_array($detailNamaPimpinan) &&
                                    count($detailNamaPimpinan) > 0 &&
                                    (is_array($detailNomorHpPimpinan) && count($detailNomorHpPimpinan) > 0))
                                @foreach ($detailNamaPimpinan as $index => $detail_nama)
                                    @if (!empty($detail_nama))
                                        <div class="flex flex-col lg:flex-row gap-2 items-baseline lg:items-center w-full">
                                            <label class="form-label max-w-56">Nama Pimpinan</label>
                                            <div class="flex flex-wrap items-baseline w-full">
                                                <input
                                                    class="input @error('detail_nama_pimpinan.nama_pimpinan.' . $index) border-danger @enderror"
                                                    type="text" name="detail_nama_pimpinan[nama_pimpinan][]"
                                                    value="{{ old('detail_nama_pimpinan.nama_pimpinan.' . $index, $detail_nama['nama_pimpinan'] ?? '') }}">
                                                @error('detail_nama_pimpinan.nama_pimpinan.' . $index)
                                                    <em class="alert text-danger text-sm">{{ $message }}</em>
                                                @enderror
                                            </div>

                                            <label class="form-label max-w-56">Nomor HP Pimpinan</label>
                                            <div class="flex flex-wrap items-baseline w-full">
                                                <input
                                                    class="input @error('detail_nomor_hp_pimpinan.nomor_hp_pimpinan.' . $index) border-danger @enderror"
                                                    type="text" name="detail_nomor_hp_pimpinan[nomor_hp_pimpinan][]"
                                                    value="{{ old('detail_nomor_hp_pimpinan.nomor_hp_pimpinan.' . $index, $detailNomorHpPimpinan[$index]['nomor_hp_pimpinan'] ?? '') }}">
                                                @error('detail_nomor_hp_pimpinan.nomor_hp_pimpinan.' . $index)
                                                    <em class="alert text-danger text-sm">{{ $message }}</em>
                                                @enderror
                                            </div>

                                            <button type="button" class="btn btn-danger btn-xs delete-button-edit">
                                                Hapus
                                            </button>
                                        </div>
                                    @endif
                                @endforeach
                            @endif
                        </div>
                    </div>
                    <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                        <label class="form-label max-w-56">
                            &nbsp;
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <button type="button" id="tambah_nama_pimpinan" class="btn btn-primary btn-xs">Tambah
                                Pimpinan</button>
                        </div>
                    </div>
                    <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                        <label class="form-label max-w-56">
                            Nama PIC Reviewer
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <input class="input  @error('nama_pic_reviewer') border-danger  @enderror" type="text"
                                name="nama_pic_reviewer"
                                value="{{ $kjpp->nama_pic_reviewer ?? old('nama_pic_reviewer') }}">
                            @error('nama_pic_reviewer')
                                <em class="alert text-danger text-sm">{{ $message }}</em>
                            @enderror
                        </div>
                        <label class="form-label max-w-56">
                            Nomor HP PIC Reviewer
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <input class="input  @error('nomor_hp_pic_reviewer') border-danger  @enderror" type="text"
                                name="nomor_hp_pic_reviewer"
                                value="{{ $kjpp->nomor_hp_pic_reviewer ?? old('nomor_hp_pic_reviewer') }}">
                            @error('nomor_hp_pic_reviewer')
                                <em class="alert text-danger text-sm">{{ $message }}</em>
                            @enderror
                        </div>
                    </div>
                    <div class="flex items-baseline flex-wrap lg:flex-nowrap">
                        <div id="detail_nama_pic_reviewer" class="flex flex-wrap items-baseline w-full gap-2.5">
                            @php
                                $detailNamaPicReviewer = old(
                                    'detail_nama_pic_reviewer.nama_pic_reviewer',
                                    json_decode($detailJoinPicReviewer, true),
                                );
                                $detailNomorHpPicReviewer = old(
                                    'detail_nomor_hp_pic_reviewer.nomor_hp_pic_reviewer',
                                    json_decode($detailJoinPicReviewer, true),
                                );
                            @endphp

                            @if (is_array($detailNamaPicReviewer) &&
                                    count($detailNamaPicReviewer) > 0 &&
                                    is_array($detailNomorHpPicReviewer) &&
                                    count($detailNomorHpPicReviewer) > 0)
                                @foreach ($detailNamaPicReviewer as $index => $detail_pic_reviewer)
                                    @if (!empty($detail_pic_reviewer))
                                        <div class="flex flex-col lg:flex-row gap-2 items-baseline lg:items-center w-full">
                                            <label class="form-label max-w-56">Nama PIC Reviewer</label>
                                            <div class="flex flex-wrap items-baseline w-full">
                                                <input
                                                    class="input @error('detail_nama_pic_reviewer.nama_pic_reviewer.' . $index) border-danger @enderror"
                                                    type="text" name="detail_nama_pic_reviewer[nama_pic_reviewer][]"
                                                    value="{{ old('detail_nama_pic_reviewer.nama_pic_reviewer.' . $index, $detail_pic_reviewer['nama_pic_reviewer'] ?? '') }}">
                                                @error('detail_nama_pic_reviewer.nama_pic_reviewer.' . $index)
                                                    <em class="alert text-danger text-sm">{{ $message }}</em>
                                                @enderror
                                            </div>

                                            <label class="form-label max-w-56">Nomor HP PIC Reviewer</label>
                                            <div class="flex flex-wrap items-baseline w-full">
                                                <input
                                                    class="input @error('detail_nomor_hp_pic_reviewer.nomor_hp_pic_reviewer.' . $index) border-danger @enderror"
                                                    type="text"
                                                    name="detail_nomor_hp_pic_reviewer[nomor_hp_pic_reviewer][]"
                                                    value="{{ old('detail_nomor_hp_pic_reviewer.nomor_hp_pic_reviewer.' . $index, $detailNomorHpPicReviewer[$index]['nomor_hp_pic_reviewer'] ?? '') }}">
                                                @error('detail_nomor_hp_pic_reviewer.nomor_hp_pic_reviewer.' . $index)
                                                    <em class="alert text-danger text-sm">{{ $message }}</em>
                                                @enderror
                                            </div>

                                            <button type="button" class="btn btn-danger btn-xs delete-button-edit">
                                                Hapus
                                            </button>
                                        </div>
                                    @endif
                                @endforeach
                            @endif
                        </div>
                    </div>
                    <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                        <label class="form-label max-w-56">
                            &nbsp;
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <button type="button" id="tambah_nama_pic_reviewer" class="btn btn-primary btn-xs">Tambah
                                PIC Reviewer</button>
                        </div>
                    </div>
                    <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                        <label class="form-label max-w-56">
                            Nama PIC Admin
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <input class="input  @error('nama_pic_admin') border-danger  @enderror" type="text"
                                name="nama_pic_admin" value="{{ $kjpp->nama_pic_admin ?? old('nama_pic_admin') }}">
                            @error('nama_pic_admin')
                                <em class="alert text-danger text-sm">{{ $message }}</em>
                            @enderror
                        </div>
                        <label class="form-label max-w-56">
                            Nomor HP PIC Admin
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <input class="input  @error('nomor_hp_pic_admin') border-danger  @enderror" type="text"
                                name="nomor_hp_pic_admin"
                                value="{{ $kjpp->nomor_hp_pic_admin ?? old('nomor_hp_pic_admin') }}">
                            @error('nomor_hp_pic_admin')
                                <em class="alert text-danger text-sm">{{ $message }}</em>
                            @enderror
                        </div>
                    </div>
                    <div class="flex items-baseline flex-wrap lg:flex-nowrap">
                        <div id="detail_nama_pic_admin" class="flex flex-wrap items-baseline w-full gap-2.5">
                            @php
                                $detailNamaPicAdmin = old(
                                    'detail_nama_pic_admin.nama_pic_admin',
                                    json_decode($detailJoinPicAdmin, true),
                                );
                                $detailNomorHpPicAdmin = old(
                                    'detail_nomor_hp_pic_admin.nomor_hp_pic_admin',
                                    json_decode($detailJoinPicAdmin, true),
                                );
                            @endphp

                            @if (is_array($detailNamaPicAdmin) &&
                                    count($detailNamaPicAdmin) > 0 &&
                                    is_array($detailNomorHpPicAdmin) &&
                                    count($detailNomorHpPicAdmin) > 0)
                                @foreach ($detailNamaPicAdmin as $index => $detail_pic_admin)
                                    @if (!empty($detail_pic_admin))
                                        <div class="flex flex-col lg:flex-row gap-2 items-baseline lg:items-center w-full">
                                            <label class="form-label max-w-56">Nama PIC Admin</label>
                                            <div class="flex flex-wrap items-baseline w-full">
                                                <input
                                                    class="input @error('detail_nama_pic_admin.nama_pic_admin.' . $index) border-danger @enderror"
                                                    type="text" name="detail_nama_pic_admin[nama_pic_admin][]"
                                                    value="{{ old('detail_nama_pic_admin.nama_pic_admin.' . $index, $detail_pic_admin['nama_pic_admin'] ?? '') }}">
                                                @error('detail_nama_pic_admin.nama_pic_admin.' . $index)
                                                    <em class="alert text-danger text-sm">{{ $message }}</em>
                                                @enderror
                                            </div>

                                            <label class="form-label max-w-56">Nomor HP PIC Admin</label>
                                            <div class="flex flex-wrap items-baseline w-full">
                                                <input
                                                    class="input @error('detail_nomor_hp_pic_admin.nomor_hp_pic_admin.' . $index) border-danger @enderror"
                                                    type="text" name="detail_nomor_hp_pic_admin[nomor_hp_pic_admin][]"
                                                    value="{{ old('detail_nomor_hp_pic_admin.nomor_hp_pic_admin.' . $index, $detailNomorHpPicAdmin[$index]['nomor_hp_pic_admin'] ?? '') }}">
                                                @error('detail_nomor_hp_pic_admin.nomor_hp_pic_admin.' . $index)
                                                    <em class="alert text-danger text-sm">{{ $message }}</em>
                                                @enderror
                                            </div>

                                            <button type="button" class="btn btn-danger btn-xs delete-button-edit">
                                                Hapus
                                            </button>
                                        </div>
                                    @endif
                                @endforeach
                            @endif
                        </div>
                    </div>
                    <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                        <label class="form-label max-w-56">
                            &nbsp;
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <button type="button" id="tambah_nama_pic_admin" class="btn btn-primary btn-xs">Tambah
                                PIC Admin</button>
                        </div>
                    </div>
                    <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                        <label class="form-label max-w-56">
                            Nama PIC Marketing
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <input class="input  @error('nama_pic_marketing') border-danger  @enderror" type="text"
                                name="nama_pic_marketing"
                                value="{{ $kjpp->nama_pic_marketing ?? old('nama_pic_marketing') }}">
                            @error('nama_pic_marketing')
                                <em class="alert text-danger text-sm">{{ $message }}</em>
                            @enderror
                        </div>
                        <label class="form-label max-w-56">
                            Nomor HP PIC Marketing
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <input class="input  @error('nomor_hp_pic_marketing') border-danger  @enderror"
                                type="text" name="nomor_hp_pic_marketing"
                                value="{{ $kjpp->nomor_hp_pic_marketing ?? old('nomor_hp_pic_marketing') }}">
                            @error('nomor_hp_pic_marketing')
                                <em class="alert text-danger text-sm">{{ $message }}</em>
                            @enderror
                        </div>
                    </div>
                    <div class="flex items-baseline flex-wrap lg:flex-nowrap">
                        <div id="detail_nama_pic_marketing" class="flex flex-wrap items-baseline w-full gap-2.5">
                            @php
                                $detailNamaPicMarketing = old(
                                    'detail_nama_pic_marketing.nama_pic_marketing',
                                    json_decode($detailJoinPicMarketing, true),
                                );
                                $detailNomorHpPicMarketing = old(
                                    'detail_nomor_hp_pic_marketing.nomor_hp_pic_marketing',
                                    json_decode($detailJoinPicMarketing, true),
                                );
                            @endphp

                            @if (is_array($detailNamaPicMarketing) &&
                                    count($detailNamaPicMarketing) > 0 &&
                                    is_array($detailNomorHpPicMarketing) &&
                                    count($detailNomorHpPicMarketing) > 0)
                                @foreach ($detailNamaPicMarketing as $index => $detail_pic_marketing)
                                    @if (!empty($detail_pic_marketing))
                                        <div class="flex flex-col lg:flex-row gap-2 items-baseline lg:items-center w-full">
                                            <label class="form-label max-w-56">Nama PIC Marketing</label>
                                            <div class="flex flex-wrap items-baseline w-full">
                                                <input
                                                    class="input @error('detail_nama_pic_marketing.nama_pic_marketing.' . $index) border-danger @enderror"
                                                    type="text" name="detail_nama_pic_marketing[nama_pic_marketing][]"
                                                    value="{{ old('detail_nama_pic_marketing.nama_pic_marketing.' . $index, $detail_pic_marketing['nama_pic_marketing'] ?? '') }}">
                                                @error('detail_nama_pic_marketing.nama_pic_marketing.' . $index)
                                                    <em class="alert text-danger text-sm">{{ $message }}</em>
                                                @enderror
                                            </div>

                                            <label class="form-label max-w-56">Nomor HP PIC Marketing</label>
                                            <div class="flex flex-wrap items-baseline w-full">
                                                <input
                                                    class="input @error('detail_nomor_hp_pic_marketing.nomor_hp_pic_marketing.' . $index) border-danger @enderror"
                                                    type="text"
                                                    name="detail_nomor_hp_pic_marketing[nomor_hp_pic_marketing][]"
                                                    value="{{ old('detail_nomor_hp_pic_marketing.nomor_hp_pic_marketing.' . $index, $detailNomorHpPicMarketing[$index]['nomor_hp_pic_marketing'] ?? '') }}">
                                                @error('detail_nomor_hp_pic_marketing.nomor_hp_pic_marketing.' . $index)
                                                    <em class="alert text-danger text-sm">{{ $message }}</em>
                                                @enderror
                                            </div>

                                            <button type="button" class="btn btn-danger btn-xs delete-button-edit">
                                                Hapus
                                            </button>
                                        </div>
                                    @endif
                                @endforeach
                            @endif
                        </div>
                    </div>
                    <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                        <label class="form-label max-w-56">
                            &nbsp;
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <button type="button" id="tambah_nama_pic_marketing" class="btn btn-primary btn-xs">Tambah
                                PIC Marketing</button>
                        </div>
                    </div>
                    <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                        <label class="form-label max-w-56">
                            Ijin Usaha
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <select name="ijin_usaha_id[]" multiple="multiple"
                                class="input tomselect w-full @error('ijin_usaha_id') border-danger @enderror"
                                id="ijin_usaha_select">
                                <option value="">Pilih Ijin Usaha</option>
                                @foreach ($ijin_usaha as $row)
                                    <option value="{{ $row->code }}"
                                        {{ isset($kjpp->ijin_usaha_id) ? (in_array($row->code, old('ijin_usaha_id', json_decode($kjpp->ijin_usaha_id, true))) ? 'selected' : '') : (in_array($row->code, old('ijin_usaha_id', [])) ? 'selected' : '') }}>
                                        {{ $row->name }}
                                    </option>
                                @endforeach
                            </select>
                            @error('ijin_usaha_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">
                            Pengalaman (Jenis Aset)
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <select name="jenis_aset_id[]" multiple="multiple"
                                class="input tomselect w-full @error('jenis_aset_id') border-danger @enderror"
                                id="jenis_aset_select">
                                <option value="">Pilih Jenis Aset</option>
                                @foreach ($jenis_aset as $row)
                                    <option value="{{ $row->code }}"
                                        {{ in_array($row->code, old('jenis_aset_id', json_decode($kjpp->jenis_aset_id ?? '[]', true))) ? 'selected' : '' }}>
                                        {{ $row->name }}
                                    </option>
                                @endforeach
                            </select>
                            @error('jenis_aset_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">
                            Attachment
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            @if (isset($kjpp) && $kjpp->attachment)
                                <div class="mb-2">
                                    <p class="flex w-full text-gray-600 font-medium text-sm">Lihat File:</p>
                                    <a href="{{ asset('storage/uploads_pdf/' . $kjpp->attachment) }}"
                                        class="btn btn-link" target="_blank">
                                        {{ $kjpp->attachment }}
                                    </a>
                                </div>
                            @endif
                            <input class="file-input @error('attachment') border-danger @enderror" name="attachment"
                                type="file" />
                            @error('attachment')
                                <em class="alert text-danger text-sm">{{ $message }}</em>
                            @enderror
                        </div>
                    </div>
                    <div class="flex justify-end">
                        <button type="submit" class="btn btn-primary">
                            Save
                        </button>
                    </div>
                </div>
            </div>
        </form>
    </div>
@endsection

@include('lpj::kjpp.scripts.index')
