@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($trainreservation ?? ''  && $trainreservation->id)
            @method('PUT')
            <input type="hidden" name="id" value="{{$trainreservation->id}}">
        @endif
        @CSRF

        <div class="form-group col-lg-6">
            <label>{{ meta('trainner', getCurrentLocale()) ?? __('trainreservations.trainner') }} </label>
           <select class="selectpicker form-control {{ $errors->has('trainner_id') ? 'is-invalid' : '' }}" data-show-subtext="true" data-live-search="true" name="trainner_id" id="trainner">
               <option selected disabled>{{__('trainreservations.select')}}</option>
               @foreach($trainners as $row)
               <option @if($trainreservation ?? ''  && $trainreservation->id) @if($row->id == $trainreservation->trainner_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()) ?? __('trainreservations.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>{{__('trainreservations.select')}}</option>
               @foreach($patients as $row)
               <option @if($trainreservation ?? ''  && $trainreservation->id) @if($row->id == $trainreservation->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()) ?? __('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", $trainreservation->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", $trainreservation->timing ?? "") }}'/>
        </div>
         @if($trainreservation ?? ''  && $trainreservation->id)
        @if(!is_null($trainreservation->count))
         <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" id="count" placeholder="{{ meta('count', getCurrentLocale()) ??__('trainreservations.count') }}" value='{{ old("count", $trainreservation->count ?? "") }}'/>
        </div>
         @endif
         @endif
         @if($trainreservation ?? ''  && $trainreservation->id)
         
           <div class="form-group col-lg-6">
            <label>{{ meta('expired', getCurrentLocale()) ?? __('trainreservations.expired') }} </label>
           <select class="form-control {{ $errors->has('expired') ? 'is-invalid' : '' }}" name="expired">
               <option selected disabled>{{__('trainreservations.select')}}</option>
               <option  @if( $trainreservation->expired =='0') selected @endif  value="0">{{__('trainreservations.expired')}}</option>
               <option  @if( $trainreservation->expired =='1') selected @endif  value="1">{{__('trainreservations.notexpired')}}</option>
              
           </select>
            </div>
            @endif
            
         <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>
     $(document).ready(function(){
   
    $(document).on('change','#trainner',function(){
      
      var trainner = $('#trainner').val();
     
          var dates = $('#dating').val();
        var data = trainner + ','+ dates;
       
        
        $.ajax({
          url : urls+data,
          type : 'GET',
          data : 'nothing',
          dataType : 'json',
          success:function(data)
          {
            $('#table').html(data);
            
          }
        })
         $.ajax({
          url : url_branch+trainner,
          type : 'GET',
          data : 'nothing',
          dataType : 'json',
          success:function(data)
          {
            $('#branch').html(data);
            
          }
        })  
      

    });
    $(document).on('change','#dating',function(){
      
      var trainner = $('#trainner').val();
     
          var dates = $('#dating').val();
        var data = trainner + ','+ dates;
        if(trainner != 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/datingtrain')}}/",
            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
