@extends('admin.layouts.app')

@section('content')
<div class="container-fluid">
    <h2>로그인 기록</h2>
    <hr/>
    @include('admin.messages')
    @include('admin.user.log.login.navTabs')

    <form name="f_admin_search" id="fAdminSearch" method="get" action="{{ route('admin.user.log.login.index') }}">
        <div class="row g-2">
            <div class="col-auto">
                <select name="field" id="field" class="form-select">
                    <option value="users.id" @if( $params->field == 'users.id') selected @endif>회원 PK</option>
                    <option value="users.sid" @if( $params->field == 'users.sid') selected @endif>회원 ID</option>
                    <option value="users.name" @if( $params->field == 'users.name') selected @endif>회원명</option>
                    <option value="users.nickname" @if( $params->field == 'users.nickname') selected @endif>회원 닉네임</option>
                    <option value="users.email" @if( $params->field == 'users..email') selected @endif>회원 이메일</option>
                    <option value="login_log.ip_address" @if( $params->field == 'login_log.ip_address') selected @endif>로그인 IP</option>
                    <option value="login_log.created_at" @if( $params->field == 'login_log.created_at') selected @endif>로그인 일시</option>
                </select>
            </div>
            <div class="col-auto">
                <div class="input-group">
                    <input type="text" name="keyword" id="keyword" class="form-control" value="{{ $params->keyword }}" placeholder="검색어를 입력하세요." />
                    <button type="submit" class="btn btn-dark">검색</button>
                </div>
            </div>
        </div>
    </form>
    <br/>

    <div class="row mb-2">
        <div class="col align-self-center">
            전체 : {{ $userLoginLogData->total }} / {{ $userLoginLogData->rows }}
        </div>
        <div class="col text-end">
            <button type="button" class="btn btn-outline-dark btn-list-delete btn-list-selected disabled" data-list-delete-url="/admin/user/log/login/destroy">선택삭제</button>
        </div>
    </div>

    <form name="f_admin_list" id="fAdminList" method="post">
        @csrf
        <div class="table-responsive">
            <table class="table table-hover table-bordered table-nowrap">
                <colgroup>
                    <col width="3%" />
                    <col width="5%" />
                    <col width="10%" />
                    <col width="7%" />
                    <col width="7%" />
                    <col width="7%" />
                    <col width="7%" />
                    <col width="*" />
                    <col width="7%" />
                </colgroup>
                <thead>
                    <tr>
                        <th><input type="checkbox" name="chk_all" id="chkAll" class="form-check-input" value="1" /></th>
                        <th>번호</th>
                        <th>ID</th>
                        <th>이메일</th>
                        <th>성공 여부</th>
                        <th>이유</th>
                        <th>IP</th>
                        <th>UserAgent</th>
                        <th>등록일시</th>
                    </tr>
                </thead>
                <tbody>
                    @if($userLoginLogData->rows > 0)
                        @foreach($userLoginLogData->list as $row)
                        <tr>
                            <td>
                                <input type="checkbox" name="chk[]" id="chk_{{ $row->id }}" class="form-check-input list-check-box" value="{{ $row->id }}" />
                            </td>
                            <td>{{ $row->num }}</td>
                            <td>{{ $row->sid ?? '-' }}</td>
                            <td>{{ $row->account }}</td>
                            <td>{{ ($row->success ? '성공' : '실패') }}</td>
                            <td>{{ $row->reason }}</td>
                            <td>{{ $row->ip_address }}</td>
                            <td>{{ $row->user_agent }}</td>
                            <td>{!! $row->createdAt !!}</td>
                        </tr>
                        @endforeach
                    @else
                        <tr>
                            <td colspan="9">
                                No data.
                            </td>
                        </tr>
                    @endif
                </tbody>
            </table>

            <div class="pagination">
                {{ $userLoginLogData->list->withQueryString()->onEachSide($params->pageCount)->links('component.pagination') }}
            </div>
        </div>
    </form>
</div>
@endsection
