<?php $__env->startSection('title', 'Add Contact Details'); ?>
<?php $__env->startSection('section'); ?>

    <?php
        if (!empty($contact->content)) {
            // Decode the 'content' JSON string into an associative array.
            $decodedData = json_decode($contact->content, true);
        }
    ?>
    <style>
        img {
            object-fit: contain !important;
            height: 200px !important;
        }
    </style>
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <div class="container-fluid">
                <div class="row mb-2">
                    <div class="col-sm-6">
                        <h1>Contact Form</h1>
                    </div>
                    <div class="col-sm-6">
                        <ol class="breadcrumb float-sm-right">
                            <li class="breadcrumb-item"><a href="#">Home</a></li>
                            <li class="breadcrumb-item active">Contact Form</li>
                        </ol>
                    </div>
                </div>
            </div><!-- /.container-fluid -->
        </section>
        <!-- /.content-header -->

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

                <div class="row">
                    <!-- left column -->
                    <div class="col-md-12">
                        <form class="category-form" method="post" action="<?php echo e(route('admin.contact-single')); ?>"
                              enctype="multipart/form-data">
                            <?php echo csrf_field(); ?>

                            <div class="card card-primary">

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

                                        <div class="tab-pane active" role="tabpanel" id="product">
                                            <h2>Contact Section</h2>


                                            <div class="col-md-4 mx-auto">
                                                <label for="">Top Title</label>
                                                <input type="text" name="top_title" placeholder="Meta Title"
                                                       class="form-control"
                                                       value="<?php echo e(!empty($contact) ? $decodedData['top_title'] : ''); ?>">
                                            </div>

                                            <div class="col-md-4 mx-auto">
                                                <label for="">Haeding</label>
                                                <input type="text" name="heading" placeholder="Meta Title"
                                                       class="form-control"
                                                       value="<?php echo e(!empty($contact) ? $decodedData['heading'] : ''); ?>">
                                            </div>

                                            <div class="col-md-4 mx-auto">
                                                <label for="">Sub Haeding</label>
                                                <input type="text" name="sub_heading" placeholder="Meta Title"
                                                       class="form-control"
                                                       value="<?php echo e(!empty($contact) ? $decodedData['sub_heading'] : ''); ?>">
                                            </div>

                                            <div class="col-md-4 mx-auto add-old-image-input">
                                                <label for="">Image</label>
                                                <input type="file" name="image"
                                                       class="form-control old-image"
                                                       id="firstimageInput"
                                                       data-old_image="<?php echo e($decodedData['image'] ?? ''); ?>">
                                                <br>
                                                <img
                                                    src="<?php echo e($contact ? asset('upload/cms_images/' . $decodedData['image']) : asset('admin/dist/img/placeholder.png')); ?>"
                                                    style="with:100px;height:100px;" id="firstimagePreview">
                                            </div>
                                            <br>
                                            <input type="submit" value="Submit" id="submit_btn" class="btn btn-primary">
                                        </div>


                                    </div>

                                </div>
                        </form>

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

            </div>
        </section>

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

                <div class="row">
                    <!-- left column -->
                    <div class="col-md-12">

                        <div class="card card-primary">

                            <div class="card-body">
                                <h2>Contact Section</h2>

                                <table id="example" class="table table-striped table-bordered" style="width:100%">
                                    <thead>
                                    <tr>
                                        <th>First Name</th>
                                        <th>Last Name</th>
                                        <th>Email</th>
                                        <th>Phone number</th>
                                        <th>Message</th>
                                    </tr>
                                    </thead>

                                    <tbody>
                                    <?php $__currentLoopData = $all_get_contacts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $all_get_contact): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <tr>
                                            <td><?php echo e($all_get_contact->first_name); ?></td>
                                            <td><?php echo e($all_get_contact->last_name); ?></td>
                                            <td><?php echo e($all_get_contact->phone); ?></td>
                                            <td><?php echo e($all_get_contact->email); ?></td>
                                            <td><?php echo e($all_get_contact->message); ?></td>


                                        </tr>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>


                                    </tbody>

                                </table>

                            </div>


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

                </div>
        </section>
    </div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('script'); ?>

    <script>

        $(document).ready(function () {
            $("table").DataTable({
                order: [0, 'dec']
            });
        });

    </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 imageInput = document.getElementById('firstimageInput');
        imageInput.addEventListener('change', function () {
            showImagePreview(this, 'firstimagePreview');
        });

        $(document).on('click', '.old-image', function () {
            var oldImage = $(this).data('old_image');
            console.log(oldImage);
            $('<input>').attr({
                type: 'hidden',
                name: 'old_image',
                value: oldImage
            }).appendTo('.add-old-image-input');


        });
    </script>

<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/servicedemoweb/public_html/global-man-cave/resources/views/admin/page/contact.blade.php ENDPATH**/ ?>