<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
<?php
/**
 * Wizard installation plugin helper
 *
 * @since             1.0.0
 * @package           TInvWishlist
 */

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

/**
 * Wizard installation plugin helper.
 */
class TInvWL_WizardSetup {
	/**
	 * Plugin name.
	 *
	 * @var string
	 */
	private string $_name;

	/**
	 * Plugin version.
	 *
	 * @var string
	 */
	private string $_version;

	/**
	 * TInvWL_WizardSetup constructor.
	 *
	 * @param string $plugin_name Plugin name.
	 * @param string $version Plugin version.
	 */
	public function __construct( string $plugin_name, string $version ) {
		$this->_name    = $plugin_name;
		$this->_version = $version;
		add_action( 'init', [ $this, 'load' ] );
		add_action( 'admin_init', [ $this, 'redirect' ] );
	}

	/**
	 * Setup trigger for show wizard installation.
	 */
	public static function setup(): void {
		set_transient( '_tinvwl_activation_redirect', 1, 30 );
	}

	/**
	 * Load wizard.
	 */
	public function load(): void {
		$page = filter_input( INPUT_GET, 'page' );
		if ( ! empty( $page ) && 'tinvwl-wizard' === $page ) {
			new TInvWL_Wizard( $this->_name, $this->_version );
		}
	}

	/**
	 * Apply redirect to wizard.
	 */
	public function redirect(): void {
		if ( ! get_transient( '_tinvwl_activation_redirect' ) ) {
			return;
		}
		delete_transient( '_tinvwl_activation_redirect' );

		$page     = filter_input( INPUT_GET, 'page' );
		$activate = filter_input( INPUT_GET, 'activate-multi' );

		if ( in_array( $page, [ 'tinvwl-wizard' ], true ) ||
		     is_network_admin() ||
		     ! is_null( $activate ) ||
		     apply_filters( 'tinvwl_prevent_automatic_wizard_redirect', false ) ) {
			return;
		}

		wp_safe_redirect( admin_url( 'index.php?page=tinvwl-wizard' ) );
		exit;
	}
}
