<?php
add_shortcode('bw_events_list', 'bw_events_list_shortcode');
function bw_events_list_shortcode ($atts = array(), $content = null, $tag = '') {
	$atts = array_change_key_case((array) $atts, CASE_LOWER);
	$atts = shortcode_atts(array('past' => false), $atts, $tag);

	$query = array('posts_per_page'=>9);
	if ($atts['past']) $query['eventDisplay'] = 'past';
	$events = tribe_get_events($query);

	ob_start();
	?>
	<div class="wp-block-kadence-iconlist bw-default-iconlist">
		<ul class="kt-svg-icon-list">
			<?php foreach ($events as $event) : setup_postdata($event); ?>
				<?php
					$e = tribe_get_event($event->ID);
					$start_ts_utc = $e->dates->start_utc->getTimestamp();
				?>
				<li class="kt-svg-icon-list-style-default kt-svg-icon-list-item-wrap">
					<div
						style="display:inline-flex;justify-content:center;align-items:center;color:var(--global-palette1)"
						class="kt-svg-icon-list-single kt-svg-icon-list-single-fas_square"
					>
						<svg
							style="display:inline-block;vertical-align:middle"
							viewBox="0 0 448 512"
							height="14"
							width="14"
							fill="currentColor"
							xmlns="http://www.w3.org/2000/svg"
							aria-hidden="true"
						>
							<path d="M400 32H48C21.5 32 0 53.5 0 80v352c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V80c0-26.5-21.5-48-48-48z"></path>
						</svg>
					</div>
					<span class="kt-svg-icon-list-text">
						<a href="<?php the_permalink($event); ?>">
							<span class="bw-list-event-date" data-changetz-timestamp="<?php echo $start_ts_utc; ?>" data-changetz-format="D, M j, Y">
								<?php echo tribe_get_start_date($event->ID, false, 'D, M j, Y'); ?>
							</span>
							<span class="bw-list-event-title">
								<?php echo get_the_title($event); ?>
							</span>
						</a>
					</span>
				</li>
			<?php endforeach; ?>
		</ul>
	</div>
	<?php
	wp_reset_postdata();
	/* registered in /plugins/kadence-blocks/dist/class-kadence-blocks-frontend.php */
	wp_enqueue_style('kadence-blocks-iconlist');
	return ob_get_clean();
}
