<xf:macro name="addon_edit" arg-addOnId="!" arg-row="{{ true }}" arg-includeAny="{{ false }}">
	<xf:set var="$addOnRepo" value="{{ $xf.app.em.getRepository('XF:AddOn') }}" />
	<xf:if is="$addOnRepo.canChangeAddOn()">
		<xf:macro name="addon_select" arg-addOnId="{$addOnId}" arg-row="{$row}" arg-includeAny="{$includeAny}" />
	<xf:else />
		<xf:hiddenval name="addon_id">{$addOnId}</xf:hiddenval>
	</xf:if>
</xf:macro>

<xf:macro name="addon_change_menu"
	arg-addOns="!"
	arg-route="!"
	arg-routeData="!"
	arg-routeParams="{{ {} }}"
	arg-currentAddOn="{{ 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('add_on:') }} {{ $currentAddOn ? $currentAddOn.title : phrase('(any)') }}</a>

	<div class="menu" data-menu="menu" aria-hidden="true">
		<div class="menu-content">
			<h3 class="menu-header">{{ phrase('add_ons') }}</h3>
			<a href="{{ link($route, $routeData, {'addon_id': null} + $routeParams) }}"
				class="menu-linkRow {{ !$currentAddOn ? 'is-selected' : '' }}">
				{{ phrase('(any)') }}
			</a>
			<xf:foreach loop="$addOns" value="$addOn">
				<a href="{{ link($route, $routeData, {'addon_id': $addOn.addon_id} + $routeParams) }}"
					class="menu-linkRow {{ ($currentAddOn && $currentAddOn.addon_id == $addOn.addon_id) ? 'is-selected' : '' }}">
					{$addOn.title}
				</a>
			</xf:foreach>
		</div>
	</div>
</xf:macro>

<xf:macro name="addon_select" arg-addOnId="!" arg-row="{{ true }}" arg-class="" arg-includeAny="{{ false }}">
	<xf:set var="$addOnRepo" value="{{ $xf.app.em.getRepository('XF:AddOn') }}" />
	<xf:set var="$select">
		<xf:select name="addon_id" value="{{ $addOnId === false ? $addOnRepo.getDefaultAddOnId() : $addOnId }}" class="{$class}">
			<xf:option value=""></xf:option>
			<xf:if is="$includeAny">
				<xf:option value="_any">{{ phrase('(any)') }}</xf:option>
			</xf:if>
			<xf:foreach loop="{{ $addOnRepo.findAddOnsForList().fetch() }}" value="$addOn">
				<xf:option value="{$addOn.addon_id}">{$addOn.title}</xf:option>
			</xf:foreach>
		</xf:select>
	</xf:set>
	<xf:if is="$row">
		<xf:formrow rowtype="input"
			label="{{ phrase('add_on') }}">

			{$select|raw}
		</xf:formrow>
	<xf:else />
		{$select|raw}
	</xf:if>
</xf:macro>