<?php
/**
 * Admin settings template for Ask Any plugin
 *
 * This template displays the plugin settings page with:
 * - Content statistics
 * - PDF statistics
 * - API configuration
 * - Widget settings
 * - Contact form integration
 * - Avatar management
 *
 * FEATURE TAGS USAGE:
 * Add tags to any feature using the following classes:
 * 
 * In table headers:
 *   <th scope="row">
 *     Feature Name
 *     <span class="askany-feature-tag askany-tag-new">NEW</span>
 *   </th>
 * 
 * In labels:
 *   <label>
 *     Feature Name
 *     <span class="askany-feature-tag askany-tag-pro">PRO</span>
 *   </label>
 * 
 * In buttons:
 *   <button class="button">
 *     Button Text
 *     <span class="askany-feature-tag askany-tag-beta">BETA</span>
 *   </button>
 * 
 * Available tag types:
 * - askany-tag-new (Blue) - For new features
 * - askany-tag-pro (Gold) - For pro/premium features
 * - askany-tag-beta (Purple) - For beta features
 * - askany-tag-hot (Red) - For trending/popular features
 * - askany-tag-updated (Green) - For recently updated features
 * - askany-tag-coming-soon (Gray) - For upcoming features
 *
 * @package Askany
 * @since 1.0.0
 */

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
?>
<div class="wrap">
	<h1><?php esc_html_e( 'Askany AI Assistant Settings', 'askany' ); ?></h1>
	
	<form id="askany-settings-form">
		<?php wp_nonce_field('askany_admin_nonce', 'askany_nonce'); ?>

		<table class="form-table">
			<tr>
				<th scope="row">
					<label for="askany_api_provider">
						<?php esc_html_e('API Provider', 'askany'); ?>
						<span class="askany-feature-tag askany-tag-new">NEW</span>
					</label>
				</th>
				<td>
					<select name="askany_api_provider" id="askany_api_provider">
						<option value="deepseek" <?php selected($settings['api_provider'], 'deepseek'); ?>>
							<?php esc_html_e('DeepSeek', 'askany'); ?>
						</option>
						<option value="openai" <?php selected($settings['api_provider'], 'openai'); ?>>
							<?php esc_html_e('OpenAI', 'askany'); ?>
						</option>
						<option value="claude" <?php selected($settings['api_provider'], 'claude'); ?>>
							<?php esc_html_e('Anthropic Claude', 'askany'); ?>
						</option>
						<option value="gemini" <?php selected($settings['api_provider'], 'gemini'); ?>>
							<?php esc_html_e('Google Gemini', 'askany'); ?>
						</option>
						<option value="grok" <?php selected($settings['api_provider'], 'grok'); ?>>
							<?php esc_html_e('X.AI Grok', 'askany'); ?>
						</option>
						<option value="openrouter" <?php selected($settings['api_provider'], 'openrouter'); ?>>
							<?php esc_html_e('OpenRouter (100+ Models)', 'askany'); ?>
						</option>
					</select>
					<p class="description">
						<?php esc_html_e('Select your AI provider. Each provider offers different models and pricing.', 'askany'); ?>
					</p>
				</td>
			</tr>

			<tr class="api-model-row">
				<th scope="row">
					<label for="askany_api_model">
						<?php esc_html_e('AI Model', 'askany'); ?>
						<span class="askany-feature-tag askany-tag-new">NEW</span>
					</label>
				</th>
				<td>
					<select name="askany_api_model" id="askany_api_model" class="regular-text">
						<!-- Models will be populated by JavaScript based on selected provider -->
					</select>
					<p class="description model-description">
						<?php esc_html_e('Select the AI model to use for chat responses.', 'askany'); ?>
					</p>
				</td>
			</tr>

			<!-- API URL field removed - now handled automatically by backend -->

			<tr>
				<th scope="row">
					<label for="askany_api_key">
						<?php esc_html_e('API Key', 'askany'); ?>
					</label>
				</th>
				<td>
					<div style="display: flex; gap: 10px; align-items: center; margin-bottom: 10px;">
						<input type="password" 
								name="askany_api_key" 
								id="askany_api_key" 
								value="<?php echo esc_attr($settings['api_key']); ?>" 
								class="regular-text"
								style="flex: 1;">
						<button type="button" class="button" id="toggle-api-key"><?php esc_html_e('Show', 'askany'); ?></button>
						<button type="button" class="button" id="askany-ai-connect-test"><?php esc_html_e('Test Connection', 'askany'); ?></button>
					</div>

					<div class="description">
						<!-- OpenAI Instructions -->
						<div class="api-key-instructions" data-provider="openai" style="display: none;">
							<p><strong><?php esc_html_e('🔑 How to get OpenAI API Key:', 'askany'); ?></strong></p>
							<ol>
								<li><?php esc_html_e('Visit:', 'askany'); ?> 
									<a href="https://platform.openai.com/api-keys" target="_blank">https://platform.openai.com/api-keys</a></li>
								<li><?php esc_html_e('Log in or sign up for an OpenAI account', 'askany'); ?></li>
								<li><?php esc_html_e('Click "+ Create new secret key" to generate a key', 'askany'); ?></li>
								<li><?php esc_html_e('Copy and paste the key above', 'askany'); ?></li>
							</ol>
						</div>

						<!-- DeepSeek Instructions -->
						<div class="api-key-instructions" data-provider="deepseek" style="display: none;">
							<p><strong><?php esc_html_e('🔑 How to get DeepSeek API Key:', 'askany'); ?></strong></p>
							<ol>
								<li><?php esc_html_e('Visit:', 'askany'); ?> 
									<a href="https://platform.deepseek.com/usage" target="_blank">https://platform.deepseek.com/usage</a></li>
								<li><?php esc_html_e('Log in or register for a DeepSeek account', 'askany'); ?></li>
								<li><?php esc_html_e('Navigate to the API Key section', 'askany'); ?></li>
								<li><?php esc_html_e('Generate a new API key if needed', 'askany'); ?></li>
								<li><?php esc_html_e('Copy and paste the key above', 'askany'); ?></li>
							</ol>
						</div>

						<!-- Claude Instructions -->
						<div class="api-key-instructions" data-provider="claude" style="display: none;">
							<p><strong><?php esc_html_e('🔑 How to get Anthropic Claude API Key:', 'askany'); ?></strong></p>
							<ol>
								<li><?php esc_html_e('Visit:', 'askany'); ?> 
									<a href="https://console.anthropic.com/settings/keys" target="_blank">https://console.anthropic.com/settings/keys</a></li>
								<li><?php esc_html_e('Log in or sign up for an Anthropic account', 'askany'); ?></li>
								<li><?php esc_html_e('Click "Create Key" to generate a new API key', 'askany'); ?></li>
								<li><?php esc_html_e('Give your key a name and click "Create Key"', 'askany'); ?></li>
								<li><?php esc_html_e('Copy and paste the key above', 'askany'); ?></li>
							</ol>
						</div>

						<!-- Gemini Instructions -->
						<div class="api-key-instructions" data-provider="gemini" style="display: none;">
							<p><strong><?php esc_html_e('🔑 How to get Google Gemini API Key:', 'askany'); ?></strong></p>
							<ol>
								<li><?php esc_html_e('Visit:', 'askany'); ?> 
									<a href="https://aistudio.google.com/app/apikey" target="_blank">https://aistudio.google.com/app/apikey</a></li>
								<li><?php esc_html_e('Sign in with your Google account', 'askany'); ?></li>
								<li><?php esc_html_e('Click "Get API key" or "Create API key"', 'askany'); ?></li>
								<li><?php esc_html_e('Select or create a Google Cloud project', 'askany'); ?></li>
								<li><?php esc_html_e('Copy and paste the key above', 'askany'); ?></li>
							</ol>
						</div>

						<!-- Grok Instructions -->
						<div class="api-key-instructions" data-provider="grok" style="display: none;">
							<p><strong><?php esc_html_e('🔑 How to get X.AI Grok API Key:', 'askany'); ?></strong></p>
							<ol>
								<li><?php esc_html_e('Visit:', 'askany'); ?> 
									<a href="https://console.x.ai/" target="_blank">https://console.x.ai/</a></li>
								<li><?php esc_html_e('Log in with your X (Twitter) account', 'askany'); ?></li>
								<li><?php esc_html_e('Navigate to API Keys section', 'askany'); ?></li>
								<li><?php esc_html_e('Click "Create API Key" to generate a new key', 'askany'); ?></li>
								<li><?php esc_html_e('Copy and paste the key above', 'askany'); ?></li>
							</ol>
						</div>

						<!-- OpenRouter Instructions -->
						<div class="api-key-instructions" data-provider="openrouter" style="display: none;">
							<p><strong><?php esc_html_e('🔑 How to get OpenRouter API Key:', 'askany'); ?></strong></p>
							<ol>
								<li><?php esc_html_e('Visit:', 'askany'); ?> 
									<a href="https://openrouter.ai/keys" target="_blank">https://openrouter.ai/keys</a></li>
								<li><?php esc_html_e('Log in or sign up for an OpenRouter account', 'askany'); ?></li>
								<li><?php esc_html_e('Click "Create Key" to generate a new API key', 'askany'); ?></li>
								<li><?php esc_html_e('Give your key a name and set limits if needed', 'askany'); ?></li>
								<li><?php esc_html_e('Copy and paste the key above', 'askany'); ?></li>
								<li><?php esc_html_e('Note: OpenRouter provides access to 100+ AI models from multiple providers', 'askany'); ?></li>
							</ol>
						</div>
					</div>
				</td>
			</tr>

			
			<tr>
				<th scope="row">
					<?php esc_html_e('API Status', 'askany'); ?>
				</th>
				<td>
					<label>
						<input type="checkbox" 
								name="askany_api_enabled" 
								id="askany_api_enabled"
								value="1" 
								<?php checked($settings['api_enabled']); ?>>
						<?php esc_html_e('Enable CHAT', 'askany'); ?>
					</label>
				</td>
			</tr>

			<tr>
				<th scope="row">
					<?php esc_html_e('Fallback Mode', 'askany'); ?>
				</th>
				<td>
					<label>
						<input type="checkbox" 
								name="askany_fallback_enabled" 
								id="askany_fallback_enabled"
								value="1" 
								<?php checked($settings['fallback_enabled']); ?>>
						<?php esc_html_e('Enable fallback mode when API is unavailable', 'askany'); ?>
						<span class="dashicons dashicons-info askany-hint-icon" data-hint="fallback-mode" style="color: #2271b1; cursor: help; font-size: 18px; vertical-align: middle;" title="Click for more info"></span>
					</label>
					<div class="askany-hint-content" id="hint-fallback-mode" style="display: none; margin-top: 10px; padding: 10px; background: #f0f6fc; border-left: 3px solid #2271b1; border-radius: 3px;">
						<p style="margin: 0 0 8px 0;">
							<?php esc_html_e('When enabled, the chatbot continues working even if the AI API fails or is unreachable.', 'askany'); ?>
						</p>
						<p style="margin: 0 0 8px 0;">
							<strong><?php esc_html_e('How it works:', 'askany'); ?></strong>
							<?php esc_html_e('Uses your indexed content and smart pattern matching to answer common questions, greetings, and product queries without requiring API access.', 'askany'); ?>
						</p>
						<p style="margin: 0;">
							<strong>💡 <?php esc_html_e('Tip:', 'askany'); ?></strong>
							<?php esc_html_e('Recommended for production sites to ensure uninterrupted service during API outages or rate limit issues.', 'askany'); ?>
						</p>
					</div>
				</td>
			</tr>

			<tr>
				<th scope="row">
					<?php esc_html_e('Floating Widget', 'askany'); ?>
				</th>
				<td>
					<label>
						<input type="checkbox" 
								name="askany_floating_widget_enabled" 
								id="askany_floating_widget_enabled"
								value="1" 
								<?php checked($settings['floating_widget_enabled']); ?>>
						<?php esc_html_e('Enable floating chat widget', 'askany'); ?>
					</label>
				</td>
			</tr>

			<tr class="floating-widget-options" style="<?php echo ! $settings['floating_widget_enabled'] ? 'display: none;' : ''; ?>">
				<th scope="row">
					<?php esc_html_e('Widget Position', 'askany'); ?>
				</th>
				<td>
					<select name="askany_widget_position" id="askany_widget_position" class="regular-text">
						<option value="bottom-right" <?php selected($settings['widget_position'], 'bottom-right'); ?>><?php esc_html_e('Bottom Right', 'askany'); ?></option>
						<option value="bottom-left" <?php selected($settings['widget_position'], 'bottom-left'); ?>><?php esc_html_e('Bottom Left', 'askany'); ?></option>
					</select>
				</td>
			</tr>

			<tr>
				<th scope="row"><?php esc_html_e('Chat Header Text', 'askany'); ?></th>
				<td>
					<input type="text" name="askany_chat_header_text" id="askany_chat_header_text" class="regular-text" value="<?php echo esc_attr($settings['chat_header_text']); ?>" />
					<p class="description"><?php esc_html_e('Enter the text to display in the chat widget header.', 'askany'); ?></p>
				</td>
			</tr>

			<tr class="assistant-avatar-row">
				<th scope="row"><?php esc_html_e('Assistant Avatar', 'askany'); ?></th>
				<td>
					<div class="askany-avatar-upload">
						<?php if ( ! empty($settings['assistant_avatar']) ) : ?>
							<div class="avatar-preview" style="margin-top: 10px;">
								<img src="<?php echo esc_url($settings['assistant_avatar']); ?>" alt="Assistant Avatar" style="max-width: 50px; max-height: 50px;" />
							</div>
						<?php endif; ?>
						<input type="text" name="askany_assistant_avatar" id="askany_assistant_avatar" class="regular-text" value="<?php echo esc_url($settings['assistant_avatar']); ?>" />
						
					</div>
					
					<p class="description"><?php esc_html_e('Enter the URL of the assistant avatar (Floating Widgets) image or upload a new one.', 'askany'); ?></p>
					<button type="button" class="button" id="upload-avatar-button"><?php esc_html_e('Upload Image', 'askany'); ?></button>
					
				</td>
			</tr>

			<tr>
				<th scope="row"><?php esc_html_e('Contact Form', 'askany'); ?></th>
				<td>
					<label>
						<input type="checkbox" 
								name="askany_contact_form_enabled" 
								id="askany_contact_form_enabled"
								value="1" 
								<?php checked($settings['contact_form_enabled']); ?>>
						<?php esc_html_e('Enable Contact Form in Chat Widget', 'askany'); ?>
					</label>
					
				</td>
			</tr>

			<tr class="contact-form-shortcode-field" style="<?php echo ! $settings['contact_form_enabled'] ? 'display: none;' : ''; ?>">
				<th scope="row">
					<label for="askany_contact_form_shortcode"><?php esc_html_e('Contact Form Shortcode:', 'askany'); ?></label>
				</th>
				<td>
					<p>
						<input type="text" 
								name="askany_contact_form_shortcode" 
								id="askany_contact_form_shortcode" 
								class="regular-text" 
								value="<?php echo esc_attr($settings['contact_form_shortcode']); ?>" />
					</p>
					<p class="description"><?php esc_html_e('Enter the shortcode for your contact form (e.g., [contact-form-7 id="123" title="Contact form 1"])', 'askany'); ?></p>
				</td>
			</tr>

			<tr>
				<th scope="row">
					<label for="askany_response_language">
						<?php esc_html_e('AI Response Language', 'askany'); ?>
					</label>
				</th>
				<td>
					<?php
					$plugin = \Askany\Plugin::get_instance();
					$is_pro = $plugin->is_pro_active();
					?>
					<select name="askany_response_language" id="askany_response_language" class="regular-text askany-language-select" data-is-pro="<?php echo $is_pro ? '1' : '0'; ?>">
						<option value="auto" <?php selected($settings['response_language'] ?? 'auto', 'auto'); ?>>
							<?php esc_html_e('Auto (Match User Language)', 'askany'); ?>
						</option>
						<option value="en" <?php selected($settings['response_language'] ?? 'auto', 'en'); ?>>
							<?php esc_html_e('English', 'askany'); ?>
						</option>
						<option value="bn" <?php selected($settings['response_language'] ?? 'auto', 'bn'); ?>>
							<?php esc_html_e('Bengali (বাংলা)', 'askany'); ?>
						</option>
						<option value="es" data-pro="true" <?php selected($settings['response_language'] ?? 'auto', 'es'); ?>>
							<?php esc_html_e('Spanish (Español)', 'askany'); ?>
						</option>
						<option value="fr" data-pro="true" <?php selected($settings['response_language'] ?? 'auto', 'fr'); ?>>
							<?php esc_html_e('French (Français)', 'askany'); ?>
						</option>
						<option value="de" data-pro="true" <?php selected($settings['response_language'] ?? 'auto', 'de'); ?>>
							<?php esc_html_e('German (Deutsch)', 'askany'); ?>
						</option>
						<option value="it" data-pro="true" <?php selected($settings['response_language'] ?? 'auto', 'it'); ?>>
							<?php esc_html_e('Italian (Italiano)', 'askany'); ?>
						</option>
						<option value="pt" data-pro="true" <?php selected($settings['response_language'] ?? 'auto', 'pt'); ?>>
							<?php esc_html_e('Portuguese (Português)', 'askany'); ?>
						</option>
						<option value="ru" data-pro="true" <?php selected($settings['response_language'] ?? 'auto', 'ru'); ?>>
							<?php esc_html_e('Russian (Русский)', 'askany'); ?>
						</option>
						<option value="zh" data-pro="true" <?php selected($settings['response_language'] ?? 'auto', 'zh'); ?>>
							<?php esc_html_e('Chinese (中文)', 'askany'); ?>
						</option>
						<option value="ja" data-pro="true" <?php selected($settings['response_language'] ?? 'auto', 'ja'); ?>>
							<?php esc_html_e('Japanese (日本語)', 'askany'); ?>
						</option>
						<option value="ko" data-pro="true" <?php selected($settings['response_language'] ?? 'auto', 'ko'); ?>>
							<?php esc_html_e('Korean (한국어)', 'askany'); ?>
						</option>
						<option value="ar" data-pro="true" <?php selected($settings['response_language'] ?? 'auto', 'ar'); ?>>
							<?php esc_html_e('Arabic (العربية)', 'askany'); ?>
						</option>
						<option value="hi" data-pro="true" <?php selected($settings['response_language'] ?? 'auto', 'hi'); ?>>
							<?php esc_html_e('Hindi (हिन्दी)', 'askany'); ?>
						</option>
						<option value="tr" data-pro="true" <?php selected($settings['response_language'] ?? 'auto', 'tr'); ?>>
							<?php esc_html_e('Turkish (Türkçe)', 'askany'); ?>
						</option>
						<option value="nl" data-pro="true" <?php selected($settings['response_language'] ?? 'auto', 'nl'); ?>>
							<?php esc_html_e('Dutch (Nederlands)', 'askany'); ?>
						</option>
						<option value="pl" data-pro="true" <?php selected($settings['response_language'] ?? 'auto', 'pl'); ?>>
							<?php esc_html_e('Polish (Polski)', 'askany'); ?>
						</option>
						<option value="sv" data-pro="true" <?php selected($settings['response_language'] ?? 'auto', 'sv'); ?>>
							<?php esc_html_e('Swedish (Svenska)', 'askany'); ?>
						</option>
						<option value="vi" data-pro="true" <?php selected($settings['response_language'] ?? 'auto', 'vi'); ?>>
							<?php esc_html_e('Vietnamese (Tiếng Việt)', 'askany'); ?>
						</option>
						<option value="th" data-pro="true" <?php selected($settings['response_language'] ?? 'auto', 'th'); ?>>
							<?php esc_html_e('Thai (ไทย)', 'askany'); ?>
						</option>
						<option value="id" data-pro="true" <?php selected($settings['response_language'] ?? 'auto', 'id'); ?>>
							<?php esc_html_e('Indonesian (Bahasa Indonesia)', 'askany'); ?>
						</option>
					</select>
					<p class="description">
						<?php esc_html_e('Select the language for AI responses. "Auto" will match the user\'s question language. Selecting a specific language will force all AI responses in that language.', 'askany'); ?>
						<br>
						<strong><?php esc_html_e('Free:', 'askany'); ?></strong> <?php esc_html_e('Auto, English, Bengali', 'askany'); ?> | 
						<strong><?php esc_html_e('Pro:', 'askany'); ?></strong> <?php esc_html_e('All 20+ languages', 'askany'); ?>
					</p>
				</td>
			</tr>

			<tr>
				<th scope="row"><?php esc_html_e('Real-time Chat', 'askany'); ?></th>
				<td>
					<label>
						<input type="checkbox" 
								name="askany_realtime_enabled" 
								id="askany_realtime_enabled"
								value="1" 
								<?php checked($settings['realtime_enabled'] ?? true); ?>>
						<?php esc_html_e('Enable Real-time Chat (SSE)', 'askany'); ?>
					</label>
					<p class="description">
						<?php esc_html_e('Uses Server-Sent Events for instant message delivery. Fallback to polling if not supported.', 'askany'); ?>
						<br>
						<strong><?php esc_html_e('Benefits:', 'askany'); ?></strong>
						<?php esc_html_e('Instant responses, lower server load, better user experience.', 'askany'); ?>
					</p>
				</td>
			</tr>

			
			<tr>
				<th scope="row">
					<?php esc_html_e('RAG (Semantic Search)', 'askany'); ?>
					<span class="askany-feature-tag askany-tag-new">NEW</span>
					<!-- <span class="askany-feature-tag askany-tag-beta">BETA</span> -->
				</th>
				<td>
					<?php
					// Check if compatible embedding provider API key is available
					$has_openai_key = !empty(get_option('askany_api_key_openai'));
					$has_gemini_key = !empty(get_option('askany_api_key_gemini'));
					$has_embedding_provider = $has_openai_key || $has_gemini_key;
					$rag_disabled_class = !$has_embedding_provider ? 'askany-rag-disabled' : '';
					$rag_enabled = $settings['rag_enabled'] ?? false;
					
					// Check pro status for advanced features
					$plugin = \Askany\Plugin::get_instance();
					$is_pro = $plugin->is_pro_active();
					?>
					<div class="askany-rag-section <?php echo esc_attr($rag_disabled_class); ?>">
						<label>
							<input type="checkbox" 
									name="askany_rag_enabled" 
									id="askany_rag_enabled"
									value="1" 
									<?php checked($rag_enabled); ?>
									<?php disabled(!$has_embedding_provider); ?>>
							<?php esc_html_e('Enable RAG Architecture (Retrieval-Augmented Generation)', 'askany'); ?>
							<span class="dashicons dashicons-info askany-hint-icon" data-hint="rag-enabled" style="color: #2271b1; cursor: help; font-size: 18px; vertical-align: middle;" title="Click for more info"></span>
						</label>
						<div class="askany-hint-content" id="hint-rag-enabled" style="display: none; margin-top: 10px; padding: 10px; background: #f0f6fc; border-left: 3px solid #2271b1; border-radius: 3px;">
							<p style="margin: 0 0 8px 0;">
								<?php esc_html_e('Uses AI embeddings and vector search for semantic understanding. Provides more accurate, contextual responses with source citations.', 'askany'); ?>
							</p>
							<p style="margin: 0 0 8px 0;">
								<strong><?php esc_html_e('Benefits:', 'askany'); ?></strong>
								<?php esc_html_e('Semantic search (understands meaning, not just keywords), better context understanding, source citations, improved answer quality.', 'askany'); ?>
							</p>
							<p style="margin: 0;">
								<strong><?php esc_html_e('Requirements:', 'askany'); ?></strong>
								<?php 
								if ($has_embedding_provider) {
									if ($has_openai_key && $has_gemini_key) {
										esc_html_e('OpenAI or Gemini API key detected. Embeddings will be generated automatically.', 'askany');
									} elseif ($has_openai_key) {
										esc_html_e('OpenAI API key detected. Using OpenAI embeddings (text-embedding-3-small).', 'askany');
									} else {
										esc_html_e('Gemini API key detected. Using Gemini embeddings (text-embedding-004).', 'askany');
									}
								} else {
									echo '<span style="color: #d63638;">';
									esc_html_e('Requires OpenAI or Gemini API key. Please configure an API key above to enable RAG.', 'askany');
									echo '</span>';
								}
								?>
							</p>
						</div>
						
						<!-- Hybrid Search Option (only visible when RAG is enabled) -->
						<div id="askany-hybrid-search-option" style="margin-top: 15px; padding-left: 25px; <?php echo !$rag_enabled ? 'display: none;' : ''; ?>">
							<?php if ( ! $is_pro ) : ?>
								<label class="askany-pro-feature-lock" style="opacity: 0.6; cursor: pointer;" onclick="if(typeof AskanyPro !== 'undefined') { AskanyPro.openModal({ title: 'Upgrade to Pro', description: 'Unlock Hybrid Search and premium RAG features', features: ['Hybrid Search (Semantic + Keyword)', 'RAG Optimization (90% API savings)', 'Priority Support', 'Advanced Analytics'] }); }">
									<input type="checkbox" 
											disabled
											style="pointer-events: none; cursor: not-allowed;">
									<strong><?php esc_html_e('Enable Hybrid Search (Recommended)', 'askany'); ?></strong>
									<span class="askany-feature-tag askany-tag-pro">PRO</span>
									<span class="dashicons dashicons-info askany-hint-icon" data-hint="hybrid-search" style="color: #2271b1; cursor: help; font-size: 18px; vertical-align: middle;" title="Click for more info" onclick="event.stopPropagation();"></span>
								</label>
							<?php else : ?>
								<label>
									<input type="checkbox" 
											name="askany_hybrid_search_enabled" 
											id="askany_hybrid_search_enabled"
											value="1" 
											<?php checked($settings['hybrid_search_enabled'] ?? false); ?>
											<?php disabled(!$has_embedding_provider || !$rag_enabled); ?>>
									<strong><?php esc_html_e('Enable Hybrid Search (Recommended)', 'askany'); ?></strong>
									<span class="dashicons dashicons-info askany-hint-icon" data-hint="hybrid-search" style="color: #2271b1; cursor: help; font-size: 18px; vertical-align: middle;" title="Click for more info"></span>
								</label>
							<?php endif; ?>
							<div class="askany-hint-content" id="hint-hybrid-search" style="display: none; margin-top: 10px; padding: 10px; background: #f0f6fc; border-left: 3px solid #2271b1; border-radius: 3px;">
								<p style="margin: 0 0 8px 0;">
									<?php esc_html_e('Combines semantic search (embeddings) with keyword search for maximum accuracy.', 'askany'); ?>
								</p>
								<p style="margin: 0 0 8px 0;">
									<strong><?php esc_html_e('How it works:', 'askany'); ?></strong>
									<?php esc_html_e('Semantic search finds conceptually related content, while keyword search ensures exact terms aren\'t missed. AI receives comprehensive context from both methods for better responses.', 'askany'); ?>
								</p>
								<p style="margin: 0;">
									<strong>💡 <?php esc_html_e('Tip:', 'askany'); ?></strong>
									<?php esc_html_e('Hybrid mode provides the best results by combining the strengths of both search methods.', 'askany'); ?>
								</p>
							</div>
						</div>
						
						<!-- RAG Optimization Option (only visible when RAG is enabled) -->
						<div id="askany-rag-optimization-option" style="margin-top: 15px; padding-left: 25px; <?php echo !$rag_enabled ? 'display: none;' : ''; ?>">
							<?php if ( ! $is_pro ) : ?>
								<label class="askany-pro-feature-lock" style="opacity: 0.6; cursor: pointer;" onclick="if(typeof AskanyPro !== 'undefined') { AskanyPro.openModal({ title: 'Upgrade to Pro', description: 'Unlock RAG Optimization and save 90% on API costs', features: ['Content Hash Caching', 'Batch Embedding API', 'Smart Update Detection', '90% API Quota Savings'] }); }">
									<input type="checkbox" 
											disabled
											style="pointer-events: none; cursor: not-allowed;">
									<strong><?php esc_html_e('Enable RAG Optimization (Content Hash Caching + Batch API)', 'askany'); ?></strong>
									<span class="askany-feature-tag askany-tag-pro">PRO</span>
									<span class="dashicons dashicons-info askany-hint-icon" data-hint="rag-optimization" style="color: #2271b1; cursor: help; font-size: 18px; vertical-align: middle;" title="Click for more info" onclick="event.stopPropagation();"></span>
								</label>
							<?php else : ?>
								<label>
									<input type="checkbox" 
											name="askany_rag_optimization_enabled" 
											id="askany_rag_optimization_enabled"
											value="1" 
											<?php checked($settings['rag_optimization_enabled'] ?? false); ?>
											<?php disabled(!$has_embedding_provider || !$rag_enabled); ?>>
									<strong><?php esc_html_e('Enable RAG Optimization (Content Hash Caching + Batch API)', 'askany'); ?></strong>
									<span class="dashicons dashicons-info askany-hint-icon" data-hint="rag-optimization" style="color: #2271b1; cursor: help; font-size: 18px; vertical-align: middle;" title="Click for more info"></span>
								</label>
							<?php endif; ?>
							<div class="askany-hint-content" id="hint-rag-optimization" style="display: none; margin-top: 10px; padding: 10px; background: #f0f6fc; border-left: 3px solid #2271b1; border-radius: 3px;">
								<p style="margin: 0 0 8px 0;">
									<?php esc_html_e('Reduces API quota usage by 90% through smart caching and batch processing.', 'askany'); ?>
								</p>
								<p style="margin: 0 0 8px 0;">
									<strong><?php esc_html_e('Features:', 'askany'); ?></strong>
								</p>
								<ul style="margin: 0 0 8px 25px;">
									<li><strong><?php esc_html_e('Content Hash Caching:', 'askany'); ?></strong> <?php esc_html_e('Reuses embeddings for duplicate content (0 API calls for duplicates)', 'askany'); ?></li>
									<li><strong><?php esc_html_e('Batch Embedding API:', 'askany'); ?></strong> <?php esc_html_e('Processes multiple texts in one request (10x fewer API calls)', 'askany'); ?></li>
									<li><strong><?php esc_html_e('Smart Updates:', 'askany'); ?></strong> <?php esc_html_e('Only re-embeds when content actually changes', 'askany'); ?></li>
								</ul>
								<p style="margin: 0 0 8px 0;">
									<strong>💡 <?php esc_html_e('Recommended:', 'askany'); ?></strong>
									<?php esc_html_e('Enable this to avoid hitting API quota limits. Especially useful for sites with 1000+ content items.', 'askany'); ?>
								</p>
								<p style="margin: 0;">
									<strong>⚠️ <?php esc_html_e('Note:', 'askany'); ?></strong>
									<?php esc_html_e('The "Regenerate All" button will bypass optimization and force re-generation of all embeddings.', 'askany'); ?>
								</p>
							</div>
						</div>
						
						
					</div>
					
					<style>
						.askany-rag-disabled {
							opacity: 0.5;
							pointer-events: none;
						}
						.askany-rag-status-box {
							background: #f0f0f1;
							border: 1px solid #c3c4c7;
							border-radius: 4px;
							padding: 15px;
						}
					</style>
				</td>
			</tr>

			<tr>
				<th scope="row">
					<?php esc_html_e( 'Web Search', 'askany' ); ?>
					<span class="askany-feature-tag askany-tag-new">NEW</span>
				</th>
				<td>
					<?php
					$plugin = \Askany\Plugin::get_instance();
					$is_pro = $plugin->is_pro_active();
					?>
					<?php if ( ! $is_pro ) : ?>
						<label class="askany-pro-feature-lock" style="opacity: 0.6; cursor: pointer;" onclick="if(typeof AskanyPro !== 'undefined') { AskanyPro.openModal({ title: 'Upgrade to Pro', description: 'Unlock Web Search to expand AI knowledge beyond your site content', features: ['AI Knowledge Expansion', 'Fallback & Always modes', 'Better answer coverage', 'Priority Support'] }); }">
							<input type="checkbox" 
									disabled
									style="pointer-events: none; cursor: not-allowed;">
							<?php esc_html_e( 'Enable Web Search (AI Knowledge Expansion)', 'askany' ); ?>
							<span class="askany-feature-tag askany-tag-pro">PRO</span>
							<span class="dashicons dashicons-info askany-hint-icon" data-hint="web-search" style="color: #2271b1; cursor: help; font-size: 18px; vertical-align: middle;" title="Click for more info" onclick="event.stopPropagation();"></span>
						</label>
					<?php else : ?>
						<!-- ── Master toggle ─────────────────────────────────────────────── -->
						<label>
							<input type="checkbox"
								name="askany_web_search_enabled"
								id="askany_web_search_enabled"
								value="1"
								<?php checked( get_option( 'askany_web_search_enabled', false ) ); ?>>
							<?php esc_html_e( 'Enable Web Search (AI Knowledge Expansion)', 'askany' ); ?>
							<span class="dashicons dashicons-info askany-hint-icon" data-hint="web-search" style="color: #2271b1; cursor: help; font-size: 18px; vertical-align: middle;" title="Click for more info"></span>
						</label>
					<?php endif; ?>

					<?php if ( $is_pro ) : ?>
					<p class="description" style="margin-top: 6px;">
						<?php esc_html_e(
							'When enabled, the AI uses its own vast training knowledge to answer questions not found in your site content — instead of saying "I don\'t know". No external API calls are made.',
							'askany'
						); ?>
					</p>

					<!-- ── Mode selector (shown only when toggle is ON) ──────────────── -->
					<div id="askany_web_search_mode_row"
						style="margin-top: 14px; padding: 14px 16px; background: #f6f7f7; border: 1px solid #dcdcde; border-radius: 4px;
								<?php echo get_option( 'askany_web_search_enabled' ) ? '' : 'display:none;'; ?>">

						<p style="margin: 0 0 10px 0; font-weight: 600;">
							<?php esc_html_e( 'Search Mode', 'askany' ); ?>
						</p>

						<!-- Fallback -->
						<label style="display: flex; align-items: flex-start; gap: 10px; margin-bottom: 12px; cursor: pointer;">
							<input type="radio"
								name="askany_web_search_mode"
								value="fallback"
								<?php checked( get_option( 'askany_web_search_mode', 'fallback' ), 'fallback' ); ?>
								style="margin-top: 3px; flex-shrink: 0;">
							<span>
								<strong><?php esc_html_e( '🟢 Fallback', 'askany' ); ?></strong><br>
								<span class="description">
									<?php esc_html_e(
										'AI answers from site content first. When the answer is missing or unclear, it automatically uses its own knowledge to give a complete response. Best for most sites.',
										'askany'
									); ?>
								</span>
							</span>
						</label>

						<!-- Always -->
						<label style="display: flex; align-items: flex-start; gap: 10px; cursor: pointer;">
							<input type="radio"
								name="askany_web_search_mode"
								value="always"
								<?php checked( get_option( 'askany_web_search_mode', 'fallback' ), 'always' ); ?>
								style="margin-top: 3px; flex-shrink: 0;">
							<span>
								<strong><?php esc_html_e( '🔵 Always Enhance', 'askany' ); ?></strong><br>
								<span class="description">
									<?php esc_html_e(
										'AI always combines site content with its own knowledge for the richest possible answer — even when the site already has relevant content. Best for sites that want maximum helpfulness.',
										'askany'
									); ?>
								</span>
							</span>
						</label>

						<!-- Info box -->
						<div style="margin-top: 12px; padding: 10px 12px; background: #fff8e1; border-left: 3px solid #f0b429; border-radius: 3px; font-size: 13px;">
							💡 <strong><?php esc_html_e( 'How it works:', 'askany' ); ?></strong>
							<?php esc_html_e(
								'The AI model (GPT, DeepSeek, Gemini, Claude, etc.) already has knowledge of millions of companies, products, and concepts from its training. This setting tells it to use that knowledge instead of refusing to answer questions not found on your site.',
								'askany'
							); ?>
						</div>
					</div>

					<!-- ── Toggle show/hide of mode row via JS ────────────────────────── -->
					<script>
					(function () {
						var toggle  = document.getElementById( 'askany_web_search_enabled' );
						var modeRow = document.getElementById( 'askany_web_search_mode_row' );
						if ( toggle && modeRow ) {
							toggle.addEventListener( 'change', function () {
								modeRow.style.display = this.checked ? '' : 'none';
							} );
						}
					})();
					</script>
					<?php endif; ?>
				</td>
			</tr>

			<!-- ── Response Tone ──────────────────────────────────────────────── -->
			<tr>
				<th scope="row">
					<?php esc_html_e( 'Response Tone', 'askany' ); ?>
					<span class="askany-feature-tag askany-tag-new">NEW</span>
				</th>
				<td>
					<?php
					$plugin = \Askany\Plugin::get_instance();
					$is_pro = $plugin->is_pro_active();
					?>
					<?php if ( ! $is_pro ) : ?>
						<label class="askany-pro-feature-lock" style="opacity: 0.6; cursor: pointer;" onclick="if(typeof AskanyPro !== 'undefined') { AskanyPro.openModal({ title: 'Upgrade to Pro', description: 'Unlock Response Tone to customize how your AI responds', features: ['Human, Professional, Friendly tones', 'Customize AI personality', 'Better user engagement', 'Priority Support'] }); }">
							<select disabled style="pointer-events: none; cursor: not-allowed; opacity: 0.6;">
								<option><?php esc_html_e( '🧑 Human — Natural, conversational, like a real person', 'askany' ); ?></option>
							</select>
							<span class="askany-feature-tag askany-tag-pro">PRO</span>
							<span class="dashicons dashicons-info askany-hint-icon" data-hint="response-tone" style="color: #2271b1; cursor: help; font-size: 18px; vertical-align: middle;" title="Click for more info" onclick="event.stopPropagation();"></span>
						</label>
					<?php else : ?>
						<select name="askany_response_tone" id="askany_response_tone" class="regular-text">
							<option value="human"        <?php selected( get_option( 'askany_response_tone', 'human' ), 'human' ); ?>>
								<?php esc_html_e( '🧑 Human — Natural, conversational, like a real person', 'askany' ); ?>
							</option>
							<option value="professional" <?php selected( get_option( 'askany_response_tone', 'human' ), 'professional' ); ?>>
								<?php esc_html_e( '💼 Professional — Clear, formal, business-appropriate', 'askany' ); ?>
							</option>
							<option value="friendly"     <?php selected( get_option( 'askany_response_tone', 'human' ), 'friendly' ); ?>>
								<?php esc_html_e( '😊 Friendly — Warm, upbeat, encouraging', 'askany' ); ?>
							</option>
							<option value="robotic"      <?php selected( get_option( 'askany_response_tone', 'human' ), 'robotic' ); ?>>
								<?php esc_html_e( '🤖 Robotic — Precise, structured, data-focused', 'askany' ); ?>
							</option>
						</select>
						<p class="description">
							<?php esc_html_e( 'Controls how the AI writes its responses. "Human" removes AI-sounding phrases like "Based on the website content".', 'askany' ); ?>
						</p>
					<?php endif; ?>
				</td>
			</tr>

			
			<tr>
				<th scope="row">
					<?php esc_html_e('Typing Animation', 'askany'); ?>
				</th>
				<td>
					<?php
					$plugin = \Askany\Plugin::get_instance();
					$is_pro = $plugin->is_pro_active();
					?>
					<?php if ( ! $is_pro ) : ?>
						<label class="askany-pro-feature-lock" style="opacity: 0.6; cursor: pointer;" onclick="if(typeof AskanyPro !== 'undefined') { AskanyPro.openModal({ title: 'Upgrade to Pro', description: 'Unlock Typing Animation for engaging conversations', features: ['Smooth Typing Effect', 'Human-like Responses', 'Enhanced User Experience', 'Priority Support'] }); }">
							<input type="checkbox" 
									disabled
									style="pointer-events: none; cursor: not-allowed;">
							<?php esc_html_e('Enable typing animation for AI/Agent responses', 'askany'); ?>
							<span class="askany-feature-tag askany-tag-pro">PRO</span>
							<span class="dashicons dashicons-info askany-hint-icon" data-hint="typing-animation" style="color: #2271b1; cursor: help; font-size: 18px; vertical-align: middle;" title="Click for more info" onclick="event.stopPropagation();"></span>
						</label>
					<?php else : ?>
						<label>
							<input type="checkbox" 
									name="askany_typing_animation_enabled" 
									id="askany_typing_animation_enabled"
									value="1" 
									<?php checked($settings['typing_animation_enabled'] ?? false); ?>>
							<?php esc_html_e('Enable typing animation for AI/Agent responses', 'askany'); ?>
							<span class="dashicons dashicons-info askany-hint-icon" data-hint="typing-animation" style="color: #2271b1; cursor: help; font-size: 18px; vertical-align: middle;" title="Click for more info"></span>
						</label>

						<!-- Speed selector — shown when animation is enabled -->
						<div id="askany_typing_speed_row" style="margin-top: 14px; <?php echo ( $settings['typing_animation_enabled'] ?? false ) ? '' : 'display:none;'; ?>">
							<p style="margin: 0 0 8px 0; font-weight: 600; font-size: 13px;"><?php esc_html_e( 'Animation Speed', 'askany' ); ?></p>
							<div style="display: flex; gap: 8px; flex-wrap: wrap;">
								<?php
								$speeds = array(
									'regular' => array( 'label' => '⏱ Regular', 'desc' => 'Default' ),
									'fast'    => array( 'label' => '⚡ Fast',    'desc' => 'Quicker' ),
									'faster'  => array( 'label' => '🚀 Faster',  'desc' => 'Very quick' ),
									'instant' => array( 'label' => '✨ Instant', 'desc' => 'Instant with subtle feel' ),
								);
								$saved_speed = get_option( 'askany_typing_speed', 'regular' );
								foreach ( $speeds as $val => $info ) :
									$is_active = $saved_speed === $val;
								?>
								<label style="display:flex;align-items:center;gap:6px;padding:7px 12px;border:2px solid <?php echo $is_active ? '#2271b1' : '#dcdcde'; ?>;border-radius:6px;cursor:pointer;background:<?php echo $is_active ? '#f0f6fc' : '#fff'; ?>;">
									<input type="radio" name="askany_typing_speed" value="<?php echo esc_attr( $val ); ?>" <?php checked( $saved_speed, $val ); ?> style="margin:0;">
									<span>
										<strong><?php echo esc_html( $info['label'] ); ?></strong>
										<small style="display:block;color:#666;font-size:11px;"><?php echo esc_html( $info['desc'] ); ?></small>
									</span>
								</label>
								<?php endforeach; ?>
							</div>
						</div>

						<script>
						(function () {
							var toggle   = document.getElementById( 'askany_typing_animation_enabled' );
							var speedRow = document.getElementById( 'askany_typing_speed_row' );
							if ( toggle && speedRow ) {
								toggle.addEventListener( 'change', function () {
									speedRow.style.display = this.checked ? '' : 'none';
								} );
							}
						})();
						</script>
					<?php endif; ?>
					<div class="askany-hint-content" id="hint-typing-animation" style="display: none; margin-top: 10px; padding: 10px; background: #f0f6fc; border-left: 3px solid #2271b1; border-radius: 3px;">
						<p style="margin: 0 0 8px 0;">
							<?php esc_html_e('AI and Agent responses appear with a smooth character-by-character typing effect, creating a more natural and engaging conversation experience.', 'askany'); ?>
						</p>
						<p style="margin: 0 0 8px 0;">
							<strong><?php esc_html_e('Benefits:', 'askany'); ?></strong>
							<?php esc_html_e('Human-like interaction, engaging user experience, professional appearance, smooth message reveal.', 'askany'); ?>
						</p>
						<p style="margin: 0;">
							<strong>💡 <?php esc_html_e('Tip:', 'askany'); ?></strong>
							<?php esc_html_e('Typing animation makes responses feel more conversational and less robotic. Disable for instant message display.', 'askany'); ?>
						</p>
					</div>
				</td>
			</tr>

			<tr>
				<th scope="row">
					<?php esc_html_e('Mobile App Push Bridge', 'askany'); ?>
					<!-- <span class="askany-feature-tag askany-tag-pro">PRO</span>
					<span class="askany-feature-tag askany-tag-beta">BETA</span> -->
				</th>
				<td>
					<?php
					$plugin = \Askany\Plugin::get_instance();
					$is_pro = $plugin->is_pro_active();
					?>
					<?php if ( ! $is_pro ) : ?>
						<label class="askany-pro-feature-lock" style="opacity: 0.6; cursor: pointer;" onclick="if(typeof AskanyPro !== 'undefined') { AskanyPro.openModal({ title: 'Upgrade to Pro', description: 'Unlock Mobile App Push Notifications for real-time admin chat', features: ['Instant push notifications', 'Real-time agent chat on mobile', 'Android APK & iOS app', 'Admin panel on your phone'] }); }">
							<input type="checkbox" 
									disabled
									style="pointer-events: none; cursor: not-allowed;">
							<?php esc_html_e('Enable Mobile Push Bridge for real-time chat/notification on mobile.', 'askany'); ?>
							<span class="askany-feature-tag askany-tag-pro">PRO</span>
							<span class="askany-feature-tag askany-tag-beta">BETA</span>
							<span class="dashicons dashicons-info askany-hint-icon" data-hint="mobile-bridge" style="color: #2271b1; cursor: help; font-size: 18px; vertical-align: middle;" title="Click for more info" onclick="event.stopPropagation();"></span>
						</label>
					<?php else : ?>
						<label>
							<input type="checkbox" 
									name="askany_mobile_bridge_enabled" 
									id="mobile_bridge_enabled"
									value="1" 
									<?php checked($settings['mobile_bridge_enabled'] ?? false); ?>>
							<?php esc_html_e('Enable Mobile Push Bridge for real-time chat/notification on mobile.', 'askany'); ?>
							<span class="askany-feature-tag askany-tag-beta">BETA</span>
							<span class="dashicons dashicons-info askany-hint-icon" data-hint="mobile-bridge" style="color: #2271b1; cursor: help; font-size: 18px; vertical-align: middle;" title="Click for more info"></span>
						</label>
					<?php endif; ?>
					<div class="askany-hint-content" id="hint-mobile-bridge" style="display: none; margin-top: 10px; padding: 10px; background: #f0f6fc; border-left: 3px solid #2271b1; border-radius: 3px;">

						<p style="margin: 0 0 12px 0; padding: 8px 12px; background: #e8f5e9; border-radius: 3px;">
							<?php esc_html_e('It’s super simple - just install the APK from the download button and you’re good to go! You’ll get instant notifications and can chat with users directly from your phone instead of logging into the website.', 'askany'); ?>
						</p>
						
						<p style="margin: 0 0 8px 0;">
							<?php esc_html_e('Enable real-time push notifications for admin/user chat on android mobile devices. Follow the steps below to log in as an admin or agent on mobile.', 'askany'); ?>
						</p>
						<p style="margin: 0 0 8px 0;">
							<strong><?php esc_html_e('Setup Steps:', 'askany'); ?></strong>
						</p>
						<ol style="margin: 0 0 8px 25px;">
							<li><?php esc_html_e('Enable this toggle and save settings', 'askany'); ?></li>
							<li><?php esc_html_e('Enter your Firebase FCM Server Key If not configured/used default one already', 'askany'); ?></li>
							<li><?php esc_html_e('Download the app from askany.apk/google drive', 'askany'); ?></li>
							<li><?php esc_html_e('Log in with your WordPress URL and Application Password', 'askany'); ?></li>
						</ol>
						<p style="margin: 0;">
							<strong>💡 <?php esc_html_e('Tip:', 'askany'); ?></strong>
							<?php esc_html_e('Application Passwords can be generated in WordPress Admin → Users → Your Profile → Application Passwords', 'askany'); ?>
						</p>
					</div>

					<?php if ( $is_pro ) : ?>
						<div id="mobile-bridge-settings" style="margin-top: 15px; padding-left: 25px; display: none;">
							
							<p style="margin: 0 0 12px 0; padding: 8px 12px; background: #fff8e1; border-left: 3px solid #f0b429; border-radius: 3px;">
								<?php esc_html_e('Using Firebase Cloud Messaging API V1 (recommended). Get credentials from Firebase Console → Project Settings → Service Accounts → Generate new private key.', 'askany'); ?>
							</p>

							<div style="margin-bottom: 15px; padding: 12px; background: #f0f6fc; border: 1px solid #2271b1; border-radius: 4px;">
								<label style="display: flex; align-items: center; gap: 8px; cursor: pointer;">
									<input type="checkbox" 
											name="askany_push_modify_credentials"
											id="askany_push_modify_credentials"
											value="1"
											<?php checked($settings['push_modify_credentials'] ?? false); ?>
											style="cursor: pointer;" />
									<strong><?php esc_html_e('Use Custom Firebase Credentials', 'askany'); ?></strong>
								</label>
								<p class="description" style="margin-top: 8px; margin-bottom: 0;">
									<?php esc_html_e('Check this box to enter your own Firebase credentials. Uncheck to use default credentials.', 'askany'); ?>
								</p>
							</div>

							<div style="margin-bottom: 15px;">
								<label for="askany_push_project_id">
									<strong><?php esc_html_e('Project ID:', 'askany'); ?></strong>
								</label>
								<input type="text"
										name="askany_push_project_id"
										id="askany_push_project_id"
										class="regular-text askany-masked-field"
										value="<?php echo esc_attr($settings['push_project_id'] ?? ''); ?>"
										data-mask-type="project-id"
										style="margin-top: 5px; display: block;" />
								<p class="description" style="margin-top: 5px;">
									<?php esc_html_e('Found in the Service Account JSON as "project_id". Also visible in Firebase Console → Project Settings → General.', 'askany'); ?>
								</p>
							</div>

							<div style="margin-bottom: 15px;">
								<label for="askany_push_client_email">
									<strong><?php esc_html_e('Client Email:', 'askany'); ?></strong>
								</label>
								<input type="text"
										name="askany_push_client_email"
										id="askany_push_client_email"
										class="regular-text askany-masked-field"
										value="<?php echo esc_attr($settings['push_client_email'] ?? ''); ?>"
										data-mask-type="email"
										style="margin-top: 5px; display: block;" />
								<p class="description" style="margin-top: 5px;">
									<?php esc_html_e('Found in the Service Account JSON as "client_email". Looks like firebase-adminsdk-xxxxx@project-id.iam.gserviceaccount.com', 'askany'); ?>
								</p>
							</div>

							<div style="margin-bottom: 15px;">
								<label for="askany_push_sender_id">
									<strong><?php esc_html_e('Sender ID:', 'askany'); ?></strong>
								</label>
								<input type="text"
										name="askany_push_sender_id"
										id="askany_push_sender_id"
										class="regular-text askany-masked-field"
										value="<?php echo esc_attr($settings['push_sender_id'] ?? ''); ?>"
										data-mask-type="sender-id"
										style="margin-top: 5px; display: block;" />
								<p class="description" style="margin-top: 5px;">
									<?php esc_html_e('Found in Firebase Console → Project Settings → Cloud Messaging → Sender ID.', 'askany'); ?>
								</p>
							</div>

							<div style="margin-bottom: 15px;">
								<label for="askany_push_private_key">
									<strong><?php esc_html_e('Private Key:', 'askany'); ?></strong>
								</label>
								<textarea
										name="askany_push_private_key"
										id="askany_push_private_key"
										class="regular-text"
										rows="5"
										style="margin-top: 5px; display: block; width: 100%; font-family: monospace; font-size: 12px;"
										placeholder="-----BEGIN RSA PRIVATE KEY-----&#10;...&#10;-----END RSA PRIVATE KEY-----"><?php echo esc_textarea($settings['push_private_key'] ?? ''); ?></textarea>
								<p class="description" style="margin-top: 5px;">
									<?php esc_html_e('Found in the Service Account JSON as "private_key". Paste the full value directly from the JSON file — the \\n characters will be converted automatically.', 'askany'); ?>
								</p>
							</div>

							<div style="margin-bottom: 15px;">
								<button type="button" class="button button-secondary" id="askany-test-fcm-connection">
									<?php esc_html_e('Test FCM Connection', 'askany'); ?>
								</button>
								<div id="askany-fcm-test-result" style="display: none; margin-top: 12px; padding: 12px; border-radius: 4px; border: 1px solid #ccc;"></div>
							</div>

							<div style="margin-bottom: 15px; padding: 12px; background: #f9f9f9; border: 1px solid #ddd; border-radius: 4px;">
								<p style="margin: 0 0 8px 0;">
									<strong><?php esc_html_e('Send Test Push Notification', 'askany'); ?></strong>
								</p>
								<p class="description" style="margin: 0 0 10px 0;">
									<?php esc_html_e('Enter a device FCM token to send a real test notification. Get the token by opening the AskAny mobile app and copying it from Settings → Device Token.', 'askany'); ?>
								</p>
								<div style="display: flex; gap: 8px; align-items: flex-start;">
									<input type="text"
										id="askany-test-push-token"
										class="regular-text"
										placeholder="<?php esc_attr_e('Paste device FCM token here...', 'askany'); ?>"
										style="flex: 1;" />
									<button type="button" class="button button-primary" id="askany-send-test-push">
										<?php esc_html_e('Send Test Push', 'askany'); ?>
									</button>
								</div>
								<div id="askany-test-push-result" style="display: none; margin-top: 10px; padding: 10px; border-radius: 4px; border: 1px solid #ccc;"></div>
							</div>

							<div style="margin-bottom: 15px;">
								<p>
									<strong><?php esc_html_e('Connected Admin Devices:', 'askany'); ?></strong>
									<span id="admin-devices-count" style="background: #f0f0f1; padding: 5px 10px; border-radius: 3px; display: inline-block;">
										<?php 
										$admin_tokens = get_option('askany_push_admin_tokens', array());
										echo esc_html(count($admin_tokens));
										?>
									</span>
								</p>
							</div>

							<div class="mobile-devices-apk">
								<p>
									<strong><?php esc_html_e('Download Android App:', 'askany'); ?></strong>
								</p>
								<a href="https://drive.google.com/drive/folders/11W-si_Zix82Y9UnsXSrrKmG4yPvLMvRS?usp=sharing" target="_blank" class="askany-download-link" title="<?php esc_attr_e('Download AskAny Mobile App', 'askany'); ?>" style="display: inline-block; padding: 8px 12px; border-radius: 4px; background: #f0f0f1; transition: all 0.2s;">
									<span class="dashicons dashicons-download" style="font-size: 24px; width: 24px; height: 24px; color: #2271b1; display: inline-block; vertical-align: middle;"></span>
								</a>
							</div>
						</div>

						<style>
							#askany_push_private_key {
								-webkit-user-select: none;
								-moz-user-select: none;
								-ms-user-select: none;
								user-select: none;
							}
							
							#askany_push_private_key::selection {
								background: transparent;
								color: inherit;
							}
							
							.askany-download-link {
								text-decoration: none;
								cursor: pointer;
							}
							
							.askany-download-link:hover {
								background: #e0e0e0 !important;
							}
							
							.askany-download-link:hover .dashicons {
								color: #0a4b8a !important;
								transform: scale(1.1);
							}
							
							.askany-masked-field {
								font-family: 'Courier New', monospace !important;
								letter-spacing: 2px;
								-webkit-user-select: none;
								-moz-user-select: none;
								-ms-user-select: none;
								user-select: none;
							}
							
							.askany-masked-field::selection {
								background: transparent;
								color: inherit;
							}
						</style>

						<script>
							(function() {
								// Default Firebase credentials
								const DEFAULT_CREDENTIALS = {
									project_id: 'askany-apk',
									client_email: 'firebase-adminsdk-fbsvc@askany-apk.iam.gserviceaccount.com',
									sender_id: '709662232412',
									private_key: '-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDMajrBA4Gc41EfJ86Gc1BLiB+S7sxxTO/TkI8o24XNAU5VAqaf3fXb1T6vLnJ/nJgMkaS9ON7VtqSRCg7+goklLNO1ag+J2cRPjPJ56USNXmMMOIWxykUjwIcVcEZj6TyiV2ovK2ur1h10HHROHkYpWBtO2hFuP7Cj1PuSWEAKqbw0SY7kSIo/BFZvBtcy1Cyk1U1fn7sH+7c/uprLrrJft9Fd08FqhA5XdogfvH3XZXU2j1wmag91Gy8UhMKkjBKKx2r+T7RXiQ0HpphyngIYJQN9Dj09+VCkgnkN5zNauvA4DQe6Ic3cd8hTmyUQtl/aCSnsa0a+WIGoN5bUpKmdAgMBAAECggEAUbV6w9FXe3Nf51C9nH+2jmKcoFqE7RsgWFSV7PKG0tHdUlzLZubN0nA0bMjnqrvZCVkkXSDA7fNiZ7l6EeDy2iHHhGIfUO5zqorAF9wW811RwT5MrqsYJPjd5kNpV6GRA6Fmh/FWyiq9vj5rfRhb2kXmMIg5ZHTf8jT91FsjSj8kflMRVgjvT0qy0MqXXwv2FuWwBxHWMMhnkwTsx+3dQxdhMBQ95REU3wplHKV2RJhvaDS4tild40llq3GuMrjSe0j3aK9bWv+iEiTYClQgs0QR2vCrDzU7gEYJWoCjv83X4cx1cKoGWMCwVuboJ/xOyN9sGVej9JQ6qLVAqFbHrwKBgQD0O6jWWLI6pQ+xf7m4vVjtDjywAIcBVEJtotxcKsTvZTpxFrJ66xqh9Rxwifq9BLyn8Htec/ePh9dQP225yey9lF6NtW0B0IZgtu2YLzuqQNjCtsmEtQwi2TqOEMJ02wJyGiP07bhX9FyWgaCEv6wPXgLKm7bCDCG+KYykUkO6DwKBgQDWQ3VmEinoil+mXxPkDG0NhDJ0s5gV0IbVpomv2NGrygwNxU+CJREwnZlIf/RB3ZKzp38y5MnakroU2u4uG2DZyBvmmKJ5MxnIrn0a1Rjk7foK2dFUXXnanLmvjug9yxzwtdZHao1xK1WbjPvzJwoQA83XAPc7HQ16bs2lKSD9kwKBgQDdaEhDKN1KNODpNLUVOPIo1UNG+vNozQ37fizukQc/TzGP29epfwEB2ccSbsOUH3s3c9cjZVYEFE2pPhcm2lt38c1WAib0AioP+0WhNRCN44Od4T8Gw2phHTTsHV1rui+ZaQE3xVncwnY9Kv5t2aUNuVgmfMtNVtowHlKVlM45GQKBgDZtnHz5UDwKKpIQxPTBU1KDqm2K0a948UeErqVE5r5E7RrybGgbEmrPHgkUt++jYYjRm7ZJ+BzV+P8jPi3oNoocEzpYu60eFgasjIssZs6AxWvMOSi9Nh8agPDf1I8d8ZQUHQK3RobhAzYocjgqSpwW20sqq6MQlkPrscGq2P6RAoGAAwdjyvJTJ1mNe1FTkzM77T0K+2M4bmBlmJz6ExazoGQi6Zv4QB1Qo53w5Ed2fhJaXW5zO62U97XrYApRZaccOVa3d8eCm0rd2vLMPAbueEtVn/D3Os8+cOj+KrpcwVlwzYTV41y+qxv0Ijc336q2Dqd7rX/77mcVkIzHxXK3yQw=\n-----END PRIVATE KEY-----'
								};

								const toggle = document.getElementById('mobile_bridge_enabled');
								const settings = document.getElementById('mobile-bridge-settings');
								const modifyCheckbox = document.getElementById('askany_push_modify_credentials');
								const projectIdField = document.getElementById('askany_push_project_id');
								const clientEmailField = document.getElementById('askany_push_client_email');
								const senderIdField = document.getElementById('askany_push_sender_id');
								const privateKeyField = document.getElementById('askany_push_private_key');
								
								function updateVisibility() {
									if (toggle && settings) {
										settings.style.display = toggle.checked ? 'block' : 'none';
										if (toggle.checked) {
											initializeCredentials();
										}
									}
								}
								
								function initializeCredentials() {
									// On page load, check if modify checkbox is already checked (from saved settings)
									const isModifyChecked = modifyCheckbox.checked;
									const hasValues = projectIdField.value || clientEmailField.value || senderIdField.value || privateKeyField.value;
									
									if (isModifyChecked) {
										// User has custom credentials enabled
										if (hasValues) {
											// Fields have saved custom values - set data attributes
											projectIdField.setAttribute('data-actual-value', projectIdField.value);
											clientEmailField.setAttribute('data-actual-value', clientEmailField.value);
											senderIdField.setAttribute('data-actual-value', senderIdField.value);
											privateKeyField.setAttribute('data-actual-value', privateKeyField.value);
										}
										updateFieldStates(false); // Don't clear fields on page load
									} else {
										// User is using defaults
										if (!hasValues) {
											// No saved values - use defaults
											projectIdField.value = DEFAULT_CREDENTIALS.project_id;
											clientEmailField.value = DEFAULT_CREDENTIALS.client_email;
											senderIdField.value = DEFAULT_CREDENTIALS.sender_id;
											privateKeyField.value = DEFAULT_CREDENTIALS.private_key;
										}
										// Set data attributes for whatever values we have (saved or defaults)
										projectIdField.setAttribute('data-actual-value', projectIdField.value);
										clientEmailField.setAttribute('data-actual-value', clientEmailField.value);
										senderIdField.setAttribute('data-actual-value', senderIdField.value);
										privateKeyField.setAttribute('data-actual-value', privateKeyField.value);
										updateFieldStates(false); // Don't clear fields on page load
										applyMasking();
									}
								}
								
								function updateFieldStates(clearOnModify = true) {
									const isModifying = modifyCheckbox.checked;
									
									projectIdField.readOnly = !isModifying;
									clientEmailField.readOnly = !isModifying;
									senderIdField.readOnly = !isModifying;
									privateKeyField.readOnly = !isModifying;
									
									// Visual feedback
									const opacity = isModifying ? '1' : '0.7';
									const bgColor = isModifying ? '#fff' : '#f5f5f5';
									projectIdField.style.opacity = opacity;
									clientEmailField.style.opacity = opacity;
									senderIdField.style.opacity = opacity;
									privateKeyField.style.opacity = opacity;
									projectIdField.style.backgroundColor = bgColor;
									clientEmailField.style.backgroundColor = bgColor;
									senderIdField.style.backgroundColor = bgColor;
									privateKeyField.style.backgroundColor = bgColor;
									
									if (isModifying) {
										projectIdField.style.cursor = 'text';
										clientEmailField.style.cursor = 'text';
										senderIdField.style.cursor = 'text';
										privateKeyField.style.cursor = 'text';
										// Only clear fields when user toggles checkbox, not on page load
										if (clearOnModify) {
											projectIdField.value = '';
											clientEmailField.value = '';
											senderIdField.value = '';
											privateKeyField.value = '';
											// Clear data attributes so user can enter custom values
											projectIdField.removeAttribute('data-actual-value');
											clientEmailField.removeAttribute('data-actual-value');
											senderIdField.removeAttribute('data-actual-value');
											privateKeyField.removeAttribute('data-actual-value');
										}
									} else {
										projectIdField.style.cursor = 'not-allowed';
										clientEmailField.style.cursor = 'not-allowed';
										senderIdField.style.cursor = 'not-allowed';
										privateKeyField.style.cursor = 'not-allowed';
										// Only restore defaults when user toggles checkbox, not on page load
										if (clearOnModify) {
											projectIdField.value = DEFAULT_CREDENTIALS.project_id;
											clientEmailField.value = DEFAULT_CREDENTIALS.client_email;
											senderIdField.value = DEFAULT_CREDENTIALS.sender_id;
											privateKeyField.value = DEFAULT_CREDENTIALS.private_key;
											// Set data attributes for default values
											projectIdField.setAttribute('data-actual-value', DEFAULT_CREDENTIALS.project_id);
											clientEmailField.setAttribute('data-actual-value', DEFAULT_CREDENTIALS.client_email);
											senderIdField.setAttribute('data-actual-value', DEFAULT_CREDENTIALS.sender_id);
											privateKeyField.setAttribute('data-actual-value', DEFAULT_CREDENTIALS.private_key);
											// Apply masking immediately after setting values
											applyMasking();
										}
									}
								}
								
								if (toggle) {
									toggle.addEventListener('change', updateVisibility);
									updateVisibility();
								}
								
								if (modifyCheckbox) {
									modifyCheckbox.addEventListener('change', updateFieldStates);
									// Initialize on page load
									setTimeout(initializeCredentials, 100);
								}
								
								// Apply masking on page load for existing values
								setTimeout(function() {
									if (projectIdField.value || clientEmailField.value || senderIdField.value || privateKeyField.value) {
										applyMasking();
									}
								}, 150);

								// Auto-convert \n literals to real newlines when pasting the private key from a JSON file
								if (privateKeyField) {
									privateKeyField.addEventListener('paste', function(e) {
										if (modifyCheckbox.checked) {
											e.preventDefault();
											const pasted = (e.clipboardData || window.clipboardData).getData('text');
											// Replace literal \n with real newlines
											const normalized = pasted.replace(/\\n/g, '\n').trim();
											this.value = normalized;
										}
									});

									// Also normalize on blur in case user typed or edited manually
									privateKeyField.addEventListener('blur', function() {
										if (modifyCheckbox.checked && this.value.includes('\\n')) {
											this.value = this.value.replace(/\\n/g, '\n').trim();
										}
									});
								}
								
								function getMaskedValue(value, maskType) {
									if (!value) return '';
									
									if (maskType === 'project-id') {
										// Show first 3 and last 3 chars: ask***apk
										if (value.length <= 6) return value;
										return value.substring(0, 3) + '***' + value.substring(value.length - 3);
									} else if (maskType === 'email') {
										// Show first 10 chars and domain: firebase-***@askany-apk.iam.gserviceaccount.com
										const parts = value.split('@');
										if (parts.length !== 2) return value;
										const localPart = parts[0];
										const domain = parts[1];
										if (localPart.length <= 10) {
											return localPart + '@' + domain;
										}
										return localPart.substring(0, 10) + '***@' + domain;
									} else if (maskType === 'sender-id') {
										// Show first 3 and last 3 digits: 709***412
										if (value.length <= 6) return value;
										return value.substring(0, 3) + '***' + value.substring(value.length - 3);
									} else if (maskType === 'private-key') {
										// NO MASKING for private key - return as-is
										return value;
									}
									return value;
								}
								
								function applyMasking() {
									// DO NOT change the value attribute - keep actual unmasked values there
									// The fields are already readonly, so users can't edit them
									// This ensures AJAX always sends correct unmasked values
								}
								
								// Add event listeners to capture custom input values
								function setupCustomInputListeners() {
									if (projectIdField) {
										projectIdField.addEventListener('input', function() {
											if (modifyCheckbox.checked) {
												this.setAttribute('data-actual-value', this.value);
											}
										});
									}
									if (clientEmailField) {
										clientEmailField.addEventListener('input', function() {
											if (modifyCheckbox.checked) {
												this.setAttribute('data-actual-value', this.value);
											}
										});
									}
									if (senderIdField) {
										senderIdField.addEventListener('input', function() {
											if (modifyCheckbox.checked) {
												this.setAttribute('data-actual-value', this.value);
											}
										});
									}
									if (privateKeyField) {
										privateKeyField.addEventListener('input', function() {
											if (modifyCheckbox.checked) {
												this.setAttribute('data-actual-value', this.value);
											}
										});
									}
								}
								
								setupCustomInputListeners();
							})();
						</script>
					<?php endif; ?>
				</td>
			</tr>
				
		</table>

		<p class="submit">
			<button type="submit" class="button button-primary" id="save-settings">
				<?php esc_html_e('Save Settings', 'askany'); ?>
			</button>
		</p>
	</form>

	<div class="askany-admin-header">
		<div class="askany-admin-stats">
			<div class="askany-stat-box">
				<h3><?php esc_html_e('Content Statistics', 'askany'); ?></h3>
				<div class="askany-stats-grid">
					<div class="askany-stats-column">
						<p>
							<?php esc_html_e('Posts:', 'askany'); ?> 
							<strong><?php echo esc_html($content_stats['posts']); ?></strong>
						</p>
						<p>
							<?php esc_html_e('Pages:', 'askany'); ?> 
							<strong><?php echo esc_html($content_stats['pages']); ?></strong>
						</p>
						<p>
							<?php esc_html_e('Template Pages:', 'askany'); ?> 
							<strong><?php echo esc_html($content_stats['template_pages']); ?></strong>
						</p>
						<p>
							<?php esc_html_e('Docs:', 'askany'); ?> 
							<strong><?php echo esc_html($content_stats['docs']); ?></strong>
						</p>
						<p>
							<?php esc_html_e('Comments:', 'askany'); ?> 
							<strong><?php echo esc_html($content_stats['comments']); ?></strong>
						</p>
					</div>
					<div class="askany-stats-column">
						<p>
							<?php esc_html_e('Products:', 'askany'); ?> 
							<strong><?php echo esc_html($content_stats['products']); ?></strong>
						</p>
						<p>
							<?php esc_html_e('Product Categories:', 'askany'); ?> 
							<strong><?php echo esc_html($content_stats['product_categories']); ?></strong>
						</p>
						<p>
							<?php esc_html_e('Product Tags:', 'askany'); ?> 
							<strong><?php echo esc_html($content_stats['product_tags']); ?></strong>
						</p>
						<p>
							<?php esc_html_e('Custom Fields:', 'askany'); ?> 
							<strong><?php echo esc_html($content_stats['custom_fields']); ?></strong>
						</p>
						<p>
							<?php esc_html_e('Menus:', 'askany'); ?> 
							<strong><?php echo esc_html($content_stats['menus']); ?></strong>
						</p>
					</div>
					<div class="askany-stats-column">
						<p>
							<?php esc_html_e('Widgets:', 'askany'); ?> 
							<strong><?php echo esc_html($content_stats['widgets']); ?></strong>
						</p>
						<p>
							<?php esc_html_e('Total Indexed:', 'askany'); ?> 
							<strong><?php echo esc_html($content_stats['total_indexed']); ?></strong>
						</p>
						<p>
							<?php esc_html_e('Content Size:', 'askany'); ?> 
							<strong><?php echo esc_html(size_format($content_stats['total_content_size'])); ?></strong>
						</p>
						<p>
							<?php esc_html_e('Health Score:', 'askany'); ?> 
							<strong class="askany-health-<?php echo esc_attr($content_stats['indexing_health']['status']); ?>">
								<?php echo esc_html($content_stats['indexing_health']['score']); ?>%
							</strong>
						</p>
						<?php if ( $content_stats['last_updated'] ) : ?>
						<p>
							<?php esc_html_e('Last Updated:', 'askany'); ?> 
							<strong><?php echo esc_html(human_time_diff(strtotime($content_stats['last_updated']), current_time('timestamp')) . ' ago'); ?></strong>
						</p>
						<?php endif; ?>
					</div>
				</div>
			</div>

			<div class="askany-stat-box">
				<h3><?php esc_html_e('PDF Statistics', 'askany'); ?></h3>
				<p>
					<?php esc_html_e('Total PDFs:', 'askany'); ?> 
					<strong><?php echo esc_html($pdf_stats['total_pdfs']); ?></strong>
				</p>
				<p>
					<?php esc_html_e('Total Size:', 'askany'); ?> 
					<strong><?php echo esc_html(size_format($pdf_stats['total_size'])); ?></strong>
				</p>
				<p>
					<?php esc_html_e('Last Updated:', 'askany'); ?> 
					<strong><?php echo esc_html($pdf_stats['last_updated']); ?></strong>
				</p>
			</div>
		</div>

		<div class="askany-admin-actions">
			<button type="button" class="button" id="askany-reindex-content">
				<?php esc_html_e('Reindex Content', 'askany'); ?>
			</button>
		</div>
	</div>
	
	<div class="askany-admin-footer">
		<h3><?php esc_html_e('Shortcode Usage', 'askany'); ?></h3>
		<p><?php esc_html_e('Use the following shortcode to add the chat interface to any post or page:', 'askany'); ?></p>
		<p><?php esc_html_e('or use floating chat widget', 'askany'); ?></p>
		<code class="copy-content"><?php esc_html_e('[askany_chat]', 'askany'); ?></code>
		<code class="copy-content"><?php esc_html_e('[askany_chat title="Customer Support" theme="dark" position="bottom-right"]', 'askany'); ?></code>
		<p><?php esc_html_e('Optional attributes:', 'askany'); ?></p>
		<ul>
			<li><code class="copy-content"><?php esc_html_e('title', 'askany'); ?></code><?php esc_html_e(' - ', 'askany'); ?><?php esc_html_e('Chat window title', 'askany'); ?></li>
			<li><code class="copy-content"><?php esc_html_e('placeholder', 'askany'); ?></code><?php esc_html_e(' - ', 'askany'); ?><?php esc_html_e('Input placeholder text', 'askany'); ?></li>
			<li><code class="copy-content"><?php esc_html_e('button_text', 'askany'); ?></code><?php esc_html_e(' - ', 'askany'); ?><?php esc_html_e('Send button text', 'askany'); ?></li>
			<li><code class="copy-content"><?php esc_html_e('theme', 'askany'); ?></code><?php esc_html_e(' - ', 'askany'); ?><?php esc_html_e('Theme (light/dark)', 'askany'); ?></li>
			<li><code class="copy-content"><?php esc_html_e('position', 'askany'); ?></code><?php esc_html_e(' - ', 'askany'); ?><?php esc_html_e('Position (inline/bottom-left/bottom-right)', 'askany'); ?></li>
			<li><code class="copy-content"><?php esc_html_e('width', 'askany'); ?></code><?php esc_html_e(' - ', 'askany'); ?><?php esc_html_e('Width (e.g., 350px)', 'askany'); ?></li>
			<li><code class="copy-content"><?php esc_html_e('height', 'askany'); ?></code><?php esc_html_e(' - ', 'askany'); ?><?php esc_html_e('Height (e.g., 500px)', 'askany'); ?></li>
		</ul>
	</div>
</div>

<script>
jQuery(document).ready(function($) {
	// Toggle hybrid search and optimization options visibility based on RAG checkbox
	$('#askany_rag_enabled').on('change', function() {
		const isChecked = $(this).is(':checked');
		const $hybridOption = $('#askany-hybrid-search-option');
		const $hybridCheckbox = $('#askany_hybrid_search_enabled');
		const $optimizationOption = $('#askany-rag-optimization-option');
		const $optimizationCheckbox = $('#askany_rag_optimization_enabled');
		
		if (isChecked) {
			$hybridOption.slideDown(300);
			$hybridCheckbox.prop('disabled', false);
			$optimizationOption.slideDown(300);
			$optimizationCheckbox.prop('disabled', false);
		} else {
			$hybridOption.slideUp(300);
			$hybridCheckbox.prop('disabled', true);
			$optimizationOption.slideUp(300);
			$optimizationCheckbox.prop('disabled', true);
		}
	});
	
	// Trigger on page load to set initial state
	$('#askany_rag_enabled').trigger('change');
	
	// Handle hint icon clicks
	$('.askany-hint-icon').on('click', function(e) {
		e.preventDefault();
		const hintId = $(this).data('hint');
		const $hintContent = $('#hint-' + hintId);
		
		// Toggle this hint
		$hintContent.slideToggle(300);
		
		// Change icon
		if ($hintContent.is(':visible')) {
			$(this).removeClass('dashicons-info').addClass('dashicons-info-outline');
		} else {
			$(this).removeClass('dashicons-info-outline').addClass('dashicons-info');
		}
	});
});
</script>
