@extends('admin.layouts.app')

@section('content')
<div class="container-fluid">
    <h2>배너 관리</h2>
    <hr/>
    @include('admin.messages')
    @include('admin.page.banner.navTabs')

    <form name="f_admin_search" id="fAdminSearch" method="get" action="{{ route('admin.page.banner.index') }}">
        <div class="row g-2">
            <div class="col-auto">
                <select name="field" id="field" class="form-select">
                    <option value="tb_banner.id" @if($params->field == 'tb_banner.id') selected @endif>PK</option>
                    <option value="tb_banner.subject" @if($params->field == 'tb_banner.subject') selected @endif>설명</option>
                    <option value="tb_banner.url" @if($params->field == 'tb_banner.url') selected @endif>URL</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>

    <div class="pt-2 pb-4">
        <div class="btn-group">
            <button name="activated" class="btn btn-outline-secondary @if($params->activated == '') active @endif" value="" form="fAdminSearch">전체</button>
            <button name="activated" class="btn btn-outline-secondary @if($params->activated == '1') active @endif" value="1" form="fAdminSearch">활성</button>
            <button name="activated" class="btn btn-outline-secondary @if($params->activated == '0') active @endif" value="0" form="fAdminSearch">비활성</button>
        </div>
    </div>

    <div class="row mb-2">
        <div class="col align-self-center">
            전체 : {{ $bannerData->total }} / {{ $bannerData->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/banner/destroy">선택삭제</button>
            <a href="{{ route('admin.page.banner.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">
                <colgroup>
                    <col width="2%"/>
                    <col width="2%"/>
                    <col width="10%"/>
                    <col width="*"/>
                    <col width="8%"/>
                    <col width="4%"/>
                    <col width="6%"/>
                    <col width="10%"/>
                    <col width="4%"/>
                    <col width="5%"/>
                    <col width="5%"/>
                    <col width="5%"/>
                </colgroup>
                <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>
                        <th>상태</th>
                        <th>비고</th>
                    </tr>
                </thead>
                <tbody>
                    @if($bannerData->rows > 0)
                        @foreach($bannerData->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>
                                @if($row->image)
                                    <img src="{{ asset($row->image) }}" alt="{{ $row->subject }}" class="img-thumbnail" style="max-width: 200px;"/>
                                @else
                                    -
                                @endif
                            </td>
                            <td>
                                <dl>
                                    <dt>{{ $row->subject ?? '-' }}</dt>
                                    <dd>{{ $row->summary ?? '-' }}</dd>
                                </dl>
                            </td>
                            <td>{{ $row->bannerGroup->name }}</td>
                            <td>{{ MAP_DEVICE_TYPE[$row->device] }}</td>
                            <td>{{ $row->width . ' x ' . $row->height }}</td>
                            <td>{{ $row->start_date . " ~ " . $row->end_date }}</td>
                            <td>{{ $row->views }}</td>
                            <td>{{ $row->order }}</td>
                            <td>{{ $row->activated == '1' ? '활성' : '비활성' }}</td>
                            <td>
                                <a href="{{ $row->editURL }}" class="btn btn-primary btn-sm">수정</a>
                            </td>
                        </tr>
                        @endforeach
                    @else
                        <tr>
                            <td colspan="12">
                                No data.
                            </td>
                        </tr>
                    @endif
                </tbody>
            </table>

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