<?php 
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}
$data = SftcyWordaiBase::sc_wordai_get_current_api_settings();
$current_provider = SftcyWordaiBase::sc_wordai_get_current_ai_provider();
$buffering_status = SftcyWordaiBase::wordai_check_output_buffering_status();
$streaming_supported = ( 'openai' === $current_provider && ! SftcyWordaiOpenai::sc_wordai_current_model_uses_responses_api() );
$streaming_checked   = $streaming_supported && ! empty( $data['sc-wordai-streaming'] );
include SFTCY_WORDAI_PLUGIN_DIR . 'admin/views/settings-pages-header-template.php';
// echo '<pre>';
// print_r( $data );
// echo '</pre>';
?>

<!-- 🔑 OpenAI API Key Section -->
<div class="wrap openai-api-key-save-div-wrapper"     
	style="<?php echo ( $current_provider === 'openai' ) ? '' : 'display:none;'; ?>">
	<h4 class="sc-wordai-apikey-require-hints">
	<?php 
	    $allowed_html = array(
			'a' => array(
				'href' => array(),
				'title' => array(),
				'target' => array()
			),
			'br' => array(),
			'i' => array(
				'class' => array()
			),
			'strong' => array(),
		);
		echo wp_kses(
			'<i class="fa-brands fa-superpowers fa-xl boost-your-productivity-icon"></i> Boost up your productivity! Humanlike natural & SEO friendly 1-Click content writing solution for your Post/Page/Product. First <a href="https://platform.openai.com/settings/organization/api-keys" target="_blank">Get your OpenAI API key</a> & start generating your content & high quality (HD) images automatically.',
			$allowed_html
		);
	?> 
	</h4>

	<form id="wordai-openai-api-key-form" method="post">
	<table>
		<tbody>
			<tr>
				<td colspan="4" class="wordai-api-key-save-feedback-msg-td"></td>
			</tr>
			<tr>
				<td class="api-key-label-td <?php echo ! empty( $data['wordai-openai-api-key-data'] )? esc_attr('success') : '';?>">
					<i class="fa-solid fa-key"></i> <?php esc_html_e('OpenAI API Key', 'wordai-pro');?>
				</td>
				<td class="api-key-input-data-td">
					<!-- <input type="text" name="wordai-openai-api-key-data" class="wordai-openai-api-key-data" value="" placeholder="<?php //echo esc_attr( isset( $data['wordai-openai-api-key-mask'] ) ? $data['wordai-openai-api-key-mask'] : '' );?>" /> -->
					<?php
					$real_key = $data['wordai-openai-api-key-data'] ?? '';
					$mask     = SftcyWordaiBase::wordai_api_key_mask_format($real_key, 'openai');
					?>
					<input type="text"
						name="wordai-openai-api-key-data"
						class="wordai-openai-api-key-data"
						data-real="<?php echo esc_attr($real_key); ?>"
						data-mask="<?php echo esc_attr($mask); ?>"

						<?php if ( empty($real_key) ) : ?>
							placeholder="<?php echo esc_attr($mask); ?>"
							value=""
						<?php else : ?>
							value="<?php echo esc_attr($mask); ?>"
						<?php endif; ?>
					/>
				</td>
				<td class="wordai-openai-api-key-show-td">
					<label for="wordai-openai-api-key-show">
						<input type="checkbox" id="wordai-openai-api-key-show" name="wordai-openai-api-key-show" class="wordai-openai-api-key-show" /> 
						<i class="fa-solid fa-eye" title="Show/Hide API Key"></i> 
					</label>  					
				</td>
				<td class="sc-wordai-save-apikey-submit-btn-td">
					<button type="submit" class="button button-primary sc-wordai-save-apikey-submit-btn" name="sc-wordai-save-apikey-submit-btn">
						<i class="fa-solid fa-hard-drive"></i> <?php esc_html_e('Save', 'wordai-pro' ); ?>
					</button>
				</td>  						
			</tr>		
		</tbody>  	
	</table>
	</form>
</div> 


<!-- 🔑 Google Gemini API Key Section -->
<div class="wrap google-gemini-api-key-save-div-wrapper" 
     style="<?php echo ( $current_provider === 'google' ) ? '' : 'display:none;'; ?>">
    <h4 class="sc-wordai-apikey-require-hints">
    <?php 
        echo wp_kses(
            '<i class="fa-brands fa-google fa-xl boost-your-productivity-icon"></i> Connect Google Gemini to generate fast, intelligent and deeply reasoning content with Gemini 2.5 models. First <a href="https://aistudio.google.com/app/apikey" target="_blank">Get your Google Gemini API key</a> & start generating your content automatically.',
            $allowed_html
        );
    ?> 
    </h4>

    <form id="wordai-gemini-api-key-form" method="post">
    <table>
        <tbody>
			<tr>
				<td colspan="4" class="wordai-api-key-save-feedback-msg-td wordai-gemini-api-key-feedback"></td>
			</tr>
            <tr>
                <td class="api-key-label-td <?php echo ! empty( $data['wordai-google-gemini-api-key-data'] ) ? esc_attr( 'success' ) : ''; ?>">
                    <i class="fa-solid fa-key"></i> <?php esc_html_e( 'Google Gemini API Key', 'wordai-pro' );?>
                </td>
                <td class="api-key-input-data-td">
                    <!-- <input type="text" name="wordai-google-gemini-api-key-data" class="wordai-google-gemini-api-key-data" value="" placeholder="<?php //echo esc_attr( isset( $data['wordai-google-gemini-api-key-mask'] ) ? $data['wordai-google-gemini-api-key-mask'] : '' );?>" /> -->
					<?php
					$real_key = $data['wordai-google-gemini-api-key-data'] ?? '';
					$mask     = SftcyWordaiBase::wordai_api_key_mask_format($real_key, 'google');
					?>
					<input type="text"
						name="wordai-google-gemini-api-key-data"
						class="wordai-google-gemini-api-key-data"
						data-real="<?php echo esc_attr($real_key); ?>"
						data-mask="<?php echo esc_attr($mask); ?>"

						<?php if ( empty($real_key) ) : ?>
							placeholder="<?php echo esc_attr($mask); ?>"
							value=""
						<?php else : ?>
							value="<?php echo esc_attr($mask); ?>"
						<?php endif; ?>
					/>

                </td>
                <td class="wordai-google-gemini-api-key-show-td">
                    <label for="wordai-google-gemini-api-key-show">
                        <input type="checkbox" id="wordai-google-gemini-api-key-show" name="wordai-google-gemini-api-key-show" class="wordai-google-gemini-api-key-show" /> 
                        <i class="fa-solid fa-eye" title="<?php esc_attr_e( 'Show/Hide API Key', 'wordai-pro' ); ?>"></i> 
                    </label>                      
                </td>
                <td class="sc-wordai-save-apikey-submit-btn-td">
                    <button type="submit" class="button button-primary sc-wordai-save-apikey-submit-btn" name="sc-wordai-save-gemini-apikey-submit-btn">
                        <i class="fa-solid fa-hard-drive"></i> <?php esc_html_e( 'Save', 'wordai-pro' ); ?>
                    </button>
                </td>                       
            </tr>     
        </tbody>     
    </table>
    </form>
</div> 


<!-- 🔑 Anthropic API Key Section -->
<div class="wrap anthropic-api-key-save-div-wrapper"
	style="<?php echo ( $current_provider === 'anthropic' ) ? '' : 'display:none;'; ?>">
	<h4 class="sc-wordai-apikey-require-hints">
	<?php
		echo wp_kses(
			'<i class="fa-solid fa-brain fa-xl boost-your-productivity-icon"></i> Connect Anthropic Claude for strong long-form writing, titles and chat workflows. First <a href="https://console.anthropic.com/settings/keys" target="_blank">get your Anthropic Claude API key</a> and then start generating content with Claude.',
			$allowed_html
		);
	?>
	</h4>

	<form id="wordai-anthropic-api-key-form" method="post">
	<table>
		<tbody>
			<tr>
				<td colspan="4" class="wordai-api-key-save-feedback-msg-td wordai-anthropic-api-key-feedback"></td>
			</tr>
			<tr>
				<td class="api-key-label-td <?php echo ! empty( $data['wordai-anthropic-api-key-data'] ) ? esc_attr( 'success' ) : ''; ?>">
					<i class="fa-solid fa-key"></i> <?php esc_html_e( 'Anthropic Claude API Key', 'wordai-pro' ); ?>
				</td>
				<td class="api-key-input-data-td">
					<?php
					$real_key = $data['wordai-anthropic-api-key-data'] ?? '';
					$mask     = SftcyWordaiBase::wordai_api_key_mask_format( $real_key, 'anthropic' );
					?>
					<input type="text"
						name="wordai-anthropic-api-key-data"
						class="wordai-anthropic-api-key-data"
						data-real="<?php echo esc_attr( $real_key ); ?>"
						data-mask="<?php echo esc_attr( $mask ); ?>"
						<?php if ( empty( $real_key ) ) : ?>
							placeholder="<?php echo esc_attr( $mask ); ?>"
							value=""
						<?php else : ?>
							value="<?php echo esc_attr( $mask ); ?>"
						<?php endif; ?>
					/>
				</td>
				<td class="wordai-anthropic-api-key-show-td">
					<label for="wordai-anthropic-api-key-show">
						<input type="checkbox" id="wordai-anthropic-api-key-show" name="wordai-anthropic-api-key-show" class="wordai-anthropic-api-key-show" />
						<i class="fa-solid fa-eye" title="<?php esc_attr_e( 'Show/Hide API Key', 'wordai-pro' ); ?>"></i>
					</label>
				</td>
				<td class="sc-wordai-save-apikey-submit-btn-td">
					<button type="submit" class="button button-primary sc-wordai-save-apikey-submit-btn" name="sc-wordai-save-anthropic-apikey-submit-btn">
						<i class="fa-solid fa-hard-drive"></i> <?php esc_html_e( 'Save', 'wordai-pro' ); ?>
					</button>
				</td>
			</tr>
		</tbody>
	</table>
	</form>
</div>


<!-- 🔑 xAI Grok API Key Section -->
<div class="wrap xai-api-key-save-div-wrapper"
	style="<?php echo ( $current_provider === 'xai' ) ? '' : 'display:none;'; ?>">
	<h4 class="sc-wordai-apikey-require-hints">
	<?php
		echo wp_kses(
			'<i class="fa-solid fa-bolt fa-xl boost-your-productivity-icon"></i> Connect xAI Grok for content, titles, images, embeddings, and AI chat workflows. First <a href="https://console.x.ai/" target="_blank">get your xAI API key</a> and then start generating with Grok.',
			$allowed_html
		);
	?>
	</h4>

	<form id="wordai-xai-api-key-form" method="post">
	<table>
		<tbody>
			<tr>
				<td colspan="4" class="wordai-api-key-save-feedback-msg-td wordai-xai-api-key-feedback"></td>
			</tr>
			<tr>
				<td class="api-key-label-td <?php echo ! empty( $data['wordai-xai-api-key-data'] ) ? esc_attr( 'success' ) : ''; ?>">
					<i class="fa-solid fa-key"></i> <?php esc_html_e( 'xAI Grok API Key', 'wordai-pro' ); ?>
				</td>
				<td class="api-key-input-data-td">
					<?php
					$real_key = $data['wordai-xai-api-key-data'] ?? '';
					$mask     = SftcyWordaiBase::wordai_api_key_mask_format( $real_key, 'xai' );
					?>
					<input type="text"
						name="wordai-xai-api-key-data"
						class="wordai-xai-api-key-data"
						data-real="<?php echo esc_attr( $real_key ); ?>"
						data-mask="<?php echo esc_attr( $mask ); ?>"
						<?php if ( empty( $real_key ) ) : ?>
							placeholder="<?php echo esc_attr( $mask ); ?>"
							value=""
						<?php else : ?>
							value="<?php echo esc_attr( $mask ); ?>"
						<?php endif; ?>
					/>
				</td>
				<td class="wordai-xai-api-key-show-td">
					<label for="wordai-xai-api-key-show">
						<input type="checkbox" id="wordai-xai-api-key-show" name="wordai-xai-api-key-show" class="wordai-xai-api-key-show" />
						<i class="fa-solid fa-eye" title="<?php esc_attr_e( 'Show/Hide API Key', 'wordai-pro' ); ?>"></i>
					</label>
				</td>
				<td class="sc-wordai-save-apikey-submit-btn-td">
					<button type="submit" class="button button-primary sc-wordai-save-apikey-submit-btn" name="sc-wordai-save-xai-apikey-submit-btn">
						<i class="fa-solid fa-hard-drive"></i> <?php esc_html_e( 'Save', 'wordai-pro' ); ?>
					</button>
				</td>
			</tr>
		</tbody>
	</table>
	</form>
</div>



<!-- ⚙️ API Settings Panel -->
<div id="openai-settings-div-wrapper">   
	<h3 style="padding: 15px;">
		<span class="sc-wordai-settings-icon dashicons dashicons-admin-settings"></span>
		<?php esc_html_e('API Settings', 'wordai-pro'); ?>
		&nbsp;&nbsp;<small>( <?php esc_html_e('You can keep all API settings default.', 'wordai-pro')?> )</small>
	</h3>  

	<!-- 💎 Minimal Mode Toggle -->
	<div class="sc-wordai-compact-toggle">
		<label>
			<input type="checkbox" id="scWordaiCompactToggle" />
			<span>💎 Minimal Mode</span>
		</label>
	</div>

	<?php
	// Decide default AJAX actions based on current provider
	$apisettings_action = SftcyWordaiBase::sc_wordai_get_provider_ajax_action( 'api', $current_provider, 'save' );
	$reset_action       = SftcyWordaiBase::sc_wordai_get_provider_ajax_action( 'api', $current_provider, 'reset' );
	?>

	<form
		id="scwordai-apisettings-form"
		method="post"
		data-provider="<?php echo esc_attr( $current_provider ); ?>"
		data-apisettings-action="<?php echo esc_attr( $apisettings_action ); ?>"
		data-reset-action="<?php echo esc_attr( $reset_action ); ?>"
	>
	<table>
		<tbody>

			<!-- 🔹 Section 1: Model Selection -->
			<tr>
				<td colspan="2">
					<h4 class="wordai-section-divider">
						<?php esc_html_e('🤖 Model & Reasoning Settings', 'wordai-pro'); ?>
					</h4>
				</td>
			</tr>

			<!-- OpenAI Models List -->
			<tr class="wordai-openai-settings-row wordai-openai-model-row" style="<?php echo ( $current_provider === 'openai' ) ? '' : 'display:none;'; ?>" >
				<td>
					<h4><?php esc_html_e('OpenAI Model', 'wordai-pro'); ?></h4>
					<?php
						$openai_models = SftcyWordaiOpenai::openai_models();
						$selected_openai_model = SftcyWordaiOpenai::normalize_openai_model( $data['sc-wordai-openai-model-slug'] ?? '' );
						$openai_model_hints = SftcyWordaiOpenai::openai_model_hints();
						echo '<select id="sc-wordai-openai-model-slug" name="sc-wordai-openai-model-slug">';

						foreach ( $openai_models as $group_label => $models ) {

							echo '<optgroup label="' . esc_attr( $group_label ) . '">';

							foreach ( $models as $modelslug => $modelname ) {
								$selected = selected( $selected_openai_model, $modelslug, false );

								echo '<option value="' . esc_attr( $modelslug ) . '" data-model-hint="' . esc_attr( $openai_model_hints[ $modelslug ] ?? '' ) . '" ' . esc_attr( $selected ) . '>';
								echo esc_html( $modelname );
								echo '</option>';
							}

							echo '</optgroup>';
						}

						echo '</select>';
					?>  
				</td>
				<td>
					<p id="sc-wordai-openai-model-hint" class="sc-wordai-settings-text-hints">
						<?php echo esc_html( SftcyWordaiOpenai::openai_model_hint( $selected_openai_model ) ); ?>
					</p>
				</td>
			</tr>

			<!-- Google Gemini Models List -->
			<tr class="wordai-google-settings-row wordai-gemini-model-row" style="<?php echo ( $current_provider === 'google' ) ? '' : 'display:none;'; ?>">
				<td>
					<h4><?php esc_html_e( 'Google Gemini Model', 'wordai-pro' ); ?></h4>
						<?php
						$gemini_models = SftcyWordaiGoogleGeminiSettings::gemini_models();
						$selected_gemini_model = SftcyWordaiGoogleGeminiSettings::normalize_gemini_model_slug( $data['sc-wordai-gemini-model-slug'] ?? '' );

						echo '<select id="sc-wordai-gemini-model-slug" name="sc-wordai-gemini-model-slug">';

						foreach ( $gemini_models as $group_label => $models ) {

							echo '<optgroup label="' . esc_attr( $group_label ) . '">';

							foreach ( $models as $modelslug => $modelname ) {

								$selected = selected( $selected_gemini_model, $modelslug, false );

								echo '<option value="' . esc_attr( $modelslug ) . '" ' . esc_attr( $selected ) . '>';
								echo esc_html( $modelname );
								echo '</option>';
							}

							echo '</optgroup>';
						}

						echo '</select>';
						?>
				</td>
				<td>
					<p class="sc-wordai-settings-text-hints">
						<?php esc_html_e( 'Gemini 3.5 Flash is the stable recommended model. Gemini 3.1 Flash-Lite minimizes cost, Gemini 3.1 Pro Preview handles advanced reasoning, and Gemini 2.5 models remain available for compatibility.', 'wordai-pro' ); ?>
					</p>
				</td>
			</tr>

			<!-- Anthropic Models List -->
			<tr class="wordai-anthropic-settings-row wordai-anthropic-model-row" style="<?php echo ( $current_provider === 'anthropic' ) ? '' : 'display:none;'; ?>">
				<td>
					<h4><?php esc_html_e( 'Anthropic Claude Model', 'wordai-pro' ); ?></h4>
					<?php
					$anthropic_models = SftcyWordaiAnthropicSettings::anthropic_models();
					$selected_anthropic_model = SftcyWordaiAnthropicSettings::normalize_anthropic_model_slug( $data['sc-wordai-anthropic-model-slug'] ?? '' );

					echo '<select id="sc-wordai-anthropic-model-slug" name="sc-wordai-anthropic-model-slug">';

					foreach ( $anthropic_models as $group_label => $models ) {
						echo '<optgroup label="' . esc_attr( $group_label ) . '">';

						foreach ( $models as $modelslug => $modelname ) {
							$selected = selected( $selected_anthropic_model, $modelslug, false );

							echo '<option value="' . esc_attr( $modelslug ) . '" ' . esc_attr( $selected ) . '>';
							echo esc_html( $modelname );
							echo '</option>';
						}

						echo '</optgroup>';
					}

					echo '</select>';
					?>
				</td>
				<td>
					<p class="sc-wordai-settings-text-hints">
						<?php esc_html_e( 'Claude Sonnet 5 is the recommended balance of speed and intelligence. Fable 5 provides maximum capability, Opus 4.8 handles demanding reasoning, and Haiku 4.5 remains the lowest-cost choice for lighter workloads.', 'wordai-pro' ); ?>
					</p>
				</td>
			</tr>

			<!-- xAI Grok Models List -->
			<tr class="wordai-xai-settings-row wordai-xai-model-row" style="<?php echo ( $current_provider === 'xai' ) ? '' : 'display:none;'; ?>">
				<td>
					<h4><?php esc_html_e( 'xAI Grok Model', 'wordai-pro' ); ?></h4>
					<?php
					$xai_models = SftcyWordaiXaiSettings::xai_models();
					$selected_xai_model = SftcyWordaiXaiSettings::normalize_xai_model_slug( $data['sc-wordai-xai-model-slug'] ?? '' );
					$xai_model_hints = SftcyWordaiXaiSettings::xai_model_hints();

					echo '<select id="sc-wordai-xai-model-slug" name="sc-wordai-xai-model-slug">';
					foreach ( $xai_models as $group_label => $models ) {
						echo '<optgroup label="' . esc_attr( $group_label ) . '">';
						foreach ( $models as $modelslug => $modelname ) {
							$selected = selected( $selected_xai_model, $modelslug, false );
							echo '<option value="' . esc_attr( $modelslug ) . '" data-model-hint="' . esc_attr( $xai_model_hints[ $modelslug ] ?? '' ) . '" ' . esc_attr( $selected ) . '>';
							echo esc_html( $modelname );
							echo '</option>';
						}
						echo '</optgroup>';
					}
					echo '</select>';
					?>
				</td>
				<td>
					<p id="sc-wordai-xai-model-hint" class="sc-wordai-settings-text-hints">
						<?php echo esc_html( SftcyWordaiXaiSettings::xai_model_hint( $selected_xai_model ) ); ?>
					</p>
				</td>
			</tr>

			<tr class="wordai-openai-settings-row wordai-openai-reasoning-row" style="<?php echo ( $current_provider === 'openai' ) ? '' : 'display:none;'; ?>" >
				<td>
					<h4><?php esc_html_e('GPT-5 Reasoning Effort', 'wordai-pro');?></h4>
					<?php
						$reasoning_efforts = SftcyWordaiOpenai::openai_reasoning_effort();	
						echo '<select id="sc-wordai-openai-reasoning-effort" name="sc-wordai-openai-reasoning-effort">';
						foreach ( $reasoning_efforts as $slug => $label ) {
							$selected = isset( $data['sc-wordai-openai-reasoning-effort'] )
								? selected( $data['sc-wordai-openai-reasoning-effort'], $slug, false)
								: selected( $slug, SftcyWordaiOpenai::$gpt_5_reasoning_effort );
							echo '<option value="'. esc_attr( $slug ) .'" ' . esc_attr( $selected ) . '>' . esc_html( $label ) . '</option>';							
						}
						echo '</select>';					
					?> 
				</td>
				<td>
					<p class="sc-wordai-settings-text-hints">
						<?php echo wp_kses(
							'Adjust how thoroughly GPT-5 reasons through problems. <strong><i>Low</i></strong> is faster and cheaper. <strong><i>High</i></strong> performs deeper reasoning for complex or multi-step logic.',
							['strong'=>[],'i'=>[]]
						); ?>
					</p>
				</td>
			</tr>

			<!-- 🔹 Section 2: Streaming -->
			<tr>
				<td colspan="2">
					<h4 class="wordai-section-divider">
						<?php esc_html_e('⚡ Streaming Options', 'wordai-pro'); ?>
					</h4>
				</td>
			</tr>

			<tr>
				<td>
					<label for="wordAIStreamingInput">
						<h4><?php esc_html_e('Enable Streaming', 'wordai-pro');?></h4>
						<input type="checkbox" name="sc-wordai-streaming" id="wordAIStreamingInput" class="streaming-input" <?php checked( $streaming_checked ); ?> <?php disabled( ! $streaming_supported ); ?> />
					</label>
				</td>
				<td>
					<p class="sc-wordai-settings-text-hints">
						<?php esc_html_e('Enable streaming to display responses as they generate in real time. If streaming fails on your server, disable this option and save again.', 'wordai-pro');?>
					</p>
					<?php
					$streaming_provider_hints = array(
						'openai'    => __( 'OpenAI supports both streaming and non-streaming in the content generation modal. Enable streaming for real-time text, or disable it for one complete response.', 'wordai' ),
						'google'    => __( 'Google Gemini currently uses WordAI’s stable non-streaming JSON path for consistent long-form and multi-item generation. Streaming is locked off for this provider.', 'wordai' ),
						'anthropic' => __( 'Anthropic Claude currently uses WordAI’s stable non-streaming JSON path for reliable multi-item generation. Streaming is locked off for this provider.', 'wordai' ),
						'xai'       => __( 'xAI Grok currently uses WordAI’s stable non-streaming JSON path while Grok streaming parsing is being verified. Streaming is locked off for this provider.', 'wordai' ),
					);
					if ( 'openai' === $current_provider && ! $streaming_supported ) {
						$streaming_provider_hints['openai'] = __( 'The selected OpenAI model uses WordAI’s stable Responses API workflow, so streaming is locked off for consistent output processing.', 'wordai' );
					}
					?>
					<p class="sc-wordai-settings-text-hints sc-wordai-streaming-provider-hint <?php echo $streaming_supported ? '' : esc_attr( 'is-locked' ); ?>">
						<i class="fa-solid fa-circle-info"></i>
						<?php echo esc_html( $streaming_provider_hints[ $current_provider ] ?? $streaming_provider_hints['openai'] ); ?>
					</p>
					<?php if ( isset( $buffering_status ) && $buffering_status === false ) { ?>
						<small class="warning-msg"><i class="fa-solid fa-triangle-exclamation fa-beat"></i>
							<?php esc_html_e('Output buffering is disabled on your server; streaming may not work properly. You can enable "output_buffering" in PHP configuration or contact your hosting provider.', 'wordai-pro');?>
						</small>
					<?php } ?>
				</td>
			</tr>

			<!-- 🔹 Section 3: Generation Parameters -->
			<tr>
				<td colspan="2">
					<h4 class="wordai-section-divider">
						<?php esc_html_e('🎛️ Generation Parameters', 'wordai-pro'); ?>
					</h4>
				</td>
			</tr>

			<tr>
				<td>
					<h4><?php esc_html_e('Temperature', 'wordai-pro');?></h4>
					<input type="range" name="sc-wordai-temperature" class="sc-temperature-input" value="<?php echo esc_attr( $data['sc-wordai-temperature'] );?>" min="0" max="2" step="0.1" />
					<p class="range-selected-value"><?php echo esc_html( $data['sc-wordai-temperature'] );?></p>
				</td>
				<td>
					<p class="sc-wordai-settings-text-hints">
						<?php esc_html_e('Controls creativity vs. focus. Lower values create more consistent results; higher values make output more varied and imaginative.', 'wordai-pro');?>
					</p>
				</td>
			</tr>

			<tr>
				<td>
					<h4><?php esc_html_e('top_p', 'wordai-pro');?></h4>
					<input type="number" name="sc-wordai-top-p" class="top-p-input" value="<?php echo esc_attr( $data['sc-wordai-top-p'] );?>" />
				</td>
				<td>
					<p class="sc-wordai-settings-text-hints">
						<?php esc_html_e('Alternative to temperature. Usually adjust either temperature or top_p, not both.', 'wordai-pro');?>
					</p>
				</td>
			</tr>

			<tr>
				<td>
					<h4><?php esc_html_e('max_tokens / max_completion_tokens', 'wordai-pro');?></h4>
					<input type="number" name="sc-wordai-max-tokens" class="max-tokens-input" value="<?php echo esc_attr( $data['sc-wordai-max-tokens'] );?>" />
				</td>
				<td>
					<p class="sc-wordai-settings-text-hints">
						<?php esc_html_e('Defines how long the model’s response can be. Leave blank for maximum length allowed by the model.', 'wordai-pro');?>
					</p>
				</td>
			</tr>

			<!-- 🔹 Section 4: Penalties & Control -->
			<tr style="<?php echo in_array( $current_provider, array( 'anthropic', 'xai' ), true ) ? 'display:none;' : ''; ?>">
				<td colspan="2">
					<h4 class="wordai-section-divider">
						<?php esc_html_e('🎯 Output Control & Penalties', 'wordai-pro'); ?>
					</h4>
				</td>
			</tr>

			<tr style="<?php echo in_array( $current_provider, array( 'anthropic', 'xai' ), true ) ? 'display:none;' : ''; ?>">
				<td>
					<h4><?php esc_html_e('presence_penalty', 'wordai-pro');?></h4>
					<input type="range" name="sc-wordai-presence-penalty-input" class="sc-wordai-presence-penalty-input" value="<?php echo esc_attr( $data['sc-wordai-presence-penalty-input'] );?>" min="-2.0" max="2.0" step="0.1" />
					<p class="range-selected-value"><?php echo esc_html( $data['sc-wordai-presence-penalty-input'] );?></p>
				</td>
				<td>
					<p class="sc-wordai-settings-text-hints">
						<?php esc_html_e('Encourages new ideas by penalizing repetition. Higher values produce more diverse topics.', 'wordai-pro');?>
					</p>
				</td>
			</tr>

			<tr style="<?php echo in_array( $current_provider, array( 'anthropic', 'xai' ), true ) ? 'display:none;' : ''; ?>">
				<td>
					<h4><?php esc_html_e('frequency_penalty', 'wordai-pro');?></h4>
					<input type="range" name="sc-wordai-frequency-penalty-input" class="sc-wordai-frequency-penalty-input" value="<?php echo esc_attr( $data['sc-wordai-frequency-penalty-input'] );?>" min="-2.0" max="2.0" step="0.1" />
					<p class="range-selected-value"><?php echo esc_html( $data['sc-wordai-frequency-penalty-input'] );?></p>
				</td>
				<td>
					<p class="sc-wordai-settings-text-hints">
						<?php esc_html_e('Reduces repeated phrases or lines. Positive values make responses less repetitive.', 'wordai-pro');?>
					</p>
				</td>
			</tr>

			<tr class="wordai-openai-settings-row wordai-openai-bestof-row" style="<?php echo ( $current_provider === 'openai' ) ? '' : 'display:none;'; ?>" >
				<td>
					<h4><?php esc_html_e('best_of', 'wordai-pro');?></h4>
					<input type="number" name="sc-wordai-best-of-input" class="best-of-input" value="<?php echo esc_attr( $data['sc-wordai-best-of-input'] ?? 1 );?>" />
				</td>
				<td>
					<p class="sc-wordai-settings-text-hints">
						<?php esc_html_e('Generates multiple completions and returns the best one. Note: streaming must be disabled.', 'wordai-pro');?>
					</p>
				</td>
			</tr>

			<tr>
				<td>
					<h4><?php esc_html_e('stop', 'wordai-pro');?></h4>
					<input type="text" name="sc-wordai-stop-input" class="stop-input" value="<?php echo esc_attr( $data['sc-wordai-stop-input'] );?>" />
				</td>
				<td>
					<p class="sc-wordai-settings-text-hints">
						<?php esc_html_e('Up to four custom stop sequences. The API stops once any sequence is encountered.', 'wordai-pro');?>
					</p>
				</td>
			</tr>

			<!-- 🔹 Save Controls -->
			<tr>
				<td colspan="2" style="text-align:center;">
					<h4 class="wordai-section-divider">
						<?php esc_html_e('💾 Save & Reset', 'wordai-pro'); ?>
					</h4>
					<button type="submit" class="button button-primary button-large">
						<i class="fa-regular fa-hard-drive"></i> <?php esc_html_e('Save API Settings','wordai-pro'); ?>
					</button>
					&nbsp;&nbsp;
					<button type="button" class="button button-primary button-large scwordai-apisettings-form-reset-data-btn">
						<i class="fa-regular fa-window-restore"></i> <?php esc_html_e('Reset Settings','wordai-pro'); ?>
					</button>
					<p class="sc-wordai-api-settings-msg"></p>
				</td>
			</tr>

		</tbody>
	</table>
	</form>
</div>

<?php
include_once SFTCY_WORDAI_PLUGIN_DIR . 'admin/views/settings-pages-footer-template.php';
?>
