@extends('admin.layouts.container')

@section('content')
    <div class="side-title">
        <h3>{{ $head ?? ''}}</h3>
    </div>

    <div class="border-item">
        <form class="form-row" method="post" onsubmit="saveForm(this)" action="{{ $action }}" enctype="multipart/form-data">
            @if($partner ?? ''  && $partner->id)
                @method('PUT')
            @endif
            @csrf

            @foreach($languages as $language)

                <div class="form-group col-lg-6">
                    <label>{{ meta('title', $language->local) ?? __('partners.title') }} {{ count($languages) > 1 ? "({$language->name})" : '' }} </label>
                    <input type="text" class="form-control {{ $errors->has('title_'.$language->local) ? 'is-invalid' : '' }}" name="title_{{ $language->local }}" placeholder="{{ meta('title', $language->local) ?? __('partners.title') }}" value='{{ old("title_{$language->local}", $partner[$language->local]->title ?? "") }}'/>
                </div>
                <div class="form-group col-lg-12">
                    <label>{{ meta('description', $language->local) ?? __('partners.description') }} {{ count($languages) > 1 ? "({$language->name})" : '' }} </label>
                    <textarea  class="form-control {{ $errors->has('description_'.$language->local) ? 'is-invalid' : '' }}" name="description_{{ $language->local }}" placeholder="{{ meta('description', $language->local) ?? __('partners.description') }}">{{ old("description_{$language->local}", $partner[$language->local]->description ?? "") }}</textarea>
                </div>

            @endforeach


            <div class="form-group col-lg-6">
                <label>{{ __('partners.image') }}</label>
                <input id="old_image" type="hidden" name="old_image" value="{{ $partner->image ?? ""}}"/>
                <input type="file" class="form-control {{ $errors->has('image') ? 'is-invalid' : '' }}" name="image" accept="image/*"/>
                @if (($partner->image ?? null) && ($partner->image_url ?? null))
                    <a href="{{ $partner->image_url }}" class="btn btn-primary mt-2" target="_new"><i class="fas fa-download"></i></a>
                @endif
            </div>

            <div class="form-group col-lg-6">
                <label>{{ __('partners.logo') }}</label>
                <input id="old_logo" type="hidden" name="old_logo" value="{{ $partner->logo ?? ""}}"/>
                <input type="file" class="form-control {{ $errors->has('logo') ? 'is-invalid' : '' }}" name="logo" accept="image/*"/>
                @if (($partner->logo ?? null) && ($partner->logo_url ?? null))
                    <a href="{{ $partner->logo_url }}" class="btn btn-primary mt-2" target="_new"><i class="fas fa-download"></i></a>
                @endif
            </div>


            <div class="border-item photos col-md-12 other_image_container">
                <div class="row">
                    @if ($partner ?? false)
                        @foreach ($partner['photos'] as $photo)
                            <div class="col-md-4">
                                <div class="items">
                                    <div class="img">
                                        <a href="{{ asset($photo->image ?? '')}}" data-fancybox="gallery"><img src="{{ asset($photo->image ?? '')}}" alt=""></a>
                                    </div>
                                    <input type="hidden" name="images[]" value="{{ $photo->image ?? "" }}">
                                    <a href="#" onclick="DeleteImg(this)" class="close"><i class="fas fa-times"></i></a>
                                </div>
                            </div>
                        @endforeach
                    @endif
                </div>
                <div class="text-center">
                    <input id="other_image_thumbnail" class="other_image_thumbnail" type="hidden"/>
                    <div class="clearfix"></div>
                    <span id="add">
                            <a id="lfm" data-width="" data-cache="article_gallery" data-input=".other_image_thumbnail" data-preview="" data-show="" data-hide="" class="lfm add">
                                {{__('partners.add_photos')}}
                            </a>
                        </span>
                </div>
            </div>

            <div class="text-center mt-5 col-12">
                <button class="butn"><span>{{ __('dashboard.save') }}</span></button>
            </div>
        </form>
    </div>

@endsection

@section('inner_js')
    <!-- Editor JS orders -->
    <script src="{{ asset('/assets/admin/js/lib/tinymce.min.js') }}"></script>

    <script>
        function DeleteImg(elem)
        {
            $(elem).closest('.col-md-4').remove();
        }
    </script>

    <script>
        let currentLanguage = "{{getCurrentLocale()}}";
    </script>
    <script src="{{ asset('assets/admin/js/editor.js') }}"></script>
@endsection



