<?php
/**
 * Echo the posts loop structural markup. It also calls the loop action hooks.
 *
 * @package SplendorStudio\Framework\Templates\Structure
 *
 * @since   1.0.0
 */

/**
 * Fires before the loop.
 *
 * This hook fires even if no post exists.
 *
 * @since 1.0.0
 */
do_action( 'fancify_lite_before_loop' );

	// phpcs:disable Generic.WhiteSpace.ScopeIndent -- Code structure mirrors HTML markup.
	if ( have_posts() && ! is_404() ):

		/**
		 * Fires before posts loop.
		 *
		 * This hook fires if posts exist.
		 *
		 * @since 1.0.0
		 */
		do_action('fancify_lite_before_posts_loop');

		while ( have_posts() ):

			the_post();

			// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Variable called in a function scope.
			$fancify_lite_article_attributes = array(
				'id'        => esc_attr( get_the_ID() ),
				'class'     => implode( ' ', get_post_class( array( 'fancify-article', ( current_theme_supports( 'fancify-default-styling' ) ? esc_attr( 'fancify-panel-box' ) : null ) ) ) ),
				'itemscope' => 'itemscope',
				'itemtype'  => 'https://schema.org/',
			);

			// Blog specifc attributes.
			if ( 'post' === get_post_type() ) {

				$fancify_lite_article_attributes['itemtype'] = 'https://schema.org/BlogPosting';

				// Only add to blogPost attribute to the main query.
				if ( is_main_query() && ! is_search() ) {
					$fancify_lite_article_attributes['itemprop'] = 'blogPost';
				}
			}
			// phpcs:enable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound

			fancify_lite_open_markup_e( 'fancify_lite_post', 'article', $fancify_lite_article_attributes );

				fancify_lite_open_markup_e( 'fancify_lite_post_header', 'header' );

					/**
					 * Fires in the post header.
					 *
					 * @since 1.0.0
					 */
					do_action( 'fancify_lite_post_header' );

				fancify_lite_close_markup_e( 'fancify_lite_post_header', 'header' );

				fancify_lite_open_markup_e( 'fancify_lite_post_body', 'div', array( 'itemprop' => 'articleBody' ) );

					/**
					 * Fires in the post body.
					 *
					 * @since 1.0.0
					 */
					do_action( 'fancify_lite_post_body' );

				fancify_lite_close_markup_e( 'fancify_lite_post_body', 'div' );

			fancify_lite_close_markup_e( 'fancify_lite_post', 'article' );
		endwhile;

		/**
		 * Fires after the posts loop.
		 *
		 * This hook fires if posts exist.
		 *
		 * @since 1.0.0
		 */
		do_action('fancify_lite_after_posts_loop');

	else:

		/**
		 * Fires if no posts exist.
		 *
		 * @since 1.0.0
		 */
		do_action('fancify_lite_no_post');
	endif;

/**
 * Fires after the loop.
 *
 * This hook fires even if no post exists.
 *
 * @since 1.0.0
 */
do_action( 'fancify_lite_after_loop' );
// phpcs:enable Generic.WhiteSpace.ScopeIndent -- Code structure mirrors HTML markup.