<?php
global $options, $sidebar, $post, $user_id, $labels;

$active_sidebar = is_active_sidebar( 'irk-sidebar-post' ) && array_key_exists( 'post', $sidebar );
?>
<?php get_header(); ?>
<?php get_template_part( 'partials/main-header' ); ?>
    <main id="main">
        <div class="container">
            <div class="row">
	            <?php $active_sidebar ? get_sidebar( 'post' ) : null; ?>
                <div class="post-container col-12 <?php echo $active_sidebar ? 'col-lg-9' : ''; ?>">
					<?php irk_breadcrumbs(); ?>
					<?php if ( have_posts() ): ?>
						<?php while ( have_posts() ): ?>
							<?php
							the_post();
							$post_id = get_the_ID();
							?>
                            <article <?php post_class( 'post-inner' ); ?>>
                                <header class="post-header">
                                    <h1 class="post-title"><?php the_title(); ?></h1>
                                    <div class="post-meta clearfix">
										<?php if ( $options->get_option( 'post-single-author' ) ): ?>
                                            <span class="post-author"><?php echo get_avatar( get_the_author_meta( 'user_email' ), 32 ); ?><?php echo get_the_author(); ?></span>
										<?php endif; ?>
										<?php if ( $options->get_option( 'post-single-date' ) ): ?>
                                            <span class="post-date"><?php echo get_the_date( get_option( 'date_format' ) ); ?></span>
										<?php endif; ?>
										<?php if ( $options->get_option( 'post-single-favorites' ) ): ?>
                                            <a href="#" class="favorites <?php echo IRK_Favorites_Manager::is_favorite( $user_id, $post_id ) ? 'active' : ''; ?>" data-pid="<?php echo $post_id; ?>" title="<?php echo esc_attr( $labels->get_label( 'add-favorites' ) ); ?>"></a>
										<?php endif; ?>
                                    </div>
                                </header>
                                <div class="post-body">
									<?php if ( $options->get_option( 'post-single-image' ) ): ?>
                                        <div class="post-image"><?php the_post_thumbnail(); ?></div>
									<?php endif; ?>
									<?php the_content(); ?>
									<?php if ( $options->get_option( 'post-single-share' ) ): ?>
                                        <div class="post-share clearfix">
                                            <span class="comments-count"><?php echo number_format( get_comments_number( get_the_ID() ) ); ?></span>
                                            <ul class="share-buttons">
                                                <li>
                                                    <a href="https://twitter.com/intent/tweet?url=<?php the_permalink(); ?>" class="twitter" rel="nofollow" target="_blank"></a>
                                                </li>
                                                <li>
                                                    <a href="https://www.facebook.com/sharer/sharer.php?m2w&s=100&p[url]=<?php the_permalink(); ?>" class="facebook" rel="nofollow" target="_blank"></a>
                                                </li>
                                                <li>
                                                    <a href="https://wa.me/?text=<?php the_permalink(); ?>" class="whatsapp" rel="nofollow" target="_blank"></a>
                                                </li>
                                                <li>
                                                    <a href="https://telegram.me/share/url?url=<?php the_permalink(); ?>" class="telegram" rel="nofollow" target="_blank"></a>
                                                </li>
                                                <li>
                                                    <a href="#" class="copy-url" data-url="<?php echo wp_get_shortlink(); ?>" title="<?php echo esc_html( $labels->get_label( 'copy-url' ) ) ?>" rel="nofollow"></a>
                                                </li>
                                            </ul>
                                        </div>
									<?php endif; ?>
                                    <?php
                                    if ($options->get_option('post-single-tags')) {
                                        switch ($post_type) {
                                            default:
                                            case 'post':
                                                if (has_tag()) {
                                                    echo '<div class="post-tags">';
                                                    the_tags('', '');
                                                    echo '</div>';
                                                }
                                                break;
                                            case 'blog':
                                                $tags = irk_get_the_terms($post->ID, 'blog_tag');
                                                if ($tags) {
                                                    echo '<div class="post-tags">'.$tags.'</div>';
                                                }
                                                break;
                                            case 'news':
                                                $tags = irk_get_the_terms($post->ID, 'news_tag');
                                                if ($tags) {
                                                    echo '<div class="post-tags">'.$tags.'</div>';
                                                }
                                                break;
                                        }
                                    }
                                    ?>
                                </div>
                            </article>
							<?php if ( comments_open( get_the_ID() ) ): ?>
                                <div class="comments-template">
                                    <header class="template-header">
                                        <strong><?php echo esc_html( $labels->get_label( 'post-comments' ) ); ?></strong>
                                    </header>
									<?php comments_template( '', true ); ?>
                                </div>
							<?php endif; ?>
						<?php endwhile; ?>
					<?php endif; ?>
                </div>
            </div>
        </div>
    </main>
<?php
get_template_part( 'partials/main-footer' );
get_footer();