<?php
    $actv = \App\Models\Settings::find(1) ;
?>
<div>
    <div class="request_titlenav">
        <div class="row request align-items-center" style="height: 39px;">
            <div class="col-md-12">
                <span class="ubication"><strong>Inicio</strong> | Producto</span>
            </div>
        </div>
    </div>
    <?php if(Auth::check()): ?>        
        <div>
            <br>
            <div class="row justify-content-center">
                <div class="form-group col-md-3">
                    <input type="text" placeholder="Buscar" class="form-control" wire:model="search"">
                </div>
                <?php if(auth()->user()->rol_user=='admin'): ?>
                    <button class="btn btn-outline-primary col-md-1" wire:click="$toggle('imputActive')"><i class="fa fa-plus"></i>Agregar</button>
                <?php endif; ?>
            </div><br><br>
            <?php if($imputActive or $updateMode): ?>
                <div class="row justify-content-center">
                    <div class="col-md-3">
                        <label>Nombre de Producto</label>
                        <input type="text" placeholder="Nombre de Producto" class="form-control" wire:model.defer="name" style="margin-right:5px;">
                        <input type="hidden" wire:model.defer="product_id">
                    </div>
                    <div class="col-md-3">
                        <label>Precio de Producto</label>
                        <input type="text" placeholder="Precio de Producto" class="form-control" wire:model.defer="price" style="margin-right:5px;">
                    </div>
                </div>
                <div class="row justify-content-center">
                    <div class="col-md-6">
                        <label>Descripcion</label>
                        <textarea placeholder="Descripcion" class="form-control" wire:model.defer="description">
                        </textarea>
                    </div>
                </div>
                <div class="row justify-content-center">
                    <div class="col-md-4">
                        <div class="form-group">
                            <label>Cargar imagen de Producto</label>
                            <select required oninput="setCustomValidity('')" oninvalid="this.setCustomValidity('Requerido')" class="form-control" id="opcion" name="opcion" onchange="seleccionado()"tabindex="1">
                                <option value="no">Sin Imagen</option>
                                <option value="img">Imagen desde mi Equipo</option>
                                <option value="url">Url</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group col-md-4" id="img" style="display:none;">
                        <label for="" class="form-label">Logo</label>
                        <input id="logo" name="logo" type="file" value="<?php echo e(old('img_product')); ?>" class="form-control" tabindex="1">        
                    </div>
                    <div class="form-group col-md-4" id="url" style="display:none;">
                        <label for="" class="form-label">Logo Url</label>
                        <input id="logo" name="logo" type="text" value="<?php echo e(old('url')); ?>" class="form-control" tabindex="1">
                    </div>
                </div>
                <br>
                <div class="row justify-content-center">  
                    <button type="button" class="btn btn-success col-md-1" wire:click="save"><i class="fa fa-save"></i>Guardar</button>
                    <button type="button" class="btn btn-danger col-md-1" wire:click="resetInput"> <i class="fa fa-trash"></i>Cancelar</button>
                </div>
            <?php endif; ?>
            <?php if(session()->has('message')): ?>
                <div class="alert" id="alert">
                    <div class="alert alert-success" style="width: 23%; margin-left:77%">
                        <?php echo e(session()->get('message')); ?>

                    </div>
                </div>
            <?php endif; ?>
            <div class="row justify-content-center">
                <div class="col-md-10">
                    <table class="table table-striped">
                        <thead style="background:#C1282D;color:#FFFFFF;text-align:center;">
                            <tr>
                                <th scope="col"></th>
                                <th scope="col">Producto</th>
                                <th scope="col">Descripcion </th>
                                <th scope="col">Precio </th>
                                <th scope="col">Cantidad </th>
                                <th scope="col">opciones</th>
                            </tr>
                        </thead>
                        <tbody style="text-align:center;">
                        <?php $__currentLoopData = $data; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $producto): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td></td>
                                <td>
                                    <span class="td__title"><?php echo e($producto->skufield); ?></span>
                                </td>
                                <td class="align-middle">
                                    <span class="align-middle"><?php echo e($producto->name); ?></span>
                                </td>
                                <td class="align-middle">
                                    <span class="align-middle"><?php echo e($producto->price); ?></span>
                                </td>
                                <td class="align-middle">
                                    <input type="number" class="form-control" placeholder="0" min="1"  name='order_quantity' oninput="validity.valid||(value='');" wire:model.defer="order_quantity" id='order_quantity'>
                                </td>
                                <td>
                                    <?php if(auth()->user()->rol_user==''): ?>
                                        <div><br>
                                            <a wire:click="addToCart(<?php echo e($producto->id); ?>)"> <i class="fas fa-shopping-cart" style="color:#4b2bfb"></i></a>
                                            <a wire:click="addFavorites(<?php echo e($producto->id); ?>)"> <i class="fas fa-heart" style="color:#006400"></i> </a>

                                        </div>
                                    <?php endif; ?>
                                    <?php if(auth()->user()->rol_user=='admin'): ?>
                                        <div><br>
                                            <a wire:click="edit(<?php echo e($producto->id); ?>)"><i class="fa fa-pen" style="color:#006400"></i></a>
                                            <a wire:click="destroy(<?php echo e($producto->id); ?>)"><i class="fa fa-trash" style="color:#C11D1D"></i></a>
                                            <?php if($actv->activacion == ''): ?>
                                                <a wire:click="addToCart(<?php echo e($producto->id); ?>)"> <i class="fas fa-shopping-cart" style="color:#4b2bfb"></i></a>
                                            <?php endif; ?>    
                                            <a wire:click="addFavorites(<?php echo e($producto->id); ?>)"><i class="fas fa-heart" style="color:#C11D1D" ></i></a>
                                        </div>
                                    <?php endif; ?>
                                </td>
                            </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    <?php endif; ?>
    <?php if(auth()->guard()->guest()): ?>
    <div class="container">
        <div class="row">
            <div class="products__card">
                <?php $__empty_1 = true; $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <?php $name = '/img/'.$category->name.'.png'; ?>
                <div class="filtros"> 
                    <a wire:click="flt_<?php echo e(strtolower($category->name)); ?>">
                        <div class="card" style="width: 18rem;">
                            <img src="<?php echo e(asset($name)); ?>">
                            <div class="card-body">
                                <p class="card_title"><?php echo e($category->name); ?></p>
                            </div>
                        </div>
                    </a>
                </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <div class="filtros"> 
                    <a wire:click="flt_filtro">
                        <div class="card" style="width: 18rem;">
                            <img src="<?php echo e(asset('/img/filtros.png')); ?>">
                            <div class="card-body">
                                <p class="card_title">FILTROS</p>
                            </div>
                        </div>
                    </a>
                </div>
                <div class="filtros"> 
                    <a wire:click="flt_mallas">
                        <div class="card" style="width: 18rem;">
                            <img src="<?php echo e(asset('/img/mallas.png')); ?>">
                            <div class="card-body">
                                <p class="card_title">MALLAS</p>
                            </div>
                        </div>
                    </a>
                </div>
                <div class="filtros">
                    <a wire:click="flt_zarandas">
                        <div class="card" style="width: 18rem;">
                            <img src="<?php echo e(asset('/img/zarandas.png')); ?>" class="card-img-top" alt="...">
                            <div class="card-body">
                                <p class="card_title">ZARANDAS</p>
                            </div>
                        </div>
                    </a>
                </div>
                <div class="filtros">
                    <a wire:click="flt_tamices">
                        <div class="card" style="width: 18rem;">
                            <img src="<?php echo e(asset('/img/tamices.png')); ?>" class="card-img-top" alt="...">
                            <div class="card-body">
                                <p class="card_title">TAMICES</p>
                            </div>
                        </div>
                    </a>
                </div>
                <?php endif; ?>
                
            </div>
        </div>
        <div class="row justify-content-center">
            <div class="form-group col-md-3">
                <input type="text" placeholder="Buscar" class="form-control" wire:model="search"">
            </div>
        </div><br>
        <div class="row justify-content-center">
            <div class="col-md-10">
                <table class="table table-striped">
                    <thead style="background:#C1282D;color:#FFFFFF;text-align:center;">
                        <tr>
                            <th scope="col"></th>
                            <th scope="col">Producto</th>
                            <th scope="col">Descripcion</th>
                            <th scope="col"></th>
                        </tr>
                    </thead>
                    <tbody style="text-align:center;">
                       <?php $__currentLoopData = $data; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $producto): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr>
                            <td></td>
                            <td>
                                <span class="td__title"><?php echo e($producto->skufield); ?></span>
                            </td>
                            <td class="align-middle">
                                <img class="shp" src="<?php echo e(asset('/img/mallas.png')); ?>"><br>
                                <span class="align-middle"><?php echo e($producto->name); ?></span>
                            </td>
                            <td class="align-middle">
                                <span class="align-middle"><img src="<?php echo e($producto->logo); ?>"></span>
                            </td>
                        </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <?php endif; ?>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

<script type="text/javascript">
    $(document).ready(function() {        
        setTimeout(function() {
          $("#alerts").hide(6000);
          }, 3000);
        });
</script>


<script>
    function seleccionado(){
        var opt = $('#opcion').val();
        
        // alert(opt);
        if(opt=="img"){
            $('#img').show();
            $('#url').hide();
            
        }else{
            if(opt=="url"){
                $('#img').hide();
                $('#url').show();
                
            }else{
                $('#img').hide();
                $('#url').hide();
                
            }
        }
    }
</script>
<script>
    $(document).on('change','input[type="file"]',function(){
        // this.files[0].size recupera el tamaño del archivo
        // alert(this.files[0].size);
        
        var fileName = this.files[0].name;
        var fileSize = this.files[0].size;

        if(fileSize > 2000000){
            alert('El archivo no debe superar los 2MB');
            this.value = '';
            this.files[0].name = '';
        }else{
            // recuperamos la extensión del archivo
            var ext = fileName.split('.').pop();
            
            // Convertimos en minúscula porque 
            // la extensión del archivo puede estar en mayúscula
            ext = ext.toLowerCase();
        
            // console.log(ext);
            switch (ext) {
                case 'jpg':
                case 'jpeg':
                case 'png':
                case 'pdf': break;
                default:
                    alert('El archivo no tiene la extensión adecuada');
                    this.value = ''; // reset del valor
                    this.files[0].name = '';
            }
        }
    });
</script>
<?php /**PATH /home/d8osolecom/public_html/sueiro/resources/views/livewire/products.blade.php ENDPATH**/ ?>