<?php

/**
 * Template part for displaying Video Format
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package Interactive Education
 */

?>

<article id="post-<?php the_ID(); ?>" <?php post_class() ?> >

	<?php
		// Get the post ID
		$interactive_education_post_id = get_the_ID();

		// Check if there are videos embedded in the post content
		$interactive_education_post = get_post($interactive_education_post_id);
		$interactive_education_content = do_shortcode(apply_filters('the_content', $interactive_education_post->post_content));
		$interactive_education_embeds = get_media_embedded_in_content($interactive_education_content);

		if (!empty($interactive_education_embeds)) {
			// Loop through embedded media and display videos
			foreach ($interactive_education_embeds as $interactive_education_embed) {
				// Check if the embed code contains a video tag or specific video providers like YouTube or Vimeo
				if (strpos($interactive_education_embed, 'video') !== false || strpos($interactive_education_embed, 'youtube') !== false || strpos($interactive_education_embed, 'vimeo') !== false || strpos($interactive_education_embed, 'dailymotion') !== false || strpos($interactive_education_embed, 'vine') !== false || strpos($interactive_education_embed, 'wordPress.tv') !== false || strpos($interactive_education_embed, 'hulu') !== false) {
					?>
					<div class="custom-embedded-video">
						<div class="video-container">
							<?php echo $interactive_education_embed; ?>
						</div>
						<div class="video-comments">
							<?php
							// Add your comments section here
							comments_template(); // This will include the default WordPress comments template
							?>
						</div>
					</div>
					<?php
				}
			}
		}
	?>

	<div class="entry-content">
		<header class="entry-header">
			<?php 
				interactive_education_entry_header();
				the_title( '<h3 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h3>' );
			?>
		</header>

		<div class="entry-meta">
			<?php interactive_education_post_meta(); ?>
		</div>
		
		<div class="entry-text">
			<?php
				$interactive_education_excerpt_limit = get_theme_mod('interactive_education_excerpt_limit', 50);
				echo "<p>" . wp_trim_words(get_the_excerpt(), $interactive_education_excerpt_limit) . "</p>";
			?>
		</div>

		<?php interactive_education_edit_link(); ?>

	</div>
	
</article>