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

get_header();
while ( have_posts() ) :
	the_post();
	$filtered = apply_filters( 'the_content', get_the_content() );
	$prepared = hapantheon_content_with_toc( $filtered );
	?>
	<article id="post-<?php the_ID(); ?>" <?php post_class( 'article-sidebar-template' ); ?>>
		<header class="art-hero wrap compact-article-hero">
			<span class="eyebrow"><?php echo esc_html( hapantheon_category_label() ); ?></span>
			<h1><?php the_title(); ?></h1>
			<?php hapantheon_post_meta_row(); ?>
		</header>

		<div class="wrap art-layout">
			<aside class="art-side">
				<?php if ( ! empty( $prepared['toc'] ) ) : ?>
					<div class="side-box">
						<h4><?php esc_html_e( 'בתוך המגילה', 'hapantheon' ); ?></h4>
						<ul class="toc">
							<?php foreach ( $prepared['toc'] as $index => $toc_item ) : ?>
								<li><a class="<?php echo 0 === $index ? 'on' : ''; ?>" href="#<?php echo esc_attr( $toc_item['id'] ); ?>"><?php echo esc_html( $toc_item['label'] ); ?></a></li>
							<?php endforeach; ?>
						</ul>
					</div>
				<?php endif; ?>

				<div class="side-box side-author">
					<?php echo get_avatar( get_the_author_meta( 'ID' ), 96 ); ?>
					<div><b><?php the_author(); ?></b><small><?php esc_html_e( 'אוצר הארכיון', 'hapantheon' ); ?></small></div>
				</div>

				<div class="side-box">
					<h4><?php esc_html_e( 'שיתוף', 'hapantheon' ); ?></h4>
					<?php hapantheon_share_row( 'side-share' ); ?>
				</div>
			</aside>

			<div>
				<figure class="mframe rv sidebar-feature">
					<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() ); ?>">
				</figure>
				<div class="art-body article-content">
					<?php echo $prepared['content']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
					<?php hapantheon_author_box(); ?>
					<?php hapantheon_adjacent_navigation(); ?>
				</div>
			</div>
		</div>
	</article>
	<?php
	hapantheon_related_posts();
	hapantheon_post_newsletter();
	if ( comments_open() || get_comments_number() ) {
		comments_template();
	}
endwhile;
get_footer();
