<?php $__env->startSection('content'); ?>
<div class="side-title">
    <h3><?php echo e($head ?? ''); ?></h3>
</div>

<div class="border-item">
    <form class="form-row" method="post" action="<?php echo e($action); ?>">
        <?php if($userfood ?? ''  && $userfood->id): ?>
            <?php echo method_field('PUT'); ?>
        <?php endif; ?>
        <?php echo csrf_field(); ?>

             <div class="form-group col-lg-6">
            <label><?php echo e(meta('patient', getCurrentLocale()) ?? __('ketos.patient')); ?> </label>
           <select class="selectpicker form-control <?php echo e($errors->has('user_id') ? 'is-invalid' : ''); ?>" data-show-subtext="true" data-live-search="true"  name="user_id">
               <option selected disabled><?php echo e(__('ketos.select')); ?></option>
               <?php $__currentLoopData = $patients; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
               <option <?php if($userfood ?? ''  && $userfood->id): ?> <?php if($row->id == $userfood->id): ?> selected <?php endif; ?> <?php endif; ?> value="<?php echo e($row->id); ?>"><?php echo e($row->name); ?></option>
               <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
           </select>
            </div>
              <div class="form-group col-lg-6">
                     <?php if($userfood ?? ''  && $userfood->id): ?>
                     <input type="checkbox" class="checkbox_check" onclick="showdata(this)" style="
    margin-top: 3pc;
    margin-right: 4pc;
">عرض واخفاء 
                     <?php endif; ?>
                 </div>
                 
                 
                  <div class="row pricing-list-item border-item mb-4 col-12" <?php if($userfood ?? ''  && $userfood->id): ?>   <?php else: ?>  style="display:none" <?php endif; ?>  id="foods">
                    <?php if($userfood ?? ''  && $userfood->id): ?>
                    <div  class="row pricing-list-item border-item mb-4 col-12" style="display:none"  id="ketoshow" >
                    <?php $__currentLoopData = $userfoods; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data=>$row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                   
                     <div class="row pricing-list-item border-item mb-4 col-12">
                      
        
 <div class="form-group col-lg-6">
            <label><?php echo e(meta('system_food_id', getCurrentLocale()) ?? __('reservations.system_food_id')); ?> </label>
          <select onchange="foodcodes(this)" class="form-control <?php echo e($errors->has('system_food_id') ? 'is-invalid' : ''); ?>" data-id="<?php echo e($data); ?>" name="food[<?php echo e($data); ?>][system_food_id]" id="system_food">
              <option selected  value=""><?php echo e(__('reservations.select')); ?></option>
                    <?php $__currentLoopData = $systemfoods; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $rows): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option  <?php if($rows->id == $row->system_food_id): ?> selected  <?php endif; ?>  value="<?php echo e($rows->id); ?>"><?php echo e($rows->name); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
           </div>
        <div class="form-group col-lg-5" >
             <label><?php echo e(__('reservations.dating')); ?> </label>
             <input type="date" class="form-control" name="food[<?php echo e($data); ?>][dating]" value="<?php echo e($row->dating); ?>">
        </div>
        <div class="form-group col-lg-1" style="font-size: 30px;margin-top:30px;" onclick="remove(this)"><i class="fas fa-times-circle"></i></div>
   
      
       <div class="form-group col-lg-6" id="categories<?php echo e($data); ?>">
            <label>التصنيفات</label>
            <select onchange="foodcals(this)" class="form-control " data-id="<?php echo e($data); ?>"  name="food[<?php echo e($data); ?>][category_id]" id="system_food">
               
              <option selected  value=""><?php echo e(__('reservations.select')); ?></option>
                    <?php $__currentLoopData = categoriesfood($row->system_food_id); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $rows): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option <?php if($rows->id == $row->category_id): ?> selected  <?php endif; ?> value="<?php echo e($rows->id); ?>"><?php echo e($rows->name); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
       </div>
       <div class="form-group col-lg-6" id="calories<?php echo e($data); ?>">
            <label>السعرات</label>
          <select onchange="foodcoding(this)" class="form-control " data-id="<?php echo e($data); ?>" name="food[<?php echo e($data); ?>][calorie_id]" id="system_food">   
              <option selected  value=""><?php echo e(__('reservations.select')); ?></option>
                    <?php $__currentLoopData = caloriesfood($row->category_id); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $rows): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option <?php if($rows->id == $row->calorie_id): ?> selected  <?php endif; ?> value="<?php echo e($rows->id); ?>"><?php echo e($rows->name); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
       </div>
       
       <div class="form-group col-lg-12" id="codes<?php echo e($data); ?>">
           <label>الاكواد</label>
          <select onchange="fooddesc(this)" class="form-control" data-id="<?php echo e($data); ?>" name="food[<?php echo e($data); ?>][code_id]" id="system_food">
                  <option selected  value=""><?php echo e(__('reservations.select')); ?></option>
                    <?php $__currentLoopData = codesfood($row->calorie_id); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $rows): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option <?php if($rows->id == $row->code_id): ?> selected  <?php endif; ?> value="<?php echo e($rows->id); ?>"><?php echo e($rows->name); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
       </div>
        <div class="form-group col-lg-12" id="desc<?php echo e($data); ?>">
            <label>الوجبة </label>
                <textarea name="food[<?php echo e($data); ?>][description]" class="form-control my-editor"><?php echo e(reservationmeal($row->id)); ?></textarea>
       </div>
       
       
       </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </div>
                    <?php endif; ?>
                    
                </div>
<div class="col-lg-12">
       <a style="cursor: pointer;" <?php if($userfood ?? ''  && $userfood->id): ?> data-id="<?php echo e(count($userfoods)); ?>" <?php else: ?>   data-id="0" <?php endif; ?> onclick="addfood(this)" class="btn_1 gray "><i class="fa fa-fw fa-plus-circle"></i><?php echo e(__("ketos.add_keto")); ?></a>
                   
</div>





           

        <div class="text-center mt-5 col-12">
            <button class="butn"><span><?php echo e(__('dashboard.save')); ?></span></button>
        </div>
    </form>
</div>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('inner_js'); ?>
 <script src="<?php echo e(asset('/assets/admin/js/lib/tinymce.min.js')); ?>"></script>
  
<script>
    function addfood(elem){
        $("#foods").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',
          success:function(data)
          {
            $('#foods').append(data);
          }
        })
    }
    
    function foodcodes(elem){
        var num = $(elem).val();
        var dir = $(elem).attr('data-id');
        
         $.ajax({
          url : urlfoodcode +dir+','+num,
          type : 'GET',
          data : 'nothing',
          dataType : 'json',
          success:function(data)
          {
              
              $('#categories'+dir).html(data);
              
          }
        })
    }
    
    function foodcals(elem){
        var num = $(elem).val();
        var dir = $(elem).attr('data-id');
        
        
         $.ajax({
          url : urlfoodcal +dir+','+num,
          type : 'GET',
          data : 'nothing',
          dataType : 'json',
          success:function(data)
          {
                $('#calories'+dir).html(data);
          }
        })
    }
    function foodcoding(elem){
         var num = $(elem).val();
         var dir = $(elem).attr('data-id');
        
        
         $.ajax({
          url : urlfoodcoding +dir+','+num,
          type : 'GET',
          data : 'nothing',
          dataType : 'json',
          success:function(data)
          {
               $('#codes'+dir).html(data);
          }
        })
    }
    
     function fooddesc(elem){
         var num = $(elem).val();
         var dir = $(elem).attr('data-id');
         
         $.ajax({
          url : urlfooddesc +num,
          type : 'GET',
          data : 'nothing',
          dataType : 'json',
          success:function(data)
          {
               $('#desc'+dir).html(`
         
       
          <label>الوجبة </label>
                <textarea name="food[`+dir+`][description]" class="appended_text_area">`+data+`</textarea>
               
            `);
            tinymce.init({
                selector: '.appended_text_area',
                init_instance_callback: function (editor) {
                    editor.on('click', function (e) {
                        console.log('Element clicked:', e.target.nodeName);
                    });
                }
            });
              
          }
        })
    
     }
    
    
    function showdata(elem){
        let data = $(elem).val();
        if ($('input.checkbox_check').is(':checked')) {
            $('#ketoshow').css('display','block');
        }
        else{
            
            $('#ketoshow').css('display','none');
        }
    } 
     function remove(elem){
            $(elem).closest('.row').remove();
        }
        </script>
    <!-- Editor JS files -->
    <script>
        let route_prefix = "<?php echo e(url(config('lfm.prefix'))); ?>",
            url = "<?php echo e(url('/')); ?>/",
            urls = "<?php echo e(url('/')); ?>/admin/adduserfood",
            urlfoodcode = "<?php echo e(url('admin/foodcodedata')); ?>/",
            urlfoodcal = "<?php echo e(url('admin/foodcaloriesdata')); ?>/",
            urlfoodcoding = "<?php echo e(url('admin/foodcodingdata')); ?>/",
            urlfooddesc = "<?php echo e(url('admin/fooddescdata')); ?>/",
            url_question = "<?php echo e(url('/')); ?>/admin/questiondata",
            imagePath = "<?php echo e(asset('')); ?>";
    </script>
    <script src="<?php echo e(asset('assets/admin/js/editor.js')); ?>"></script>
    <script src="<?php echo e(asset('assets/admin/js/lfm.js')); ?>"></script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layouts.container', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/omaralyomhost/public_html/green_apple/resources/views/admin/userfoods/form.blade.php ENDPATH**/ ?>