@extends('mobile.layouts.app')

@section('content')
<div id="accountPost" class="container">
    @include('mobile.account.navTabs')

    <h4>작성 게시글</h4>
    <hr/>

    <div class="row g-2 mb-2 align-items-center">
        <div class="col">
            <span>Total : {{ $posts->total }}</span>
        </div>
        <div class="col-auto">
            <button type="button" id="btnAccountPostDelete" class="btn btn-dark">선택삭제</button>
        </div>
        <div class="col-auto 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>

    <table class="table table-hover">
        <colgroup>
            <col style="width: 4%;"/>
            <col style="width: auto;"/>
        </colgroup>
        <thead>
            <tr>
                <th>
                    <input type="checkbox" name="chk_all" id="chkAll" class="form-check-input" value="1"/>
                </th>
                <th colspan="2">게시글 내용</th>
            </tr>
        </thead>
        <tbody>
        @if($posts->total > 0)
            @foreach($posts->list as $row)
            <tr id="post_{{ $row->num }}">
                <td>
                    <input type="checkbox" name="chk[]" class="form-check-input list-check-box" value="{{ $row->id }}"/>
                </td>
                <td>
                    <div class="row">
                        <div class="col col-md-10">
                            <p>
                                @if($row->categoryName)
                                    <label>[{{ $row->categoryName }}]</label>
                                @endif
                                <a href="{{ $row->viewURL }}" hreflang="ko" referrerpolicy="origin" type="text/html" target="_self">{{ $row->subject }}</a>

                                @if($row->is_secret)
                                    <i class="fas fa-lock"></i>
                                @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
                            </p>
                            <ul>
                                <li>{{ $row->user->name }}</li>
                                <li>{{ $row->createdAt }}</li>
                                <li>조회 {{ $row->hit }}</li>
                            </ul>
                        </div>
                        @if($row->thumbnail)
                        <div class="col-3 col-md-2 align-self-center">
                            <div class="thumbnail">
                                <img src="{{ $row->thumbnail }}" class="img-fluid rounded" alt="{{ $row->subject }}" onerror="this.src='{{ NO_IMAGE_NORMAL_SRC }}'"/>
                            </div>
                        </div>
                        @endif
                    </div>
                </td>
            </tr>
            @endforeach
        @else
            <tr>
                <td colspan="2" class="p-5">
                    작성 게시글이 없습니다.
                </td>
            </tr>
        @endif
        </tbody>
    </table>

    @if($posts->total > 0)
    <div class="pagination">
        {{ $posts->list->onEachSide($params->pageCount)->links('component.pagination') }}
    </div>
    @endif

    <form name="f_account_post" id="fAccountPost" method="post" action="{{ route('account.post') }}" autocomplete="off" accept-charset="UTF-8">
        @csrf
        <input type="hidden" name="per_page" value="{{ $params->perPage }}"/>
    </form>
</div>
@endsection

@push('styles')
    <link rel="stylesheet" href="{{ asset('css/mobile/account/post.css') }}"/>
@endpush

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