@extends('app.admin.layout.layout')
@section('title',__('Edit Gallery'))
@push('css')
    <link rel="stylesheet" href="{{asset('/assets/admin/plugins/src/image-uploader/uploader.css')}}">
@endpush
@section('content')
    <style>
        .form-control{
            border-radius: 10px;
            border: 1px solid #7b7bff;
            box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px;        }
        .form-label{
            font-family: "Helvetica Neue", "Helvetica", "Arial", sans-serif;
        }
        .form-select{
            background-image: none !important;
        }
        .layout-top-spacing{
            margin: 20px;
            border-radius: 15px;
            box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px;
        }
    </style>
    <br><br><br>
    <div class="card layout-top-spacing">
        <div class="card-body">
            <div class="page-title-container">
                <div class="row">
                    <div class="col-12 col-md-7">
                        <h1 class="mb-0 pb-0 display-4" id="title">@lang('Edit Gallery')</h1>
                        <nav class="breadcrumb-container d-inline-block" aria-label="breadcrumb">
                                <ul class="breadcrumb pt-0">
                                        <li class="breadcrumb-item"><a href="{{ route('admin:home') }}">@lang('Home')</a></li>
                                        <li class="breadcrumb-item"><a href="{{ route('admin:galleries.index') }}">@lang('Galleries')</a></li>
                                        <li class="breadcrumb-item"><a href="#">@lang('Edit Gallery')</a></li>
                                </ul>
                        </nav>
                    </div>


                   <script>
                        document.addEventListener('DOMContentLoaded', (event) => {
                            // Əgər mövcud URL referrer ilə eyni deyilsə, onu sessionStorage-da saxla
                            if (document.referrer && document.referrer !== window.location.href) {
                                sessionStorage.setItem('previousURL', document.referrer);
                            }
                        });

                        function goToPreviousURL() {
                            const previousURL = sessionStorage.getItem('previousURL');
                            // Əgər previousURL mövcuddursa və cari URL ilə eyni deyilsə ona yönləndir
                            if (previousURL && previousURL !== window.location.href) {
                                window.location.href = previousURL;
                            } else {
                                // Əks halda bir əvvəlki səhifəyə yönləndir
                                history.go(-1);
                            }
                        }
                    </script>


                    <div class="col-12 col-md-5 d-flex align-items-start justify-content-end">
        <button type="button" class="btn btn-outline-primary btn-icon btn-icon-start w-100 w-md-auto" onclick="goToPreviousURL()">
            <i data-acorn-icon="arrow-left" class="me-2" data-acorn-size="17"></i>
            <span>@lang('Back')</span>
        </button>
    </div>
                </div>
            </div>
            <form @class(["row needs-validation","was-validated" => $errors->any()]) action="{{route('admin:galleries.update',$gallery->getAttribute('id'))}}" method="post" novalidate enctype="multipart/form-data">
                @csrf
                @method('PUT')

            <div class="col-12 p-0 p-md-3 d-flex flex-wrap flex-md-nowrap justify-content-center justify-content-md-start align-items-center">

                <div class="row w-100 my-auto">

                    <div class="row">
                        <div class="col-lg-3 col-sm-12 p-0 p-md-3 d-flex flex-wrap flex-md-nowrap justify-content-center justify-content-md-start align-items-center">
                                <div class="me-md-5" id="imageContainer">
                                    <img style="height: 224px; width: 427px; object-fit: contain; cursor:pointer;" src="{{$gallery->image()}}" class="img-thumbnail" alt="Tambura" onclick="document.getElementById('fileInput').click()">
                                </div>
                                <!-- Hidden file input -->
                                <input id="fileInput" type="file" style="display:none;" name="image">
                        </div>
                    </div>



                </div>
            </div>
                <x-admin.form.submit-button button-text="Update"/>
            </form>
        </div>
    </div>
@endsection
@push('js')
    <script src="{{asset('/assets/admin/plugins/src/image-uploader/uploader.js')}}"></script>
    <script>
        $("#partners").imageUploader({
            label:"{{__('Drag & Drop files here or click to browse')}}",
            imagesInputName: 'gallery',
            maxFiles: 50,
            maxSize: '2 * 1024 * 1024',
            allowedExt: 'jpg|jpeg|gif|png|webp|svg',
        });
    </script>

    <script src="{{asset('/assets/admin/plugins/src/tinymce/tinymce.min.js')}}"></script>
    <script>
        let tinyDarkActive = JSON.parse(localStorage.getItem("theme")).settings.layout.darkMode;
        tinymce.init({
            selector: 'textarea',
            plugins: [
                'advlist', 'autolink', 'link', 'image', 'lists', 'charmap', 'preview', 'anchor', 'pagebreak',
                'searchreplace', 'wordcount', 'visualblocks', 'visualchars', 'code', 'fullscreen', 'insertdatetime',
                'media', 'table', 'emoticons', 'help'
            ],
            skin: tinyDarkActive ? "oxide-dark" : null,
            content_css: tinyDarkActive ? "dark" : null,
            @if(in_array(app()->getLocale(),['az','ru']))
            language: '{{app()->getLocale()}}'
            @endif
        });
    </script>
@endpush
