<?php
/**
 * Forumax Setup Wizard Template
 *
 * Single-page multi-step wizard — all steps rendered in HTML,
 * JavaScript handles transitions with no page reloads.
 *
 * @package Forumax
 * @since   2.2.0
 */

defined( 'ABSPATH' ) || exit;

$steps = [
	1 => [ 'label' => __( 'Welcome',     'forumax' ) ],
	2 => [ 'label' => __( 'Forum Setup', 'forumax' ) ],
	3 => [ 'label' => __( 'Appearance',  'forumax' ) ],
	4 => [ 'label' => __( 'Ready!',      'forumax' ) ],
];
$total_steps = count( $steps );

/* Retrieve the currently saved brand color (CSF option) for the color picker default. */
$csf_options = get_option( 'bbp_core_settings', [] );
$brand_color = ! empty( $csf_options['bbpc_brand_color'] ) ? $csf_options['bbpc_brand_color'] : '#6a28ea';
?>
<div class="wrap forumax-setup-wrap">

	<?php /* ── Top Bar ── */ ?>
	<div class="forumax-setup-topbar">
		<div class="forumax-setup-logo">
			<img src="<?php echo esc_url( FORUMAX_IMG . 'logo.svg' ); ?>"
				alt="<?php esc_attr_e( 'Forumax', 'forumax' ); ?>">
		</div>
		<a href="<?php echo esc_url( admin_url( 'admin.php?page=forumax' ) ); ?>"
		   class="forumax-btn-skip-top forumax-btn-skip-wizard">
			<?php esc_html_e( 'Skip Setup', 'forumax' ); ?>
		</a>
	</div>

	<?php /* ── Step Indicator ── */ ?>
	<div class="forumax-setup-steps-bar">
		<div class="forumax-progress-steps">
			<?php foreach ( $steps as $step_num => $step_data ) : ?>
				<div class="forumax-progress-step <?php echo $step_num === 1 ? 'active' : ''; ?>"
				     data-step="<?php echo esc_attr( $step_num ); ?>">
					<div class="forumax-step-circle">
						<span class="frmx-step-number"><?php echo esc_html( $step_num ); ?></span>
						<span class="frmx-step-check dashicons dashicons-yes"></span>
					</div>
					<span class="forumax-step-label"><?php echo esc_html( $step_data['label'] ); ?></span>
				</div>
			<?php endforeach; ?>
		</div>
	</div>

	<?php /* ── Wizard Card ── */ ?>
	<div class="forumax-setup-card" data-total-steps="<?php echo esc_attr( $total_steps ); ?>">

		<div class="forumax-setup-card-body">

			<?php /* ── Step 1: Welcome ── */ ?>
			<div class="forumax-setup-step forumax-step-welcome" data-step="1">
				<span class="forumax-welcome-emoji">🎉</span>
				<h2 class="forumax-setup-step-title">
					<?php esc_html_e( 'Welcome to Forumax!', 'forumax' ); ?>
				</h2>
				<p class="forumax-setup-step-desc">
					<?php esc_html_e( 'Thank you for choosing Forumax — the most powerful forum plugin for WordPress. Let\'s get your community set up in just a few steps.', 'forumax' ); ?>
				</p>

				<div class="forumax-feature-grid">
					<div class="forumax-feature-item">
						<div class="forumax-feature-icon">
							<span class="dashicons dashicons-admin-tools"></span>
						</div>
						<h3><?php esc_html_e( 'Easy Setup', 'forumax' ); ?></h3>
						<p><?php esc_html_e( 'Configure your forum with our intuitive wizard', 'forumax' ); ?></p>
					</div>
					<div class="forumax-feature-item">
						<div class="forumax-feature-icon">
							<span class="dashicons dashicons-layout"></span>
						</div>
						<h3><?php esc_html_e( 'Beautiful Design', 'forumax' ); ?></h3>
						<p><?php esc_html_e( 'Modern, responsive templates for every device', 'forumax' ); ?></p>
					</div>
					<div class="forumax-feature-item">
						<div class="forumax-feature-icon">
							<span class="dashicons dashicons-groups"></span>
						</div>
						<h3><?php esc_html_e( 'Community', 'forumax' ); ?></h3>
						<p><?php esc_html_e( 'Advanced features to engage your community', 'forumax' ); ?></p>
					</div>
				</div>

				<div class="forumax-info-box">
					<span class="dashicons dashicons-info"></span>
					<div>
						<strong><?php esc_html_e( 'Note:', 'forumax' ); ?></strong>
						<?php esc_html_e( 'You can skip this setup and configure everything later from the settings page.', 'forumax' ); ?>
					</div>
				</div>
			</div>

			<?php /* ── Step 2: Forum Setup (merged from old Steps 2 + 3) ── */ ?>
			<div class="forumax-setup-step forumax-step-forum" data-step="2">
				<h2 class="forumax-setup-step-title">
					<?php esc_html_e( 'Create Your First Forum', 'forumax' ); ?>
				</h2>
				<p class="forumax-setup-step-desc">
					<?php esc_html_e( 'Let\'s create your first forum to get the community started.', 'forumax' ); ?>
				</p>

				<div class="forumax-section">
					<h3 class="forumax-section-heading"><?php esc_html_e( 'Forum Details', 'forumax' ); ?></h3>
					<p class="forumax-section-subheading"><?php esc_html_e( 'Name and describe your first forum category.', 'forumax' ); ?></p>

					<div class="forumax-setup-form">
						<div class="forumax-form-group">
							<label for="create_forum"><?php esc_html_e( 'Forum Title', 'forumax' ); ?></label>
							<input type="text" id="create_forum" name="create_forum"
								placeholder="<?php esc_attr_e( 'e.g., General Discussion', 'forumax' ); ?>"
								value="<?php echo esc_attr( get_option( 'forumax_wizard_create_forum', __( 'General Discussion', 'forumax' ) ) ); ?>">
							<p class="forumax-field-description"><?php esc_html_e( 'Name of your first forum category', 'forumax' ); ?></p>
						</div>

						<div class="forumax-form-group">
							<label for="forum_description"><?php esc_html_e( 'Forum Description', 'forumax' ); ?></label>
							<textarea id="forum_description" name="forum_description" rows="3"
								placeholder="<?php esc_attr_e( 'Brief description of your community', 'forumax' ); ?>"><?php echo esc_textarea( get_option( 'forumax_wizard_forum_description', '' ) ); ?></textarea>
							<p class="forumax-field-description"><?php esc_html_e( 'Help users understand what they can discuss here', 'forumax' ); ?></p>
						</div>
					</div>
				</div>

				<div class="forumax-section">
					<h3 class="forumax-section-heading"><?php esc_html_e( 'Quick Setup', 'forumax' ); ?></h3>
					<p class="forumax-section-subheading"><?php esc_html_e( 'Choose how you\'d like to get started.', 'forumax' ); ?></p>

					<div class="forumax-option-cards">
						<label class="forumax-option-card">
							<input type="radio" name="setup_type" value="single" <?php checked( get_option( 'forumax_wizard_setup_type', 'single' ), 'single' ); ?>>
							<div class="forumax-option-content">
								<span class="dashicons dashicons-admin-post"></span>
								<h4><?php esc_html_e( 'Single Forum', 'forumax' ); ?></h4>
								<p><?php esc_html_e( 'Create one forum to start', 'forumax' ); ?></p>
							</div>
						</label>
						<label class="forumax-option-card">
							<input type="radio" name="setup_type" value="sample" <?php checked( get_option( 'forumax_wizard_setup_type', 'single' ), 'sample' ); ?>>
							<div class="forumax-option-content">
								<span class="dashicons dashicons-download"></span>
								<h4><?php esc_html_e( 'Sample Data', 'forumax' ); ?></h4>
								<p><?php esc_html_e( 'Import demo content', 'forumax' ); ?></p>
							</div>
						</label>
						<label class="forumax-option-card">
							<input type="radio" name="setup_type" value="skip" <?php checked( get_option( 'forumax_wizard_setup_type', 'single' ), 'skip' ); ?>>
							<div class="forumax-option-content">
								<span class="dashicons dashicons-controls-forward"></span>
								<h4><?php esc_html_e( 'Skip for Now', 'forumax' ); ?></h4>
								<p><?php esc_html_e( 'Set up manually later', 'forumax' ); ?></p>
							</div>
						</label>
					</div>
				</div>

				<div class="forumax-section">
					<h3 class="forumax-section-heading"><?php esc_html_e( 'Essential Pages', 'forumax' ); ?></h3>
					<p class="forumax-section-subheading"><?php esc_html_e( 'Forumax needs a few WordPress pages to display your forum.', 'forumax' ); ?></p>

					<div class="forumax-toggle-rows">
						<label class="forumax-toggle-row">
							<input type="checkbox" name="create_pages" value="1" <?php checked( get_option( 'forumax_wizard_create_pages', '1' ), '1' ); ?>>
							<div class="frmx-row-icon"><span class="dashicons dashicons-admin-page"></span></div>
							<div class="frmx-row-body">
								<span class="frmx-row-title"><?php esc_html_e( 'Auto-Create Forum Pages', 'forumax' ); ?></span>
								<span class="frmx-row-desc"><?php esc_html_e( 'Automatically create the required Forum and Topics pages if they don\'t exist yet', 'forumax' ); ?></span>
							</div>
							<span class="frmx-toggle-switch"></span>
						</label>
					</div>
				</div>
			</div>

			<?php /* ── Step 3: Appearance ── */ ?>
			<div class="forumax-setup-step forumax-step-appearance" data-step="3">
				<h2 class="forumax-setup-step-title">
					<?php esc_html_e( 'Customize Appearance', 'forumax' ); ?>
				</h2>
				<p class="forumax-setup-step-desc">
					<?php esc_html_e( 'Choose the perfect look for your forum. You can change these anytime from Settings.', 'forumax' ); ?>
				</p>

				<div class="forumax-section">
					<h3 class="forumax-section-heading"><?php esc_html_e( 'Brand Color', 'forumax' ); ?></h3>
					<p class="forumax-section-subheading"><?php esc_html_e( 'Pick a primary color that matches your brand. This color is used throughout the forum.', 'forumax' ); ?></p>

					<div class="forumax-setup-form">
						<div class="forumax-form-group forumax-color-field">
							<label for="brand_color"><?php esc_html_e( 'Primary Color', 'forumax' ); ?></label>
							<div class="forumax-color-input-wrap">
								<input type="color" id="brand_color" name="brand_color"
									value="<?php echo esc_attr( $brand_color ); ?>">
								<input type="text" id="brand_color_hex" name="brand_color_hex"
									value="<?php echo esc_attr( $brand_color ); ?>"
									class="forumax-color-hex-input"
									maxlength="7"
									pattern="^#([A-Fa-f0-9]{6})$"
									placeholder="#6a28ea">
							</div>
							<p class="forumax-field-description"><?php esc_html_e( 'Used for buttons, links, and accents across the forum frontend', 'forumax' ); ?></p>
						</div>
					</div>
				</div>

				<div class="forumax-section">
					<h3 class="forumax-section-heading"><?php esc_html_e( 'Forum Layout Style', 'forumax' ); ?></h3>
					<p class="forumax-section-subheading"><?php esc_html_e( 'Select how forum topics and discussions are displayed.', 'forumax' ); ?></p>

					<div class="forumax-layout-grid">
						<label class="forumax-layout-option">
							<input type="radio" name="layout_style" value="classic" <?php checked( get_option( 'forumax_wizard_layout_style', 'classic' ), 'classic' ); ?>>
							<div class="forumax-layout-preview">
								<div class="forumax-layout-preview-img forumax-preview-classic">
									<span class="dashicons dashicons-menu"></span>
								</div>
								<div class="forumax-layout-info">
									<span class="forumax-layout-title"><?php esc_html_e( 'Classic', 'forumax' ); ?></span>
									<span class="forumax-layout-desc"><?php esc_html_e( 'Traditional forum layout', 'forumax' ); ?></span>
								</div>
							</div>
						</label>
						<label class="forumax-layout-option">
							<input type="radio" name="layout_style" value="modern" <?php checked( get_option( 'forumax_wizard_layout_style', 'classic' ), 'modern' ); ?>>
							<div class="forumax-layout-preview">
								<div class="forumax-layout-preview-img forumax-preview-modern">
									<span class="dashicons dashicons-grid-view"></span>
								</div>
								<div class="forumax-layout-info">
									<span class="forumax-layout-title"><?php esc_html_e( 'Modern', 'forumax' ); ?></span>
									<span class="forumax-layout-desc"><?php esc_html_e( 'Clean grid layout', 'forumax' ); ?></span>
								</div>
							</div>
						</label>
						<label class="forumax-layout-option">
							<input type="radio" name="layout_style" value="card" <?php checked( get_option( 'forumax_wizard_layout_style', 'classic' ), 'card' ); ?>>
							<div class="forumax-layout-preview">
								<div class="forumax-layout-preview-img forumax-preview-card">
									<span class="dashicons dashicons-images-alt2"></span>
								</div>
								<div class="forumax-layout-info">
									<span class="forumax-layout-title"><?php esc_html_e( 'Card Style', 'forumax' ); ?></span>
									<span class="forumax-layout-desc"><?php esc_html_e( 'Card-based design', 'forumax' ); ?></span>
								</div>
							</div>
						</label>
					</div>
				</div>

				<div class="forumax-section">
					<div class="forumax-advanced-box">
						<span class="frmx-adv-icon">💡</span>
						<div class="frmx-adv-body">
							<span class="frmx-adv-title"><?php esc_html_e( 'Advanced Configuration', 'forumax' ); ?></span>
							<span class="frmx-adv-desc"><?php esc_html_e( 'More appearance options (colors, fonts, custom CSS) can be configured in the full Settings panel after completing this wizard.', 'forumax' ); ?></span>
							<a href="<?php echo esc_url( admin_url( 'admin.php?page=forumax-settings' ) ); ?>" class="frmx-adv-link">
								<?php esc_html_e( 'View Appearance Settings', 'forumax' ); ?> →
							</a>
						</div>
					</div>
				</div>
			</div>

			<?php /* ── Step 4: Complete ── */ ?>
			<div class="forumax-setup-step forumax-step-complete" data-step="4">
				<div class="forumax-success-circle">
					<span class="dashicons dashicons-yes"></span>
				</div>
				<h2 class="forumax-complete-title">
					<?php esc_html_e( 'Setup Complete!', 'forumax' ); ?>
				</h2>
				<p class="forumax-complete-desc">
					<?php esc_html_e( 'Your forum is ready to go. Here\'s what you can do next:', 'forumax' ); ?>
				</p>

				<div class="forumax-next-steps">
					<a href="<?php echo esc_url( admin_url( 'post-new.php?post_type=forum' ) ); ?>" class="forumax-next-step-card">
						<div class="forumax-next-step-icon">
							<span class="dashicons dashicons-plus-alt"></span>
						</div>
						<div class="forumax-next-step-content">
							<h3><?php esc_html_e( 'Create More Forums', 'forumax' ); ?></h3>
							<p><?php esc_html_e( 'Add more forum categories to your community', 'forumax' ); ?></p>
						</div>
						<span class="dashicons dashicons-arrow-right-alt2"></span>
					</a>

					<a href="<?php echo esc_url( admin_url( 'admin.php?page=forumax-settings' ) ); ?>" class="forumax-next-step-card">
						<div class="forumax-next-step-icon">
							<span class="dashicons dashicons-admin-settings"></span>
						</div>
						<div class="forumax-next-step-content">
							<h3><?php esc_html_e( 'Configure Settings', 'forumax' ); ?></h3>
							<p><?php esc_html_e( 'Fine-tune your forum settings and appearance', 'forumax' ); ?></p>
						</div>
						<span class="dashicons dashicons-arrow-right-alt2"></span>
					</a>

					<a href="<?php echo esc_url( admin_url( 'admin.php?page=forumax' ) ); ?>" class="forumax-next-step-card">
						<div class="forumax-next-step-icon">
							<span class="dashicons dashicons-dashboard"></span>
						</div>
						<div class="forumax-next-step-content">
							<h3><?php esc_html_e( 'Go to Dashboard', 'forumax' ); ?></h3>
							<p><?php esc_html_e( 'View your forum stats and activity', 'forumax' ); ?></p>
						</div>
						<span class="dashicons dashicons-arrow-right-alt2"></span>
					</a>

					<a href="https://helpdesk.spider-themes.net/docs/forumax-wordpress-plugin/" target="_blank" rel="noopener noreferrer" class="forumax-next-step-card">
						<div class="forumax-next-step-icon">
							<span class="dashicons dashicons-book"></span>
						</div>
						<div class="forumax-next-step-content">
							<h3><?php esc_html_e( 'Read Documentation', 'forumax' ); ?></h3>
							<p><?php esc_html_e( 'Learn about all available features', 'forumax' ); ?></p>
						</div>
						<span class="dashicons dashicons-external"></span>
					</a>
				</div>
			</div>

		</div><!-- .forumax-setup-card-body -->

		<?php /* ── Card Footer / Navigation ── */ ?>
		<div class="forumax-setup-card-footer">
			<button type="button" class="forumax-btn forumax-btn-secondary forumax-btn-prev">
				<span class="dashicons dashicons-arrow-left-alt2"></span>
				<?php esc_html_e( 'Back', 'forumax' ); ?>
			</button>

			<button type="button" class="forumax-btn forumax-btn-primary forumax-btn-next">
				<?php esc_html_e( 'Continue', 'forumax' ); ?>
				<span class="dashicons dashicons-arrow-right-alt2"></span>
			</button>

			<a href="<?php echo esc_url( admin_url( 'admin.php?page=forumax' ) ); ?>"
			   class="forumax-btn forumax-btn-primary forumax-btn-finish">
				<?php esc_html_e( 'Go to Dashboard', 'forumax' ); ?>
				<span class="dashicons dashicons-arrow-right-alt2"></span>
			</a>
		</div>

	</div><!-- .forumax-setup-card -->

	<?php if ( ! forumax_is_premium() ) : ?>
		<div class="forumax-upgrade-banner">
			<div class="forumax-upgrade-content">
				<span class="dashicons dashicons-star-filled"></span>
				<div>
					<h3><?php esc_html_e( 'Unlock Premium Features', 'forumax' ); ?></h3>
					<p><?php esc_html_e( 'Get private replies, voting system, advanced attachments, and more!', 'forumax' ); ?></p>
				</div>
			</div>
			<a href="<?php echo esc_url( bc_fs()->get_upgrade_url() ); ?>" class="forumax-btn-upgrade">
				<?php esc_html_e( 'Upgrade to Pro', 'forumax' ); ?>
				<span class="dashicons dashicons-arrow-right-alt"></span>
			</a>
		</div>
	<?php endif; ?>

</div><!-- .forumax-setup-wrap -->
