<?php

$id = "$block[id]";
if(!empty($block['anchor'])) {
	$id = $block['anchor'];
}

// date_default_timezone_set( 'America/Los_Angeles' );

$now = new DateTime( 'now', new DateTimeZone( 'America/Los_Angeles' ) );
$now = $now->sub( new DateInterval( 'PT60M' ) );

?>
<div id="<?php echo $id; ?>" class="bw-date-links-block">
	<ul>
		<?php while ( have_rows( 'items' ) ) : the_row(); ?>
			<?php 
				$datetime = new DateTime( get_sub_field( 'datetime' ), new DateTimeZone( 'America/Los_Angeles' ) );
				$datestring = $datetime->format( 'D, F j - g:ia' );
				$link_text = get_sub_field( 'text' );
				$link_url = get_sub_field( 'link' );
			?>
			<?php if ( $now < $datetime ) : ?>
				<li>
					<?php if ( ! empty( $link_url ) ) : ?>
						<a href="<?php echo $link_url; ?>">
							<?php echo ! empty( $link_text ) ? "$datestring - $link_text" : $datestring; ?>
						</a>
					<?php else: ?>
						<?php echo ! empty( $link_text ) ? "$datestring - $link_text" : $datestring; ?>
					<?php endif; ?>
				</li>
			<?php endif; ?>
		<?php endwhile ?>
	</ul>
</div>
