<?php
defined('ABSPATH') || exit;
?>
<section class="kb-docs-home">
    <h1><?php esc_html_e('Knowledgebase', 'kb-markdown-importer'); ?></h1>
    <div class="kb-product-list">
        <?php foreach ((array) $products as $item) : ?>
            <?php $term = $item['term']; ?>
            <?php $latest = $item['versions'][0] ?? null; ?>
            <section class="kb-product-card">
                <h2><a href="<?php echo esc_url($latest ? $url_builder::version($term->slug, $latest->slug) : $url_builder::product($term->slug)); ?>"><?php echo esc_html($term->name); ?></a></h2>
                <?php if (! empty($item['versions'])) : ?>
                    <ul>
                        <?php foreach ($item['versions'] as $version) : ?>
                            <li><a href="<?php echo esc_url($url_builder::version($term->slug, $version->slug)); ?>"><?php echo esc_html($version->name); ?></a></li>
                        <?php endforeach; ?>
                    </ul>
                <?php endif; ?>
            </section>
        <?php endforeach; ?>
    </div>
</section>
