<?php
include 'validar.php';
include("conexion.php");


if (isset($_POST['anadealcarrito'])){

    if(isset($_SESSION['cart'])){
        
        $session_array_id = array_column($_SESSION['cart'], "id");

        if(!in_array($_GET['id'], $session_array_id)){
           
            $session_array = array(
                'id' => $_GET['id'],
                "imagen"=> $_POST['imagen'],
                "nombre"=> $_POST['nombre'],
                "precio"=> $_POST['precio'],
                "quantity" => $_POST['quantity'],
            );
            $_SESSION['cart'][]=$session_array;
            
        }

    }else{

        $session_array= array(
            'id' => $_GET['id'],
            "imagen"=> $_POST['imagen'],
            "nombre"=> $_POST['nombre'],
            "precio"=> $_POST['precio'],
            "quantity" => $_POST['quantity'],
        );
        $_SESSION['cart'][]=$session_array;
    }

}

// division

$consulta = $conectado->prepare("SELECT * FROM productos");
$consulta->execute();
$datos = $consulta->get_result();

if (isset($_GET["id"])) {
    // Obtener el valor del parámetro "id"
    $id_obtenido = $_GET["id"];
    $query2 = "DELETE FROM productos WHERE id=$id_obtenido";
    $eliminar = $conectado->prepare($query2);
    $eliminar->execute();
    header("location: carrito2.php");
}


?>



<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
    <style>
        table {
        margin-left:270px;
        width: 60%;
        border-collapse: collapse;
        margin-bottom: 20px;
        background-color: #fff;
        border-radius: 8px;
        overflow: hidden;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    }
    th, td {
        padding: 12px;
        text-align: left;
        border-bottom: 1px solid #ddd;
    }
    th {
        background-color: #4CAF50;
        color: white;
    }
    tr:nth-child(even) {
        background-color: #f2f2f2;
    }
    tr:hover {
        background-color: #ddd;
    }
    table a {
        border: 1px solid;
        border-radius : 10px;
        padding: 15px;
        text-decoration: none;
        color: #4CAF50;
    }

    .chat-icon {
    position: fixed;
    bottom: 20px; /* Distancia desde la parte inferior */
    right: 20px; /* Distancia desde el lado derecho */
    background-color: #3056C4;
    color: #ffffff;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    transition: transform 0.3s ease;
}

.chat-icon:hover {
    transform: scale(1.1); /* Efecto de escala al pasar el mouse */
}


        
    </style>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
    <link rel='stylesheet' href='https://cdn-uicons.flaticon.com/uicons-regular-rounded/css/uicons-regular-rounded.css'>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
    <link rel="stylesheet" type="text/css" href="Estilos/index.css">
    <link rel="stylesheet" href="Estilos/shop.css">
    <script src="https://unpkg.com/feather-icons"></script>
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" 
    integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
    <script src="Javas/shop.js"></script>
    <script src="Javas/menu.js"></script>
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" 
    integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/uikit@3.18.3/dist/js/uikit.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/uikit@3.18.3/dist/js/uikit-icons.min.js"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/uikit@3.18.3/dist/css/uikit.min.css" />

</head>
<body>
    <?php include("menu2.php") ?>
     
   
    </section>  
      
<table>
    <thead>
        <tr>
            <td><a href="agregar_producto.php">AGREGAR</a></td>
        </tr>
        <tr>
            <th>Nombre</th>
            <th>Imagen</th>
            <th>Precio</th>
            <th>Boton de acciones</th>
        </tr>
    </thead>
    <tbody>
        <?php foreach ($datos as $valores) {?>
            <tr>
                <td><?php echo $valores["nombre"]; ?></td>
                <td><img src="img/<?php echo $valores["imagen"]; ?>" width="60px" height="50px"alt=""></td>
                <td><?php echo $valores["precio"]. "$"; ?></td>
                <td><a href="editar.php?id=<?php echo $valores["id"]; ?>">editar</a><a href="carrito2.php?id=<?php echo $valores["id"]; ?>">eliminar</a></td>
            </tr>
        <?php } ?>
 
    </tbody>
</table> 

<?php include("aparece2.php") ?>

<div class="chat-icon">
    <i class="far fa-comment"></i>
    </div>


      <footer>
        <div class="footer-container">
          <div class="copyright">
            &copy; 2023 Tu Empresa. Todos los derechos reservados.
          </div>
          <div class="contact-info">
            <div class="phone">Teléfono: +1 234 567 890</div>
            <div class="address">Dirección: Calle Principal, Ciudad, Estado</div>
            <div class="icono">
              <i class="fi fi-brands-instagram"></i>
            </div>
            <img src="img/" alt="">
            <a href="#" id="backToTop">
              <i class="fas fa-arrow-up"></i>
            </a>
          </div>
        </div>
    </footer>
   
    
    <script src="Javas/shop.js"></script>

        <script src="Javas/slides.js"></script>  
        <script src="Javas/menu.js  "></script>  
      <script src="Javas/filtrar.js"></script>
</body>
</html>