@extends('admin.layouts.app')

@section('content')
<div class="container-fluid">
    <h2>기본</h2>
    <hr/>
    @include('admin.messages')
    @include('admin.config.setting.navTabs')

    <form name="f_admin_write" id="fAdminWrite" method="post" action="{{ route('admin.config.setting.basic.store') }}" enctype="multipart/form-data">
        @csrf
        <div class="row mb-3">
            <label for="adminTitle" class="col-sm-2 col-form-label">관리자 제목</label>
            <div class="col-sm-10">
                <input type="text" name="admin_title" id="adminTitle" class="form-control" value="{{ config('admin_title') }}" />
            </div>
        </div>
        <div class="row mb-3">
            <label for="siteTitle" class="col-sm-2 col-form-label">홈페이지 제목</label>
            <div class="col-sm-10">
                <input type="text" name="site_title" id="siteTitle" class="form-control" value="{{ config('site_title') }}" />
            </div>
        </div>
        <div class="row mb-3">
            <label for="masterKey" class="col-sm-2 col-form-label">최고관리자</label>
            <div class="col-sm-10">
                <select name="master_key" id="masterKey" class="form-select w-auto">
                    <option value="">선택하세요.</option>
                    @foreach($admins as $admin)
                        <option value="{{ $admin->id }}" {{ (config('master_key')) == $admin->id ? 'selected' : '' }} >
                            {{ $admin->name }} ({{ $admin->sid }})
                        </option>
                    @endforeach
                </select>
            </div>
        </div>
        <div class="row mb-3">
            <label for="masterEmail" class="col-sm-2 col-form-label">관리자 이메일</label>
            <div class="col-sm-10">
                <input type="email" name="master_email" id="masterEmail" class="form-control" value="{{ config('master_email') }}" />
                <div class="form-text text-muted">관리자가 보내고 받는 용도로 사용하는 메일 주소를 입력합니다.</div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="masterName" class="col-sm-2 col-form-label">관리자 이메일 이름</label>
            <div class="col-sm-10">
                <input type="text" name="master_name" id="masterName" class="form-control" value="{{ config('master_name') }}" />
                <div class="form-text text-muted">관리자가 보내고 받는 용도로 사용하는 메일의 발송자 이름을 입력합니다.</div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="footerScript" class="col-sm-2 col-form-label">하단 Script</label>
            <div class="col-sm-10">
                <textarea name="footer_script" id="footerScript" class="form-control" rows="5">{{ config('footer_script') }}</textarea>
                <div class="form-text text-muted">페이지 하단에 스크립트를 삽입합니다. 통계 스크립트 등을 입력해주시면 됩니다. 관리자 페이지에는 반영되지 않습니다.</div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="spamWord" class="col-sm-2 col-form-label">금지 단어</label>
            <div class="col-sm-10">
                <textarea name="spam_word" id="spamWord" class="form-control" rows="10">{{ config('spam_word') }}</textarea>
                <div class="form-text text-muted">필터링하고 싶은 단어를 쉼표로 구분하여 입력해주세요, 해당 단어는 원글작성, 댓글작성의 경우에 입력이 제한되어 있습니다.</div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="whiteIframe" class="col-sm-2 col-form-label">허용 Iframe</label>
            <div class="col-sm-10">
                <textarea name="white_iframe" id="whiteIframe" class="form-control" rows="10">{{ config('white_iframe') }}</textarea>
                <div class="form-text text-muted">&lt;iframe&gt; 태그에 허용 할 URL을 지정할 수 있습니다. 주소 맨 앞에 http://, https:// 를 제외하고 입력합니다.</div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="ipDisplayStyle" class="col-sm-2 col-form-label">IP 공개시 표시 형식</label>
            <div class="col-sm-10">
                <select name="ip_display_style" id="ipDisplayStyle" class="form-select w-auto">
                    <option value="0001" {{ (config('ip_display_style', '0001')) == '0001' ? 'selected' : '' }}>&#9825;.&#9825;.&#9825;.127</option>
                    <option value="0010" {{ (config('ip_display_style', '0010')) == '0010' ? 'selected' : '' }}>&#9825;.&#9825;.127.&#9825;</option>
                    <option value="0011" {{ (config('ip_display_style', '0011')) == '0011' ? 'selected' : '' }}>&#9825;.&#9825;.127.127</option>
                    <option value="0100" {{ (config('ip_display_style', '0100')) == '0100' ? 'selected' : '' }}>&#9825;.127.&#9825;.&#9825;</option>
                    <option value="0101" {{ (config('ip_display_style', '0101')) == '0101' ? 'selected' : '' }}>&#9825;.127.&#9825;.127</option>
                    <option value="0110" {{ (config('ip_display_style', '0110')) == '0110' ? 'selected' : '' }}>&#9825;.127.127.&#9825;</option>
                    <option value="0111" {{ (config('ip_display_style', '0111')) == '0111' ? 'selected' : '' }}>&#9825;.127.127.127</option>
                    <option value="1000" {{ (config('ip_display_style', '1000')) == '1000' ? 'selected' : '' }}>127.&#9825;.&#9825;.&#9825;</option>
                    <option value="1001" {{ (config('ip_display_style', '1001')) == '1001' ? 'selected' : '' }}>127.&#9825;.&#9825;.127</option>
                    <option value="1010" {{ (config('ip_display_style', '1010')) == '1010' ? 'selected' : '' }}>127.&#9825;.127.&#9825;</option>
                    <option value="1011" {{ (config('ip_display_style', '1011')) == '1011' ? 'selected' : '' }}>127.&#9825;.127.127</option>
                    <option value="1100" {{ (config('ip_display_style', '1100')) == '1100' ? 'selected' : '' }}>127.127.&#9825;.&#9825;</option>
                    <option value="1101" {{ (config('ip_display_style', '1101')) == '1101' ? 'selected' : '' }}>127.127.&#9825;.127</option>
                    <option value="1110" {{ (config('ip_display_style', '1110')) == '1110' ? 'selected' : '' }}>127.127.127.&#9825;</option>
                </select>
                <div class="form-text text-muted">IP 를 일부공개하는 페이지에서 공개하는 형식입니다., 관리자에게는 IP 전체가 보입니다.</div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="newPostSecond" class="col-sm-2 col-form-label">새로운 글쓰기 시간</label>
            <div class="col-sm-10">
                <div class="row">
                    <div class="col-sm-3">
                        <div class="input-group">
                            <input type="text" name="new_post_second" id="newPostSecond" class="form-control only-digits-input" value="{{ config('new_post_second', NEW_POST_SECOND) }}" />
                            <span class="input-group-text">초</span>
                        </div>
                    </div>
                </div>
                <div class="form-text text-muted">초 이상 지나야 새로운 글쓰기가 가능합니다. (0 을 입력하면 확인하지 않음)</div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="openCurrentVisitor" class="col-sm-2">현재 접속자 공개 여부</label>
            <div class="col-sm-10">
                <div class="form-check">
                    <input type="checkbox" name="open_current_visitor" id="openCurrentVisitor" class="form-check-input" value="1" {{ (config('open_current_visitor') ? 'checked' : '') }}/>
                    <label for="openCurrentVisitor" class="form-check-inline">현재접속자를 공개합니다.</label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="currentVisitorMinute" class="col-sm-2 col-form-label">현재 접속자 기준</label>
            <div class="col-sm-10">
                <div class="row">
                    <div class="col-sm-3">
                        <input type="text" name="current_visitor_minute" id="currentVisitorMinute" class="form-control me-2 only-digits-input" value="{{ config('current_visitor_minute', CURRENT_VISITOR_MINUTE) }}" size="20"/>
                    </div>
                    <div class="col align-self-center">
                        <div class="form-text text-muted">분 이내의 접속자만 현재 접속자로 인정</div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="cacheExpireTime" class="col-sm-2 col-form-label">캐시 생성 시간</label>
            <div class="col-sm-10">
                <div class="row">
                    <div class="col-sm-3">
                        <div class="input-group">
                            <input type="text" name="cache_expire_time" id="cacheExpireTime" class="form-control only-digits-input" value="{{ config('cache_expire_time', CACHE_EXPIRE_TIME) }}" />
                            <span class="input-group-text">초</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="verifyExpiresAt" class="col-sm-2 col-form-label">인증번호 만료시간</label>
            <div class="col-sm-10">
                <div class="row">
                    <div class="col-sm-3">
                        <div class="input-group">
                            <input type="text" name="verify_expires_at" id="verifyExpiresAt" class="form-control only-digits-input" value="{{ config('verify_expires_at', VERIFY_EXPIRES_AT) }}" />
                            <span class="input-group-text">분</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="verifySendLimit" class="col-sm-2 col-form-label">인증번호 발송 분당 제한 수</label>
            <div class="col-sm-10">
                <div class="row">
                    <div class="col-sm-3">
                        <div class="input-group">
                            <input type="text" name="verify_send_limit" id="verifySendLimit" class="form-control only-digits-input" value="{{ config('verify_send_limit', VERIFY_SEND_LIMIT) }}" />
                            <span class="input-group-text">회</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label class="col-sm-2">게시물 이동 및 복사 기록</label>
            <div class="col-sm-10">
                <div class="form-check-inline">
                    <input type="radio" name="use_post_copy_log" id="usePostCopyLog_0" class="form-check-input" value="1" {{ (config('use_post_copy_log')) ? 'checked' : '' }} />
                    <label for="usePostCopyLog_0" class="form-check-label">예</label>
                </div>
                <div class="form-check-inline">
                    <input type="radio" name="use_post_copy_log" id="usePostCopyLog_1" class="form-check-input" value="0" {{ !(config('use_post_copy_log')) ? 'checked' : '' }} />
                    <label for="usePostCopyLog_1" class="form-check-label">아니오</label>
                </div>
                <div class="form-text text-muted">게시글이 이동/복사가 기록됩니다.</div>
            </div>
        </div>
        <div class="row mb-3">
            <label class="col-sm-2">검색기록 저장 여부</label>
            <div class="col-sm-10">
                <div class="form-check-inline">
                    <input type="radio" name="use_header_search_log" id="useHeaderSearchLog_0" class="form-check-input" value="1" {{ (config('use_header_search_log')) ? 'checked' : '' }} />
                    <label for="useHeaderSearchLog_0" class="form-check-label">예</label>
                </div>
                <div class="form-check-inline">
                    <input type="radio" name="use_header_search_log" id="useHeaderSearchLog_1" class="form-check-input" value="0" {{ !(config('use_header_search_log')) ? 'checked' : '' }} />
                    <label for="useHeaderSearchLog_1" class="form-check-label">아니오</label>
                </div>
                <div class="form-text text-muted">사용자가 검색한 단어가 기록됩니다.</div>
            </div>
        </div>
        <hr/>
        <div class="form-group text-end">
            <button type="submit" class="btn btn-success">저장하기</button>
        </div>
    </form>
</div>

<script type="module">
$("#fAdminWrite").validate({
    rules: {
        admin_title: {required: true},
        site_title: {required: true},
        master_email: {required: true, email: true},
        master_name: {required: true},
        footer_script: {maxlength: 2000},
        spam_word: {required: false, maxlength: 2000},
        white_iframe: {maxlength: 2000},
        ip_display_style: {required: true, number: true},
        new_post_second: {required: true, min: 0},
        open_current_visitor: {required: false, number: true},
        current_visitor_minute: {required: true, min: 0},
        use_post_copy_log: {required: true},
        use_header_search_log: {required: true},
        cache_expire_time: {required: true, number: true, min: 1, max: 86400},
        verify_expires_at: {required: true, number: true, min: 1, max: 3600},
        verify_send_limit: {required: true, number: true}
    }
});
</script>
@endsection
