<?php
/**
 * Single entry template - tournament items.
 *
 * @var $attributes - block or archive attributes
 *
 * @package cyberpress/templates
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound

$tournament       = cyberpress()->get_the_tournament();
$url              = $tournament->get_url();
$tournament_title = $tournament->get_title();
$game             = $tournament->get_game();
$total_prize_pool = $tournament->get_total_prize_pool();
$time_start       = $tournament->get_time_start_formatted();
$time_end         = $tournament->get_time_end_formatted();

?>

<?php do_action( 'cyberpress_tournaments_before_loop', $attributes ); ?>

<li id="post-<?php echo esc_attr( $tournament->get_id() ); ?>" <?php $tournament->tournament_classes( 'cyberpress-col cyberpress-tournament' ); ?>>

    <?php do_action( 'cyberpress_tournaments_before_title', $attributes ); ?>

    <?php if ( $tournament_title && $attributes['displayMetaTitle'] ) : ?>
        <h2 class="cyberpress-tournament-title">
            <a href="<?php echo esc_url( $url ); ?>">
                <?php echo esc_html( $tournament_title ); ?>
            </a>
        </h2>
    <?php endif; ?>

    <?php do_action( 'cyberpress_tournaments_after_title', $attributes ); ?>

    <?php do_action( 'cyberpress_tournaments_before_info', $attributes ); ?>

    <?php if ( ( $time_start && $attributes['displayMetaDate'] ) || ( $game && $attributes['displayMetaGame'] ) || ( $total_prize_pool && $attributes['displayMetaTotalPrizePool'] ) ) : ?>
        <ul class="cyberpress-tournament-info">
            <?php if ( $time_start && $attributes['displayMetaDate'] ) : ?>
                <li>
                    <?php
                    echo wp_kses(
                        // translators: %1s - start date, %2s - end date.
                        sprintf( __( '<strong>Dates</strong>: %1$1s %2$2s', 'cyberpress' ), esc_html( $time_start ), $time_end ? '- ' . esc_html( $time_end ) : '' ),
                        array(
                            'strong' => array(),
                        )
                    );
                    ?>
                </li>
            <?php endif; ?>
            <?php if ( $game && $attributes['displayMetaGame'] ) : ?>
                <li>
                    <?php
                    echo wp_kses_post(
                        sprintf(
                            // translators: %1$s - game url, %2$s - game title.
                            __( '<strong>Game</strong>: <a href="%1$s" class="cyberpress-game-inline-link">%2$s</a>', 'cyberpress' ),
                            esc_url( $game->get_url() ),
                            $game->get_thumbnail() . ' ' . esc_html( $game->get_title() )
                        )
                    );
                    ?>
                </li>
            <?php endif; ?>
            <?php if ( $total_prize_pool && $attributes['displayMetaTotalPrizePool'] ) : ?>
                <li>
                    <?php
                    echo wp_kses(
                        // translators: %s total prize pool.
                        sprintf( __( '<strong>Total Prize pool</strong>: %s', 'cyberpress' ), esc_html( $total_prize_pool ) ),
                        array(
                            'strong' => array(),
                        )
                    );
                    ?>
                </li>
            <?php endif; ?>
        </ul>
    <?php endif; ?>

    <?php do_action( 'cyberpress_tournaments_after_info', $attributes ); ?>

</li><!-- #post-## -->

<?php do_action( 'cyberpress_tournaments_after_loop', $attributes ); ?>
