@extends('layouts.app')
@section('title', '減免確認マスタ')

@section('content')
    <!-- Content Header -->
    <div class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-lg-6">
                    <h1 class="m-0 text-dark">減免確認マスタ</h1>
                </div>
                <div class="col-lg-6">
                    <ol class="breadcrumb float-sm-right text-sm">
                        <li class="breadcrumb-item"><a href="{{ route('home') }}">ホーム</a></li>
                        <li class="breadcrumb-item active">減免確認マスタ</li>
                    </ol>
                </div>
            </div>
        </div>
    </div>

    <section class="content">
        <div class="container-fluid">
            {{-- エラーメッセージ表示 --}}
            @if ($errors->any())
                <div class="alert alert-danger alert-dismissible fade show" role="alert">
                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    <h4 class="alert-heading">エラーが発生しました</h4>
                    <ul class="mb-0">
                        @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            @endif

            {{-- 成功メッセージ表示 --}}
            @if (session('success'))
                <div class="alert alert-success alert-dismissible fade show" role="alert">
                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    {{ session('success') }}
                </div>
            @endif

            <!-- 駐輪場情報カード -->
            <div class="col-lg-12 px-0">
                <div class="card">
                    <div class="card-header">
                        <h3 class="card-title">駐輪場情報</h3>
                    </div>
                    <div class="card-body">
                        <div class="row align-items-center">
                            <div class="col-md-2">
                                <label class="font-weight-bold mb-0">駐輪場名</label>
                            </div>
                            <div class="col-md-10">
                                <div class="park-name-display">
                                    {{ $park->park_name ?? '' }}
                                </div>
                            </div>
                        </div>
                    </div>

                </div>
            </div>


        </div>
        <!-- 減免確認マスタ テーブル -->
        <div class="col-lg-12 px-0 ">
            <form action="{{ route('reduction_confirm_store') }}" method="POST" id="reduction-form">
                <div class="d-flex justify-content-between align-items-center mb-2">
                    {{-- 左側：登録ボタン --}}
                    <button type="submit" class="btn btn-primary btn-submit">登録</button>

                    {{-- 右側：件数 + ページネーション --}}
                    <div class="text-right">
                        <div>
                            全 {{ $reductionData->total() }} 件中
                            {{ $reductionData->firstItem() }}〜{{ $reductionData->lastItem() }} 件を表示
                        </div>
                        <div>
                            {{ $reductionData->appends(keepUserListQuery())->links('pagination') }}
                        </div>
                    </div>
                </div>
        </div>
        @csrf
        <input type="hidden" name="park_id" value="{{ $parkId }}">
        <div class="table-responsive">
            <table class="table table-bordered">
                <thead class="thead-light">
                    <tr>
                        <th style="width: 5%; text-align: center;">利用者分類</th>
                        <th style="width: 10%;">分類名1</th>
                        <th style="width: 10%;">分類名2</th>
                        <th style="width: 10%;">分類名3</th>
                        <th style="width: 20%; text-align: center;">減免確認種別</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse ($reductionData as $row)
                        @include('admin.reduction_confirm._form', ['row' => $row, 'index' => $loop->index])
                    @empty
                        <tr>
                            <td colspan="5" class="text-center text-muted">
                                利用者分類がありません。
                            </td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        </form>
        </div>
    </section>

    <style>
        .gap-3 {
            gap: 1rem !important;
        }

        .custom-control {
            display: flex;
            align-items: center;
        }

        .custom-control-label {
            margin-bottom: 0;
            margin-left: 0.25rem;
        }

        .park-name-display {
            background-color: #e9ecef;
            border-radius: 6px;
            padding: 10px 14px;
            font-size: 16px;
            color: #6c757d;
            width: fit-content;
            min-width: 320px;
        }

        .sample03-wrapper {
            background-color: white;
        }
    </style>
@endsection
