<?php
/**
* Menu Functions
*
* @package GridRead WordPress Theme
* @copyright Copyright (C) 2025 ThemesDNA
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
* @author ThemesDNA <themesdna@gmail.com>
*/

// Get our wp_nav_menu() fallback, wp_page_menu(), to show a "Home" link as the first item
function gridread_page_menu_args( $args ) {
    $args['show_home'] = true;
    return $args;
}
add_filter( 'wp_page_menu_args', 'gridread_page_menu_args' );

function gridread_primary_menu_text() {
   $menu_text = esc_html__( 'Menu', 'gridread' );
    if ( gridread_get_option('primary_menu_text') ) {
        $menu_text = gridread_get_option('primary_menu_text');
    }
   return apply_filters( 'gridread_primary_menu_text', $menu_text );
}

function gridread_secondary_menu_text() {
   $menu_text = esc_html__( 'Menu', 'gridread' );
    if ( gridread_get_option('secondary_menu_text') ) {
        $menu_text = gridread_get_option('secondary_menu_text');
    }
   return apply_filters( 'gridread_secondary_menu_text', $menu_text );
}

function gridread_primary_fallback_menu() {
   wp_page_menu( array(
        'sort_column'  => 'menu_order, post_title',
        'menu_id'      => 'gridread-menu-primary-navigation',
        'menu_class'   => 'gridread-primary-nav-menu gridread-menu-primary',
        'container'    => 'ul',
        'echo'         => true,
        'link_before'  => '',
        'link_after'   => '',
        'before'       => '',
        'after'        => '',
        'item_spacing' => 'discard',
        'walker'       => '',
    ) );
}

function gridread_secondary_fallback_menu() {
   wp_page_menu( array(
        'sort_column'  => 'menu_order, post_title',
        'menu_id'      => 'gridread-menu-secondary-navigation',
        'menu_class'   => 'gridread-secondary-nav-menu gridread-menu-secondary',
        'container'    => 'ul',
        'echo'         => true,
        'link_before'  => '',
        'link_after'   => '',
        'before'       => '',
        'after'        => '',
        'item_spacing' => 'discard',
        'walker'       => '',
    ) );
}

function gridread_secondary_menu_area() {
if ( gridread_is_secondary_menu_active() ) { ?>
<div class="gridread-secondary-menu-container gridread-clearfix">
<div class="gridread-secondary-menu-container-inside gridread-clearfix">
<nav class="gridread-nav-secondary" id="gridread-secondary-navigation" itemscope="itemscope" itemtype="http://schema.org/SiteNavigationElement" role="navigation" aria-label="<?php esc_attr_e( 'Secondary Menu', 'gridread' ); ?>">
<div class="gridread-boxview-wrapper">
<button class="gridread-secondary-responsive-menu-icon" aria-controls="gridread-menu-secondary-navigation" aria-expanded="false"><?php echo esc_html( gridread_secondary_menu_text() ); ?></button>
<?php wp_nav_menu( array( 'theme_location' => 'secondary', 'menu_id' => 'gridread-menu-secondary-navigation', 'menu_class' => 'gridread-secondary-nav-menu gridread-menu-secondary gridread-clearfix', 'fallback_cb' => 'gridread_secondary_fallback_menu', 'container' => '', ) ); ?>
</div>
</nav>
</div>
</div>
<?php }
}