<?php
defined('ABSPATH') || exit;
?>
<section class="kb-docs-version">
    <header class="kb-doc-header">
        <div class="kb-doc-header__main">
            <nav class="kb-breadcrumbs">
                <a href="<?php echo esc_url($url_builder::docsIndex()); ?>"><?php esc_html_e('Dokumentation', 'kb-markdown-importer'); ?></a><span>/</span>
                <a href="<?php echo esc_url($url_builder::product($product->slug)); ?>"><?php echo esc_html($product->name); ?></a><span>/</span>
                <span><?php echo esc_html($version->name); ?></span>
            </nav>
            <h1><?php echo esc_html($product->name . ' ' . $version->name); ?></h1>
        </div>
        <?php if (! empty($versions)) : ?>
            <div class="kb-version-switcher">
                <label for="kb-version-switcher"><?php esc_html_e('Version', 'kb-markdown-importer'); ?></label>
                <select id="kb-version-switcher">
                    <?php foreach ((array) $versions as $available_version) : ?>
                        <option value="<?php echo esc_attr($available_version->slug); ?>" data-url="<?php echo esc_url($url_builder::version($product->slug, $available_version->slug)); ?>" <?php selected($available_version->slug, $version->slug); ?>>
                            <?php echo esc_html($available_version->name); ?>
                        </option>
                    <?php endforeach; ?>
                </select>
            </div>
        <?php endif; ?>
    </header>
    <ul class="kb-page-list">
        <?php foreach ((array) $pages as $page) : ?>
            <?php $slug = (string) get_post_meta($page->ID, '_kb_page_slug', true); ?>
            <li><a href="<?php echo esc_url($url_builder::page($product->slug, $version->slug, $slug)); ?>"><?php echo esc_html(get_the_title($page)); ?></a></li>
        <?php endforeach; ?>
    </ul>
</section>
