<?php
$imagenes = glob("uploads/anuncio2/*.{jpg,jpeg,png,webp,gif}", GLOB_BRACE);
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, orientation=landscape">
<title>Anuncio 2</title>
<style>
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: black;
}

#slider-container {
    position: relative;
    width: 100%;
    height: 100%;
}

.slide {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover; /* llena sin deformar */
    opacity: 0;
    transition: opacity 1s ease-in-out;
}

.active {
    opacity: 1;
}
</style>
</head>
<body>
<div id="slider-container">
    <?php foreach ($imagenes as $index => $img): ?>
        <img src="<?= $img ?>" class="slide <?= $index === 0 ? 'active' : '' ?>">
    <?php endforeach; ?>
</div>

<script>
let slides = document.querySelectorAll('.slide');
let index = 0;

if (slides.length > 0) {
    setInterval(() => {
        slides[index].classList.remove('active');
        index = (index + 1) % slides.length;
        slides[index].classList.add('active');
    }, 10000);
} else {
    document.body.innerHTML = "<p style='color:white;text-align:center;margin-top:40%;font-size:24px;'>No hay imágenes</p>";
}
</script>
</body>
</html>
