<?php

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

$setup_complete = ! get_option( 'smp_show_setup' );


$is_license_activated = ! smp_fs()->is_premium() || smp_fs()->is_trial() || smp_fs()->has_active_valid_license();


global $wpdb;

$players_count            = $wpdb->get_var( "SELECT COUNT(*) FROM `{$wpdb->prefix}smp_players`" );

$is_player_created = ! empty( $players_count);

$should_finish = $is_license_activated && $is_player_created;

$plugin_install_url = admin_url( 'plugin-install.php?tab=plugin-information&plugin=soft-multimedia-player&TB_iframe=true&width=600&height=550' );
$plugin_upload_url  = admin_url( 'plugin-install.php?tab=upload' );

$license_url         = smp_fs()->get_account_url();
$player_builder_url  = admin_url( 'admin.php?page=soft-multimedia-player' );
$finish_url          = admin_url( 'admin.php?page=soft-multimedia-player' );

$steps = [
	[
		'id'                => 'download-install',
		'title'             => __( 'Download & Install', 'soft-multimedia-player' ),
		'description'       => __( 'Download the plugin and install it via admin dashboard', 'soft-multimedia-player' ),
		'url'               => $plugin_install_url,
		'doc_url'           => 'https://softlabbd.com/docs/how-to-purchase-soft-multimedia-player-pro-version-and-activate-pro-license/',
		'video_url'         => '#',
		'render'            => true,
		'checked_condition' => true, // always checked
	],
	[
		'id'                => 'activate-license',
		'title'             => __( 'Activate License', 'soft-multimedia-player' ),
		'description'       => __( 'If you have purchased the premium version, activate license to unlock all features', 'soft-multimedia-player' ),
		'url'               => $license_url,
		'doc_url'           => 'https://softlabbd.com/docs/how-to-purchase-soft-multimedia-player-pro-version-and-activate-pro-license/',
		'video_url'         => '#',
		'render'            => smp_fs()->is_premium(),
		'checked_condition' => $is_license_activated,
	],

	[
		'id'                => 'create-players',
		'title'             => __( 'Create Players', 'soft-multimedia-player' ),
		'description'       => __( 'Create custom Audio, Video, or Podcast players', 'soft-multimedia-player' ),
		'url'               => $player_builder_url,
		'doc_url'           => 'https://softlabbd.com/docs/how-to-use-soft-multimedia-player-shortcode-builder-brief/',
		'video_url'         => '#',
		'render'            => true,
		'checked_condition' => $is_player_created,
//		'checked_condition' => false,
	],
	[
		'id'                => 'display-players',
		'title'             => __( 'Display & Share Players', 'soft-multimedia-player' ),
		'description'       => __( 'Display & share your created player across WordPress', 'soft-multimedia-player' ),
		'url'               => $player_builder_url,
		'doc_url'           => 'https://softlabbd.com/docs/how-to-use-soft-multimedia-player-shortcode-builder-brief/',
		'video_url'         => '#',
		'render'            => true,
		'checked_condition' => false,
	],
	[
		'id'                => 'finish',
		'title'             => __( 'Explore And Enjoy Features', 'soft-multimedia-player' ),
		'description'       => __( 'Explore the powerful features of the Multimedia Player plugin.', 'soft-multimedia-player' ),
		'url'               => '#',
		'doc_url'           => 'https://softlabbd.com/docs/',
		'video_url'         => 'https://softlabbd.com/support/',
		'render'            => true,
		'checked_condition' => false,
		'is_finish'         => true,
	],
];

if ( ! $is_license_activated ) {
	smp_fs()->_add_license_action_link();
	smp_fs()->_add_license_activation();
}

?>

<div class="content-heading heading-get-started">
    <h2><?php printf( __( '%s Get Started %s', 'soft-multimedia-player' ), '<mark>', '</mark>' ); ?></h2>
</div>

<section class="section-get-started section-half">
    <div class="col-description">

        <div class="timeline-container">

            <div class="timeline-rail"></div>

			<?php
			$step_number = 1;
			foreach ( $steps as $step ) :
				if ( empty( $step['render'] ) ) {
					continue;
				}
				?>

                <div class="timeline-item timeline-step-<?php echo esc_attr( $step['id'] ); ?>">

                    <div class="timeline-step">
                        <div class="circle">
							<?php echo esc_html( $step_number ); ?>

							<?php if ( ( $step['checked_condition'] ) || $should_finish ): ?>
                                <div class="checked">
                                    <i class="dashicons dashicons-saved"></i>
                                </div>
							<?php endif; ?>

                        </div>
                        <div class="connector"></div>
                    </div>

                    <div class="timeline-content-wrap">

                        <div class="timeline-header">
                            <img src="<?php echo esc_url( SOFT_MULTIMEDIA_PLAYER_ASSETS . "/images/dashboard/timeline/{$step['id']}.png" ); ?>"
                                 alt="<?php echo esc_attr( $step['title'] ); ?>">

                            <div class="timeline-content">

                                <div class="timeline-content-header">
                                    <strong><?php echo esc_html( $step['title'] ); ?></strong>

									<?php if ( ! $is_license_activated && 'activate-license' == $step['id'] ) { ?>
                                        <span class="smp-btn btn-primary activate-license soft-multimedia-player">
                                            <i class="dashicons dashicons-admin-network"></i>
											<?php esc_html_e( 'Activate License', 'soft-multimedia-player' ); ?>
                                        </span>
									<?php } ?>

									<?php if (! $is_player_created && 'create-players' == $step['id'] ) { ?>
                                        <a href="<?php echo esc_url( $step['url'] ); ?>" class="smp-btn btn-primary">
                                            <i class="dashicons dashicons-plus"></i>
											<?php esc_html_e( 'Create First Module', 'soft-multimedia-player' ); ?>
                                        </a>
									<?php } ?>

									<?php if ( $should_finish && 'finish' == $step['id'] ) { ?>
                                        <button type="button" class="smp-btn btn-primary btn-finish">
                                            <i class="dashicons dashicons-saved"></i>
											<?php esc_html_e( 'Finish', 'soft-multimedia-player' ); ?>
                                        </button>
									<?php } ?>

                                </div>

                                <p><?php echo esc_html( $step['description'] ); ?></p>
                            </div>

                            <i class="timeline-content-toggle dashicons dashicons-arrow-down-alt2"></i>
                        </div>

                        <div class="timeline-body">

							<?php if ( 'download-install' === $step['id'] ) { ?>
                                <p><?php
									/* translators: Installing Integrate Google Drive plugin */
									esc_html_e( 'Follow these simple steps to install and activate the Integrate Google Drive plugin.', 'soft-multimedia-player' );
									?></p>

                                <h4><?php esc_html_e( 'Installing the FREE Version:', 'soft-multimedia-player' ); ?></h4>
                                <ol>
                                    <li><?php esc_html_e( 'Log in to your WordPress admin dashboard.', 'soft-multimedia-player' ); ?></li>
                                    <li><?php
										printf(
											__( 'Navigates to %s.', 'soft-multimedia-player' ),
											'<a href="' . $plugin_install_url . '"><strong>Plugins > Add New</strong></a>' );
										?>
                                    </li>
                                    <li><?php esc_html_e( 'Search for the Soft Multimedia Player.', 'soft-multimedia-player' ); ?></li>
                                    <li><?php esc_html_e( 'Click Install Now next to the plugin.', 'soft-multimedia-player' ); ?></li>
                                    <li><?php esc_html_e( 'Once installed, click Activate.', 'soft-multimedia-player' ); ?></li>
                                    <li><?php esc_html_e( 'A confirmation message will appear once the plugin is successfully activated.', 'soft-multimedia-player' ); ?></li>
                                </ol>

                                <h4><?php esc_html_e( 'Install PRO Version:', 'soft-multimedia-player' ); ?></h4>
                                <ol>
                                    <li><?php esc_html_e( 'After completing your purchase, you will receive a confirmation email with a Premium download link and license key.', 'soft-multimedia-player' ); ?></li>
                                    <li>
										<?php
										printf(
											__( 'You can also get the PRO Download link and license key from the %s.', 'soft-multimedia-player' ),
											'<a href="https://users.freemius.com/store/1760/" target="_blank"><strong>Freemius Dashboard</strong></a>'
										);
										?>
                                    </li>
                                    <li><?php esc_html_e( 'Download the .zip file of the PRO plugin from the purchase confirmation email or the Freemius dashboard.', 'soft-multimedia-player' ); ?></li>
                                    <li><?php
										printf(
											__( 'In your WordPress admin dashboard, go to %s.', 'soft-multimedia-player' ),
											'<a href="' . $plugin_upload_url . '"><strong>Plugins > Add New > Upload Plugin</strong></a>' );
										?>
                                    </li>
                                    <li><?php esc_html_e( 'Upload the downloaded .zip file and click Install Now.', 'soft-multimedia-player' ); ?></li>
                                    <li><?php esc_html_e( 'After installation, activate the PRO plugin to enable its features.', 'soft-multimedia-player' ); ?></li>
                                </ol>

                                <p><?php
									esc_html_e( 'Once installed, you can create, display, and enjoy a multimedia player on your WordPress website.', 'soft-multimedia-player' );
									?></p>
							<?php } ?>

							<?php if ( 'activate-license' == $step['id'] ) { ?>
                                <p><?php esc_html_e( 'After installing the PRO plugin, follow these steps to activate your license and unlock all premium features.', 'soft-multimedia-player' ); ?></p>

                                <h4><?php esc_html_e( 'Activating the PRO License:', 'soft-multimedia-player' ); ?></h4>
                                <ol>
                                    <li><?php esc_html_e( 'After completing your purchase, you will receive a confirmation email with License Key & premium download link.', 'soft-multimedia-player' ); ?></li>
                                    <li>
										<?php
										printf(
											__( 'You can also get the License Key from the %s.', 'soft-multimedia-player' ),
											'<a href="https://users.freemius.com/store/1760/" target="_blank"><strong>Freemius Dashboard</strong></a>'
										);
										?>
                                    </li>
                                    <li><?php esc_html_e( 'Copy the license key from the purchase confirmation email or Freemius dashboard.', 'soft-multimedia-player' ); ?></li>
                                    <li><?php esc_html_e( 'Now after installing the PRO version you will be promted to activate your license key.', 'soft-multimedia-player' ); ?></li>
                                    <li><?php esc_html_e( 'Enter the license key into the activation field.', 'soft-multimedia-player' ); ?></li>
                                    <li><?php esc_html_e( 'Click Agree & Activate License to enable the PRO features.', 'soft-multimedia-player' ); ?></li>
                                </ol>

                                <p><?php
									esc_html_e( 'Once activated, you can start enjoying all the advanced features and enhanced capabilities of the PRO version.', 'soft-multimedia-player' );
									?></p>
							<?php } ?>

							<?php if ( 'create-players' == $step['id'] ) { ?>

								<p><?php esc_html_e('You can create multiple Audio, Video, or Podcast players and customize them as per requirement.', 'soft-multimedia-player'); ?></p>

								<p><?php esc_html_e('Navigate to Multimedia Player > All Players > Add New Player Select your preferred player type.', 'soft-multimedia-player'); ?></p>

                                <h4><?php esc_html_e( 'Available player types to create:', 'soft-multimedia-player' ); ?></h4>

                                <ol>
                                    <li>
                                        <strong><?php esc_html_e( 'Audio Player -', 'soft-multimedia-player' ); ?></strong>
										<?php esc_html_e( 'Stream MP3, WAV, and more with fully adjustable controls and styling.', 'soft-multimedia-player' ); ?>
                                    </li>
                                    <li>
                                        <strong><?php esc_html_e( 'Video Player -', 'soft-multimedia-player' ); ?></strong>
										<?php esc_html_e( 'Embed MP4, WebM, YouTube, Vimeo, or even Facebook videos effortlessly.', 'soft-multimedia-player' ); ?>
                                    </li>
                                    <li>
                                        <strong><?php esc_html_e( 'Podcast Player -', 'soft-multimedia-player' ); ?></strong>
										<?php esc_html_e( 'Optimized for podcasters to play local episodes or stream directly from RSS feeds.', 'soft-multimedia-player' ); ?>
                                    </li>
                                </ol>

							<?php } ?>

							<?php if ( 'display-players' == $step['id'] ) { ?>

                                <p><?php esc_html_e( 'You can display & share any created player using multiple methods. Read below to uncover all of them.', 'soft-multimedia-player' ); ?></p>

                                <h4><?php esc_html_e( 'Shortcode', 'soft-multimedia-player' ); ?></h4>
								<p><?php esc_html_e( 'Display the player anywhere using a simple shortcode. Perfect for posts, pages, or widgets.', 'soft-multimedia-player' ) ?></p>
                                <ol>
                                    <li><?php esc_html_e( 'Go to player settings.', 'soft-multimedia-player' ); ?></li>
                                    <li><?php esc_html_e( 'Copy the shortcode (e.g., [multimedia_player id="1"]).', 'soft-multimedia-player' ); ?></li>
                                    <li><?php esc_html_e( 'Paste it into any post, page, or widget.', 'soft-multimedia-player' ); ?></li>
                                    <li><?php esc_html_e( 'Save or update the content.', 'soft-multimedia-player' ); ?></li>
                                </ol>

								<h4><?php esc_html_e( 'Embed Code', 'soft-multimedia-player' ); ?></h4>
								<p><?php esc_html_e( 'Use HTML embed code to insert the player into custom areas or even external sites.', 'soft-multimedia-player' ) ?></p>
                                <ol>
                                    <li><?php esc_html_e( 'Copy the embed code from the player settings (3 dots button).', 'soft-multimedia-player' ); ?></li>
                                    <li><?php esc_html_e( 'Paste it into an HTML block or widget.', 'soft-multimedia-player' ); ?></li>
                                    <li><?php esc_html_e( 'Save the changes.', 'soft-multimedia-player' ); ?></li>
                                </ol>

								<h4><?php esc_html_e( 'Classic Editor Widget', 'soft-multimedia-player' ); ?></h4>
								<p><?php esc_html_e( 'Easily insert the player using the classic WordPress editor.', 'soft-multimedia-player' ) ?></p>
                                <ol>
                                    <li><?php esc_html_e( 'Open any post or page in Classic Editor.', 'soft-multimedia-player' ); ?></li>
                                    <li><?php esc_html_e( 'Click Multimedia Player Widget & Select a Player type.', 'soft-multimedia-player' ); ?></li>
                                    <li><?php esc_html_e( 'Save or publish the content.', 'soft-multimedia-player' ); ?></li>
                                </ol>

								<h4><?php esc_html_e( 'Gutenberg Block', 'soft-multimedia-player' ); ?></h4>
								<p><?php esc_html_e( 'Add the player using a dedicated block or shortcode block in the modern editor.', 'soft-multimedia-player' ) ?></p>
                                <ol>
                                    <li><?php esc_html_e( 'Open any post/page in the Gutenberg editor.', 'soft-multimedia-player' ); ?></li>
                                    <li><?php esc_html_e( 'Click “+” to add a block.', 'soft-multimedia-player' ); ?></li>
                                    <li><?php esc_html_e( 'Search for the "Multimedia Player" block and insert the block.', 'soft-multimedia-player' ); ?></li>
                                    <li><?php esc_html_e( 'Select your preferred player.', 'soft-multimedia-player' ); ?></li>
                                    <li><?php esc_html_e( 'Save or publish.', 'soft-multimedia-player' ); ?></li>
                                </ol>

								<h4><?php esc_html_e( 'Elementor Widget', 'soft-multimedia-player' ); ?></h4>
								<p><?php esc_html_e( 'Use the Elementor widget to drag and drop your player into any layout.', 'soft-multimedia-player' ) ?></p>
                                <ol>
                                    <li><?php esc_html_e( 'Open any page or post with Elementor.', 'soft-multimedia-player' ); ?></li>
                                    <li><?php esc_html_e( 'Search for “Multimedia Player” in the widget panel.', 'soft-multimedia-player' ); ?></li>
                                    <li><?php esc_html_e( 'Drag it into your design.', 'soft-multimedia-player' ); ?></li>
                                    <li><?php esc_html_e( 'Choose the player.', 'soft-multimedia-player' ); ?></li>
                                    <li><?php esc_html_e( 'Click Update or Publish.', 'soft-multimedia-player' ); ?></li>
                                </ol>
							<?php } ?>

							<?php if ( 'finish' == $step['id'] ) {
								if ( $should_finish ) {
									?>
                                    <p><?php esc_html_e( 'Congratulations! You have successfully set up Multimedia Player. Now you can explore and enjoy the powerful features it offers.', 'soft-multimedia-player' ); ?></p>
                                    <p><?php esc_html_e( 'If you need any help, please visit our support page or contact us directly.', 'soft-multimedia-player' ); ?></p>
									<?php
								} else { ?>
                                    <p><?php esc_html_e( 'You\'re almost there! Please complete all the setup steps to unlock the full power of Multimedia Player', 'soft-multimedia-player' ); ?></p>

                                    <p><?php esc_html_e( 'If you need assistance or have any questions, visit our support page or contact us anytime — we’re here to help!', 'soft-multimedia-player' ); ?></p>
								<?php }
							} ?>

                            <div class="timeline-body-actions">
                                <a href="<?php echo $step['doc_url'] ?>" target="_blank" class="smp-btn btn-info">
                                    <i class="dashicons dashicons-text-page"></i>
									<?php esc_html_e( 'Read Documentation', 'soft-multimedia-player' ); ?>
                                </a>
                                <a href="<?php echo $step['video_url'] ?>" target="_blank" class="smp-btn btn-info">

									<?php echo 'finish' == $step['id'] ? '<i class="dashicons dashicons-sos"></i>' : '<i class="dashicons dashicons-video-alt3"></i>'; ?>

									<?php echo 'finish' == $step['id'] ? esc_html__( 'Get Support', 'soft-multimedia-player' ) : esc_html__( 'Watch Video', 'soft-multimedia-player' ); ?>

                                </a>
                            </div>

                        </div>

                    </div>
                </div>

				<?php
				$step_number ++;
			endforeach;
			?>

        </div>

    </div>
</section>
