@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>
    <!-- /.content-header -->

    <section class="content">
        <div class="container-fluid">
            <div class="row">
                <form action="{{route('usertypes')}}" 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="container-fluid mb20">
                    <div class="d-flex justify-content-between align-items-center">
                        <div>
                            <a href="{{route('usertype_add')}}" class="btn btn-sm btn-default mr10">{{__('新規')}}</a>
                            <button type="submit" class="btn btn-sm btn-default mr10" form="form_delete" name="delete"
                                id="delete">{{__('削除')}}</button>
                            <button type="submit" class="btn btn-sm btn-default mr10" name="export_csv" id="export_csv"
                                action="{{route('usertypes_export')}}">{{__('CSV出力')}}</button>
                        </div>
                        <div>
                            {{ $list->appends(['sort' => $sort, 'sort_type' => $sort_type])->links('pagination') }}
                        </div>
                    </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>
                <div class="col-lg-12 sample03-wrapper no_padding_right mb20">
                    <form action="{{route('usertypes_delete')}}" method="post" id="form_delete">
                        @csrf
                        <div class="scroll">
                            <table class="table table-bordered table-hover rv-table mb-0 text-nowrap">
                                <thead>
                                    <tr>
                                        <th style="width:80px;">
                                            <input type="checkbox" id="chkAll">
                                            <span class="ml-1"></span>
                                        </th>
                                        <th class="sorting @if($sort == 'user_categoryid'){{$sort_type == 'asc' ? 'sorting_asc' : 'sorting_desc'}}@endif"
                                            sort="user_categoryid">
                                            <span>{{__('利用者分類ID')}}</span>
                                        </th>
                                        <th>
                                            <span>{{__('ソート順')}}</span>
                                        </th>
                                        <th>
                                            <span>{{__('分類名1')}}</span>
                                        </th>
                                        <th>
                                            <span>{{__('分類名2')}}</span>
                                        </th>
                                        <th>
                                            <span>{{__('分類名3')}}</span>
                                        </th>
                                        <th class="sorting @if($sort == 'print_name'){{$sort_type == 'asc' ? 'sorting_asc' : 'sorting_desc'}}@endif"
                                            sort="print_name">
                                            <span>{{__('分類名')}}</span>
                                        </th>
                                        <th>
                                            <span>{{__('適用料率')}}</span>
                                        </th>
                                        <th>
                                            <span>{{__('備考')}}</span>
                                        </th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @foreach($list as $item)
                                        <tr>
                                            <td style="background-color:#faebd7;" class="op-cell">
                                                <div class="d-flex align-items-center">
                                                    <input type="checkbox" class="mr-2 chkRow" name="pk[]"
                                                        value="{{ $item->user_categoryid }}">
                                                    <a href="{{ route('usertype_edit', ['id' => $item->user_categoryid]) }}"
                                                        class="btn btn-sm btn-default">編集</a>
                                                </div>
                                            </td>
                                            <td class='sm-item text-left'>
                                                <span>{{ mb_substr($item->user_categoryid, 0, 10) }}</span>
                                            </td>
                                            <td class='sm-item text-left'>
                                                <span>{{ mb_substr($item->sort_order, 0, 10) }}</span>
                                            </td>
                                            <td class='sm-item text-left'>
                                                <span>{{ mb_substr($item->category_name1, 0, 10) }}</span>
                                            </td>
                                            <td class='sm-item text-left'>
                                                <span>{{ mb_substr($item->category_name2, 0, 10) }}</span>
                                            </td>
                                            <td class='sm-item text-left'>
                                                <span>{{ mb_substr($item->category_name3, 0, 10) }}</span>
                                            </td>
                                            <td class='sm-item text-left'>
                                                <span>{{ mb_substr($item->print_name, 0, 10) }}</span>
                                            </td>
                                            <td class='sm-item text-right'>
                                                <span>{{ mb_substr($item->usertype_money, 0, 10) }}</span>
                                            </td>
                                            <td class='sm-item text-left'>
                                                <span>{{ mb_substr($item->usertype_remarks, 0, 20) }}</span>
                                            </td>
                                        </tr>
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </section>

    <script>
        (function () {
            // 全選択チェック
            var chkAll = document.getElementById('chkAll');
            var chks = document.getElementsByClassName('chkRow');
            if (chkAll) {
                chkAll.addEventListener('change', function () {
                    Array.prototype.forEach.call(chks, function (c) { c.checked = chkAll.checked; });
                });
            }

            // 一括削除ボタン
            var btn = document.getElementById('btnBulkDel');
            var form = document.getElementById('bulkDeleteForm');
            if (btn && form) {
                btn.addEventListener('click', function () {
                    var any = false;
                    Array.prototype.forEach.call(chks, function (c) { if (c.checked) any = true; });
                    if (!any) { alert('削除対象の行を選択してください。'); return; }
                    if (confirm('選択した予約を削除します。よろしいですか？')) {
                        form.submit();
                    }
                });
            }
        })();
    </script>


@endsection