<?php

/**
 * Provide a admin area view for the schema markup settings
 *
 * @link       https://yourwebsite.com
 * @since      1.0.0
 *
 * @package    Basic_SEO_Helper
 * @subpackage Basic_SEO_Helper/admin/partials
 */

// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Template variables are scoped to this included file, not global scope

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
	die;
}

$options = get_option( 'cspgbase_options', array() );

// Handle form submission
if ( isset( $_POST['submit'] ) && isset( $_POST['basic_seo_helper_schema_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['basic_seo_helper_schema_nonce'] ) ), 'basic_seo_helper_schema_settings' ) ) {
	$options = array_merge(
		$options,
		array(
			'default_schema_enabled' => isset( $_POST['default_schema_enabled'] ) ? '1' : '0',
		)
	);

	update_option( 'cspgbase_options', $options );
	echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( 'Schema markup settings saved successfully!', 'cspg-basic-seo-helper' ) . '</p></div>';
}
?>

<div class="wrap">
	<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
	
	<div class="basic-seo-helper-admin-wrapper">
		<!-- Schema Settings Form -->
		<div class="postbox">
			<div class="postbox-header">
				<h2><?php esc_html_e( 'Schema Settings', 'cspg-basic-seo-helper' ); ?></h2>
			</div>
			<div class="inside">
				<form method="post" action="">
					<?php wp_nonce_field( 'basic_seo_helper_schema_settings', 'basic_seo_helper_schema_nonce' ); ?>
					
					<table class="form-table">
						<tr>
							<th scope="row">
								<label for="default_schema_enabled"><?php esc_html_e( 'Schema Markup Default', 'cspg-basic-seo-helper' ); ?></label>
							</th>
							<td>
								<fieldset>
									<legend class="screen-reader-text"><span><?php esc_html_e( 'Default Schema Markup Setting', 'cspg-basic-seo-helper' ); ?></span></legend>
									<label for="default_schema_enabled">
										<input type="checkbox" id="default_schema_enabled" name="default_schema_enabled" value="1" <?php checked( $options['default_schema_enabled'] ?? '1', '1' ); ?> />
										<?php esc_html_e( 'Enable Schema markup by default for new posts and pages', 'cspg-basic-seo-helper' ); ?>
									</label>
									<p class="description"><?php esc_html_e( 'When creating new content, Schema markup will be enabled by default. You can still override this setting on individual posts and pages.', 'cspg-basic-seo-helper' ); ?></p>
								</fieldset>
							</td>
						</tr>
					</table>
					
					<?php submit_button(); ?>
				</form>
			</div>
		</div>
		
		<!-- Schema Markup Guide -->
		<div class="bsh-seo-elements-guide">
			<div class="bsh-guide-wrapper">
				<div class="bsh-guide-header">
					<h2><span class="bsh-guide-icon">🏗️</span><?php esc_html_e( 'Schema Markup Guide', 'cspg-basic-seo-helper' ); ?></h2>
					<p><?php esc_html_e( 'Schema markup is like structured labels that help search engines understand what your content is about. Think of it like putting clear, organized stickers on items in a store so customers can easily find what they\'re looking for.', 'cspg-basic-seo-helper' ); ?></p>
				</div>
				
				<div class="bsh-guide-columns">
					<div class="bsh-guide-column">
						<div class="bsh-guide-item">
							<h4><span class="bsh-guide-icon">🏢</span><?php esc_html_e( 'Organization Information', 'cspg-basic-seo-helper' ); ?></h4>
							<p><strong><?php esc_html_e( 'What It Creates:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'A digital "business card" for your website that search engines can use to display your business information.', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'Information Included:', 'cspg-basic-seo-helper' ); ?></strong><br>
							• <?php esc_html_e( 'Your business/website name', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Your website URL', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Your logo (if uploaded in General Settings)', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Links to your social media profiles', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'Why It Matters:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'Google can show this information in search results and create a "knowledge panel" for your business, making you more visible and credible.', 'cspg-basic-seo-helper' ); ?></p>
						</div>
						
						<div class="bsh-guide-item">
							<h4><span class="bsh-guide-icon">🌐</span><?php esc_html_e( 'Website Information', 'cspg-basic-seo-helper' ); ?></h4>
							<p><strong><?php esc_html_e( 'What It Creates:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'Basic details about your website that help search engines understand your site\'s purpose and content.', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'Information Included:', 'cspg-basic-seo-helper' ); ?></strong><br>
							• <?php esc_html_e( 'Website name and URL', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Website description (from WordPress tagline)', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Basic site structure information', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'Why It Matters:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'Helps search engines categorize and understand what your website is about, improving overall search visibility.', 'cspg-basic-seo-helper' ); ?></p>
						</div>
						
						<div class="bsh-guide-item">
							<h4><span class="bsh-guide-icon">📝</span><?php esc_html_e( 'Article Information (Blog Posts)', 'cspg-basic-seo-helper' ); ?></h4>
							<p><strong><?php esc_html_e( 'What It Creates:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'Detailed information about each blog post that can make your content appear as "rich results" in Google search.', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'Information Included:', 'cspg-basic-seo-helper' ); ?></strong><br>
							• <?php esc_html_e( 'Article title and description', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Author name', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Publication and last update dates', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Featured image', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Publisher information', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'Why It Matters:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'Can make your blog posts show up in Google with extra information like author, date, and thumbnail image, increasing click-through rates.', 'cspg-basic-seo-helper' ); ?></p>
						</div>
						
						<div class="bsh-guide-item">
							<h4><span class="bsh-guide-icon">🎛️</span><?php esc_html_e( 'Individual Post Control', 'cspg-basic-seo-helper' ); ?></h4>
							<p><strong><?php esc_html_e( 'How It Works:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'Each post and page has a checkbox in the SEO meta box to enable or disable Schema markup for that specific content.', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'Default Behavior:', 'cspg-basic-seo-helper' ); ?></strong><br>
							• <?php esc_html_e( 'Schema is automatically enabled for all new posts and pages', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'You can disable it individually if needed', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Having Schema enabled adds 10 points to your SEO score', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'SEO Dashboard Integration:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'The SEO Dashboard tracks which posts have Schema enabled and includes it in the overall SEO health scoring.', 'cspg-basic-seo-helper' ); ?></p>
						</div>
					</div>
					
					<div class="bsh-guide-column">
						<div class="bsh-guide-item">
							<h4><span class="bsh-guide-icon">⚙️</span><?php esc_html_e( 'How It Actually Works', 'cspg-basic-seo-helper' ); ?></h4>
							<p><strong><?php esc_html_e( 'Data Collection:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'The plugin automatically gathers information from your General Settings, Social Media settings, and individual post content.', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'JSON-LD Generation:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'This information is converted into a special format called "JSON-LD" that search engines can easily read and understand.', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'Invisible Output:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'The structured data is added to your page\'s HTML head section as invisible code that only search engines see - visitors see nothing different.', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'Smart Targeting:', 'cspg-basic-seo-helper' ); ?></strong><br>
							• <?php esc_html_e( 'All pages: Organization + Website schema', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Blog posts: Organization + Website + Article schema', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Context-aware generation based on page type', 'cspg-basic-seo-helper' ); ?></p>
						</div>
						
						<div class="bsh-guide-item">
							<h4><span class="bsh-guide-icon">🎯</span><?php esc_html_e( 'Benefits You\'ll See', 'cspg-basic-seo-helper' ); ?></h4>
							<p><strong><?php esc_html_e( 'Enhanced Search Results:', 'cspg-basic-seo-helper' ); ?></strong><br>
							• <?php esc_html_e( 'Blog posts may show thumbnails, author names, and publish dates', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Your business might get a knowledge panel on Google', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Rich snippets with additional information', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'Better Understanding:', 'cspg-basic-seo-helper' ); ?></strong><br>
							• <?php esc_html_e( 'Search engines better understand your content', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Improved categorization and relevance', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Potential for better search rankings', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'Professional Appearance:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'Your content appears more professional and trustworthy in search results, leading to higher click-through rates and better user engagement.', 'cspg-basic-seo-helper' ); ?></p>
						</div>
						
						<div class="bsh-guide-item">
							<h4><span class="bsh-guide-icon">⚙️</span><?php esc_html_e( 'Schema Markup Default Setting', 'cspg-basic-seo-helper' ); ?></h4>
							<p><strong><?php esc_html_e( 'What It Controls:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'Determines whether Schema markup is automatically enabled or disabled when you create new posts and pages.', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'How It Works:', 'cspg-basic-seo-helper' ); ?></strong><br>
							• <?php esc_html_e( 'When checked: New content automatically gets Schema markup enabled', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'When unchecked: New content starts with Schema markup disabled', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Individual Override: You can always change this setting on specific posts and pages', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Existing Content: Changing this setting doesn\'t affect already published content', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'Recommended Setting:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'Keep this enabled (checked). Schema markup provides significant SEO benefits with no downside. It helps search engines understand your content better and can improve your search result appearance with rich snippets.', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'SEO Value:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'Schema markup contributes 10 points to your SEO score per post/page. More importantly, it can help your content appear as rich snippets in search results with enhanced information like author, publication date, and featured images.', 'cspg-basic-seo-helper' ); ?></p>
						</div>
						
						<div class="bsh-guide-item">
							<h4><span class="bsh-guide-icon">📄</span><?php esc_html_e( 'Schema Output Example', 'cspg-basic-seo-helper' ); ?></h4>
							<p><strong><?php esc_html_e( 'What Gets Generated:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'Schema.org structured data helps search engines understand your content better. The plugin automatically generates different schema types based on your content.', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'Automatically Generated Schema Types:', 'cspg-basic-seo-helper' ); ?></strong><br>
							• <strong><?php esc_html_e( 'Organization:', 'cspg-basic-seo-helper' ); ?></strong> <?php esc_html_e( 'Generated from your general settings', 'cspg-basic-seo-helper' ); ?><br>
							• <strong><?php esc_html_e( 'Website:', 'cspg-basic-seo-helper' ); ?></strong> <?php esc_html_e( 'Basic website information', 'cspg-basic-seo-helper' ); ?><br>
							• <strong><?php esc_html_e( 'Article:', 'cspg-basic-seo-helper' ); ?></strong> <?php esc_html_e( 'For blog posts and pages', 'cspg-basic-seo-helper' ); ?><br>
							• <strong><?php esc_html_e( 'BreadcrumbList:', 'cspg-basic-seo-helper' ); ?></strong> <?php esc_html_e( 'Navigation breadcrumbs', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'Example JSON-LD Output:', 'cspg-basic-seo-helper' ); ?></strong></p>
							<textarea readonly rows="12" cols="60" class="large-text code" style="font-family: monospace; font-size: 11px;">{
	"@context": "https://schema.org",
	"@graph": [
	{
		"@type": "Organization",
		"name": "<?php echo esc_js( $options['organization_name'] ?? get_bloginfo( 'name' ) ); ?>",
		"url": "<?php echo esc_js( home_url() ); ?>",
		<?php if ( ! empty( $options['organization_logo'] ) ) : ?>
		"logo": {
		"@type": "ImageObject",
		"url": "<?php echo esc_js( $options['organization_logo'] ); ?>"
		},
		<?php endif; ?>
		<?php if ( ! empty( $options['social_profiles'] ) ) : ?>
		"sameAs": [
			<?php
			$social_urls = array_filter( $options['social_profiles'] );
			if ( ! empty( $social_urls ) ) {
				echo '"' . implode( '",\n        "', array_map( 'esc_js', $social_urls ) ) . '"';
			}
			?>
		]
		<?php endif; ?>
	},
	{
		"@type": "WebSite",
		"name": "<?php echo esc_js( get_bloginfo( 'name' ) ); ?>",
		"url": "<?php echo esc_js( home_url() ); ?>",
		"description": "<?php echo esc_js( get_bloginfo( 'description' ) ); ?>"
	}
	]
}</textarea>
							
							<p><strong><?php esc_html_e( 'Implementation:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'This schema markup is automatically added to your website\'s head section as invisible code. Additional schema types (Article, BreadcrumbList) are generated contextually based on the current page type.', 'cspg-basic-seo-helper' ); ?></p>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
