<?php
/**
 * Partial template for displaying opponent team in player stats table.
 *
 * This template can be overridden by copying it to yourtheme/sports-leagues/player/player-stats-opponent-cell.php.
 *
 * @var object $data - Object with args.
 *
 * @author        Andrei Strekozov <anwp.pro>
 * @package       Sports-Leagues/Templates
 * @since         0.14.0
 *
 * @version       0.14.0
 */

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

$data = (object) wp_parse_args(
	$data,
	[
		'team_opp'       => null,
		'game_permalink' => '',
	]
);

if ( empty( $data->team_opp ) ) {
	return;
}

$team_display_name = '';
if ( ! empty( $data->team_opp->code ) ) {
	$team_display_name = $data->team_opp->code;
} elseif ( ! empty( $data->team_opp->abbr ) ) {
	$team_display_name = $data->team_opp->abbr;
} else {
	$team_display_name = $data->team_opp->title;
}

$has_link = ! empty( $data->game_permalink );
?>

<?php if ( $has_link ) : ?>
	<a href="<?php echo esc_url( $data->game_permalink ); ?>" class="anwp-link-without-effects p-0 m-0 d-flex align-items-center">
		<?php if ( ! empty( $data->team_opp->logo ) ) : ?>
			<div class="team-logo__cover team-logo__cover--small mr-1" style="background-image: url('<?php echo esc_attr( $data->team_opp->logo ); ?>')"></div>
		<?php endif; ?>
		<span><?php echo esc_html( $team_display_name ); ?></span>
	</a>
<?php else : ?>
	<div class="p-0 m-0 d-flex align-items-center">
		<?php if ( ! empty( $data->team_opp->logo ) ) : ?>
			<div class="team-logo__cover team-logo__cover--small mr-1" style="background-image: url('<?php echo esc_attr( $data->team_opp->logo ); ?>')"></div>
		<?php endif; ?>
		<span><?php echo esc_html( $team_display_name ); ?></span>
	</div>
<?php endif; ?>