<?php
/**
 * Livada SEO — Social Settings View
 *
 * @package Livada_SEO
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

$og_image          = Livada_SEO_Loader::get_setting( 'og_default_image', '' );
$twitter_card_type = Livada_SEO_Loader::get_setting( 'twitter_card_type', 'summary_large_image' );
$social_facebook   = Livada_SEO_Loader::get_setting( 'social_facebook', '' );
$social_twitter    = Livada_SEO_Loader::get_setting( 'social_twitter', '' );
$social_linkedin   = Livada_SEO_Loader::get_setting( 'social_linkedin', '' );
$social_instagram  = Livada_SEO_Loader::get_setting( 'social_instagram', '' );
?>
<div class="wrap livada-seo-wrap has-ls-hero">
<?php include LIVADA_SEO_PATH . 'includes/admin/views/_partials/header.php'; ?>
	<h1><?php esc_html_e( 'Social', 'livada-seo' ); ?></h1>

	<?php if ( isset( $_GET['updated'] ) ) : // phpcs:ignore ?>
		<div class="notice notice-success is-dismissible"><p><?php esc_html_e( 'Settings saved.', 'livada-seo' ); ?></p></div>
	<?php endif; ?>

	<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
		<?php wp_nonce_field( 'livada_seo_save_social' ); ?>
		<input type="hidden" name="action" value="livada_seo_save_social">

		<!-- ── Open Graph ── -->
		<h2><?php esc_html_e( 'Open Graph', 'livada-seo' ); ?></h2>
		<table class="form-table" role="presentation">
			<tbody>
				<tr>
					<th scope="row"><?php esc_html_e( 'Default OG Image', 'livada-seo' ); ?></th>
					<td>
						<input type="hidden" name="livada_seo[og_default_image]" id="og_default_image" value="<?php echo esc_url( $og_image ); ?>">
						<img
							id="og_default_image_preview"
							src="<?php echo esc_url( $og_image ); ?>"
							style="max-width:200px;display:block;margin-bottom:8px;<?php echo empty( $og_image ) ? 'display:none;' : ''; ?>"
							alt=""
						>
						<button type="button" class="button livada-media-upload" data-target="og_default_image"><?php esc_html_e( 'Choose Image', 'livada-seo' ); ?></button>
						<button type="button" class="button livada-media-remove" data-target="og_default_image"<?php echo empty( $og_image ) ? ' style="display:none;"' : ''; ?>><?php esc_html_e( 'Remove', 'livada-seo' ); ?></button>
						<p class="description"><?php esc_html_e( 'Fallback image used when a post has no featured image (minimum 1200×630 px recommended).', 'livada-seo' ); ?></p>
					</td>
				</tr>
			</tbody>
		</table>

		<!-- ── Twitter / X ── -->
		<h2><?php esc_html_e( 'Twitter / X', 'livada-seo' ); ?></h2>
		<table class="form-table" role="presentation">
			<tbody>
				<tr>
					<th scope="row"><label for="twitter_card_type"><?php esc_html_e( 'Card Type', 'livada-seo' ); ?></label></th>
					<td>
						<select id="twitter_card_type" name="livada_seo[twitter_card_type]">
							<option value="summary" <?php selected( $twitter_card_type, 'summary' ); ?>><?php esc_html_e( 'Summary', 'livada-seo' ); ?></option>
							<option value="summary_large_image" <?php selected( $twitter_card_type, 'summary_large_image' ); ?>><?php esc_html_e( 'Summary with Large Image', 'livada-seo' ); ?></option>
						</select>
					</td>
				</tr>
			</tbody>
		</table>

		<!-- ── Social URLs ── -->
		<h2><?php esc_html_e( 'Social Profile URLs', 'livada-seo' ); ?></h2>
		<p class="description"><?php esc_html_e( 'These are used for sameAs links in Schema output and may be used in OG tags.', 'livada-seo' ); ?></p>
		<table class="form-table" role="presentation">
			<tbody>
				<tr>
					<th scope="row"><label for="social_facebook"><?php esc_html_e( 'Facebook', 'livada-seo' ); ?></label></th>
					<td><input type="url" id="social_facebook" name="livada_seo[social_facebook]" value="<?php echo esc_url( $social_facebook ); ?>" class="regular-text" placeholder="https://www.facebook.com/yourpage"></td>
				</tr>
				<tr>
					<th scope="row"><label for="social_twitter"><?php esc_html_e( 'Twitter / X', 'livada-seo' ); ?></label></th>
					<td><input type="url" id="social_twitter" name="livada_seo[social_twitter]" value="<?php echo esc_url( $social_twitter ); ?>" class="regular-text" placeholder="https://twitter.com/yourhandle"></td>
				</tr>
				<tr>
					<th scope="row"><label for="social_linkedin"><?php esc_html_e( 'LinkedIn', 'livada-seo' ); ?></label></th>
					<td><input type="url" id="social_linkedin" name="livada_seo[social_linkedin]" value="<?php echo esc_url( $social_linkedin ); ?>" class="regular-text" placeholder="https://www.linkedin.com/company/yourcompany"></td>
				</tr>
				<tr>
					<th scope="row"><label for="social_instagram"><?php esc_html_e( 'Instagram', 'livada-seo' ); ?></label></th>
					<td><input type="url" id="social_instagram" name="livada_seo[social_instagram]" value="<?php echo esc_url( $social_instagram ); ?>" class="regular-text" placeholder="https://www.instagram.com/yourhandle"></td>
				</tr>
			</tbody>
		</table>

		<?php submit_button( __( 'Save Settings', 'livada-seo' ) ); ?>
	</form>
</div>
