<?php
if ( ! defined( 'ABSPATH' ) ) exit;

/**
 * Handles all admin-facing functionality, like menu pages and notices.
 */
class Sifency_Theme_Builder_Admin {
	
	public function render_admin_page() {
		$tabs       = sifency_addons_themebuilder_get_tabs();
		// Changing tabs only affects which section is shown, no data is modified.
		// Nonce verification is not required here.
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		$active_tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : 'all';
		?>
		<div class="sifency-admin-page">
			<div class="sifency-dashboard-layout">
				<nav class="sifency-dashboard-nav">
					<?php foreach ( $tabs as $tab_slug => $tab_data ) : ?>
						<a href="<?php echo esc_url( admin_url( 'admin.php?page=sifency-theme-builder&tab=' . $tab_slug ) ); ?>" 
						class="sifency-nav-item sifency-admin-btn <?php echo $active_tab === $tab_slug ? 'is-active' : ''; ?>"
						<?php echo ! empty( $tab_data['tooltip'] ) ? 'title="' . esc_attr( $tab_data['tooltip'] ) . '"' : ''; ?>>

							<!-- Icon -->
							<?php if ( ! empty( $tab_data['icon'] ) ) : ?>
								<span class="sifency-nav-item-icon dashicons <?php echo esc_attr( $tab_data['icon'] ); ?>"></span>
							<?php endif; ?>

							<!-- Label -->
							<span class="sifency-nav-item-label"><?php echo esc_html( $tab_data['label'] ); ?></span>

							<!-- Beta Badge -->
							<?php if ( ! empty( $tab_data['beta'] ) ) : ?>
								<span class="sifency-beta-badge">Beta</span>
							<?php endif; ?>

							<!-- PRO Badge -->
							<?php if ( ! empty( $tab_data['premium'] ) && ! Sifency_Addons_Theme_Builder_Master::sifency_addons_is_legal() ) : ?>
								<span class="sifency-pro-badge">PRO</span>
							<?php endif; ?>

						</a>
					<?php endforeach; ?>
				</nav>

				<div class="sifency-dashboard-content">
					<?php sifency_addons_render_tab_content( $active_tab ); ?>
				</div>
			</div>
		</div>

		<?php // --- MODALS --- ?>
		<?php sifency_addons_render_conditions_modal(); ?>
		<?php sifency_addons_render_new_template_modal( $tabs, $active_tab ); ?>
		<?php
	}

}

