@extends('layouts.app')

@section('title', '市区マスタ')

@section('content')
    {{-- ▼ フラッシュメッセージ --}}
    @if(session('success'))
        <div class="alert alert-success">{{ session('success') }}</div>
    @endif
    @if(session('error'))
        <div class="alert alert-danger">{{ session('error') }}</div>
    @endif

    <!-- Content Header (Page 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="{{ url('/home') }}">ホーム</a></li>
                        <li class="breadcrumb-item active">市区マスタ</li>
                    </ol>
                </div>
            </div>
        </div>
    </div>

    <!-- Main content -->
    <section class="content">
        <div class="container-fluid">

            <!-- Action Buttons -->
            <div class="mb-3">
                <a href="{{ route('city_add') }}" class="btn btn-sm btn-primary">新規</a>
                <button type="submit" form="deleteForm" class="btn btn-sm btn-danger"
                    onclick="return confirm('選択した市区を削除しますか？');">削除</button>
            </div>

            @if ($list->count() > 0)
                <form id="deleteForm" method="POST" action="{{ route('city_delete') }}">
                    @csrf
                    <div class="table-responsive ">
                        <table class="table table-bordered table-hover" >
                            <thead class="thead-light ">
                                <tr>
                                    <th><input type="checkbox"
                                            onclick="$('input[name*=\'pk\']').prop('checked', this.checked);"></th>
                                    <th>
                                        <a href="{{ route('city', array_merge(request()->all(), ['sort' => 'city_id', 'sort_type' => $sort === 'city_id' && $sort_type === 'asc' ? 'desc' : 'asc'])) }}">
                                            市区ID
                                            @if($sort === 'city_id')
                                                <i class="fa fa-sort-{{ $sort_type }}"></i>
                                            @endif
                                        </a>
                                    </th>
                                    <th>
                                        <a href="{{ route('city', array_merge(request()->all(), ['sort' => 'city_name', 'sort_type' => $sort === 'city_name' && $sort_type === 'asc' ? 'desc' : 'asc'])) }}">
                                            市区名
                                            @if($sort === 'city_name')
                                                <i class="fa fa-sort-{{ $sort_type }}"></i>
                                            @endif
                                        </a>
                                    </th>
                                    <th>印字レイアウトファイル</th>
                                    <th>顧客M入力不要フィールドID</th>
                                    <th>備考</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach ($list as $city)
                                    <tr>
                                        <td style="background: #faebd7; width:100px; padding-right:4px; padding-left:4px;">
                                            <input type="checkbox" name="pk[]" value="{{ $city->city_id }}">
                                            <a href="{{ route('city_edit', ['id' => $city->city_id]) }}" class="btn btn-sm btn-default" style="margin-left:4px;">編集</a>
                                        </td>
                                        <td>{{ $city->city_id }}</td>
                                        <td>{{ $city->city_name }}</td>
                                        <td>{{ $city->print_layout }}</td>
                                        <td>{{ $city->city_user }}</td>
                                        <td>{{ $city->city_remarks }}</td>
                                    </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                </form>
                <div class="mt-3">
                    {{ $list->appends(request()->except('page'))->links('pagination::bootstrap-4') }}
                </div>
            @else
                <div class="alert alert-info mt-4">表示する市区データがありません。</div>
            @endif

        </div>
    </section>
@endsection