{{-- ===== エラーメッセージ ===== --}}
@if(Session::has('success'))
    <div class="alert alert-success alert-dismissible" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
        {{ Session::get('success') }}
    </div>
@endif

@if($errors->any())
    <div class="alert alert-danger alert-dismissible">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
        <h4><i class="icon fa fa-ban"></i> {{ __('入力内容に不備があります') }}:</h4>
        <ul>
            @foreach($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
@endif


{{-- ===== フォーム ===== --}}
<div class="card-body">
    <div class="row">

        @if(!empty($isEdit))
            {{-- デバイスID --}}
            <div class="form-group col-3">
                <label>{{ __('デバイスID') }}</label>
            </div>
            <div class="form-group col-9">
                <div class="input-group">
                    <input type="text"
                           value="{{ $device->device_id ?? '' }}"
                           class="form-control form-control-lg"
                           readonly/>
                </div>
            </div>
        @endif

        {{-- 駐輪場 --}}
        <div class="form-group col-3">
            <label class="required">{{ __('駐輪場') }}</label>
        </div>
        <div class="form-group col-9">
            <div class="input-group">
                <select name="park_id" class="form-control form-control-lg">
                    <option value="">{{ __('選択してください') }}</option>
                    @foreach($parks as $park)
                        <option value="{{ $park->park_id }}"
                            {{ old('park_id', $device->park_id ?? '') == $park->park_id ? 'selected' : '' }}>
                            {{ $park->park_name }}
                        </option>
                    @endforeach
                </select>
            </div>
        </div>


        
        {{-- デバイス種別 --}}
        <div class="form-group col-3">
            <label class="required">{{ __('デバイス種別') }}</label>
        </div>
        <div class="form-group col-9">
            <div class="row">
                @php $deviceType = old('device_type', $device->device_type ?? '1'); @endphp

                <div class="col-3 offset-1 form-check">
                    <input type="radio" class="minimal" name="device_type" id="device_type_server" value="1"
                        {{ $deviceType == '1' ? 'checked' : '' }}>
                    <label class="form-check-label" for="device_type_server">サーバー</label>
                </div>

                <div class="col-3 form-check">
                    <input type="radio" class="minimal" name="device_type" id="device_type_printer" value="2"
                        {{ $deviceType == '2' ? 'checked' : '' }}>
                    <label class="form-check-label" for="device_type_printer">プリンタ</label>
                </div>

                <div class="col-3 form-check">
                    <input type="radio" class="minimal" name="device_type" id="device_type_other" value="3"
                        {{ $deviceType == '3' ? 'checked' : '' }}>
                    <label class="form-check-label" for="device_type_other">その他</label>
                </div>
            </div>
        </div>



        {{-- デバイス名 --}}
        <div class="form-group col-3">
            <label class="required">{{ __('デバイス名') }}</label>
        </div>
        <div class="form-group col-9">
            <div class="input-group">
                <input type="text"
                       name="device_subject"
                       value="{{ old('device_subject', $device->device_subject ?? '') }}"
                       class="form-control form-control-lg"
                       placeholder="{{ __('validation.attributes.device_subject') }}">
            </div>
        </div>

        {{-- 識別子 --}}
        <div class="form-group col-3">
            <label class="required">{{ __('識別子') }}</label>
        </div>
        <div class="form-group col-9">
            <div class="input-group">
                <input type="text"
                       name="device_identifier"
                       value="{{ old('device_identifier', $device->device_identifier ?? '') }}"
                       class="form-control form-control-lg"
                       placeholder="{{ __('validation.attributes.device_identifier') }}">
            </div>
        </div>

        {{-- 稼働/停止 --}}
        <div class="form-group col-3">
            <label class="required">{{ __('稼働/停止') }}</label>
        </div>
        <div class="form-group col-9">
            <div class="row">
                @php $work = old('device_work', $device->device_work ?? '1'); @endphp

                <div class="col-3 offset-1 form-check">
                    <input type="radio" class="minimal" name="device_work" id="device_work_on" value="1"
                        {{ $work == '1' ? 'checked' : '' }}>
                    <label class="form-check-label" for="device_work_on">稼働</label>
                </div>

                <div class="col-3 form-check">
                    <input type="radio" class="minimal" name="device_work" id="device_work_off" value="0"
                        {{ $work == '0' ? 'checked' : '' }}>
                    <label class="form-check-label" for="device_work_off">停止</label>
                </div>
            </div>
        </div>


        {{-- 稼働開始日 --}}
        <div class="form-group col-3">
            <label class="required">{{ __('稼働開始日') }}</label>
        </div>
        <div class="form-group col-9">
            <div class="input-group">
                <input type="date"
                       name="device_workstart"
                       value="{{ old('device_workstart', optional($device->device_workstart)->toDateString()) }}"
                       class="form-control form-control-lg">
            </div>
        </div>

        {{-- リプレース予約日 --}}
        <div class="form-group col-3">
            <label>{{ __('リプレース予約日') }}</label>
        </div>
        <div class="form-group col-9">
            <div class="input-group">
                <input type="date"
                       name="device_replace"
                       value="{{ old('device_replace', optional($device->device_replace)->toDateString() ?? '') }}"
                       class="form-control form-control-lg">
            </div>
        </div>

        {{-- 備考 --}}
        <div class="form-group col-3">
            <label>{{ __('備考') }}</label>
        </div>
        <div class="form-group col-9">
            <div class="input-group">
                <input type="text"
                       name="device_remarks"
                       value="{{ old('device_remarks', $device->device_remarks ?? '') }}"
                       class="form-control form-control-lg"
                       maxlength="255"
                       placeholder="{{ __('validation.attributes.device_remarks') }}">
            </div>
        </div>

    </div>
    {{-- ▼ 下部ボタン --}}
    <div class="row mt-4">
        <div class="form-group col-md-10 d-flex align-items-center gap-2 justify-content-start">

            {{-- 登録ボタン --}}
            @if($isEdit)
                <button type="button" id="register_edit" class="btn btn-lg btn-success mr-2">
                    {{ __('登録') }}
                </button>
            @else
                <button type="submit" id="register" class="btn btn-lg btn-success mr-2 register">
                    {{ __('登録') }}
                </button>
            @endif

            {{-- 削除ボタン（編集時のみ表示） --}}
            @if($isEdit)
                <button type="button" id="delete_edit" class="btn btn-lg btn-danger">
                    {{ __('削除') }}
                </button>
            @endif

        </div>
    </div>
</div>