<?php
/**
 * Event countdown template.
 *
 * @package Rsmspark_Content_Widgets
 *
 * @var string               $title
 * @var string               $end_date
 * @var string               $end_time
 * @var string               $expired_message
 * @var bool                 $hide_when_expired
 * @var int                  $target_ts
 * @var bool                 $is_expired
 * @var array<string, int>   $units
 * @var string               $static_message
 * @var string               $style_vars
 */

defined( 'ABSPATH' ) || exit;

$classes = array(
	'rsmspark-cw',
	'rsmspark-cw-event-countdown',
);

if ( ! empty( $is_expired ) ) {
	$classes[] = 'rsmspark-cw-event-countdown--expired';
}
?>
<section
	class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>"
	style="<?php echo esc_attr( $style_vars ); ?>"
	data-rsmspark-cw-event-countdown
	data-end-ts="<?php echo esc_attr( (string) (int) $target_ts ); ?>"
	data-expired-message="<?php echo esc_attr( (string) $expired_message ); ?>"
	data-hide-when-expired="<?php echo ! empty( $hide_when_expired ) ? '1' : '0'; ?>"
	aria-live="polite"
>
	<?php if ( ! empty( $title ) ) : ?>
		<h2 class="rsmspark-cw-event-countdown__title"><?php echo esc_html( $title ); ?></h2>
	<?php endif; ?>

	<?php if ( ! empty( $is_expired ) ) : ?>
		<p class="rsmspark-cw-event-countdown__expired"><?php echo esc_html( (string) $expired_message ); ?></p>
	<?php else : ?>
		<?php if ( ! empty( $static_message ) ) : ?>
			<p class="rsmspark-cw-event-countdown__static"><?php echo esc_html( (string) $static_message ); ?></p>
		<?php endif; ?>
		<div class="rsmspark-cw-event-countdown__display" role="timer">
			<span class="rsmspark-cw-event-countdown__unit">
				<span class="rsmspark-cw-event-countdown__value" data-unit="days"><?php echo esc_html( (string) (int) $units['days'] ); ?></span>
				<span class="rsmspark-cw-event-countdown__label"><?php esc_html_e( 'days', 'rsm-content-widgets' ); ?></span>
			</span>
			<span class="rsmspark-cw-event-countdown__unit">
				<span class="rsmspark-cw-event-countdown__value" data-unit="hours"><?php echo esc_html( (string) (int) $units['hours'] ); ?></span>
				<span class="rsmspark-cw-event-countdown__label"><?php esc_html_e( 'hours', 'rsm-content-widgets' ); ?></span>
			</span>
			<span class="rsmspark-cw-event-countdown__unit">
				<span class="rsmspark-cw-event-countdown__value" data-unit="minutes"><?php echo esc_html( (string) (int) $units['minutes'] ); ?></span>
				<span class="rsmspark-cw-event-countdown__label"><?php esc_html_e( 'minutes', 'rsm-content-widgets' ); ?></span>
			</span>
			<span class="rsmspark-cw-event-countdown__unit">
				<span class="rsmspark-cw-event-countdown__value" data-unit="seconds"><?php echo esc_html( (string) (int) $units['seconds'] ); ?></span>
				<span class="rsmspark-cw-event-countdown__label"><?php esc_html_e( 'seconds', 'rsm-content-widgets' ); ?></span>
			</span>
		</div>
	<?php endif; ?>
</section>
