@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>{{ __('app.blog.add_post') }}</h2>
    <div class="blogEdit">
        {{ __('app.blog.published') }} <input type="checkbox" id="blogPublished_new" checked><br /><br />

        {{ __('app.blog.language') }}:
        <select id="blogLanguage_new" name="language" autocomplete="off">
            <option value="de">{{ __('app.language.de') }}</option>
            <option value="en">{{ __('app.language.en') }}</option>
        </select><br /><br />

        <label for="blogTitle_new">{{ __('app.blog.title') }}:<br />
        </label><input id="blogTitle_new" type="text" value="" placeholder="{{ __('app.blog.title_placeholder') }}">
        <br /><br />

        <label for="blogBody_new">{{ __('app.blog.content') }}:</label><br />
        <textarea cols="64" rows="8" maxlength="2000" id="blogBody_new" placeholder="{{ __('app.blog.content_placeholder') }}"></textarea>
        <br />
        <br />
        <button onclick="addBlog()" id="blogEdit_new">{{ __('app.blog.add') }}</button><br /><br />

    </div>

    <h2>{{ __('app.blog.edit_delete_posts') }}</h2>
    <br />

    @foreach($blogs as $blog)
        <div class="blogEdit">
            <b>{{ __('app.blog.created_by') }}: {{$blog->byUser()->first()->name}} - {{ __('app.blog.created_at') }}: {{ $blog->created_at }} - {{ __('app.blog.updated_at') }}: {{ $blog->updated_at }}</b><br /><br />

            {{ __('app.blog.published') }} <input type="checkbox" id="blogPublished_{{$blog->id}}"{{ $blog->published ? " checked" : "" }}><br /><br />

            {{ __('app.blog.language') }}:
            <select id="blogLanguage_{{ $blog->id }}" name="language" autocomplete="off">
                <option value="de"{{ ($blog->language == "de" ? " selected" : "") }}>{{ __('app.language.de') }}</option>
                <option value="en"{{ ($blog->language == "en" ? " selected" : "") }}>{{ __('app.language.en') }}</option>
            </select><br /><br />

            <button onclick="deleteBlog({{ $blog->id }})" id="blogDelete_{{ $blog->id }}">{{ __('app.blog.delete') }}</button><br /><br />

            <label for="blogTitle_{{ $blog->id }}">{{ __('app.blog.title') }}:<br />
            </label><input id="blogTitle_{{ $blog->id }}" type="text" value="{{ $blog->title }}">
            <br /><br />

            <label for="blogBody_{{$blog->id}}">{{ __('app.blog.content') }}:</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 }}">{{ __('app.blog.save') }}</button><br /><br />

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