<?php

/**
 * Provide a admin area view for the social media 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_social_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['basic_seo_helper_social_nonce'] ) ), 'basic_seo_helper_social_settings' ) ) {
	$options = array_merge(
		$options,
		array(
			'facebook_app_id'  => isset( $_POST['facebook_app_id'] ) ? sanitize_text_field( wp_unslash( $_POST['facebook_app_id'] ) ) : '',
			'twitter_username' => isset( $_POST['twitter_username'] ) ? sanitize_text_field( wp_unslash( $_POST['twitter_username'] ) ) : '',
			'social_profiles'  => isset( $_POST['social_profiles'] ) ? array_map( 'esc_url_raw', array_filter( array_map( 'sanitize_text_field', wp_unslash( $_POST['social_profiles'] ) ) ) ) : array(),
		)
	);

	update_option( 'cspgbase_options', $options );
	echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( 'Social media 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( 'Social Media Settings', 'cspg-basic-seo-helper' ); ?></h2>
			</div>
			<div class="inside">
				<form method="post" action="">
					<?php wp_nonce_field( 'basic_seo_helper_social_settings', 'basic_seo_helper_social_nonce' ); ?>
					
					<table class="form-table">
						<tr>
							<th scope="row">
								<label for="facebook_app_id"><?php esc_html_e( 'Facebook App ID', 'cspg-basic-seo-helper' ); ?></label>
							</th>
							<td>
								<input type="text" id="facebook_app_id" name="facebook_app_id" value="<?php echo esc_attr( $options['facebook_app_id'] ?? '' ); ?>" class="regular-text" />
								<p class="description"><?php esc_html_e( 'Your Facebook App ID for Open Graph meta tags.', 'cspg-basic-seo-helper' ); ?></p>
							</td>
						</tr>
						
						<tr>
							<th scope="row">
								<label for="twitter_username"><?php esc_html_e( 'Twitter Username', 'cspg-basic-seo-helper' ); ?></label>
							</th>
							<td>
								<input type="text" id="twitter_username" name="twitter_username" value="<?php echo esc_attr( $options['twitter_username'] ?? '' ); ?>" class="regular-text" placeholder="@username" />
								<p class="description"><?php esc_html_e( 'Your Twitter username (include the @).', 'cspg-basic-seo-helper' ); ?></p>
							</td>
						</tr>
					</table>
					
					<h3><?php esc_html_e( 'Social Media Profiles', 'cspg-basic-seo-helper' ); ?></h3>
					<p class="description"><?php esc_html_e( 'Add your social media profile URLs for structured data.', 'cspg-basic-seo-helper' ); ?></p>
					
					<table class="form-table">
						<tr>
							<th scope="row">
								<label for="social_facebook"><?php esc_html_e( 'Facebook Page', 'cspg-basic-seo-helper' ); ?></label>
							</th>
							<td>
								<input type="url" id="social_facebook" name="social_profiles[facebook]" value="<?php echo esc_attr( $options['social_profiles']['facebook'] ?? '' ); ?>" class="regular-text" />
							</td>
						</tr>
						
						<tr>
							<th scope="row">
								<label for="social_twitter"><?php esc_html_e( 'Twitter Profile', 'cspg-basic-seo-helper' ); ?></label>
							</th>
							<td>
								<input type="url" id="social_twitter" name="social_profiles[twitter]" value="<?php echo esc_attr( $options['social_profiles']['twitter'] ?? '' ); ?>" class="regular-text" />
							</td>
						</tr>
						
						<tr>
							<th scope="row">
								<label for="social_linkedin"><?php esc_html_e( 'LinkedIn Profile', 'cspg-basic-seo-helper' ); ?></label>
							</th>
							<td>
								<input type="url" id="social_linkedin" name="social_profiles[linkedin]" value="<?php echo esc_attr( $options['social_profiles']['linkedin'] ?? '' ); ?>" class="regular-text" />
							</td>
						</tr>
						
						<tr>
							<th scope="row">
								<label for="social_instagram"><?php esc_html_e( 'Instagram Profile', 'cspg-basic-seo-helper' ); ?></label>
							</th>
							<td>
								<input type="url" id="social_instagram" name="social_profiles[instagram]" value="<?php echo esc_attr( $options['social_profiles']['instagram'] ?? '' ); ?>" class="regular-text" />
							</td>
						</tr>
						
						<tr>
							<th scope="row">
								<label for="social_youtube"><?php esc_html_e( 'YouTube Channel', 'cspg-basic-seo-helper' ); ?></label>
							</th>
							<td>
								<input type="url" id="social_youtube" name="social_profiles[youtube]" value="<?php echo esc_attr( $options['social_profiles']['youtube'] ?? '' ); ?>" class="regular-text" />
							</td>
						</tr>
					</table>
					
					<?php submit_button(); ?>
				</form>
			</div>
		</div>
		
		<!-- Social Media 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( 'Social Media Configuration Guide', 'cspg-basic-seo-helper' ); ?></h2>
					<p><?php esc_html_e( 'Proper social media configuration enhances how your content appears when shared on social platforms. Each setting optimizes different aspects of social media integration and structured data.', '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( 'Facebook App ID', '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 website to Facebook when content is shared. This enables Facebook Insights for your domain and provides better analytics for shared content.', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'How to Get It:', 'cspg-basic-seo-helper' ); ?></strong><br>
							• <?php esc_html_e( 'Visit Facebook Developers (developers.facebook.com)', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Create a new app or use an existing one', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Copy the App ID from your app dashboard', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Add your domain to the app domains list', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'SEO Impact:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'Enables Facebook Insights analytics, improves content attribution, and can enhance social proof through proper Facebook integration.', 'cspg-basic-seo-helper' ); ?></p>
						</div>
						
						<div class="bsh-guide-item">
							<h4><span class="bsh-guide-icon">🐦</span><?php esc_html_e( 'Twitter Username', '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 your website content to your Twitter account when shared. This appears in Twitter Card metadata and helps with content attribution.', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'Best Practices:', 'cspg-basic-seo-helper' ); ?></strong><br>
							• <?php esc_html_e( 'Include the @ symbol (e.g., @yourcompany)', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Use your main business or personal Twitter handle', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Ensure the account is active and professional', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Match the username exactly as it appears on Twitter', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'SEO Impact:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'Improves Twitter Card functionality, provides content attribution, and can drive traffic back to your Twitter profile from shared content.', 'cspg-basic-seo-helper' ); ?></p>
						</div>
						
						<div class="bsh-guide-item">
							<h4><span class="bsh-guide-icon">📘</span><?php esc_html_e( 'Facebook Page 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 your website to your Facebook business page in structured data. This helps search engines understand your social presence and can appear in knowledge panels.', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'URL Format:', 'cspg-basic-seo-helper' ); ?></strong><br>
							• <?php esc_html_e( 'Use your complete Facebook page URL', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Example: https://www.facebook.com/YourBusiness', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Use the vanity URL if you have one set up', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Ensure the page is public and active', 'cspg-basic-seo-helper' ); ?></p>
						</div>
						
						<div class="bsh-guide-item">
							<h4><span class="bsh-guide-icon">🐦</span><?php esc_html_e( 'Twitter Profile 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( 'Provides your complete Twitter profile URL for structured data markup. Different from the username field, this is the full URL to your profile.', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'URL Format:', 'cspg-basic-seo-helper' ); ?></strong><br>
							• <?php esc_html_e( 'Use the complete Twitter profile URL', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Example: https://twitter.com/YourCompany', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Match the username in the Twitter Username field', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Ensure consistency between username and profile URL', '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( 'LinkedIn Profile 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 LinkedIn company page or personal profile for professional networking and B2B social proof in search results.', '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 LinkedIn company page for businesses', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Personal profiles work for individual brands', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Ensure the profile is complete and professional', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Keep the profile information updated regularly', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'SEO Impact:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'Enhances professional credibility, supports B2B SEO efforts, and can appear in knowledge panels for business-related searches.', 'cspg-basic-seo-helper' ); ?></p>
						</div>
						
						<div class="bsh-guide-item">
							<h4><span class="bsh-guide-icon">📸</span><?php esc_html_e( 'Instagram Profile 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( 'Connects your website to your Instagram account for visual social proof and brand consistency across platforms.', '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 business Instagram account if available', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Maintain consistent branding with your website', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Post high-quality, relevant content regularly', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Use a professional profile picture and bio', 'cspg-basic-seo-helper' ); ?></p>
						</div>
						
						<div class="bsh-guide-item">
							<h4><span class="bsh-guide-icon">🎥</span><?php esc_html_e( 'YouTube Channel 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 your website to your YouTube channel, supporting video SEO and providing additional content discovery opportunities.', '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 custom YouTube channel URL if available', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Optimize your channel with proper branding', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Create playlists and organize content effectively', 'cspg-basic-seo-helper' ); ?><br>
							• <?php esc_html_e( 'Include channel keywords in your description', 'cspg-basic-seo-helper' ); ?></p>
							
							<p><strong><?php esc_html_e( 'SEO Impact:', 'cspg-basic-seo-helper' ); ?></strong><br>
							<?php esc_html_e( 'Supports video SEO efforts, provides additional content visibility, and can enhance multimedia search presence across Google properties.', 'cspg-basic-seo-helper' ); ?></p>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
