<?php

namespace Barn2\Plugin\Password_Protected_Categories\Admin\Wizard;

use Barn2\Plugin\Password_Protected_Categories\Admin\Wizard\Steps\Access_Types;
use Barn2\Plugin\Password_Protected_Categories\Admin\Wizard\Steps\Completed;
use Barn2\Plugin\Password_Protected_Categories\Admin\Wizard\Steps\License_Verification;
use Barn2\Plugin\Password_Protected_Categories\Admin\Wizard\Steps\Password_Protection;
use Barn2\Plugin\Password_Protected_Categories\Admin\Wizard\Steps\Upsell;
use Barn2\Plugin\Password_Protected_Categories\Admin\Wizard\Steps\User_Protection;
use Barn2\Plugin\Password_Protected_Categories\Admin\Wizard\Steps\Visibility;
use Barn2\Plugin\Password_Protected_Categories\Dependencies\Setup_Wizard\Setup_Wizard;
use Barn2\Plugin\Password_Protected_Categories\Dependencies\Setup_Wizard\Util;
use Barn2\Plugin\Password_Protected_Categories\Dependencies\Lib\Plugin\License\EDD_Licensing;
use Barn2\Plugin\Password_Protected_Categories\Dependencies\Lib\Plugin\License\Plugin_License;
use Barn2\Plugin\Password_Protected_Categories\Dependencies\Lib\Plugin\Licensed_Plugin;
use Barn2\Plugin\Password_Protected_Categories\Dependencies\Lib\Registerable;
use Barn2\Plugin\Password_Protected_Categories\Dependencies\Lib\Service\Standard_Service;

class Service implements Standard_Service, Registerable {

	/**
	 * Plugin instance
	 *
	 * @var Licensed_Plugin
	 */
	private $plugin;

	/**
	 * Wizard instance
	 *
	 * @var Wizard
	 */
	private $wizard;

	/**
	 * Setup the setup wizard. Pun intended.
	 *
	 * @param Licensed_Plugin $plugin
	 */
	public function __construct( Licensed_Plugin $plugin ) {

		$this->plugin = $plugin;

		$steps = [
			new License_Verification(),
			new Visibility(),
			new Access_Types(),
			new Password_Protection(),
			new User_Protection(),
			new Upsell(),
			new Completed(),
		];

		$wizard = new Setup_Wizard( $this->plugin, $steps, false );

		$this->wizard = $wizard;
	}

	public function configure() {
		$this->wizard->configure(
			[
				'skip_url'        => admin_url( 'options-general.php?page=protected_categories' ),
				'license_tooltip' => esc_html__( 'The licence key is contained in your order confirmation email.', 'password-protected-categories' ),
				'utm_id'          => 'ppc',
			]
		);

		$this->wizard->add_edd_api( EDD_Licensing::class );
		$this->wizard->add_license_class( Plugin_License::class );

		$this->wizard->add_custom_asset(
			$this->plugin->get_dir_url() . 'assets/js/admin/ppc-wizard.js',
			Util::get_script_dependencies( $this->plugin, './assets/js/admin/ppc-wizard.js' )
		);

		$this->wizard->add_restart_link( $this->plugin->get_slug(), $this->plugin->get_name() );
	}

	/**
	 * Boot the wizard.
	 *
	 * @return void
	 */
	public function register() {
		$this->configure();
		$this->wizard->boot();
	}
}
