<?php include __DIR__ . '/../layout/header.php'; ?>

<div class="container" style="padding-top:28px;padding-bottom:48px;">

    <div style="display:flex;align-items:center;gap:16px;border-bottom:2px solid var(--border-color);padding-bottom:14px;margin-bottom:25px;">
        <?php
        $brandImg = '';
        if (!empty($brand['image'])) {
            $brandImg = $baseUrl . '/' . ltrim($brand['image'], '/');
        } else {
            $imgPath = __DIR__ . '/../../public/uploads/brands/' . $brand['slug'] . '.webp';
            if (file_exists($imgPath)) {
                $brandImg = $baseUrl . '/uploads/brands/' . $brand['slug'] . '.webp';
            }
        }
        ?>
        <?php if ($brandImg): ?>
        <img src="<?php echo htmlspecialchars($brandImg); ?>" alt="<?php echo htmlspecialchars($brand['name']); ?>" style="width:120px;height:60px;object-fit:contain;border-radius:8px;background:var(--bg-secondary);">
        <?php endif; ?>
        <div style="flex:1;">
            <h1 style="font-size:24px;font-weight:800;color:var(--text-1);margin:0;"><?php echo htmlspecialchars($brand['name']); ?> Ürünleri</h1>
            <p style="font-size:13px;color:var(--text-3);margin:4px 0 0;"><?php echo $total; ?> ürün listeleniyor</p>
        </div>
    </div>

    <?php if (!empty($products)): ?>
        <div class="products-grid">
            <?php foreach ($products as $prod): ?>
                <article class="product-card">
                    <div class="product-image">
                        <a href="<?php echo $baseUrl; ?>/<?php echo $prod->slug; ?>">
                            <img src="<?php echo $prod->getMainImage($baseUrl); ?>" alt="<?php echo htmlspecialchars($prod->name); ?>" loading="lazy">
                        </a>
                        <button class="quick-add" onclick="addToCart('<?php echo $prod->id; ?>', 1)">
                            <i class="fa fa-shopping-basket"></i> Sepete Ekle
                        </button>
                    </div>
                    <div class="product-body">
                        <div class="product-brand"><?php echo htmlspecialchars($brand['name']); ?></div>
                        <h4 class="product-title">
                            <a href="<?php echo $baseUrl; ?>/<?php echo $prod->slug; ?>">
                                <?php echo htmlspecialchars($prod->name); ?>
                            </a>
                        </h4>
                        <div class="product-price"><?php echo $prod->getFormattedPrice(); ?></div>
                    </div>
                </article>
            <?php endforeach; ?>
        </div>
        <?php if ($totalPages > 1): ?>
        <div class="pagination">
            <?php if ($page > 1): ?>
            <a href="?page=<?php echo $page - 1; ?>" class="page-link">&laquo; Önceki</a>
            <?php endif; ?>
            <?php for ($i = 1; $i <= $totalPages; $i++): ?>
            <a href="?page=<?php echo $i; ?>" class="page-link <?php echo $i === $page ? 'active' : ''; ?>"><?php echo $i; ?></a>
            <?php endfor; ?>
            <?php if ($page < $totalPages): ?>
            <a href="?page=<?php echo $page + 1; ?>" class="page-link">Sonraki &raquo;</a>
            <?php endif; ?>
        </div>
        <?php endif; ?>
    <?php else: ?>
        <div style="background-color: var(--bg-secondary); border: 1px dashed var(--border-color); border-radius: var(--radius-md); padding: 40px; text-align: center; color: var(--text-secondary);">
            <i class="fa fa-print" style="font-size: 40px; opacity: 0.3; margin-bottom: 15px;"></i>
            <p style="font-weight: 500;">Bu markaya ait henüz sergilenecek bir ürün bulunmuyor.</p>
            <a href="<?php echo $baseUrl; ?>/product/manufacturer" style="margin-top: 15px; display: inline-block;" class="btn-primary">Tüm Markalar</a>
        </div>
    <?php endif; ?>
</div>

<?php include __DIR__ . '/../layout/footer.php'; ?>