@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="col-lg-12">
        <div class="card">
            <div class="card-header"><h3 class="card-title">絞り込みフィルター</h3></div>
            <div class="card-body">
                <form action="{{ route('operator_ques') }}" method="POST" id="list-form">
                    @csrf
                    <input type="hidden" name="sort" value="{{ $sort ?? '' }}">
                    <input type="hidden" name="sort_type" value="{{ $sort_type ?? '' }}">

                    <div class="row">
                        <div class="form-group col-12">
                            <label>キューステータス</label>
                            <select name="que_status" class="form-control">
                                <option value="">-- 選択してください --</option>
                                @foreach(\App\Models\OperatorQue::QueStatus as $key => $label)
                                    <option value="{{ $key }}" {{ old('que_status', $que_status ?? '') == $key ? 'selected' : '' }}>
                                        {{ $label }}
                                    </option>
                                @endforeach
                            </select>
                        </div>
                    
                        <div class="form-group col-12 text-left">
                            <button type="submit" name="action" value="filter" class="btn btn-default mr10">絞り込み</button>
                            <a href="{{ route('operator_ques') }}" class="btn btn-default">解除</a>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <!-- ▲ 絞り込みフィルター -->

    <div class="container-fluid">
        <!-- ▼ ツールバー -->
        <div class="container-fluid mb20">
            <button type="button" class="btn btn-sm btn-default mr10" onclick="location.href='{{ route('operator_ques_add') }}'">新規</button>
            <button type="button" class="btn btn-sm btn-default mr10" id="delete">削除</button>
            
            <div class="d-flex justify-content-end">
                {{ $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>
        <!-- ▲ メッセージ表示 -->

        <!-- ▼ 単一テーブル構成 -->
        <div class="col-lg-12 mb20">
            <div class="table-responsive">
                <form action="{{ route('operator_ques_delete') }}" method="POST" id="form_delete">
                    @csrf
                    <table class="table table-bordered dataTable text-nowrap">
                        <thead class="thead-light">
                        <tr>
                            <th style="width:120px;" class="text-left">
                                <input type="checkbox" onclick="$('input[name*=\'pk\']').prop('checked', this.checked);">
                            </th>
                            <th class="sorting {{ ($sort=='que_id') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="que_id"><span>キューID</span></th>
                            <th class="sorting {{ ($sort=='user_id') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="user_id"><span>利用者名</span></th>
                            <th><span>携帯電話番号</span></th>
                            <th><span>自宅電話番号</span></th>
                            <th><span>定期契約ID</span></th>
                            <th class="sorting {{ ($sort=='park_name') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="park_name"><span>駐輪場</span></th>
                            <th class="sorting {{ ($sort=='que_class') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="que_class"><span>キュー種別</span></th>
                            <th><span>キューコメント</span></th>
                            <th class="sorting {{ ($sort=='que_status') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="que_status"><span>キューステータス</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;">
                                    <div class="d-flex align-items-center">
                                        <input type="checkbox" class="m-0 checkbox" name="pk[]" value="{{ $item->que_id }}">
                                        <a href="{{ route('operator_ques_edit', ['id' => $item->que_id]) }}" class="btn btn-sm btn-default ml10">編集</a>
                                    </div>
                                </td>
                                <td class="sm-item text-left align-middle">{{ $item->que_id }}</td>
                                <td class="sm-item text-left align-middle">{{ !empty($item->getUser()) ? $item->getUser()->user_name : '' }}</td>
                                <td class="sm-item text-left align-middle">{{ !empty($item->getUser()) ? $item->getUser()->user_mobile : '' }}</td>
                                <td class="sm-item text-left align-middle">{{ !empty($item->getUser()) ? $item->getUser()->user_homephone : '' }}</td>
                                <td class="sm-item text-left align-middle">{{ $item->contract_id }}</td>
                                <td class="sm-item text-left align-middle">{{ !empty($item->getPark()) ? $item->getPark()->park_name : '' }}</td>
                                <td class="sm-item text-left align-middle">{{ $item->getQueClassLabel() }}</td>
                                <td class="sm-item text-left align-middle">{{ $item->que_comment }}</td>
                                <td class="sm-item text-left align-middle">{{ $item->getQueStatusLabel() }}</td>
                                <td class="sm-item text-left align-middle">{{ $item->que_status_comment }}</td>

                                <td class="sm-item text-left align-middle"></td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                </form>
            </div>
        </div>
        <!-- ▲ 単一テーブル構成 -->
    </div>
</section>

@endsection
