@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($anatomy ?? ''  && $anatomy->id)
            @method('PUT')
        @endif
        @CSRF
         
         <div class="form-group col-lg-6">
                <label>{{ meta('user', getCurrentLocale()) ?? __('anatomies.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 >{{__('anatomies.select')}}</option>
                    @foreach($users as $row)
                    <option  @if($anatomy ?? ''  && $anatomy->id) @if($anatomy->id == $row->id) selected @endif @endif value="{{$row->id}}">{{$row->name}}</option>
                    @endforeach
               </select>
                </div>
                 <div class="form-group col-lg-6">
                     @if($anatomy ?? ''  && $anatomy->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($anatomy ?? ''  && $anatomy->id)   @else  style="display:none" @endif  id="anatomies">
                    @if($anatomy ?? ''  && $anatomy->id)
                    <div  class="row pricing-list-item border-item mb-4 col-12" style="display:none"  id="anatomieshow" >
                    @foreach($anatomies as $data=>$anatomys)
                   
                    <div class="row pricing-list-item border-item mb-4 col-12">
                         <div class="form-group col-lg-6">
               <input type="hidden" name="anatomy[{{$data}}][id]" value="{{$anatomys->id}}">
            <label>الانواع </label>
            <select class="form-control"onchange="anantomyoption(this)" data-id="{{$data}}" name="anatomy[{{$data}}][category_id]">
                @foreach($categories as $row)
                <option @if($row->id == $anatomys->category_id) selected @endif value="{{$row->id}}">{{$row->name}}</option>
                @endforeach
                </select>
        </div>
          <div class="form-group col-lg-5">
               <input type="hidden" name="anatomy[{{$data}}][id]"  value="{{$anatomys->id}}">
            <label>التحاليل </label>
            <select class="form-control" id="anantomy_id{{$data}}" name="anatomy[{{$data}}][anatomy_id]" >
                @foreach(anatomycats($anatomys->category_id) as $row)
                <option @if($row->id == $anatomys->anatomy_id) selected @endif value="{{$row->id}}">{{$row->name}}</option>
                @endforeach
                </select>
        </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.description") }}</label>
            <input type="text" class="form-control" name="anatomy[{{$data}}][description]" placeholder="{{__("reservations.description")}}" value="{{$anatomys->description}}" />
        </div>
        
        <div class="form-group col-lg-6">
            <label>{{ __("reservations.cost") }} </label>
            <input type="number" min="0" step=".01" class="form-control" name="anatomy[{{$data}}][cost]" placeholder="{{__('reservations.cost') }}" value="{{$anatomys->cost}}" />
        </div>
          <div class="form-group col-lg-6">
            <label>{{ __("reservations.result") }} </label>
            <input type="text" class="form-control" name="anatomy[{{$data}}][result]" placeholder="{{__('reservations.result') }}" value="{{$anatomys->result}}" />
        </div>
        
        <div class="form-group col-lg-12">
            <label>{{ __('reservations.image_anatomy') }} </label>
            <input  class="image_anatomy_thumbnail" type="file" name="anatomy[{{$data}}][image_anatomy]" />

          <hr>
          
          </div>
          </div>
                    @endforeach
                    </div>
                    @endif
                    
                </div>
<div class="col-lg-12">
       <a style="cursor: pointer;" @if($anatomy ?? ''  && $anatomy->id) data-id="{{count($anatomies)}}" @else   data-id="0" @endif onclick="addanatomy(this)" class="btn_1 gray "><i class="fa fa-fw fa-plus-circle"></i>{{__("anatomies.add_anatomy")}}</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 addanatomy(elem){
        $("#anatomies").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)
          {
            $('#anatomies').append(data);
          }
        })
    }
    function showdata(elem){
        let data = $(elem).val();
        if ($('input.checkbox_check').is(':checked')) {
            $('#anatomieshow').css('display','block');
        }
        else{
            
            $('#anatomieshow').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_anatomy+'/'+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/addanatomytypes",
            urls_anatomy = "{{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
