<?php
/**
 * BaseCloud Boost — Admin Sidebar Navigation (v7 Glassmorphism)
 *
 * Included at the top of every admin view. Renders the full-screen
 * fixed left sidebar and the Ballpit canvas background.
 *
 * @package BaseCloud\Boost
 */

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

$current_page = $_GET['page'] ?? 'basecloud-dashboard';

$tabs = [
	'basecloud-dashboard' => [
		'label' => __( 'Dashboard', 'basecloud-boost' ),
		'icon'  => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="7" height="7" rx="1"/><rect x="14" y="3" width="7" height="7" rx="1"/><rect x="3" y="14" width="7" height="7" rx="1"/><rect x="14" y="14" width="7" height="7" rx="1"/></svg>',
	],
	'basecloud-page-cache' => [
		'label' => __( 'Page Cache', 'basecloud-boost' ),
		'icon'  => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/></svg>',
	],
	'basecloud-file-optimization' => [
		'label' => __( 'File Optimization', 'basecloud-boost' ),
		'icon'  => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"/><path d="M19.07 4.93a10 10 0 0 1 0 14.14M4.93 4.93a10 10 0 0 0 0 14.14"/></svg>',
	],
	'basecloud-media' => [
		'label' => __( 'Media', 'basecloud-boost' ),
		'icon'  => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg>',
	],
	'basecloud-preload' => [
		'label' => __( 'Preload', 'basecloud-boost' ),
		'icon'  => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="23 4 23 10 17 10"/><path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/></svg>',
	],
	'basecloud-cdn' => [
		'label' => __( 'CDN', 'basecloud-boost' ),
		'icon'  => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="2" y1="12" x2="22" y2="12"/><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/></svg>',
	],
	'basecloud-database' => [
		'label' => __( 'Database', 'basecloud-boost' ),
		'icon'  => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"/><path d="M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"/></svg>',
	],
	'basecloud-advanced' => [
		'label' => __( 'Advanced', 'basecloud-boost' ),
		'icon'  => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></svg>',
	],
	'basecloud-appearance' => [
		'label' => __( 'Appearance', 'basecloud-boost' ),
		'icon'  => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 22a10 10 0 1 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.2a1.8 1.8 0 0 0-1.4 2.9 1.8 1.8 0 0 1-1.4 3.1z"/><circle cx="7.5" cy="11.5" r="1"/><circle cx="12" cy="7.5" r="1"/><circle cx="16.5" cy="11.5" r="1"/></svg>',
	],
	'basecloud-webhook' => [
		'label' => __( 'Webhook', 'basecloud-boost' ),
		'icon'  => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>',
	],
	'basecloud-lighthouse' => [
		'label' => __( 'Lighthouse', 'basecloud-boost' ),
		'icon'  => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/><line x1="12" y1="2" x2="12" y2="4"/><line x1="12" y1="20" x2="12" y2="22"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/><line x1="2" y1="12" x2="4" y2="12"/><line x1="20" y1="12" x2="22" y2="12"/></svg>',
	],
	'basecloud-tools' => [
		'label' => __( 'Tools', 'basecloud-boost' ),
		'icon'  => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"/></svg>',
	],
];
?>
<?php
// Backdrop selection: 'classic' draws particles on the shared canvas
// (admin.js); video themes render a looping ambient <video>; 'dark' and
// 'light' are pure CSS — no canvas, no video. Slug is whitelisted — never
// interpolate an unvalidated option into a src. Videos are muted+playsinline
// (autoplay-safe); admin.js pauses them under prefers-reduced-motion and in
// hidden tabs.
$bcb_admin_theme = \BaseCloud\Boost\Admin\Admin_Controller::normalize_theme(
	(string) BCBOOST_get_option( 'admin_theme', 'dark' )
);
$bcb_video_slug = ( 0 === strpos( $bcb_admin_theme, 'video-' ) ) ? substr( $bcb_admin_theme, 6 ) : '';
?>
<?php if ( '' !== $bcb_video_slug ) : ?>
<!-- Ambient video backdrop -->
<video id="bcboost-bg-video" class="bcboost-bg-video" autoplay muted loop playsinline
	preload="auto" aria-hidden="true" tabindex="-1"
	src="<?php echo esc_url( BCBOOST_URL . 'admin/videos/' . $bcb_video_slug . '.webm' ); ?>"></video>
<?php elseif ( 'classic' === $bcb_admin_theme ) : ?>
<!-- Classic particles background canvas -->
<canvas id="bcboost-ballpit-canvas" aria-hidden="true"></canvas>
<?php endif; ?>

<!-- BaseCloud Boost Sidebar -->
<aside class="bcboost-sidebar" role="navigation" aria-label="<?php esc_attr_e( 'BaseCloud Boost Navigation', 'basecloud-boost' ); ?>">

	<!-- Wordmark -->
	<a class="bcboost-sidebar-logo" href="<?php echo esc_url( admin_url( 'admin.php?page=basecloud-dashboard' ) ); ?>" aria-label="BaseCloud Boost">
		<span class="bcboost-sidebar-brand">BaseCloud</span>
		<span class="bcboost-sidebar-product">Boost</span>
	</a>

	<!-- Navigation -->
	<nav class="bcboost-nav" aria-label="<?php esc_attr_e( 'Plugin sections', 'basecloud-boost' ); ?>">
		<?php foreach ( $tabs as $slug => $tab ) :
			$is_active = ( $current_page === $slug );
			$class     = 'bcboost-nav-item' . ( $is_active ? ' bcboost-nav-item--active' : '' );
			$aria      = $is_active ? ' aria-current="page"' : '';
		?>
		<a href="<?php echo esc_url( admin_url( 'admin.php?page=' . $slug ) ); ?>"
		   class="<?php echo esc_attr( $class ); ?>"
		   <?php echo $aria; ?>>
			<?php echo $tab['icon']; /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- SVG is hardcoded */ ?>
			<span><?php echo esc_html( $tab['label'] ); ?></span>
		</a>
		<?php endforeach; ?>
	</nav>

	<!-- Sidebar Footer -->
	<div class="bcboost-sidebar-footer">
		<span class="bcboost-version-badge">v<?php echo esc_html( BCBOOST_VERSION ); ?></span>
		<a href="<?php echo esc_url( admin_url() ); ?>" class="bcboost-btn bcboost-btn--ghost bcboost-btn--small bcboost-back-btn" style="width:100%;justify-content:center;margin-bottom:8px;text-decoration:none;">
			<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M19 12H5M12 19l-7-7 7-7"/></svg>
			<?php esc_html_e( 'WP Admin', 'basecloud-boost' ); ?>
		</a>
		<button class="bcboost-btn bcboost-btn--primary bcboost-btn--small" id="bcboost-clear-cache" style="width:100%;justify-content:center;">
			<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14M12 5l7 7-7 7"/></svg>
			<?php esc_html_e( 'Boost Cache', 'basecloud-boost' ); ?>
		</button>
	</div>

</aside>

<div id="bcboost-action-feedback" class="bcboost-feedback" style="display:none;position:fixed;bottom:24px;right:24px;z-index:9999;min-width:260px;"></div>
