<xf:macro name="language_change_menu"
	arg-languageTree="!"
	arg-route="!"
	arg-routeParams="{{ {} }}"
	arg-currentLanguage="{{ null }}"
	arg-linkClass="button button--link">

	<a class="{$linkClass} menuTrigger"
		data-xf-click="menu"
		role="button"
		tabindex="0"
		aria-expanded="false"
		aria-haspopup="true">{{ phrase('language:') }} {$currentLanguage.title}</a>

	<div class="menu" data-menu="menu" aria-hidden="true">
		<div class="menu-content">
			<h3 class="menu-header">{{ phrase('languages') }}</h3>
			<xf:foreach loop="$languageTree.getFlattened()" value="$treeEntry">
				<a href="{{ link($route, $treeEntry.record, $routeParams) }}"
				   class="menu-linkRow {{ ($currentLanguage && $currentLanguage.language_id == $treeEntry.record.language_id) ? 'is-selected' : '' }}">
					<span class="u-depth{$treeEntry.depth}">{$treeEntry.record.title}</span>
				</a>
			</xf:foreach>
		</div>
	</div>
</xf:macro>

<xf:macro name="language_select"
	arg-languageTree="!"
	arg-languageId="!"
	arg-name="language_id"
	arg-row="{{ true }}"
	arg-class="">

	<xf:set var="$select">
		<xf:select name="{$name}" value="{$languageId}" class="{$class}">
			<xf:foreach loop="{{ $languageTree.getFlattened() }}" value="$treeEntry">
				<xf:option value="{$treeEntry.record.language_id}">{{ repeat('--', $treeEntry.depth) }} {$treeEntry.record.title}</xf:option>
			</xf:foreach>
		</xf:select>
	</xf:set>

	<xf:if is="$row">
		<xf:formrow label="{{ phrase('language') }}" rowtype="input">
			{$select|raw}
		</xf:formrow>
	<xf:else />
		{$select|raw}
	</xf:if>
</xf:macro>