@php
    // $psections: 車種区分コレクション
    // $ptypes: 駐輪分類コレクション
    // $parkId: 駐輪場ID
    // $record: 編集用レコード（null = 新規）
    $selectedPsection = old('psection_id', $record->psection_id ?? null);
    $selectedPtype = old('ptype_id', $record->ptype_id ?? null);
    $regulationsText = old('regulations_text', $record->regulations_text ?? '');
@endphp

<input type="hidden" name="park_id" value="{{ $parkId }}">

<input type="hidden" name="park_id" value="{{ $parkId }}">

{{-- 駐輪場名（編集不可） --}}
<div class="mb-3 row">
    <label class="col-md-2 col-form-label font-weight-bold">駐輪場名</label>
    <div class="col-md-10">
        <input type="text"
               class="form-control"
               value="{{ $park->park_name }}"
               readonly>
    </div>
</div>
{{-- 車種区分 --}}
<div class="mb-3 row">
    <label class="col-md-2 col-form-label font-weight-bold">車種区分 <span class="text-danger">*</span></label>
    <div class="col-md-10">
        <select name="psection_id" class="form-control" required>
            <option value="">選択してください</option>
            @foreach($psections as $ps)
                <option value="{{ $ps->psection_id }}"
                    @selected($selectedPsection == $ps->psection_id)>
                    {{ $ps->psection_subject }}
                </option>
            @endforeach
        </select>
    </div>
</div>

{{-- 駐輪分類 --}}
<div class="mb-3 row">
    <label class="col-md-2 col-form-label font-weight-bold">駐輪分類 <span class="text-danger">*</span></label>
    <div class="col-md-10">
        <select name="ptype_id" class="form-control" required>
            <option value="">選択してください</option>
            @foreach($ptypes as $pt)
                <option value="{{ $pt->ptype_id }}"
                    @selected($selectedPtype == $pt->ptype_id)>
                    {{ $pt->ptype_subject }}
                </option>
            @endforeach
        </select>
    </div>
</div>

{{-- 駐輪規定 --}}
<div class="mb-3 row">
    <label class="col-md-2 col-form-label font-weight-bold">
        駐輪規定 <span class="text-danger">*</span>
    </label>
    <div class="col-md-10">
        <textarea name="regulations_text"
                  class="form-control js-summernote"
                  required>{!! $regulationsText !!}</textarea>
    </div>
</div>

<script>
document.addEventListener('DOMContentLoaded', function () {
    $('.js-summernote').summernote({
        height: 420,
        minHeight: 420,
        toolbar: [
            ['style', ['style']],
            ['font', ['bold', 'underline', 'italic', 'clear']],
            ['fontname', ['fontname']],
            ['color', ['color']],
            ['para', ['ul', 'ol', 'paragraph']],
            ['table', ['table']],
            ['insert', ['link', 'picture']],
            ['view', ['fullscreen', 'codeview', 'help']]
        ]
    });
});
</script>


