<!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>Programacion</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
    <style>
        *{
            padding: 0;
            margin: 0;
            box-sizing: border-box;
            font-family: sans-serif;
        }
        h1{
            text-align: center;
            position: relative;
            width: 80%;
            margin: 50px auto;
        }
        body{
            background-color: #ecf4fb;
        }
        h1::before{
            content: "";
            display: block;
            width: 100%;
            height: 2px;
            position: absolute;
            background-color: rgba(0, 0, 0, 0);
            top: 50%;
            z-index: -1;
        }
        h1 span{
            background-color:#ecf4fb;
            padding: 0 15px;
        }
        .img-gallery{
            width: 80%;
            margin: 50px auto 50px;
            display: grid;
            grid-template-columns: repeat(auto-fit,minmax(240px,1fr));
            gap: 30px;
        }
        .img-gallery img{
            width: 100%;
            cursor: pointer;
            transition: 1s;
        }
        .img-gallery img:hover{
            transform: scale(1.2);
        }
        .ful-img{
            width: 100%;
            height: 100vh;
            background-color: rgba(0, 0,0, 0.9);
            position: fixed;
            top: 0;
            left: 0;
            display: none;
            align-items: center;
            justify-content: center;
            z-index: 99;
        }
        .ful-img span{
            position: absolute;
            top: 5%;
            right: 5%;
            font-size: 30px;
            color: #fff;
            cursor: pointer;
        }
        .ful-img img{
            width: 90%;
            max-width: 600px;
        }
        @media screen and (max-width:400px){
            h1{
                text-decoration: underline;
            }
            h1::before{
                display: none;
            }
            h1 span{
                padding: 0;
            }
        }

        .img-gallery {
            width: 80%;
            margin: 50px auto 50px;
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
            gap: 30px;
        }

        .img-gallery > div {
            display: flex;
            flex-direction: column;
        }

        .img-gallery img {
            width: 100%;
            height: 200px; /* Specify the desired height for the images */
            object-fit: cover; /* Maintain aspect ratio */
            cursor: pointer;
            transition: 1s;
        }

        .img-gallery img:hover {
            transform: scale(1.2);
        }

        .background-radial-gradient {
            background-color: hsl(236, 243, 249);
        }

        #radius-shape-1 {
            height: 220px;
            width: 220px;
            top: -60px;
            left: -130px;
            background: radial-gradient(#44006b, #ad1fff);
            overflow: hidden;
        }

        #radius-shape-2 {
            border-radius: 38% 62% 63% 37% / 70% 33% 67% 30%;
            bottom: -60px;
            right: -110px;
            width: 300px;
            height: 300px;
            background: radial-gradient(#44006b, #ad1fff);
            overflow: hidden;
        }

        .bg-glass {
            background-color: hsl(0, 0%, 100%) !important;
            backdrop-filter: saturate(200%) blur(25px);
        }

        .navbar {
            margin-bottom: 20px;
        }

        .navbar .button1, .navbar .logo {
            margin: 10px;
        }

        .content-wrapper {
            display: flex;
            justify-content: center;
            align-items: center;
            height: calc(100vh - 60px); /* Ajusta la altura para tener en cuenta la altura de la barra de navegaci√≥n */
        }

        .card {
            max-width: 500px;
            width: 100%;
        }

    </style>


</head>
<body>


    <nav class="navbar navbar-expand-lg navbar-light bg-glass fixed-top">
        <div class="container-fluid">
            <a href="/"><button class="btn btn-primary button1">Volver al inicio</button></a>
            <a href="/carrito-compra"><button class="btn btn-primary">Carrito<i class="fas fa-shopping-cart"></i></button></a>
            <a href="/conocenos"><img src="/uploads/logo.jpeg" alt="Logo" class="logo"></a>
        </div>
    </nav>
    
    <section class="background-radial-gradient overflow-hidden">
        <div class="container px-4 py-5 px-md-5 text-center text-lg-start my-5">
            <div class="row gx-lg-5 align-items-center mb-5">
                

                    <h1 class="mb-4">Programacion</h1>
                    <div class="img-gallery" id="galleryDiv">
                    </div>
                    
            </div>
        </div>           
    </section>

    <script src="script.js"></script>
    <script>
        const divParent = document.getElementById("galleryDiv");
    
        async function showImagesInDOM() {
            const response = await fetch('http://localhost:3001/productos-categoria?categoria=programacion');
            const productos = await response.json();

            const URLforImages = "http://localhost:3001/showImage/";
            for (const producto of productos) {
                const newDivForImage = document.createElement("div");

                const newImageInsideDiv = document.createElement("img");
                newImageInsideDiv.src = URLforImages + producto.nombre_imagen;

                const newLabelProductIdDiv = document.createElement("p");
                newLabelProductIdDiv.textContent = `Id del producto: ${producto.producto_id}`;

                const newLabelProductInsideDiv = document.createElement("p");
                newLabelProductInsideDiv.textContent = `Nombre: ${producto.nombre}`;

                const newLabelPriceInsideDiv = document.createElement("p");
                newLabelPriceInsideDiv.textContent = `Precio: ${producto.precio}`;

                const newLabelCantInsideDiv = document.createElement("p");
                newLabelCantInsideDiv.textContent = `Cantidad disponible: ${producto.cantidad}`;

                const formInsideDiv = document.createElement("form");
                formInsideDiv.action = '/carrito-compra';
                formInsideDiv.method = 'POST';

                const newButtonOfSubmit = document.createElement("button");
                newButtonOfSubmit.textContent = "Comprar producto";
                formInsideDiv.appendChild(newButtonOfSubmit);

                // Add hidden input fields for product details
                const hiddenId = document.createElement("input");
                hiddenId.type = "hidden";
                hiddenId.name = "producto_id";
                hiddenId.value = producto.producto_id;

                
                formInsideDiv.appendChild(hiddenId);

                newDivForImage.appendChild(newImageInsideDiv);
                newDivForImage.appendChild(newLabelProductIdDiv);
                newDivForImage.appendChild(newLabelProductInsideDiv);
                newDivForImage.appendChild(newLabelPriceInsideDiv);
                newDivForImage.appendChild(newLabelCantInsideDiv);
                newDivForImage.appendChild(formInsideDiv);

                divParent.appendChild(newDivForImage);
            }
        }

        showImagesInDOM();
    </script>
</body>
</html>