@extends('admin.layouts.container')

@section('content')

<div class="side-title">
    <h3>{{ $head ?? '' }}</h3>
</div>

<div class="border-item">
    <form class="form-row" id="form" method="post" action="{{ $action }}" enctype="multipart/form-data">
        @if($service ?? ''  && $service->id)
            @method('PUT')
        @endif
        @CSRF
 @if($service ?? ''  && $service->id)
  @php 
            $error_name ='service_name';
            $error_description ='service_description';

              @endphp
               @foreach($language as $lang)
     <div class="form-group col-lg-6">
            <label>The Name {{$lang->local}} </label>
            @php 
            $error_name ='service_'.$lang->local.'_name';
            $error_description ='service_'.$lang->local.'_description';
              @endphp
            <input type="text" class="form-control {{ $errors->has($error_name) ? 'is-invalid' : '' }}" name="service[{{$lang->local}}][name]" placeholder="{{ meta('name', getCurrentLocale()) ??__('services.name') }}" id="{{$error_name}}" value='{{ old("$error_name", servicename($service->id,$lang->id) ?? "") }}'/>
            <input type="hidden" name="service[{{$lang->local}}][language_id]" value="{{$lang->id}}">
        </div>

        <div class="form-group col-lg-6">
            <label>The Description {{$lang->local}} </label>
            <input type="text" class="form-control {{ $errors->has($error_description) ? 'is-invalid' : '' }}" id="{{$error_description}}" name="service[{{$lang->local}}][description]" placeholder="{{ meta('description', getCurrentLocale()) ??__('services.description') }}" value='{{ old("$error_description", servicedescription($service->id,$lang->id) ?? "") }}'/>
        </div>
       @endforeach
 @else
 @foreach($language as $lang)
        <div class="form-group col-lg-6">
            <label>The Name {{$lang->local}} </label>
            @php 
            $error_name ='service_'.$lang->local.'_name';
            $error_description ='service_'.$lang->local.'_description';
              @endphp
            <input type="text" class="form-control {{ $errors->has($error_name) ? 'is-invalid' : '' }}" name="service[{{$lang->local}}][name]" placeholder="{{ meta('name', getCurrentLocale()) ??__('services.name') }}" id="{{$error_name}}" value='{{ old("$error_name", $service->name ?? "") }}'/>
            <input type="hidden" name="service[{{$lang->local}}][language_id]" value="{{$lang->id}}">
        </div>

        <div class="form-group col-lg-6">
            <label>The Description {{$lang->local}} </label>
            <input type="text" class="form-control {{ $errors->has($error_description) ? 'is-invalid' : '' }}" id="{{$error_description}}" name="service[{{$lang->local}}][description]" placeholder="{{ meta('description', getCurrentLocale()) ??__('services.description') }}" value='{{ old("$error_description", $service->description ?? "") }}'/>
        </div>


    @endforeach
    @endif
     <div class="form-group col-lg-12">
            <label>{{ meta('img', getCurrentLocale()) ?? __('services.img') }} </label>
            <input type="file" class="form-control" name="img" id="img" />
            
        </div>

     <a style="cursor: pointer;float:right;"@if($service ?? ''  && $service->id)  data-id="{{($forms->count())}}" onclick="addform(this)" @else    data-id="0" onclick="addform(this)" @endif class="btn_1 gray"><i class="fa fa-fw fa-plus-circle"></i>{{__('services.add_form')}}</a>
<table id="pricing-list-container" style="width:100%;" >
                            <tbody id="body">
                                 @if($service ?? ''  && $service->id)
                           @foreach($forms as $key=>$row)
                           <tr class="pricing-list-item" id="data0" >
                  <td>
                   <div class="row" id="data">
                   
                     @foreach($language as $lang)
                       <div class="col-md-5" >
                                                    <div class="form-group">
                                                        <input type="text" class="form-control" name="form[{{$key}}][{{$lang->local}}][question]" id="form_{{$key.'_'.$lang->local}}_question" placeholder='{{__("questions.form")}} {{$lang->local}}' value="{{formlang($row->id,$lang->id)}}">
                                                        <input type="hidden" name="form[{{$key}}][{{$lang->local}}][lang]" value="{{$lang->id}}">
                                                    </div>
                                                </div>
                    @endforeach
                                                <div class="col-md-1">
                     <a style="font-size:25px;margin-top:5px;cursor: pointer;" row-id="{{$row->id}}" onclick="deleteform(this)"><i  class="fas fa-times-circle" ></i></a>
                                            </div>
                                                
                                            
                    
                   </div>
                       </td>
         </tr>
                          @endforeach    
                          @endif 
                            </tbody>
                             
                                </table>


      
        
        

        <div class="text-center mt-5 col-12">
            <button class="butn" @if($service ?? ''  && $service->id) onclick="update()" @else onclick="store()" @endif> {{ __('site.save') }}</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>
        let route_prefix = "{{ url(config('lfm.prefix')) }}",
            url = "{{url('/')}}/",
            imagePath = "{{asset('')}}";
            url_editform = {!! json_encode(url(getCurrentLocale().'/admin/editform')) !!}
            url_addform = {!! json_encode(url(getCurrentLocale().'/admin/addform')) !!}
            url_deleteform = {!! json_encode(url(getCurrentLocale().'/admin/deleteform')) !!}
    </script>

    <script src="{{ asset('assets/admin/js/addform.js') }}"></script>
    <script src="{{ asset('assets/admin/js/editor.js') }}"></script>
    <script src="{{ asset('assets/admin/js/lfm.js') }}"></script>
@endsection
