@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($codephyscal ?? ''  && $codephyscal->id)
            @method('PUT')
        @endif
        @CSRF
         
         <div class="form-group col-lg-6">
                <label>{{ meta('systemphyscals', getCurrentLocale()) ?? __('codes.systemphyscals') }} </label>
               <select class="selectpicker form-control {{ $errors->has('system_food_id') ? 'is-invalid' : '' }}"  data-show-subtext="true" data-live-search="true"  name="system_physcal_id">
                   <option selected disabled >{{__('codes.select')}}</option>
                    @foreach($systemphysics as $row)
                    <option  @if($codephyscal ?? ''  && $codephyscal->id) @if($codephyscal->system_physcal_id == $row->id) selected @endif @endif value="{{$row->id}}">{{$row->name}}</option>
                    @endforeach
               </select>
                </div>
                 <div class="form-group col-lg-6"></div>
                 
        <div class="form-group col-lg-6">
            <label>{{ meta('name', getCurrentLocale()) ?? __('codes.name') }} </label>
            <input type="text" class="form-control {{ $errors->has('name') ? 'is-invalid' : '' }}" name="name" placeholder="{{ meta('name', getCurrentLocale()) ??__('codes.name') }}" value='{{ old("name", $codephyscal->name ?? "") }}'/>
        </div>
<div class="form-group col-lg-6"></div>
        

       
       
                
                <div class="row pricing-list-item border-item mb-4 col-12" @if($codephyscal ?? ''  && $codephyscalphyscal->id) @else  style="display:none" @endif id="physcals">
                    @if($codephyscal ?? ''  && $codephyscal->id)
                    @foreach($physcals as $data=>$physcal)
                    <div class="row pricing-list-item border-item mb-4 col-12">
          <div class="form-group col-lg-6">
            <label>التمرين </label>
            <select class="form-control" name="physcal[{{$data}}][physcal_id]" >
                @foreach($physcaling as $row)
                <option @if($row->id == $physcal->physcal_id) selected @endif value="{{$row->id}}">{{$row->name}}</option>
                @endforeach
                </select>
        </div>

         <div class="form-group col-lg-5">
            <label>العدد </label>
            <input type="number" min="0" class="form-control" placeholder="العدد" value="{{ $row->count }}" />
            </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>
                    @endforeach
                    @endif
                </div>
<div class="col-lg-12">
       <a style="cursor: pointer;" @if($codephyscal ?? ''  && $codephyscal->id) data-id="{{count($physcals)}}" @else   data-id="0" @endif onclick="addphyscal(this)" class="btn_1 gray "><i class="fa fa-fw fa-plus-circle"></i>{{__("codes.add_physcal")}}</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 addphyscal(elem){
        $("#physcals").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)
          {
            $('#physcals').append(data);
          }
        })
    }
     function remove(elem){
            $(elem).closest('.row').remove();
        }
</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/addphyscaltype",
            imagePath = "{{asset('')}}";
    </script>
    <script src="{{ asset('assets/admin/js/editor.js') }}"></script>
    <script src="{{ asset('assets/admin/js/lfm.js') }}"></script>
@endsection
