<?php

/**
 * Provide a admin area view for the plugin
 *
 * This file is used to markup the admin-facing aspects of the plugin.
 *
 * @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_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['basic_seo_helper_nonce'] ) ), 'basic_seo_helper_settings' ) ) {
	$options = array_merge(
		$options,
		array(
			'author_name'       => isset( $_POST['author_name'] ) ? sanitize_text_field( wp_unslash( $_POST['author_name'] ) ) : '',
			'author_url'        => isset( $_POST['author_url'] ) ? esc_url_raw( wp_unslash( $_POST['author_url'] ) ) : '',
			'organization_name' => isset( $_POST['organization_name'] ) ? sanitize_text_field( wp_unslash( $_POST['organization_name'] ) ) : '',
			'organization_logo' => isset( $_POST['organization_logo'] ) ? esc_url_raw( wp_unslash( $_POST['organization_logo'] ) ) : '',
			'default_image'     => isset( $_POST['default_image'] ) ? esc_url_raw( wp_unslash( $_POST['default_image'] ) ) : '',
		)
	);

	update_option( 'cspgbase_options', $options );
	echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( '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">
		<div class="postbox">
			<div class="postbox-header">
				<h2><?php esc_html_e( 'General Settings', 'cspg-basic-seo-helper' ); ?></h2>
			</div>
			<div class="inside">
				<form method="post" action="">
					<?php wp_nonce_field( 'basic_seo_helper_settings', 'basic_seo_helper_nonce' ); ?>
					
					<table class="form-table">
						<tr>
							<th scope="row">
								<label for="author_name"><?php esc_html_e( 'Author Name', 'cspg-basic-seo-helper' ); ?></label>
							</th>
							<td>
								<input type="text" id="author_name" name="author_name" value="<?php echo esc_attr( $options['author_name'] ?? '' ); ?>" class="regular-text" />
								<p class="description"><?php esc_html_e( 'Default author name for structured data.', 'cspg-basic-seo-helper' ); ?></p>
							</td>
						</tr>
						
						<tr>
							<th scope="row">
								<label for="author_url"><?php esc_html_e( 'Author URL', 'cspg-basic-seo-helper' ); ?></label>
							</th>
							<td>
								<input type="url" id="author_url" name="author_url" value="<?php echo esc_attr( $options['author_url'] ?? '' ); ?>" class="regular-text" />
								<p class="description"><?php esc_html_e( 'Author website or profile URL.', 'cspg-basic-seo-helper' ); ?></p>
							</td>
						</tr>
						
						<tr>
							<th scope="row">
								<label for="organization_name"><?php esc_html_e( 'Organization Name', 'cspg-basic-seo-helper' ); ?></label>
							</th>
							<td>
								<input type="text" id="organization_name" name="organization_name" value="<?php echo esc_attr( $options['organization_name'] ?? get_bloginfo( 'name' ) ); ?>" class="regular-text" />
								<p class="description"><?php esc_html_e( 'Your organization or website name.', 'cspg-basic-seo-helper' ); ?></p>
							</td>
						</tr>
						
						<tr>
							<th scope="row">
								<label for="organization_logo"><?php esc_html_e( 'Organization Logo', 'cspg-basic-seo-helper' ); ?></label>
							</th>
							<td>
								<div class="bsh-media-field-wrapper">
									<div class="bsh-media-input-group">
										<input type="url" id="organization_logo" name="organization_logo" value="<?php echo esc_attr( $options['organization_logo'] ?? '' ); ?>" class="regular-text" />
										<button type="button" class="button" id="upload_logo_button"><?php esc_html_e( 'Select Logo', 'cspg-basic-seo-helper' ); ?></button>
									</div>
									<?php if ( ! empty( $options['organization_logo'] ) ) : ?>
										<div class="bsh-image-preview" id="logo_preview">
											<img src="<?php echo esc_url( $options['organization_logo'] ); ?>" alt="<?php esc_html_e( 'Organization Logo Preview', 'cspg-basic-seo-helper' ); ?>" />
											<small><?php esc_html_e( 'Current logo', 'cspg-basic-seo-helper' ); ?></small>
										</div>
									<?php endif; ?>
									<p class="description"><?php esc_html_e( 'Logo for structured data (recommended: 600x60px).', 'cspg-basic-seo-helper' ); ?></p>
								</div>
							</td>
						</tr>
						
						<tr>
							<th scope="row">
								<label for="default_image"><?php esc_html_e( 'Default Social Image', 'cspg-basic-seo-helper' ); ?></label>
							</th>
							<td>
								<div class="bsh-media-field-wrapper">
									<div class="bsh-media-input-group">
										<input type="url" id="default_image" name="default_image" value="<?php echo esc_attr( $options['default_image'] ?? '' ); ?>" class="regular-text" />
										<button type="button" class="button" id="upload_image_button"><?php esc_html_e( 'Select Image', 'cspg-basic-seo-helper' ); ?></button>
									</div>
									<?php if ( ! empty( $options['default_image'] ) ) : ?>
										<div class="bsh-image-preview" id="social_image_preview">
											<img src="<?php echo esc_url( $options['default_image'] ); ?>" alt="<?php esc_html_e( 'Default Social Image Preview', 'cspg-basic-seo-helper' ); ?>" />
											<small><?php esc_html_e( 'Current default social image', 'cspg-basic-seo-helper' ); ?></small>
										</div>
									<?php endif; ?>
									<p class="description"><?php esc_html_e( 'Default image for social media sharing (recommended: 1200x630px).', 'cspg-basic-seo-helper' ); ?></p>
								</div>
							</td>
						</tr>
					</table>
					
					<?php submit_button(); ?>
				</form>
			</div>
		</div>
		
		<!-- Settings Configuration 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( 'Settings Configuration Guide', 'cspg-basic-seo-helper' ); ?></h2>
					<p><?php esc_html_e( 'Understanding each setting will help you configure your SEO properly. Each field serves a specific purpose in how search engines and social media platforms understand and display your content.', '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( 'Author Name', 'cspg-basic-seo-helper' ); ?></h4>
							<p><strong><?php esc_html_e( 'What It Does:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'Sets the default author name used in structured data markup. This tells search engines who created your content and can appear in rich snippets and knowledge panels.', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'Best Practices:', 'cspg-basic-seo-helper' ); ?></strong><br>
							• <?php esc_html_e( 'Use your real name or brand name consistently', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Match the name used on your social media profiles', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Keep it professional and recognizable', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Use the same format across all platforms', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'SEO Impact:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'Helps establish authorship and expertise, which are important ranking factors. Google uses this for Author Rich Snippets and to build trust in your content.', 'cspg-basic-seo-helper' ); ?></p>
						</div>
						
						<div class="bsh-guide-item">
							<h4><span class="bsh-guide-icon">🔗</span><?php esc_html_e( 'Author URL', 'cspg-basic-seo-helper' ); ?></h4>
							<p><strong><?php esc_html_e( 'What It Does:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'Links to your personal website, LinkedIn profile, or author bio page. This validates your identity and provides additional context about the content creator.', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'Best Practices:', 'cspg-basic-seo-helper' ); ?></strong><br>
							• <?php esc_html_e( 'Use your main professional website or portfolio', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'LinkedIn profiles work well for professional content', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Ensure the URL is active and professional', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Include an about page or bio on the linked site', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'SEO Impact:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'Builds author authority and can help with E-A-T (Expertise, Authoritativeness, Trustworthiness) signals that Google values for content ranking.', '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( 'Plugin Information', 'cspg-basic-seo-helper' ); ?></h4>
							<p><strong><?php esc_html_e( 'What It Does:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'Basic SEO Helper helps you optimize your website for search engines and social media platforms by automatically generating the necessary meta tags and structured data.', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'Features:', 'cspg-basic-seo-helper' ); ?></strong><br>
							• <?php esc_html_e( 'Open Graph meta tags for Facebook and other social platforms', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Twitter Card meta tags', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Schema.org structured data markup', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Customizable meta tags for each post and page', 'cspg-basic-seo-helper' ); ?></p>
						</div>
						
						<div class="bsh-guide-item">
							<h4><span class="bsh-guide-icon">🏢</span><?php esc_html_e( 'Organization Name', 'cspg-basic-seo-helper' ); ?></h4>
							<p><strong><?php esc_html_e( 'What It Does:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'Identifies your business or website organization in structured data. This appears in search results, social shares, and helps search engines understand your brand.', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'Best Practices:', 'cspg-basic-seo-helper' ); ?></strong><br>
							• <?php esc_html_e( 'Use your official business or brand name', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Keep it consistent with your domain name and social profiles', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Avoid special characters or excessive punctuation', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Match your Google My Business listing if applicable', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'SEO Impact:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'Helps build brand recognition in search results and can contribute to branded search queries. Essential for business schema markup and local SEO.', 'cspg-basic-seo-helper' ); ?></p>
						</div>
						
						<div class="bsh-guide-item">
							<h4><span class="bsh-guide-icon">🎨</span><?php esc_html_e( 'Organization Logo', 'cspg-basic-seo-helper' ); ?></h4>
							<p><strong><?php esc_html_e( 'What It Does:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'Your brand logo that appears in search results, knowledge panels, and structured data. This visual element helps users recognize your brand instantly.', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'Technical Requirements:', 'cspg-basic-seo-helper' ); ?></strong><br>
							• <?php esc_html_e( 'Recommended size: 600x60px (10:1 aspect ratio)', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Format: PNG or JPG with transparent background preferred', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'File size: Under 200KB for fast loading', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'High contrast and legible at small sizes', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'SEO Impact:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'Improves brand visibility in search results and can appear in Google\'s knowledge panel. Essential for organization schema markup and building brand trust.', 'cspg-basic-seo-helper' ); ?></p>
						</div>
						
						<div class="bsh-guide-item">
							<h4><span class="bsh-guide-icon">📱</span><?php esc_html_e( 'Default Social Image', 'cspg-basic-seo-helper' ); ?></h4>
							<p><strong><?php esc_html_e( 'What It Does:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'The fallback image used when your content is shared on social media platforms and no specific image is set for a post or page. This ensures your brand always looks professional when shared.', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'Technical Requirements:', 'cspg-basic-seo-helper' ); ?></strong><br>
							• <?php esc_html_e( 'Recommended size: 1200x630px (Facebook/LinkedIn standard)', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Minimum size: 600x315px for proper display', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Format: JPG or PNG, under 1MB', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Include your logo and avoid too much text', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'Design Best Practices:', 'cspg-basic-seo-helper' ); ?></strong><br>
							• <?php esc_html_e( 'Include your brand logo and colors', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Keep text large and readable on mobile', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Use high contrast and simple design', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Test how it looks on different platforms', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'SEO Impact:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'Improves click-through rates from social media, increases brand recognition, and ensures professional appearance across all social platforms when content is shared.', 'cspg-basic-seo-helper' ); ?></p>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
