@extends('admin.layouts.container')

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

<div class="border-item">
    <form class="form-row" method="post" action="{{ $action }}">
        @if($userphysic ?? ''  && $userphysic->id)
            @method('PUT')
        @endif
        @CSRF

             <div class="form-group col-lg-6">
            <label>{{ meta('patient', getCurrentLocale()) ?? __('ketos.patient') }} </label>
           <select class="selectpicker form-control {{ $errors->has('user_id') ? 'is-invalid' : '' }}" data-show-subtext="true" data-live-search="true"  name="user_id">
               <option selected disabled>{{__('ketos.select')}}</option>
               @foreach($patients as $row)
               <option @if($userphysic ?? ''  && $userphysic->id) @if($row->id == $userphysic->id) selected @endif @endif value="{{$row->id}}">{{$row->name}}</option>
               @endforeach
           </select>
            </div>
              <div class="form-group col-lg-6">
                     @if($userphysic ?? ''  && $userphysic->id)
                     <input type="checkbox" class="checkbox_check" onclick="showdata(this)" style="
    margin-top: 3pc;
    margin-right: 4pc;
">عرض واخفاء 
                     @endif
                 </div>
                 
                 
                  <div class="row pricing-list-item border-item mb-4 col-12" @if($userphysic ?? ''  && $userphysic->id)   @else  style="display:none" @endif  id="ketos">
                    @if($userphysic ?? ''  && $userphysic->id)
                    <div  class="row pricing-list-item border-item mb-4 col-12" style="display:none"  id="ketoshow" >
                    @foreach($userphysics as $data=>$row)
                   
                    <div class="row pricing-list-item border-item mb-4 col-12">
                      
             <div class="form-group col-lg-6">
            <label>{{ meta('dating', getCurrentLocale()) ?? __('ketos.dating') }} </label>
            <input type="date" class="form-control {{ $errors->has('dating') ? 'is-invalid' : '' }}" name="physical[{{$data}}][dating]" value="{{$row->dating}}" id="dating" placeholder="{{ meta('dating', getCurrentLocale()) ??__('ketos.dating') }}" value='{{ old("dating", $userphysic->dating ?? "") }}'/>
        </div>
           
             <div class="form-group col-lg-5">
           <label>{{ __('foods.type') }} </label>
            <select class="form-control" onchange="foodcodes(this)" data-id="{{$data}}"  name="physical[{{$data}}][system_physic_id]">
                <option selected disabled>{{__("foods.select")}}</option>
               @foreach($systemphysics as $systemphysic)
               <option  @if($row->system_physic_id == $systemphysic->id) selected  @endif   value="{{$systemphysic->id}}">{{$systemphysic->name}}</option>
               @endforeach
            </select>
            </div>
         <div class="form-group col-lg-1" style="font-size: 30px;margin-top:30px;" onclick="removeread(this)"><i class="fas fa-times-circle"></i></div>
   

      <div class="form-group col-lg-6">
            <label>الكود </label>
            <select class="form-control" id="type{{$data}}" name="physical[{{$data}}][code_id]">
                <option selected disabled>{{__("foods.select")}}</option>
               @foreach(physiccodes($row->system_physic_id) as $code)
                <option @if($row->code_id == $code->id) selected  @endif   value="{{$code->id}}">{{$code->name}}</option>
                @endforeach
            </select>
        </div>
        <div class="form-group col-lg-12">
            <div  id="physics{{$data}}">
                @foreach(physicsuser($row->id) as $rows=>$physic)
                <div class="row col-12 pricing-list-item border-item mb-4" >
        
           
             <div class="form-group col-lg-6">
           <label>{{ __('foods.type') }} </label>
            <select class="form-control" data-id="{{$data}}"  name="physical[{{$data}}][physicals][{{$row}}][physcal_id]">
                <option selected disabled>{{__("foods.select")}}</option>
               @foreach($physicals as $physical)
               <option @if($physic->physcal_id == $physical->id) selected  @endif value="{{$physical->id}}">{{$physical->name}}</option>
               @endforeach
            </select>
            </div>
              <div class="form-group col-lg-5">
            <label>العدد </label>
            <input type="number" class="form-control" name="physical[{{$data}}][physicals][{{$row}}][num]"  placeholder="العدد" value='{{ $physic->num }}'/>
        </div>
         <div class="form-group col-lg-1" style="font-size: 30px;margin-top:30px;" onclick="remove(this)"><i class="fas fa-times-circle"></i></div>
   

      
             </div>
            
@endforeach
            </div>
        </div>
       <div class="form-group col-lg-12">
               <a style="cursor: pointer;"   data-id="{{$data}}" row-id="{{count(physicsuser($row->id))}}" onclick="addphysic(this)" class="btn_1 gray "><i class="fa fa-fw fa-plus-circle"></i>اضافة تمرين</a>
   
       </div>
             
             
          </div>
                    @endforeach
                    </div>
                    @endif
                    
                </div>
<div class="col-lg-12">
       <a style="cursor: pointer;" @if($userphysic ?? ''  && $userphysic->id) data-id="{{count($userphysics)}}" @else   data-id="0" @endif onclick="addketo(this)" class="btn_1 gray "><i class="fa fa-fw fa-plus-circle"></i>{{__("ketos.add_keto")}}</a>
                   
</div>





           

        <div class="text-center mt-5 col-12">
            <button class="butn"><span>{{ __('dashboard.save') }}</span></button>
        </div>
    </form>
</div>

@endsection

@section('inner_js')
<script>

 function addphysic(elem){
        
        var num = $(elem).attr('data-id');
       let datas = $(elem).attr('row-id');
       var newrow = parseInt(datas)+1; 
        $(elem).attr('row-id', newrow);
        
         $.ajax({
          url : urls_physical+num+','+datas,
          type : 'GET',
          data : 'nothing',
          success:function(data)
          {
            $('#physics'+num).append(data);
          }
        })
    }
    function addketo(elem){
        $("#ketos").css("display", "block");
        var num = $(elem).attr('data-id');
       
       var newrow = parseInt(num)+1; 
        $(elem).attr('data-id', newrow);
        
         $.ajax({
          url : urls+'/'+num,
          type : 'GET',
          data : 'nothing',
          success:function(data)
          {
            $('#ketos').append(data);
          }
        })
    }
     function foodcodes(elem){
        var num = $(elem).val();
        let datas = $(elem).attr('data-id');
        
         $.ajax({
          url : urlfoodcode +num,
          type : 'GET',
          data : 'nothing',
          dataType : 'json',
          success:function(data)
          {
              
              $('#type'+datas).html(data);
          }
        })
    }
    function showdata(elem){
        let data = $(elem).val();
        if ($('input.checkbox_check').is(':checked')) {
            $('#ketoshow').css('display','block');
        }
        else{
            
            $('#ketoshow').css('display','none');
        }
    } 
    
    function removeread(elem){
        $(elem).closest('.row').remove();
    }
     function remove(elem){
            $(elem).closest('.row').remove();
        }
        </script>
    <!-- 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('/')}}/",
            urls = "{{url('/')}}/admin/addphysical",
            urlfoodcode = "{{url('admin/physcalcode')}}/",
            urls_physical = "{{url('admin/physicsdata')}}/",
            url_question = "{{url('/')}}/admin/questiondata",
            imagePath = "{{asset('')}}";
    </script>
    <script src="{{ asset('assets/admin/js/editor.js') }}"></script>
    <script src="{{ asset('assets/admin/js/lfm.js') }}"></script>
@endsection
