@extends('admin.layouts.app')

@section('content')
<div class="container-fluid">
    <h2>게시판 관리 - 기본</h2>
    <hr/>
    @include('admin.messages')
    @if($boardID)
        @include('admin.board.board.navTabs')
    @endif

    <form name="f_admin_write" id="fAdminWrite" method="post" action="{{ $actionURL }}" enctype="multipart/form-data">
        @csrf
        @if($boardID)
            <input type="hidden" name="board_id" value="{{ $boardID }}" />
            @method('PUT')
        @endif
        <div class="row mb-3">
            <label for="code" class="col-sm-2 col-form-label">주소</label>
            <div class="col-sm-10">
                {{ url('board') }} / <input type="text" name="code" id="code" class="form-control d-inline w-auto" value="{{ $boardData->code ?? old('code') }}" />
            </div>
        </div>
        <div class="row mb-3">
            <label for="name" class="col-sm-2 col-form-label">제목</label>
            <div class="col-sm-10">
                <input type="text" name="name" id="name" class="form-control" value="{{ $boardData->name ?? old('name') }}" />
            </div>
        </div>
        <div class="row mb-3">
            <label for="boardGroupID" class="col-sm-2 col-form-label">그룹</label>
            <div class="col-sm-10">
                <select name="board_group_id" id="boardGroupID" class="form-select w-auto">
                    <option value="">선택하세요.</option>
                    @foreach($boardGroupData as $bgr)
                        <option value="{{ $bgr->id }}" @if(($boardData->board_group_id ?? old('board_group_id')) == $bgr->id) ? selected @endif>{{ $bgr->name }} ({{ $bgr->code }})</option>
                    @endforeach
                </select>
            </div>
        </div>
        <div class="row mb-3">
            <label for="grpHeaderContent" class="col-sm-2 col-form-label">PC 상단 내용</label>
            <div class="col-sm-8">
                <?php echo htmlEditor('pc_header_content', ($boardMetaData->pc_header_content ?? old('pc_header_content')), 'form-control dhtml-editor', true, false, '', 8, 'pcHeaderContent'); ?>
            </div>
            <div class="col-sm-2">
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="grp[pc_header_content]" id="grpHeaderContent" class="form-check-input" value="1" />
                    <label for="grpHeaderContent" class="form-check-label">그룹적용</label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="all[pc_header_content]" id="allHeaderContent" class="form-check-input" value="1" />
                    <label for="allHeaderContent" class="form-check-label">전체적용</label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="grpFooterContent" class="col-sm-2 col-form-label">PC 하단 내용</label>
            <div class="col-sm-8">
                <?php echo htmlEditor('pc_footer_content', ($boardMetaData->pc_footer_content ?? old('pc_footer_content')), 'form-control dhtml-editor', true, false, '', 8, 'pcFooterContent'); ?>
            </div>
            <div class="col-sm-2">
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="grp[pc_footer_content]" id="grpFooterContent" class="form-check-input" value="1" />
                    <label for="grpFooterContent" class="form-check-label">그룹적용</label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="all[pc_footer_content]" id="allFooterContent" class="form-check-input" value="1" />
                    <label for="allFooterContent" class="form-check-label">전체적용</label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="mobileHeaderContent" class="col-sm-2 col-form-label">모바일 상단 내용</label>
            <div class="col-sm-8">
                <?php echo htmlEditor('mobile_header_content', ($boardMetaData->mobile_header_content ?? old('mobile_header_content')), 'form-control dhtml-editor', true, false, '', 8, 'mobileHeaderContent'); ?>
            </div>
            <div class="col-sm-2">
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="grp[mobile_header_content]" id="grpMobileHeaderContent" class="form-check-input" value="1" />
                    <label for="grpMobileHeaderContent" class="form-check-label">그룹적용</label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="all[mobile_header_content]" id="allMobileHeaderContent" class="form-check-input" value="1" />
                    <label for="allMobileHeaderContent" class="form-check-label">전체적용</label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="mobileFooterContent" class="col-sm-2 col-form-label">모바일 하단 내용</label>
            <div class="col-sm-8">
                <?php echo htmlEditor('mobile_footer_content', ($boardMetaData->mobile_footer_content ?? old('mobile_footer_content')), 'form-control dhtml-editor', true, false, '', 8, 'mobileFooterContent'); ?>
            </div>
            <div class="col-sm-2">
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="grp[mobile_footer_content]" id="grpMobileFooterContent" class="form-check-input" value="1" />
                    <label for="grpMobileFooterContent" class="form-check-label">그룹적용</label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="all[mobile_footer_content]" id="allMobileFooterContent" class="form-check-input" value="1" />
                    <label for="allMobileFooterContent" class="form-check-label">전체적용</label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="brdSort" class="col-sm-2 col-form-label">순서</label>
            <div class="col-sm-10">
                <div class="form-inline">
                    <input type="number" name="sort" id="brdSort" class="form-control" value="{{ $boardData->sort ?? old('sort') }}" />
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="brdIsSearch_1" class="col-sm-2 col-form-label">검색 여부</label>
            <div class="col-sm-10">
                <div class="form-check form-check-inline">
                    <input type="radio" name="is_search" id="brdIsSearch_1" class="form-check-input" value="1" @if(($boardData->is_search ?? old('is_search')) == '1') checked @endif/>
                    <label for="brdIsSearch_1" class="form-check-label">예</label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="radio" name="is_search" id="brdIsSearch_0" class="form-check-input" value="0" @if(($boardData->is_search ?? old('is_search')) == '0') checked @endif />
                    <label for="brdIsSearch_0" class="form-check-label">아니오</label>
                </div>
                <div class="form-text text-muted">
                    게시판 제목이나 내용을 검색할 수 있도록 합니다.
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="isDisplay_1" class="col-sm-2 col-form-label">사용 여부</label>
            <div class="col-sm-10">
                <div class="form-check form-check-inline">
                    <input type="radio" name="is_display" id="isDisplay_1" class="form-check-input" value="1" @if(($boardData->is_display ?? old('is_display')) == '1') checked @endif />
                    <label for="isDisplay_1" class="form-check-label">예</label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="radio" name="is_display" id="isDisplay_0" class="form-check-input" value="0" @if(($boardData->is_display ?? old('is_display')) == '0') checked @endif />
                    <label for="isDisplay_0" class="form-check-label">아니오</label>
                </div>
                <div class="form-text text-muted">
                    게시판을 실제 사용할지 결정합니다. (비활성시 사용 안함)
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="useInformModal_1" class="col-sm-2 col-form-label">이용안내 표시</label>
            <div class="col-sm-8">
                <div class="form-check form-check-inline">
                    <input type="radio" name="use_inform_modal" id="useInformModal_1" class="form-check-input" value="1" @if(($boardMetaData->use_inform_modal ?? old('use_inform_modal')) == '1') checked @endif />
                    <label for="useInformModal_1" class="form-check-label">예</label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="radio" name="use_inform_modal" id="useInformModal_0" class="form-check-input" value="0" @if(($boardMetaData->use_inform_modal ?? old('use_inform_modal')) == '0') checked @endif />
                    <label for="useInformModal_0" class="form-check-label">아니오</label>
                </div>
                <div class="form-text text-muted">
                    게시판 우측 상단에 이용안내 버튼을 표시합니다.
                </div>
            </div>
            <div class="col-sm-2">
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="grp[use_inform_modal]" id="grpUseInformModal" class="form-check-input" value="1" />
                    <label for="grpUseInformModal" class="form-check-label">그룹적용</label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="all[use_inform_modal]" id="allUseInformModal" class="form-check-input" value="1" />
                    <label for="allUseInformModal" class="form-check-label">전체적용</label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="informContent" class="col-sm-2 col-form-label">이용안내 내용</label>
            <div class="col-sm-8">
                <?php echo htmlEditor('inform_content', ($boardMetaData->inform_content ?? old('inform_content')), 'form-control dhtml-editor', true, false, '', 8, 'informContent'); ?>
            </div>
            <div class="col-sm-2">
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="grp[inform_content]" id="grpInformContent" class="form-check-input" value="1" />
                    <label for="grpInformContent" class="form-check-label">그룹적용</label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="all[inform_content]" id="allInformContent" class="form-check-input" value="1" />
                    <label for="allInformContent" class="form-check-label">전체적용</label>
                </div>
            </div>
        </div>
        <hr/>
        <div class="text-end">
            <button type="submit" class="btn btn-success">저장하기</button>
            <button type="button" class="btn btn-light btn-write-cancel" value="{{ route('admin.board.board.list.index') }}">취소하기</button>
        </div>
    </form>
</div>

<script type="module">
$("#fAdminWrite").validate({
    rules: {
        code: {required: true, minlength: 3, maxlength: 50, alpha_dash: true},
        name: {required: true, maxlength: 255},
        group_id: {required: true, number: true},
        pc_header_content: {'required_tinymce': false},
        pc_footer_content: {'required_tinymce': false},
        mobile_header_content: {'required_tinymce': false},
        mobile_footer_content: {'required_tinymce': false},
        sort: {required: true, number: true},
        is_search: {required: true},
        is_display: {required: true},
        use_inform_modal: {required: true},
        inform_content: {"required_tinymce": function() {
            return document.getElementById("useInformModal_1").checked;
        }}
    }
});
</script>
@endsection
