<?php
/**
 * Admin Dashboard View — Arabic Control Center.
 *
 * @package Kutby
 * @var string               $panel  Active panel.
 * @var array<string, mixed> $panels Panel map.
 * @var bool                 $notice Saved notice flag (legacy query arg).
 */

declare(strict_types=1);

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

use Kutby\Admin\Notifications\Notices;
use Kutby\Admin\UI\Components;
use Kutby\Icons\Icon;
use Kutby\Pages\PageFactory;
?>
<div class="wrap kutby-admin" dir="rtl" lang="ar">
	<div class="kutby-admin__shell">
		<?php Components::sidebar_start( 'قائمة إعدادات كتبي' ); ?>
			<div class="kutby-admin__brand">
				<span class="kutby-admin__brand-mark" aria-hidden="true">ك</span>
				<div>
					<strong>كتبي</strong>
					<small>مركز التحكم</small>
				</div>
			</div>

			<nav class="kutby-admin__nav">
				<?php foreach ( $panels as $id => $meta ) : ?>
					<?php
					$url    = add_query_arg(
						array(
							'page'  => KUTBY_ADMIN_SLUG,
							'panel' => $id,
						),
						admin_url( 'admin.php' )
					);
					$active = ( $panel === $id ) ? ' is-active' : '';
					$icon   = (string) ( $meta['icon'] ?? 'settings' );
					?>
					<a class="kutby-admin__nav-item<?php echo esc_attr( $active ); ?>" href="<?php echo esc_url( $url ); ?>">
						<span class="kutby-admin__nav-icon" aria-hidden="true"><?php Icon::print( $icon, '', 'sm' ); ?></span>
						<span><?php echo esc_html( (string) ( $meta['label'] ?? $id ) ); ?></span>
					</a>
				<?php endforeach; ?>
			</nav>
		<?php Components::sidebar_end(); ?>

		<main class="kutby-admin__main">
			<?php
			Notices::render_flash();
			if ( $notice ) {
				Notices::render( 'تم حفظ الإعدادات بنجاح.', Notices::SUCCESS, true, true );
			}
			PageFactory::render( $panel );
			?>
		</main>
	</div>
</div>
