<?php
/**
 * The Template for displaying flag.
 *
 * This template can be overridden by copying it to yourtheme/sports-leagues/general/flag--legacy.php.
 *
 * @var object $data - Object with widget data.
 *
 * @author        Andrei Strekozov <anwp.pro>
 * @package       Sports-Leagues/Templates
 * @since         0.13.6
 *
 * @version       0.13.6
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

$data = (object) wp_parse_args(
	$data,
	[
		'country_code' => '',
		'class'        => 'options__flag',
		'size'         => 16,
	]
);

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

if ( in_array( $data->country_code, [ '__World', '__Africa', '__Asia', '__Europe', '__NC_America', '__Oceania', '__South_America' ], true ) ) : ?>
	<div
		class="d-inline-block f<?php echo absint( $data->size ); ?> <?php echo esc_attr( $data->class ); ?>"
		data-toggle="anwp-sl-tooltip"
		data-tippy-content="<?php echo esc_attr( sports_leagues()->data->get_country_by_code( $data->country_code ) ); ?>">
		<svg class="anwp-icon anwp-icon--octi anwp-icon--s<?php echo 32 === absint( $data->size ) ? 36 : 20; ?>">
			<use xlink:href="#icon-world-flag"></use>
		</svg>
	</div>
<?php else : ?>
	<div
		class="d-inline-block f<?php echo absint( $data->size ); ?> <?php echo esc_attr( $data->class ); ?>"
		data-toggle="anwp-sl-tooltip"
		data-tippy-content="<?php echo esc_attr( sports_leagues()->data->get_country_by_code( $data->country_code ) ); ?>">
		<span class="flag <?php echo esc_attr( $data->country_code ); ?>"></span>
	</div>
	<?php
endif;
