<?php if($settings?->show_news ?? true): ?>
<section class="section <?php echo e($sectionBg ?? ''); ?>" id="noticias">
    <div class="container">
        <div class="d-flex justify-content-between align-items-end mb-5" data-aos="fade-up">
            <div>
                <span class="badge-pill">Noticias</span>
                <h2 class="section-title mt-2 mb-0"><?php echo $settings?->news_title ?: 'Ultimas Novedades'; ?></h2>
                <?php if($settings?->news_subtitle): ?>
                    <p class="text-muted mb-0 mt-2"><?php echo $settings->news_subtitle; ?></p>
                <?php endif; ?>
            </div>
            <div class="d-flex align-items-center gap-2">
                <button type="button" class="btn btn-outline-primary rounded-circle" style="width:44px;height:44px;" data-bs-target="#newsCarousel" data-bs-slide="prev" aria-label="Anterior">
                    <i class="bi bi-chevron-left"></i>
                </button>
                <button type="button" class="btn btn-outline-primary rounded-circle" style="width:44px;height:44px;" data-bs-target="#newsCarousel" data-bs-slide="next" aria-label="Siguiente">
                    <i class="bi bi-chevron-right"></i>
                </button>
                <a href="<?php echo e(route('news.index')); ?>" class="btn btn-outline-primary rounded-pill ms-2">Ver todas</a>
            </div>
        </div>

        <?php if($news->isNotEmpty()): ?>
            <div id="newsCarousel" class="carousel slide" data-bs-ride="carousel" data-bs-interval="4000">
                <div class="carousel-inner" id="newsCarouselInner"></div>
            </div>
            <div id="newsCardsSource" class="d-none">
                <?php $__currentLoopData = $news; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <div class="news-card-src">
                        <div class="card card-hover h-100 shadow-sm">
                            <?php if($item->image): ?>
                                <img src="<?php echo e(image_url($item->image)); ?>" class="card-img-cover" alt="<?php echo e($item->title); ?>">
                            <?php endif; ?>
                            <div class="card-body p-4 d-flex flex-column">
                                <div class="text-muted small mb-2"><i class="bi bi-calendar3 me-1"></i><?php echo e($item->published_at?->format('d/m/Y')); ?></div>
                                <h6 class="fw-bold"><a href="<?php echo e(route('news.show', $item->slug)); ?>" class="text-decoration-none text-dark"><?php echo e($item->title); ?></a></h6>
                                <p class="text-muted small mb-3"><?php echo e(Str::limit($item->excerpt ?? strip_tags($item->content ?? ''), 90)); ?></p>
                                <a href="<?php echo e(route('news.show', $item->slug)); ?>" class="fw-bold text-decoration-none mt-auto" style="color:var(--primary);">Leer mas</a>
                            </div>
                        </div>
                    </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </div>
        <?php else: ?>
            <div class="text-center text-muted py-5">No hay noticias publicadas.</div>
        <?php endif; ?>
    </div>
</section>
<?php endif; ?>

<?php $__env->startPush('scripts'); ?>
<script>
(function () {
    var source = document.getElementById('newsCardsSource');
    var inner = document.getElementById('newsCarouselInner');
    if (!source || !inner) return;

    var cards = Array.prototype.slice.call(source.querySelectorAll('.news-card-src'));
    var currentPer = 0;

    function perSlide() {
        if (window.innerWidth < 576) return 1;
        if (window.innerWidth < 992) return 2;
        return 3;
    }

    function build() {
        var per = perSlide();
        if (per === currentPer && inner.children.length) return;
        currentPer = per;

        var colClass = per === 1 ? 'col-12' : (per === 2 ? 'col-sm-6' : 'col-md-4');

        var arr = cards.slice();
        var rem = arr.length % per;
        if (rem !== 0) {
            for (var i = 0; i < per - rem; i++) {
                arr.push(cards[i % cards.length]);
            }
        }

        inner.innerHTML = '';
        for (var g = 0; g < arr.length; g += per) {
            var item = document.createElement('div');
            item.className = 'carousel-item' + (g === 0 ? ' active' : '');
            var row = document.createElement('div');
            row.className = 'row g-4';
            for (var k = g; k < g + per; k++) {
                var col = document.createElement('div');
                col.className = colClass;
                col.appendChild(arr[k].cloneNode(true));
                row.appendChild(col);
            }
            item.appendChild(row);
            inner.appendChild(item);
        }
    }

    build();
    window.addEventListener('resize', function () {
        clearTimeout(window.__newsT);
        window.__newsT = setTimeout(build, 150);
    });
})();
</script>
<?php $__env->stopPush(); ?>
<?php /**PATH /Applications/XAMPP/xamppfiles/htdocs/PROYECTOS/LARAVEL/paginaweb/resources/views/partials/home/news.blade.php ENDPATH**/ ?>