<?php if ( ! defined( 'ABSPATH' ) ) {
	exit;} ?>
<header class="menu">
   <a href='https://wpbens.com/plugins/quicker/' target="_blank">
	   <div class="logo">
		   <img src = "<?php echo esc_url( Quicker::assets_url() . 'images/quicker-icon.svg' ); ?>"
			   alt="quicker-logo" width="48px" />
		   <span class='version'><?php echo esc_html( 'v ' . Quicker::get_version() ); ?></span>
	   </div>
   </a>
   <?php
	   $menus = array(
		   array(
			   'name'   => esc_html__( 'Settings', 'quicker' ),
			   'url'    => admin_url() . 'admin.php?page=quicker-settings',
			   'slug'   => 'quicker-settings',
			   'target' => '_self',
		   ),
		   array(
			   'name'   => esc_html__( 'Checkout Fields', 'quicker' ),
			   'url'    => admin_url() . 'admin.php?page=quicker-checkout-fields',
			   'slug'   => 'quicker-checkout-fields',
			   'target' => '_self',
		   ),
		   array(
			   'name'   => esc_html__( 'Resources', 'quicker' ),
			   'submenu' => array(
				   array(
					   'name'   => esc_html__( 'Documentation', 'quicker' ),
					   'url'    => 'https://wpbens.com/docs/quicker/',
					   'target' => '_blank',
				   ),
				   array(
					   'name'   => esc_html__( 'Support', 'quicker' ),
					   'url'    => 'https://wpbens.com/support/',
					   'target' => '_blank',
				   ),
				   array(
					   'name'   => esc_html__( 'Feature Request', 'quicker' ),
					   'url'    => 'https://app.loopedin.io/quicker#/roadmap',
					   'target' => '_blank',
				   ),
			   ),
		   )
	   );
	   if ( ! class_exists( 'QuickerPro' ) ) {
		   $menus[] = array(
			   'name'   => esc_html__( 'Upgrade to Pro', 'quicker' ),
			   'url'    => 'https://wpbens.com/plugins/quicker/',
			   'target' => '_blank',
		   );
	   }

   ?>


	
	<div class="navigation">
		<?php
			// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Menu page navigation does not require nonce
			$current_page = ! empty( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
			foreach ( $menus as $key => $value ) {
				$active = ( ! empty( $value['slug'] ) && $value['slug'] == $current_page ) ? 'active' : '';
				$class  = $value === end( $menus ) ? 'upgrade_pro' : '';
				?>
					<li class="menu-item<?php echo ! empty( $value['submenu'] ) ? ' has-submenu' : ''; ?>">
						<?php if ( ! empty( $value['submenu'] ) ) : ?>
							<a class="menu-trigger <?php echo esc_attr( $active ); ?>">
								<?php echo esc_html( $value['name'] ); ?>
								<span class="submenu-arrow">
									<svg width="10" height="6" viewBox="0 0 10 6" fill="none" xmlns="http://www.w3.org/2000/svg">
										<path d="M1 1L5 5L9 1" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
									</svg>
								</span>
							</a>
							<ul class="submenu">
								<?php foreach ( $value['submenu'] as $submenu ) : ?>
									<li>
										<a href="<?php echo esc_url( $submenu['url'] ); ?>" 
											target="<?php echo esc_attr( $submenu['target'] ); ?>">
											<?php echo esc_html( $submenu['name'] ); ?>
										</a>
									</li>
								<?php endforeach; ?>
							</ul>
							<?php else : ?>
							<a class="<?php echo esc_attr( $class ) . ' ' . esc_attr( $active ); ?>" 
								href="<?php echo esc_url( $value['url'] ); ?>"
								target="<?php echo esc_attr( $value['target'] ); ?>">
								<?php echo esc_html( $value['name'] ); ?>
							</a>
						<?php endif; ?>
					</li>
					<?php
			}
		?>
	</div>
</header>