@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">{{__('packages.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">{{__('packages.features')}}</span>
                </a>
            </li>

        </ul>
        <form class="form-row" method="post" onsubmit="saveForm(this)" action="{{ $action }}" enctype="multipart/form-data">
            @if($package ?? ''  && $package->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">

                        <div class="form-group col-lg-6">
                            <label>{{ meta('cost', getCurrentLocale()) ?? __('packages.cost') }} </label>
                            <input type="number" min="0" step=".01" class="form-control {{ $errors->has('cost') ? 'is-invalid' : '' }}" name="cost" placeholder="{{ meta('cost', getCurrentLocale()) ?? __('packages.cost') }}" value='{{ old("cost", $package->cost ?? "") }}'/>
                        </div>

                        @foreach($languages as $language)

                            <div class="form-group col-lg-6">
                                <label>{{ meta('title', $language->local) ?? __('packages.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) ?? __('packages.title') }}" value='{{ old("title_{$language->local}", $package[$language->local]->title ?? "") }}'/>
                            </div>
                            <div class="form-group col-lg-12">
                                <label>{{ meta('description', $language->local) ?? __('packages.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) ?? __('packages.description') }}">{{ old("description_{$language->local}", $package[$language->local]->description ?? "") }}</textarea>
                            </div>

                        @endforeach

                    </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>{{__("packages.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>
        let route_prefix = "{{ url(config('lfm.prefix')) }}",
            url = "{{url('/')}}/",
            url_feature = "{{route('fetch.features')}}",
            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



