@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">
        @if (isset($model->id))
            <form action="{{ route('basicdata.updateData', ['type' => $header[1], 'id' => $model->id]) }}" method="POST">
                <input type="hidden" name="id" value="{{ $model->id ?? '' }}">
                @method('PUT')
            @else
                <form method="POST" action="{{ route('basicdata.storeData', ['type' => $header[1]]) }}">
        @endif
        @csrf
        <div class="card border border-agi-100 pb-2.5">
            <input type="hidden" name="action" value="{{ $header[1] }}">
            <div class="card-header bg-agi-50" id="basic_settings">
                <h3 class="card-title">
                    {{ isset($jenisAset->id) ? 'Edit' : 'Tambah' }} {{ $header[0] }}
                </h3>
                <div class="flex items-center gap-2">
                    <a href="{{ route('basicdata.' . $header[1] . '.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">
                        Code
                    </label>
                    <div class="flex flex-wrap items-baseline w-full">
                        <input class="input  @error('code') border-danger bg-danger-light @enderror" type="text"
                            name="code" value="{{ $model->code ?? '' }}">
                        @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">
                        Name
                    </label>
                    <div class="flex flex-wrap items-baseline w-full">
                        <input class="input  @error('name') border-danger bg-danger-light @enderror" type="text"
                            name="name" value="{{ $model->name ?? '' }}">
                        @error('name')
                            <em class="alert text-danger text-sm">{{ $message }}</em>
                        @enderror
                    </div>
                </div>

                @if (isset($header[1]) && $header[1] == 'spek-bangunan')
                    <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                        <label class="form-label max-w-56">
                            Kategori
                        </label>
                        <div class="flex flex-wrap items-baseline w-full">
                            <select
                                class="input tomselect w-full @error('spek_kategori_bangunan_id') border-danger bg-danger-light  @enderror"
                                name="spek_kategori_bangunan_id">
                                <option value="">Select Kategori Bangunan</option>
                                @if (!empty($spekKategoriBagunan))
                                    @foreach ($spekKategoriBagunan as $item)
                                        <option value="{{ $item->id }}"
                                            @if (
                                                (isset($model->spek_kategori_bangunan_id) && $model->spek_kategori_bangunan_id == $item->id) ||
                                                    old('spek_kategori_bangunan_id') == $item->id) selected @endif>
                                            {{ $item->name }}
                                        </option>
                                    @endforeach
                                @endif
                            </select>
                            @error('spek_kategori_bangunan_id')
                                <em class="alert text-danger text-sm">{{ $message }}</em>
                            @enderror
                        </div>
                    </div>
                @endif

                @if (isset($header[1]) && $header[1] == 'foto-objek-jaminan')
                <div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
                    <label class="form-label max-w-56">Form Kategori</label>
                    <div class="flex flex-wrap items-baseline w-full">
                        <select
                            class="input tomselect w-full @error('kategori') border-danger bg-danger-light @enderror  select2"
                            name="kategori">

                            <option value="">Pilih Kategori</option>
                            @foreach (['tanah', 'bangunan', 'kapal', 'kendaraan', 'mesin', 'pesawat', 'alat-berat', 'apartemen-kantor'] as $item)
                                <option value="{{ $item }}"
                                    @if (isset($model) && $model->kategori == $item) {{ 'selected' }} @endif>
                                    {{ $item }}
                                </option>
                            @endforeach
                        </select>
                        @error('form_kategori')
                            <em class="alert text-danger text-sm">{{ $message }}</em>
                        @enderror
                    </div>
                </div>
                @endif


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