<?php
$products = section_products($s);
$link = $s['show_link'] === '1' ? section_products_link($s) : null;
?>
<?php if ($products): ?>
    <?php if ($s['layout'] === 'promo'): ?>
        <div class="grid overflow-hidden rounded-[var(--radius-panel)] bg-accent-50 lg:grid-cols-12">
            <div class="flex flex-col justify-center p-8 sm:p-12 lg:col-span-4">
                <?php if ($s['subtitle']): ?><p class="eyebrow text-accent-700"><?= e($s['subtitle']) ?></p><?php endif ?>
                <h2 class="heading mt-4 text-4xl <?= heading_weight_class() ?>"><?= e($s['title']) ?></h2>
                <?php if ($s['promo_text']): ?><p class="mt-4 text-zinc-600"><?= e($s['promo_text']) ?></p><?php endif ?>
                <?php if ($link): ?><a href="<?= e($link) ?>" class="btn-primary mt-8 self-start">Tümünü gör<?= icon('arrow', 'size-4', '2') ?></a><?php endif ?>
            </div>
            <div class="grid grid-cols-2 gap-x-4 gap-y-8 p-6 sm:gap-x-6 sm:p-10 lg:col-span-8 lg:grid-cols-4 lg:pl-0">
                <?php foreach (array_slice($products, 0, 4) as $product): ?>
                    <?php product_card($product) ?>
                <?php endforeach ?>
            </div>
        </div>
    <?php elseif ($s['layout'] === 'carousel'): ?>
        <div data-carousel>
            <div class="mb-8 flex flex-wrap items-end justify-between gap-4">
                <div>
                    <h2 class="heading text-2xl <?= heading_weight_class() ?> sm:text-3xl"><?= e($s['title']) ?></h2>
                    <?php if ($s['subtitle']): ?><p class="mt-2 text-zinc-500"><?= e($s['subtitle']) ?></p><?php endif ?>
                </div>
                <div class="flex items-center gap-2">
                    <?php if ($link): ?><a href="<?= e($link) ?>" class="mr-2 text-sm font-medium text-zinc-600 hover:text-ink">Tümünü gör</a><?php endif ?>
                    <button type="button" data-carousel-prev class="flex size-10 items-center justify-center rounded-full border border-zinc-200 transition hover:border-ink" aria-label="Önceki"><?= icon('left', 'size-4', '2') ?></button>
                    <button type="button" data-carousel-next class="flex size-10 items-center justify-center rounded-full border border-zinc-200 transition hover:border-ink" aria-label="Sonraki"><?= icon('right', 'size-4', '2') ?></button>
                </div>
            </div>
            <div data-carousel-track class="-mx-4 flex snap-x snap-mandatory gap-4 overflow-x-auto scroll-smooth px-4 pb-1 [scrollbar-width:none] sm:gap-6 [&::-webkit-scrollbar]:hidden">
                <?php foreach ($products as $product): ?>
                    <div class="w-[46%] shrink-0 snap-start sm:w-[31%] lg:w-[23.5%]"><?php product_card($product) ?></div>
                <?php endforeach ?>
            </div>
        </div>
    <?php else: ?>
        <?= section_title_html($s['title'], $s['subtitle'], $link) ?>
        <?php product_grid($products) ?>
    <?php endif ?>
<?php endif ?>
