@extends('layouts.admin-layout')
@section('title', 'All Contact User')
@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">
                        <!-- general form elements -->
                        <div class="card card-dark card-box-shadow">
                            <div class="card-header">
                                <h3 class="card-title">Site Settings</h3>
                            </div>
                            <form class="category-form" method="post" action="{{ route('admin.setting.store') }}"
                                enctype="multipart/form-data">
                                @csrf
                                <div class="card-body">
                                    <div class="row">

                                        <div class="col-md-4">
                                            <div class="form-group">
                                                <label for="name">Site Title</label>
                                                <input type="text" class="form-control form__field" name="site_title"
                                                    value="{{ $content->site_title ?? '' }}" placeholder="site title">
                                            </div>
                                        </div>

                                        <div class="col-md-4">
                                            <div class="form-group">
                                                <label for="name">Email</label>
                                                <input type="email" class="form-control form__field" name="email"
                                                    id="email" required value="{{ $content->email ?? '' }}"
                                                    placeholder="email">
                                            </div>

                                        </div>


                                        <div class="col-md-4">
                                            <div class="form-group">
                                                <label for="name">Phone No</label>
                                                <input type="text" class="form-control form__field" name="phone_num"
                                                    id="name" required value="{{ $content->phone_num ?? '' }}"
                                                    placeholder="Phone Number 1">
                                            </div>

                                        </div>

                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label for="name">Footer Bottom Description *</label>
                                                <input type="text" class="form-control form__field"
                                                    name="footer_btm_description" id="heading" required
                                                    value="{{ $content->footer_btm_description ?? '' }}"
                                                    placeholder="Footer Heading">
                                            </div>
                                        </div>
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label for="name">Footer Description</label>
                                                <textarea name="footer_description" class="form-control form__field" id="" required>{{ $content->footer_description ?? '' }} </textarea>

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

                                    <h1 class="mt-4 mb-3">Logos</h1>

                                    <div class="row">

                                        <div class="col-md-4">
                                            <div class="form-group add-old-to-banner-image-input">
                                                <label for="topBannerImageInput">Header Logo *</label><br>
                                                <input type="file"
                                                    class="form-control form__field old-top-banner-image visually-hidden"
                                                    name="header_logo" id="topBannerImageInput" accept="image/*">
                                                <label for="topBannerImageInput"
                                                    class="file-input-label form__field form-control">
                                                    <i class="fas fa-camera"></i> Choose file
                                                </label>
                                                <img id="topBannerImagePreview"
                                                    src="{{ isset($content) ? $content->settingImage('header_logo') : asset('upload/No-Image.png') }}"
                                                    alt="Profile Preview"
                                                    style="width: 300px; height: 200px; margin-top: 10px;" class="bg-dark">
                                            </div>

                                        </div>

                                        <div class="col-md-4">
                                            <div class="form-group add-old-to-banner-image-input">
                                                <label for="topFooterLogoInput">Footer Logo</label><br>
                                                <input type="file"
                                                    class="form-control form__field old-top-banner-image visually-hidden"
                                                    name="footer_logo" id="topFooterLogoInput" accept="image/*">
                                                <label for="topFooterLogoInput"
                                                    class="file-input-label form__field form-control">
                                                    <i class="fas fa-camera"></i> Choose file
                                                </label>
                                                <img id="topFooterLogoPreview"
                                                    src="{{ isset($content) ? $content->settingImage('footer_logo') : asset('upload/No-Image.png') }}"
                                                    alt="Profile Preview"
                                                    style="width: 300px; height: 200px; margin-top: 10px;" class="bg-dark">
                                            </div>

                                        </div>

                                        <div class="col-md-4">
                                            <div class="form-group add-old-to-banner-image-input">
                                                <label for="fav_icon">Fav Icon</label><br>
                                                <input type="file"
                                                    class="form-control form__field old-top-banner-image visually-hidden"
                                                    name="fav_icon" id="fav_icon" accept="image/*">
                                                <label for="fav_icon" class="file-input-label form__field form-control">
                                                    <i class="fas fa-camera"></i> Choose file
                                                </label>
                                                <img id="favIconPreview"
                                                    src="{{ isset($content) ? $content->settingImage('fav_icon') : asset('upload/No-Image.png') }}"
                                                    alt="Profile Preview"
                                                    style="width: 300px; height: 200px; margin-top: 10px;"
                                                    class="bg-dark">
                                            </div>

                                        </div>

                                        {{-- <div class="col-md-4">
                                            <div class="form-group add-old-to-banner-image-input">
                                                <label for="loader_video">Loader Video</label><br>
                                                <input type="file"
                                                    class="form-control form__field old-top-banner-image visually-hidden"
                                                    name="loader_video" id="loader_video" accept="video/*">
                                                <label for="loader_video"
                                                    class="file-input-label form__field form-control">
                                                    <i class="fas fa-camera"></i> Choose file
                                                </label>

                                            </div>
                                            <video muted autoplay loop preload src="{{ $content->settingImage('loader') }}">
                                                <source>
                                            </video>

                                        </div> --}}
                                    </div>
                                    <div class="text-center mt-3">
                                        <button type="submit" class="btn btn-primary">Submit
                                        </button>
                                    </div>
                                </div>

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

@endsection

@section('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 topBannerImageInput = document.getElementById('topBannerImageInput');
        topBannerImageInput.addEventListener('change', function() {
            showImagePreview(this, 'topBannerImagePreview');
        });

        const topFooterLogoInput = document.getElementById('topFooterLogoInput');
        topFooterLogoInput.addEventListener('change', function() {
            showImagePreview(this, 'topFooterLogoPreview');
        });

        const fav_icon = document.getElementById('fav_icon');
        fav_icon.addEventListener('change', function() {
            showImagePreview(this, 'favIconPreview');
        });


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


        });


        const mainImageInput = document.getElementById('mainImageInput');
        mainImageInput.addEventListener('change', function() {
            showImagePreview(this, 'mainImagePreview');
        });

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


        });
    </script>
@endsection
