@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($reservation ?? ''  && $reservation->id)
            @method('PUT')
        @endif
        @CSRF 
       <input type="hidden" name="id" value="{{$reservation->id}}">
       <input type="hidden" name="trainner_id" id="trainner" value="{{\Auth::user()->id}}">
       
        <div class="form-group col-lg-12">
        <label>{{__('trainreservations.patient_details')}}</label>
        <br><br>
        @foreach($systemfoods as $data)
          <label>#{{$data->name}}</label>
            <table id="pricing-list-container" style="width:100%;word-break:break-all">
                <thead>
                    <th >{{__('trainreservations.meal_name')}}</th>
                    <th >{{__('trainreservations.meal_type')}}</th>
                    <th >{{__('trainreservations.meal_calories')}}</th>
                    <th >{{__('trainreservations.meal_fats')}}</th>
                    <th >{{__('trainreservations.meal_carbohydrates')}}</th>
                    <th >{{__('trainreservations.meal_protein')}}</th>
                    <th >{{__('trainreservations.meal_glycemic')}}</th>
                    
                </thead>
                <tbody>
                      @foreach($data->meals->sortBy('type') as $row)
                    <tr>
                    <td>{{$row->name}}</td>
                    <td>@if($row->type == '1'){{__('trainreservations.breakfast')}} @elseif($row->type == '2') {{__('trainreservations.launch')}} @elseif($row->type == '3') {{__('trainreservations.dinner')}}  @else {{__('trainreservations.snakes')}} @endif</td>
                    <td>{{$row->calories}}</td>
                    <td>{{$row->fats}}</td>
                    <td>{{$row->Carbohydrates}}</td>
                    <td>{{$row->Protein}}</td>
                    <td>{{$row->glycemic}}</td>
                    </tr>
                    @endforeach
                </tbody>
            </table> 
            <br><br>
            @endforeach
            @if(count($reservations)>0)
          
            <h3>{{__('trainreservations.continue_reservation')}}</h3>
            @php $all = $reservation->count ;
                 $remain = $all - $reserved;
            @endphp
            <h5>{{__('trainreservations.remain_reservation') .' : ' }} @if($remain != '0') {{$remain}} @else {{__('trainreservations.notcontinue')}} @endif</h5>
            <br><br>
            <label>{{__('trainreservations.compare')}}</label>
            <table id="pricing-list-container" style="width:100%;">
                <thead>
                    <th>#</th>
                    <th>{{__('trainreservations.height')}}</th>
                    <th>{{__('trainreservations.width')}}</th>
                    <th>{{__('trainreservations.wight')}}</th>
                    <th>{{__('trainreservations.train')}}</th>
                    <th>{{__('trainreservations.trainner')}}</th>
                    <th>{{__('trainreservations.day')}}</th>
                </thead>
                <tbody>
                    @foreach($reservations as $key=>$row)
                    <tr>
                    <td>{{$key+1}}</td>
                    <td>{{$row->height}}</td>
                    <td>{{$row->width}}</td>
                    <td>{{$row->weight}}</td>
                    <td>{{$row->system_physic['name']}}</td>
                    <td>{{$row->trainner->name}}</td>
                    <td>{{date("Y-m-d", strtotime($row->created_at) )}}</td>
                </tr>
                    @endforeach
                </tbody>
            </table> 
            <br><br>
            
          
            <label>#{{$last->system_physic->name}} : {{$last->code->name}}</label>
            <table id="pricing-list-container" style="width:100%;word-break:break-all">
                <thead>
                    <th >{{__("meals.number")}}</th>
                    
                </thead>
                <tbody>
                    @foreach($allreserved as $key=>$rows)
                    <tr><td style="width:20pc">{{$key+1}} </td> @foreach($rows->physics as $row) <td>{{$row->physcal->name}} ({{$row->num}})</td> @endforeach </tr>
                    @endforeach
                </tbody>
            </table> 
            <br><br>
        
            
            
              
            @else
            <h3>{{__('trainreservations.new_reservation')}}</h3>
            @endif
       
        </div>
        
        <label>{{__('trainreservations.patient_details')}}</label>
         <div class="row">
            
              <div class="form-group col-lg-6">
                   <label>{{  __('trainreservations.patient') }} </label>
            <input type="text" disabled class="form-control"  value='{{$patient->name}}'/>
              </div>
               <div class="form-group col-lg-6">
                   <label>{{  __('trainreservations.patient_email') }} </label>
            <input type="text" disabled class="form-control"  value='{{$patient->email}}'/>
              </div>
                 <div class="form-group col-lg-6">
                   <label>{{  __('trainreservations.patient_phone') }} </label>
            <input type="text" disabled class="form-control"  value='{{$patient->phone}}'/>
              </div>
                 <div class="form-group col-lg-6">
                   <label>{{  __('trainreservations.patient_email') }} </label>
            <input type="text" disabled class="form-control"  value='{{$patient->email}}'/>
              </div>
              @if(!is_null($patient->details))
                 <div class="form-group col-lg-6">
                   <label>{{  __('trainreservations.patient_status') }} </label>
            <input type="text" disabled class="form-control"  value='{{$patient->details->status}}'/>
              </div>
             
             <div class="form-group col-lg-6">
                   <label>{{  __('trainreservations.patient_job') }} </label>
            <input type="text" disabled class="form-control"  value='{{$patient->details->job}}'/>
              </div>
              
             <div class="form-group col-lg-6">
                   <label>{{  __('trainreservations.patient_gender') }} </label>
            <input type="text" disabled class="form-control"  value='@if($patient->details->gender == "1") {{  __("reservations.male") }}  @else {{  __("reservations.female") }} @endif'/>
              </div>
            <div class="form-group col-lg-6">
                   <label>{{  __('trainreservations.patient_date_of_birth') }} </label>
            <input type="text" disabled class="form-control"  value='{{$patient->details->date_of_birth}}'/>
              </div>
              @endif
         </div>
         
        @if(count($reservations)==0)
         <div class="form-group col-lg-6">
            <label>{{ meta('count', getCurrentLocale()) ?? __('trainreservations.count') }} </label>
            <input type="number" min="0"  class="form-control {{ $errors->has('count') ? 'is-invalid' : '' }}" name="count" placeholder="{{ meta('count', getCurrentLocale()) ??__('trainreservations.count') }}" value='{{ old("count", $reservation->count ?? "") }}'/>
        </div>
        <div class="form-group col-lg-6"></div>
        @else
          <div class="form-group col-lg-12">
            <label>{{ meta('type', getCurrentLocale()) ?? __('trainreservations.type') }} </label>
          <select class="form-control {{ $errors->has('type') ? 'is-invalid' : '' }}" name="type">
              <option value="1">{{__('trainreservations.arrived')}}</option>
                    <option value="0">{{__('trainreservations.notarrived')}}</option>
                    </select>
           </div>
        @endif
         <div class="form-group col-lg-6">
            <label>{{ meta('dating', getCurrentLocale()) ?? __('trainreservations.dating') }} </label>
            <input type="date"  class="form-control {{ $errors->has('dating') ? 'is-invalid' : '' }}" name="dating" id="dating" placeholder="{{ meta('dating', getCurrentLocale()) ??__('trainreservations.dating') }}" value='{{ old("dating") }}'/>
        </div>
         <div class="form-group col-lg-6">
            <label>{{ meta('timing', getCurrentLocale()) ?? __('trainreservations.timing') }} </label>
            <input type="time"  class="form-control {{ $errors->has('timing') ? 'is-invalid' : '' }}" name="timing" placeholder="{{ meta('timing', getCurrentLocale()) ??__('trainreservations.timing') }}" value='{{ old("timing") }}'/>
        </div>
         <div id="table" class="text-center mt-4 col-12">
            
         </div>
         
      
       
           
         @if(count($reservations)==0)
        <div class="form-group col-lg-6">
            <label>{{ meta('system_physic_id', getCurrentLocale()) ?? __('reservations.system_physic_id') }} </label>
          <select onchange="foodcodes(this)" class="form-control {{ $errors->has('system_physic_id') ? 'is-invalid' : '' }}" name="system_physic_id" id="system_food">
              <option selected  value="">{{__('reservations.select')}}</option>
                    @foreach($systemphysics as $row)
                    <option value="{{$row->id}}">{{$row->name}}</option>
                    @endforeach
                    </select>
           </div>
        @else
        <div class="form-group col-lg-6">
            <label>{{ meta('system_physic_id', getCurrentLocale()) ?? __('reservations.system_physic_id') }} </label>
          <select onchange="foodcodes(this)" class="form-control {{ $errors->has('system_physic_id') ? 'is-invalid' : '' }}" name="system_physic_id" id="system_food">
              <option selected  value="">{{__('reservations.select')}}</option>
                    @foreach($systemphysics as $row)
                    <option @if($last->system_physic_id == $row->id) selected @endif value="{{$row->id}}">{{$row->name}}</option>
                    @endforeach
                    </select>
           </div>
        @endif
      
             <div class="form-group col-lg-6" >
                  <label>{{ meta('code_id', getCurrentLocale()) ?? __('reservations.code_id') }} </label>
          <select onchange="codemeal(this)" class="form-control {{ $errors->has('system_physic_id') ? 'is-invalid' : '' }}" id="tablephysicalcode" name="code_id" >
              <option selected  value="">{{__('reservations.selectsystem')}}</option>
                   @if(count($reservations)>0)
                   @foreach($codes as $row)
                   <option @if($last->code_id == $row->id) selected @endif value="{{$row->id}}">{{$row->name}}</option>
                   @endforeach
                   @endif
                    </select>
           </div>
            
             <div class="form-group col-lg-12" id="tablephysical" >
               @if(count($reservations)>0)
               @foreach($physcals as $key=>$row)
               <div id="mealrow" class="row">
         <div class="form-group col-lg-6">
            <label>تمرين </label>
            <input type="hidden" class="form-control" name="physcal[{{$key}}][physcal_id]" value="{{$row->physcal_id}}" />
            <input type="text" class="form-control" disabled value="{{$row->physcal->name}}" />
            </div>
          <div class="form-group col-lg-5">
            <label>العدد </label>
            <input type="number" min="0" class="form-control" name="physcal[{{$key}}][num]" value="{{$row->num}}" />
            </div>
           <div class="form-group col-lg-1" style="font-size: 30px;margin-top:35px;">
    	<i class="fas fa-times-circle" onclick="remove(this)"></i></div></div>
               @endforeach
               @endif
             </div>
                 <div class="col-lg-12" >
       <a style="cursor: pointer;" id="removing" @if(count($reservations)==0) data-id="0" @else  data-id="{{count($physcals)}}"  @endif onclick="addmeal(this)" class="btn_1 gray "><i class="fa fa-fw fa-plus-circle"></i>{{__("physcalneeds.add_physcal")}}</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')
    <!-- Editor JS files -->
    <script type="text/javascript">
    $(document).ready(function(){
    $(document).on('change','#dating',function(){
      
      var doctor = $('#doctor').val();
     
          var dates = $('#dating').val();
        var data = doctor + ','+ dates;
        
        
        $.ajax({
          url : urldating+data,
          type : 'GET',
          data : 'nothing',
          dataType : 'json',
          success:function(data)
          {
              
            $('#table').html(data);
            
          }
        })
    });
    $(document).on('change','#system_food',function(){
     
      var data = $('#system_food').val();
      
        
        if(doctor != null)
        $.ajax({
          url : urlfood+data,
          type : 'GET',
          data : 'nothing',
          dataType : 'json',
          success:function(data)
          {
              
            $('#tablephyscal').html(data);
            
          }
        })
    });
       $(document).on('change','#system_physical',function(){
      
      var data = $('#system_physical').val();
    
        
        if(doctor != null)
        $.ajax({
          url : urlphysical+data,
          type : 'GET',
          data : 'nothing',
          dataType : 'json',
          success:function(data)
          {

            $('#tablephysical').html(data);
            
          }
        })
    });
  });
    function addanatomy(elem) {
    
  
      var datarow =$(elem).attr('counter');
      
      var newdata = parseInt(datarow)+1; 
      
      $(elem).attr('counter', newdata);
        
        $.ajax({
          url : urlanatomy +datarow,
          type : 'GET',
          data : 'nothing',
          dataType : 'json',
          success:function(data)
          {
            $('#anatomy').append(data);
          }
        })
}
</script>
<script type="text/javascript">
    function addprescription(elem) {
    
  
      var datarow =$(elem).attr('counter');
      
      var newdata = parseInt(datarow)+1; 
      
      $(elem).attr('counter', newdata);
        
        $.ajax({
          url : urlprescription +datarow,
          type : 'GET',
          data : 'nothing',
          dataType : 'json',
          success:function(data)
          {
            $('#prescription').append(data);
          }
        })
}

    function addmeal(elem){
        $("#meals").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',
          dataType : 'json',
          success:function(data)
          {
            $('#tablephysical').append(data);
          }
        })
    }
    function foodcodes(elem){
        var num = $(elem).val();
        
        
         $.ajax({
          url : urlfoodcode +num,
          type : 'GET',
          data : 'nothing',
          dataType : 'json',
          success:function(data)
          {
              
              $('#tablephysicalcode').html(data);
          }
        })
    }
    function codemeal(elem)
    {
        
        var num = $(elem).val();
        
        
         $.ajax({
          url : urlmealcode +num,
          type : 'GET',
          data : 'nothing',
          dataType : 'json',
          success:function(data)
          {
              $('#removing').attr('data-id',data.counting);
              $('#tablephysical').html(data.outs);
          }
        })
    }
    function remove(elem){
            $(elem).closest('#mealrow').remove();
        }
</script>

{{--    <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/addphysictypes",
            urlanatomy = "{{url('admin/anatomy')}}/",
            urlprescription = "{{url('admin/prescription')}}/",
            urldating = "{{url('admin/datingtrain')}}/",
            urlfood = "{{url('admin/systemphysic')}}/",
            urlfoodcode = "{{url('admin/physcalcode')}}/",
            urlmealcode = "{{url('admin/physiccode')}}/",
            urlphysical = "{{url('admin/systemphysical')}}/",
            imagePath = "{{asset('')}}";
    </script>
    <script src="{{ asset('assets/admin/js/editor.js') }}"></script>
    <script src="{{ asset('assets/admin/js/lfm.js') }}"></script>
@endsection
