@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">
        {{-- 並び替え用 hidden --}}
        <form action="{{ route('opes') }}" method="POST" id="list-form">
            @csrf
            <input type="hidden" name="sort" value="{{ $sort ?? '' }}">
            <input type="hidden" name="sort_type" value="{{ $sort_type ?? '' }}">
        </form>

        <!-- ツールバー -->
        <div class="container-fluid mb20">
            <button type="button" class="btn btn-sm btn-default mr10" onclick="location.href='{{ route('opes_add') }}'">新規</button>
            <button type="button" class="btn btn-sm btn-default mr10" id="delete">削除</button>
            <button type="button" class="btn btn-sm btn-default mr10" id="import">インポート</button>
            <button type="button" class="btn btn-sm btn-default mr10" id="export">CSV出力</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('opes_delete') }}" method="POST" id="form_delete">
                    @csrf
                    <table class="table table-bordered dataTable text-nowrap">
                        <thead class="thead-light">
                            <tr>
                                <th style="width:140px;" class="text-left">
                                    <input type="checkbox" onclick="$('input[name=\'ids[]\']').prop('checked', this.checked);">
                                </th>
                                <th class="sorting {{ ($sort=='ope_id') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="ope_id"><span>オペレータID</span></th>
                                <th class="sorting {{ ($sort=='ope_name') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="ope_name"><span>オペレータ名</span></th>
                                <!-- <th><span>パスワード</span></th> -->
                                <th class="sorting {{ ($sort=='ope_type') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="ope_type"><span>オペレータ種別</span></th>
                                <th><span>メールアドレス</span></th>
                                <th class="sorting {{ ($sort=='ope_phone') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="ope_phone"><span>電話番号</span></th>
                                @for ($i = 1; $i <= 13; $i++)
                                    <th class="text-center sorting {{ ($sort=='ope_sendalart_que'.$i) ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="ope_sendalart_que{{$i}}"><span>キュー{{ $i }}アラート送信</span></th>
                                @endfor
                                <th class="sorting {{ ($sort=='ope_auth1') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="ope_auth1"><span>管理者権限付与</span></th>
                                <th class="sorting {{ ($sort=='ope_auth2') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="ope_auth2"><span>エリアマネージャー権限付与</span></th>
                                <th class="sorting {{ ($sort=='ope_auth3') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="ope_auth3"><span>エリアオペレーター権限付与</span></th>
                                <th class="sorting {{ ($sort=='ope_auth4') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="ope_auth4"><span>オペレーター権限付与</span></th>
                                <th class="sorting {{ ($sort=='ope_quit_flag') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="ope_quit_flag"><span>退職フラグ</span></th>
                                <th class="sorting {{ ($sort=='ope_quitday') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="ope_quitday"><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="ids[]" value="{{ $item->ope_id }}">
                                            <a href="{{ route('opes_edit', ['id' => $item->ope_id]) }}" class="btn btn-sm btn-default ml10">編集</a>
                                        </div>
                                    </td>
                                    <td class="sm-item text-left align-middle">{{ $item->ope_id }}</td>
                                    <td class="sm-item text-left align-middle">{{ $item->ope_name }}</td>
                                    <!-- <td class="sm-item text-left align-middle">{{ $item->ope_pass }}</td> -->
                                    <td class="sm-item text-left align-middle">{{ \App\Models\Ope::OPE_TYPE[$item->ope_type] }}</td>
                                    <td class="sm-item text-left align-middle">{{ $item->ope_mail }}</td>
                                    <td class="sm-item text-left align-middle">{{ $item->ope_phone }}</td>
                                    @for ($i = 1; $i <= 13; $i++)
                                        <td class="text-center">
                                            {{ $item->{'ope_sendalart_que'.$i} ? 'はい' : 'いいえ' }}
                                        </td>
                                    @endfor                                    
                                    <td class="sm-item text-left align-middle">{{ $item->ope_auth1 }}</td>
                                    <td class="sm-item text-left align-middle">{{ $item->ope_auth2 }}</td>
                                    <td class="sm-item text-left align-middle">{{ $item->ope_auth3 }}</td>
                                    <td class="sm-item text-left align-middle">{{ $item->ope_auth4 }}</td>
                                    <td class="sm-item text-left align-middle">{{ $item->ope_quit_flag ? '退職' : '在籍中' }}</td>
                                    <td class="sm-item text-left align-middle">{{ $item->ope_quitday }}</td>
                                </tr>
                            @endforeach
                        </tbody>
                    </table>
                </form>
            </div>
        </div>
        <!-- ▲ 単一テーブル構成ここまで ----------------------------------------- -->
    </div>
</section>


@endsection
