<?php
/**
 * Admin content index template for Ask Any plugin
 *
 * This template displays the content indexing interface with:
 * - Content type selection
 * - Indexing status
 * - Indexing progress
 * - Content statistics
 * - Bulk actions
 *
 * @package Askany
 * @since 1.0.0
 */

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

// Helper function for eye icon
function askany_eye_icon() {
	return '<svg class="askany-eye-icon" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
		<path d="M10 3C5 3 1.73 6.11 1 10c.73 3.89 4 7 9 7s8.27-3.11 9-7c-.73-3.89-4-7-9-7zm0 12c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z" fill="currentColor"/>
	</svg>';
}
?>
<div class="wrap">
	<h1><?php esc_html_e( 'Content Index Management', 'askany' ); ?></h1>
	
	<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">
					<div class="askany-stat-item">
						<span class="askany-stat-label"><?php esc_html_e('Posts:', 'askany'); ?></span>
						<span class="askany-stat-count"><?php echo esc_html($content_stats['posts']); ?></span>
						<?php if ($content_stats['posts'] > 0): ?>
							<button type="button" class="askany-view-btn askany-view-content" data-type="post" title="<?php esc_attr_e('View indexed posts', 'askany'); ?>">
								<?php echo askany_eye_icon(); ?>
							</button>
						<?php endif; ?>
					</div>
					<div class="askany-stat-item">
						<span class="askany-stat-label"><?php esc_html_e('Pages:', 'askany'); ?></span>
						<span class="askany-stat-count"><?php echo esc_html($content_stats['pages']); ?></span>
						<?php if ($content_stats['pages'] > 0): ?>
							<button type="button" class="askany-view-btn askany-view-content" data-type="page" title="<?php esc_attr_e('View indexed pages', 'askany'); ?>">
								<?php echo askany_eye_icon(); ?>
							</button>
						<?php endif; ?>
					</div>
					<div class="askany-stat-item">
						<span class="askany-stat-label"><?php esc_html_e('Template Pages:', 'askany'); ?></span>
						<span class="askany-stat-count"><?php echo esc_html($content_stats['template_pages']); ?></span>
						<?php if ($content_stats['template_pages'] > 0): ?>
							<button type="button" class="askany-view-btn askany-view-content" data-type="template_page" title="<?php esc_attr_e('View indexed template pages', 'askany'); ?>">
								<?php echo askany_eye_icon(); ?>
							</button>
						<?php endif; ?>
					</div>
					<div class="askany-stat-item">
						<span class="askany-stat-label"><?php esc_html_e('Docs:', 'askany'); ?></span>
						<span class="askany-stat-count"><?php echo esc_html($content_stats['docs']); ?></span>
						<?php if ($content_stats['docs'] > 0): ?>
							<button type="button" class="askany-view-btn askany-view-content" data-type="docs" title="<?php esc_attr_e('View indexed docs', 'askany'); ?>">
								<?php echo askany_eye_icon(); ?>
							</button>
						<?php endif; ?>
					</div>
					<div class="askany-stat-item">
						<span class="askany-stat-label"><?php esc_html_e('FAQs:', 'askany'); ?></span>
						<span class="askany-stat-count"><?php echo esc_html($content_stats['faqs']); ?></span>
						<?php if ($content_stats['faqs'] > 0): ?>
							<button type="button" class="askany-view-btn askany-view-content" data-type="faq" title="<?php esc_attr_e('View indexed FAQs', 'askany'); ?>">
								<?php echo askany_eye_icon(); ?>
							</button>
						<?php endif; ?>
					</div>
					<div class="askany-stat-item">
						<span class="askany-stat-label"><?php esc_html_e('Q&A Pairs:', 'askany'); ?></span>
						<span class="askany-stat-count"><?php echo esc_html($content_stats['qa_pairs']); ?></span>
						<?php if ($content_stats['qa_pairs'] > 0): ?>
							<button type="button" class="askany-view-btn askany-view-content" data-type="qa" title="<?php esc_attr_e('View indexed Q&A pairs', 'askany'); ?>">
								<?php echo askany_eye_icon(); ?>
							</button>
						<?php endif; ?>
					</div>
				</div>
				<div class="askany-stats-column">
					<div class="askany-stat-item">
						<span class="askany-stat-label"><?php esc_html_e('Comments:', 'askany'); ?></span>
						<span class="askany-stat-count"><?php echo esc_html($content_stats['comments']); ?></span>
						<?php if ($content_stats['comments'] > 0): ?>
							<button type="button" class="askany-view-btn askany-view-content" data-type="comment" title="<?php esc_attr_e('View indexed comments', 'askany'); ?>">
								<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
									<path d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z" fill="currentColor"/>
								</svg>
							</button>
						<?php endif; ?>
					</div>
					<div class="askany-stat-item">
						<span class="askany-stat-label"><?php esc_html_e('Products:', 'askany'); ?></span>
						<span class="askany-stat-count"><?php echo esc_html($content_stats['products']); ?></span>
						<?php if ($content_stats['products'] > 0): ?>
							<button type="button" class="askany-view-btn askany-view-content" data-type="product" title="<?php esc_attr_e('View indexed products', 'askany'); ?>">
								<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
									<path d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z" fill="currentColor"/>
								</svg>
							</button>
						<?php endif; ?>
					</div>
					<div class="askany-stat-item">
						<span class="askany-stat-label"><?php esc_html_e('Product Categories:', 'askany'); ?></span>
						<span class="askany-stat-count"><?php echo esc_html($content_stats['product_categories']); ?></span>
						<?php if ($content_stats['product_categories'] > 0): ?>
							<button type="button" class="askany-view-btn askany-view-content" data-type="product_category" title="<?php esc_attr_e('View indexed product categories', 'askany'); ?>">
								<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
									<path d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z" fill="currentColor"/>
								</svg>
							</button>
						<?php endif; ?>
					</div>
					<div class="askany-stat-item">
						<span class="askany-stat-label"><?php esc_html_e('Product Tags:', 'askany'); ?></span>
						<span class="askany-stat-count"><?php echo esc_html($content_stats['product_tags']); ?></span>
						<?php if ($content_stats['product_tags'] > 0): ?>
							<button type="button" class="askany-view-btn askany-view-content" data-type="product_tag" title="<?php esc_attr_e('View indexed product tags', 'askany'); ?>">
								<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
									<path d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z" fill="currentColor"/>
								</svg>
							</button>
						<?php endif; ?>
					</div>
					<div class="askany-stat-item">
						<span class="askany-stat-label"><?php esc_html_e('PDF Documents:', 'askany'); ?></span>
						<span class="askany-stat-count"><?php echo esc_html($content_stats['pdfs']); ?></span>
						<?php if ($content_stats['pdfs'] > 0): ?>
							<button type="button" class="askany-view-btn askany-view-content" data-type="pdf" title="<?php esc_attr_e('View indexed PDFs', 'askany'); ?>">
								<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
									<path d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z" fill="currentColor"/>
								</svg>
							</button>
						<?php endif; ?>
					</div>
				</div>
				<div class="askany-stats-column">
					<div class="askany-stat-item">
						<span class="askany-stat-label"><?php esc_html_e('Custom Fields:', 'askany'); ?></span>
						<span class="askany-stat-count"><?php echo esc_html($content_stats['custom_fields']); ?></span>
						<?php if ($content_stats['custom_fields'] > 0): ?>
							<button type="button" class="askany-view-btn askany-view-content" data-type="custom_field" title="<?php esc_attr_e('View indexed custom fields', 'askany'); ?>">
								<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
									<path d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z" fill="currentColor"/>
								</svg>
							</button>
						<?php endif; ?>
					</div>
					<div class="askany-stat-item">
						<span class="askany-stat-label"><?php esc_html_e('Menus:', 'askany'); ?></span>
						<span class="askany-stat-count"><?php echo esc_html($content_stats['menus']); ?></span>
						<?php if ($content_stats['menus'] > 0): ?>
							<button type="button" class="askany-view-btn askany-view-content" data-type="menu" title="<?php esc_attr_e('View indexed menus', 'askany'); ?>">
								<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
									<path d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z" fill="currentColor"/>
								</svg>
							</button>
						<?php endif; ?>
					</div>
					<div class="askany-stat-item">
						<span class="askany-stat-label"><?php esc_html_e('Widgets:', 'askany'); ?></span>
						<span class="askany-stat-count"><?php echo esc_html($content_stats['widgets']); ?></span>
						<?php if ($content_stats['widgets'] > 0): ?>
							<button type="button" class="askany-view-btn askany-view-content" data-type="widget" title="<?php esc_attr_e('View indexed widgets', 'askany'); ?>">
								<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
									<path d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z" fill="currentColor"/>
								</svg>
							</button>
						<?php endif; ?>
					</div>
					<div class="askany-stat-item">
						<span class="askany-stat-label"><?php esc_html_e('External Sources:', 'askany'); ?></span>
						<span class="askany-stat-count"><?php echo esc_html($content_stats['external_sources']); ?></span>
						<?php if ($content_stats['external_sources'] > 0): ?>
							<button type="button" class="askany-view-btn askany-view-content" data-type="external_source" title="<?php esc_attr_e('View indexed external sources', 'askany'); ?>">
								<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
									<path d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z" fill="currentColor"/>
								</svg>
							</button>
						<?php endif; ?>
					</div>
					<div class="askany-stat-item">
						<span class="askany-stat-label"><?php esc_html_e('Store Config:', 'askany'); ?></span>
						<span class="askany-stat-count"><?php echo esc_html($content_stats['store_config']); ?></span>
						<?php if ($content_stats['store_config'] > 0): ?>
							<button type="button" class="askany-view-btn askany-view-content" data-type="store_config" title="<?php esc_attr_e('View indexed store configuration', 'askany'); ?>">
								<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
									<path d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z" fill="currentColor"/>
								</svg>
							</button>
						<?php endif; ?>
					</div>
					<div class="askany-stat-item askany-total-stat">
						<span class="askany-stat-label"><?php esc_html_e('Total Indexed:', 'askany'); ?></span>
						<span class="askany-stat-count"><?php echo esc_html($content_stats['total_indexed']); ?></span>
					</div>
				</div>
			</div>
		</div>
	</div>
	
	<div class="card">
		<h2><?php esc_html_e( 'Index Management', 'askany' ); ?></h2>
		<p><?php esc_html_e( 'Rebuild the content index to ensure the chat assistant has access to the latest content.', 'askany' ); ?></p>
		
		<div class="askany-admin-actions">
			<button type="button" class="button button-primary" id="askany-reindex-content">
				<?php esc_html_e('Reindex Content', 'askany'); ?>
			</button>
		</div>
		
		<p class="description">
			<?php esc_html_e( 'Note: Rebuilding the index may take some time depending on the amount of content on your site.', 'askany' ); ?>
		</p>
	</div>
</div>

<!-- Content Viewer Modal -->
<div id="askany-content-viewer-modal" class="askany-modal" style="display: none;">
	<div class="askany-modal-content">
		<div class="askany-modal-header">
			<h2 id="askany-modal-title"><?php esc_html_e('Indexed Content', 'askany'); ?></h2>
			<span class="askany-modal-close">&times;</span>
		</div>
		<div class="askany-modal-body">
			<div id="askany-content-list">
				<!-- Content will be loaded here -->
			</div>
		</div>
	</div>
</div>

<!-- Individual Content Item Modal -->
<div id="askany-content-item-modal" class="askany-modal" style="display: none;">
	<div class="askany-modal-content askany-modal-large">
		<div class="askany-modal-header">
			<h2 id="askany-item-modal-title"><?php esc_html_e('Content Details', 'askany'); ?></h2>
			<span class="askany-modal-close">&times;</span>
		</div>
		<div class="askany-modal-body">
			<div id="askany-content-item-details">
				<!-- Content details will be loaded here -->
			</div>
		</div>
	</div>
</div>

<style>
:root {
	--primary-color: #0073aa;
	--primary-hover: #005177;
	--border-radius: 32px;
	--transition: opacity .15s ease, background-color .15s ease;
}

/* Eye icon SVG for consistency */
.askany-eye-icon {
	width: 16px;
	height: 16px;
}

.askany-modal {
	position: fixed;
	z-index: 100000;
	left: 0;
	top: 0;
	width: 100%;
	height: 100%;
	background-color: rgba(0,0,0,0.5);
}

.askany-modal-content {
	background-color: #fefefe;
	margin: 5% auto;
	padding: 0;
	border: 1px solid #888;
	width: 80%;
	max-width: 800px;
	border-radius: 5px;
	box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.askany-modal-large {
	width: 90%;
	max-width: 1200px;
}

.askany-modal-header {
	padding: 20px;
	background-color: #f1f1f1;
	border-bottom: 1px solid #ddd;
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.askany-modal-header h2 {
	margin: 0;
}

.askany-modal-close {
	color: #aaa;
	font-size: 28px;
	font-weight: bold;
	cursor: pointer;
}

.askany-modal-close:hover {
	color: #000;
}

.askany-modal-body {
	padding: 20px;
	max-height: 70vh;
	overflow-y: auto;
}

.askany-content-item {
	border: 1px solid #ddd;
	margin-bottom: 10px;
	padding: 15px;
	border-radius: 3px;
	background: #f9f9f9;
}

.askany-content-item h4 {
	margin: 0 0 10px 0;
	color: #0073aa;
}

.askany-content-preview {
	color: #666;
	font-style: italic;
	margin: 10px 0;
}

.askany-content-meta {
	font-size: 12px;
	color: #999;
	margin-top: 10px;
}

.askany-view-full-content {
	margin-top: 10px;
}

.askany-content-full {
	background: #fff;
	padding: 15px;
	border: 1px solid #ddd;
	border-radius: 3px;
	white-space: pre-wrap;
	font-family: monospace;
	font-size: 12px;
	line-height: 1.4;
	max-height: 400px;
	overflow-y: auto;
}

.button.button-small {
	padding: 2px 8px;
	font-size: 11px;
	line-height: 1.4;
	margin-left: 10px;
}

/* Enhanced Content Statistics Styling */
.askany-stats-grid {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 20px;
	margin-top: 15px;
}

.askany-stats-column {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.askany-stat-item {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 8px 12px;
	background: #f8f9fa;
	border: 1px solid #e1e5e9;
	border-radius: 6px;
	transition: all 0.2s ease;
}

.askany-stat-item:hover {
	background: #f1f3f4;
	border-color: #d1d5db;
}

.askany-stat-label {
	font-weight: 500;
	color: #374151;
	font-size: 13px;
}

.askany-stat-count {
	font-weight: 600;
	color: #0073aa;
	font-size: 14px;
	margin-left: auto;
	margin-right: 8px;
}

.askany-view-btn {
	align-items: center;
    background-color: transparent;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    display: flex;
    flex-shrink: 0;
    height: 32px;
    justify-content: center;
    margin-left: 8px;
    margin-right: 5px;
    min-width: 32px;
    transition: var(--transition);
    width: 32px;
    color: #959595;
}

.askany-view-btn:hover {
	background-color: var(--primary-hover);
	 color: #ffffffff;
	opacity: 0.9;
}

.askany-view-btn:focus {
	outline: 2px solid var(--primary-color);
	outline-offset: 2px;
}

.askany-view-btn svg {
	width: 16px;
	height: 16px;
}

.askany-total-stat {
	background: #e8f4fd;
	border-color: #0073aa;
	font-weight: 600;
}

.askany-total-stat .askany-stat-label {
	color: #0073aa;
}

.askany-total-stat .askany-stat-count {
	color: #005177;
	font-size: 16px;
}

@media (max-width: 768px) {
	.askany-stats-grid {
		grid-template-columns: 1fr;
		gap: 15px;
	}
	
	.askany-stat-item {
		padding: 10px 12px;
	}
}
</style>

<script>
jQuery(document).ready(function($) {
	// View content button click
	$('.askany-view-content').on('click', function() {
		var contentType = $(this).data('type');
		loadContentList(contentType);
	});
	
	// Modal close functionality
	$('.askany-modal-close').on('click', function() {
		$(this).closest('.askany-modal').hide();
	});
	
	// Close modal when clicking outside
	$('.askany-modal').on('click', function(e) {
		if (e.target === this) {
			$(this).hide();
		}
	});
	
	function loadContentList(contentType) {
		$('#askany-modal-title').text('Indexed Content: ' + contentType.replace('_', ' ').toUpperCase());
		$('#askany-content-list').html('<p>Loading...</p>');
		$('#askany-content-viewer-modal').show();
		
		$.ajax({
			url: ajaxurl,
			type: 'POST',
			data: {
				action: 'askany_get_indexed_content',
				content_type: contentType,
				nonce: '<?php echo wp_create_nonce('askany_admin_nonce'); ?>'
			},
			success: function(response) {
				if (response.success) {
					displayContentList(response.data);
				} else {
					$('#askany-content-list').html('<p>Error loading content: ' + response.data + '</p>');
				}
			},
			error: function() {
				$('#askany-content-list').html('<p>Error loading content.</p>');
			}
		});
	}
	
	function displayContentList(items) {
		var html = '';
		
		if (items.length === 0) {
			html = '<p>No indexed content found for this type.</p>';
		} else {
			items.forEach(function(item) {
				html += '<div class="askany-content-item">';
				html += '<h4>' + escapeHtml(item.title) + '</h4>';
				html += '<div class="askany-content-preview">' + escapeHtml(item.content_preview) + '...</div>';
				html += '<div class="askany-content-meta">';
				html += 'ID: ' + item.id + ' | ';
				html += 'Length: ' + item.content_length + ' chars | ';
				html += 'Updated: ' + item.updated_at;
				if (item.url) {
					html += ' | <a href="' + item.url + '" target="_blank">View Original</a>';
				}
				html += '</div>';
				html += '<button type="button" class="button button-small askany-view-full-content" data-id="' + item.id + '">View Full Content</button>';
				html += '</div>';
			});
		}
		
		$('#askany-content-list').html(html);
		
		// Bind view full content buttons
		$('.askany-view-full-content').on('click', function() {
			var contentId = $(this).data('id');
			loadFullContent(contentId);
		});
	}
	
	function loadFullContent(contentId) {
		$('#askany-item-modal-title').text('Content Details - ID: ' + contentId);
		$('#askany-content-item-details').html('<p>Loading...</p>');
		$('#askany-content-item-modal').show();
		
		$.ajax({
			url: ajaxurl,
			type: 'POST',
			data: {
				action: 'askany_get_content_details',
				content_id: contentId,
				nonce: '<?php echo wp_create_nonce('askany_admin_nonce'); ?>'
			},
			success: function(response) {
				if (response.success) {
					displayFullContent(response.data);
				} else {
					$('#askany-content-item-details').html('<p>Error loading content details: ' + response.data + '</p>');
				}
			},
			error: function() {
				$('#askany-content-item-details').html('<p>Error loading content details.</p>');
			}
		});
	}
	
	function displayFullContent(item) {
		var html = '<h3>' + escapeHtml(item.title) + '</h3>';
		html += '<p><strong>Type:</strong> ' + item.object_type + '</p>';
		html += '<p><strong>Object ID:</strong> ' + item.object_id + '</p>';
		if (item.url) {
			html += '<p><strong>URL:</strong> <a href="' + item.url + '" target="_blank">' + item.url + '</a></p>';
		}
		html += '<p><strong>Created:</strong> ' + item.created_at + '</p>';
		html += '<p><strong>Updated:</strong> ' + item.updated_at + '</p>';
		html += '<p><strong>Content Length:</strong> ' + item.content.length + ' characters</p>';
		html += '<h4>Full Indexed Content:</h4>';
		html += '<div class="askany-content-full">' + escapeHtml(item.content) + '</div>';
		
		$('#askany-content-item-details').html(html);
	}
	
	function escapeHtml(text) {
		var map = {
			'&': '&amp;',
			'<': '&lt;',
			'>': '&gt;',
			'"': '&quot;',
			"'": '&#039;'
		};
		return text.replace(/[&<>"']/g, function(m) { return map[m]; });
	}
});
</script>
