@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.notify.store') }}" enctype="multipart/form-data">
        @csrf
        <div class="row mb-3">
            <label for="useNotification" class="col-sm-2">알림 기능</label>
            <div class="col-sm-10">
                <div class="form-check">
                    <input type="checkbox" name="use_notification" id="useNotification" class="form-check-input" value="1" {{ config('use_notification') ? 'checked' : '' }} />
                    <label for="useNotification" class="form-check-inline">사용합니다.</label>
                </div>
                <div class="form-text text-muted">알림기능을 사용하시게 되면, 내 글에 댓글이 달리거나, 쪽지가 수신된 경우에 우측상단에 알림이 뜨게 됩니다.</div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="notificationPostReply" class="col-sm-2">내 글에 답변글이 달렸을 때 알림</label>
            <div class="col-sm-10">
                <div class="form-check">
                    <input type="checkbox" name="notification_post_reply" id="notificationPostReply" class="form-check-input" value="1" {{ config('notification_post_reply') ? 'checked' : '' }} />
                    <label for="notificationPostReply" class="form-check-label">
                        사용합니다.
                    </label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="notificationPostComment" class="col-sm-2">내 글에 댓글이 달렸을 때 알림</label>
            <div class="col-sm-10">
                <div class="form-check">
                    <input type="checkbox" name="notification_post_comment" id="notificationPostComment" class="form-check-input" value="1" {{ config('notification_post_comment') ? 'checked' : '' }} />
                    <label for="notificationPostComment" class="form-check-label">
                        사용합니다.
                    </label>
                </div>
            </div>
        </div>
        <div class="row mb-3">
            <label for="notificationPostCommentReply" class="col-sm-2">내 댓글에 댓글이 달렸을 때 알림</label>
            <div class="col-sm-10">
                <div class="form-check">
                    <input type="checkbox" name="notification_post_comment_reply" id="notificationPostCommentReply" class="form-check-input" value="1" {{ config('notification_post_comment_reply') ? 'checked' : '' }} />
                    <label for="notificationPostCommentReply" class="form-check-label">
                        사용합니다.
                    </label>
                </div>
            </div>
        </div>
        <hr/>
        <div class="form-group text-end">
            <button type="submit" class="btn btn-success">저장하기</button>
        </div>
    </form>
</div>

<script type="module">
$(function() {
    $(document).on('change', '#useNotification', function () {
        if ($(this).is(':checked')) {
            $('.chk').prop('checked', true).prop('disabled', false);
        } else {
            $('.chk').prop('checked', false).prop('disabled', true);
        }
    });
    @if(config('use_notification', '0'))
        $('.chk').prop('checked', false).prop('disabled', true);
    @endif
});
</script>
@endsection
