<?php


function save_navigation($file_name, $menu_data) {
    $template_path = get_stylesheet_directory() . '/navigations';

    if (!file_exists($template_path)) {
        mkdir($template_path, 0777, true);
    }

    $file_path = $template_path . '/' . $file_name . '.txt';

    error_log("📝 File Path: " . $file_path);

    if ((isset($_GET['generate-nav']) && $_GET['generate-nav'] == 'true')
        || !file_exists($file_path)) {
        error_log("✍ Writing file now...");
        file_put_contents($file_path, $menu_data);
    } else {
        error_log("⏩ Skipping file write...");
    }
}



/********* get_header_mobile_navigation *********/
function get_header_mobile_navigation() {
    $menu = '<div class="collapse navbar-collapse justify-content-end" id="navbarText">' .
        wp_nav_menu(array(
            'theme_location' => 'primary-menu',
            'container'      => false,
            'echo'           => false,
            'menu_class'     => 'navbar-nav gap-2 gap-lg-1 mb-2 mb-lg-0 mx-auto',
            'fallback_cb'    => false,
            'items_wrap'     => '<ul id="%1$s" class="%2$s">%3$s</ul>',
            'depth'          => 2,
            'walker'         => new WP_Bootstrap_Navwalker(),
        )) .
        '<div class="contact-btn">
            <a href="' . site_url() . '/signup/">Start for free</a>
        </div>
    </div>';

    save_navigation('navigation-data', $menu);

    return $menu;
}

function get_header_mobile_navigation_white() {
    $menu = '<div class="collapse navbar-collapse justify-content-end" id="navbarText">' .
        wp_nav_menu(array(
        'theme_location' => 'primary-menu',
        'container' => false,
        'menu_class' => 'navbar-nav mb-2 mb-lg-0',
        'fallback_cb' => '__return_false',
        'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
        'depth' => 2,
        'walker' => new WP_Bootstrap_Navwalker(), 
        )) .
        '<div class="contact-btn">
            <a href="' . site_url() . '/signup/">Start for free</a>
        </div>
    </div>';

    save_navigation('header-white', $menu);

    return $menu;
}
