<?php
// Fetch post options
$post_author          = glamer_options('glamer_single_post_author', true);
$post_date            = glamer_options('glamer_single_post_date', true);
$post_comment_number  = glamer_options('glamer_single_post_cmnt', true);
$post_cat_name        = glamer_options('glamer_single_post_cat', true);
$post_tag             = glamer_options('glamer_single_post_tag', true);
$post_share           = glamer_options('glamer_post_share', true);
$post_nav             = glamer_options('glamer_post_nav', true);
$author_profile       = glamer_options('glamer_author_profile', false);
$fullwidth_content    = glamer_options('post_single_fullwith_content');

// Override the fullwidth content layout with 'bs' URL parameter if it exists
$layout_override = isset($_GET['view']) ? sanitize_text_field($_GET['view']) : $fullwidth_content;

$post_format = get_post_format();

// Load post format template part
$template_part = 'template-parts/post/post-format/post-format-others';
if ($post_format) {
    $template_part = 'template-parts/post/post-format/post-format-' . $post_format;
}
?>

<article id="post-<?php the_ID(); ?>" <?php post_class('post-single ' . ($layout_override !== 'two' && get_post_type() === 'post' ? 'full-width-post-style-one' : 'full-width-post-style-two')); ?>>

    <?php get_template_part($template_part); ?>
    <?php if ($layout_override === 'one') : ?>
        <div class="row align-items-center justify-content-center">
            <div class="col-lg-8">
                <div class="single-post-wrapper">
                    <?php if ('post' === get_post_type()) : ?>
                        <div class="post-meta post-details-meta">
                            <ul>
                                <?php if ($post_author) : ?>
                                    <li><?php glamer_posted_by(); ?></li>
                                <?php endif; ?>
                                <?php if ($post_date) : ?>
                                    <li><?php glamer_posted_on(); ?></li>
                                <?php endif; ?>
                                <?php if ($post_cat_name) : ?>
                                    <li><?php glamer_post_categories(); ?></li>
                                <?php endif; ?>
                            </ul>
                        </div>
                    <?php endif; ?>
                    <?php the_title('<h3 class="post-title single-blog-post-title underline-anim-wrap">', '</h3>'); ?>

                    <div class="hero-eye-tag">
                        <ul>
                            <li>
                                <div class="eye-tag-wrap">
                                    <div class="tag-icon">
                                        <i class="fas fa-eye"></i>
                                    </div>
                                    <h5 class="tag-title"><?php echo do_shortcode('[post_views]'); ?></h5>
                                </div>
                            </li>
                            <?php if (get_comments_number() != 0 && $post_comment_number) : ?>
                                <li>
                                    <div class="eye-tag-wrap">
                                        <div class="tag-icon">
                                            <i class="fas fa-comment"></i>
                                        </div>
                                        <h5 class="tag-title"><?php echo get_comments_number(); ?></h5>
                                    </div>
                                </li>
                            <?php endif; ?>

                            <?php
                            $share_count = get_post_meta(get_the_ID(), 'glamer_metabox', true)['glamer_post_share_count'] ?? '';
                            if (!empty($share_count)):
                            ?>
                                <li>
                                    <div class="eye-tag-wrap social-share">
                                        <div class="tag-icon">
                                            <i class="fas fa-share-alt"></i>
                                            <?php glamercore_post_share(); ?>
                                        </div>
                                        <span class="tag-title"><?php echo esc_html($share_count); ?></span>
                                    </div>
                                </li>
                            <?php endif; ?>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    <?php endif; ?>

        <?php if ($layout_override !== 'two' && get_post_type() === 'post') : ?>
        <div class="col-lg-8 single-post-style-one">
        <?php endif; ?>
        <div class="post-content-wrapper">
            <?php if ($layout_override === 'two' && get_post_type() === 'post') : ?>
                <div class="post-meta post-details-meta">
                    <ul>
                        <?php if ($post_author) : ?>
                            <li><?php glamer_posted_by(); ?></li>
                        <?php endif; ?>
                        <?php if ($post_date) : ?>
                            <li><?php glamer_posted_on(); ?></li>
                        <?php endif; ?>
                        <?php if ($post_cat_name) : ?>
                            <li><?php glamer_post_categories(); ?></li>
                        <?php endif; ?>
                    </ul>
                </div>
            <?php endif; ?>

            <div class="entry-content">
                <?php if ($layout_override === 'two') : ?>
                    <?php
                    $title_length = glamer_options('glamer_blog_post_title_length'); // Retrieve the dynamic title length
                    ?>
                    <h3 class="post-title single-blog-post-title underline-anim-wrap">
                        <?php echo wp_trim_words(get_the_title(), $title_length, ''); ?>
                    </h3>
                <?php endif; ?>

                <?php
                the_content(sprintf(
                    wp_kses(
                        __('Continue reading<span class="screen-reader-text"> "%s"</span>', 'glamer'),
                        array('span' => array('class' => array()))
                    ),
                    get_the_title()
                ));

                wp_link_pages(array(
                    'before' => '<div class="page-links">' . esc_html__('Pages:', 'glamer'),
                    'after'  => '</div>',
                ));
                ?>
            </div><!-- .entry-content -->

            <?php if (has_tag() && $post_tag) : ?>
                <div class="post-share-wrapper pt-10">
                    <?php glamer_post_tags(); ?>
                </div>
            <?php endif; ?>
        </div>
        <?php if ($layout_override !== 'two' && get_post_type() === 'post') : ?>
        </div>
        <?php endif; ?>
    <?php if (function_exists('glamercore_post_share') && $post_share) {
        glamercore_post_share();
    } ?>
</article><!-- #post-<?php the_ID(); ?> -->
<?php
$total_post = wp_count_posts('post')->publish;
if ($total_post > 1 && $post_nav) {
    glamer_next_prev_post_link();
}
if ($author_profile) {
    /**
	* Hook - glamer_action_author_info_hook.
	*
	* @hooked glamer_author_info_hook -  10
	*/
	do_action( 'glamer_action_author_info_hook' );
}
?>