<?php
/**
 * MINIORANGE OAuth admin pointers configuration.
 *
 * @package    MoCognito
 */

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

/**
 * Build admin pointer definitions for the current request context.
 *
 * @return array<string, array<string, mixed>>
 */
function mocognito_get_admin_pointers() {
	$pointers = array();

	// @phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Safe to ignore nonce here as no data operation
	$action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : '';
	// @phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Safe to ignore nonce here as no data operation
	$tab    = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : '';
	// @phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Safe to ignore nonce here as no data operation
	$app_id = isset( $_GET['appId'] ) ? sanitize_text_field( wp_unslash( $_GET['appId'] ) ) : '';
	// @phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Safe to ignore nonce here as no data operation
	$app    = isset( $_GET['app'] ) ? sanitize_text_field( wp_unslash( $_GET['app'] ) ) : '';

	if ( 'update' === $action ) {
		$pointers['miniorange-configure-test-config-pointer'] = array(
			'title'     => sprintf( '<h3>%s</h3>', esc_html__( 'Test Your Application Configuration', 'login-with-cognito' ) ),
			'content'   => sprintf( '<p>%s</p>', esc_html__( 'Click here to see the list of attributes provided by your OAuth Provider. If you are getting any error, please refer the FAQ tab.', 'login-with-cognito' ) ),
			'anchor_id' => '#mo_oauth_test_configuration',
			'edge'      => 'left',
			'align'     => 'right',
			'where'     => array( 'toplevel_page_mo_oauth_settings' ),
		);

	} elseif ( '' !== $app_id ) {
		$pointers['miniorange-configure-addapp-pointer'] = array(
			'title'     => sprintf( '<h3>%s</h3>', esc_html__( 'Configure Your Application', 'login-with-cognito' ) ),
			'content'   => sprintf( '<p>%s</p>', esc_html__( 'Need help with configuration? Click on How to Configure?', 'login-with-cognito' ) ),
			'anchor_id' => '#mo_oauth_config_guide',
			'edge'      => 'left',
			'align'     => 'right',
			'where'     => array( 'toplevel_page_mo_oauth_settings' ),
		);
	}

	if ( 'config' === $tab ) {
		$pointers['miniorange-support-pointer'] = array(
			'title'     => sprintf( '<h3>%s</h3>', esc_html__( 'We are here!!', 'login-with-cognito' ) ),
			'content'   => sprintf( '<p>%s</p>', esc_html__( 'Get in touch with us and we will help you setup the plugin in no time.', 'login-with-cognito' ) ),
			'anchor_id' => '#mo_support_layout',
			'edge'      => 'right',
			'align'     => 'left',
			'where'     => array( 'toplevel_page_mo_oauth_settings' ),
		);

		if ( '' === $app_id && '' === $app ) {
			if ( is_array( get_option( 'mo_oauth_apps_list' ) ) && count( get_option( 'mo_oauth_apps_list' ) ) > 0 ) {
				$pointers['miniorange-app-list-pointer'] = array(
					'title'     => sprintf( '<h3>%s</h3>', esc_html__( 'App List', 'login-with-cognito' ) ),
					'content'   => sprintf( '<p>%s</p>', esc_html__( 'Click here to Update or Delete the application.', 'login-with-cognito' ) ),
					'anchor_id' => '#mo_oauth_app_list',
					'edge'      => 'left',
					'align'     => 'right',
					'where'     => array( 'toplevel_page_mo_oauth_settings' ),
				);
			} else {
				$pointers['miniorange-select-your-idp'] = array(
					'title'     => sprintf( '<h3>%s</h3>', esc_html__( 'Select your OAuth Provider', 'login-with-cognito' ) ),
					'content'   => sprintf( '<p>%s</p>', esc_html__( 'Choose your OAuth Provider from the list of OAuth Providers', 'login-with-cognito' ) ),
					'anchor_id' => '#mo_oauth_client_default_apps',
					'edge'      => 'left',
					'align'     => 'left',
					'where'     => array( 'toplevel_page_mo_oauth_settings' ),
				);
			}
		}
	}

	if ( 'attributemapping' === $tab ) {
		$pointers['miniorange-configure-atribute-mapping-pointer'] = array(
			'title'     => sprintf( '<h3>%s</h3>', esc_html__( 'Mapping Attributes', 'login-with-cognito' ) ),
			'content'   => sprintf( '<p>%s</p>', esc_html__( 'Enter the appropriate values(attribute names) from the Test Configuration table.', 'login-with-cognito' ) ),
			'anchor_id' => '#attribute-mapping',
			'edge'      => 'left',
			'align'     => 'right',
			'where'     => array( 'toplevel_page_mo_oauth_settings' ),
		);
	}

	return $pointers;
}

return mocognito_get_admin_pointers();
