@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>
@elseif(Session::has('error'))
    <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>
        {!! Session::get('error') !!}
    </div>
@elseif(isset($errorMsg))
    <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>
        {!! $errorMsg !!}
    </div>
@endif

<div class="card-body">
    {{-- バリデーションエラー表示 --}}
    @if ($errors->any())
        <div class="alert alert-danger">
            <ul class="mb-0">
                @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
    @endif

    <div class="row">

        <!-- 駐車場所ID -->
        <div class="col-3">
            <label class="required">{{ __('駐車場所ID') }}</label>
        </div>
        <div class="form-group col-9">
            <div class="input-group">
                <input type="text"
                    name="price_parkplaceid"
                    value="{{ old('price_parkplaceid', $price_parkplaceid ?? '') }}"
                    class="form-control form-control-lg"
                    @if($isEdit) readonly @endif
                    placeholder="駐車場所ID" />
            </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="prine_name"
                    value="{{ old('prine_name', $prine_name ?? '') }}"
                    class="form-control form-control-lg"
                    placeholder="商品名" />
            </div>
        </div>

       <!-- 期間 -->
        <div class="form-group col-3">
            <label class="required">{{ __('期間') }}</label>
        </div>
        <div class="form-group col-9">
            <div class="input-group">
                <select name="price_month" class="form-control form-control-lg">
                    <option value="">{{ __('期間') }}</option>
                    @foreach(\App\Models\Price::PRICE_MONTH as $key => $item)
                        <option value="{{ $key }}" 
                            @if($key == old('price_month', $price_month ?? '')) selected @endif>
                            {{ $item }}
                        </option>
                    @endforeach
                </select>
            </div>
        </div>

        <!-- 駐輪場ID -->
        <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 $key => $item)
                        <option value="{{ $key }}" 
                            @if($key == old('park_id', $park_id ?? '')) selected @endif>
                            {{ $item }}
                        </option>
                    @endforeach
                </select>
            </div>
        </div>

       <!-- 車種区分名 -->
        <div class="form-group col-3">
            <label class="required">{{ __('車種区分名') }}</label>
        </div>
        <div class="form-group col-9">
            <div class="input-group">
                <select name="psection_id" class="form-control form-control-lg">
                    <option value="">{{ __('車種区分名') }}</option>
                    @foreach($psections as $key => $item)
                        <option value="{{ $key }}" 
                            @if($key == old('psection_id', $psection_id ?? '')) selected @endif>
                            {{ $item }}
                        </option>
                    @endforeach
                </select>
            </div>
        </div>

        <!-- 駐輪分類名 -->
        <div class="form-group col-3">
            <label class="required">{{ __('駐輪分類名') }}</label>
        </div>
        <div class="form-group col-9">
            <div class="input-group">
                <select name="price_ptypeid" class="form-control form-control-lg">
                    <option value="">{{ __('駐輪分類名') }}</option>
                    @foreach($ptypes as $key => $item)
                        <option value="{{ $key }}" 
                            @if($key == old('price_ptypeid', $price_ptypeid ?? '')) selected @endif>
                            {{ $item }}
                        </option>
                    @endforeach
                </select>
            </div>
        </div>
        <!-- 利用者分類 -->
        <div class="form-group col-3">
            <label class="required">{{ __('利用者分類') }}</label>
        </div>
        <div class="form-group col-9">
            <div class="input-group">
                <select name="user_categoryid" class="form-control form-control-lg">
                    <option value="">{{ __('利用者分類') }}</option>
                    @foreach($userTypes as $key => $item)
                        <option value="{{ $key }}" 
                            @if($key == old('user_categoryid', $user_categoryid ?? '')) selected @endif>
                            {{ $item }}
                        </option>
                    @endforeach
                </select>
            </div>
        </div>

    <!-- 駐車車室ID -->
    <div class="form-group col-3">
        <label class="required">{{ __('駐車車室ID') }}</label>
    </div>
    <div class="form-group col-9">
        <input type="text" 
            name="pplace_id" 
            value="{{ old('pplace_id', $pplace_id ?? '') }}" 
            class="form-control form-control-lg" 
            placeholder="駐車車室ID">

        @error('pplace_id')
            <div class="text-danger">{{ $message }}</div>
        @enderror
    </div>


        <!-- 駐輪料金（税込） -->
        <div class="form-group col-3">
            <label class="required">{{ __('駐輪料金（税込）') }}</label>
        </div>
        <div class="form-group col-9">
            <div class="input-group">
                <input type="number"
                    name="price"
                    value="{{ old('price', $price ?? '') }}"
                    class="form-control form-control-lg"
                    placeholder="駐輪料金（税込）"
                    step="1" min="0" required>
            </div>
        </div>
    </div>
       
    {{-- ▼ 下部ボタン --}}
    <div class="form-group col-12 d-flex gap-2 mt-4">
        {{-- 登録ボタン --}}
        <button type="submit" class="btn btn-lg btn-success mr-2">{{ __('登録') }}</button>

        {{-- 削除ボタン（編集画面のみ表示） --}}
        @if(!empty($price_parkplaceid))
        </form>
            <form method="POST" action="{{ route('prices_delete') }}" 
                onsubmit="return confirm('本当に削除しますか？')" class="d-inline-block mr-2">
                @csrf
                <input type="hidden" name="pk" value="{{ $price_parkplaceid }}">
                <button type="submit" class="btn btn-lg btn-danger mr-2">{{ __('削除') }}</button>
            </form>
        @endif
    </div>

</div>
<!-- /.card-body -->