@extends('admin.layouts.app')

@section('content')
<div class="container-fluid">
    <h2>문서 @if($documentID) 수정 @else 등록 @endif</h2>
    <hr/>
    @include('admin.messages')

    <form name="f_admin_write" id="fAdminWrite" method="post" action="{{ $actionURL }}" enctype="multipart/form-data">
        @csrf
        @if($documentID)
            <input type="hidden" name="document_id" value="{{ $documentID }}" />
            @method('PUT')
        @endif
        <div class="row mb-3">
            <label for="code" class="col-sm-2 col-form-label">주소</label>
            <div class="col-sm-10">
                {{ BASE_URL }} / <input type="text" name="code" id="code" class="form-control d-inline w-auto" value="{{ $documentData->code ?? old('code') }}" />
            </div>
        </div>
        <div class="row mb-3">
            <label for="subject" class="col-sm-2 col-form-label">제목</label>
            <div class="col-sm-10">
                <input type="text" name="subject" id="subject" class="form-control" value="{{ $documentData->subject ?? old('subject') }}" />
            </div>
        </div>
        <div class="row mb-3">
            <label for="content" class="col-sm-2 col-form-label">내용</label>
            <div class="col-sm-10">
                <?php echo htmlEditor('content', ($documentData->content ?? old('content')), 'form-control dhtml-editor', true, false, '', 8, 'content'); ?>
            </div>
        </div>
        @isset($documentData->updated_at)
        <div class="row mb-3">
            <label class="col-sm-2">수정일시</label>
            <div class="col-sm-10">
                {{ $documentData->updated_at }}
            </div>
        </div>
        @endisset
        @isset($documentData->created_at)
        <div class="row">
            <label class="col-sm-2">등록일시</label>
            <div class="col-sm-10">
                {{ $documentData->created_at }}
            </div>
        </div>
        @endisset
        <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.page.document.index') }}">취소하기</button>
        </div>
    </form>
</div>

<script type="module">
$("#fAdminWrite").validate({
    rules: {
        code: {required: true, minlength: 3, maxlength: 50, alpha_dash: true},
        subject: {required: true, maxlength: 150},
        content: {'required_tinymce': true}
    }
});
</script>
@endsection
