@extends('admin.layouts.app')

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

    <form name="f_admin_search" id="fAdminSearch" method="get" action="{{ route('admin.page.document.store') }}">
        <div class="row g-2">
            <div class="col-auto">
                <select name="field" id="field" class="form-select">
                    <option value="tb_document.id" @if($params->field == 'tb_document.id') selected @endif>PK</option>
                    <option value="tb_document.subject" @if($params->field == 'tb_document.subject') selected @endif>제목</option>
                    <option value="tb_document.code" @if($params->field == 'tb_document.code') selected @endif>주소</option>
                    <option value="tb_document.content" @if($params->field == 'tb_document.content') selected @endif>PC 내용</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.email" @if($params->field == 'users.email') 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">
            전체 : {{ $documentData->total }} / {{ $documentData->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/page/document/destroy">선택삭제</button>
            <a href="{{ route('admin.page.document.create') }}" 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>제목</th>
                        <th>주소</th>
                        <th>조회수</th>
                        <th>작성자</th>
                        <th>등록일시</th>
                        <th>최종 수정자</th>
                        <th>최종 수정일시</th>
                        <th>비고</th>
                    </tr>
                </thead>
                <tbody>
                    @if($documentData->rows > 0)
                        @foreach($documentData->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->id }}</td>
                            <td>{{ $row->subject }}</td>
                            <td>
                                <a href="{{ $row->url }}" target="_blank">{{ $row->url }}</a>
                            </td>
                            <td>{{ $row->views }}</td>
                            <td>{{ $row->creater->nickname ?? '-' }}</td>
                            <td>{{ $row->created_at ?? '-' }}</td>
                            <td>{{ $row->updater->nickname ?? '-' }}</td>
                            <td>{{ $row->updated_at ?? '-' }}</td>
                            <td>
                                <a href="{{ $row->editURL }}" 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">
                {{ $documentData->list->withQueryString()->links() }}
            </div>
        </div>
    </form>
</div>
@endsection
