@extends('layouts.admin-layout')
@section('title', 'Contact Us')
@section('content')
    <style>
        .shadow-section {
            border: 1px solid #ddd;
            /* Light border around the section */
            box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
            /* Subtle shadow effect */
            border-radius: 8px;
            /* Rounded corners */
            padding: 20px;
            /* Add padding inside the section */
            margin-bottom: 20px;
            /* Space between core value sections */
            background-color: #fff;
            /* Background color */
        }

        .shadow-section img {
            border: 1px solid #ddd;
            /* Add border around images */
            border-radius: 8px;
            /* Rounded corners for images */
        }

        .text-end {
            text-align: end !important;
        }
    </style>
    <div class="content-wrapper">
        <section class="content">
            <div class="container-fluid">
                <div class="row">
                    <!-- left column -->
                    <div class="col-md-12 mt-5">
                        <!-- general form elements -->
                        <div class="card card-dark card-box-shadow">
                            <div class="card-header">
                                <h3 class="card-title">(Contact Us Page)</h3>
                            </div>
                            <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">
                                <input type="hidden" name="media_collections[]" value="reach">

                                <div class="card-body">
                                    <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>

                                    <h2 class="text-center mb-5">Contact From Section</h2>
                                    <div class="row">

                                        <!-- Banner Section -->
                                        <div class="col-md-4">
                                            <div class="form-group">
                                                <label for="title"> Main Heading *</label><br>
                                                <input type="text" required class="form-control form__field"
                                                    name="cont_info_heading" id="title"
                                                    value="{{ $content['cont_info_heading'] ?? '' }}">
                                            </div>
                                        </div>

                                        <div class="col-md-4">
                                            <div class="form-group">
                                                <label for="title">Heading *</label><br>
                                                <input type="text" required class="form-control form__field"
                                                    name="con_form_heading" id="title"
                                                    value="{{ $content['con_form_heading'] ?? '' }}">
                                            </div>
                                        </div>

                                        <div class="col-md-4">
                                            <div class="form-group">
                                                <label for="title">Button Text *</label><br>
                                                <input type="text" required class="form-control form__field"
                                                    name="con_form_btn" id="title"
                                                    value="{{ $content['con_form_btn'] ?? '' }}">
                                            </div>
                                        </div>


                                    </div>
                                    <h2 class="text-center my-5">Contact Map Section</h2>

                                    <div class="row">
                                        <div class="col-md-12">
                                            <label for="">Map Link*</label>
                                            <textarea name="con_map_link" class="form-control form__field">{{ $content['con_map_link'] ?? '' }}</textarea>
                                            </div>

                                    </div>
                                </div>

                                <div class="text-center mt-3">
                                    <button type="submit" class="btn btn-dark">Update</button>
                                </div>
                            </form>


                        </div>

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

@endsection

@section('script')
    <script>
        function previewImage(event) {
            const preview = document.getElementById('banner_image');
            const file = event.target.files[0];

            if (file) {
                const reader = new FileReader();
                reader.onload = function(e) {
                    preview.src = e.target.result;
                };
                reader.readAsDataURL(file);
            } else {
                preview.src =
                    '{{ isset($contact) ? $contact->pagesImage('banner_image') : asset('upload/No-Image.png') }}'; // Reset to saved image if no file selected
            }
        }
    </script>
@endsection
