<?php
/**
 * Cookie Banner — admin settings page (multi-tab, client-side).
 *
 * @package BlaminhorEssentials
 *
 * @var Blaminhor_Essentials_Module_Cookies                $module
 * @var Blaminhor_Essentials_Cookies_Consent_Manager        $consent_manager
 * @var Blaminhor_Essentials_Cookies_Consent_Log            $consent_log
 * @var Blaminhor_Essentials_Cookies_Service_Templates      $templates
 * @var Blaminhor_Essentials_Cookies_Regional_Presets       $presets
 * @var Blaminhor_Essentials_Cookies_Geo_Resolver           $geo_resolver
 * @var Blaminhor_Essentials_Cookies_TCF_Adapter            $tcf_adapter
 * @var array                                               $settings
 * @var string                                              $active_tab
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

$tabs = apply_filters(
	'blaminhor_cookies_admin_tabs',
	array(
		'general'    => __( 'General', 'blaminhor-essentials' ),
		'services'   => __( 'Services', 'blaminhor-essentials' ),
		'diagnostic' => __( 'Diagnostic', 'blaminhor-essentials' ),
		'advanced'   => __( 'Advanced', 'blaminhor-essentials' ),
	)
);

if ( ! isset( $tabs[ $active_tab ] ) ) {
	$active_tab = 'general';
}

// Tabs that contain settings inputs and need the "Save settings" button.
$writable_tabs = array( 'general', 'services', 'advanced' );
?>
<div class="wrap blaminhor-essentials-wrap">
	<div class="blaminhor-essentials-header">
		<h1><?php esc_html_e( 'Cookie Banner', 'blaminhor-essentials' ); ?></h1>
		<p class="blaminhor-essentials-tagline">
			<?php echo esc_html( $module->get_description() ); ?>
		</p>
	</div>

	<div class="blaminhor-essentials-tabs-wrapper">
		<div class="blaminhor-essentials-tabs">
			<?php foreach ( $tabs as $key => $label ) : ?>
				<button
					type="button"
					class="blaminhor-essentials-tab<?php echo $active_tab === $key ? ' active' : ''; ?>"
					data-tab="<?php echo esc_attr( $key ); ?>"
				><?php echo esc_html( $label ); ?></button>
			<?php endforeach; ?>
		</div>

		<form method="post" action="">
			<?php $module->render_nonce_field(); ?>
			<input type="hidden" name="active_tab" value="<?php echo esc_attr( $active_tab ); ?>">

			<?php foreach ( $tabs as $key => $label ) : ?>
				<div
					class="blaminhor-essentials-tab-content<?php echo $active_tab === $key ? ' active' : ''; ?>"
					data-tab-content="<?php echo esc_attr( $key ); ?>"
				>
					<?php
					$view = __DIR__ . '/settings-' . $key . '.php';
					if ( file_exists( $view ) ) {
						require $view;
					} else {
						echo '<p>' . esc_html__( 'Section not found.', 'blaminhor-essentials' ) . '</p>';
					}
					?>
				</div>
			<?php endforeach; ?>

			<p class="submit">
				<button type="submit" class="button button-primary">
					<?php esc_html_e( 'Save settings', 'blaminhor-essentials' ); ?>
				</button>
			</p>
		</form>
	</div>
</div>
