<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly.
}

$wcmamtx_layout = wcmamtx_get_layout();

$sidebar_style = "01";

$extra_nav_sidebar_class = "";

if ($sidebar_style == "02") {
    $extra_nav_sidebar_class = "wcmamtx_float_sidebar_right";
}

?>
<nav class="woocommerce-MyAccount-navigation wsmt_extra_navclass <?php echo $extra_nav_sidebar_class; ?> <?php echo $menu_position_extra_class; ?>">

    <?php

    $show_avatar = 'yes';

    $avatar_settings = (array) get_option( 'wcmamtx_avatar_settings' );


    if (!isset($avatar_settings['disable_avatar'])) {


        $avatar_settings['intro_text_hello']      = 'yes';
        $avatar_settings['disable_avatar']        = 'yes';
        $avatar_settings['custom_avatar_content'] = 'yes';

    }

    // Always use the saved DB value for custom_avatar_content so setting it
    // to 'no' in the customizer is respected even when above defaults ran.
    $_fresh_avatar = (array) get_option( 'wcmamtx_avatar_settings' );
    if ( array_key_exists( 'custom_avatar_content', $_fresh_avatar ) ) {
        $avatar_settings['custom_avatar_content'] = $_fresh_avatar['custom_avatar_content'];
    }

    if (isset($avatar_settings['disable_avatar']) && ($avatar_settings['disable_avatar'] == "yes")) {

        $show_avatar = 'yes';
    } else {
        $show_avatar = 'no';
    }


    

    if (($show_avatar == 'yes')) {
        echo (new wcmamtx_upload_avatar_tab())->wcmamtx_shortcode();
    }



    if (isset($avatar_settings['custom_avatar_content']) && ($avatar_settings['custom_avatar_content'] == "yes") && ($show_avatar == "yes")) {

        $editor_content_avatar = isset($avatar_settings['content_avatar']) ? $avatar_settings['content_avatar'] : '<p class="wcmamtx_default_text_below_avatar" style="text-align: center;">Hello <strong>{display_name}</strong> (not <strong>{display_name}</strong>? <a href="{user_logout_link}">Log out</a>)</p>';

        

        $editor_content_avatar = wcmamtx_parse_smart_tag_function($editor_content_avatar);

        echo '<div id="wcmamtx-avatar-content-output">' . wp_kses_post( $editor_content_avatar ) . '</div>';

    }

    $wcmamtx_layout = wcmamtx_get_layout();

    $default_style = isset($wcmamtx_layout['style']) ? $wcmamtx_layout['style'] : "01";

    ?>
   
	<ul class="wcmamtx_vertical style_<?php echo $default_style; ?>">
		<?php foreach ( $wcmamtx_tabs as $key => $value ) { 



			if (isset($value['endpoint_name']) && ($value['endpoint_name'] != '')) {
                $name = $value['endpoint_name'];
            } else {
                $name = $value;
            }

            $should_show = 'yes';


            if (isset($value['visibleto']) && ($value['visibleto'] != "all")) {

                $allowedroles  = isset($value['roles']) ? $value['roles'] : "";

                $allowedusers  = isset($value['users']) ? $value['users'] : array();

                $is_visible    = wcmamtx_check_role_visibility($allowedroles,$value['visibleto'],$allowedusers);
                
            } else {

                $is_visible = 'yes';
            }



            if (isset($value['show']) && ($value['show'] == "no")) {
                
                 $should_show = 'no';
                
            }


            if (isset($value['class']) && ($value['class'] != '')) {
            	$extraclass = str_replace(',',' ', $value['class']);
            } else {
            	$extraclass = '';
            }

            if (isset($value['endpoint_key']) && ($value['endpoint_key'] != '')) {
            	$key = $value['endpoint_key'];
            }

            if (isset($value['parent']) && ($value['parent'] != '')) {
                $parent = $value['parent'];
            } else {
                $parent = 'none';
            }


            
            $icon_source       = isset($value['icon_source']) ? $value['icon_source'] : "default";

            $hide_in_navigation = isset($value['hide_in_navigation']) && ($value['hide_in_navigation'] == "01") ? "enabled" : "disabled";

            if (isset($hide_in_navigation) && ($hide_in_navigation == "enabled")) {
                
                 $should_show = 'no';
                
            }


            $third_party = isset($value['third_party']) ? $value['third_party'] : null; 

            $third_party_go_ahead = 'yes';

            if (isset($third_party)) {
           
                 $third_party_go_ahead = wcmamtx_third_party_goahead_check($key);

                 if ($third_party_go_ahead == "no") {
                    $should_show = 'no';
                 }
            }


            if (($should_show == "yes") && ($is_visible == "yes")) {
            
                if (isset($value['wcmamtx_type']) && ($value['wcmamtx_type'] == "group")) {

                    
                    wcmamtx_get_account_menu_group_html( $name,$key ,$value ,$icon_extra_class,$extraclass,$icon_source );
                    
                    

            
                } else {

                   

                    if (($parent == "none")) {


                        wcmamtx_get_account_menu_li_html( $name,$key ,$value ,$icon_extra_class,$extraclass,$icon_source );
                    }

                } ?>

            <?php } ?>
		
		<?php } ?>
	</ul>
    <?php do_action( 'wcmamtx_after_account_navigation' ); ?>
</nav>