@extends('layout.app')
@section('scripts')
    <script>
        const i18n = {
            common: {
                error_occurred: "{{ __('app.common.error_occurred') }}"
            },
            blog: {
                confirm_save: "{{ __('app.blog.confirm_save') }}",
                confirm_delete: "{{ __('app.blog.confirm_delete') }}"
            }
        };
    </script>
    <link rel="stylesheet" href="{{ asset("css/blog/edit.css") . "?rnd=" . rand(0, 1000000000) }}">
    <script src="{{ asset('/js/blog/blog.js') }}"></script>
@endsection

@section('content')

    <h2>Post hinzufügen</h2>
    <div class="blogEdit">
        Veröffentlichen? <input type="checkbox" id="blogPublished_new" checked><br /><br />

        Sprache:
        <select id="blogLanguage_new" name="language" autocomplete="off">
            <option value="de">Deutsch</option>
            <option value="en">Englisch</option>
        </select><br /><br />

        <label for="blogTitle_new">Titel:<br />
        </label><input id="blogTitle_new" type="text" value="" placeholder="Titel eingeben...">
        <br /><br />

        <label for="blogBody_new">Inhalt:</label><br />
        <textarea cols="64" rows="8" maxlength="2000" id="blogBody_new" placeholder="Text/HTML eingeben..."></textarea>
        <br />
        <br />
        <button onclick="addBlog()" id="blogEdit_new">Hinzufügen</button><br /><br />

    </div>

    <h2>Posts ändern/löschen</h2>
    <br />

    @foreach($blogs as $blog)
        <div class="blogEdit">
            <b>Erstellt von: {{$blog->byUser()->first()->name}} - Erstellt am: {{ $blog->created_at }} - Verändert am: {{ $blog->updated_at }}</b><br /><br />

            Veröffentlicht: <input type="checkbox" id="blogPublished_{{$blog->id}}"{{ $blog->published ? " checked" : "" }}><br /><br />

            Sprache:
            <select id="blogLanguage_{{ $blog->id }}" name="language" autocomplete="off">
                <option value="de"{{ ($blog->language == "de" ? " selected" : "") }}>Deutsch</option>
                <option value="en"{{ ($blog->language == "en" ? " selected" : "") }}>Englisch</option>
            </select><br /><br />

            <button onclick="deleteBlog({{ $blog->id }})" id="blogDelete_{{ $blog->id }}">Löschen</button><br /><br />

            <label for="blogTitle_{{ $blog->id }}">Titel:<br />
            </label><input id="blogTitle_{{ $blog->id }}" type="text" value="{{ $blog->title }}">
            <br /><br />

            <label for="blogBody_{{$blog->id}}">Inhalt:</label><br />
            <textarea cols="64" rows="8" maxlength="2000" id="blogBody_{{$blog->id}}">{!! $blog->body !!}</textarea>
            <br />
            <br />
            <button onclick="editBlog({{ $blog->id }})" id="blogEdit_{{ $blog->id }}">Speichern</button><br /><br />

        </div>
    @endforeach
    <br /><br />
    {{ $blogs->links() }}
    <br /><br />
@endsection
