@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 }}" enctype="multipart/form-data">
        @if($reservation ?? ''  && $reservation->id)
            @method('PUT')
        @endif
        @CSRF 
       <input type="hidden" name="id" value="{{$reservation->id}}">
       <input type="hidden" name="doctor_id" id="doctor" value="{{\Auth::user()->id}}">
       
        <div class="form-group col-lg-12">
        <label>{{__('reservations.reservation_details')}}</label>
            @if(count($reservations)>0)
            <div class="row">
             <div class="form-group col-lg-4">
            <a href="{{ route ('doctorreservations.anatomyshow', $reservation->id) }}"  class="butn"><span>{{ __('reservations.anatomyshow') }}</span></a>
        </div>
           <div class="form-group col-lg-4">
              <a style="float:right;" href="{{ route ('doctorreservations.prescriptionshow', $reservation->id) }}"  class="butn"><span>{{ __('reservations.prescriptionshow') }}</span></a>
        </div>
        <div class="form-group col-lg-4">
              <a style="float:right;" href="{{ route ('doctorreservations.ultrasoundshow', $reservation->id) }}"  class="butn"><span>ultrasound</span></a>
        </div>
        </div>
            <h3>{{__('reservations.continue_reservation')}}</h3>
            @php $all = $reservation->count + 1;
                 $remain = $all - $reserved;
            @endphp
            <h5>{{__('reservations.remain_reservation') .' : ' }} @if($remain != '0') {{$remain}} @else {{__('reservations.notcontinue')}} @endif</h5>
            <br><br>
            <label>{{__('reservations.compare')}}</label>
            <table id="pricing-list-container" style="width:100%;">
                <thead>
                    <th>#</th>
                <th>{{__('histories.date')}}</th>
                <th>{{__('histories.weight')}}</th>
                <th>{{__('histories.fat')}}</th>
                <th>{{__('histories.muscle')}}</th>
                <th>{{__('histories.liquid')}}</th>
                <th>{{__('histories.bone')}}</th>
                <th>{{__('histories.trust')}}</th>
                <th>{{__('histories.sport')}}</th>
                <th>{{__('histories.recommend')}}</th>
                <th>{{__('histories.complain')}}</th>
                <th>{{__('histories.system')}}</th>
                <th>{{__('histories.note')}}</th>
                </thead>
                <tbody>
                    @foreach($histories as $key=>$row)
                    <tr>
                    <td>{{$key+1}}</td><td>{{$row->date}}</td>
                    <td>{{$row->weight}}</td>
                    <td>{{$row->fat}}</td>
                    <td>{{$row->muscle}}</td>
                    <td>{{$row->liquid}}</td>
                    <td>{{$row->bone}}</td>
                    <td>{{$row->trust}}</td>
                    <td>{{$row->sport}}</td>
                    <td>{{$row->recommend}}</td>
                    <td>{{$row->complain}}</td>
                    <td>{{$row->system}}</td>
                    <td>{{$row->note}}</td>
                </tr>
                    @endforeach
                </tbody>
            </table> 
            <br><br>
            
             <div class="form-group col-lg-12">
                 <textarea class="my-editor" disabled>{{$meal->description}}</textarea>
             </div>
        
              
            @else
            <h3>{{__('reservations.new_reservation')}}</h3>
            @endif
       
        </div>
        <!--
       
         -->
        <label>{{__('reservations.patient_details')}}</label>
         <div class="row">
              
              <div class="form-group col-lg-6">
                   <label>{{  __('reservations.patient') }} </label>
            <input type="text" disabled class="form-control"  value='{{$patient->name}}'/>
              </div>
               <div class="form-group col-lg-6">
                   <label>{{  __('reservations.patient_email') }} </label>
            <input type="text" disabled class="form-control"  value='{{$patient->email}}'/>
              </div>
                 <div class="form-group col-lg-6">
                   <label>{{  __('reservations.patient_phone') }} </label>
            <input type="text" disabled class="form-control"  value='{{$patient->phone}}'/>
              </div>
              
                 <div class="form-group col-lg-6">
                   <label>{{  __('reservations.patient_status') }} </label>
            <input type="text" disabled class="form-control"  value='@if(!is_null($patient->details["status"])){{$patient->details->status}}@endif'/>
              </div>
             <div class="form-group col-lg-6">
                   <label>{{  __('reservations.patient_job') }} </label>
            <input type="text" disabled class="form-control"  value='@if(!is_null($patient->details["job"])){{$patient->details->job}}@endif'/>
              </div>
              
             <div class="form-group col-lg-6">
                   <label>{{  __('reservations.patient_gender') }} </label>
            <input type="text" disabled class="form-control"  value='@if(!is_null($patient->details["gender"]))@if($patient->details->gender == "1") {{  __("reservations.male") }}  @else {{  __("reservations.female") }} @endif @endif'/>
              </div>
            <div class="form-group col-lg-6">
                   <label>{{  __('reservations.patient_date_of_birth') }} </label>
            <input type="text" disabled class="form-control"  value='@if(!is_null($patient->details["date_of_birth"])){{$patient->details->date_of_birth}}@endif'/>
              </div>
         </div>
         
        @if(count($reservations)==0)
         <div class="form-group col-lg-6">
            <label>{{ meta('count', getCurrentLocale()) ?? __('reservations.count') }} </label>
            <input type="number" min="0"  class="form-control {{ $errors->has('count') ? 'is-invalid' : '' }}" name="count" placeholder="{{ meta('count', getCurrentLocale()) ??__('reservations.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()) ?? __('reservations.type') }} </label>
          <select class="form-control {{ $errors->has('type') ? 'is-invalid' : '' }}" name="type">
              <option value="1">{{__('reservations.arrived')}}</option>
                    <option value="0">{{__('reservations.notarrived')}}</option>
                    </select>
           </div>
        @endif
         <div class="form-group col-lg-6">
            <label>{{ meta('dating', getCurrentLocale()) ?? __('reservations.dating') }} </label>
            <input type="date"  class="form-control {{ $errors->has('dating') ? 'is-invalid' : '' }}" name="dating" id="dating" placeholder="{{ meta('dating', getCurrentLocale()) ??__('reservations.dating') }}" value='{{ old("dating") }}'/>
        </div>
         <div class="form-group col-lg-6">
            <label>{{ meta('timing', getCurrentLocale()) ?? __('reservations.timing') }} </label>
            <input type="time"  class="form-control {{ $errors->has('timing') ? 'is-invalid' : '' }}" name="timing" placeholder="{{ meta('timing', getCurrentLocale()) ??__('reservations.timing') }}" value='{{ old("timing") }}'/>
        </div>
         <div id="table" class="text-center mt-4 col-12">
            
         </div>
          <div class="form-group col-lg-6">
            <label>يحتاج الي تدريب  </label>
             
            <select class="form-control" name="physcal">
                
                <option @if(count($reservations)!=0) @if($last->type == '0') selected @endif @endif value="0">لا يحتاج</option>
                <option @if(count($reservations)!=0) @if($last->type == '1') selected @endif @endif value="1">يحتاج</option>
                
            </select>
            </div>
        {{--Start image container--}}
        <div class="form-group col-lg-12">
            <label>{{ meta('image', getCurrentLocale()) ?? __('reservations.image') }} </label>
            <input id="image_thumbnail" class="image_thumbnail" type="hidden" name="image" value="{{old("image", $reservation->image ?? "")}}"/>

            <div class="images main_image {{ old('image', $reservation->image ?? '') ? ' wow fadeInUp' : 'hide' }}">
                <div class="col-lg-4">
                    <div class="items">
                        <div class="img">
                            <a href="#" id="lfm" data-input=".image_thumbnail" data-preview=".image_holder" class="lfm" data-hide=".pick_button">
                                <img src="{{asset(old('image', $reservation->image ?? ''))}} "  id="image_holder" class="image_holder"/>
                            </a>
                        </div>
                        <a href="#" class="showHide resetImage close" data-empty=".image_thumbnail" data-hide=".main_image" data-show=".pick_button"><i class="fas fa-times"></i></a>
                    </div>
                </div>
            </div>

            <div class="clearfix"></div>
            <span class="input-group-btn pick_button {{ old('image', $reservation->image ?? '') ? 'hide' : '' }} ">
                <a id="lfm" data-input=".image_thumbnail" data-preview=".image_holder" data-show=".main_image" data-hide=".pick_button" class="lfm btn btn-primary text-light">
                    <i class="fas fa-camera-retro"></i> Choose
                </a>
            </span>
        </div>
         <div class="form-group col-lg-12" >
        <div  class="row">
        {{--End image container--}}    
        
        <div class="form-group col-lg-6">
            <label>{{ meta('system_food_id', getCurrentLocale()) ?? __('reservations.system_food_id') }} </label>
          <select onchange="foodcodes(this)" class="form-control {{ $errors->has('system_food_id') ? 'is-invalid' : '' }}" name="system_food_id" id="system_food">
              <option selected  value="">{{__('reservations.select')}}</option>
                    @foreach($systemfoods as $row)
                    <option value="{{$row->id}}">{{$row->name}}</option>
                    @endforeach
                    </select>
           </div>
        
       <div class="form-group col-lg-6" id="categories">
           
       </div>
       <div class="form-group col-lg-6" id="calories">
           
       </div>
       <div class="form-group col-lg-6" id="codes">
           
       </div>
       
       <div class="form-group col-lg-12" id="desc">
           
       </div>
         
       
            </div>
           
            
            
              
             </div>
               
                
                
             
               

            
       <a style="cursor: pointer;"   counter="0"  onclick="addanatomy(this)" class="btn_1 gray"><i class="fa fa-fw fa-plus-circle"></i>{{__('reservations.addanatomy')}}</a>
              <table  style="width:100%;" >
                <tbody id="anatomy"> 
                  </tbody>

            </table>
            <br>
              <a style="cursor: pointer;"   counter="0"  onclick="addprescription(this)" class="btn_1 gray"><i class="fa fa-fw fa-plus-circle"></i>{{__('reservations.addprescription')}}</a>
              <table  style="width:100%;" >
                <tbody id="prescription"> 
                  </tbody>

            </table>
            <a style="cursor: pointer;"   counter="0"  onclick="addultra(this)" class="btn_1 gray"><i class="fa fa-fw fa-plus-circle"></i>{{__('reservations.addultrasound')}}</a>
              <table  style="width:100%;" >
                <tbody id="ultra"> 
                  </tbody>

            </table>
       

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

@endsection

@section('inner_js')
<script src="{{ asset('/assets/admin/js/lib/tinymce.min.js') }}"></script>
 
    <!-- 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;
        if(doctor != null)
        $.ajax({
          url : urldating+data,
          type : 'GET',
          data : 'nothing',
          dataType : 'json',
          success:function(data)
          {
              
            $('#table').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);
              $('#tablefood').html(data.outs);
          }
        })
    }
    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)
          {
            $('#tablefood').append(data);
          }
        })
    }
    
     function fooddesc(elem){
         var num = $(elem).val();
         
         $.ajax({
          url : urlfooddesc +num,
          type : 'GET',
          data : 'nothing',
          dataType : 'json',
          success:function(data)
          {
              $('#desc').html(`
         
       
          <label>الوجبة </label>
                <textarea name="description" class="appended_text_area">`+data+`</textarea>
               
            `);
            tinymce.init({
                selector: '.appended_text_area',
                init_instance_callback: function (editor) {
                    editor.on('click', function (e) {
                        console.log('Element clicked:', e.target.nodeName);
                    });
                }
            });
              
          }
        })
    
     }
     
     
    function foodcoding(elem){
         var num = $(elem).val();
        
        
         $.ajax({
          url : urlfoodcoding +num,
          type : 'GET',
          data : 'nothing',
          dataType : 'json',
          success:function(data)
          {
              
              $('#codes').html(data);
          }
        })
    }
    function foodcals(elem){
        var num = $(elem).val();
        
        
         $.ajax({
          url : urlfoodcal +num,
          type : 'GET',
          data : 'nothing',
          dataType : 'json',
          success:function(data)
          {
              
              $('#calories').html(data);
          }
        })
    }
    function foodcodes(elem){
        var num = $(elem).val();
        
        
         $.ajax({
          url : urlfoodcode +num,
          type : 'GET',
          data : 'nothing',
          dataType : 'json',
          success:function(data)
          {
              
              $('#categories').html(data);
          }
        })
    }
    function physcalcode(elem){}
    
    
    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 addultra(elem){
    var datarow =$(elem).attr('counter');
      
      var newdata = parseInt(datarow)+1; 
      
      $(elem).attr('counter', newdata);
        
        $.ajax({
          url : urlultra +datarow,
          type : 'GET',
          data : 'nothing',
          dataType : 'json',
          success:function(data)
          {
            $('#ultra').append(data);
          }
        })
}
    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 remove(elem){
            $(elem).closest('#mealrow').remove();
        }
</script>

   <script>
        let route_prefix = "{{ url(config('lfm.prefix')) }}",
            url = "{{url('/')}}/",
            urls = "{{url('/')}}/admin/addmealtypes",
            urlanatomy = "{{url('admin/anatomy')}}/",
            urlprescription = "{{url('admin/prescription')}}/",
            urldating = "{{url('admin/dating')}}/",
            urlfood = "{{url('admin/systemfood')}}/",
            urlfoodcode = "{{url('admin/foodcode')}}/",
            urlfoodcoding = "{{url('admin/foodcoding')}}/",
            urlfooddesc = "{{url('admin/fooddesc')}}/",
            urlfoodcal = "{{url('admin/foodcalories')}}/",
            urlmealcode = "{{url('admin/mealcode')}}/",
            urlultra = "{{url('admin/addultra')}}/",
            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
