@section('title', 'Edit Press Releases')
@extends('layout.admin')
@section('content')
<div class="card">

    <div class="card-body">
        <div class="card-title"></div>
        <form action="{{ route('blogs.update', ['blog' => $blog->id]) }}" method="post" enctype="multipart/form-data">
            @method('patch')
            @csrf
            <fieldset>
                <legend>Edit Press Releases</legend>
                @if($errors->any())
                <div class="alert alert-danger">
                {!! implode('', $errors->all('<div>:message</div>')) !!}
                </div>
                @endif
                <div class="row mb-3">
                    <div class="col-sm-12 mb-3">
                        <label class="form-label">Title</label>
                        <input type="text" name="title" value="{{$blog->title}}" require class="form-control">
                    </div>
                    <div class="col-sm-12 mb-3">
                        <label class="form-label">Category</label>
                        <select name="category_id"  require class="form-control">
                            @foreach($categories as $category)
                            <option value="{{ $category->id }}"  {{ $blog->category_id === $category->id ? 'selected' : '' }}>{{ $category->name }}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="col-sm-12 mb-3">
                        <label class="form-label">Publish Date</label>
                        <input type="date" name="publish_date" value="{{$blog->publish_date}}" require class="form-control">
                    </div>
                    <div class="col-sm-12 mb-3">
                        <label class="form-label">Thumbnail</label>
                        <input type="file" name="image" value="" require class="form-control">
                    </div>
                    <div class="col-sm-12 mb-3">
                        <label class="form-label">Meta Title</label>
                        <input type="text" name="meta[title]" value="{{$blog->meta_data->title}}" require
                            class="form-control">
                    </div>
                    <div class="col-sm-12 mb-3">
                        <label class="form-label">Meta Description</label>
                        <input type="text" name="meta[description]" value="{{$blog->meta_data->description}}" require
                            class="form-control">
                    </div>
                    <div class="col-sm-12 mb-3">
                        <label class="form-label">Meta Keyword</label>
                        <input type="text" name="meta[keyword]" value="{{$blog->meta_data->keyword}}"
                            class="form-control">
                    </div>
                    <div class="col-sm-12 mb-3">
                        <label class="form-label">Blog</label>
                        <textarea name="description" id="editor" class="form-control"></textarea>
                    </div>
                </div>
            </fieldset>
            <button type="submit" class="btn btn-primary">Update</button>
        </form>
    </div>
</div>
@endsection

@section('extra')
<script>
    $(document).ready(function () {
        $('#editor').summernote()
        $('#editor').summernote('code', '{!! $blog->description !!}')
        var noteBar = $('.note-toolbar');
        noteBar.find('[data-toggle]').each(function () {
            $(this).attr('data-bs-toggle', $(this).attr('data-toggle')).removeAttr('data-toggle');
        });
    })
</script>
@endsection