<?php if ( ! defined( 'ABSPATH' ) ) {
	exit;} ?>

<header class="menu">
	<a href='https://wpbens.com/discountify/' target="_blank">
		<div class="logo">
			<img src = "<?php echo esc_url( Discountify::assets_url() . 'images/discountify-logo.svg' ); ?>"
				alt="discountify"
			/>
			<span class='version'><?php echo esc_html( 'v ' ) . esc_html( Discountify::get_version() ); ?></span>
		</div>
	</a>
	<?php
		$discountify_menus         = array(
			array(
				'name'   => esc_html__( 'Settings', 'discountify' ),
				'url'    => admin_url() . 'admin.php?page=discountify',
				'slug'   => 'discountify',
				'target' => '_self',
			),
			array(
				'name'   => esc_html__( 'Discount Rules', 'discountify' ),
				'url'    => admin_url() . 'admin.php?page=discountify-rules',
				'slug'   => 'discountify-rules',
				'target' => '_self',
			),
			array(
				'name'   => esc_html__( 'Documentation', 'discountify' ),
				'url'    => 'https://wpbens.com/docs/discountify/',
				'target' => '_blank',
			),
			array(
				'name'   => esc_html__( 'Support', 'discountify' ),
				'url'    => 'https://wpbens.com/support/',
				'target' => '_blank',
			),
			array(
				'name'   => esc_html__( 'Feature Request', 'discountify' ),
				'url'    => 'https://app.loopedin.io/discountify#/ideas/',
				'target' => '_blank',
			),
		);
		$discountify_is_pro_active = Discountify\Utils\Helper::instance()->is_pro_active();
		if ( $discountify_is_pro_active === false ) {
			$discountify_menus[] = array(
				'name'   => esc_html__( 'Upgrade to Pro', 'discountify' ),
				'url'    => 'https://wpbens.com/discountify/',
				'target' => '_blank',
			);
		}
		?>
	<div class="navigation">
		<?php
			// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash -- Navigation parameter for display
			$discountify_current_page = ! empty( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
		foreach ( $discountify_menus as $discountify_key => $discountify_value ) {
			$discountify_active = ( ! empty( $discountify_value['slug'] ) && $discountify_value['slug'] === $discountify_current_page ) ? 'active' : '';
			$discountify_class  = $discountify_value === end( $discountify_menus ) ? 'upgrade_pro' : '';
			?>
				<li>
					<a class="<?php echo esc_attr( $discountify_class ) . ' ' . esc_attr( $discountify_active ); ?>" href="<?php echo esc_url( $discountify_value['url'] ); ?>"
					target="<?php echo esc_attr( $discountify_value['target'] ); ?>">
				<?php echo esc_html( $discountify_value['name'] ); ?>
					</a>
				</li>
				<?php
		}
		?>
	</div>
</header>
