@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 }}">
        @if($product ?? ''  && $product->id)
            @method('PUT')
        @endif
        @csrf

        <div class="form-group col-lg-6">
            <label>{{ meta('code', getCurrentLocale()) ?? __('products.code') }} </label>
            <input type="text" class="form-control {{ $errors->has('code') ? 'is-invalid' : '' }}" name="code" placeholder="{{ meta('code', getCurrentLocale()) ?? __('products.code') }}" value='{{ old("code", $product->code ?? "") }}'/>
        </div>

        <div class="form-group col-lg-6">
            <label>{{ meta('category_id', getCurrentLocale()) ?? __('products.category_id') }} </label>
            <select onchange="selectCategory(this)" class="form-control {{ $errors->has('category_id') ? 'is-invalid' : '' }}" name="category_id" >
                <option value="">{{__('dashboard.select')}}</option>
                @foreach($categories as $row)
                    <option @if((isset($product) ? $product->category_id : "") == $row->id ) selected @endif value="{{$row->id}}">{{$row->name}}</option>
                @endforeach
            </select>
        </div>

        <div class="form-group col-lg-12 row" id="attributes">
            @if($product ?? ''  && $product->id)
                <div class="col-lg-12 row pricing-list-item border-item mb-4" style="background-color: rgba(21,97,203,0.1);height:auto">
                    @if(count($models))
                        <div class="form-group col-lg-6">
                            <label>{{ meta('model_id', getCurrentLocale()) ?? __('products.model_id') }} </label>
                            <select class="form-control {{ $errors->has('model_id') ? 'is-invalid' : '' }}" name="model_id" >
                                <option value="">{{__('dashboard.select')}}</option>
                                @foreach($models as $row)
                                    <option {{$product->model_id == $row->id ? 'selected' : ''}} value="{{$row->id}}">{{$row->name}}</option>
                                @endforeach
                            </select>
                        </div>
                    @endif

                    @if($category->brand_status == 'true')
                        <div class="form-group col-lg-6">
                            <label>{{ meta('brand_id', getCurrentLocale()) ?? __('products.brand_id') }} </label>
                            <select  class="form-control {{ $errors->has('brand_id') ? 'is-invalid' : '' }}" name="brand_id" >
                                <option value="">{{__('dashboard.select')}}</option>
                                @foreach($brands as $row)
                                    <option {{$product->brand_id == $row->id ? 'selected' : ''}} value="{{$row->id}}">{{$row->name}}</option>
                                @endforeach
                            </select>
                        </div>
                    @endif
                    
                    @if($category->gender_status == 'true')
                        <div class="form-group col-lg-6">
                            <label>{{ meta('gender', getCurrentLocale()) ?? __('products.gender') }} </label>
                            <select  class="form-control {{ $errors->has('gender') ? 'is-invalid' : '' }}" name="gender" >
                                <option value="">{{__('dashboard.select')}}</option>
                                <option {{$product->gender == 'male' ? 'selected' : ''}} value="male">{{__('web.male')}}</option>
                                <option {{$product->gender == 'female' ? 'selected' : ''}} value="female">{{__('web.female')}}</option>
                            </select>
                        </div>
                    @endif
    
                    @foreach($ones as $attribute)
                        <div class="col-lg-12 row pricing-list-item border-item mb-4" style="background-color:white;height:auto">
                            <div class="col-lg-12">
                                <h3>{{$attribute->name}}</h3>
                            </div>
                            <div class="form-group col-lg-6">
                                <label>{{ __('products.choice') }} </label>
                                <select class="form-control" name="one[{{$attribute->id}}][choice_id]" >
                                    <option value="">{{__('dashboard.select')}}</option>
                                    @foreach($attribute->choices as $choice)
                                        <option {{$product->attributeChoice($attribute->id,$choice->choice_id) ? 'selected' : ''}} value="{{$choice->choice_id}}">{{$choice->choice->currentLangauge->name}}</option>
                                    @endforeach
                                </select>
                            </div>
                        </div>
                    @endforeach

                    @if($main)
                    <div class="col-lg-12 row pricing-list-item border-item mb-4" style="background-color:white;height:auto">
                        <div class="col-lg-12">
                            <h3>{{$main->details->name}}</h3>
                        </div>

                        @foreach($main->choices as $main_choice)
                            <div class="col-lg-12 row">
                                <div class="col-lg-12 row pricing-list-item border-item mb-4" style="background-color: rgba(21,97,203,0.1);height:auto">
                                    <div class="form-group col-lg-12">
                                        <h3>{{ $main_choice->choice->details->name}}</h3>
                                    </div>

                        @if(!$sub)
                            <div class="form-group col-lg-6">
                                <label>{{ __('products.count') }} </label>
                                <input type="number" min="0" name="multi[{{$main->id}}][{{$main_choice->choice_id}}][count]" class="form-control" placeholder="{{ __('products.count') }}" value="{{$product->attributeChoiceMulti($main->id,$main_choice->choice_id)['count']}}">
                            </div>
                        @endif
                        <div class="form-group col-lg-6 image_container">
                            <label>{{  __('pages.image') }} </label>
                            <input id="image_{{$main->id . 'choice'.$main_choice->id }}_thumbnail" class="image_{{$main->id . 'choice'.$main_choice->id }}_thumbnail" type="hidden" name="multi[{{$main->id}}][{{$main_choice->choice_id}}][image]" value="{{$product->attributeChoiceMulti($main->id,$main_choice->choice_id)['image']}}"/>

                            <div class="photos main_{{$main->id . 'choice'.$main_choice->id }}_photo @if($product->attributeChoiceMulti($main->id,$main_choice->choice_id)['image']) wow fadeInUp @else hide @endif">
                                <div class="col-md-4">
                                    <div class="items">
                                        <div class="img">
                                            <a href="#" id="lfm" data-input=".image_{{$main->id . 'choice'.$main_choice->id }}_thumbnail" data-preview=".image_{{$main->id . 'choice'.$main_choice->id }}_holder" class="lfm" data-hide=".pick_{{$main->id . 'choice'.$main_choice->id }}_button">
                                                <img @if($product->attributeChoiceMulti($main->id,$main_choice->choice_id)['image']) src="{{asset($product->attributeChoiceMulti($main->id,$main_choice->choice_id)['image'])}}" @endif id="image_{{$main->id . 'choice'.$main_choice->id }}_holder" class="image_{{$main->id . 'choice'.$main_choice->id }}_holder"/>
                                            </a>
                                        </div>
                                        <a href="#" class="showHide resetImage close" data-empty=".image_{{$main->id . 'choice'.$main_choice->id }}_thumbnail" data-hide=".main_{{$main->id . 'choice'.$main_choice->id }}_photo" data-show=".pick_{{$main->id . 'choice'.$main_choice->id }}_button"><i class="fas fa-times"></i></a>
                                    </div>
                                </div>
                            </div>

                            <div class="clearfix"></div>
                            <span class="input-group-btn pick_{{$main->id . 'choice'.$main_choice->id }}_button @if(!is_null($product->attributeChoiceMulti($main->id,$main_choice->choice_id)['image'])) hide @endif">
                                <a id="lfm"  data-input=".image_{{$main->id . 'choice'.$main_choice->id }}_thumbnail" data-preview=".image_{{$main->id . 'choice'.$main_choice->id }}_holder" data-show=".main_{{$main->id . 'choice'.$main_choice->id }}_photo" data-hide=".pick_{{$main->id . 'choice'.$main_choice->id }}_button" class="lfm btn btn-primary text-light">
                                    <i class="fas fa-camera-retro"></i> Choose
                                </a>
                             </span>
                        </div>
                        
                        @if($sub)
                                        @foreach($sub->choices as $choice)
                                            <div class="col-lg-12 row pricing-list-item border-item mb-4" style="background-color: rgba(21,97,203,0.1);height:auto">
                                                <div class="form-group col-lg-12">
                                                    <h5>{{ $choice->choice->details->name}}</h5>
                                                </div>
                                                <div class="form-group col-lg-6">
                                                    <label>{{ __('products.count') }} </label>
                                                    <input type="number"min="0" name="multi[{{$main->id}}][{{$main_choice->choice_id}}][sub][{{$sub->id}}][{{$choice->choice_id}}][count]" value="{{$product->attributeChoiceMulti($main->id,$main_choice->choice_id,$sub->id,$choice->choice_id)['count']}}" class="form-control" placeholder="{{ __('products.count') }}">
                                                </div>
                                                <div class="form-group col-lg-6 image_container">
                                                    <label>{{  __('pages.image') }} </label>
                                                    <input id="image_{{$main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id}}_thumbnail" class="image_{{$main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id}}_thumbnail" type="hidden" name="multi[{{$main->id}}][{{$main_choice->choice_id}}][sub][{{$sub->id}}][{{$choice->choice_id}}][image]" value="{{$product->attributeChoiceMulti($main->id,$main_choice->choice_id,$sub->id,$choice->choice_id)['image']}}"  />

                                                    <div class="photos main_{{$main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id}}_photo @if($product->attributeChoiceMulti($main->id,$main_choice->choice_id,$sub->id,$choice->choice_id)['image']) wow fadeInUp @else hide @endif">
                                                        <div class="col-md-4">
                                                            <div class="items">
                                                                <div class="img">
                                                                    <a href="#" id="lfm" data-input=".image_{{$main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id}}_thumbnail" data-preview=".image_{{$main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id}}_holder" class="lfm" data-hide=".pick_{{$main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id}}_button">
                                                                        <img src="{{asset($product->attributeChoiceMulti($main->id,$main_choice->choice_id,$sub->id,$choice->choice_id)['image'])}}"  id="image_{{$main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id}}_holder" class="image_{{$main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id}}_holder"/>
                                                                    </a>
                                                                </div>
                                                                <a href="#" class="showHide resetImage close" data-empty=".image_{{$main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id}}_thumbnail" data-hide=".main_{{$main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id}}_photo" data-show=".pick_{{$main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id}}_button"><i class="fas fa-times"></i></a>
                                                            </div>
                                                        </div>
                                                    </div>

                                                    <div class="clearfix"></div>
                                                    <span class="input-group-btn pick_{{$main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id}}_button  @if($product->attributeChoiceMulti($main->id,$main_choice->choice_id,$sub->id,$choice->choice_id)['image']) hide @endif ">
                                                        <a id="lfm"  data-input=".image_{{$main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id}}_thumbnail" data-preview=".image_{{$main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id}}_holder" data-show=".main_{{$main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id}}_photo" data-hide=".pick_{{$main->id . 'choice'.$main_choice->id . 'subattr'.$sub->id .'choice'.$choice->id}}_button" class="lfm btn btn-primary text-light">
                                                            <i class="fas fa-camera-retro"></i> Choose
                                                        </a>
                                                     </span>
                                                </div>
                                            </div>
                                        @endforeach
                        @endif
                                </div>
                            </div>
                        @endforeach
                    </div>
                @endif
                </div>
            @endif
        </div>


        @foreach($cost_status as $status)
            <div class="form-group col-lg-6">
                <label>{{ __('products.cost'). ' (' . __('products.'.$status) .')' }} </label>
                <input type="number" min="1" class="form-control" name="costs[{{$status}}][cost]" placeholder="{{ meta('cost', getCurrentLocale()) ?? __('products.cost') }}" value='{{ old("cost",  isset($product) ? $product->costs($status,'cost') : "") }}'/>
            </div>

            <div class="form-group col-lg-6">
                <label>{{ __('products.cost_discount'). ' (' . __('products.'.$status) .')' }} </label>
                <input type="number"min="1"  class="form-control" name="costs[{{$status}}][cost_discount]" placeholder="{{ meta('cost_discount', getCurrentLocale()) ?? __('products.cost_discount') }}" value='{{ old("cost_discount", isset($product) ? $product->costs($status,'cost_discount') : "") }}'/>
            </div>
        @endforeach

        <div class="form-group col-lg-6" id="count_check">
            <label>{{ meta('count', getCurrentLocale()) ?? __('products.count') }} </label>
            <input type="number" min="0" class="form-control {{ $errors->has('count') ? 'is-invalid' : '' }}" name="count" placeholder="{{ meta('count', getCurrentLocale()) ?? __('products.count') }}" value='{{ old("count", $product->count ?? "") }}'/>
        </div>
        <div class="form-group col-lg-6">
            <label>{{ meta('min_order', getCurrentLocale()) ?? __('products.min_order') }} </label>
            <input type="number" min='1' class="form-control {{ $errors->has('min_order') ? 'is-invalid' : '' }}" name="min_order" placeholder="{{ meta('min_order', getCurrentLocale()) ?? __('products.min_order') }}" value='{{ old("min_order", $product->min_order ?? "") }}'/>
        </div>
        <div class="form-group col-lg-6">
            <label>{{ meta('num_buy', getCurrentLocale()) ?? __('products.num_buy') }} </label>
            <input type="number" min='1' class="form-control {{ $errors->has('num_buy') ? 'is-invalid' : '' }}" name="num_buy" placeholder="{{ meta('num_buy', getCurrentLocale()) ?? __('products.num_buy') }}" value='{{ old("num_buy", $product->num_buy ?? "") }}'/>
        </div>

        <div class="form-group col-lg-6">
            <label>{{ meta('most_sale', getCurrentLocale()) ?? __('products.most_sale') }} </label>
            <select  class="form-control {{ $errors->has('most_sale') ? 'is-invalid' : '' }}" name="most_sale" >
                <option @if((isset($product) ? $product->most_sale : "") == 'false' ) selected @endif value="false">{{__('products.false')}}</option>
                <option @if((isset($product) ? $product->most_sale : "") == 'true' ) selected @endif value="true">{{__('products.true')}}</option>
            </select>
        </div>

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

        @endforeach

                <div class="col-12">
                    <div  class="row pricing-list-item border-item mb-4" style="background-color: white;height:auto">
                        <div class="col-lg-12">
                            <h3> {{__('rates.head')}} </h3>
                            <div class="col-lg-12" style="height:100%;" id="rates">
                            @if($product ?? ''  && $product->id)
                                @foreach($rates as $key=>$rate)
                                    <div class="col-lg-12 row pricing-list-item border-item mb-4" style="background-color: rgba(21,97,203,0.1);height:auto">
                                        <div class="form-group col-lg-6">
                                            <label>{{ meta('rate', getCurrentLocale()) ?? __('rates.rate') }} </label>
                                            <select  class="form-control {{ $errors->has('rate') ? 'is-invalid' : '' }}" name="rates[{{$key}}][rate]" >
                                                <option {{$rate->rate == '1' ? 'selected' : ''}} value="1">1</option>
                                                <option {{$rate->rate == '5' ? 'selected' : ''}} value="2">2</option>
                                                <option {{$rate->rate == '3' ? 'selected' : ''}} value="3">3</option>
                                                <option {{$rate->rate == '4' ? 'selected' : ''}} value="4">4</option>
                                                <option {{$rate->rate == '5' ? 'selected' : ''}} value="5">5</option>
                                            </select>
                                        </div>
                                        
                                        <div class="form-group col-lg-6">
                                            <label>{{ __('rates.name') }} </label>
                                            <input type="text" class="form-control" name="rates[{{$key}}][name]" placeholder="{{  __('rates.name') }}" value="{{$rate->name}}" />
                                        </div>
                                        <div class="form-group col-lg-6">
                                            <label>{{ __('rates.comment') }} </label>
                                            <input type="text" class="form-control" name="rates[{{$key}}][comment]" placeholder="{{  __('rates.comment') }}" value="{{$rate->comment}}"/>
                                        </div>
                                        
                                        <div class="form-group col-lg-10 image_rate_{{$key}}container" >
                                            <label>{{ meta('image', getCurrentLocale()) ?? __('products.image') }} </label>
                                            <input id="image_rate_{{$key}}thumbnail" class="image_rate_{{$key}}thumbnail" type="hidden" name="rates[{{$key}}][image]" value="{{$rate->image}}"/>
                                    
                                            <div class="photos main_rate_{{$key}}photo wow fadeInUp">
                                                <div class="col-md-4">
                                                    <div class="items">
                                                        <div class="img">
                                                            <a href="#" id="lfm" data-input=".image_rate_{{$key}}thumbnail" data-preview=".image_rate_{{$key}}holder" class="lfm" data-hide=".pick_rate_{{$key}}button">
                                                                <img src="{{asset($rate->image)}}" id="image_rate_{{$key}}holder" class="image_rate_{{$key}}holder"/>
                                                            </a>
                                                        </div>
                                                        <a href="#" class="showHide resetImage close" data-empty=".image_rate_{{$key}}thumbnail" data-hide=".main_rate_{{$key}}photo" data-show=".pick_rate_{{$key}}button"><i class="fas fa-times"></i></a>
                                                    </div>
                                                </div>
                                            </div>
                                    
                                            <div class="clearfix"></div>
                                            <span class="input-group-btn pick_rate_{{$key}}button hide">
                                            <a id="lfm"  data-input=".image_rate_{{$key}}thumbnail" data-preview=".image_rate_{{$key}}holder" data-show=".main_rate_{{$key}}photo" data-hide=".pick_rate_{{$key}}button" class="lfm btn btn-primary text-light">
                                                <i class="fas fa-camera-retro"></i> {{__('dashboard.choose')}}
                                            </a>
                                         </span>
                                        </div>
                                        <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>
                                @endforeach
                            @endif
                            </div>
                        </div>
                    </div>
                </div>
        <div class="col-lg-12">
            <a style="cursor: pointer;" @if($product ?? ''  && $product->id) data-id="{{count($rates)}}" @else data-id="0" @endif onclick="addrate(this)" class="btn_1 gray "><i class="fa fa-fw fa-plus-circle"></i>{{__("products.addrate")}}</a>
        </div>

            <div class="form-group col-lg-12 image_container" >
                <label>{{ meta('image', getCurrentLocale()) ?? __('products.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-md-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.choose')}}
                </a>
             </span>
            </div>

            <div class="border-item photos col-md-12 other_image_container">
                <div class="row">
                    @if ($product ?? false)
                        @foreach ($product['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="#" 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">
                        Add New Item
                    </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 files -->
        <script src="{{ asset('/assets/admin/js/lib/tinymce.min.js') }}"></script>
{{--    <script src="//cdn.tinymce.com/4/tinymce.min.js"></script>--}}
    <script>
        function saveForm(elem)
        {
            event.preventDefault();
            var action = $(elem).attr('action');
            let dataform = new FormData( $(elem)[0]);
            $.ajax
            ({
                url : action,
                type: 'POST',
                data: dataform,
                dataType : 'json',
                contentType: false,
                processData: false,
                success:function(data)
                {
                    $('#errors').html('');
                    $('#errors').css("display", "none");
                    if(data.hasOwnProperty('errors'))
                    {
                         $('#errors').css("display", "block");
                        let html = '<div class="alert alert-danger">';
                        $.each(data.errors, function(key,value)
                        {
                            html += '<li>'+value+'</li>';
                        });
                        html += "</div>";
                        $('#errors').html(html);
                    }
                    else
                    {
                        setTimeout(
                            function()
                            {
                               window.location.href = data.data
                            }, 1000);
                    }
                }
                ,error:function(data)
                {
                    $('#errors').css("display", "block");
                    let html = '<div class="alert alert-danger">';
                    $.each(data.responseJSON.errors, function(key,value)
                    {
                        html += '<li>'+value+'</li>';
                    });
                    html += "</div>";
                    $('#errors').html(html);
                }
            })
        }
        function selectCategory(elem)
        {
        var data = $(elem).val();
        if(data == '')
        {
            $('#attributes').html('');
        }
        else
        {
            $.ajax({
                url : url_attribute,
                type : 'GET',
                data : 'id='+data,
                success:function(data)
                {
                    $('#attributes').html(data.view);
                    if(data.count_check == true)
                    {
                        $('#count_check').show();
                    }
                    else
                    {
                        $('#count_check').hide();
                    }
                }
            })
        }
        
    }
    
    
        function addrate(elem)
        {
            var num = $(elem).attr('data-id');
            var newrow = parseInt(num)+1;
            $(elem).attr('data-id', newrow);
            $.ajax({
                url : url_addrate,
                type : 'GET',
                data : 'key='+num,
                success:function(data)
                {
                    $('#rates').append(data);
                }
            })
        }
        
            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);
                    });
                }
            });
        function remove(elem){
            $(elem).closest('.row').remove();
        }
    </script>
    <script>
        let route_prefix = "{{ url(config('lfm.prefix')) }}",
            url = "{{url('/')}}/",
            url_attribute = "{{url('/')}}/admin/attribute",
            url_addrate = "{{url('/')}}/admin/addrate",
            currentLanguage = "{{getCurrentLocale()}}",
            imagePath = "{{asset('')}}";
    </script>
    <script src="{{ asset('assets/admin/js/editor.js') }}"></script>
    <script src="{{ asset('assets/admin/js/lfm.js') }}"></script>
@endsection



