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

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

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

$player           = cyberpress()->get_the_player();
$thumbnail_size   = CyberPress_Settings::get_option( 'players_archive_thumbnail_size', 'cyberpress_players' );
$player_url       = $player->get_url();
$player_title     = $player->get_title();
$player_full_name = $player->get_full_name();
$player_gender    = $player->get_gender();
$player_age       = $player->get_age();
$player_country   = $player->get_country();
?>

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

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

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

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

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

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

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

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

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

    <?php if ( ( $player_full_name && $attributes['displayMetaFullName'] ) || ( $player_gender && $attributes['displayMetaGender'] ) || ( $player_country && $attributes['displayMetaCountry'] ) || ( $player_age && $attributes['displayMetaAge'] ) ) : ?>
        <ul class="cyberpress-player-info">
            <?php if ( $player_full_name && $attributes['displayMetaFullName'] ) : ?>
                <li>
                    <?php
                    echo wp_kses(
                        // translators: %s player name.
                        sprintf( __( '<strong>Name</strong>: %s', 'cyberpress' ), esc_html( $player_full_name ) ),
                        array(
                            'strong' => array(),
                        )
                    );
                    ?>
                </li>
            <?php endif; ?>
            <?php if ( $player_gender && $attributes['displayMetaGender'] ) : ?>
                <li>
                    <?php
                    echo wp_kses(
                        // translators: %s gender.
                        sprintf( __( '<strong>Gender</strong>: %s', 'cyberpress' ), esc_html( $player_gender ) ),
                        array(
                            'strong' => array(),
                        )
                    );
                    ?>
                </li>
            <?php endif; ?>
            <?php if ( $player_country && $player_country['flag'] && $attributes['displayMetaCountry'] ) : ?>
                <li>
                    <?php
                    echo sprintf(
                        // translators: %s country.
                        wp_kses_post( __( '<strong>Country</strong>: %s', 'cyberpress' ) ),
                        wp_kses( $player_country['flag'] . ' ' . $player_country['name'], cyberpress()->get_kses_allowed_img() )
                    );
                    ?>
                </li>
            <?php endif; ?>
            <?php if ( $player_age && $attributes['displayMetaAge'] ) : ?>
                <li>
                    <?php
                    echo wp_kses(
                        // translators: %s player age.
                        sprintf( __( '<strong>Age</strong>: %s years old', 'cyberpress' ), esc_html( $player_age ) ),
                        array(
                            'strong' => array(),
                        )
                    );
                    ?>
                </li>
            <?php endif; ?>
        </ul>
    <?php endif; ?>

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

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

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