<?php $products = favorite_products() ?>
<?php if (!$products): ?>
    <div class="flex flex-1 flex-col items-center justify-center px-8 text-center">
        <span class="flex size-16 items-center justify-center rounded-full bg-zinc-100 text-zinc-400"><?= icon('heart', 'size-7') ?></span>
        <p class="font-display mt-5 text-lg font-semibold tracking-tight">Favori listeniz boş</p>
        <p class="mt-1 text-sm text-zinc-500">Beğendiğiniz ürünlerdeki kalbe dokunun, burada saklayalım.</p>
        <a href="<?= url('urunler') ?>" class="btn-primary mt-6">Ürünleri keşfet</a>
    </div>
<?php else: ?>
    <?php if (!is_customer()): ?>
        <p class="border-b border-zinc-100 px-6 py-3 text-[13px] text-zinc-600"><a href="<?= url('giris') ?>" class="font-semibold text-ink underline underline-offset-4">Giriş yapın</a>, listeniz her cihazda saklansın.</p>
    <?php endif ?>

    <ul class="flex-1 divide-y divide-zinc-100 overflow-y-auto px-6">
        <?php foreach ($products as $product): ?>
            <?php $discount = discount_rate($product) ?>
            <li class="flex gap-4 py-5">
                <a href="<?= product_url($product) ?>" class="h-24 w-20 shrink-0 overflow-hidden rounded-xl bg-zinc-100"><?= product_image($product, 'h-full w-full object-cover', 'text-2xl') ?></a>
                <div class="flex min-w-0 flex-1 flex-col">
                    <div class="flex justify-between gap-3">
                        <a href="<?= product_url($product) ?>" class="line-clamp-2 text-sm font-medium text-ink"><?= e($product['name']) ?></a>
                        <form method="post" action="<?= url('favori') ?>" data-ajax>
                            <?= csrf_field() ?>
                            <input type="hidden" name="id" value="<?= $product['id'] ?>">
                            <button class="text-zinc-400 transition hover:text-rose-600" aria-label="Favorilerden çıkar"><?= icon('x', 'size-4') ?></button>
                        </form>
                    </div>
                    <div class="mt-1 flex items-baseline gap-2">
                        <span class="text-sm font-semibold <?= $discount ? 'text-accent-600' : 'text-ink' ?>"><?= money($product['price']) ?></span>
                        <?php if ($discount): ?><span class="text-xs text-zinc-400 line-through"><?= money($product['old_price']) ?></span><?php endif ?>
                    </div>
                    <div class="mt-auto pt-3">
                        <?php if ($product['stock'] < 1): ?>
                            <span class="text-xs font-medium text-zinc-400">Tükendi</span>
                        <?php elseif ($product['variant_name']): ?>
                            <a href="<?= product_url($product) ?>" class="btn-light btn-sm">Seçenekleri gör</a>
                        <?php else: ?>
                            <form method="post" action="<?= url('sepet-ekle') ?>" data-ajax>
                                <?= csrf_field() ?>
                                <input type="hidden" name="id" value="<?= $product['id'] ?>">
                                <button class="btn-primary btn-sm"><?= icon('bag', 'size-4') ?>Sepete ekle</button>
                            </form>
                        <?php endif ?>
                    </div>
                </div>
            </li>
        <?php endforeach ?>
    </ul>

    <div class="shrink-0 border-t border-zinc-100 bg-zinc-50/60 px-6 py-5">
        <a href="<?= url('favorilerim') ?>" class="btn-light w-full">Tüm favorilerim (<?= count($products) ?>)</a>
    </div>
<?php endif ?>
