@extends("admin.layout.base")
@extends("admin.layout.header")

@section("title")
    Nyhed - Rediger
@endsection

@section("path")
    <a href="{{route('news.edit', ['news' => $news])}}" class="text-white">Rediger nyhed</a> /
@endsection

@section("content")
    <style>
        .ck-editor__main {
            margin-bottom: 1rem;
        }
    </style>
    <script src="https://cdn.ckeditor.com/ckeditor5/21.0.0/classic/ckeditor.js"></script>
    <h1>Rediger nyhed:</h1>
    <form method="post" action="{{route("news.update", ["news" => $news])}}">
        @csrf
        @method("PUT")
        <label for="title">Navn</label>
        <input value="{{$news->name}}" type="text" name="name" id="title" required>
        <textarea name="content" id="editor">{{$news->content}}</textarea>
        <input type="submit" class="btn btn-dark text-white" value="Rediger">
    </form>

    <script>
        ClassicEditor
            .create( document.querySelector( '#editor' ), {
                toolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote' ],
                heading: {
                    options: [
                        { model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph' },
                        { model: 'heading1', view: 'h3', title: 'Heading 1', class: 'sde-blue' },
                        { model: 'heading2', view: 'h4', title: 'Heading 2', class: 'sde-blue' }
                    ]
                }
            } )
            .catch( error => {
                console.log( error );
            } );

    </script>
@endsection
@section("scripts")
    <script>
        $(function() {
            $('form').areYouSure(
                {
                    message: 'It looks like you have been editing something. '
                        + 'If you leave before saving, your changes will be lost.'
                }
            );
        });
    </script>
@endsection