<?php
/**
 * Multi Tab Switcher View for Pixelio Cart Abandon Recovery More plugin.
 *
 * This file defines a reusable class for rendering a tab switcher with multiple tabs
 * in the admin pages or front-end of the Pixelio Cart Abandon Recovery More plugin.
 *
 * PHP version 8.0+
 *
 * @package PixelioCartAbandonRecoveryMore
 */

namespace PixelioCartAbandonRecoveryMore\Admin\Views\Reusable;

use PixelioCartAbandonRecoveryMore\Includes\Utils\Pixelio_Cart_Abandon_Recovery_More_Util;

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

/**
 * Class Pixelio_Cart_Abandon_Recovery_More_Multi_Tab_Switcher
 *
 * Reusable class for displaying multiple tabs with a sliding indicator
 * and content area. Each tab can trigger a callback function.
 *
 * @package PixelioCartAbandonRecoveryMore\Admin\Views\Reusable
 */
class Pixelio_Cart_Abandon_Recovery_More_Multi_Tab_Switcher {


	/**
	 * Array of tabs, key = tab name, value = callback function name
	 *
	 * @var array
	 */
	private $tabs = array();

	/**
	 * Number of tabs
	 *
	 * @var int
	 */
	private int $nums;

	/**
	 * Constructor.
	 *
	 * @param array $tabs Associative array of tabs: ['Tab Name' => 'callbackFunctionName'].
	 */
	public function __construct( $tabs = array() ) {
		$this->tabs = $tabs;
		$this->nums = count( $this->tabs );
	}

	/**
	 * Outputs the HTML, CSS, and JS for the multi-tab switcher.
	 *
	 * Each tab triggers a callback when clicked. A sliding indicator
	 * highlights the active tab.
	 *
	 * @return void
	 */
	public function pixelio_cart_abandon_recovery_more_get_views() {

		if ( empty( $this->tabs ) ) {
			return;
		}
		?>
		<div class="pixelio-cart-abandon-recovery-more-multi-tab-switcher">
			<div class="pixelio-cart-abandon-recovery-more-tabs" style="columns: <?php echo esc_attr( $this->nums ); ?> auto">
				<?php
				$index = 0;

				foreach ( $this->tabs as $tab_name => $callback ) :
					?>
					<div class="pixelio-cart-abandon-recovery-more-tab" data-callback="<?php echo esc_attr( $callback ); ?>"
						 data-index="<?php echo esc_attr( $index ); ?>">
						<?php echo esc_html( $tab_name ); ?>
					</div>
					<?php
					++$index;
				endforeach;
				?>
				<div class="pixelio-cart-abandon-recovery-more-tab-indicator"></div>
			</div>
			<div class="pixelio-cart-abandon-recovery-more-tab-content"></div>
		</div>




		<?php
	}
}

