<?php

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

$variant   = isset( $args['variant'] )   ? (string) $args['variant']   : '';
$tabs      = isset( $args['tabs'] )      ? (array)  $args['tabs']      : array();
$active_id = isset( $args['active_id'] ) ? (string) $args['active_id'] : '';

if ( empty( $tabs ) ) {
    return;
}

$variant_class = '';
if ( $variant === 'analytics' ) {
    $variant_class = ' aieo-dmm-subtab-bar--analytics';
} elseif ( $variant === 'chat' ) {
    $variant_class = ' aieo-dmm-subtab-bar--chat';
}

if ( $active_id === '' && ! empty( $tabs[0]['id'] ) ) {
    $active_id = (string) $tabs[0]['id'];
}
?>
<nav class="aieo-dmm-subtab-bar<?php echo esc_attr( $variant_class ); ?>" data-aieo-toc-bar="1" aria-label="<?php esc_attr_e( 'Page sections', 'ai-eshop-optimizer' ); ?>">
<?php foreach ( $tabs as $tab ) :
    if ( empty( $tab['href'] ) || empty( $tab['label'] ) ) { continue; }
    $tab_id     = isset( $tab['id'] ) ? (string) $tab['id'] : '';
    $is_active  = ( $tab_id !== '' && $tab_id === $active_id );
    ?>
    <a class="aieo-dmm-subtab<?php echo $is_active ? ' is-active' : ''; ?>"
       href="<?php echo esc_attr( $tab['href'] ); ?>"
       data-aieo-toc-id="<?php echo esc_attr( $tab_id ); ?>">
        <?php echo esc_html( $tab['label'] ); ?>
    </a>
<?php endforeach; ?>
</nav>
