@extends('admin.layouts.app')

@section('content')
<div class="container-fluid">
    <h2>SMS 주소록 관리</h2>
    <hr/>
    @include('admin.messages')

    <div class="mb-2">
        <button type="button" class="btn btn-link btn-write-cancel" value="{{ route('admin.sms.book.list.index') }}">< 뒤로가기</button>
    </div>

    <form name="f_admin_search" id="fAdminSearch" method="get" action="{{ route('admin.sms.book.user.index') }}">
        <input type="hidden" name="book" value="{{ $params->smsBookID }}"/>
        <table class="table table-bordered">
            <colgroup>
                <col width="15%" />
                <col width="*" />
            </colgroup>
            <tbody>
                <tr>
                    <th>검색</th>
                    <td>
                        <div class="row g-2">
                            <div class="col-auto">
                                <select name="field" id="field" class="form-select">
                                    <option value="tb_sms_user.id" @if($params->field == 'tb_sms_user.id') selected @endif>주소록 PK</option>
                                    <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>
                                </select>
                            </div>
                            <div class="col">
                                <input type="text" name="keyword" id="keyword" class="form-control" value="{{ $params->keyword }}" placeholder="검색어를 입력하세요." />
                            </div>
                        </div>
                    </td>
                </tr>
                @if($userGroupData->count() > 0)
                <tr>
                    <th>회원그룹</th>
                    <td class="text-start">
                        @foreach($userGroupData as $row)
                            <div class="form-check form-check-inline">
                                <input type="checkbox" name="user_group_id[]" id="userGroupID_{{ $row->id }}" class="form-check-input" value="{{ $row->id }}" @if(in_array($row->id, $params->userGroupID)) checked @endif/>
                                <label for="userGroupID_{{ $row->id }}" class="form-check-label">{{ $row->kor_name }}</label>
                            </div>
                        @endforeach
                    </td>
                </tr>
                @endif
                @if($userGradeData->count() > 0)
                <tr>
                    <th>회원등급</th>
                    <td class="text-start">
                        @foreach($userGradeData as $row)
                            <div class="form-check form-check-inline">
                                <input type="checkbox" name="user_grade_id[]" id="userGradeID_{{ $row->id }}" class="form-check-input" value="{{ $row->id }}" @if(in_array($row->id, $params->userGradeID)) checked @endif/>
                                <label for="userGradeID_{{ $row->id }}" class="form-check-label">{{ $row->kor_name }}</label>
                            </div>
                        @endforeach
                    </td>
                </tr>
                @endif
            </tbody>
        </table>

        <div class="text-center">
            <button type="submit" class="btn btn-dark">검색</button>
        </div>
    </form>
    <br/>

    <div class="row mb-2">
        <div class="col align-self-center">
            <label>전체 : {{ $smsUserData->total }} / {{ $smsUserData->rows }}</label>
        </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/sms/book/user/destroy?book={{ $params->smsBookID }}">선택삭제</button>
            <a href="{{ route('admin.sms.book.user.create') }}?book={{ $params->smsBookID }}" class="btn btn-success">새로등록</a>
        </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">
                <thead>
                    <tr>
                        <th><input type="checkbox" name="chk_all" id="chkAll" class="form-check-input" value="1"/></th>
                        <th>PK</th>
                        <th>ID</th>
                        <th>이메일</th>
                        <th>이름</th>
                        <th>닉네임</th>
                        <th>연락처</th>
                        <th>등록일시</th>
                        <th>비고</th>
                    </tr>
                </thead>
                <tbody>
                    @if($smsUserData->rows > 0)
                        @foreach($smsUserData->list as $row)
                        <tr>
                            <td>
                                <input type="checkbox" name="chk[]" id="chk_{{ $chk }}" class="form-check-input list-check-box" value="{{ $row->id }}" />
                            </td>
                            <td>{{ $row->id }}</td>
                            <td>{{ $row->sid }}</td>
                            <td>{{ $row->email ?? '-' }}</td>
                            <td>{{ $row->name ?? '-' }}</td>
                            <td>{{ $row->nickname ?? '-' }}</td>
                            <td>{{ $row->phone ?? '-' }}</td>
                            <td>{{ $row->created_at }}</td>
                            <td>
                                <a href="{{ $row->searchURL }}" class="btn btn-primary btn-sm">검색</a>
                            </td>
                        </tr>
                        @endforeach
                    @else
                        <tr>
                            <td colspan="10">
                                No data.
                            </td>
                        </tr>
                    @endif
                </tbody>
            </table>

            <div class="pagination">
                {{ $smsUserData->list->withQueryString()->links() }}
            </div>
        </div>
    </form>
</div>
@endsection
