<x-app-layout>
    @section('title')
        Blog Create
    @endsection
    <!-- Page Heading -->
    <h1 class="h3 mb-2 text-gray-800">
        @can('Blog access')
            <a href="{{ route('admin.blogs.index') }}" class="btn btn-primary"><i class="fas fa-plus" aria-hidden="true"></i>
                Blog Listing
            </a>
        @endcan
    </h1>

    <!-- DataTales Example -->
    <div class="row">
        <div class="col-md-12">
            <form action="{{ route('admin.blogs.store') }}" method="POST" enctype="multipart/form-data" class="needs-validation" role="form" novalidate>
                @csrf
                <div class="card shadow mb-4">
                    <div class="card-header py-3">
                        <h6 class="m-0 font-weight-bold text-primary">Blog Form</h6>
                    </div>
                    <div class="card-body">
                        <div class="form-group">
                            <label class="mb-0" for="title">Title <span class="text-danger">*</span></label>
                            <input type="text" name="title" class="form-control @error('title') is-invalid @enderror" id="title" required />
                            @error('title')
                                <span class="text-danger">{{ $message }}</span>
                            @enderror
                        </div>

                        <div class="form-group">
                            <label class="mb-0" for="category_id">Category <span class="text-danger">*</span></label>
                            <select name="category_id" id="category_id" class="form-control @error('category_id') is-invalid @enderror">
                                @foreach ($categories as $row)
                                    <option value="{{ $row->id }}">{{ $row->name }}</option>
                                @endforeach
                            </select>
                            @error('category_id')
                                <span class="text-danger">{{ $message }}</span>
                            @enderror
                        </div>
                        <div class="form-group">
                            <label class="mb-0" for="image">Image <span class="text-danger">*</span></label>
                            <input type="file" name="image" id="image" class="mb-2 form-control @error('image') is-invalid @enderror" />
                            <div id="showImage" style="display: none" class="mt-2">
                                <img class="img-fuild" width="150px" height="120px" id="prevImg" src="#" alt="" style="border: 1px dotted #000" >
                                @error('image')
                                    <span class="text-danger">{{ $message }}</span>
                                @enderror
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="mb-0" for="short_description">Short Description <span class="text-danger">*</span></label>
                            <textarea class="form-control @error('short_description') is-invalid @enderror" cols="30" rows="5" id="short_description" name="short_description"></textarea>
                            @error('short_description')
                                <span class="text-danger">{{ $message }}</span>
                            @enderror
                        </div>

                        <div class="form-group">
                            <label class="mb-0" for="description">Description <span class="text-danger">*</span></label>
                            <textarea class="summernote @error('description') is-invalid @enderror" id="description" name="description"></textarea>
                            @error('description')
                                <span class="text-danger">{{ $message }}</span>
                            @enderror
                        </div>

                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="mb-0" for="status">Type and press Enter to add tags <span class="text-danger">*</span></label>
                                    <input name="tags" class="form-control @error('tags') is-invalid @enderror" type="text" id="tags" placeholder="tags" />
                                    @error('tags')
                                        <span class="text-danger">{{ $message }}</span>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="mb-0" for="status">Status <span class="text-danger">*</span></label>
                                    <select name="status" id="status" class="form-control @error('status') is-invalid @enderror">
                                        <option value="1">Active</option>
                                        <option value="0">Inactive</option>
                                    </select>
                                    @error('status')
                                        <span class="text-danger">{{ $message }}</span>
                                    @enderror
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="card-footer text-right">
                        <button type="submit" class="btn btn-success">Save</button>
                    </div>

                </div>
            </form>
        </div>
    </div>
    @section('script')

    <script>
        $(document).ready(() => {
            // Banner Image
            $('#image').change(function() {
                const file = this.files[0];
                console.log(file);
                if (file) {
                    let reader = new FileReader();
                    reader.onload = function(event) {
                        console.log(event.target.result);
                        $('#prevImg').attr('src', event.target.result);
                        $("#showImage").css('display','block')
                    }
                    reader.readAsDataURL(file);
                }
            });

        });
    </script>

    <script>
    $('input[name="tags"]').amsifySuggestags({
        type : 'amsify',
        suggestions: ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupitor', 'Uranus', 'Neptune', 'Pluto'],
    });
    </script>


    @endsection
</x-app-layout>
