@extends('dashboard.main')

@section('main-content')

<div class="container-fluid">

    <div class="card shadow">

        <div class="card-header">

            <h3>Edit Blog</h3>

        </div>

        <div class="card-body">

            @if(session('success'))

                <div class="alert alert-success">
                    {{ session('success') }}
                </div>

            @endif

            <form action="{{ route('blogs.update',$blog->id) }}"
                  method="POST"
                  enctype="multipart/form-data">

                @csrf
                @method('PUT')

                <!-- Blog Title -->

                <div class="mb-3">

                    <label class="form-label">
                        Blog Title
                    </label>

                    <input type="text"
                           name="title"
                           value="{{ old('title',$blog->title) }}"
                           class="form-control @error('title') is-invalid @enderror">

                    @error('title')
                        <div class="invalid-feedback">
                            {{ $message }}
                        </div>
                    @enderror

                </div>

                <!-- Short Description -->

                <div class="mb-3">

                    <label class="form-label">
                        Short Description
                    </label>

                    <textarea rows="4"
                              name="short_description"
                              class="form-control @error('short_description') is-invalid @enderror">{{ old('short_description',$blog->short_description) }}</textarea>

                    @error('short_description')
                        <div class="invalid-feedback">
                            {{ $message }}
                        </div>
                    @enderror

                </div>

                <!-- Description -->

                <div class="mb-3">

                    <label class="form-label">
                        Full Description
                    </label>

                    <textarea rows="8"
                              name="description"
                              class="form-control @error('description') is-invalid @enderror">{{ old('description',$blog->description) }}</textarea>

                    @error('description')
                        <div class="invalid-feedback">
                            {{ $message }}
                        </div>
                    @enderror

                </div>

                <!-- Current Image -->

                <div class="mb-3">

                    <label class="form-label">

                        Current Image

                    </label>

                    <br>

                    @if($blog->image)

                        <img src="{{ asset('uploads/blogs/'.$blog->image) }}"
                             width="180"
                             class="rounded border shadow">

                    @else

                        <img src="{{ asset('assets/images/no-image.png') }}"
                             width="180"
                             class="rounded border">

                    @endif

                </div>

                <!-- Upload Image -->

                <div class="mb-3">

                    <label class="form-label">

                        Change Image

                    </label>

                    <input type="file"
                           name="image"
                           class="form-control @error('image') is-invalid @enderror">

                    @error('image')
                        <div class="invalid-feedback">
                            {{ $message }}
                        </div>
                    @enderror

                </div>

                <!-- Status -->

                <div class="mb-4">

                    <label class="form-label">

                        Status

                    </label>

                    <select name="status"
                            class="form-select @error('status') is-invalid @enderror">

                        <option value="active"
                            {{ $blog->status=='active' ? 'selected' : '' }}>
                            Active
                        </option>

                        <option value="inactive"
                            {{ $blog->status=='inactive' ? 'selected' : '' }}>
                            Inactive
                        </option>

                    </select>

                    @error('status')
                        <div class="invalid-feedback">
                            {{ $message }}
                        </div>
                    @enderror

                </div>

                <!-- Buttons -->

                <button class="btn btn-success">

                    <i class="fas fa-save"></i>

                    Update Blog

                </button>

                <a href="{{ route('blogs.index') }}"
                   class="btn btn-secondary">

                    Cancel

                </a>

            </form>

        </div>

    </div>

</div>

@endsection
