<?php
/**
 * Template for rendering a custom admin menu page.
 *
 * This template dynamically generates the content for a custom admin menu page,
 * including a title, help links, navigation tabs, and optionally, custom page content
 * specified through a template path. Additional CSS classes for the main wrapper and
 * content wrapper can be specified for further customization.
 *
 * @package IgnitionDeck
 *
 * Variables:
 * - $page_title (string): The title of the menu page. Defaults to 'IgnitionDeck'.
 * - $help_links (array): An array of help links to be displayed on the page. Each help link
 *                        is an associative array with keys 'url', 'text', and 'title'.
 *                        Defaults to an empty array.
 * - $tabs (array): An array of tabs for navigation within the menu page. Each tab is an
 *                  associative array with keys 'title', 'url', and 'active'. The 'active' key
 *                  indicates if the tab is the current active tab. Defaults to an empty array.
 * - $page_content_template_path (string): The file path to the template for the page content.
 *                                         Defaults to an empty string, indicating no custom content template.
 * - $classes (array): An optional array containing CSS classes for customization. It supports:
 *      - 'main_wrapper_classes' (string): Additional CSS classes for the main wrapper. Defaults to an empty string.
 *      - 'content_wrapper_classes' (string): Additional CSS classes for the content wrapper. Defaults to an empty string.
 *
 * @note This template should be included via a function or method that sets up the above variables.
 */
$page_title = isset( $page_title ) ? $page_title : 'IgnitionDeck';
$help_links = isset( $help_links ) ? $help_links : array();
$page_note = isset( $page_note ) ? $page_note : '';
$tabs = isset( $tabs ) ? $tabs : array();
$page_content_template_path = isset( $page_content_template_path ) ? $page_content_template_path : '';
$main_wrapper_classes = ( !empty( $classes ) && isset( $classes['main_wrapper_classes'] ) ) ? $classes['main_wrapper_classes'] : '';
$content_wrapper_classes = ( !empty( $classes ) && isset( $classes['content_wrapper_classes'] ) ) ? $classes['content_wrapper_classes'] : '';
?>
<div class="wrap <?php echo esc_attr( $main_wrapper_classes ); ?>">
	<?php echo ( isset( $message ) ? esc_attr( $message ) : '' ); ?>
	<div class="sidebar ignitiondeck">
		<div class="icon32"></div>
		<h2 class="title"><?php echo esc_html__( $page_title, 'ignitiondeck' ); ?></h2>
		<div class="idf-above-tabs-section">
			<!-- Check if $help_links is not empty before looping -->
			<?php if ( !empty( $help_links ) ): ?>
				<div class="idf-help-links">
					<?php foreach ( $help_links as $link ): ?>
						<a href="<?php echo esc_url( $link['url'] ); ?>" class="button button-secondary" title="<?php echo esc_attr( $link['title'] ); ?>" target="_blank">
							<?php echo esc_html__( $link['text'], 'ignitiondeck' ); ?>
						</a>
					<?php endforeach; ?>
				</div>
			<?php endif; ?>

			<!-- Check if $help_links is not empty before looping -->
			<?php if ( !empty( $page_note ) ): ?>
				<div class="idf-page-note">
					<p>
						<?php echo esc_html__( $page_note, 'ignitiondeck' ); ?>
					</p>
				</div>
			<?php endif; ?>
		</div>


		<!-- Check if $tabs is not empty before looping -->
		<?php if ( !empty( $tabs ) ): ?>
			<h3 class="nav-tab-wrapper">
				<?php foreach ( $tabs as $tab ): ?>
					<a href="<?php echo esc_url( $tab['url'] ); ?>" class="nav-tab <?php echo esc_attr( $tab['active'] ? 'nav-tab-active' : '' ); ?>">
						<?php echo esc_html__( $tab['title'], 'ignitiondeck' ); ?>
					</a>
				<?php endforeach; ?>
			</h3>
		<?php endif; ?>
	</div>

	<div class="<?php echo esc_attr( $content_wrapper_classes ); ?>">
		<?php if ( !empty( $page_content_template_path ) ): ?>
			<?php include( $page_content_template_path ); ?>
		<?php endif; ?>
	</div>

	<?php do_action( 'idf_after_menu_page_tab_content' ); ?>

</div>

