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



    <div class="border-item">
        <ul class="nav nav-pills bg-nav-pills nav-justified mb-3">
            <li class="nav-item">
                <a href="#main" data-toggle="tab" aria-expanded="false" class="nav-link rounded-0 active">
                    <i class="mdi mdi-home-variant d-lg-none d-block mr-1"></i>
                    <span class="d-none d-lg-block"><?php echo e(__('products.details')); ?></span>
                </a>
            </li>
            <li class="nav-item">
                <a href="#section_images" data-toggle="tab" aria-expanded="false" class="nav-link rounded-0">
                    <i class="mdi mdi-home-variant d-lg-none d-block mr-1"></i>
                    <span class="d-none d-lg-block"><?php echo e(__('products.images')); ?></span>
                </a>
            </li>
            <li class="nav-item">
                <a href="#section_items" data-toggle="tab" aria-expanded="false" class="nav-link rounded-0">
                    <i class="mdi mdi-home-variant d-lg-none d-block mr-1"></i>
                    <span class="d-none d-lg-block"><?php echo e(__('products.items')); ?></span>
                </a>
            </li>
            <li class="nav-item">
                <a href="#section_additions" data-toggle="tab" aria-expanded="false" class="nav-link rounded-0">
                    <i class="mdi mdi-home-variant d-lg-none d-block mr-1"></i>
                    <span class="d-none d-lg-block"><?php echo e(__('products.additions')); ?></span>
                </a>
            </li>

            <?php if(@$product): ?>
                <li class="nav-item">
                    <a href="#section_reasons" data-toggle="tab" aria-expanded="false" class="nav-link rounded-0">
                        <i class="mdi mdi-home-variant d-lg-none d-block mr-1"></i>
                        <span class="d-none d-lg-block"><?php echo e(__('products.reasons')); ?></span>
                    </a>
                </li>
            <?php endif; ?>
        </ul>
        <form class="form-row" method="post" onsubmit="saveForm(this)" action="<?php echo e($action); ?>" enctype="multipart/form-data">
            <?php if($product ?? ''  && $product->id): ?>
                <?php echo method_field('PUT'); ?>
            <?php endif; ?>
            <?php echo csrf_field(); ?>
            <div class="tab-content row col-12">
                <div class="tab-pane col-lg-12 active" id="main">
                    <div class="form-row">

                        <div class="form-group col-lg-6">
                            <label><?php echo e(__('products.category_id')); ?> </label>
                            <select onchange="categorySelect(this)" id="category_id" class="form-control <?php echo e($errors->has('category_id') ? 'is-invalid' : ''); ?>" name="category_id">
                                <option value=""><?php echo e(__('dashboard.select')); ?></option>
                                <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option <?php echo e((isset($product) ? $product->category_id : null) == $row->id ? 'selected' : ''); ?> value="<?php echo e($row->id); ?>"><?php echo e($row->title); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                        
                        <?php $__currentLoopData = $languages; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $language): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <div class="form-group col-lg-6">
                                <label><?php echo e(meta('title', $language->local) ?? __('products.title')); ?> <?php echo e(count($languages) > 1 ? "({$language->name})" : ''); ?> </label>
                                <input type="text" class="form-control <?php echo e($errors->has('title_'.$language->local) ? 'is-invalid' : ''); ?>" name="title_<?php echo e($language->local); ?>" placeholder="<?php echo e(meta('title', $language->local) ?? __('products.title')); ?>" value='<?php echo e(old("title_{$language->local}", $product[$language->local]->title ?? "")); ?>'/>
                            </div>
                            <div class="form-group col-lg-12">
                                <label><?php echo e(meta('description', $language->local) ?? __('products.description')); ?> <?php echo e(count($languages) > 1 ? "({$language->name})" : ''); ?> </label>
                                <textarea  class="form-control <?php echo e($errors->has('description_'.$language->local) ? 'is-invalid' : ''); ?>" name="description_<?php echo e($language->local); ?>" placeholder="<?php echo e(meta('description', $language->local) ?? __('products.description')); ?>"><?php echo e(old("description_{$language->local}", $product[$language->local]->description ?? "")); ?></textarea>
                            </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                        <div class="form-group col-lg-6" >
                            <label><?php echo e(__('products.cost')); ?> </label>
                            <input type="text" class="form-control <?php echo e($errors->has('cost') ? 'is-invalid' : ''); ?>" name="cost" placeholder="<?php echo e(__('products.cost')); ?>" value='<?php echo e(old("cost", $product->cost ?? "")); ?>'/>
                        </div>

                        <div class="form-group col-lg-6" >
                            <label><?php echo e(__('products.cost_discount')); ?> </label>
                            <input type="text" class="form-control <?php echo e($errors->has('cost_discount') ? 'is-invalid' : ''); ?>" name="cost_discount" placeholder="<?php echo e(__('products.cost_discount')); ?>" value='<?php echo e(old("cost_discount", $product->cost_discount ?? "")); ?>'/>
                        </div>

                        <div class="form-group col-lg-6" >
                            <label><?php echo e(__('products.count')); ?> </label>
                            <input type="text" class="form-control <?php echo e($errors->has('count') ? 'is-invalid' : ''); ?>" name="count" placeholder="<?php echo e(__('products.count')); ?>" value='<?php echo e(old("count", $product->count ?? "")); ?>'/>
                        </div>

                    </div>

                </div>
                <div class="tab-pane  col-lg-12" id="section_images">

                    <div class="col-lg-12">
                        <h3> <?php echo e(__('products.images')); ?> </h3>
                    </div>
                    <div class="row col-12">
                    <div class="form-group col-lg-6">
                        <label><?php echo e(meta('image', getCurrentLocale()) ?? __('products.image')); ?> </label>
                        <input type="file" class="form-control <?php echo e($errors->has('image') ? 'is-invalid' : ''); ?>" name="image" placeholder="<?php echo e(meta('image', getCurrentLocale()) ?? __('products.image')); ?>" value='<?php echo e(old("image", $product->image ?? "")); ?>'/>
                    </div>
                    
                    <?php if(isset($product)): ?>
                        <div class="form-group col-lg-6">
                            <a href="<?php echo e(asset($product->image)); ?>" target="_blank"><?php echo e(__('products.show')); ?></a>
                        </div>
                    <?php endif; ?>
                    </div>
                    <div class="col-lg-12">
                        <h4><?php echo e(__('products.images_add')); ?></h4>
                    </div>
                    <div class="col-lg-12" id="images">
                        <?php if(@$product): ?>
                            <?php $__currentLoopData = $product->photos; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <?php echo $__env->make('store.product.image',['image'=>$row], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <?php endif; ?>
                    </div>
                    <div class="col-lg-12">
                        <a style="cursor: pointer;" onclick="addimage(this)" class="btn_1 gray "><i class="fa fa-fw fa-plus-circle"></i><?php echo e(__("products.add_image")); ?></a>
                    </div>

                </div>
                <div class="tab-pane col-lg-12" id="section_items">
                    <div class="row">
                        <div class="col-lg-12">
                            <h3> <?php echo e(__('products.items')); ?> </h3>
                        </div>
                        <div class="col-lg-12" id="product_items">
                            <?php if(@$product): ?>
                                <?php $__currentLoopData = $items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php echo $__env->make('store.product.product_item',['item'=>$row,'key'=>$key], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            <?php endif; ?>
                        </div>
                        <div class="col-lg-12">
                            <a style="cursor: pointer;" <?php if($product ?? ''  && $product->id): ?> data-id="<?php echo e(count($items)); ?>" <?php else: ?> data-id="0" <?php endif; ?> onclick="addproductitem(this)" class="btn_1 gray "><i class="fa fa-fw fa-plus-circle"></i><?php echo e(__("products.add_new")); ?></a>
                        </div>
                    </div>
                </div>
                <div class="tab-pane col-lg-12" id="section_additions">
                    <div class="row">
                        <div class="col-lg-12">
                            <h3> <?php echo e(__('products.additions')); ?> </h3>
                        </div>
                        <div class="col-lg-12" id="additions">
                            <?php if(@$product): ?>
                                <?php $__currentLoopData = $additions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php echo $__env->make('store.product.addition',['addition'=>$row,'key'=>$key], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            <?php endif; ?>
                        </div>
                        <div class="col-lg-12">
                            <a style="cursor: pointer;" <?php if(@$additions): ?> data-id="<?php echo e(count($additions)); ?>" <?php else: ?> data-id="0" <?php endif; ?> onclick="addaddition(this)" class="btn_1 gray "><i class="fa fa-fw fa-plus-circle"></i><?php echo e(__("products.add_addition")); ?></a>
                        </div>
                    </div>
                </div>
                <?php if(@$product): ?>
                    <div class="tab-pane col-lg-12" id="section_reasons">
                        <div class="row">
                            <div class="col-lg-12">
                                <h3> <?php echo e(__('products.reasons')); ?> </h3>
                            </div>
                            <div class="col-lg-12">
                                <?php $__currentLoopData = $logs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <div class="row pricing-list-item  mb-4 "  style="background-color: rgba(21,97,203,0.1);height:auto;padding: 20px">
                                        <div class="form-group col-lg-6">
                                            <label><?php echo e(__('products.message')); ?> </label>
                                            <input type="text" class="form-control" disabled value="<?php echo e($row->message); ?>"/>
                                        </div>
                                        <div class="form-group col-lg-6">
                                            <label><?php echo e(__('products.reason_id')); ?> </label>
                                            <input type="text" class="form-control" disabled value="<?php echo e($row->reason->currentDescription->title); ?>"/>
                                        </div>
                                        <div class="form-group col-lg-6">
                                            <label><?php echo e(__('products.created_at')); ?> </label>
                                            <input type="text" class="form-control" disabled value="<?php echo e(date('Y-m-d g:i a',strtotime($row->created_at))); ?>"/>
                                        </div>
                                    </div>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </div>
                        </div>
                    </div>
                <?php endif; ?>
            </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'); ?>
    <!-- Editor JS orders -->
    
    <script src="<?php echo e(asset('/assets/admin/js/lib/tinymce.min.js')); ?>"></script>

    <script>
        function DeleteImg(elem)
        {
            $(elem).closest('.col-md-4').remove();
        }
    </script>
    <script>
        function categorySelect(elem)
        {
            let category_id = $(elem).val()
            $.ajax({
                url : url_model,
                type : 'GET',
                data : 'category_id='+category_id,
                success:function(data)
                {
                    $('#sub_category_id').html(data);
                }
            })
        }
        function addproductitem(elem)
        {
            var num = $(elem).attr('data-id');
            var newrow = parseInt(num)+1;
            $(elem).attr('data-id', newrow);

            $.ajax({
                url : url_product_item,
                type : 'GET',
                data : 'key='+num,
                success:function(data)
                {
                    $('#product_items').append(data);
                }
            })
        }
        function addaddition(elem)
        {
            var num = $(elem).attr('data-id');
            var newrow = parseInt(num)+1;
            $(elem).attr('data-id', newrow);

            $.ajax({
                url : url_addition,
                type : 'GET',
                data : 'key='+num,
                success:function(data)
                {
                    $('#additions').append(data);
                }
            })
        }

        function additem(elem)
        {
            var num = $(elem).attr('data-id');
            var key = $(elem).attr('key-id');
            var newrow = parseInt(num)+1;
            $(elem).attr('data-id', newrow);

            $.ajax({
                url : url_item,
                type : 'GET',
                data : 'keyItem='+num+"&key="+key,
                success:function(data)
                {
                    $('#items'+key).append(data);
                }
            })
        }

        function addimage(elem)
        {
            $.ajax({
                url : url_image,
                type : 'GET',
                data : '',
                success:function(data)
                {
                    $('#images').append(data);
                }
            })
        }

        function remove(elem)
        {
            $(elem).closest('.row').remove();
        }
    </script>
    <script>
        let route_prefix = "<?php echo e(url(config('lfm.prefix'))); ?>",
            url = "<?php echo e(url('/')); ?>/",
            url_addition = "<?php echo e(route('store.addition')); ?>",
            url_product_item = "<?php echo e(route('store.product.item')); ?>",
            url_item = "<?php echo e(route('store.item')); ?>",
            url_model = "<?php echo e(route('store.model')); ?>",
            url_image = "<?php echo e(route('store.image')); ?>",
            currentLanguage = "<?php echo e(getCurrentLocale()); ?>",
            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('store.layouts.container', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/omaralyomhost/public_html/made/resources/views/store/product/form.blade.php ENDPATH**/ ?>