<?php
/**
 * Template part for displaying post content
 *
 * @package Blog_Over
 */
$layout = get_theme_mod('Blog_Over_layout', 'right-sidebar');
$is_grid = (strpos($layout, 'grid') !== false);
$elements = blog_over_get_blog_entry_elements();
$show_thumbnail = get_theme_mod('Blog_Over_show_thumbnail', true);
$ratio_class = function_exists('blog_over_get_image_ratio_class') ? blog_over_get_image_ratio_class() : 'ratio-full';
?>

<article id="post-<?php the_ID(); ?>" <?php post_class('blog-over-post-item'); ?>>
    <?php
    // Featured Image - fixed at top, controlled by toggle
    if ($show_thumbnail && has_post_thumbnail()):
        ?>
        <div class="blog-over-post-thumbnail blog-image <?php echo esc_attr($ratio_class); ?>">
            <a href="<?php the_permalink(); ?>">
                <?php
                $size = $is_grid ? 'blog-over-medium' : 'blog-over-featured';
                the_post_thumbnail($size);
                ?>
            </a>
        </div>
        <?php
    endif;
    ?>

    <div class="blog-over-post-content">
        <?php
        // Render elements in saved order
        foreach ($elements as $element):
            switch ($element):
                case 'category':
                    // Category only shows when thumbnail is enabled
                    if ($show_thumbnail):
                        $cats = get_the_category();
                        if (!empty($cats)):
                            ?>
                            <div class="blog-over-post-category">
                                <?php the_category(' '); ?>
                            </div>
                            <?php
                        endif;
                    endif;
                    break;

                case 'header':
                    ?>
                    <header class="blog-over-post-header">
                        <?php the_title('<h2 class="blog-over-post-title"><a href="' . esc_url(get_permalink()) . '">', '</a></h2>'); ?>
                    </header>
                    <?php
                    break;

                case 'meta':
                    ?>
                    <div class="blog-over-post-meta">
                        <?php blog_over_render_entry_meta(); ?>
                    </div>
                    <?php
                    break;

                case 'summary':
                    ?>
                    <div class="blog-over-post-excerpt">
                        <?php
                        if (get_theme_mod('blog_over_content_type', 'excerpt') === 'excerpt') {
                            the_excerpt();
                        } else {
                            the_content();
                        }
                        ?>
                    </div>
                    <?php
                    break;

                case 'footer':
                    ?>
                    <footer class="blog-over-post-footer">
                        <a href="<?php the_permalink(); ?>" class="blog-over-read-more">
                            <?php echo esc_html(get_theme_mod('blog_over_read_more_text', __('Read More', 'blog-over'))); ?>
                            <i class="fas fa-arrow-right"></i>
                        </a>
                    </footer>
                    <?php
                    break;
            endswitch;
        endforeach;
        ?>
    </div>
</article>