 <?php
    session_start();
    include('../conexion.php');
    include('../include/sesiones.php'); ?>
 <?php
    $can4 = mysqli_query($con, "SELECT * FROM cotizacion_detalle_deseo WHERE clie_id='" . $_SESSION["clie_id"] . "' ") or die(mysqli_error($con));
    $dat1oee = mysqli_fetch_array($can4);
    $clie_id = ($dat1oee['clie_id'] ?? '');
    if (empty($clie_id)) {
    ?> <br><br> <br> <br> <br>
     <div class="section_title">
         <center>
             <h2>Tu Lista de deseos esta vacia</h2>
         </center>
     </div> <br> <br> <br> <br>
 <?php } else if (isset($clie_id)) { ?>
     <div class="row no-gutters shop_wrapper">
         <?php
            $can4 = mysqli_query($con, "SELECT * FROM cotizacion_detalle_deseo WHERE clie_id='" . $_SESSION["clie_id"] . "' ") or die(mysqli_error($con));
            while ($datoee = mysqli_fetch_array($can4)) {
                $cotd_art_id = ($datoee['cotd_art_id']);

                $can3 = mysqli_query($con, "SELECT * FROM articulos WHERE art_id='$cotd_art_id' ") or die(mysqli_error($con));
                while ($load1 = mysqli_fetch_array($can3)) {
                    $art_atributo_estado = ($load1['art_atributo_estado']);
                    $nombre_archivo = '../../img/articulos/' . $load1['art_id'] . '.jpg'; ?>
                 <div class="col-lg-3">
                     <div class="tab-content">
                         <div class="single_product">
                             <div class="product_thumb">
                                 <?php if (file_exists($nombre_archivo)) { ?>
                                     <a><img src="<?php echo $emp_url_sub; ?>/img/articulos/<?php echo $load1['art_id']; ?>.jpg" style="height:270px;">
                                     <?php } else { ?>
                                         <img src="<?php echo $emp_url_sub; ?>/img/articulos/sin_imagen.jpg" alt="#" style="height:270px;">
                                     <?php } ?></a>
                             </div>
                             <div class="product_content grid_content">
                                 <div class="product_name">
                                     <h3><a href="articulos_detalles.php?art_id=<?php echo $load1['art_id']; ?>"><?php echo substr($load1['art_nombre_online'], 0, 65); ?></a>
                                     </h3>
                                 </div>
                                 <div class="price_box">

                                     <?php
                                        $art_promo_desc = $load1['art_promo_desc'];

                                        if ($art_promo_desc > 0) {
                                            if (isset($_SESSION['clie_id'])) {
                                                $casa1 = mysqli_query($con, "SELECT * FROM precio WHERE tarifas_tar_id='$tarifas_tar_id' and articulos_art_id='" . $load1["art_id"] . "' ") or die(mysqli_error($con));
                                                $load2 = mysqli_fetch_array($casa1) ?>


                                             <span class="current_price" style="color: gray; font-size: 1em; text-decoration: line-through;">
                                                 $<?php echo number_format($load2['pre_precio'], 0, ",", "."); ?>
                                             </span>
                                             </br>

                                             <?php
                                                    $casa3 = mysqli_query($con, "SELECT * FROM precio WHERE tarifas_tar_id='$tarifas_tar_id' and articulos_art_id='" . $load1["art_id"] . "' ") or die(mysqli_error($con));
                                                    $load4 = mysqli_fetch_array($casa3);

                                                    $pre_precio = $load4['pre_precio'];
                                                    $desc_promo = $art_promo_desc / 100;
                                                    $desc_art = $desc_promo * $pre_precio;
                                                    $total_desc = $pre_precio - $desc_art;

                                                ?>
                                                 <span class="current_price">$<?php echo number_format($total_desc, 0, ",", "."); ?></span>
                                                 <label style="color: red;  width: 40px; height: auto; font-size: 15px ; align-items: center; justify-content: center; text-align: center;">
                                                     -<?php echo number_format($art_promo_desc); ?>%
                                                 </label>
                                             <?php
                                                
                                            } else {
                                                $casa2 = mysqli_query($con, "SELECT * FROM precio WHERE tarifas_tar_id='$tar_destacada' and articulos_art_id='" . $load1["art_id"] . "' ") or die(mysqli_error($con));
                                                $load3 = mysqli_fetch_array($casa2)
                                                ?>
                                             <span class="current_price" style="color: gray; font-size: 1em; text-decoration: line-through;">$<?php echo number_format($load3['pre_precio'], 0, ",", "."); ?></span>
                                             </br>

                                             <?php
                                               
                                                    $casa3 = mysqli_query($con, "SELECT * FROM precio WHERE tarifas_tar_id='$tar_destacada' and articulos_art_id='" . $load1["art_id_art"] . "' ") or die(mysqli_error($con));
                                                    $load4 = mysqli_fetch_array($casa3);

                                                    $pre_precio = $load4['pre_precio'];

                                                    $desc_promo = $art_promo_desc / 100;
                                                    $desc_art = $desc_promo * $pre_precio;
                                                    $total_desc = $pre_precio - $desc_art;
                                                ?>
                                                 <span class="current_price">$<?php echo number_format($total_desc, 0, ",", "."); ?></span>
                                                 <label style="color: red;  width: 40px; height: auto; font-size: 15px ; align-items: center; justify-content: center; text-align: center;">
                                                     -<?php echo number_format($art_promo_desc); ?>%
                                                 </label>
                                             <?php
                                               
                                            }
                                        } else {
                                            if (isset($_SESSION['clie_id'])) {
                                                $casa1 = mysqli_query($con, "SELECT * FROM precio WHERE tarifas_tar_id='$tarifas_tar_id' AND articulos_art_id='" . $load1["art_id"] . "' ")
                                                    or die(mysqli_error($con));
                                                $load2 = mysqli_fetch_array($casa1);

                                                if ($load2 && $load2['pre_precio'] > 0) {
                                                ?>
                                                <label style="margin-right: 500px;"></label>
                                                 <span class="current_price">
                                                     $<?php echo number_format($load2['pre_precio'], 0, ",", "."); ?>
                                                 </span>
                                             <?php
                                                }
                                            }   /*else {
                                                $casa2 = mysqli_query($con, "SELECT * FROM precio WHERE tarifas_tar_id='$tar_destacada' AND articulos_art_id='" . $load1["art_id"] . "' ")
                                                    or die(mysqli_error($con));
                                                $load3 = mysqli_fetch_array($casa2);

                                                if ($load3 && $load3['pre_precio'] > 0) {
                                                ?>
                                                <label style="margin-right: 500px;"></label>
                                                 <span class="current_price">
                                                     $<?php echo number_format($load3['pre_precio'], 0, ",", "."); ?>
                                                 </span>
                                     <?php
                                                }
                                            }*/
                                        }
                                        ?>



                                 </div>
                                 <div class="action_links">
                                     <ul>
                                         <li class="wishlist" onclick="eliminar_deseo($('#art_id<?php echo $load1['art_id']; ?>').val());"><a class="active" title="Agregar a deseos"><i class="fa fa-heart-o" aria-hidden="true"></i></a></li>
                                         <?php
                                            if ($art_atributo_estado == 'si') { ?>
                                             <li class="add_to_cart"><a data-id="<?php echo $load1['art_id']; ?>" class="btn_agregar"><i class="zmdi zmdi-shopping-cart-plus"></i> Agregar al Carrito</a></li>
                                         <?php  } else if ($art_atributo_estado == 'no') { ?>
                                             <li class="add_to_cart" onclick="envia_carrito1($('#art_id<?php echo $load1['art_id']; ?>').val(),$('#cantidad<?php
                                                                                                                                                            echo $load1['art_id']; ?>').val());loadDeseos();"><a><i class="zmdi zmdi-shopping-cart-plus"></i> Agregar al Carrito</a></li>
                                         <?php } ?>
                                         <input name="art_id" type="hidden" id="art_id<?php echo $load1["art_id"]; ?>" value="<?php echo $load1["art_id"]; ?>" />
                                         <input name="cantidad" type="hidden" id="cantidad<?php echo $load1["art_id"]; ?>" value="1" class="pl-2" />
                                         </li>
                                     </ul>
                                 </div>
                             </div>
                         </div>
                     </div>
                 </div><?php
                    }
                }
                        ?>
     </div>

     <div class="modal fade" id="modal_box" tabindex="-1" role="dialog" aria-hidden="true">
         <div class="modal-dialog modal-dialog-centered" role="document">
             <div class="modal-content">
                 <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
                     <span aria-hidden="true">&times;</span>
                 </button>
                 <div class="modal_body">
                     <div id="modal_detalle"></div>
                 </div>
             </div>
         </div>
     </div>


     <script type="text/javascript">
         $(".btn_agregar").click(function() {
             id = $(this).data("id");
             $.get("./php_tienda/modal_detalles.php", "id=" + id, function(data) {
                 $("#modal_detalle").html(data);
             });
             $('#modal_box').modal('show');
         });
     </script>
 <?php } ?>