<?php
/**
 * Output of the single team players.
 *
 * @package cyberpress/templates
 */

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

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

$team         = cyberpress()->get_the_team();
$team_players = $team->get_players();

if ( $team_players && ! empty( $team_players ) ) {
    ?>
    <h3><?php echo esc_html__( 'Players', 'cyberpress' ); ?></h3>

    <?php
    $table_headings = array(
        'thumbnail' => array(
            'class' => 'cyberpress-table-item-small',
            'label' => '',
        ),
        'nickname'  => __( 'Nickname', 'cyberpress' ),
        'name'      => __( 'Name', 'cyberpress' ),
        'role'      => __( 'Role', 'cyberpress' ),
        'gender'    => __( 'Gender', 'cyberpress' ),
        'age'       => __( 'Age', 'cyberpress' ),
    );

    $table_items = array();

    foreach ( $team_players as $player ) {
        $player_role = $player['role'];
        $player      = $player['data'];
        $thumbnail   = $player->get_thumbnail(
            'thumbnail',
            array(
                'class' => 'cyberpress-team-players-thumb',
            )
        );

        $table_items[] = array(
            'thumbnail' => $thumbnail ? ( '
                <a href="' . esc_url( $player->get_url() ) . '">
                    ' . wp_kses( $thumbnail, cyberpress()->get_kses_allowed_img() ) . '
                </a>
            ' ) : '',
            'nickname'  => $player->get_title() ? ( '<a href="' . esc_url( $player->get_url() ) . '">' . esc_html( $player->get_title() ) . '</a>' ) : '',
            'name'      => esc_html( $player->get_full_name() ),
            'role'      => esc_html( $player_role ),
            'gender'    => esc_html( $player->get_gender() ),
            'age'       => esc_html( $player->get_age() ),
        );
    }

    CyberPress_Template_Parts::get_template(
        'global/table.php',
        array(
            'table_class'    => 'cyberpress-team-players',
            'table_headings' => $table_headings,
            'table_items'    => $table_items,
        )
    );
}
