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

/** Unified admin header with logo */
if ( ! function_exists( 'awxct_admin_header' ) ) {
	require_once AWXCT_PATH . 'includes/helpers.php';
}
awxct_admin_header( __( 'Welcome', 'anywarex-clone-translate' ) );
?>

<div class="wrap awxct-welcome-page">

<?php
/**
 * Determine active tab.
 *
 * NOTE:
 * - This is VIEW-ONLY navigation via GET.
 * - No data is modified or persisted.
 * - Therefore no nonce is required.
 */
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : 'benefits';

$allowed_tabs = array(
	'benefits',
	'quickstart',
	'compare',
	'js',
	'php',
	'css',
	'contact',
);

$current_tab = in_array( $tab, $allowed_tabs, true ) ? $tab : 'benefits';

/**
 * Helper for active tab CSS class.
 */
if ( ! function_exists( 'awxct_tab_class' ) ) {
	function awxct_tab_class( $tab, $current ) {
		return ( $tab === $current ) ? 'nav-tab nav-tab-active' : 'nav-tab';
	}
}
?>

<p class="description">
	<?php esc_html_e(
		'This page gives you a quick overview of the JSON-based translation methods, the differences between the Free, Plus and Pro editions, a quick start guide, and optional custom CSS tips for the language switcher.',
		'anywarex-clone-translate'
	); ?>
</p>

<h2 class="nav-tab-wrapper">

	<a href="<?php echo esc_url( add_query_arg( 'tab', 'benefits' ) ); ?>"
		class="<?php echo esc_attr( awxct_tab_class( 'benefits', $current_tab ) ); ?>">
		<?php esc_html_e( 'Benefits', 'anywarex-clone-translate' ); ?>
	</a>

	<a href="<?php echo esc_url( add_query_arg( 'tab', 'quickstart' ) ); ?>"
		class="<?php echo esc_attr( awxct_tab_class( 'quickstart', $current_tab ) ); ?>">
		<?php esc_html_e( 'Quick Start', 'anywarex-clone-translate' ); ?>
	</a>

	<a href="<?php echo esc_url( add_query_arg( 'tab', 'compare' ) ); ?>"
		class="<?php echo esc_attr( awxct_tab_class( 'compare', $current_tab ) ); ?>">
		<?php esc_html_e( 'Free / Plus / Pro', 'anywarex-clone-translate' ); ?>
	</a>

	<a href="<?php echo esc_url( add_query_arg( 'tab', 'js' ) ); ?>"
		class="<?php echo esc_attr( awxct_tab_class( 'js', $current_tab ) ); ?>">
		<?php esc_html_e( 'JS-based JSON', 'anywarex-clone-translate' ); ?>
	</a>

	<a href="<?php echo esc_url( add_query_arg( 'tab', 'php' ) ); ?>"
		class="<?php echo esc_attr( awxct_tab_class( 'php', $current_tab ) ); ?>">
		<?php esc_html_e( 'PHP-based JSON', 'anywarex-clone-translate' ); ?>
	</a>

	<a href="<?php echo esc_url( add_query_arg( 'tab', 'css' ) ); ?>"
		class="<?php echo esc_attr( awxct_tab_class( 'css', $current_tab ) ); ?>">
		<?php esc_html_e( 'Custom CSS (Switcher)', 'anywarex-clone-translate' ); ?>
	</a>


	<a href="<?php echo esc_url( add_query_arg( 'tab', 'contact' ) ); ?>"
		class="<?php echo esc_attr( awxct_tab_class( 'contact', $current_tab ) ); ?>">
		<?php esc_html_e( 'Contact', 'anywarex-clone-translate' ); ?>
	</a>

</h2>

<div class="awxct-tab-content">

<?php
$views = array(
	'benefits'   => 'welcome-benefits-page.php',
	'quickstart' => 'welcome-quickstart-page.php',
	'compare'    => 'welcome-compare-page.php',
	'js'         => 'json-js-based-page.php',
	'php'        => 'json-php-based-page.php',
	'css'        => 'welcome-switcher-css-page.php',
	'contact'    => 'welcome-contact-page.php',
);

$file = AWXCT_PATH . 'admin/views/' . $views[ $current_tab ];

if ( file_exists( $file ) ) {
	include $file;
} else {
	echo '<h2>' . esc_html( ucfirst( $current_tab ) ) . '</h2>';
	echo '<p>' . esc_html__( 'View file missing.', 'anywarex-clone-translate' ) . '</p>';
}
?>

</div>
</div>
