<?php if (!defined('ABSPATH')) exit; ?>
<div class="brands-section py-8 bg-gray-50">
    <div class="container mx-auto px-4">
        <h2 class="text-2xl font-bold text-center mb-8 text-gray-800">محبوب‌ترین برندها</h2>
        <div class="grid grid-cols-3 md:grid-cols-6 lg:grid-cols-8 gap-4">
            <?php foreach ($brands as $brand): 
                $logo_id = get_term_meta($brand->term_id, 'brand_logo', true);
                $logo_url = $logo_id ? wp_get_attachment_image_url($logo_id, 'thumbnail') : '';
            ?>
            <a href="<?php echo esc_url(get_term_link($brand)); ?>" class="bg-white rounded-lg p-4 flex items-center justify-center hover:shadow-md transition h-20">
                <?php if ($logo_url): ?>
                    <img src="<?php echo esc_url($logo_url); ?>" alt="<?php echo esc_attr($brand->name); ?>" class="max-h-12 object-contain grayscale hover:grayscale-0 transition">
                <?php else: ?>
                    <span class="text-gray-600 font-medium"><?php echo esc_html($brand->name); ?></span>
                <?php endif; ?>
            </a>
            <?php endforeach; ?>
        </div>
    </div>
</div>