<?php
/**
 * Plugins Welcome page that appears when plugin is activated.
 *
 * @package Flexible_FAQs
 */

namespace WPGO_Plugins\Flexible_Faqs;

/**
 * Plugin 'Welcome' settings page
 */
class Settings_Welcome {

	/**
	 * Common root paths/directories.
	 *
	 * @var $module_roots
	 */
	protected $module_roots;

	/**
	 * Main class constructor.
	 *
	 * @param Array $module_roots Root plugin path/dir.
	 * @param Array $plugin_data Plugin data.
	 * @param Array $custom_plugin_data Custom plugin data.
	 * @param Array $utility Utility data.
	 */
	public function __construct( $module_roots, $plugin_data, $custom_plugin_data, $utility ) {
		$this->module_roots                  = $module_roots;
		$this->plugin_data                   = $plugin_data;
		$this->custom_plugin_data            = $custom_plugin_data;
		$this->freemius_upgrade_url          = $this->custom_plugin_data->freemius_upgrade_url;
		$this->freemius_discount_upgrade_url = $this->custom_plugin_data->freemius_discount_upgrade_url;
		$this->new_features_url              = $this->custom_plugin_data->new_features_url;
		$this->admin_url                     = $this->custom_plugin_data->admin_url;
		$this->utility                       = $utility;

		// $this->pro_attribute = '<span class="pro" title="Shortcode attribute available in ' . $this->custom_plugin_data->main_menu_label . ' Pro"><a href="' . $this->freemius_upgrade_url . '">PRO</a></span>';
		// $this->settings_slug = $this->custom_plugin_data->settings_pages['settings']['slug'];
		// $this->new_features_slug = $this->custom_plugin_data->settings_pages['new-features']['slug'];
		$this->welcome_slug = $this->custom_plugin_data->settings_pages['welcome']['slug'];
		$this->plugin_data  = $plugin_data;

		add_action( 'admin_menu', array( &$this, 'add_options_page' ) );
	}

	/**
	 * Add menu page.
	 */
	public function add_options_page() {
		$parent_slug = null;

		if ( FFAQ_FREEMIUS_NAVIGATION === 'tabs' ) {
			// Only show submenu page when tabs enabled if welcome tab is active.
			if ( isset( $_GET['page'] ) && $_GET['page'] === $this->welcome_slug ) {
				$parent_slug = $this->custom_plugin_data->parent_slug;
			}
		} else {
			// Always use this if navigation is set to 'menu'.
			$parent_slug = $this->custom_plugin_data->parent_slug;
		}

		if ( 'top' === $this->custom_plugin_data->menu_type || 'top-cpt' === $this->custom_plugin_data->menu_type ) {
			$label = 'About';
		} elseif ( 'sub' === $this->custom_plugin_data->menu_type ) {
			$label = '<span class="fs-submenu-item fs-sub wpgo-plugins">About</span>';
		}

		$hook = add_submenu_page(
			$parent_slug,
			__( 'Welcome to ' . $this->custom_plugin_data->main_menu_label, 'flexible-faqs' ),
			$label,
			'manage_options',
			$this->welcome_slug,
			array( &$this, 'render_sub_menu_form' )
		);

	}

	/**
	 * Display the sub menu page.
	 */
	public function render_sub_menu_form() {

		$tabs_list_html        = $this->utility->build_settings_tabs_html( $this->plugin_data );
		$tab_classes           = FFAQ_FREEMIUS_NAVIGATION === 'tabs' ? ' fs-section fs-full-size-wrapper' : ' no-tabs';
		$is_premium            = $this->custom_plugin_data->is_premium;
				$plugin_lbl    = $this->custom_plugin_data->main_menu_label;
				$more_features = $is_premium ? 'View the full set of <a href="https://flexiblefaqs.com/docs/" target="_blank">shortcode attributes</a> available.' : 'See the <a href="' . $this->custom_plugin_data->main_settings_url . '">main settings</a> page for a list of shortcode attributes available in the free version (expand the <strong>Shortcode Attributes & Default Values</strong> section).';
		?>
				<div class="wrap <?php echo $tab_classes; ?> about-wrap">
					<?php echo $tabs_list_html; ?>
					<div class="wpgo-settings-inner about-con">
						<div class="header">
							<div class="header-img">
								<img src="<?php echo $this->module_roots['uri'] . '/assets/images/flexible-faqs-thumb.jpg'; ?>" />
							</div>
							<div class="sub-header">
								<div class="sub-header-title">
									<div>
										<h1 class="title">Welcome to <?php _e( $plugin_lbl . '!', 'flexible-faqs' ); ?></h1>
									</div>
									<div>
										<span class="dashicons dashicons-flag"></span>
										<span class="title-ver">v<?php echo $this->plugin_data['Version']; ?></span>
										<span style="display:none;" class="title-ver">v<?php echo $this->plugin_data['Version']; ?> | <a href="#">Changelog</a></span>
									</div>
								</div>
								<div class="title-desc">
									<p>This is a very exciting release for us. It's taken the best part of a year but we've finally got there! Lots of new features have been added, and many have been updated. Let's dig in and see what's new, and how you can quickly get started adding FAQs to your site.</p>
								</div>
							</div>
						</div>

						<?php if ( ! $is_premium ) : ?>
							<table class="premium-tbl">
								<tr>
									<td>
										<a href="<?php echo $this->freemius_discount_upgrade_url; ?>">
											<button class="button upgrade-txt-pc" title="Apply the exclusive discount offer right now">Upgrade to PRO - <span style="color:red;">30% OFF</span></button>
										</a>
									</td>
									<td>
										<div class="detail-cel">
											<strong>Exclusive discount offer for our FREE plugin users!</strong>
											Get immediate access to <a class="upgrade-link" href="<?php echo $this->freemius_upgrade_url; ?>" title="View the FULL list of pro plugin features" target="_blank">all Pro features</a> right now, at a significantly reduced price! <small>(first year only - renewals charged at normal rate)</small>
										</div>
									</td>
								</tr>
							</table>
						<?php endif; ?>

						<div class="plugin-desc-con">
							<div class="new-con plugin-des-item">
								<div class="new-fea-con-des">
									<h2 style="margin-top:25px;" class="sub-title">What's New in <?php echo $this->plugin_data['Version']; ?>?</h2>
									<p>To see all new major features for this plugin release, click the <span style="font-weight:bold;">'New Features'</span> button below for more details. You can also access the plugin documentation, and check out the the live FAQ demo examples via the other two buttons.</p>
									<div>
										<span><a class="plugin-btn" href="<?php echo $this->new_features_url; ?>">New Features<span style="margin:0 -2px 0 3px;width:18px;height:18px;" class="dashicons dashicons-arrow-right-alt2"></span></a></span>
										<span style="margin-left:5px;"><a style="background:#933c60;border:2px #6d314a solid;" class="plugin-btn" href="https://flexiblefaqs.com/docs/getting-started/" target="_blank">Plugin Docs</a></span>
										<span style="margin-left:5px;"><a style="background:#f5a356;border:2px #d9914e solid;" class="plugin-btn" href="https://flexiblefaqs.com/demo/accordion-faq-template/" target="_blank">FAQ Live Demo</a></span>
									</div>
							</div>

							<div class="new-fea-con-des">
									<h2 style="margin-top:25px;" class="sub-title">Breaking Changes!</h2>
									<p>This new version of the plugin (0.5.10) has been completely overhauled and is the result of almost a years work. As such, if you're upgrading from a previous version then you may experience some breaking changes.</p>
									<p>Existing sets of FAQs should not be affected but if you've added an FAQ block to a page then we recommend deleting it and re-adding it to make sure there are no issues. For shortcode users some attributes have been updated so please check your shortcode attributes against the list in the <a href="https://flexiblefaqs.com/docs/getting-started/" target="_blank">plugin docs</a>.</p>
							</div>

							<div class="getting-start-con plugin-des-item">
								<h2 class="sub-title">Getting Started Using <?php echo $plugin_lbl; ?></h2>
								<p>Flexible FAQs is a complete solution to author and display any number of FAQs on your site. To get started quickly, follow these steps and you'll be creating FAQs in no time at all. For full instructions take a look at the plugin <a href="https://flexiblefaqs.com/docs/getting-started/" target="_blank">documentation</a>.</p>
								<div class="getting-start-gen-con">
									<div class="getting-start-gen">
										<h3 style="margin-top:0;display:flex;align-items:center;"><span><img style="margin:0 6px 2px 0;width:40px;" src="<?php echo $this->module_roots['uri'] . '/assets/images/icons/1s.svg'; ?>" /></span><span> Create some FAQs</span></h3>
										<p>The first thing to do is create a new set of FAQs! Either use <a href="<?php echo $this->admin_url . '/post-new.php?post_type=wpgo_faq'; ?>" target="_blank">this link</a> or go to <strong>Flexible FAQs > Add New FAQs</strong> via the WordPress admin.</p>
										<p>There, you can enter a title for your FAQs and create any number of items manually, or if you just want to see how it all works you can click the <strong>Add Sample FAQs</strong> link which will create some sample FAQs automatically for you!</p>
										<p>Once you've created a few FAQ items you can dynamically reorder them by clicking and dragging the hamburger icon to the left of the question text.</p>
									</div>
									<div class="getting-start-img">
										<img src="<?php echo $this->module_roots['uri'] . '/assets/images/getting-started-thumb.png'; ?>" />
									</div>
								</div>
								<div class="getting-start-gen-con">
									<div class="getting-start-gen">
									<h3 style="margin-top:0;display:flex;align-items:center;"><span><img style="margin:0 6px 2px 0;width:40px;" src="<?php echo $this->module_roots['uri'] . '/assets/images/icons/2s.svg'; ?>" /></span><span> Insert Them Into a Page</span></h3>
										<p>There are two ways to add FAQs to a post or page:</p>
										<ul style="list-style:initial;padding-left:20px;">
											<li><a href="https://wordpress.org/support/article/adding-a-new-block/" target="_blank">Blocks</a></li>
											<li><a href="https://codex.wordpress.org/shortcode" target="_blank">Shortcodes</a></li>
										</ul>
										<p>You'll see all available FAQ blocks listed in the block inserter, along with all the other blocks. To find them quicker just start typing 'faq..' and you'll see the text, box, or accordion FAQ blocks appear in the list.</p>
										<p>FAQ shortcodes are included as they can be used in any page builder, which is very useful if you're not using the core block editor. Any block setting is also available as a shortcode attribute for convenience.</p>
									</div>
									<div class="getting-start-img">
										<img src="<?php echo $this->module_roots['uri'] . '/assets/images/add-faqs-to-page.png'; ?>" />
									</div>
								</div>
								<div class="getting-start-gen-con">
									<div class="getting-start-gen">
									<h3 style="margin-top:0;display:flex;align-items:center;"><span><img style="margin:0 6px 2px 0;width:40px;" src="<?php echo $this->module_roots['uri'] . '/assets/images/icons/3s.svg'; ?>" /></span><span> Customize & Display</span></h3>
										<p>Once you've inserted an FAQ block into the editor you can configure the block options (FAQ theme, font, spacing etc.) via the settings sidebar panel to the right.</p>
										<p>There are many options to choose from so take your time looking through each settings panel. One cool option in-particular is being able to customize FAQ themes. This saves you a ton of time as you can use any existing theme as a starting point!</p>
									</div>
									<div class="getting-start-img">
										<img src="<?php echo $this->module_roots['uri'] . '/assets/images/text-faq-block.png'; ?>" />
									</div>
								</div>
								<div class="getting-start-gen-con">
									<div class="getting-start-gen">
									<h3 style="margin-top:0;display:flex;align-items:center;"><span><img style="margin:0 6px 2px 0;width:40px;" src="<?php echo $this->module_roots['uri'] . '/assets/images/icons/4s.svg'; ?>" /></span><span> Let's Get Started!</span></h3>
									<p>OK, time to get started. What would you like to do first? <span class="dashicons dashicons-smiley"></span></p>
										<div>
											<div><a class="plugin-btn get-started-btn" href="<?php echo $this->admin_url . '/post-new.php?post_type=wpgo_faq'; ?>" target="_blank"><span style="margin:0 -2px 0 3px;width:18px;height:18px;" class="dashicons dashicons-arrow-right-alt2"></span><span class="get-started-txt">Create a new set of FAQs</span></a></div>
											<div><a class="plugin-btn get-started-btn" href="https://flexiblefaqs.com/docs/getting-started/" target="_blank"><span style="margin:0 -2px 0 3px;width:18px;height:18px;" class="dashicons dashicons-arrow-right-alt2"></span><span class="get-started-txt">View plugin documentation</span></a></div>
											<div><a class="plugin-btn get-started-btn" href="https://flexiblefaqs.com/demo/accordion-faq-template/" target="_blank"><span style="margin:0 -2px 0 3px;width:18px;height:18px;" class="dashicons dashicons-arrow-right-alt2"></span><span class="get-started-txt">See some FAQ examples</span></a></div>
											<div><a class="plugin-btn get-started-btn" href="<?php echo $this->custom_plugin_data->contact_us_url; ?>" target="_blank"><span style="margin:0 -2px 0 3px;width:18px;height:18px;" class="dashicons dashicons-arrow-right-alt2"></span><span class="get-started-txt">Ask us a question</span></a></div>
										</div>
									</div>
								</div>
							</div>
							<div class="coming-soon-con">
								<h2 class="sub-title">Coming Soon</h2>
								<p>We're not done yet! There's still lot's more feature we want to add to <?php echo $plugin_lbl; ?>. Some of the upcoming features include:</p>
								<ul class="coming-soon-ul">
									<li>Reset multiple colors at once.</li>
									<li>Add even more FAQ themes (already 100 themes available!).</li>
									<li>Submit FAQs from the front end.</li>
									<li>Support for background gradient colors.</li>
									<li>More expand/collapse FAQ icons.</li>
									<li>Import/export FAQs.</li>
									<li><strong><em>Plus many more...</em></strong></li>
								</ul>
								<p>If you'd like to be notified of all plugin changes as soon as they are available then please <a href="http://eepurl.com/g3PxkD" target="_blank">signup to our newsletter</a>.</p>
								<p>Or, if you'd like to see a feature added then why not drop us a line? We always like to hear how our plugins can be improved. Click the button below to send us a message and tell us what's on your mind.</a></p>
								<p><a href="<?php echo $this->custom_plugin_data->contact_us_url; ?>"><button class="button"><strong>Suggest a Feature</strong></button></a></p>
							</div>
						</div>
					</div>
				</div>
				<?php
	}

} /* End class definition */
