<?php
/**
 * General Settings Tab
 *
 * @package AmbassadorHub\Admin\Settings\Tabs
 */

namespace AmbassadorHub\Admin\Settings\Tabs;

use AmbassadorHub\Admin\Settings\AbstractTab;
use AmbassadorHub\Admin\Settings\Fields;
use function __;
use function settings_fields;
use function do_settings_sections;
use function do_action;
use function submit_button;
use function check_admin_referer;
use function current_user_can;
use function wp_die;
use function apply_filters;
use function esc_html__;
/**
 * General settings tab.
 *
 * Contains platform-wide general settings.
 */
final class AdvancedTab extends AbstractTab {
	/**
	 * Constructor.
	 */
	public function __construct() {
		$this->id       = 'advanced';
		$this->label    = __( 'Advanced', 'ambassadorhub' );
		$this->priority = 50;
	}

	/**
	 * Render the Advanced tab content.
	 *
	 * @return void
	 */
	public function render(): void {
		?>
		<form method="post" action="options.php"> 
			<?php settings_fields( 'ambh_advanced' ); ?>
			<?php do_settings_sections( 'ambh_advanced' ); ?>

			<h3><?php esc_html_e( 'Page Settings', 'ambassadorhub' ); ?></h3>
			<p class="description"><?php esc_html_e( 'Select which WordPress page serves each built-in function. The matching block must be placed on the selected page.', 'ambassadorhub' ); ?></p>

			<table class="form-table" role="presentation">
				<tbody>
					<?php
					Fields::page_selector(
						'ambh_psp_redirect_page_id',
						esc_html__( 'Post-payment redirect page', 'ambassadorhub' ),
						esc_html__( 'Donors land on this page after completing a PSP-hosted checkout (Mollie, FinDock, etc.). Defaults to the home page when not set.', 'ambassadorhub' )
					);
					?>
					<?php
					/**
					 * Fires to register page settings fields.
					 *
					 * Modules register which pages should be used for their functionality
					 * (e.g. Account page, Login/Signup page).
					 *
					 * @since 0.1.0
					 */
					do_action( 'ambh_settings_advanced_page_fields' );
					?>
				</tbody>
			</table>

			<h3><?php esc_html_e( 'Analytics', 'ambassadorhub' ); ?></h3>
			<p class="description"><?php esc_html_e( 'Off by default. Enabling this sends fundraiser, campaign, and ambassador sign-up events to window.dataLayer, and sets a first-party cookie to correlate events across page loads. Nothing is sent unless you already have your own GTM container or gtag.js snippet installed to consume it, and nothing is sent at all until you turn this on.', 'ambassadorhub' ); ?></p>

			<table class="form-table" role="presentation">
				<tbody>
					<?php
					Fields::checkbox(
						'ambh_analytics_tracking_enabled',
						esc_html__( 'Analytics event tracking', 'ambassadorhub' ),
						esc_html__( 'Push fundraiser, campaign, and ambassador sign-up events to window.dataLayer', 'ambassadorhub' ),
						esc_html__( 'Also sets the ambh_tk session cookie, only while this is enabled.', 'ambassadorhub' )
					);
					?>
				</tbody>
			</table>

			<?php
			/**
			 * Fires at the bottom of the General settings tab.
			 *
			 * Modules and feature plugins can add extra fields here.
			 *
			 * @since 0.1.0
			 */
			do_action( 'ambh_settings_advanced_fields' );
			?>

			<?php submit_button(); ?>
		</form>
		<?php
	}
}
