<?php
/**
 * The Primary Site navigation
 *
 * @package Reach
 */

use Reach\App\Fields\SiteOptions;
use Reach\App\Theme\ThemeMenus;

$options       = SiteOptions::getSiteOptions();
$nav_class     = ! empty( $options['header_layout'] ) && 'justified' === $options['header_layout'] ? 'header__nav--center' : '';
$nav_class_alt = ! empty( $options['header_layout'] ) && empty( $options['mega_menu'] ) && 'left' === $options['header_layout'] ? 'header__nav--left' : '';

// get sub menu attributes
$menu       = ThemeMenus::getPrimaryMenuObject();
$menu_meta  = ! empty( $menu ) ? get_term_meta( $menu->term_id ) : [];
$position   = ! empty( $menu_meta['position'][0] ) ? esc_attr( $menu_meta['position'][0] ) : 'right';
$text_align = ! empty( $menu_meta['text_align'][0] ) ? esc_attr( $menu_meta['text_align'][0] ) : 'right';
?>

<nav id="site-navigation" class="header__nav <?php echo $nav_class . ' ' . $nav_class_alt; ?>" role="navigation">
    <?php
    wp_nav_menu( [
        'theme_location' => 'primary',
        'menu_class'     => sprintf( 'sub--pos-%s sub--align-%s', $position, $text_align ),
        'depth'          => 3
    ] );
    ?>
</nav><!-- /#menu-primary -->