@extends('layouts.admin-layout')
@section('title', 'Delivery Page Cms')
@section('content')

    <div class="content-wrapper">

        <section class="content ">
            <div class="container-fluid">

                <div class="row">
                    <!-- left column -->
                    <div class="col-md-12 mt-5">
                        <form action="{{ route('admin.pages.update', ['slug' => $page->slug]) }}" method="post"
                            class="category-form" enctype="multipart/form-data">
                            @csrf
                            <input type="hidden" name="slug" value="{{ $page->slug }}">
                            <input type="hidden" name="media_collections[]" value="banner_image">
                            <div class="card card-dark card-box-shadow">
                                <div class="card-header">
                                    <h3 class="card-title">(Delivery Page)</h3>
                                </div>

                                <div class="card-body">
                                    <div class="tab-content text-center">

                                        <h2 class="text-center mb-5">Banner Section</h2>

                                        <div class="row">
                                            <!-- Banner Section -->
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label for="title">Banner Title</label><br>
                                                    <input type="text" required class="form-control form__field"
                                                        name="banner_heading" id="title"
                                                        value="{{ $content['banner_heading'] ?? '' }}">
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label for="banner_image">Banner Image</label><br>
                                                    <input type="file" class="form-control form__field"
                                                        name="banner_image" id="cta_image">
                                                    @if ($page->hasMedia('banner_image'))
                                                        <label for="existing_background_banner_image"></label>
                                                        @foreach ($page->getMedia('banner_image') as $media)
                                                            <img src="{{ $media->getUrl() }}" alt="Existing Banner Image"
                                                                style="max-width: 200px; max-height: 200px; margin-top: 10px; background-color: black">
                                                        @endforeach
                                                    @endif
                                                </div>
                                            </div>
                                            <div class="col-md-12">
                                                <div class="form-group">
                                                    <label for="title">Main Heading</label><br>
                                                    <input type="text" required class="form-control form__field"
                                                        name="story_heading" id="title"
                                                        value="{{ $content['story_heading'] ?? '' }}">
                                                </div>
                                            </div>
                                            <div class="col-md-12">
                                                <label for="">Content *</label>
                                                <textarea name="story_des" rows="4" placeholder="Description" class="form-control form__field" id="summernote1">{!! $content['story_des'] ?? '' !!}</textarea>
                                                <small class="text-danger">
                                                    @error('story_des')
                                                        {{ $message }}
                                                    @enderror
                                                </small>

                                            </div>
                                        </div>
                                    </div>

                                </div>
                            </div>
                            <br>
                            <div class="text-center">
                                <input type="submit" value="Submit" class="btn btn-primary">
                            </div>
                            <br>
                        </form>

                        <!-- /.card -->
                    </div>
                </div>

            </div>
        </section>
    </div>
@endsection
@section('script')
    <script>
        $('#summernote1').summernote({
            placeholder: 'Hello Admin',
            tabsize: 2,
            height: 100
        });
    </script>
    <script>
        function showImagePreview(input, previewId) {
            const preview = document.getElementById(previewId);

            if (input.files && input.files[0]) {
                const reader = new FileReader();

                reader.onload = function(e) {
                    preview.src = e.target.result;
                    preview.style.display = 'block';
                };

                reader.readAsDataURL(input.files[0]);
            }
        }


        const ourDrinkHomeSecondSecImageInput = document.getElementById('ourDrinkHomeSecondSecImageInput');
        ourDrinkHomeSecondSecImageInput.addEventListener('change', function() {
            showImagePreview(this, 'ourDrinkPageFirstImagePreview');
        });
    </script>
@endsection
