<?php
/**
 * A row of tabs.
 *
 * Rows arrive already resolved — label, icon, URL and whether it is current — so
 * this partial makes no decisions and the two screens using it cannot end up
 * with two different tab strips.
 *
 * @package TextTango
 *
 * @var array<string, mixed> $args {
 *     @type array<int, array{label: string, icon: string, url: string, active: bool}> $rows
 *     @type string $label What this navigation is, for assistive technology.
 * }
 */

declare( strict_types=1 );

defined( 'ABSPATH' ) || exit;

use TextTango\Admin\Icons;

$texttango_rows = (array) ( $args['rows'] ?? array() );

if ( empty( $texttango_rows ) ) {
	return;
}
?>
<nav class="tt-mb-6 tt-border-0 tt-border-b tt-border-solid tt-border-slate-200"
	aria-label="<?php echo esc_attr( (string) ( $args['label'] ?? '' ) ); ?>">
	<ul class="tt-m-0 tt-flex tt-flex-wrap tt-list-none tt-gap-1 tt-p-0">
		<?php foreach ( $texttango_rows as $texttango_row ) : ?>
			<?php $texttango_active = ! empty( $texttango_row['active'] ); ?>
			<li class="tt-m-0">
				<a
					class="tt-tab<?php echo $texttango_active ? ' tt-tab-active' : ''; ?>"
					href="<?php echo esc_url( (string) ( $texttango_row['url'] ?? '' ) ); ?>"
					<?php echo $texttango_active ? 'aria-current="page"' : ''; ?>>
					<?php
					/*
					 * Decorative: the label is the next thing in this element, so
					 * announcing the icon as well reads the tab out twice.
					 */
					echo wp_kses( Icons::get( (string) ( $texttango_row['icon'] ?? '' ) ), Icons::allowed_html() );
					?>
					<?php echo esc_html( (string) ( $texttango_row['label'] ?? '' ) ); ?>
				</a>
			</li>
		<?php endforeach; ?>
	</ul>
</nav>
