<?php
/**
 * Output of the single player teams.
 *
 * @package cyberpress/templates
 */

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

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

$player       = cyberpress()->get_the_player();
$player_teams = $player->get_teams();

if ( $player_teams && ! empty( $player_teams ) ) {
    ?>

    <h3><?php echo esc_html__( 'Teams', 'cyberpress' ); ?></h3>

    <?php
    $table_items = array();

    foreach ( $player_teams as $team ) {
        $start_date = $team['start_date_formatted'];
        $end_date   = $team['end_date_formatted'];
        $team       = $team['data'];
        $thumbnail  = $team->get_thumbnail( 'thumbnail', array( 'class' => 'cyberpress-player-team-thumb' ) );

        $table_items[] = array(
            'thumbnail' => array(
                'class'  => 'cyberpress-table-item-small',
                'output' => $thumbnail ? ( '
                    <a href="' . esc_url( $team->get_url() ) . '">
                        ' . wp_kses( $thumbnail, cyberpress()->get_kses_allowed_img() ) . '
                    </a>
                ' ) : '',
            ),
            'title' => '
                <a href="' . esc_url( $team->get_url() ) . '">
                    ' . esc_html( $team->get_title() ) . '
                </a>
                <div class="cyberpress-player-team-dates">
                    ' . esc_html( $start_date ) . ' - ' . esc_html( $end_date ) . '
                </div>
            ',
        );
    }

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