<?php
/**
 * The resource single item template file.
 *
 * @package kadence
 */

namespace Kadence;

get_header();

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

kadence()->print_styles( 'kadence-content' );
/**
 * Hook for everything, makes for better elementor theming support.
 */
$types = get_the_terms(get_the_ID(), 'resource_type');
if (is_array($types) && !empty($types)) {
	$types = array_map(function ($term) {
		$link = get_term_link($term);
		if (is_wp_error($link)) return '';
		return '<li><a href="' . esc_url($link) . '">' . esc_html($term->name) . '</a></li>';
	}, $types);
	$types = implode('', $types);
	$types = "<ul>$types</ul>";
} else {
	$types = '';
}

$sets = get_the_terms(get_the_ID(), 'set');
if (is_array($sets) && !empty($sets)) {
	$sets = array_map(function ($term) {
		$link = get_term_link($term);
		if (is_wp_error($link)) return '';
		return '<li><a href="' . esc_url($link) . '">' . esc_html($term->name) . '</a></li>';
	}, $sets);
	$sets = implode('', $sets);
	$sets = "<span>&gt;</span><ul>$sets</ul>";
} else {
	$sets = '';
}

?>
<div id="primary" class="content-area">
	<div class="content-container site-container">
		<main id="main" class="site-main" role="main">
			<div class="content-wrap">
				<article id="post-<?php the_ID(); ?>" <?php post_class( 'entry content-bg single-entry bw-resource-single-entry' ); ?>>
					<div class="entry-content-wrap">
						<header class="bw-resource-header">
							<?php if (has_post_thumbnail()) : ?>
								<div class="bw-resource-image">
									<?php if ( kadence()->show_feature_above() ) the_post_thumbnail( array(183, 183) ); ?>
								</div>
							<? endif; ?>
							<div class="bw-title-column">
								<div class="bw-resource-tax">
									<?php echo $types ?>
									<?php echo $sets ?>
								</div>
								<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
							</div>
						</header>
						<div class="entry-content single-content">
							<div class="bw-media-list">
								<?php get_template_part( 'template-parts/resource-content/entry_media', get_post_type() ); ?>
							</div>
							<?php get_template_part( 'template-parts/content/entry_content', get_post_type() ); ?>
						</div>
						<footer>
							<?php do_action( 'kadence_header_social' ); ?>
							<?php get_template_part( 'template-parts/resource-content/entry_tags', get_post_type() ); ?>
						</footer>
					</div>
				</article><!-- #post-<?php the_ID(); ?> -->
			</div>
		</main><!-- #main -->
		<?php
		get_sidebar();
		?>
	</div>
</div>


<?php
if ( is_singular( get_post_type() ) ) {
	// Show comments only when the post type supports it and when comments are open or at least one comment exists.
	if ( kadence()->show_comments() ) {
		comments_template();
	}
}


get_footer();

