<?php
/**
 * Template Name: Recipe Article
 * Template Post Type: post
 *
 * @package HaPantheon
 */

get_header();
while ( have_posts() ) :
	the_post();
	$prep       = get_post_meta( get_the_ID(), '_hapantheon_recipe_prep', true );
	$wait       = get_post_meta( get_the_ID(), '_hapantheon_recipe_wait', true );
	$yield      = get_post_meta( get_the_ID(), '_hapantheon_recipe_yield', true );
	$difficulty = get_post_meta( get_the_ID(), '_hapantheon_recipe_difficulty', true );
	$tests      = get_post_meta( get_the_ID(), '_hapantheon_recipe_tests', true );
	$video_id   = get_post_meta( get_the_ID(), '_hapantheon_recipe_video_id', true );
	$content    = apply_filters( 'the_content', get_the_content() );
	if ( $video_id ) {
		$content = preg_replace( '/data-yt=("|\')[^"\']*("|\')/i', 'data-yt="' . esc_attr( $video_id ) . '"', $content, 1 );
	}
	?>
	<article id="post-<?php the_ID(); ?>" <?php post_class( 'recipe-article-template' ); ?>>
		<header class="art-hero wrap">
			<span class="eyebrow"><?php echo esc_html( hapantheon_category_label() ); ?></span>
			<h1><?php the_title(); ?></h1>
			<?php hapantheon_post_meta_row( false ); ?>
			<div class="rmeta rv">
				<div class="rm"><?php echo hapantheon_icon( 'clock' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?><b><?php echo esc_html( $prep ? $prep : __( '15 דקות', 'hapantheon' ) ); ?></b><small><?php esc_html_e( 'הכנה', 'hapantheon' ); ?></small></div>
				<div class="rm"><?php echo hapantheon_icon( 'hourglass' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?><b><?php echo esc_html( $wait ? $wait : __( '18 שעות', 'hapantheon' ) ); ?></b><small><?php esc_html_e( 'המתנה', 'hapantheon' ); ?></small></div>
				<div class="rm"><?php echo hapantheon_icon( 'glass' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?><b><?php echo esc_html( $yield ? $yield : __( '4 מנות', 'hapantheon' ) ); ?></b><small><?php esc_html_e( 'כמות', 'hapantheon' ); ?></small></div>
				<div class="rm"><?php echo hapantheon_icon( 'star' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?><b><?php echo esc_html( $difficulty ? $difficulty : __( 'קל', 'hapantheon' ) ); ?></b><small><?php esc_html_e( 'דרגת קושי', 'hapantheon' ); ?></small></div>
			</div>
		</header>

		<div class="wrap recipe-feature-wrap">
			<figure class="mframe art-frame rv">
				<img decoding="async" src="<?php echo esc_url( hapantheon_featured_image_url( get_the_ID(), 'hapantheon-hero' ) ); ?>" alt="<?php echo esc_attr( get_the_title() ); ?>">
				<?php if ( $tests ) : ?><span class="tag"><?php echo esc_html( $tests ); ?></span><?php endif; ?>
			</figure>
		</div>

		<div class="recipe-content">
			<?php echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
		</div>

		<div class="wrap art-body recipe-after">
			<?php hapantheon_share_row(); ?>
			<?php hapantheon_author_box(); ?>
			<?php hapantheon_adjacent_navigation(); ?>
		</div>
	</article>
	<?php
	hapantheon_related_posts();
	hapantheon_post_newsletter();
	if ( comments_open() || get_comments_number() ) {
		comments_template();
	}
endwhile;
get_footer();
