<?php
/**
 * Shared maintenance page content.
 *
 * @package MacaHold
 *
 * @var array<string, mixed>            $maca_hold_settings
 * @var string                          $maca_hold_title
 * @var string                          $maca_hold_subtitle
 * @var string                          $maca_hold_message
 * @var string                          $maca_hold_logo_url
 * @var string                          $maca_hold_logo_alt
 * @var string                          $maca_hold_badge_text
 * @var string                          $maca_hold_countdown_label
 * @var string                          $maca_hold_footer_text
 * @var array<int, array<string, mixed>> $maca_hold_links
 * @var bool                            $maca_hold_has_bg_image
 * @var int|null                        $maca_hold_countdown_target
 * @var string                          $maca_hold_background_image_url
 * @var string                          $maca_hold_template_slug
 */

defined( 'ABSPATH' ) || exit;

$maca_hold_content_class = $maca_hold_has_bg_image ? 'maca-hold-content maca-hold-content--on-image' : 'maca-hold-card';
$maca_hold_shell_class   = 'maca-hold-shell';

if ( $maca_hold_has_bg_image ) {
	$maca_hold_shell_class .= ' maca-hold-shell-on-image';
} elseif ( 'minimal' === ( $maca_hold_template_slug ?? '' ) ) {
	$maca_hold_shell_class .= ' maca-hold-shell-minimal';
}

$maca_hold_logo_alt_text = '' !== trim( (string) $maca_hold_logo_alt ) ? $maca_hold_logo_alt : __( 'Logo', 'maca-hold' );
?>
<main class="<?php echo esc_attr( $maca_hold_shell_class ); ?>">
	<div class="<?php echo esc_attr( $maca_hold_content_class ); ?>">
		<?php if ( ! empty( $maca_hold_logo_url ) ) : ?>
			<img class="maca-hold-logo" src="<?php echo esc_url( $maca_hold_logo_url ); ?>" alt="<?php echo esc_attr( $maca_hold_logo_alt_text ); ?>" />
		<?php endif; ?>

		<?php if ( '' !== $maca_hold_badge_text ) : ?>
			<p class="maca-hold-badge"><?php echo esc_html( $maca_hold_badge_text ); ?></p>
		<?php endif; ?>

		<h1><?php echo esc_html( $maca_hold_title ); ?></h1>

		<?php if ( '' !== trim( (string) $maca_hold_subtitle ) ) : ?>
			<p class="maca-hold-subtitle"><?php echo esc_html( $maca_hold_subtitle ); ?></p>
		<?php endif; ?>

		<div class="maca-hold-message"><?php echo wp_kses_post( wpautop( $maca_hold_message ) ); ?></div>

		<?php if ( ! empty( $maca_hold_links ) ) : ?>
			<nav class="maca-hold-links" aria-label="<?php echo esc_attr__( 'Useful links', 'maca-hold' ); ?>">
				<?php foreach ( $maca_hold_links as $maca_hold_link ) : ?>
					<a
						class="maca-hold-link"
						href="<?php echo esc_url( $maca_hold_link['url'] ); ?>"
						<?php echo ! empty( $maca_hold_link['new_tab'] ) ? 'target="_blank" rel="noopener noreferrer"' : ''; ?>
					>
						<?php echo esc_html( $maca_hold_link['label'] ); ?>
					</a>
				<?php endforeach; ?>
			</nav>
		<?php endif; ?>

		<?php
		/**
		 * Fires after maintenance page links. Add-ons may output social links or extras.
		 *
		 * @param array<int, array<string, mixed>> $links    Sanitized link rows.
		 * @param array<string, mixed>            $settings Plugin settings from the renderer.
		 */
		do_action( 'maca_hold_after_links', $maca_hold_links, $maca_hold_settings );
		?>

		<?php if ( ! empty( $maca_hold_countdown_target ) ) : ?>
			<div class="maca-hold-countdown<?php echo $maca_hold_has_bg_image ? ' maca-hold-countdown--on-image' : ''; ?>" data-countdown-target="<?php echo esc_attr( (string) $maca_hold_countdown_target ); ?>">
				<span class="maca-hold-countdown-label"><?php echo esc_html( $maca_hold_countdown_label ); ?></span>
				<strong class="maca-hold-countdown-value"></strong>
			</div>
		<?php endif; ?>

		<?php if ( '' !== trim( wp_strip_all_tags( (string) $maca_hold_footer_text ) ) ) : ?>
			<div class="maca-hold-footer"><?php echo wp_kses_post( wpautop( $maca_hold_footer_text ) ); ?></div>
		<?php endif; ?>
	</div>
</main>
