
<?php
	$current_id = get_the_ID();

	$prev_post = get_posts([
		'post_type'      => 'podcasty',
		'posts_per_page' => 1,
		'orderby'        => 'date',
		'order'          => 'DESC',
		'date_query'     => [
			['before' => get_the_date('Y-m-d H:i:s', $current_id)]
		],
	]);

	$next_post = get_posts([
		'post_type'      => 'podcasty',
		'posts_per_page' => 1,
		'orderby'        => 'date',
		'order'          => 'ASC',
		'date_query'     => [
			['after' => get_the_date('Y-m-d H:i:s', $current_id)]
		],
	]);

	$time = get_field('time');
	$links = get_field('links');
	$iframe = get_field('iframe');
?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?> type="podcast">
	<div class="a-box-1">
		<div class="box-bg">
			<img src="/wp-content/uploads/2025/10/Frame-364.png" alt="">
		</div>

		<div class="a-row a-row-1">
			<div class="a-col-1">
				<ol>
					<li>
						<a href="<?php echo get_permalink(125); ?>" class="btn-2">
							<img src="/wp-content/uploads/2025/10/ArrowBendUpLeft-1.svg" alt="">
							<span>Wszystkie odcinki</span>
						</a>
					</li>
					<?php if (!empty($time)): ?>
					<li>
						<span>Czas trwania: <?php echo $time; ?></span>
					</li>
					<?php endif; ?>
					<li>
						<span><?php echo get_the_date('j F Y'); ?></span>
					</li>
				</ol>

				<div class="a-box-title">
					<h1><?php the_title(); ?></h1>
				</div>
				<div class="a-box-text">
					<?php the_content(); ?>
				</div>
			</div>
			<div class="a-col-2">
				<div class="box-img">
					<?php the_post_thumbnail('full', ['alt' => get_the_title()]); ?>
				</div>
			</div>
		</div>
		<div class="a-row a-row-2">
			<div class="a-col-1">
				<nav>
					<?php if (!empty($links)): ?>
					<ul>
						<?php foreach ($links as $link) : ?>
							<?php
								$icon_color = $link['icon_color'] ?? '';
								$btn_color  = $link['btn_color'] ?? '';
							?>
						<li>
							<a href="<?php echo $link['btn']['url']; ?>" class="btn-social" style="background-color: <?php echo $btn_color; ?>;">
								<div class="btn-icon">
									<span style="color: <?php echo $icon_color; ?>;" class="dashicons <?php echo esc_attr($link['icon']); ?>"></span>
								</div>
								<span>
									<?php echo $link['btn']['title']; ?>
								</span>
							</a>
						</li>
						<?php endforeach; ?>
					</ul>
					<?php endif; ?>
				</nav>
			</div>
		</div>
	</div>

	<div class="a-box-2">
		<div class="a-row a-row-1">
			<?php if (!empty($iframe)) {
				echo $iframe;
			}?>
		</div>
		<div class="a-row a-row-2">
			<ol>
				<?php if (!empty($prev_post)): ?>
				<li>
					<a href="<?php echo get_permalink($prev_post[0]->ID); ?>" class="btn-2">
						<div class="btn-icon">
							<img src="/wp-content/uploads/2025/10/ArrowLeft.svg" alt="">
						</div>
						<span>Poprzedni odcinek</span>
					</a>
				</li>
				<?php endif; ?>

				<li>
					<a href="<?php echo get_permalink(125); ?>" class="btn-2">
						<span>Wszystkie odcinki</span>
					</a>
				</li>

				<?php if (!empty($next_post)): ?>
				<li>
					<a href="<?php echo get_permalink($next_post[0]->ID); ?>" class="btn-2">
						<span>Następny odcinek</span>
						<div class="btn-icon">
							<img src="/wp-content/uploads/2025/10/ArrowRight-1.svg" alt="">
						</div>
					</a>
				</li>
				<?php endif; ?>
			</ol>
		</div>
	</div>
</article>