<?php

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

?>

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

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

		// Check if there are videos embedded in the post content
		$home_gardening_post = get_post($home_gardening_post_id);
		$home_gardening_content = do_shortcode(apply_filters('the_content', $home_gardening_post->post_content));
		$home_gardening_embeds = get_media_embedded_in_content($home_gardening_content);

		if (!empty($home_gardening_embeds)) {
			// Loop through embedded media and display videos
			foreach ($home_gardening_embeds as $home_gardening_embed) {
				// Check if the embed code contains a video tag or specific video providers like YouTube or Vimeo
				if (strpos($home_gardening_embed, 'video') !== false || strpos($home_gardening_embed, 'youtube') !== false || strpos($home_gardening_embed, 'vimeo') !== false || strpos($home_gardening_embed, 'dailymotion') !== false || strpos($home_gardening_embed, 'vine') !== false || strpos($home_gardening_embed, 'wordPress.tv') !== false || strpos($home_gardening_embed, 'hulu') !== false) {
					?>
					<div class="custom-embedded-video">
						<div class="video-container">
							<?php echo $home_gardening_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 
				home_gardening_entry_header();
				the_title( '<h3 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h3>' );
			?>
		</header>

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

		<?php home_gardening_edit_link(); ?>

	</div>
	
</article>