<?php

/**
 * Navigation.php template
 *
 * Shows main navigation menu.
 *
 * This template can be overridden by copying it to your theme your-theme/sysbasics-myaccount/navigation.php , for better practice create your child theme and copy it to your-child-theme/sysbasics-myaccount/navigation.php.
 *
 */

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

do_action( 'woocommerce_before_account_navigation' );



$wcmamtx_tabs          =  (array) get_option('wcmamtx_advanced_settings');



$items                 =  wc_get_account_menu_items();

foreach ($items as $itkey=>$itvalue) {
    if (!array_key_exists($itkey, $wcmamtx_tabs)) {

        $third_party_check = wcmamtx_third_party_goahead_check($itkey);

        $new_array = array();


        if ($third_party_check == "yes") {

            unset($items[$itkey]);
            $new_array = array($itkey=>$itvalue);
        }

        


        update_option('wcmamtx_tabs_to_add_third_party',$new_array);
    }
}

$core_fields    = 'dashboard,orders,downloads,edit-address,edit-account,customer-logout';

$core_fields_array =  array(
    'dashboard'       => esc_html__('Dashboard','customize-my-account-for-woocommerce'),
    'orders'          => esc_html__('Orders','customize-my-account-for-woocommerce'),
    'downloads'       => esc_html__('Downloads','customize-my-account-for-woocommerce'),
    'edit-address'    => esc_html__('Addresses','customize-my-account-for-woocommerce'),
    'edit-account'    => esc_html__('Account Details','customize-my-account-for-woocommerce'),
    'customer-logout' => esc_html__('Log out','customize-my-account-for-woocommerce')
  );






foreach ($items as $ikey=>$ivalue) {

    if (!array_key_exists($ikey, $wcmamtx_tabs) && !array_key_exists($ikey, $core_fields_array) ) {
        
        $match_index = 0;

        foreach ($wcmamtx_tabs as $tkey=>$tvalue) {
            if (isset($tvalue['endpoint_key']) && ($tvalue['endpoint_key'] == $ikey)) {
                $match_index++;
            }
        }

        if ($match_index == 0) {
            $wcmamtx_tabs[$ikey] = array(
              'show' => 'yes',
              'third_party'  => 'yes',
              'endpoint_key' => $ikey,
              'wcmamtx_type' => 'endpoint',
              'parent'       => 'none',
              'endpoint_name'=> $ivalue,
          );   
        }           

    }
}



$plugin_options = get_option('wcmamtx_plugin_options');


$menu_shape = 'vertical';



if (isset($plugin_options['horizontal_menu']) && ($plugin_options['horizontal_menu'] == "yes")) {

    $menu_shape = 'horizontal';

} else {

    $menu_shape = 'vertical';
}

$icon_position  = 'right';
$icon_extra_class = '';

if (!is_array($wcmamtx_tabs)) { 
    $wcmamtx_tabs = $items;
    
}

if (!isset($wcmamtx_tabs) || (count($wcmamtx_tabs) === 1) || isset($wcmamtx_tabs[0])) {
    $wcmamtx_tabs = $items;
    
}


                    $core_fields_array_filter =  array(
                        'dashboard'=>'dashboard',
                        'orders'=>'orders',
                        'downloads'=>'downloads',
                        'edit-address'=>'edit-address',
                        'edit-account'=>'edit-account',
                        'customer-logout'=>'customer-logout',
                        'payment-methods'=>'payment-methods'
                    );


        foreach($wcmamtx_tabs as $gtkey=>$gtvalue) {

            if (!array_key_exists($gtkey, $core_fields_array_filter)) {
                  $third_party_check = wcmamtx_third_party_goahead_check($gtkey);

                  $wcmamtx_type = isset($gtvalue['wcmamtx_type']) ? $gtvalue['wcmamtx_type'] : "endpoint";

                                $act_goahead = "yes";

              $act_goahead = wcmamtx_act_goahead_check_verified();


              if ($act_goahead == "yes") {
                  if (($third_party_check == "no") && ($wcmamtx_type == "endpoint") && (strpos($gtkey, 'custom-endpoint-') === false))   {
                     unset($wcmamtx_tabs[$gtkey]);
                 }
             } else if ($act_goahead == "no") {
                if (($third_party_check == "no") && ($wcmamtx_type == "endpoint")) {
                    unset($wcmamtx_tabs[$gtkey]);
                }
            }
            }

        }



if (isset($plugin_options['icon_position']) && ($plugin_options['icon_position'] != '')) {
    $icon_position = $plugin_options['icon_position'];
}

if (isset($plugin_options['menu_position']) && ($plugin_options['menu_position'] != '')) {
    $menu_position = $plugin_options['menu_position'];
}



switch($icon_position) {
	case "right":
	   $icon_extra_class = "wcmamtx_custom_right";
	break;

	case "left":
	   $icon_extra_class = "wcmamtx_custom_left";
	break;

	default:
	   $icon_extra_class = "wcmamtx_custom_right";
	break;
}

$menu_position_extra_class = "";

if (isset($menu_position) && ($menu_position != '')) {
    switch($menu_position) {
        case "left":
        $menu_position_extra_class = "wcmamtx_menu_left";
        break;

        case "right":
        $menu_position_extra_class = "wcmamtx_menu_right";
        break;

        default:
        $menu_position_extra_class = "";
        break;
    }
}






if ($menu_shape == 'vertical') {

    $wcmamtx_layout = wcmamtx_get_layout();


    


    

    $theme_strings = wcmamtx_get_clean_design_theme_array();




    $nav_style = isset($wcmamtx_layout['nav_style']) ? $wcmamtx_layout['nav_style'] : wcmamtx_get_clean_design_theme_array();
if ( ! is_string( $nav_style ) ) { $nav_style = '02'; }
$nav_style = preg_replace( '/[^0-9a-zA-Z_-]/', '', basename( $nav_style ) );
if ( $nav_style === '' ) { $nav_style = '02'; }


    
    $nav_template = "navigation/$nav_style.php";

    $nav_template = apply_filters("wcmamtx_override_navigation_template",$nav_template,$wcmamtx_layout,$wcmamtx_tabs);

        $file_to_check = "wcmamtx_template/navigation/$nav_style.php"; // Change to your relative file path

        if ( file_exists( get_stylesheet_directory() . '/' . $file_to_check ) ) {
         // The file exists in the active child theme
         $nav_template = ''.get_stylesheet_directory().'/wcmamtx_template/navigation/'.$nav_style.'.php';
     }

     include($nav_template);
     
     
     
 } else {



    include ("menu_default.php");


}

do_action( 'woocommerce_after_account_navigation' ); ?>