<?php
/**
 * Shared CertaCart app navigation.
 *
 * @package CertaCart_EU_Product_Readiness
 */

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

$ccpr_current_page = isset( $ccpr_current_page ) ? sanitize_key( $ccpr_current_page ) : 'home';
$ccpr_nav_items    = array(
	'home'     => array( __( 'Home', 'certacart-eu-product-readiness' ), admin_url( 'admin.php?page=ccpr-readiness' ), 'dashicons-admin-home' ),
	'tasks'    => array( __( 'Tasks', 'certacart-eu-product-readiness' ), admin_url( 'admin.php?page=ccpr-tasks' ), 'dashicons-yes-alt' ),
	'history'  => array( __( 'History', 'certacart-eu-product-readiness' ), admin_url( 'admin.php?page=ccpr-history' ), 'dashicons-backup' ),
	'settings' => array( __( 'Settings', 'certacart-eu-product-readiness' ), admin_url( 'admin.php?page=ccpr-settings' ), 'dashicons-admin-generic' ),
);

if ( post_type_exists( 'ccpr_profile' ) ) {
	$ccpr_nav_items = array_slice( $ccpr_nav_items, 0, 2, true ) + array(
		'profiles' => array( __( 'Profiles', 'certacart-eu-product-readiness' ), admin_url( 'edit.php?post_type=ccpr_profile' ), 'dashicons-admin-users' ),
	) + array_slice( $ccpr_nav_items, 2, null, true );
}
?>
<header class="ccpr-app-header">
	<a class="ccpr-brand" href="<?php echo esc_url( admin_url( 'admin.php?page=ccpr-readiness' ) ); ?>">
		<span class="ccpr-brand-mark" aria-hidden="true">C</span>
		<span>CertaCart</span>
	</a>
	<nav class="ccpr-app-nav" aria-label="<?php esc_attr_e( 'CertaCart navigation', 'certacart-eu-product-readiness' ); ?>">
		<?php foreach ( $ccpr_nav_items as $ccpr_nav_key => $ccpr_nav_item ) : ?>
			<a class="<?php echo $ccpr_current_page === $ccpr_nav_key ? 'is-current' : ''; ?>" href="<?php echo esc_url( $ccpr_nav_item[1] ); ?>" <?php echo $ccpr_current_page === $ccpr_nav_key ? 'aria-current="page"' : ''; ?>>
				<span class="dashicons <?php echo esc_attr( $ccpr_nav_item[2] ); ?>" aria-hidden="true"></span>
				<?php echo esc_html( $ccpr_nav_item[0] ); ?>
			</a>
		<?php endforeach; ?>
	</nav>
	<div class="ccpr-app-actions">
		<?php if ( post_type_exists( 'ccpr_profile' ) && 'profiles' === $ccpr_current_page ) : ?>
			<a class="ccpr-tool-link" href="<?php echo esc_url( admin_url( 'admin.php?page=ccpr-pro-bulk-tools' ) ); ?>"><?php esc_html_e( 'Bulk actions', 'certacart-eu-product-readiness' ); ?></a>
		<?php elseif ( post_type_exists( 'ccpr_profile' ) && 'settings' === $ccpr_current_page ) : ?>
			<a class="ccpr-tool-link" href="<?php echo esc_url( admin_url( 'admin.php?page=ccpr-pro-settings' ) ); ?>"><?php esc_html_e( 'Pro settings', 'certacart-eu-product-readiness' ); ?></a>
		<?php endif; ?>
		<a class="ccpr-exit-link" href="<?php echo esc_url( admin_url( 'admin.php?page=wc-admin' ) ); ?>">
			<span class="dashicons dashicons-arrow-left-alt2" aria-hidden="true"></span>
			<?php esc_html_e( 'Back to WooCommerce', 'certacart-eu-product-readiness' ); ?>
		</a>
	</div>
</header>
