<?php
$imagenes = glob("uploads/anuncio3/*.{jpg,jpeg,png,gif,webp}", GLOB_BRACE);
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Anuncio 1</title>
<style>
html, body {
    margin: 0;
    padding: 0;
    background: black;
    height: 100%;
    width: 100%;
    overflow: hidden;
}
img {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: cover; /* ocupa toda la pantalla */
    transition: opacity 1s ease-in-out;
    opacity: 1;
}
</style>
</head>
<body>

<?php if (!empty($imagenes)): ?>
<img id="banner" src="<?= $imagenes[0] ?>" alt="Anuncio">
<?php else: ?>
<p style="color:white;text-align:center;">No hay imágenes disponibles</p>
<?php endif; ?>

<script>
let imagenes = <?= json_encode($imagenes) ?>;
let index = 0;
const banner = document.getElementById('banner');

if (imagenes.length > 1 && banner) {
    setInterval(() => {
        index = (index + 1) % imagenes.length;
        banner.style.opacity = 0;
        setTimeout(() => {
            banner.src = imagenes[index];
            banner.style.opacity = 1;
        }, 1000);
    }, 10000); // cambia cada 10 segundos
}
</script>
</body>
</html>