<?php
/**
 * Documentation Viewer Template
 *
 * Displays formatted HTML documentation with navigation breadcrumbs.
 *
 * @package Card_Oracle/Admin/Partials
 * @since   1.2.1
 */

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

<div class="co-dashboard">
	<header class="co-dashboard__hero co-dashboard__hero--subtle">
		<div class="co-dashboard__hero-text">
			<span class="co-dashboard__badge"><?php esc_html_e( 'Documentation', 'card-oracle' ); ?></span>
			<h1 class="co-dashboard__hero-title">
				<span class="dashicons <?php echo esc_attr( $current_doc['icon'] ); ?>" style="font-size: 28px; width: 28px; height: 28px; margin-right: 8px;"></span>
				<?php echo esc_html( $current_doc['title'] ); ?>
			</h1>
			<nav class="co-doc-breadcrumbs" aria-label="<?php esc_attr_e( 'Breadcrumb', 'card-oracle' ); ?>">
				<a href="<?php echo esc_url( admin_url( 'admin.php?page=card-oracle-admin-documentation' ) ); ?>">
					<?php esc_html_e( 'All Documentation', 'card-oracle' ); ?>
				</a>
				<span class="separator" aria-hidden="true">&rsaquo;</span>
				<span class="current" aria-current="page"><?php echo esc_html( $current_doc['title'] ); ?></span>
			</nav>
		</div>
		<div class="co-dashboard__hero-actions">
			<a class="button button-secondary" href="<?php echo esc_url( admin_url( 'admin.php?page=card-oracle-admin-documentation' ) ); ?>">
				<span class="dashicons dashicons-arrow-left-alt2" style="margin-top: 3px;"></span>
				<?php esc_html_e( 'Back to Documentation', 'card-oracle' ); ?>
			</a>
		</div>
	</header>

	<section class="co-dashboard__section co-dashboard__section--panel">
		<div class="co-dashboard__panel-body">
			<div class="co-doc-content">
				<?php
				// Safe HTML is already sanitized with wp_kses in the display function.
				echo $safe_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
				?>
			</div>
		</div>
	</section>
</div>

<script>
// Keep Card Oracle menu expanded on doc-viewer page.
jQuery(document).ready(function($) {
	var $coMenu = $('#toplevel_page_card-oracle-admin-menu');
	if ($coMenu.length) {
		$coMenu.addClass('wp-has-current-submenu wp-menu-open').removeClass('wp-not-current-submenu');
		$coMenu.find('> a').addClass('wp-has-current-submenu wp-menu-open').removeClass('wp-not-current-submenu');
		// Highlight Documentation submenu item.
		$coMenu.find('a[href*="card-oracle-admin-documentation"]').parent().addClass('current');
	}
});
</script>
