<?php
/**
 * Template part for displaying posts
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package Prime Spa Center
 */
?>
<div class="col-lg-4 col-md-6 my-2">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
	<div id="featured-posts" class="post-item ">
		<?php  
		$prime_spa_center_meta_order = get_theme_mod('prime_spa_center_post_meta_order', array('featured-image', 'heading', 'author', 'content', 'button'));

		foreach ( $prime_spa_center_meta_order as $prime_spa_center_order_item ) :
			if ( 'featured-image' === $prime_spa_center_order_item ) :
				$prime_spa_center_img_setting  = prime_spa_center_get_option( 'prime_spa_center_post_feature_image_setting' );
				if ( $prime_spa_center_img_setting ) : ?>
					<div class="featured-image">
						<?php if ( has_post_thumbnail() ) : ?>
							<?php the_post_thumbnail(); ?>
						<?php else : ?>
							<img src="<?php echo esc_url( get_stylesheet_directory_uri() . '/assets/images/default-header.png' ); ?>">
						<?php endif; ?>
						<a href="<?php the_permalink(); ?>" class="post-thumbnail-link"></a>
						<div class="entry-meta">
							<?php prime_spa_center_posted_on(); ?>
						</div>
					</div>
				<?php endif;
			endif;

			if ( 'heading' === $prime_spa_center_order_item ) :
				$prime_spa_center_title_setting  = prime_spa_center_get_option( 'prime_spa_center_post_title_setting' );
				if ( $prime_spa_center_title_setting ) : ?>
					<header class="entry-header">
						<h2 class="entry-title">
							<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
						</h2>
					</header>
				<?php endif;
			endif;

			if ( 'author' === $prime_spa_center_order_item ) :
				$prime_spa_center_meta_setting  = prime_spa_center_get_option( 'prime_spa_center_post_meta_setting' );
				if ( $prime_spa_center_meta_setting ) : ?>
					<ul class="auther-comment">
						<li>
							<svg width="23" height="23" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
								<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 19a2 2 0 01-2-2V7a2 2 0 012-2h4l2 2h4a2 2 0 012 2v1M5 19h14a2 2 0 002-2v-5a2 2 0 00-2-2H9a2 2 0 00-2 2v5a2 2 0 01-2 2z"></path>
							</svg>
							<a href="<?php echo esc_url(get_author_posts_url( get_the_author_meta( 'ID' ) )); ?>"><?php esc_html_e('By', 'prime-spa-center'); ?> <?php the_author(); ?></a>
						</li>
						<li>
							<a href="javascript:void(0);"><?php echo esc_html(get_comments_number($post->ID)); ?> comment</a>
						</li>
					</ul>
				<?php endif;
			endif;

			if ( 'content' === $prime_spa_center_order_item ) :
				$prime_spa_center_content_setting  = prime_spa_center_get_option( 'prime_spa_center_post_content_setting' );
				if ( $prime_spa_center_content_setting ) : ?>
					<div class="entry-content">
						<?php
							$excerpt_length = prime_spa_center_get_option('excerpt_length');
							echo esc_html( wp_trim_words( get_the_content(), $excerpt_length ) );
						?>
					</div>
				<?php endif;
			endif;

			if ( 'button' === $prime_spa_center_order_item ) :
				$prime_spa_center_button_setting = prime_spa_center_get_option( 'prime_spa_center_post_button_setting' );
				if ( $prime_spa_center_button_setting ) :
					$readmore_text = prime_spa_center_get_option( 'readmore_text' );
					if ( !empty( $readmore_text ) ) : ?>
						<div class="read-more">
							<a href="<?php the_permalink(); ?>"><?php echo esc_html( $readmore_text ); ?> <i class="<?php echo esc_attr( get_theme_mod( 'prime_spa_center_readmore_icon', 'fas fa-arrow-right' ) ); ?>"></i></a>
						</div>
					<?php endif;
				endif;
			endif;

		endforeach; ?>
	</div><!-- .post-item -->
</article><!-- #post-## -->
</div>
