@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
        <input type="hidden" name="board_id" value="{{ $boardID }}" />
        <div class="row mb-3">
            <label for="blockDelete_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="block_delete" id="blockDelete_1" class="form-check-input" value="1" @if($boardMetaData->block_delete ?? old('block_delete')) checked @endif/>
                    <label for="blockDelete_1" class="form-check-label">예</label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="radio" name="block_delete" id="blockDelete_0" class="form-check-input" value="0" @if(!($boardMetaData->block_delete ?? old('block_delete'))) checked @endif/>
                    <label for="blockDelete_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[block_delete]" id="grpBlockDelete" class="form-check-input" value="1" />
                    <label for="grpBlockDelete" class="form-check-label">
                        그룹적용
                    </label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="all[block_delete]" id="allBlockDelete" class="form-check-input" value="1" />
                    <label for="allBlockDelete" class="form-check-label">
                        전체적용
                    </label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="protectPostDay" class="col-sm-2 col-form-label">게시글 수정/삭제 금지 기간</label>
            <div class="col-sm-8">
                <div class="row">
                    <div class="col-auto">
                        <input type="number" name="protect_post_day" id="protectPostDay" class="form-control" value="{{ $boardMetaData->protect_post_day ?? old('protect_post_day') }}" />
                    </div>
                    <div class="col align-self-center">
                        일이 지난 원글은 수정 및 삭제가 불가합니다.
                    </div>
                </div>
                <div class="form-text text-muted">
                    0 이면 항상 수정 및 삭제 가능
                </div>
            </div>
            <div class="col-sm-2">
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="grp[protect_post_day]" id="grpProtectPostDay" class="form-check-input" value="1" />
                    <label for="grpProtectPostDay" class="form-check-label">
                        그룹적용
                    </label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="all[protect_post_day]" id="allProtectPostDay" class="form-check-input" value="1" />
                    <label for="allProtectPostDay" class="form-check-label">
                        전체적용
                    </label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="protectCommentDay" class="col-sm-2 col-form-label">댓글 수정/삭제 금지 기간</label>
            <div class="col-sm-8">
                <div class="row">
                    <div class="col-auto">
                        <input type="number" name="protect_comment_day" id="protectCommentDay" class="form-control" value="{{ $boardMetaData->protect_comment_day ?? old('protect_comment_day') }}" />
                    </div>
                    <div class="col align-self-center">
                        일이 지난 댓글은 수정 및 삭제가 불가합니다.
                    </div>
                </div>
                <div class="form-text text-muted">
                     0 이면 항상 수정 및 삭제 가능
                </div>
            </div>
            <div class="col-sm-2">
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="grp[protect_comment_day]" id="grpProtectCommentDay" class="form-check-input" value="1" />
                    <label for="grpProtectCommentDay" class="form-check-label">
                        그룹적용
                    </label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="all[protect_comment_day]" id="allProtectCommentDay" class="form-check-input" value="1" />
                    <label for="allProtectCommentDay" class="form-check-label">
                        전체적용
                    </label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="protectDeletePost_1" class="col-sm-2">게시글 보호 기능 (삭제 시)</label>
            <div class="col-sm-8">
                <div class="form-check form-check-inline">
                    <input type="radio" name="protect_delete_post" id="protectDeletePost_1" class="form-check-input" value="1" @if($boardMetaData->protect_delete_post ?? old('protect_delete_post')) checked @endif/>
                    <label for="protectDeletePost_1" class="form-check-label">예</label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="radio" name="protect_delete_post" id="protectDeletePost_0" class="form-check-input" value="0" @if(!($boardMetaData->protect_delete_post ?? old('protect_delete_post'))) checked @endif/>
                    <label for="protectDeletePost_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[protect_delete_post]" id="allProtectDeletePost" class="form-check-input" value="1" />
                    <label for="allProtectDeletePost" class="form-check-label">
                        그룹적용
                    </label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="all[protect_delete_post]" id="grpProtectDeletePost" class="form-check-input" value="1" />
                    <label for="grpProtectDeletePost" class="form-check-label">
                        전체적용
                    </label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="protectUpdatePost_1" class="col-sm-2">게시글 보호 기능 (수정 시)</label>
            <div class="col-sm-8">
                <div class="form-check form-check-inline">
                    <input type="radio" name="protect_update_post" id="protectUpdatePost_1" class="form-check-input" value="1" @if($boardMetaData->protect_update_post ?? old('protect_update_post')) checked @endif/>
                    <label for="protectUpdatePost_1" class="form-check-label">예</label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="radio" name="protect_update_post" id="protectUpdatePost_0" class="form-check-input" value="0" @if(!($boardMetaData->protect_update_post ?? old('protect_update_post'))) checked @endif/>
                    <label for="protectUpdatePost_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[protect_update_post]" id="allProtectUpdatePost" class="form-check-input" value="1" />
                    <label for="allProtectUpdatePost" class="form-check-label">
                        그룹적용
                    </label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="all[protect_update_post]" id="grpProtectUpdatePost" class="form-check-input" value="1" />
                    <label for="grpProtectUpdatePost" class="form-check-label">
                        전체적용
                    </label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="useCategory_1" class="col-sm-2">분류 기능</label>
            <div class="col-sm-8">
                <div class="form-check form-check-inline">
                    <input type="radio" name="use_category" id="useCategory_1" class="form-check-input" value="1" @if($boardMetaData->use_category ?? old('use_category')) checked @endif/>
                    <label for="useCategory_1" class="form-check-label">예</label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="radio" name="use_category" id="useCategory_0" class="form-check-input" value="0" @if(!($boardMetaData->use_category ?? old('use_category'))) checked @endif/>
                    <label for="useCategory_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_category]" id="grpUseCategory" class="form-check-input" value="1" />
                    <label for="grpUseCategory" class="form-check-label">
                        그룹적용
                    </label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="all[use_category]" id="allUseCategory" class="form-check-input" value="1" />
                    <label for="allUseCategory" class="form-check-label">
                        전체적용
                    </label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="usePersonal_1" class="col-sm-2">1:1 게시판</label>
            <div class="col-sm-8">
                <div class="form-check form-check-inline">
                    <input type="radio" name="use_personal" id="usePersonal_1" class="form-check-input" value="1" @if($boardMetaData->use_personal ?? old('use_personal')) checked @endif/>
                    <label for="usePersonal_1" class="form-check-label">예</label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="radio" name="use_personal" id="usePersonal_0" class="form-check-input" value="0" @if(!($boardMetaData->use_personal ?? old('use_personal'))) checked @endif/>
                    <label for="usePersonal_0" class="form-check-label">아니오</label>
                </div>
                <div class="form-text text-muted">
                    1:1 상담이 가능한 게시판으로 질문자가 관리자에게 1:1 답변을 받을 수 있습니다.
                </div>
            </div>
            <div class="col-sm-2">
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="grp[use_personal]" id="grpUsePersonal" class="form-check-input" value="1" />
                    <label for="grpUsePersonal" class="form-check-label">
                        그룹적용
                    </label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="all[use_personal]" id="allUsePersonal" class="form-check-input" value="1" />
                    <label for="allUsePersonal" class="form-check-label">
                        전체적용
                    </label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="useAnonymous_1" class="col-sm-2">익명 게시판</label>
            <div class="col-sm-8">
                <div class="form-check form-check-inline">
                    <input type="radio" name="use_anonymous" id="useAnonymous_1" class="form-check-input" value="1" @if($boardMetaData->use_anonymous ?? old('use_anonymous')) checked @endif/>
                    <label for="useAnonymous_1" class="form-check-label">예</label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="radio" name="use_anonymous" id="useAnonymous_0" class="form-check-input" value="0" @if(!($boardMetaData->use_anonymous ?? old('use_anonymous'))) checked @endif/>
                    <label for="useAnonymous_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_anonymous]" id="grpUseAnonymous" class="form-check-input" value="1" />
                    <label for="grpUseAnonymous" class="form-check-label">
                        그룹적용
                    </label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="all[use_anonymous]" id="allUseAnonymous" class="form-check-input" value="1" />
                    <label for="allUseAnonymous" class="form-check-label">
                        전체적용
                    </label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="anonymousExceptAdmin_1" class="col-sm-2">관리자 익명 제외</label>
            <div class="col-sm-8">
                <div class="form-check form-check-inline">
                    <input type="radio" name="anonymous_except_admin" id="anonymousExceptAdmin_1" class="form-check-input" value="1" @if($boardMetaData->anonymous_except_admin ?? old('anonymous_except_admin')) checked @endif/>
                    <label for="anonymousExceptAdmin_1" class="form-check-label">예</label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="radio" name="anonymous_except_admin" id="anonymousExceptAdmin_0" class="form-check-input" value="0" @if(!($boardMetaData->anonymous_except_admin ?? old('anonymous_except_admin'))) checked @endif/>
                    <label for="anonymousExceptAdmin_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[anonymous_except_admin]" id="grpAnonymousExceptAdmin" class="form-check-input" value="1" />
                    <label for="grpAnonymousExceptAdmin" class="form-check-label">
                        그룹적용
                    </label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="all[anonymous_except_admin]" id="allAnonymousExceptAdmin" class="form-check-input" value="1" />
                    <label for="allAnonymousExceptAdmin" class="form-check-label">
                        전체적용
                    </label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="anonymousName" class="col-sm-2 col-form-label">익명 이름</label>
            <div class="col-sm-8">
                <input type="text" name="anonymous_name" id="anonymousName" class="form-control" value="{{ $boardMetaData->anonymous_name ?? old('anonymous_name') }}"/>
                <div class="form-text text-muted">
                    익명 기능을 사용할 때 표시할 익명 이름을 정할 수 있습니다.<br/>
                    <strong>$NUM</strong>을 사용하면 회원마다 고유한 난수를 부여할 수 있습니다. (예: 익명_$NUM → 익명_12345678)<br/>
                    <strong>$DAILYNUM</strong>을 사용하면 매일 난수가 변경되고, $DOCNUM을 사용하면 문서마다 변경됩니다.<br/>
                    <strong>$DOCDAILYNUM</strong>을 사용하면 문서마다 각각, 그리고 매일 변경됩니다.<br/>
                    각 변수 뒤에 <strong>$DAILYNUM</strong>:5와 같이 1~8 숫자를 붙여 자릿수를 조정할 수 있습니다.
                </div>
            </div>
            <div class="col-sm-2">
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="grp[anonymous_name]" id="grpAnonymousName" class="form-check-input" value="1" />
                    <label for="grpAnonymousName" class="form-check-label">
                        그룹적용
                    </label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="all[anonymous_name]" id="allAnonymousName" class="form-check-input" value="1" />
                    <label for="allAnonymousName" class="form-check-label">
                        전체적용
                    </label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="useDownloadLog_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_download_log" id="useDownloadLog_1" class="form-check-input" value="1" @if($boardMetaData->use_download_log ?? old('use_download_log')) checked @endif/>
                    <label for="useDownloadLog_1" class="form-check-label">예</label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="radio" name="use_download_log" id="useDownloadLog_0" class="form-check-input" value="0" @if(!($boardMetaData->use_download_log ?? old('use_download_log'))) checked @endif/>
                    <label for="useDownloadLog_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_download_log]" id="grpUseDownloadLog" class="form-check-input" value="1" />
                    <label for="grpUseDownloadLog" class="form-check-label">
                        그룹적용
                    </label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="all[use_download_log]" id="allUseDownloadLog" class="form-check-input" value="1" />
                    <label for="allUseDownloadLog" class="form-check-label">
                        전체적용
                    </label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="usePostHistory_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_post_history" id="usePostHistory_1" class="form-check-input" value="1" @if($boardMetaData->use_post_history ?? old('use_post_history')) checked @endif/>
                    <label for="usePostHistory_1" class="form-check-label">예</label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="radio" name="use_post_history" id="usePostHistory_0" class="form-check-input" value="0" @if(!($boardMetaData->use_post_history ?? old('use_post_history'))) checked @endif/>
                    <label for="usePostHistory_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_post_history]" id="grpUsePostHistory" class="form-check-input" value="1" />
                    <label for="grpUsePostHistory" class="form-check-label">
                        그룹적용
                    </label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="all[use_post_history]" id="allUsePostHistory" class="form-check-input" value="1" />
                    <label for="allUsePostHistory" class="form-check-label">
                        전체적용
                    </label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="useLinkClickLog_1" class="col-sm-2 col-form-label">Link 클릭 기록</label>
            <div class="col-sm-8">
                <div class="form-check form-check-inline">
                    <input type="radio" name="use_link_click_log" id="useLinkClickLog_1" class="form-check-input" value="1" @if(($boardMetaData->use_link_click_log ?? old('use_link_click_log'))) checked @endif />
                    <label for="useLinkClickLog_1" class="form-check-label">예</label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="radio" name="use_link_click_log" id="useLinkClickLog_0" class="form-check-input" value="0" @if(!($boardMetaData->use_link_click_log ?? old('use_link_click_log'))) checked @endif />
                    <label for="useLinkClickLog_0" class="form-check-label">아니오</label>
                </div>
                <div class="form-text text-muted">
                    누가 어떤 Link를 클릭했는지 기록를 남깁니다.
                </div>
            </div>
            <div class="col-sm-2">
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="grp[use_link_click_log]" id="grpUseLinkClickLog" class="form-check-input" value="1" />
                    <label for="grpUseLinkClickLog" class="form-check-label">
                        그룹적용
                    </label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="all[use_link_click_log]" id="allUseLinkClickLog" class="form-check-input" value="1" />
                    <label for="allUseLinkClickLog" class="form-check-label">
                        전체적용
                    </label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="useCommentHistory_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_comment_history" id="useCommentHistory_1" class="form-check-input" value="1" @if(($boardMetaData->use_comment_history ?? old('use_comment_history'))) checked @endif />
                    <label for="useCommentHistory_1" class="form-check-label">예</label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="radio" name="use_comment_history" id="useCommentHistory_0" class="form-check-input" value="0" @if(!($boardMetaData->use_comment_history ?? old('use_comment_history'))) checked @endif />
                    <label for="useCommentHistory_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_comment_history]" id="grpUseCommentHistory" class="form-check-input" value="1" />
                    <label for="grpUseCommentHistory" class="form-check-label">
                        그룹적용
                    </label>
                </div>
                <div class="form-check form-check-inline">
                    <input type="checkbox" name="all[use_comment_history]" id="allUseCommentHistory" class="form-check-input" value="1" />
                    <label for="allUseCommentHistory" 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: {
        block_delete: {required: true, number: true},
        protect_post_day: {required: true, number: true, min: 0, max: 365},
        protect_comment_day: {required: true, number: true, min: 0, max: 365},
        protect_delete_post: {required: true, number: true},
        protect_update_post: {required: true, number: true},
        use_category: {required: true, number: true},
        use_personal: {required: true, number: true},
        use_anonymous: {required: true, number: true},
        anonymous_except_admin: {required: true, number: true},
        anonymous_name: {required: true, maxlength: 100},
        use_download_log: {required: true, number: true},
        use_post_history: {required: true, number: true},
        use_link_click_log: {required: true, number: true},
        use_comment_history: {required: true, number: true}
    }
});
</script>
@endsection
