<?php
/**
 * FansPaysite Onboarding — Getting Started admin page.
 *
 * Displayed under Appearance > Getting Started in wp-admin.
 * Provides setup steps, recommended plugins, and documentation links.
 *
 * @package FansPaysite
 * @since   2.2
 */

/**
 * Register the Getting Started page under Appearance.
 */
function fanspaysite_register_onboarding_page() {
	add_theme_page(
		__( 'Getting Started', 'fanspaysite' ),
		__( 'Getting Started', 'fanspaysite' ),
		'edit_theme_options',
		'fanspaysite-getting-started',
		'fanspaysite_onboarding_page_html'
	);
}
add_action( 'admin_menu', 'fanspaysite_register_onboarding_page' );

/**
 * Show a one-time admin notice after theme activation.
 */
function fanspaysite_activation_notice() {
	if ( get_option( 'fanspaysite_activation_notice_dismissed' ) ) {
		return;
	}
	$screen = get_current_screen();
	if ( ! $screen || $screen->id !== 'themes' ) {
		return;
	}
	$url = admin_url( 'themes.php?page=fanspaysite-getting-started' );
	echo '<div class="notice notice-info is-dismissible" id="fanspaysite-welcome-notice">';
	echo '<p>' . sprintf(
		/* translators: %s: Getting Started page URL */
		__( 'Welcome to FansPaysite! <a href="%s">Get started here</a> to set up your site.', 'fanspaysite' ),
		esc_url( $url )
	) . '</p>';
	echo '</div>';
}
add_action( 'admin_notices', 'fanspaysite_activation_notice' );

/**
 * Dismiss the activation notice via AJAX.
 */
function fanspaysite_dismiss_activation_notice() {
	check_ajax_referer( 'fanspaysite_dismiss_notice', 'nonce' );
	if ( ! current_user_can( 'edit_theme_options' ) ) {
		wp_die();
	}
	update_option( 'fanspaysite_activation_notice_dismissed', true );
	wp_die();
}
add_action( 'wp_ajax_fanspaysite_dismiss_notice', 'fanspaysite_dismiss_activation_notice' );

/**
 * Inline script to dismiss notice via AJAX when the WP dismiss button is clicked.
 */
function fanspaysite_dismiss_notice_script() {
	$screen = get_current_screen();
	if ( ! $screen || $screen->id !== 'themes' ) {
		return;
	}
	if ( get_option( 'fanspaysite_activation_notice_dismissed' ) ) {
		return;
	}
	?>
	<script>
	jQuery(function($) {
		$(document).on('click', '#fanspaysite-welcome-notice .notice-dismiss', function() {
			$.post(ajaxurl, { action: 'fanspaysite_dismiss_notice', nonce: '<?php echo esc_js( wp_create_nonce( 'fanspaysite_dismiss_notice' ) ); ?>' });
		});
	});
	</script>
	<?php
}
add_action( 'admin_footer', 'fanspaysite_dismiss_notice_script' );

/**
 * Render the Getting Started page HTML.
 */
function fanspaysite_onboarding_page_html() {
	?>
	<div class="wrap">
		<h1><?php esc_html_e( 'Welcome to FansPaysite', 'fanspaysite' ); ?></h1>
		<p><?php esc_html_e( 'Thank you for choosing FansPaysite! Follow these steps to set up your creator platform.', 'fanspaysite' ); ?></p>

		<div style="display:grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap:20px; margin-top:20px;">

			<!-- Step 1 -->
			<div style="background:#fff; border:1px solid #c3c4c7; border-radius:4px; padding:20px;">
				<h2 style="margin-top:0;"><?php esc_html_e( '1. Choose Your Style', 'fanspaysite' ); ?></h2>
				<p><?php esc_html_e( 'Pick a pre-built skin (OnlyFans, Fansly, Patreon, etc.) to match your brand. Colors and layout can be fine-tuned later.', 'fanspaysite' ); ?></p>
				<a href="<?php echo esc_url( admin_url( 'themes.php?page=fanspaysite-skins' ) ); ?>" class="button button-primary">
					<?php esc_html_e( 'Browse Skins', 'fanspaysite' ); ?>
				</a>
			</div>

			<!-- Step 2 -->
			<div style="background:#fff; border:1px solid #c3c4c7; border-radius:4px; padding:20px;">
				<h2 style="margin-top:0;"><?php esc_html_e( '2. Set Up Navigation', 'fanspaysite' ); ?></h2>
				<p><?php esc_html_e( 'Create your primary menu. Each item can have a custom icon — the theme auto-maps 200+ common titles to FontAwesome icons.', 'fanspaysite' ); ?></p>
				<a href="<?php echo esc_url( admin_url( 'nav-menus.php' ) ); ?>" class="button button-primary">
					<?php esc_html_e( 'Edit Menus', 'fanspaysite' ); ?>
				</a>
			</div>

			<!-- Step 3 -->
			<div style="background:#fff; border:1px solid #c3c4c7; border-radius:4px; padding:20px;">
				<h2 style="margin-top:0;"><?php esc_html_e( '3. Customize Appearance', 'fanspaysite' ); ?></h2>
				<p><?php esc_html_e( 'Fine-tune colors, header style, layout, typography, and footer settings in the Customizer.', 'fanspaysite' ); ?></p>
				<a href="<?php echo esc_url( admin_url( 'customize.php' ) ); ?>" class="button button-primary">
					<?php esc_html_e( 'Open Customizer', 'fanspaysite' ); ?>
				</a>
			</div>

			<!-- Step 4 -->
			<div style="background:#fff; border:1px solid #c3c4c7; border-radius:4px; padding:20px;">
				<h2 style="margin-top:0;"><?php esc_html_e( '4. Create Pages', 'fanspaysite' ); ?></h2>
				<p><?php esc_html_e( 'Use the FansPaysite block patterns to quickly build pages: Creator Landing, FAQ, Testimonials, Blog Home, and more.', 'fanspaysite' ); ?></p>
				<a href="<?php echo esc_url( admin_url( 'post-new.php?post_type=page' ) ); ?>" class="button button-primary">
					<?php esc_html_e( 'Add New Page', 'fanspaysite' ); ?>
				</a>
			</div>

			<!-- Step 5 -->
			<div style="background:#fff; border:1px solid #c3c4c7; border-radius:4px; padding:20px;">
				<h2 style="margin-top:0;"><?php esc_html_e( '5. Set Homepage', 'fanspaysite' ); ?></h2>
				<p><?php esc_html_e( 'After creating your pages, set your homepage and posts page in Settings > Reading.', 'fanspaysite' ); ?></p>
				<a href="<?php echo esc_url( admin_url( 'options-reading.php' ) ); ?>" class="button button-primary">
					<?php esc_html_e( 'Reading Settings', 'fanspaysite' ); ?>
				</a>
			</div>

			<!-- Recommended Plugins -->
			<div style="background:#fff; border:1px solid #c3c4c7; border-radius:4px; padding:20px;">
				<h2 style="margin-top:0;"><?php esc_html_e( 'Recommended Plugins', 'fanspaysite' ); ?></h2>
				<p><?php esc_html_e( 'These plugins are optional but work well with FansPaysite:', 'fanspaysite' ); ?></p>
				<ul style="list-style:disc; padding-left:20px;">
					<li><?php esc_html_e( 'MicroPayments — Content monetization', 'fanspaysite' ); ?></li>
					<li><?php esc_html_e( 'Yoast SEO or Rank Math — SEO optimization', 'fanspaysite' ); ?></li>
					<li><?php esc_html_e( 'Elementor — Visual page builder (use the Blank Canvas template)', 'fanspaysite' ); ?></li>
					<li><?php esc_html_e( 'VideoWhisper Live Streaming — Live video features', 'fanspaysite' ); ?></li>
				</ul>
			</div>

		</div>

		<hr style="margin:30px 0;">

		<h2><?php esc_html_e( 'Recommended Image Sizes', 'fanspaysite' ); ?></h2>
		<table class="widefat" style="max-width:600px;">
			<tbody>
				<tr><td><strong><?php esc_html_e( 'Logo', 'fanspaysite' ); ?></strong></td><td>128 &times; 128 px</td></tr>
				<tr><td><strong><?php esc_html_e( 'Header Image', 'fanspaysite' ); ?></strong></td><td>1920 &times; 128 px</td></tr>
				<tr><td><strong><?php esc_html_e( 'Featured Image', 'fanspaysite' ); ?></strong></td><td>1200 &times; 630 px</td></tr>
				<tr><td><strong><?php esc_html_e( 'Default Thumbnail', 'fanspaysite' ); ?></strong></td><td>300 &times; 200 px</td></tr>
			</tbody>
		</table>

		<hr style="margin:30px 0;">

		<h2><?php esc_html_e( 'Page Templates', 'fanspaysite' ); ?></h2>
		<p><?php esc_html_e( 'FansPaysite includes two special page templates for page builders:', 'fanspaysite' ); ?></p>
		<ul style="list-style:disc; padding-left:20px;">
			<li><strong><?php esc_html_e( 'Full Width', 'fanspaysite' ); ?></strong> — <?php esc_html_e( 'No sidebars, full-width content area with header and footer.', 'fanspaysite' ); ?></li>
			<li><strong><?php esc_html_e( 'Blank Canvas', 'fanspaysite' ); ?></strong> — <?php esc_html_e( 'No header, footer, or sidebars. Perfect for Elementor landing pages.', 'fanspaysite' ); ?></li>
		</ul>

	</div>
	<?php
}
