@extends('layouts.app')

@section('content')
<div id="board" class="container">
    <div class="row">
        <div class="col align-self-end">
            <h5 class="board-name">최신글 보기</h5>
        </div>
        <div class="col align-self-center text-end">

        </div>
    </div>
    <hr/>
    <div id="boardList">

        {{-- 검색 --}}
        <div class="search">
            <div class="row">
                <div class="col">
                    <form name="f_board_search" id="fBoardSearch" method="get" action="{{ $listURL }}" autocomplete="off" accept-charset="UTF-8">
                        <input type="hidden" name="page" value="{{ $params->page }}"/>
                        <input type="hidden" name="per_page" value="{{ $params->perPage }}"/>
                        <input type="hidden" name="sort" value="{{ $params->sort }}"/>

                        <div class="row g-2 justify-content-center">
                            <div class="col-auto">
                                <select name="field" id="field" class="form-select">
                                    <option value="1" @if($params->field == '1') selected @endif>제목 + 내용</option>
                                    <option value="2" @if($params->field == '2') selected @endif>제목</option>
                                    <option value="3" @if($params->field == '3') selected @endif>글 작성자</option>
                                    <option value="4" @if($params->field == '4') selected @endif>댓글 내용</option>
                                    <option value="5" @if($params->field == '5') selected @endif>댓글 작성자</option>
                                </select>
                            </div>
                            <div class="col-auto">
                                <input type="text" name="keyword" id="keyword" class="form-control" value="{{ $params->keyword }}"/>
                            </div>
                            <div class="col-auto">
                                <button type="submit" class="btn btn-dark">검색</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>

        <div class="body">
            <table class="table">
                <caption>
                    <div class="row">
                        <div class="col-auto align-self-center">
                            <span>전체 : {{ $recent->total }}개</span>
                        </div>
                        <div class="col text-end">
                            <select name="per_page" id="perPage" class="form-select">
                                <option value="10" @if($params->perPage == 10) selected @endif>10개씩</option>
                                <option value="15" @if($params->perPage == 15) selected @endif>15개씩</option>
                                <option value="20" @if($params->perPage == 20) selected @endif>20개씩</option>
                                <option value="30" @if($params->perPage == 30) selected @endif>30개씩</option>
                                <option value="40" @if($params->perPage == 40) selected @endif>40개씩</option>
                                <option value="50" @if($params->perPage == 50) selected @endif>50개씩</option>
                            </select>
                        </div>
                    </div>
                </caption>
                <colgroup>
                    <col width="6%"/>
                    <col width="*"/>
                    <col width="14%"/>
                    <col width="14%"/>
                    <col width="8%"/>
                    <col width="8%"/>
                </colgroup>
                <thead>
                    <tr>
                        <th>번호</th>
                        <th>제목</th>
                        <th>작성자</th>
                        <th>작성일</th>
                        <th>조회</th>
                        <th>추천</th>
                    </tr>
                </thead>
                <tbody>

                {{-- 최신 게시글 --}}
                @if($recent->total > 0)
                    @foreach($recent->list as $row)
                        <tr>
                            <td>{{ $row->num }}</td>
                            <td class="text-start">
                                @if($row->categoryName)
                                    <label>
                                        <a href="{{ $listURL }}?category={{ $row->board_category_id }}" rel="search">
                                            [{{ $row->categoryName }}]
                                        </a>
                                    </label>
                                @endif
                                @if($row->is_secret)
                                    <a href="{{ $row->viewURL }}" hreflang="ko" referrerpolicy="origin" type="text/html" target="_self">
                                        <i class="fas fa-lock"></i> 비밀글입니다.
                                    </a>
                                @elseif($row->isBlame)
                                    <i class="fas fa-ban"></i> <del>{{ $row->subject }}</del>
                                @else
                                    <a href="{{ $row->viewURL }}" hreflang="ko" referrerpolicy="origin" type="text/html" target="_self">{{ $row->subject }}</a>
                                @endif
                                @if($row->comment_rows > 0)
                                    <var>[{{ $row->comment_rows }}]</var>
                                @endif
                                @if($row->file_rows > 0)
                                    <i class="fas fa-save"></i>
                                @endif
                                @if($row->link_rows > 0)
                                    <i class="fas fa-external-link-alt"></i>
                                @endif
                                @if($row->image_rows > 0)
                                    <i class="fas fa-image"></i>
                                @endif
                                @if($row->isNew)
                                    <span class="badge bg-warning text-dark">New</span>
                                @endif
                                @if($row->isHot)
                                    <span class="badge bg-danger">Hot</span>
                                @endif
                            </td>
                            <td>{{ $row->user->name }}</td>
                            <td>{{ $row->createdAt }}</td>
                            <td>{{ $row->hit }}</td>
                            <td>{{ $row->like }}</td>
                        </tr>
                    @endforeach
                @else
                    <tr>
                        <td colspan="6" class="p-5">
                            최신 글이 존재하지 않습니다.
                        </td>
                    </tr>
                @endif
                </tbody>

                @if($recent->total > 0)
                <tfoot>
                    <tr>
                        <td colspan="6">
                            {{ $recent->list->onEachSide($params->pageCount)->links('board.component.pagination') }}
                        </td>
                    </tr>
                </tfoot>
                @endif
            </table>

        </div>
    </div>
</div>
@endsection

@push('styles')
    <link rel="stylesheet" href="{{ asset('css/desktop/board/index.css') }}"/>
@endpush

@push('scripts')
    <script src="{{ asset('js/board/index.js') }}" defer></script>
@endpush
