@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')
            <input type="hidden" name="id" value="{{$reservation->id}}">
        @endif
        @CSRF

        <div class="form-group col-lg-6">
            <label>{{ meta('doctor', getCurrentLocale()) ?? __('reservations.doctor') }} </label>
           <select class="selectpicker form-control  {{ $errors->has('doctor_id') ? 'is-invalid' : '' }}" data-show-subtext="true" data-live-search="true" onchange="doctorselection(this)"  name="doctor_id" id="doctor">
               <option selected disabled>{{__('reservations.select')}}</option>
               @foreach($doctors as $row)
               <option @if($reservation ?? ''  && $reservation->id) @if($row->id == $reservation->doctor_id) selected @endif @endif value="{{$row->id}}">{{$row->name}}</option>
               @endforeach
           </select>
            </div>
            <div class="form-group col-lg-6">
            <label>{{ meta('branch', getCurrentLocale()) ?? __('reservations.branch') }} </label>
           <select class="form-control {{ $errors->has('branch_id') ? 'is-invalid' : '' }}"  name="branch_id" id="branch">
               <option selected disabled>{{__('reservations.selectdoctor')}}</option>
               
           </select>
            </div>
            
             <div class="form-group col-lg-6">
            <label>{{ meta('patient', getCurrentLocale()) ?? __('reservations.patient') }} </label>
           <select class="selectpicker form-control {{ $errors->has('patient_id') ? 'is-invalid' : '' }}" data-show-subtext="true" data-live-search="true"  name="patient_id">
               <option selected disabled>{{__('reservations.select')}}</option>
               @foreach($patients as $row)
               <option @if($reservation ?? ''  && $reservation->id) @if($row->id == $reservation->patient_id) selected @endif @endif value="{{$row->id}}">{{$row->name}}</option>
               @endforeach
           </select>
            </div>
         <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", $reservation->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", $reservation->timing ?? "") }}'/>
        </div>
           <div class="form-group col-lg-6">
            <label>{{ meta('type', getCurrentLocale()) ?? __('reservations.type') }} </label>
           <select class="form-control {{ $errors->has('type') ? 'is-invalid' : '' }}" name="type">
               <option selected disabled>{{__('reservations.select')}}</option>
               <option @if($reservation ?? ''  && $reservation->id) @if( $reservation->type =='0') selected @endif @endif value="0">{{__('reservations.offline')}}</option>
               <option @if($reservation ?? ''  && $reservation->id) @if( $reservation->type =='1') selected @endif @endif value="1">{{__('reservations.online')}}</option>
              
           </select>
            </div>
         
         <div id="table" class="text-center mt-4 col-12">
            
         </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 doctorselection(elem){
       var doctor = $('#doctor').val();
     
          var dates = $('#dating').val();
        var data = doctor + ','+ dates;
        
        $.ajax({
          url : urls+data,
          type : 'GET',
          data : 'nothing',
          dataType : 'json',
          success:function(data)
          {
            $('#table').html(data);
            
          }
        })
          $.ajax({
          url : url_branch+doctor,
          type : 'GET',
          data : 'nothing',
          dataType : 'json',
          success:function(data)
          {
            $('#branch').html(data);
            
          }
        })  
  }
    
    $(document).on('change','#dating',function(){
      
      var doctor = $('#doctor').val();
     
          var dates = $('#dating').val();
        var data = doctor + ','+ dates;
        if(doctor != null)
        $.ajax({
          url : urls+data,
          type : 'GET',
          data : 'nothing',
          dataType : 'json',
          success:function(data)
          {
              
            $('#table').html(data);
            
          }
        })
        
      

    });
    
 

    
  

</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/dating')}}/",
            url_branch ="{{url('admin/branch')}}/",
            imagePath = "{{asset('')}}";
    </script>
    <script src="{{ asset('assets/admin/js/editor.js') }}"></script>
    <script src="{{ asset('assets/admin/js/lfm.js') }}"></script>
@endsection
