
@extends('app.admin.layout.layout')
@section('title',__('Edit partner'))
@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-textarea{
            border-radius: 10px;
            border: 1px solid #7b7bff;
            padding: 0px !important;
        }
        .layout-top-spacing{
            margin: 20px;
            border-radius: 15px;
            box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px;
        }
    </style>
    <div class="card layout-top-spacing">
        <div class="card-header d-flex justify-content-between align-items-center" style="background-color: #ff2a0e !important">
            <h5 class="m-0" style="color: white">@lang('Edit partner')</h5>
            <a class="btn btn-secondary" href="{{route('admin:partners.index')}}">@lang('Back')</a>
        </div>
        <div class="card-body">
            <form @class(["row needs-validation","was-validated" => $errors->any()]) action="{{route('admin:partners.update',$partner->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">
                    @if($partner->getAttribute('image'))
                        <div class="me-md-5">
                            <img style="height:200px;width:100%;object-fit:cover" src="{{$partner->image()}}" class="img-thumbnail" alt="">
                        </div>
                    @endif
                </div>

            <x-admin.form.text-area
                :label="__('Description Az')"
                name="description_az"
                type="text"
                custom-div-class="col-12 col-lg-12"
                :value="old('description_az',$partner->getAttribute('description_az'))"/>

            <x-admin.form.text-area
                    :label="__('Description Ru')"
                    name="description"
                    type="text"
                    custom-div-class="col-12 col-lg-12"
                    :value="old('description_ru',$partner->getAttribute('description_ru'))"/>

            <x-admin.form.text-area
                    :label="__('Description En')"
                    name="description_en"
                    type="text"
                    custom-div-class="col-12 col-lg-12"
                    :value="old('description',$partner->getAttribute('description_en'))"/>



                <x-admin.form.submit-button button-text="Update"/>
            </form>
        </div>
    </div>
@endsection
@push('js') <script src="https://cdn.quilljs.com/1.3.6/quill.js"></script>
<script>
    var quillAz = new Quill('#edit_partnerAz', {
        theme: 'snow'
    });

    var quillRu = new Quill('#edit_partnerRu', {
        theme: 'snow'
    });

    var quillEn = new Quill('#edit_partnerEn', {
        theme: 'snow'
    });

    document.querySelector('form').onsubmit = function() {
        var descriptionAzInput = document.querySelector('input[name=description_az]');
        descriptionAzInput.value = JSON.stringify(quillAz.root.innerHTML);

        var descriptionRuInput = document.querySelector('input[name=description_ru]');
        descriptionRuInput.value = JSON.stringify(quillRu.root.innerHTML);

        var descriptionEnInput = document.querySelector('input[name=description_en]');
        descriptionEnInput.value = JSON.stringify(quillEn.root.innerHTML);
    };

    var description_az = {!! json_encode($partner->getAttribute('description_az')) !!};
    var description_ru = {!! json_encode($partner->getAttribute('description_ru')) !!};
    var description_en = {!! json_encode($partner->getAttribute('description_en')) !!};

    quillAz.root.innerHTML = description_az;
    quillRu.root.innerHTML = description_ru;
    quillEn.root.innerHTML = description_en;

</script>
    <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: 'partners',
            maxFiles: 50,
            maxSize: '2 * 1024 * 1024',
            allowedExt: 'jpg|jpeg|gif|png|webp|svg',
            preloaded: {!! $partner !!}
        });
    </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
