<?php
/**
 * Theme facing template tags.
 *
 * Module specific tags are added by their own module in later releases; this
 * file provides the generic entry point every module renders through.
 *
 * @package MenuVerse
 */

defined( 'ABSPATH' ) || exit;

if ( ! function_exists( 'menuverse_render' ) ) {
	/**
	 * Renders a module and enqueues only that module's assets.
	 *
	 * @param string $module_id Module identifier.
	 * @param array  $args      Optional per-call settings overriding stored values.
	 * @return string Rendered markup, empty when the module is unavailable.
	 */
	function menuverse_render( $module_id, array $args = array() ) {
		return \WPXero\MenuVerse\Plugin::instance()->modules()->render( $module_id, $args, array( 'source' => 'template_tag' ) );
	}
}

if ( ! function_exists( 'menuverse_the_menu' ) ) {
	/**
	 * Echoes a rendered module.
	 *
	 * @param string $module_id Module identifier.
	 * @param array  $args      Optional per-call settings overriding stored values.
	 * @return void
	 */
	function menuverse_the_menu( $module_id, array $args = array() ) {
		// Markup is escaped inside the render pipeline before it is returned.
		echo menuverse_render( $module_id, $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
	}
}

if ( ! function_exists( 'menuverse_mobile_menu' ) ) {
	/**
	 * Returns the rendered mobile menu.
	 *
	 * @param array $args Optional per call settings, for example
	 *                    array( 'menu' => 'classic:12', 'panel_side' => 'end' ).
	 * @return string Empty string when the module is disabled or has no menu.
	 */
	function menuverse_mobile_menu( array $args = array() ) {
		return menuverse_render( 'mobile_menu', $args );
	}
}

if ( ! function_exists( 'menuverse_the_mobile_menu' ) ) {
	/**
	 * Echoes the rendered mobile menu.
	 *
	 * @param array $args Optional per call settings.
	 * @return void
	 */
	function menuverse_the_mobile_menu( array $args = array() ) {
		menuverse_the_menu( 'mobile_menu', $args );
	}
}

if ( ! function_exists( 'menuverse_bottom_menu' ) ) {
	/**
	 * Returns the rendered bottom menu.
	 *
	 * @param array $args Optional per call settings.
	 * @return string Empty string when the module is disabled or has no items.
	 */
	function menuverse_bottom_menu( array $args = array() ) {
		return menuverse_render( 'bottom_menu', $args );
	}
}

if ( ! function_exists( 'menuverse_the_bottom_menu' ) ) {
	/**
	 * Echoes the rendered bottom menu.
	 *
	 * @param array $args Optional per call settings.
	 * @return void
	 */
	function menuverse_the_bottom_menu( array $args = array() ) {
		menuverse_the_menu( 'bottom_menu', $args );
	}
}

if ( ! function_exists( 'menuverse_mega_menu' ) ) {
	/**
	 * Returns the rendered mega menu.
	 *
	 * @param array $args Optional per call settings.
	 * @return string Empty string when the module is disabled or has no menu.
	 */
	function menuverse_mega_menu( array $args = array() ) {
		return menuverse_render( 'mega_menu', $args );
	}
}

if ( ! function_exists( 'menuverse_the_mega_menu' ) ) {
	/**
	 * Echoes the rendered mega menu.
	 *
	 * @param array $args Optional per call settings.
	 * @return void
	 */
	function menuverse_the_mega_menu( array $args = array() ) {
		menuverse_the_menu( 'mega_menu', $args );
	}
}

if ( ! function_exists( 'menuverse_nav' ) ) {
	/**
	 * Returns the block styled navigation, rendered from a stored menu.
	 *
	 * @param array $args Optional per call settings.
	 * @return string Empty string when the module is disabled or has no menu.
	 */
	function menuverse_nav( array $args = array() ) {
		return menuverse_render( 'block_menu', $args );
	}
}

if ( ! function_exists( 'menuverse_the_nav' ) ) {
	/**
	 * Echoes the block styled navigation.
	 *
	 * @param array $args Optional per call settings.
	 * @return void
	 */
	function menuverse_the_nav( array $args = array() ) {
		menuverse_the_menu( 'block_menu', $args );
	}
}

if ( ! function_exists( 'menuverse_vertical_menu' ) ) {
	/**
	 * Returns the rendered vertical menu.
	 *
	 * @param array $args Optional per call settings.
	 * @return string Empty string when the module is disabled or has no menu.
	 */
	function menuverse_vertical_menu( array $args = array() ) {
		return menuverse_render( 'vertical_menu', $args );
	}
}

if ( ! function_exists( 'menuverse_the_vertical_menu' ) ) {
	/**
	 * Echoes the rendered vertical menu.
	 *
	 * @param array $args Optional per call settings.
	 * @return void
	 */
	function menuverse_the_vertical_menu( array $args = array() ) {
		menuverse_the_menu( 'vertical_menu', $args );
	}
}
