@extends('admin.layouts.container')

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

<div class="border-item">
    <form class="form-row" enctype="multipart/form-data" method="post" action="{{ $action }}">
        
        @if($medicine ?? ''  && $medicine->id)
            @method('PUT')
        @endif
        @CSRF
         
         <div class="form-group col-lg-6">
                <label>{{ meta('user', getCurrentLocale()) ?? __('medicines.user') }} </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 >{{__('medicines.select')}}</option>
                    @foreach($users as $row)
                    <option  @if($medicine ?? ''  && $medicine->id) @if($medicine->id == $row->id) selected @endif @endif value="{{$row->id}}">{{$row->name}}</option>
                    @endforeach
               </select>
                </div>
                 <div class="form-group col-lg-6">
                     @if($medicine ?? ''  && $medicine->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($medicine ?? ''  && $medicine->id)   @else  style="display:none" @endif  id="medicines">
                    @if($medicine ?? ''  && $medicine->id)
                    <div  class="row pricing-list-item border-item mb-4 col-12" style="display:none"  id="medicineshow" >
                    @foreach($medicines as $data=>$row)
                    <div class="row pricing-list-item border-item mb-4 col-12">
            <div class="form-group col-lg-6">
            <label>{{ __('reservations.type_pre') }} </label>
            <select name="medicine[{{$data}}][type]" class="form-control ">
            <option @if($row->type == 'old') selected @endif value="old">قديم</option>
            <option @if($row->type == 'present') selected @endif value="present">حالي</option>
            <option @if($row->type == 'new') selected @endif value="new">جديد</option>
            </select>
        </div>
        <div class="form-group col-lg-5">
            <label>{{ __('reservations.name') }} </label>
            <input type="text" class="form-control " name="medicine[{{$data}}][name]" value="{{$row->name}}" placeholder="{{__('reservations.name')}}"/>
        </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 class="form-group col-lg-6">
            <label>{{ __('reservations.count_per')}} </label>
            <input type="number" min="0" class="form-control " name="medicine[{{$data}}][count]" value="{{$row->count}}" placeholder="{{__('reservations.count_per') }}" />
        </div>
        <div class="form-group col-lg-6">
            <label>{{ __('reservations.duration')}} </label>
            <input type="text" class="form-control " name="medicine[{{$data}}][duration]" value="{{$row->duration}}" placeholder="{{__('reservations.duration')}}" />
       
           </div>
          </div>
                    @endforeach
                    </div>
                    @endif
                    
                </div>
<div class="col-lg-12">
       <a style="cursor: pointer;" @if($medicine ?? ''  && $medicine->id) data-id="{{count($medicines)}}" @else   data-id="0" @endif onclick="addmedicine(this)" class="btn_1 gray "><i class="fa fa-fw fa-plus-circle"></i>{{__("medicines.add_medicine")}}</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 addmedicine(elem){
        $("#medicines").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)
          {
            $('#medicines').append(data);
          }
        })
    }
    function showdata(elem){
        let data = $(elem).val();
        if ($('input.checkbox_check').is(':checked')) {
            $('#medicineshow').css('display','block');
        }
        else{
            
            $('#medicineshow').css('display','none');
        }
    } 
     function remove(elem){
            $(elem).closest('.row').remove();
        }
      function anantomyoption(elem){
          
          var num = $(elem).val();
         var number= $(elem).attr('data-id');
        
        
         $.ajax({
          url : urls_medicine+'/'+num,
          type : 'GET',
          data : 'nothing',
          dataType : 'json',
          success:function(data)
          {
            $('#anantomy_id'+number).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/addmedicinetypes",
            urls_medicine = "{{url('/')}}/admin/anantomyoption",
            imagePath = "{{asset('')}}";
    </script>
    <script src="{{ asset('assets/admin/js/editor.js') }}"></script>
    <script src="{{ asset('assets/admin/js/lfm.js') }}"></script>
@endsection
