<?php

namespace SugarCalendarBookings\Support\Admin\PageLayouts;

use SugarCalendarBookings\Support\Admin\AbstractPage;
// phpcs:disable WPForms.PHP.UseStatement.UnusedUseStatement
use SugarCalendarBookings\Support\Admin\AbstractTabPage;
use SugarCalendarBookings\Support\Helpers\UI;

/**
 * Tabbed layout.
 *
 * @since 1.0.0
 */
class TabbedLayout implements LayoutInterface {

	/**
	 * Tabs.
	 *
	 * @since 1.0.0
	 *
	 * @var array<class-string<AbstractTabPage>>
	 */
	private $tabs;

	/**
	 * Constructor.
	 *
	 * @since 1.0.0
	 *
	 * @param array<class-string<AbstractTabPage>> $tabs Tabs.
	 */
	public function __construct( $tabs ) {

		$this->tabs = $tabs;
	}

	/**
	 * Display page.
	 *
	 * @since 1.0.0
	 *
	 * @param AbstractPage $page Page instance.
	 */
	public function display( AbstractPage $page ) {

		$tabs = [];

		foreach ( $this->tabs as $tab ) {
			$tabs[ $tab::get_menu_slug() ] = [
				'name'     => $tab::get_label(),
				'url'      => $tab::get_url(),
				'priority' => $tab::get_priority(),
			];
		}

		$active_tab_slug = $page->get_menu_slug();

		?>
		<div class="wrap sugar-calendar-bookings-admin-wrap">
			<?php UI::tabs( $tabs, $active_tab_slug ); ?>

			<div class="sugar-calendar-bookings-admin-content">
				<h1 class="screen-reader-text"><?php echo esc_html( $page->get_title() ); ?></h1>
				<?php $page->display_content(); ?>
			</div>
		</div>
		<?php
	}
}
