<?php
/**
 * Accounts Module Settings
 *
 * Registers account-specific settings in the settings page.
 *
 * @package AmbassadorHub\Accounts\Admin\Settings
 */

namespace AmbassadorHub\Consent\Admin\Settings;

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

use AmbassadorHub\Admin\Settings\Fields;

use function add_action;
use function esc_html__;

/**
 * Handles registration of account-related settings.
 *
 * Registers where the Account/My Account page should be.
 */
final class SettingsManager {
	/**
	 * Initialize settings registration hooks.
	 *
	 * @return void
	 */
	public static function init(): void {

		add_action( 'ambh_register_settings', array( self::class, 'register_settings' ) );
		add_action( 'ambh_settings_general_fields', array( self::class, 'render_page_settings' ) );
	}

	public static function register_settings(): void {

		register_setting(
			'ambh_general',
			'ambh_ambassador_consent_enabled',
			array(
				'sanitize_callback' => 'rest_sanitize_boolean',
				'default'           => true,
				'type'              => 'boolean',
			)
		);

		register_setting(
			'ambh_general',
			'ambh_ambassador_general_consent_text',
			array(
				'sanitize_callback' => 'sanitize_text_field',
				'default'           => __( 'I consent to be contacted by email about news, updates, and fundraising opportunities.', 'ambassadorhub' ),
				'type'              => 'string',
			)
		);

		register_setting(
			'ambh_general',
			'ambh_donor_consent_enabled',
			array(
				'sanitize_callback' => 'rest_sanitize_boolean',
				'default'           => true,
				'type'              => 'boolean',
			)
		);

		register_setting(
			'ambh_general',
			'ambh_donor_general_consent_text',
			array(
				'sanitize_callback' => 'sanitize_text_field',
				'default'           => __( 'I consent to be contacted by email about news, updates, and fundraising opportunities.', 'ambassadorhub' ),
				'type'              => 'string',
			)
		);
	}

	/**
	 * Register the Account page setting.
	 *
	 * Allows admins to select which page contains the Account/My Account functionality.
	 * This page should have the Account block placed on it.
	 *
	 * @return void
	 */
	public static function render_page_settings(): void {

		?>

		<h3 style="margin:0;padding:1em 0 0;"><?php esc_html_e( 'Consent Settings', 'ambassadorhub' ); ?></h3>
		<table class="form-table" role="presentation">
			<tbody>

				<?php

					Fields::checkbox(
						'ambh_ambassador_consent_enabled',
						esc_html__( 'Ambassador consent', 'ambassadorhub' ),
						esc_html__( 'Enable consent collection for ambassadors', 'ambassadorhub' ),
						esc_html__( 'Add a consent checkbox to the ambassador registration form', 'ambassadorhub' )
					);

					Fields::textarea(
						'ambh_ambassador_general_consent_text',
						esc_html__( 'Ambassador consent text', 'ambassadorhub' ),
						esc_html__( 'The text that will be shown next to the consent checkbox on the ambassador registration form', 'ambassadorhub' ),
						3
					);

					Fields::checkbox(
						'ambh_donor_consent_enabled',
						esc_html__( 'Donor consent', 'ambassadorhub' ),
						esc_html__( 'Enable consent collection for donors', 'ambassadorhub' ),
						esc_html__( 'Add a consent checkbox to the donation form', 'ambassadorhub' )
					);

					Fields::textarea(
						'ambh_donor_general_consent_text',
						esc_html__( 'Donor consent text', 'ambassadorhub' ),
						esc_html__( 'The text that will be shown next to the consent checkbox on the donation form', 'ambassadorhub' ),
						3
					);

				?>
			
			</tbody>
		</table>
		<?php
	}
}
