<?php get_header(); ?>

<main class="site-main">
	<div class="container content-grid">
		<section class="content-area">
			<?php while ( have_posts() ) : the_post(); ?>
				<?php
				$is_rest_termin = (int) get_post_meta( get_the_ID(), '_kgv_is_rest_termin', true );
				$termin_datum   = get_post_meta( get_the_ID(), '_kgv_termin_datum_formatted', true );
				$termin_owner   = get_post_meta( get_the_ID(), '_kgv_termin_owner', true );
				?>

				<article id="post-<?php the_ID(); ?>" <?php post_class( 'post-card single-post' ); ?>>
					<div class="single-post">

						<?php if ( $is_rest_termin ) : ?>
							<div class="kgv-termin-single-header">
								<span class="kgv-termin-badge">Termin</span>
								<h1 class="entry-title"><?php the_title(); ?></h1>

								<div class="kgv-termin-meta-grid">
									<?php if ( ! empty( $termin_datum ) ) : ?>
										<div class="kgv-termin-meta-item">
											<span class="kgv-termin-meta-label">Datum</span>
											<span class="kgv-termin-meta-value"><?php echo esc_html( $termin_datum ); ?></span>
										</div>
									<?php endif; ?>

									<?php if ( ! empty( $termin_owner ) ) : ?>
										<div class="kgv-termin-meta-item">
											<span class="kgv-termin-meta-label">Verantwortlich</span>
											<span class="kgv-termin-meta-value"><?php echo esc_html( $termin_owner ); ?></span>
										</div>
									<?php endif; ?>
								</div>
							</div>

							<div class="entry-content kgv-termin-content">
								<?php the_content(); ?>
							</div>
						<?php else : ?>
							<h1 class="entry-title"><?php the_title(); ?></h1>

							<div class="entry-meta">
								<span><?php echo esc_html( get_the_date() ); ?></span>
								<span>·</span>
								<span><?php the_author(); ?></span>
							</div>

							<?php if ( has_post_thumbnail() ) : ?>
								<div class="featured-image">
									<?php the_post_thumbnail( 'large' ); ?>
								</div>
							<?php endif; ?>

							<div class="entry-content">
								<?php the_content(); ?>
							</div>
						<?php endif; ?>

					</div>
				</article>

				<?php comments_template(); ?>
			<?php endwhile; ?>
		</section>

		<?php get_sidebar(); ?>
	</div>
</main>

<?php get_footer(); ?>