@extends('layouts.app')
@section('title', '駐輪車室マスタ')
@section('content')
<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">

            <form action="{{route('pplaces')}}" method='post' id='list-form'>
                @csrf
                <input type="hidden" value="{{$sort}}" name="sort" id="sort">
                <input type="hidden" value="{{$sort_type}}" name="sort_type" id="sort_type">
            </form>

            {{-- ▼ アクションボタン --}}
            <div class="mb-3">
                <a href="{{ route('pplaces_add') }}" class="btn btn-sm btn-default mr10">新規</a>
                <button type="button" class="btn btn-sm btn-default mr10" id="delete">削除</button>
                <button type="submit" class="btn btn-sm btn-default mr10" name="export_csv" id="export_csv" action="{{route('pplaces_export')}}">{{__('CSV出力')}}</button>
            </div>

            {{-- ▼ ページネーション --}}
            <div class="container-fluid">
                <div class="d-flex justify-content-end mb-3">
                    {{ $list->appends([
                        'sort'      => $sort ?? '',
                        'sort_type' => $sort_type ?? ''
                    ])->links('pagination') }}
                </div>
            </div>

            <div class="form col-lg-12">
                @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>

            <form action="{{route('pplaces_delete')}}" method="post" id="form_delete">
                @csrf
                <!-- ▼ ここから単一テーブル構成 ----------------------------------------- -->
                <div class="col-lg-12 mb20">
                    <div class="table-responsive">
                        <table class="table table-bordered dataTable text-nowrap">
                            <thead class="thead-light">
                                <tr>
                                    <th style="width:140px; border-left:1px solid #dcdcdc;" class="text-left">
                                        <input type="checkbox" onclick="$('input[name*=\'pk\']').prop('checked', this.checked);">
                                    </th>
                                    <th class="sorting @if($sort=='pplace_id'){{$sort_type == 'asc'?'sorting_asc':'sorting_desc'}}@endif" sort="pplace_id">
                                        <span>{{__('駐輪車室ID')}}</span>
                                    </th>
                                    <th>
                                        <span>{{__('駐輪車室番号')}}</span>
                                    </th>
                                    <th>
                                        <span>{{__('備考')}}</span>
                                    </th>
                                </tr>
                            </thead>

                            <tbody class="bg-white">
                                @foreach($list as $item)
                                    <tr>
                                        <td class="align-middle" style="background-color:#faebd7; border-left:1px solid #dcdcdc;">
                                            <div class="d-flex align-items-center">
                                                <input type="checkbox" class="m-0 checkbox" name="pk[]" value="{{ $item->pplace_id }}">
                                                <a href="{{ route('pplaces_edit', ['id' => $item->pplace_id]) }}"
                                                class="btn btn-sm btn-default ml10">編集</a>
                                            </div>
                                        </td>
                                        <td class='sm-item text-left'><span>{{mb_substr($item->pplace_id, 0, 10)}}</span></td>
                                        <td class='sm-item text-left'><span>{{mb_substr($item->pplace_number, 0, 20)}}</span></td>
                                        <td class='sm-item text-left'><span>{{mb_substr($item->pplace_remarks, 0, 20)}}</span></td>                                        
                                    </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                </div>
                <!-- ▲ ここまで単一テーブル構成 ----------------------------------------- -->
            </form>
    </div>
</section>
@endsection
