<?php
/**
 * Team Info Block — Template
 *
 * @var \WP_Post $team     The parent team fundraiser post.
 * @var bool     $can_join Whether the current context allows joining this team.
 * @var string   $join_url URL to the create fundraiser page pre-set to join this team.
 *
 * @package AmbassadorHub\Fundraisers\Blocks\TeamInfo
 */

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

$ambh_team_url      = get_permalink( $team );
$ambh_has_thumbnail = has_post_thumbnail( $team );
$ambh_thumbnail_id  = get_post_thumbnail_id( $team );
?>
<div class="ambh-team-info">
	<div class="ambh-team-info__header">
		<a class="ambh-team-info__link" href="<?php echo esc_url( $ambh_team_url ); ?>">
			<?php if ( $ambh_has_thumbnail ) : ?>
				<div class="ambh-team-info__image">
					<?php
					echo wp_get_attachment_image(
						$ambh_thumbnail_id,
						'thumbnail',
						false,
						array(
							'class' => 'ambh-team-info__img',
							'alt'   => esc_attr( get_the_title( $team ) ),
						)
					);
					?>
				</div>
			<?php endif; ?>
			<span class="ambh-team-info__name"><?php echo esc_html( get_the_title( $team ) ); ?></span>
		</a>
	</div>
	<?php if ( $can_join && $join_url ) : ?>
		<div class="ambh-team-info__actions">
			<a class="ambh-team-info__btn" href="<?php echo esc_url( $ambh_team_url ); ?>">
				<?php esc_html_e( 'View team', 'ambassadorhub' ); ?>
			</a>
			<a class="ambh-team-info__btn ambh-team-info__btn--create" href="<?php echo esc_url( $join_url ); ?>">
				<?php esc_html_e( 'Create fundraiser', 'ambassadorhub' ); ?>
			</a>
		</div>
	<?php endif; ?>
</div>
