<?php
/**
 * Render the core header navigation.
 */
namespace Greyd\Navigation;

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

new Render();
class Render {

	public function __construct() {
		if ( ! strpos( $_SERVER['SCRIPT_FILENAME'], 'wp-activate.php' ) ) {
			add_action( 'wp', array( $this, 'render' ), 10 );
			add_action( 'analytics', array( $this, 'add_analytics' ), 10, 1 );
		} else {
			add_action( 'navigation', array( $this, 'add_empty_navigation' ) );
		}

	}

	public function render() {
		// debug(get_theme_mod('enable_headerconcept', false));
		if ( get_theme_mod( 'enable_headerconcept', false ) ) {
			add_action( 'navigation', array( $this, 'add_navigation' ) );
			add_action( 'footer', array( $this, 'add_footer' ) );
		} else {
			// deprecated header v1
			require get_template_directory() . '/inc/deprecated/header.php';
		}
	}

	public function add_analytics( $position ) {
		if ( is_customize_preview() || isset( $_GET['popup_preview'] ) ) {
			return;
		}
		// get settings data
		global $config;
		$data = (array) $config->settings;
		// debug ($data);

		$enable       = isset( $data['site']['analytics']['enable'] ) ? ( $data['site']['analytics']['enable'] === 'true' ? true : false ) : get_theme_mod( 'enable_analytics', false );
		$track_admins = isset( $data['site']['analytics']['track_admins'] ) ? ( $data['site']['analytics']['track_admins'] === 'true' ? true : false ) : get_theme_mod( 'analytics_track_admins', false );
		$analytics    = isset( $data['site']['analytics'][ 'code_' . $position ] ) ? $data['site']['analytics'][ 'code_' . $position ] : get_theme_mod( 'analytics_code_' . $position, '' );
		$analytics    = urldecode( $analytics );

		if ( $enable ) {
			if ( current_user_can( 'administrator' ) && ! $track_admins ) {
				return;
			}
			if ( strpos( $analytics, '<script>' ) === false &&
				strpos( $analytics, '</script>' ) === false &&
				strpos( $analytics, '<noscript>' ) === false &&
				strpos( $analytics, '</noscript>' ) === false ) {
					$analytics = '<script>' . $analytics . '</script>';
			}
			echo $analytics;
		}
	}

	public function add_footer() {

		$footermode = get_theme_mod( 'navi_footer_mode', 'on' );
		if ( $footermode != 'none' ) {
			$footerrow   = get_theme_mod( 'navi_footer_more', false ) ? 'vc_row wp-block-columns ' . get_theme_mod( 'navi_footer_row', 'full' ) : '';
			$footerstyle = $footerrow == 'vc_row wp-block-columns full' ? "style='max-width: none;'" : '';
			echo "<div class='foot $footerrow' $footerstyle>";
			echo "<section id='footer' class='footer v2 " . $footermode . "' aria-label='Footer'>";
			if ( shortcode_exists( 'dynamic' ) && ! strpos( $_SERVER['SCRIPT_FILENAME'], 'wp-activate.php' ) ) {

				$footertemplate = get_theme_mod( 'navi_footer_content', '' );

				// show main menu as default
				if ( $footertemplate == '' ) {
					echo "<div class='vc_row wp-block-columns row_xxl'>";
					echo do_shortcode( '[vc_blank_space height="36px"]' );
					echo "<nav class='menu_wrapper menu_column menu_column_flex-start'>";
					echo wp_nav_menu( array( 'theme_location' => 'main-menu' ) );
					echo '</nav>';
					echo do_shortcode( '[vc_blank_space height="20px"]' );
					echo '</div>';
				}
				// show footer template
				else {
					// debug("footer template");
					echo do_shortcode( "[dynamic template='footer']" );
				}
			}
			echo '</section>';
			echo '</div>';
		}
	}

	public function add_empty_navigation() {
		return "<header class='navigation v2 animate_fast'></header>";
	}

	public function add_navigation() {

		// navigation
		$overlay       = get_theme_mod( 'navi_header_overlay', 'move' );
		$naviscroll    = get_theme_mod( 'navi_header_scroll_enable', true );
		$naviscrollon  = $naviscroll ? get_theme_mod( 'navi_header_scroll_on', 250 ) : 'false';
		$naviscrolloff = $naviscroll ? get_theme_mod( 'navi_header_scroll_off', 150 ) : 'false';
		$sticky        = get_theme_mod( 'navi_header_scroll', 'sticky' );

		// main menu
		$navimode      = get_theme_mod( 'navi_header_mode', 'on' );
		$navirow       = get_theme_mod( 'navi_header_row', 'row_xxl' );
		$naviboxrow    = get_theme_mod( 'navi_header_more', false ) ? get_theme_mod( 'navi_header_boxrow', 'row_xxl' ) : 'row_xxxl';
		$navidirection = get_theme_mod( 'navi_header_off_direction', 'right' );
		$navitemplate  = get_theme_mod( 'navi_header_off_content', '' );
		$naviclose     = get_theme_mod( 'navi_header_off_close', true );
		$navitype      = get_theme_mod( 'navi_header_off_type', 'offcanvas' );
		if ( $navitype == 'none' ) {
			$navistyle = 'none';
		}
		if ( $navitype == 'offcanvas' ) {
			$navistyle = 'off' . $navidirection;
		}
		if ( $navitype == 'overlay' ) {
			$navistyle = 'over' . $navidirection;
		}
		if ( $navitype == 'full' ) {
			$navistyle = 'full' . $navidirection;

			// force close button for most fullscreen offmenus
			$nav_vert        = get_theme_mod( 'navi_vert_type', 'none' );
			$off_overlap     = get_theme_mod( 'navi_vert_offmenu_overlap', 0 );
			$vert_burgermode = get_theme_mod( 'navi_vert_burger_enable', 1 );
			$has_vert_burger = ( $nav_vert === 'left' || $nav_vert === 'right' ) && $vert_burgermode;
			if ( ! $has_vert_burger || $off_overlap ) {
				$naviclose = true;
			}
		}
		$navimenu    = get_theme_mod( 'navi_header_menu_mode', 'desktop' );
		$navilogo    = get_theme_mod( 'navi_header_logo_mode', 'on' );
		$burgermode  = get_theme_mod( 'navi_header_burger_mode', 'on' );
		$burgerstyle = get_theme_mod( 'navi_header_burger_style', 'collapse' );

		// meta menu
		$metamode      = get_theme_mod( 'navi_header_sec_mode', 'none' );
		$metarow       = get_theme_mod( 'navi_header_sec_row', 'row_xxl' );
		$metaboxrow    = get_theme_mod( 'navi_header_sec_more', false ) ? get_theme_mod( 'navi_header_sec_boxrow', 'row_xxl' ) : 'row_xxxl';
		$metadirection = get_theme_mod( 'navi_header_sec_off_direction', 'left' );
		$metatemplate  = get_theme_mod( 'navi_header_sec_off_content', '' );
		$metaclose     = get_theme_mod( 'navi_header_sec_off_close', true );
		$metatype      = get_theme_mod( 'navi_header_sec_off_type', 'offcanvas' );
		if ( $metatype == 'none' ) {
			$metastyle = 'none';
		}
		if ( $metatype == 'offcanvas' ) {
			$metastyle = 'off' . $metadirection;
		}
		if ( $metatype == 'overlay' ) {
			$metastyle = 'over' . $metadirection;
		}
		if ( $metatype == 'full' ) {
			$metastyle = 'full' . $metadirection;

			// force close button for most fullscreen offmenus
			$nav_vert        = get_theme_mod( 'navi_vert_type', 'none' );
			$off_overlap     = get_theme_mod( 'navi_vert_offmenu_overlap', 0 );
			$vert_burgermode = get_theme_mod( 'navi_vert_burger_enable', 1 );
			$has_vert_burger = ( $nav_vert === 'left' || $nav_vert === 'right' ) && $vert_burgermode;
			if ( ! $has_vert_burger || $off_overlap ) {
				$metaclose = true;
			}
		}
		$metamenu   = get_theme_mod( 'navi_header_sec_menu_mode', 'desktop' );
		$metalogo   = get_theme_mod( 'navi_header_sec_logo_mode', 'none' );
		$metaburger = get_theme_mod( 'navi_header_sec_burger_mode', 'none' );

		// dropmenus
		$dropmode    = get_theme_mod( 'drop_mode', 'on' );
		$droptrigger = get_theme_mod( 'drop_trigger', 'hover' ); // hover click
		$dropanim    = get_theme_mod( 'drop_anim', 'slide' ); // slide fade toggle
		$dropalign   = get_theme_mod( 'drop_align', 'center' ); // left center right
		$droptab     = get_theme_mod( 'drop_tab_style', 'triangle' );

		/**
		 * @filter 'greyd_header_classes'
		 */
		$header_classes = apply_filters( 'greyd_header_classes', "navigation v2 animate_fast $sticky overlay_$overlay main_$navimode meta_$metamode" );

		// render
		\enqueue::$style_count = 100;
		echo "<header class='$header_classes'
			data-mod-header_scroll_on='" . $naviscrollon . "'
			data-mod-header_scroll_off='" . $naviscrolloff . "'
			data-mod-anim='" . get_theme_mod( 'anim', 0.3 ) . "'
			data-mod-scrollspeed='" . get_theme_mod( 'scrollspeed', 0.5 ) . "' >";

		// announcement
		do_action( 'announcement_hook' );

		// meta menu
		$sets = array(
			'slug'       => 'meta-menu',
			'id'         => 'metamenu',
			'navirow'    => $metarow,
			'naviboxrow' => $metaboxrow,
			'navilogo'   => $metalogo,
			'navimenu'   => $metamenu,
			'navimode'   => $metamode,
			'burgermode' => $metaburger,
			'navitemplate' => $navitemplate,
		);
		$this->add_menu( $sets );

		// main menu
		$sets = array(
			'slug'       => 'main-menu',
			'id'         => 'mainmenu',
			'navirow'    => $navirow,
			'naviboxrow' => $naviboxrow,
			'navilogo'   => $navilogo,
			'navimenu'   => $navimenu,
			'navimode'   => $navimode,
			'burgermode' => $burgermode,
			'navitemplate' => $navitemplate,
		);
		$this->add_menu( $sets );

		// // dropdown menüs
		// $sets = array(
		// 	'droprow'  => '',
		// 	'dropmode' => $dropmode,
		// 	'trigger'  => $droptrigger,
		// 	'effect'   => $dropanim,
		// 	'align'    => $dropalign,
		// 	'tab'      => $droptab,
		// );
		// $this->add_dropmenus( $sets );

		// offcanvas menüs
		$sets = array(
			'navistyle'      => $navistyle,
			'navitemplate'   => $navitemplate,
			'naviclose'      => $naviclose,
			'navimode'       => $navimode,
			'metastyle'      => $metastyle,
			'metatemplate'   => $metatemplate,
			'metaclose'      => $metaclose,
			'metamode'       => $metamode,
			'burger'         => $burgerstyle,
			'burgermode'     => $burgermode,
			'metaburgermode' => $metaburger,
		);
		$this->add_offmenus( $sets );

		do_action( 'render_vertical_navbar' );
		
		echo '</header>';

		// reset the style count
		\enqueue::$style_count = 0;
	}

	public function add_menu( $sets ) {
		$slug       = $sets['slug'];
		$id         = $sets['id'];
		$navirow    = $sets['navirow'] . ( is_greyd_blocks() ? '' : ' vc_row' );
		$naviboxrow = $sets['naviboxrow'] . ( is_greyd_blocks() ? '' : ' vc_row' );
		$navimode   = $sets['navimode']; // 'none' => 'nicht aktivieren', 'on' => 'immer', 'desktop' => 'nur Desktop', 'mobile' => 'nur Mobil'
		$menumode   = $sets['navimenu']; // 'none' => 'nicht aktivieren', 'on' => 'immer', 'desktop' => 'nur Desktop', 'mobile' => 'nur Mobil'
		$logomode   = $sets['navilogo']; // 'none' => 'nicht aktivieren', 'on' => 'immer', 'desktop' => 'nur Desktop', 'mobile' => 'nur Mobil'
		$burgermode = $sets['burgermode']; // 'none' => 'nicht aktivieren', 'on' => 'immer', 'desktop' => 'nur Desktop', 'mobile' => 'nur Mobil'

		$dropdown_args = array(
			'mode'    => get_theme_mod( 'drop_mode', 'on' ),
			'trigger' => get_theme_mod( 'drop_trigger', 'hover' ), // hover click
			'anim'    => get_theme_mod( 'drop_anim', 'slide' ), // slide fade toggle
			'align'   => get_theme_mod( 'drop_align', 'center' ), // left center right
			'tab'     => get_theme_mod( 'drop_tab_style', 'triangle' ),
		);

		if ( $navimode != 'none' ) {

			// get mods
			if ( $slug == 'main-menu' ) {
				$logo_position   = get_theme_mod( 'navi_header_logo_position', 'left' );
				$logo_align      = get_theme_mod( 'navi_header_logo_row_vertical', 'center' );
				$menu_position   = get_theme_mod( 'navi_header_menu_position', 'right' );
				$menu_align      = get_theme_mod( 'navi_header_menu_row_vertical', 'center' );
				$burger_position = get_theme_mod( 'navi_header_burger_position', 'right' );
				$navi_gutter     = get_theme_mod( 'navi_header_more', false ) ? get_theme_mod( 'navi_header_gutter', 0 ) : 0;
				$mobile_change   = get_theme_mod( 'navi_header_mobile_more', false ) ? 'mobile_change' : '';
			} else {
				$logo_position   = get_theme_mod( 'navi_header_sec_logo_position', 'left' );
				$logo_align      = get_theme_mod( 'navi_header_sec_logo_row_vertical', 'center' );
				$menu_position   = get_theme_mod( 'navi_header_sec_menu_position', 'left' );
				$menu_align      = get_theme_mod( 'navi_header_sec_menu_row_vertical', 'center' );
				$burger_position = get_theme_mod( 'navi_header_sec_burger_position', 'right' );
				$navi_gutter     = get_theme_mod( 'navi_header_sec_more', false ) ? get_theme_mod( 'navi_header_sec_gutter', 0 ) : 0;
				$mobile_change   = get_theme_mod( 'navi_header_sec_mobile_more', false ) ? 'mobile_change' : '';
			}

			$logo = $burger = $menu = $justify_class = '';

			// clean alignment when at least one element is centered
			if ( ( $logomode === 'on' && $logo_position === 'center' ) || ( $menumode === 'on' && $menu_position === 'center' ) ) {
				// either are always on and centered
				$justify_class = 'justify_center';
			} else {
				// desktop
				if ( ( $logomode === 'desktop' && $logo_position === 'center' ) || ( $menumode === 'desktop' && $menu_position === 'center' ) ) {
					$justify_class = 'justify_center_desktop';
				}
				// mobile
				if ( ( $logomode === 'mobile' && $logo_position === 'center' ) || ( $menumode === 'mobile' && $menu_position === 'center' ) ) {
					$justify_class .= ' justify_center_mobile';
				}
			}

			// build logo
			if ( $logomode !== 'none' ) {
				$logo = $this->add_headerlogo(
					array(
						'slug' => $slug,
						'echo' => false,
					)
				);
				$logo = "<div class='logo_wrapper $logomode'><div class='branding animate_fast $logomode'>" . $logo . '</div></div>';
			}

			// build burger
			if ( $burgermode !== 'none' ) {
				$burgerstyle = get_theme_mod( 'navi_header_burger_style', 'collapse' );
				$burger      = self::add_headerburger(
					array(
						'burgerstyle' => $burgerstyle,
						'burgermode'  => $burgermode,
						'echo'        => false,
						'id'          => $id,
						'location'    => $sets['navitemplate'] == 'template' ? "" : $slug
					)
				);
				$burger      = '<div class="burger_wrapper ' . $burgermode . '">' . $burger . '</div>';
			}
			// build menu
			if ( $menumode !== 'none' ) {
				$menu = wp_nav_menu( array(
					'theme_location' => $slug,
					'container'      => false,
					'depth'          => 0,
					'dropmenu'       => true,
					'echo'           => false,
					'walker'         => new Header_Menu_Walker(),
					'dropdown_args'  => $dropdown_args,
				) );

				if ( $burger_position === 'menu_left' ) {
					$menu = $burger . $menu;
				} elseif ( $burger_position === 'menu_right' ) {
					$menu .= $burger;
				}
				$menu = "<div class='mymenu animate_fast $menumode'>" . $menu . '</div>';
				$menu = '<nav class="menu_wrapper ' . $menumode . '">' . $menu . '</nav>';
			}

			// set gutter
			$navi_gutter = $navi_gutter ? 'force_gutter' : '';

			$holder = array(
				'left' => array(),
				'center' => array(),
				'right' => array(),
			);

			if ( isset($holder[$burger_position]) ) $holder[$burger_position][] = $burger;
			if ( isset($holder[$logo_position]) ) $holder[$logo_position][] = $logo;
			if ( isset($holder[$menu_position]) ) $holder[$menu_position][] = $menu;

			// outer wrapper
			echo "<div class='header_wrapper animate_fast $mobile_change'>";
			  echo "<div class='header_row $naviboxrow'>";

				// skip link
				echo "<a href='#greyd_main' class='greyd_skip_link'>" . __( 'Menü überspringen', 'greyd_forms' ) . '</a>';

				// header div
				echo "<div id='$id' class='header $navimode animate_fast'>";
				  echo "<div class='header_row $navirow'>";
					echo "<div class='holder vertical holder_top $justify_class $navi_gutter'>";
						// left container
						echo '<div class="holder horizontal holder_left animate_fast">';
						foreach( $holder['left'] as $element ) {
							echo $element;
						}
						echo '</div>';

						// middle container
						if ( count($holder['center']) ) {
							echo '<div class="holder horizontal holder_center animate_fast">';
							foreach( $holder['center'] as $element ) {
								echo $element;
							}
							echo '</div>';
						}

						// right container
						echo '<div class="holder horizontal holder_right animate_fast">';
						foreach( array_reverse($holder['right']) as $element ) {
							echo $element;
						}
						echo '</div>';
					echo '</div>';

					// menu below
					if ( strpos( $menu_position, '-below' ) !== false ) {
						$justify_class = $menu_position === 'center-below' ? 'justify_center' : '';
						echo "<div class='holder vertical holder_bottom $justify_class $navi_gutter'>";
							// left container
							echo '<div class="holder horizontal holder_left animate_fast">';
							if ( $menu_position === 'left-below' ) {
								echo $menu;
							}
							echo '</div>';

							// middle container
							echo '<div class="holder horizontal holder_center animate_fast">';
							if ( $menu_position === 'center-below' ) {
								echo $menu;
							}
							echo '</div>';

							// right container
							echo '<div class="holder horizontal holder_right animate_fast">';
							if ( $menu_position === 'right-below' ) {
								echo $menu;
							}
							echo '</div>';
						echo '</div>';
					}
				  echo '</div>';
				echo '</div>';

			  echo '</div>';
			echo '</div>';

		}
	}

	public static function add_headerburger( $sets ) {
		$echo        = isset( $sets['echo'] ) && $sets['echo'] === false ? false : true;
		$burgerstyle = $sets['burgerstyle'];
		$burgermode  = $sets['burgermode']; // 'on' => 'immer', 'desktop' => 'nur Desktop', 'mobile' => 'nur Mobil'

		$menu_title = empty( $sets['location'] ) ? __( 'Offmenü', 'core' ) : wp_get_nav_menu_name( $sets['location'] );
		$aria_label = sprintf( __( '%s öffnen', 'core' ), $menu_title );


		/**
		 * Filter the HTML output of the header burger button.
		 * @since 1.7.0
		 */
		$return = apply_filters(
			'greyd_render_headerburger',
			"<span id='dropmenu_all' class='hamburger hamburger--{$burgerstyle} {$burgermode} animate_fast' tabindex='0' role='button' aria-label='{$aria_label}' aria-expanded='false' aria-controls='{$sets['id']}off'>
				<span class='hamburger-box'>
					<span class='hamburger-inner'></span>
				</span>
			</span>",
			$sets
		);

		if ( $echo ) {
			echo $return;
		}
		return $return;
	}

	public function add_headerlogo( $sets ) {
		$echo = isset( $sets['echo'] ) && $sets['echo'] === false ? false : true;
		$slug = $sets['slug'];

		if ( $slug == 'main-menu' ) {
			$homeurl = esc_url( home_url( '/' ) );
			$name    = esc_html( get_bloginfo( 'name' ) );
			$info    = esc_html( get_bloginfo( 'description' ) );
			$title   = $name . ( empty( $info ) ? '' : ' | ' . $info );

			$logo = $this->get_theme_mod_image( 'custom_logo' );

			$home    = '';
			$class   = '';
			$content = '';
			if ( $logo && ! empty( $logo->file ) ) {

				$logo_mobile = $this->get_theme_mod_image( 'mobile_logo' ) ?: $logo;

				$home    = get_theme_mod( 'branding_logo_link', true ) ? "href='" . $homeurl . "'" : '';
				$class   = get_theme_mod( 'branding_logo_link', true ) ? '' : 'no-link';
				$content = "<img src='{$logo->file}' class='custom-logo' itemprop='logo' alt='{$logo->alt}' >
							<img src='{$logo_mobile->file}' class='custom-logo mobile' itemprop='logo' alt='{$logo_mobile->alt}' >";
			} elseif ( get_theme_mod( 'header_text', true ) ) {
				$home    = "href='" . $homeurl . "'";
				$class   = 'site-title';
				$content = $name;
			}
		}
		if ( $slug == 'meta-menu' ) {
			$home    = '';
			$title   = '';
			$class   = 'no-link';
			$content = '';

			$logo = $this->get_theme_mod_image( 'navi_header_sec_logo_image' );

			if ( $logo && ! empty( $logo->file ) ) {
				$content = "<img src='{$logo->file}' class='custom-logo' itemprop='logo' alt='{$logo->alt}' >";
			}

			$enablelink = get_theme_mod( 'navi_header_sec_logo_enablelink', false );
			if ( $enablelink ) {
				$title   = get_theme_mod( 'navi_header_sec_logo_title', '' );
				$homeurl = get_theme_mod( 'navi_header_sec_logo_link', '' );
				if ( $homeurl != '' ) {
					if ( strpos( $homeurl, 'http://' ) !== 0 && strpos( $homeurl, 'https://' ) !== 0 ) {
						$homeurl = 'http://' . $homeurl;
					}
					$home  = "href='" . $homeurl . "'";
					$class = '';
				}
			}
		}

		/**
		 * Filter the HTML output of the header logo.
		 * @since 1.7.0
		 */
		$return = apply_filters(
			'greyd_render_headerlogo',
			"<a {$home} class='{$class}' title='{$title}' rel='home' itemprop='url'>{$content}</a>",
			$sets
		);

		if ( $echo ) {
			echo $return;
		}
		return $return;
	}

	public function add_offmenus( $sets ) {
		$navistyle    = $sets['navistyle'];
		$navitemplate = $sets['navitemplate'] == 'template' ? 'main-menu-offcanvas' : '';
		$naviclose    = $sets['naviclose'];
		$navimode     = $sets['navimode'];
		$metastyle    = $sets['metastyle'];
		$metatemplate = $sets['metatemplate'] == 'template' ? 'meta-menu-offcanvas' : '';
		$metaclose    = $sets['metaclose'];
		$metamode     = $sets['metamode'];
		$burger       = $sets['burger'];

		$burgermode     = $sets['burgermode'];
		$metaburgermode = $sets['metaburgermode'];

		echo "<div class='offmenu_wrapper'>";
		if ( $navimode != 'none' && $navistyle != 'none' && $burgermode != 'none' ) {
			$this->add_offmenu(
				array(
					'slug'         => 'main-menu',
					'id'           => 'mainmenuoff',
					'navistyle'    => $navistyle,
					'navitemplate' => $navitemplate,
					'naviclose'    => $naviclose,
					'burger'       => $burger,
				)
			);
		}
		if ( $metamode != 'none' && $metastyle != 'none' && $metaburgermode != 'none' ) {
			$this->add_offmenu(
				array(
					'slug'         => 'meta-menu',
					'id'           => 'metamenuoff',
					'navistyle'    => $metastyle,
					'navitemplate' => $metatemplate,
					'naviclose'    => $metaclose,
					'burger'       => $burger,
				)
			);
		}
		echo '</div>';
	}

	public function add_offmenu( $sets ) {
		$slug         = $sets['slug'];
		$id           = $sets['id'];
		$navistyle    = $sets['navistyle'];
		$navitemplate = $sets['navitemplate'];
		$naviclose    = $sets['naviclose'];
		$burger       = $sets['burger'];

		echo "<div id='" . $id . "' class='offmenu " . $navistyle . " animate_fast' aria-hidden='true'".( $navitemplate == '' ? " aria-label='".wp_get_nav_menu_name($slug)."'" : "" )." tabindex='-1'>";
			echo "<span class='hamburger hamburger--" . $burger . ' toggle_close ' . ( $naviclose ? '' : 'nav-hide-on-desktop' ) . "'>
					<span class='hamburger-box'>
						<span class='hamburger-inner'></span>
					</span>
				</span>";
		if ( $navitemplate == '' ) {
			echo "<div class='menu_wrapper'>";
				wp_nav_menu( array(
					'theme_location' => $slug,
					'walker'         => $this->get_offcanvas_menu_walker()
				) );
			echo '</div>';
		} else {
			/**
			 * Use the offmenu walker even in menus inside the offcanvas template.
			 * @since 1.5.5
			 */
			add_filter( 'greyd_menu_render_walker', array( $this, 'get_offcanvas_menu_walker' ) );
			echo do_shortcode( "[dynamic template='" . $navitemplate . "']" );
			remove_filter( 'greyd_menu_render_walker', array( $this, 'get_offcanvas_menu_walker' ) );
		}
		echo '</div>';
	}

	public function get_offcanvas_menu_walker() {
		return new Offcanvas_Menu_Walker();
	}

	/**
	 * @deprecated since 1.5.0
	 */
	public function add_dropmenus( $sets ) {
		$droprow  = $sets['droprow'];
		$dropmode = $sets['dropmode'];
		$trigger  = $sets['trigger'];
		$effect   = $sets['effect'];
		$align    = $sets['align'];
		$tab      = $sets['tab'];

		if ( ! class_exists('\Greyd\Navigation\Dropdown_Menu_Walker') ) {
			require_once __DIR__.'/deprecated/dropdown-menu-walker.php';
		}

		if ( $dropmode != 'none' ) {
			echo "<div class='dropmenu_wrapper " . $droprow . ' ' . $dropmode . "' data-trigger='" . $trigger . "' data-effect='" . $effect . "' data-align='" . $align . "'>";
			wp_nav_menu( array(
				'theme_location' => 'main-menu',
				'container'      => false,
				'items_wrap'     => '%3$s',
				'fallback_cb'    => false,
				'dropmenu'       => true,
				'walker'         => new \Greyd\Navigation\Dropdown_Menu_Walker(),
				'tab'            => $tab,
			) );
			if ( has_nav_menu( 'meta-menu' ) ) {
				wp_nav_menu( array(
					'theme_location' => 'meta-menu',
					'container'      => false,
					'items_wrap'     => '%3$s',
					'fallback_cb'    => false,
					'dropmenu'       => true,
					'walker'         => new \Greyd\Navigation\Dropdown_Menu_Walker(),
					'tab'            => $tab,
				) );
			}
			echo '</div>';
		}
	}

	/**
	 * Get the image object of a theme_mod, eg. the 'custom_logo'.
	 *
	 * @supports WPML translated logo files.
	 *
	 * @since 1.1.2
	 *
	 * @return false    On failure.
	 * @return object   Image object on success:
	 *      @property int ID        ID of the attachment.
	 *      @property string file   URL to the attachment file.
	 *      @property string alt    Alt text of the attachment.
	 */
	public function get_theme_mod_image( $slug ) {

		$img = (object) array(
			'ID'   => -1,
			'file' => '',
			'alt'  => '',
		);

		// get the attachment id
		$img->ID = get_theme_mod( $slug, $img->ID );
		if ( ! $img->ID || $img->ID === -1 ) {
			return false;
		}

		// image is an url
		if ( ! is_numeric( $img->ID ) ) {
			$img->file = $img->ID;
			$img->ID   = attachment_url_to_postid( $img->file );
		}

		/**
		 * Support WPML translated logo file
		 *
		 * @since 1.1.2
		 */
		if ( function_exists( 'icl_object_id' ) && $img->ID && is_numeric( $img->ID ) ) {
			$translated_id = apply_filters( 'wpml_object_id', $img->ID, 'attachment', false, get_language() );
			if ( $translated_id && $translated_id != $img->ID ) {
				$img->ID = $translated_id;
			}
		}

		// get image file from ID
		if ( empty( $img->file ) ) {

			$img_data  = wp_get_attachment_image_src( $img->ID, 'full' );
			$img->file = $img_data ? $img_data[0] : '';
		}

		// get alt text
		$img->alt = \vc\helper::get_attachment_text( $img->ID );

		// fallback for alt text: image name
		if ( empty( $img->alt ) && ! empty( $img->file ) ) {
			$img->alt = basename( $img->file );
		}

		return $img;
	}
}
