<?php
session_start();
$id = @$_SESSION['id'];
$nombre = @$_SESSION['nombre'];
include("include/conexion.php");
if (!isset($_SESSION['nombre'])) {
    header("Location: login.php");
    exit();
}

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'],
                "img"=> $_POST['imagen'],
                "producto"=> $_POST['producto'],
                "precio"=> $_POST['precio'],
                "quantity" => $_POST['quantity'],
            );
            $_SESSION['cart'][]=$session_array;
            
        }

    }else{

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

}
?>


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
    <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="css/index.css">
    <link rel="stylesheet" href="css/productos.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">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/uikit@3.18.3/dist/css/uikit.min.css" />
    <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>
</head>
<body>
    <?php include("include/img.php"); ?>
    <nav class="uk-navbar-container">
        <div uk-navbar>
            <a href="index.php"><img src="<?php echo $path .$img["logos"][0]["logo"];?>" alt="Logo" class="logo uk-flex uk-flex-center uk-margin-large-left"></a>
            <div class="uk-navbar-right">
                <ul class="uk-navbar-nav uk-margin-xlarge-right">
                    <li class="uk-active uk-margin-small-right uk-visible@s">
                        <a href="index.php" class="">Inicio</a>
                        <div class="uk-navbar-dropdown">
                            <ul class="uk-nav uk-navbar-dropdown-nav">
                                <li class=""><a href="#">Sobre Nosotros</a></li>
                                <li><a href="#">Nuestros servicios</a></li>
                                <li><a href="#">Galeria</a></li>
                            </ul>
                        </div>
                    </li>
                    <li class="uk-margin-small-right  uk-visible@s"><a href="tienda.php">Comprar</a></li>
                    <li class="uk-margin-small-right  uk-visible@s"><a href="historial.php">Historial de compras</a></li>
                    <li class="uk-margin-small-right  uk-visible@s"><a href="contactos.php">Contactanos</a></li>
                    <li class="uk-margin-small-right uk-flex uk-flex-middle uk-visible@s k" ><button onclick="hacerVisibleCarrito()" class="fas fa-shopping-cart">carrito</button></li>
                    <?php 
                    if(isset($_SESSION['nombre'])) {
                        echo '<li class="uk-margin-small-right uk-flex uk-flex-middle uk-visible@s">' . $_SESSION["nombre"] . '</li>';
                    }
                    ?>

                    <li class="uk-visible@s"><a href="login.php"><span uk-icon="icon: sign-in; ratio: 1.2"></span></a></li>;
                    <a href="#" class="uk-button uk-button-default uk-margin-medium-right uk-margin-small-top uk-margin-small-bottom uk-hidden@s" type="button" uk-icon="icon:menu; ratio:1.4;" uk-toggle="target: #offcanvas-overlay"></a>
                </ul>

            </div>

        </div>
    </nav>     
    <div class="uk-section">
        <div class="uk-container">
            <input type="search" id="buscador" class="uk-input" placeholder="Buscar..." data-table="item" />
        </div>
    </div>
   
    <?php include("aparece.php") ?>
    <?php include("include/footer.php") ?>
    <?php include("include/offcanvas.php") ?>

    <script src="js/shop.js"></script>
    <script src="js/ll.js"></script>
</body>
</html>