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

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

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

$team           = cyberpress()->get_the_team();
$thumbnail_size = CyberPress_Settings::get_option( 'teams_archive_thumbnail_size', 'cyberpress_teams' );
$team_url       = $team->get_url();
$team_title     = $team->get_title();
$team_country   = $team->get_country_of_foundation();
$team_founded   = $team->get_date_of_foundation_formatted();
$team_game      = $team->get_game();
$team_players   = $team->get_players();
?>

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

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

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

    <?php if ( '' !== $team->check_thumbnail() && $attributes['displayMetaThumbnail'] ) : ?>
        <div class="cyberpress-team-thumbnail">
            <a href="<?php echo esc_url( $team_url ); ?>">
                <?php echo wp_kses( $team->get_thumbnail( $thumbnail_size ), cyberpress()->get_kses_allowed_img() ); ?>
            </a>
        </div><!-- .post-thumbnail -->
    <?php endif; ?>

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

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

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

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

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

    <?php if ( ( $team_country && $attributes['displayMetaCountry'] ) || ( $team_founded && $attributes['displayMetaFoundedDate'] ) || ( $team_game && $attributes['displayMetaGameTitle'] ) || ( $team_players && $attributes['displayMetaCountOfPlayers'] ) ) : ?>
        <ul class="cyberpress-team-info">
            <?php if ( $team_country && $team_country['flag'] && $attributes['displayMetaCountry'] ) : ?>
                <li>
                    <?php
                    echo sprintf(
                        // translators: %s country.
                        wp_kses_post( __( '<strong>Country</strong>: %s', 'cyberpress' ) ),
                        wp_kses( $team_country['flag'] . ' ' . $team_country['name'], cyberpress()->get_kses_allowed_img() )
                    );
                    ?>
                </li>
            <?php endif; ?>
            <?php if ( $team_founded && $attributes['displayMetaFoundedDate'] ) : ?>
                <li>
                    <?php
                    echo wp_kses(
                        // translators: %s foundation date.
                        sprintf( __( '<strong>Founded</strong>: %s', 'cyberpress' ), esc_html( $team_founded ) ),
                        array(
                            'strong' => array(),
                        )
                    );
                    ?>
                </li>
            <?php endif; ?>
            <?php if ( $team_game && $attributes['displayMetaGameTitle'] ) : ?>
                <li>
                    <?php
                    echo wp_kses_post(
                        sprintf(
                            // translators: %1$s - game url, %2$s - game title.
                            __( '<strong>Main Game</strong>: <a href="%1$s" class="cyberpress-game-inline-link">%2$s</a>', 'cyberpress' ),
                            esc_url( $team_game->get_url() ),
                            $team_game->get_thumbnail() . ' ' . esc_html( $team_game->get_title() )
                        )
                    );
                    ?>
                </li>
            <?php endif; ?>
            <?php if ( $attributes['displayMetaCountOfPlayers'] ) : ?>
                <li>
                    <?php
                    echo wp_kses(
                        // translators: %s players count.
                        sprintf( __( '<strong>Players</strong>: %s', 'cyberpress' ), $team_players ? count( $team_players ) : '-' ),
                        array(
                            'strong' => array(),
                        )
                    );
                    ?>
                </li>
            <?php endif; ?>
        </ul>
    <?php endif; ?>

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

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

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