@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">{{__('services.details')}}</span>
                </a>
            </li>
            <li class="nav-item">
                <a href="#section_features" 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">{{__('services.features')}}</span>
                </a>
            </li>

        </ul>--->
        <form class="form-row" method="post" onsubmit="saveForm(this)" action="{{ $action }}" enctype="multipart/form-data">
            @if($service ?? ''  && $service->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('title', $language->local) ?? __('services.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) ?? __('services.title') }}" value='{{ old("title_{$language->local}", $service[$language->local]->title ?? "") }}'/>
                            </div>
                            <div class="form-group col-lg-12">
                                <label>{{ meta('description', $language->local) ?? __('services.description') }} {{ count($languages) > 1 ? "({$language->name})" : '' }} </label>
                                <textarea id="description_{{ $language->local }}" class="form-control tinymce {{ $errors->has('description_'.$language->local) ? 'is-invalid' : '' }}" name="description_{{ $language->local }}" placeholder="{{ meta('description', $language->local) ?? __('services.description') }}">{{ old("description_{$language->local}", $service[$language->local]->description ?? "") }}</textarea>
                            </div>

                        @endforeach

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

                </div>
<!---
                <div class="tab-pane col-lg-12" id="section_features">
                    <div class="row">

                        <div class="col-lg-12" id="features">
                            @foreach($features as $key=>$row)
                                @include('admin.features.form',['feature'=>$row,'key'=>$key])
                            @endforeach
                        </div>
                        <div class="col-lg-12">
                            <a style="cursor: pointer;"  data-id="{{count($features)}}" onclick="addFeature(this)" class="btn_1 gray "><i class="fa fa-fw fa-plus-circle"></i>{{__("services.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="{{ asset('/assets/admin/js/lib/tinymce.min.js') }}"></script>

    <script>

        function addFeature(elem)
        {
            var num = $(elem).attr('data-id');
            var newrow = parseInt(num)+1;
            $(elem).attr('data-id', newrow);

            $.ajax({
                url : url_feature,
                type : 'GET',
                data : 'key='+num,
                success:function(data)
                {
                    $('#features').append(data);
                }
            })
        }

        function remove(elem)
        {
            $(elem).closest('.row').remove();
        }

    </script>

    <script>
        var route_prefix = "{{ url(config('lfm.prefix')) }}";
        var url = "{{url('/')}}/";
    </script>
    <script>
        let url_feature = "{{route('fetch.features')}}",
            currentLanguage = "{{getCurrentLocale()}}";
    </script>
    <script>
        // Initialize TinyMCE for services description fields
        tinymce.init({
            path_absolute : url,
            selector: "textarea.tinymce",
            plugins: [
                "advlist autolink lists link image charmap print preview hr anchor pagebreak",
                "searchreplace wordcount visualblocks visualchars code fullscreen",
                "insertdatetime media nonbreaking save table contextmenu directionality",
                "emoticons template paste textcolor colorpicker textpattern"
            ],
            toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image media",
            relative_urls: false,
            file_browser_callback : function(field_name, url, type, win) {
                var x = window.innerWidth || document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth;
                var y = window.innerHeight|| document.documentElement.clientHeight|| document.getElementsByTagName('body')[0].clientHeight;

                var cmsURL = url + 'laravel-filemanager?field_name=' + field_name;
                if (type == 'image') {
                    cmsURL = cmsURL + "&type=Images";
                } else {
                    cmsURL = cmsURL + "&type=Files";
                }

                tinyMCE.activeEditor.windowManager.open({
                    file : cmsURL,
                    title : 'Filemanager',
                    width : x * 0.8,
                    height : y * 0.8,
                    resizable : "yes",
                    close_previous : "no"
                });
            }
        });
    </script>
@endsection



