@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">
            @method('PUT')
            @csrf

            <div class="form-group col-lg-6">
                <label>{{ __('banners.active_status') }} </label>
                <select class="form-control {{ $errors->has('active_status') ? 'is-invalid' : '' }}" name="active_status">
                    @foreach($active_statuses as $row)
                        <option {{ (isset($banner) ? $banner->active_status : null) == $row ? 'selected' : '' }} value="{{$row}}">{{ __('banners.active_statuses.'.$row) }}</option>
                    @endforeach
                </select>
            </div>

            <div class="form-group col-lg-6 {{$banner->status != $status_footer ? 'd-none' : ''}}" >
                <label>{{ __('banners.show_all_pages') }} </label>
                <select class="form-control {{ $errors->has('show_all_pages') ? 'is-invalid' : '' }}" name="show_all_pages">
                    @foreach($active_statuses as $row)
                        <option {{ (isset($banner) ? $banner->show_all_pages : null) == $row ? 'selected' : '' }} value="{{$row}}">{{ __('banners.active_statuses.'.$row) }}</option>
                    @endforeach
                </select>
            </div>

            <div class="form-group col-lg-6" >
                <label>{{ __('banners.count_photo') }} </label>
                <select onchange="countPhotos()" id="count_photo" class="form-control {{ $errors->has('count_photo') ? 'is-invalid' : '' }}" name="count_photo">
                    @foreach($count_photos as $row)
                        <option {{ (isset($banner) ? $banner->count_photo : null) == $row ? 'selected' : '' }} value="{{$row}}">{{ __('banners.count_photos.'.$row) }}</option>
                    @endforeach
                </select>
            </div>
            @foreach($count_photos as $key=>$row)
                <div class="col-lg-12 row images" id="image_{{$row}}">
                    <div class="col-lg-6">
                        <label>{{ __('banners.link') }} {{$row}}</label>
                        <input type="url" id="images_{{$row}}_link" class="form-control {{ $errors->has('link') ? 'is-invalid' : '' }}" name="images[{{$row}}][link]" placeholder="{{ __('banners.link') }}" value='{{ $photos[$key]->link ?? "" }}'/>
                    </div>
                    <div class="form-group col-lg-6 image_container " id="images_{{$row}}_image">
                        <label>{{ __('banners.image') }} {{$row}}</label>
                        <input id="image_{{$row}}_thumbnail" class="image_{{$row}}_thumbnail" type="hidden" name="images[{{$row}}][image]" value="{{$photos[$key]->image ?? ""}}"/>

                        <div class="photos main_{{$row}}_photo {{ ($photos[$key] ?? null)  ? ' wow fadeInUp' : 'hide' }}">
                            <div class="col-md-4">
                                <div class="items">
                                    <div class="img">
                                        <a href="#" id="lfm" data-input=".image_{{$row}}_thumbnail" data-preview=".image_{{$row}}_holder" class="lfm" data-hide=".pick_{{$row}}_button">
                                            <img src="{{asset(old('image', $photos[$key]->image ?? ''))}} "  id="image_{{$row}}_holder" class="image_{{$row}}_holder"/>
                                        </a>
                                    </div>
                                    <a href="#" class="showHide resetImage close" data-empty=".image_{{$row}}_thumbnail" data-hide=".main_{{$row}}_photo" data-show=".pick_{{$row}}_button"><i class="fas fa-times"></i></a>
                                </div>
                            </div>
                        </div>

                        <div class="clearfix"></div>
                        <span class="input-group-btn pick_{{$row}}_button {{  ($photos[$key] ?? null) ? 'hide' : '' }} ">
                            <a id="lfm"  data-input=".image_{{$row}}_thumbnail" data-preview=".image_{{$row}}_holder" data-show=".main_{{$row}}_photo" data-hide=".pick_{{$row}}_button" class="lfm btn btn-primary text-light">
                                <i class="fas fa-camera-retro"></i> {{__('dashboard.choose')}}
                            </a>
                         </span>
                    </div>
                </div>
            @endforeach
            <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 countPhotos()
        {
            $('.images').hide()
            let count = $('#count_photo').val()
            for (i = 1; i <= count; i ++)
            {
                $('#image_'+i).show()
            }
        }
        $('#count_photo').trigger('change')
    </script>
    <script>
        let route_prefix = "{{ url(config('lfm.prefix')) }}",
            url = "{{url('/')}}/",
            currentLanguage = "{{getCurrentLocale()}}",
            imagePath = "{{asset('')}}";
    </script>
    <script src="{{ asset('assets/admin/js/editor.js') }}"></script>
    <script src="{{ asset('assets/admin/js/lfm.js') }}"></script>
    <script src="{{ asset('assets/admin/js/articles.js') }}"></script>
@endsection



