<?php
get_header();

if ( ! function_exists( 'elementor_theme_do_location' ) || ! elementor_theme_do_location( 'single' ) ) {
    $pzy_single_post_template = pzy_get_option('pzy_single_post_template');
    if($pzy_single_post_template){
        pzy_load_element_template($pzy_single_post_template);
    }else{
    
        echo '<div class="container">';
    
        pzy_breadcrumb_enabled() && pzy_breadcrumb();
    
        $comments_html = '';
    
        while (have_posts()): the_post();
    
            ?>
            <article id="post-<?php the_ID(); ?>" <?php post_class('pzy-single-post'); ?>>
                <header>
                    <h1 class="pzy-single-post-title"><?php the_title(); ?></h1>
                    <?php
                    $post_metas = pzy_get_option('post_metas');
                    $meta_types = $post_metas['meta_type'] ?? [];
                    $single_post_header_share = pzy_get_option('single_post_header_share');
                    if (count($meta_types) || $single_post_header_share) {
                        ?>
                        <div class="pzy-meta">
                            <?php foreach ($meta_types as $index => $meta_type) { ?>
                                <?php switch ($meta_type) {
                                    case 'date':
                                        ?>
                                        <div class="pzy-meta-item"><i class="pzy-meta-icon"
                                                                    data-feather="calendar"></i><?php echo get_the_date('Y/m/d') ?>
                                        </div>
                                        <?php
                                        break;
                                    case 'view':
                                        ?>
                                        <div class="pzy-meta-item"><i class="pzy-meta-icon"
                                                                    data-feather="eye"></i><?php echo do_shortcode('[iawp_view_counter label="' . __('بازدید', 'pezeshkyar') . '" icon="0"]') ?>
                                        </div>
                                        <?php
                                        break;
                                    case 'comment':
                                        ?>
                                        <div class="pzy-meta-item"><i class="pzy-meta-icon"
                                                                    data-feather="message-square"></i><?php comments_number() ?>
                                        </div>
                                        <?php
                                        break;
                                    case 'author':
                                        ?>
                                        <div class="pzy-meta-item"><i class="pzy-meta-icon"
                                                                    data-feather="user"></i><?php the_author_posts_link(); ?>
                                        </div>
                                        <?php
                                        break;
                                } ?>
                                <?php if ($index < count($meta_types) - 1) { ?>
                                    <span class="pzy-meta-item-divider"></span>
                                <?php } ?>
                            <?php } ?>
    
                            <?php if ($single_post_header_share): ?>
                                <?php echo do_shortcode('[pzy_share_article_dropdown transparent="1"]') ?>
                            <?php endif; ?>
                        </div>
                    <?php } ?>
                </header>
                <div class="post-thumbnail">
                    <?php
                    if (has_post_thumbnail()):
                        echo "<img class='pzy-post-feature-image' src='" . get_the_post_thumbnail_url(get_the_ID(), 'full') . "'/>";
                    endif;
                    ?>
                </div>
                <div class="pzy-post-content">
                    <?php
                    wp_link_pages(
                        array(
                            'before' => '<p class="inner-pagination">' . esc_html__('صفحات:', 'pezeshkyar'),
                            'after' => '</p>',
                        )
                    );
                    ?>
                    <?php the_content(); ?>
                </div>
                <div class="pzy-post-footer-1">
                    <div class="pzy-post-categories">
                        <span class="pzy-post-categories-title"><?php echo __('دسته بندی:', 'pezeshkyar') ?></span>
                        <div class="pzy-post-categories-list"><?php the_category('، ') ?></div>
                    </div>
                    <?php if (pzy_get_option('single_post_footer_share')): ?>
                        <div class="pzy-post-share">
                            <div class="pzy-post-share-icon-title">
                                <p class="pzy-post-share-icon"><i data-feather="share-2"></i></p>
                                <p class="pzy-post-share-title"><?php echo __('اشتراک گذاری مقاله', 'pezeshkyar') ?></p>
                            </div>
                            <?php echo do_shortcode('[pzy_share_article]'); ?>
                        </div>
                    <?php endif; ?>
                </div>
                <div class="pzy-post-footer-2">
                    <div class="pzy-post-tags">
                        <span class="pzy-post-tags-title"><?php echo __('برچسب ها:', 'pezeshkyar') ?></span>
                        <div class="pzy-post-tags-list"><?php the_tags('','') ?></div>
                    </div>
                </div>
            </article>
    
            <?php
    
        // If comments are open or we have at least one comment, load up the comment template.
            ob_start();
            if (comments_open() || get_comments_number()):
                comments_template();
            endif;
            $comments_html = ob_get_clean();
    
        // End of the loop.
        endwhile;
        wp_reset_postdata();
    
    
        $template_id = pzy_get_option('blog_after_content');
        pzy_load_element_template($template_id);
    
        echo $comments_html;
        echo "</div>";
    
    }
}

get_footer();