@extends('admin.layouts.container')

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



<div class="border-item">
    <ul class="nav nav-pills bg-nav-pills nav-justified mb-3">
        <li class="nav-item">
            <a href="#main" data-toggle="tab" aria-expanded="false" class="nav-link rounded-0 active">
                <i class="mdi mdi-home-variant d-lg-none d-block mr-1"></i>
                <span class="d-none d-lg-block">{{__('menu.details')}}</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="#section_items" data-toggle="tab" aria-expanded="false" class="nav-link rounded-0">
                <i class="mdi mdi-home-variant d-lg-none d-block mr-1"></i>
                <span class="d-none d-lg-block">{{__('menu.items')}}</span>
            </a>
        </li>

    </ul>
    <form class="form-row" method="post" onsubmit="saveForm(this)" action="{{ $action }}" enctype="multipart/form-data">
        @if($product ?? ''  && $product->id)
            @method('PUT')
        @endif
        @csrf
        <div class="tab-content row col-12">
            <div class="tab-pane col-lg-12 active" id="main">
                <div class="form-row">

                    @foreach($languages as $language)
                        <div class="form-group col-lg-6">
                            <label>{{ meta('name', $language->local) ?? __('menu.name') }} {{ count($languages) > 1 ? "({$language->name})" : '' }} </label>
                            <input type="text" class="form-control {{ $errors->has('name_'.$language->local) ? 'is-invalid' : '' }}" name="name_{{ $language->local }}" placeholder="{{ meta('name', $language->local) ?? __('menu.name') }}" value='{{ old("name_{$language->local}", $product[$language->local]->name ?? "") }}'/>
                        </div>
                        <div class="form-group col-lg-12">
                            <label>{{ meta('description', $language->local) ?? __('menu.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) ?? __('menu.description') }}">{{ old("description_{$language->local}", $product[$language->local]->description ?? "") }}</textarea>
                        </div>
                    @endforeach


                    {{--Start image container--}}
                        <div class="form-group col-lg-12">
                            <label>{{ meta('image', getCurrentLocale()) ?? __('menu.image') }} </label>
                            <input id="image_thumbnail" class="image_thumbnail" type="hidden" name="image" value="{{old("image", $product->image ?? "")}}"/>

                            <div class="photos main_photo {{ old('image', $product->image ?? '') ? ' wow fadeInUp' : 'hide' }}">
                                <div class="col-lg-4">
                                    <div class="items">
                                        <div class="img">
                                            <a href="#" id="lfm" data-input=".image_thumbnail" data-preview=".image_holder" class="lfm" data-hide=".pick_button">
                                                <img src="{{asset(old('image', $product->image ?? ''))}} "  id="image_holder" class="image_holder"/>
                                            </a>
                                        </div>
                                        <a href="#" class="showHide resetImage close" data-empty=".image_thumbnail" data-hide=".main_photo" data-show=".pick_button"><i class="fas fa-times"></i></a>
                                    </div>
                                </div>
                            </div>

                            <div class="clearfix"></div>
                            <span class="input-group-btn pick_button {{ old('image', $product->image ?? '') ? 'hide' : '' }} ">
                        <a id="lfm" data-input=".image_thumbnail" data-preview=".image_holder" data-show=".main_photo" data-hide=".pick_button" class="lfm btn btn-primary text-light">
                            <i class="fas fa-camera-retro"></i> {{__('dashboard.select')}}
                        </a>
                    </span>
                        </div>
                    {{--End image container--}}

                </div>

            </div>
            <div class="tab-pane col-lg-12" id="section_items">
                <div class="row">
                    <div class="col-lg-12">
                        <h3> {{__('menu.items')}} </h3>
                    </div>
                    <div class="col-lg-12" id="items">
                        @if($product ?? ''  && $product->id)
                            @foreach($features as $key=>$row)
                                <div class="row pricing-list-item  mb-4 "  style="background-color: rgba(21,97,203,0.1);height:auto;padding: 20px">
                                        @foreach($languages as $language)
                                            <div class="form-group col-lg-5">
                                                <label>{{  __('menu.name') }} {{ count($languages) > 1 ? "({$language->name})" : '' }} </label>
                                                <input type="text" class="form-control" id="items_{{$key}}_name_{{ $language->local }}"  name="items[{{$key}}][name_{{ $language->local }}]" placeholder="{{ meta('name', $language->local) ?? __('menu.name') }}" value="{{$row->descriptions($language->id)->name}}"/>
                                            </div>

                                        @endforeach

                                        <div class="form-group col-lg-2" style="font-size: 30px;margin-top:35px;">
                                            <i class="fas fa-times-circle" onclick="remove(this)"></i>
                                        </div>


                                        <div class="form-group col-lg-12">
                                                <label>{{  __('menu.icon') }} </label>
                                                <input id="icon_{{$key}}_thumbnail" class="icon_{{$key}}_thumbnail" type="hidden" name="items[{{$key}}][image]" value="{{$row->image}}" />

                                                <div class="photos main_icon_{{$key}}_photo wow fadeInUp">
                                                    <div class="col-lg-4">
                                                        <div class="items">
                                                            <div class="img">
                                                                <a href="#" id="lfm" data-input=".icon_{{$key}}_thumbnail" data-preview=".icon_{{$key}}_holder" class="lfm" data-hide=".pick_icon_{{$key}}_button">
                                                                    <img src="{{asset($row->image)}}"  id="icon_{{$key}}_holder" class="icon_{{$key}}_holder"/>
                                                                </a>
                                                            </div>
                                                            <a href="#" class="showHide resetImage close" data-empty=".icon_{{$key}}_thumbnail" data-hide=".main_icon_{{$key}}_photo" data-show=".pick_icon_{{$key}}_button"><i class="fas fa-times"></i></a>
                                                        </div>
                                                    </div>
                                                </div>

                                                <div class="clearfix"></div>
                                                <span class="input-group-btn pick_icon_{{$key}}_button hide">
                                                    <a id="lfm" data-input=".icon_{{$key}}_thumbnail" data-preview=".icon_{{$key}}_holder" data-show=".main_icon_{{$key}}_photo" data-hide=".pick_icon_{{$key}}_button" class="lfm btn btn-primary text-light">
                                                        <i class="fas fa-camera-retro"></i> {{__('dashboard.select')}}
                                                    </a>
                                                </span>
                                            </div>
                                </div>


                                @endforeach
                        @endif
                    </div>
                    <div class="col-lg-12">
                        <a style="cursor: pointer;" @if($product ?? ''  && $product->id) data-id="{{count($features)}}" @else data-id="0" @endif onclick="additem(this)" status-id="items" class="btn_1 gray "><i class="fa fa-fw fa-plus-circle"></i>{{__("menu.add_new")}}</a>
                    </div>
                </div>
            </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="//cdn.tinymce.com/4/tinymce.min.js"></script>--}}
    <script src="{{ asset('/assets/admin/js/lib/tinymce.min.js') }}"></script>
    <script src="{{url('')}}/assets/admin/js/custom/admin/products.js"></script>
    <script>
        tinymce.init({
            selector: '.description_ar',
            init_instance_callback: function (editor) {
                editor.on('change', function (e) {
                    $('#description_ar').val(e.level.content);
                });
            }
        });
        tinymce.init({
            selector: '.description_en',
            init_instance_callback: function (editor) {
                editor.on('change', function (e) {
                    $('#description_en').val(e.level.content);
                });
            }
        });
    </script>
    <script>
        function additem(elem)
        {
            var num = $(elem).attr('data-id');
            var status = $(elem).attr('status-id');
            var newrow = parseInt(num)+1;
            $(elem).attr('data-id', newrow);

            $.ajax({
                url : url_item,
                type : 'GET',
                data : 'status='+status+'&num='+num,
                success:function(data)
                {
                    $('#'+status).append(data);
                }
            })
        }
        function remove(elem)
        {
            $(elem).closest('.row').remove();
        }
    </script>
    <script>
        let route_prefix = "{{ url(config('lfm.prefix')) }}",
            url = "{{url('/')}}/",
            url_item = "{{route('admin.item')}}",
            currentLanguage = "{{getCurrentLocale()}}",
            imagePath = "{{asset('')}}";
    </script>
    <script src="{{ asset('assets/admin/js/editor.js') }}"></script>
    <script src="{{ asset('assets/admin/js/lfm.js') }}"></script>
@endsection



