@extends('admin.layouts.app')

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

    <div class="row mb-3">
        <div class="col align-self-center">
            <label>전체 : {{ $bannerGroupData->total }}</label>
        </div>
        <div class="col text-end">
            <button type="button" class="btn btn-outline-dark btn-list-update btn-list-selected disabled" data-list-update-url="/admin/page/banner/group/update">선택수정</button>
            <button type="button" class="btn btn-outline-dark btn-list-delete btn-list-selected disabled" data-list-delete-url="/admin/page/banner/group/destroy">선택삭제</button>
        </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="1%"/>
                    <col width="5%"/>
                    <col width="*"/>
                    <col width="20%"/>
                </colgroup>
                <thead>
                    <tr>
                        <th><input type="checkbox" name="chk_all" id="chkAll" value="1" class="form-check-input"/></th>
                        <th>PK</th>
                        <th>위치명</th>
                        <th>배너 수</th>
                    </tr>
                </thead>
                <tbody>
                    @if($bannerGroupData->total > 0)
                        @foreach($bannerGroupData->list as $row)
                        <tr>
                            <td>
                                <input type="checkbox" name="chk[]" id="chk_{{ $row->id }}" class="form-check-input list-check-box" value="{{ $row->id }}" required maxlength="255" />
                            </td>
                            <td>
                                {{ $row->id }}
                                @if($row->bannerCount > 0)
                                    <br/><span class="badge bg-danger">삭제 불가</span>
                                @endif
                            </td>
                            <td>
                                <input type="text" name="name[{{ $row->id }}]" class="form-control" value="{{ $row->name }}" />
                            </td>
                            <td>{{ $row->bannerCount }}</td>
                        </tr>
                        @endforeach
                    @else
                        <tr>
                            <td colspan="4">
                                No data.
                            </td>
                        </tr>
                    @endif
                </tbody>
            </table>
        </div>
    </form>

    <form name="f_admin_write" id="fAdminWrite" method="post" action="{{ $actionURL }}">
        @csrf
        <div class="row">
            <label for="name" class="col-auto col-form-label">배너 위치명</label>
            <div class="col-sm-3">
                <div class="input-group">
                    <input type="text" name="name" id="name" class="form-control" placeholder="배너명을 입력해주세요."/>
                    <button type="submit" class="btn btn-success btn-sm">추가하기</button>
                </div>
            </div>
        </div>
    </form>
</div>

<script type="module">
$("#fAdminWrite").validate({
    rules: {
        name: {required: true}
    }
});
</script>
@endsection
