<?php
/**
 * Tabs template.
 *
 * @package Rsmspark_Content_Widgets
 */

defined( 'ABSPATH' ) || exit;

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

$remember_tab = ! empty( $remember_tab );
$storage_key  = isset( $storage_key ) ? (string) $storage_key : '';
?>
<div
	id="<?php echo esc_attr( $widget_uid ); ?>"
	class="rsmspark-cw rsmspark-cw-tabs"
	style="<?php echo esc_attr( $style_vars ); ?>"
	data-rsmspark-cw-tabs
	<?php if ( $remember_tab && '' !== $storage_key ) : ?>
		data-rsmspark-cw-tabs-remember="1"
		data-rsmspark-cw-tabs-storage-key="<?php echo esc_attr( $storage_key ); ?>"
	<?php endif; ?>
>
	<div class="rsmspark-cw-tabs__nav" role="tablist">
		<?php foreach ( $items as $index => $item ) : ?>
			<button
				type="button"
				class="rsmspark-cw-tabs__tab<?php echo 0 === $index ? ' is-active' : ''; ?>"
				role="tab"
				aria-selected="<?php echo 0 === $index ? 'true' : 'false'; ?>"
				data-rsmspark-cw-tab="<?php echo esc_attr( (string) $index ); ?>"
				data-rsmspark-cw-tab-slug="<?php echo esc_attr( $item['slug'] ?? '' ); ?>"
			>
				<?php echo esc_html( $item['title'] ); ?>
			</button>
		<?php endforeach; ?>
	</div>
	<div class="rsmspark-cw-tabs__panels">
		<?php foreach ( $items as $index => $item ) : ?>
			<div
				class="rsmspark-cw-tabs__panel rsmspark-rt-root<?php echo 0 === $index ? ' is-active' : ''; ?>"
				role="tabpanel"
				data-rsmspark-cw-panel="<?php echo esc_attr( (string) $index ); ?>"
				data-rsmspark-cw-panel-slug="<?php echo esc_attr( $item['slug'] ?? '' ); ?>"
				<?php echo 0 !== $index ? 'hidden' : ''; ?>
			>
				<?php echo wp_kses_post( Rsmspark_Rich_Text_Body::render( $item['content'] ) ); ?>
			</div>
		<?php endforeach; ?>
	</div>
</div>
