<?php

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

$current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification

$tab_items = array(
	'general' => esc_html__( 'General', 'gigneo' ),
	'status'  => esc_html__( 'Status', 'gigneo' ),
);

$tab_items = apply_filters( 'gigneo_tools_tabs', $tab_items );

if ( ! empty( $current_tab ) && ! isset( $tab_items[ $current_tab ] ) ) {
	wp_safe_redirect( admin_url( 'admin.php?page=gigneo-tools' ) );
	exit();
}

// load the header template
gigneo_load_template( 'admin/header.php' );
?>
<div class="gn-tools">
	<div class="gn-nav-tab-wrapper">
		<?php
		foreach ( $tab_items as $t_slug => $tab_item ) {
			$tab_class  = 'gn-tab-menu';
			$tab_class .= $current_tab === $t_slug ? ' active' : '';
			$tab_class .= ! isset( $tab_items[ $current_tab ] ) && 'general' === $t_slug ? ' active' : '';
			$tab_url    = admin_url( 'admin.php?page=gigneo-tools&tab=' . esc_attr( $t_slug ) );
			?>
			<a href="<?php echo esc_url( $tab_url ); ?>" class="<?php echo esc_attr( $tab_class ); ?>">
				<?php echo esc_html( $tab_item ); ?>
			</a>
		<?php } ?>
	</div>
	<div class="gn-setting-tabs-content">
		<?php
		$active_tab      = isset( $tab_items[ $current_tab ] ) ? $current_tab : 'general';
		$active_tab_name = str_replace( '_', '-', $active_tab );
		gigneo_load_template( "admin/parts/tools/{$active_tab_name}" );
		?>
	</div>
</div>