<?php
/**
 * theme Hook class
 * */
if ( ! defined( 'ABSPATH' ) ) {
	exit(); //exit if access directly
}

if ( ! class_exists( 'Nextpage_blog_hook' ) ) {

	class Nextpage_blog_hook {

		public $nextpageTag;

		public $nextpageFunctions;

		private static $instance;

		public function __construct() {

			//Tags class init
			$this->nextpageTag = Nextpage_Function( 'Tags' );

			$this->nextpageFunctions = Nextpage_Function( 'Functions' );

			//display blog meta
			add_action( 'nextpage_single_post_before_content', array( $this, 'single_page_top' ) );

			//tag and social share display from here
			add_action( 'nextpage_after_content_in_single_page', array( $this, 'tag_and_social_share' ) );

			//author bio display from here
			add_action( 'nextpage_after_content_in_single_page', array( $this, 'author_bio' ) );

			//Related post
			add_action( 'nextpage_after_content_in_single_page', array( $this, 'related_post' ) );

			//blog page meta
			add_action( 'nextpage_blog_page_meta', array( $this, 'author_meta' ) );

			add_action( 'nextpage_blog_page_meta', array( $this, 'posted_on' ) );

			add_action( 'nextpage_blog_page_meta', array( $this, 'category' ) );

			add_action( 'nextpage_blog_page_meta', array( $this, 'comment_count' ) );

		}


		/**
		 * getInstance();
		 * @since 1.0.0
		 * */
		public static function getInstance() {
			if ( null == self::$instance ) {
				self::$instance = new self();
			}

			return self::$instance;
		}


		/**
		 * display blog meta
		 * @since 1.0.0
		 *
		 */
		public function single_page_top() {

			if ( has_post_thumbnail() ) :
				?>
               	<div class="single-post-wrap style-overlay">
	                <?php $this->nextpageTag->post_thumbnail(); ?>
	                <div class="details pb-4">
	                    <div class="post-meta-single mb-2">
	                        <ul>
	                        	<?php 
	                        	$cat = get_the_category();

	                        	 if( isset( $cat[0] ) ):
	                        	 ?>
	                            	<li>
		                            	<a class="tag-base <?php echo esc_attr( $cat[0]->slug ); ?>"
		                            	   href="<?php echo get_category_link($cat[0]->term_id); ?>">
		                            	   <?php echo get_cat_name( $cat[0]->term_id ); ?>
		                            	</a>
	                            	</li>
	                        	<?php endif; ?>
	                            <li><p><?php $this->nextpageTag->posted_on_two(); ?></p></li>
	                            <li><?php $this->nextpageTag->posted_by(); ?></li>
	                        </ul>
	                    </div>
	                     <h5 class="title mt-0"><?php the_title(); ?></h5>
	                </div>
	            </div>

			<?php
			endif;
		}

		/**
		 * tag and social share
		 * @since 1.0.0
		 *
		 */
		public function tag_and_social_share() {
			if ( has_tag() ):
				$class = ( nextpage_get_option( 'social_share', false ) == 1 ? '6' : '12' );
				?>
                <div class="meta">
                    <div class="row">
                        <div class="col-md-<?php echo esc_attr( $class ); ?>">
							<?php $this->nextpageTag->tags(); ?>
                        </div>
						<?php if ( class_exists( 'Nextpage_Core_Init' ) ) :
							nextpage_social_share();
						endif; ?>
                    </div>
                </div>
			<?php
			endif;
		}

		/**
		 * author bio
		 * @since 1.0.0
		 *
		 */
		public function author_bio() {
			$nextpage_avatar_url = get_avatar_url( get_the_author_meta( 'ID' ), array( 'size' => 135 ) );
			?>
            <div class="author-area">
                <div class="media">
                    <img src="<?php echo esc_url( $nextpage_avatar_url ); ?>" alt="<?php the_title(); ?>">
                    <div class="media-body align-self-center">
                        <h4><?php the_author(); ?></h4>
                        <p><?php the_author_meta( 'description' ); ?></p>
                    </div>
                </div>
            </div>
			<?php
		}

		/**
		 * author name
		 * @since 1.0.0
		 *
		 */
		public function author_meta() {
			if ( nextpage_get_option( 'blog_author_enable', 1 ) ):
				$this->nextpageTag->posted_by(); //author name
			endif;
		}

		/**
		 * post date
		 * @since 1.0.0
		 *
		 */
		public function posted_on() {
			if ( nextpage_get_option( 'blog_date_enable', 1 ) ):
				$this->nextpageTag->posted_on(); //post date
			endif;
		}

		/**
		 * post date
		 * @since 1.0.0
		 *
		 */
		public function category() {
			if ( nextpage_get_option( 'blog_category_enable', 1 ) ):
				?>
                <span><i class="fa fa-folder-open"></i><?php the_category( ', ' ); ?></span>

			<?php endif;
		}

		/**
		 * Comment count
		 * @since 1.0.0
		 *
		 */
		public function comment_count() {
			if ( nextpage_get_option( 'blog_commnet_enable', 1 ) ):
				?>
                <span class="comments">
                <i class="fa fa-comments"></i>
                <?php comments_popup_link(); ?>
            </span>

			<?php endif;
		}

		/**
		 * related post
		 * @since 1.0.0
		 *
		 */
		public function related_post() {
			if ( class_exists( 'Nextpage_Core_Init' ) ) :
				nextpage_related_post();
			endif;
		}


	} //end class

	Nextpage_blog_hook::getInstance();


} //endif