<?php
/**
 * Template part for displaying portfolio content in archive-portfolio.php
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package Portfolio_One
 */
$tags       = get_the_terms(get_the_ID(), 'post_tag');
$terms 		= wp_get_post_terms(get_the_ID(), 'portfolio_categories');
?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    
    <div class="img-wrapp cww-img-hover">
	    <?php portfolio_one_post_thumbnail(); ?>
    </div>

	<div class="entry-content">

		<div class="pfolio-cat">
			<?php if ( $terms && !is_wp_error( $terms ) ) : 
					$term = $terms[0];
					while ($term->parent != 0) {
						$term = get_term($term->parent, 'portfolio_categories');
					}
					echo esc_html($term->name);
			endif; ?>
		</div>

        <header class="entry-header">
			<a href="<?php the_permalink()?>">
            <?php the_title( '<h2 class="entry-title">', '</h2>' ); ?>
			</a>
        </header>

		
		<?php
		the_excerpt();

		if (!empty($tags) && !is_wp_error($tags)) {
			echo '<ul>';
			foreach ($tags as $tag) {
				echo '<li>';
				echo '<a href="' . esc_url(get_term_link($tag)) . '">'
					. esc_html($tag->name) .
				'</a> ';
				echo '</li>';
			}
			echo '</ul>';
        } ?>

		<div class="pfolio-btn">
			<a href="<?php the_permalink(); ?>" class="pfolio-link">
				<?php esc_html_e('View Case Study','portfolio-one'); ?>
				<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-arrow-up-right w-5 h-5 transform group-hover/link:translate-x-1 group-hover/link:-translate-y-1 transition-transform duration-300" aria-hidden="true"><path d="M7 7h10v10"></path><path d="M7 17 17 7"></path></svg>
			</a>
        </div>
		<?php 
		wp_link_pages(
			array(
				'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'portfolio-one' ),
				'after'  => '</div>',
			)
		);
		?>
	</div>

</article>
