<xf:title>{{ phrase('user_upgrades') }}</xf:title>

<xf:pageaction>
	<xf:button href="{{ link('user-upgrades/add') }}" icon="add">{{ phrase('add_user_upgrade') }}</xf:button>
</xf:pageaction>

<xf:if is="!$xf.livePayments">
	<div class="blockMessage blockMessage--important blockMessage--iconic">
		{{ phrase('live_payments_have_been_disabled') }}
	</div>
</xf:if>

<xf:if is="$upgrades is not empty">
	<xf:form action="{{ link('user-upgrades/toggle') }}" class="block" ajax="true">
		<div class="block-outer">
			<xf:macro template="filter_macros" name="quick_filter"
				arg-key="user-upgrades"
				arg-class="block-outer-opposite" />
		</div>
		<div class="block-container">
			<div class="block-body">
				<xf:datalist>
					<xf:foreach loop="$upgrades" value="$upgrade">
						<xf:datarow
								label="{$upgrade.title}"
								hint="{$upgrade.cost_phrase}"
								href="{{ link('user-upgrades/edit', $upgrade) }}"
								delete="{{ link('user-upgrades/delete', $upgrade) }}">

							<xf:toggle name="can_purchase[{$upgrade.user_upgrade_id}]" selected="$upgrade.can_purchase"
								class="dataList-cell--separated" submit="true"
								tooltip="{{ phrase('enable_disable_x', {'title': $upgrade.title}) }}"/>

							<xf:popup class="dataList-cell--action">
								<div class="menu" data-menu="menu" aria-hidden="true">
									<div class="menu-content">
										<h3 class="menu-header">{{ phrase('actions') }}</h3>
										<a href="{{ link('user-upgrades/active', $upgrade) }}" class="menu-linkRow">{{ phrase('view_users') }}</a>
										<a href="{{ link('user-upgrades/expired', $upgrade) }}" class="menu-linkRow">{{ phrase('view_expired_upgrades') }}</a>
										<a href="{{ link('user-upgrades/manual', $upgrade) }}" class="menu-linkRow">{{ phrase('manually_upgrade_user') }}</a>
									</div>
								</div>
							</xf:popup>

						</xf:datarow>
					</xf:foreach>
				</xf:datalist>
			</div>
			<div class="block-footer">
				<span class="block-footer-counter">{{ display_totals($upgrades) }}</span>
			</div>
		</div>
	</xf:form>

	<div class="block">
		<div class="block-container">
			<h2 class="block-header"><a href="{{ link('user-upgrades/active') }}">{{ phrase('active_user_upgrades') }}</a></h2>
			<xf:if is="$activeUpgrades is not empty">
				<div class="block-body">
					<xf:macro name="upgrade_list" arg-upgrades="{$activeUpgrades}" arg-active="1" />
				</div>
				<div class="block-footer block-footer--split">
					<span class="block-footer-counter">{{ display_totals($activeUpgrades, $totalActiveUpgrades) }}</span>
					<span class="block-footer-controls"><xf:button href="{{ link('user-upgrades/active') }}">{{ phrase('view_more...') }}</xf:button></span>
				</div>
			<xf:else />
				<div class="block-body block-row">{{ phrase('no_results_found') }}</div>
			</xf:if>
		</div>
	</div>

	<div class="block">
		<div class="block-container">
			<h2 class="block-header"><a href="{{ link('user-upgrades/expired') }}">{{ phrase('expired_user_upgrades') }}</a></h2>
			<xf:if is="$expiredUpgrades is not empty">
				<div class="block-body">
					<xf:macro name="upgrade_list" arg-upgrades="{$expiredUpgrades}" arg-active="0" />
				</div>
				<div class="block-footer block-footer--split">
					<span class="block-footer-counter">{{ display_totals($expiredUpgrades, $totalExpiredUpgrades) }}</span>
					<span class="block-footer-controls"><xf:button href="{{ link('user-upgrades/expired') }}">{{ phrase('view_more...') }}</xf:button></span>
				</div>
			<xf:else />
				<div class="block-body block-row">{{ phrase('no_results_found') }}</div>
			</xf:if>
		</div>
	</div>
<xf:else />
	<div class="blockMessage">{{ phrase('no_items_have_been_created_yet') }}</div>
</xf:if>

<xf:macro name="upgrade_list"
	arg-upgrades="!"
	arg-viewMoreUrl=""
	arg-active="1">
	
	<xf:datalist data-xf-init="responsive-data-list">
		<xf:datarow rowtype="header">
			<xf:cell>{{ phrase('user') }}</xf:cell>
			<xf:cell>{{ phrase('upgrade_title') }}</xf:cell>
			<xf:cell>{{ phrase('payment_profile') }}</xf:cell>
			<xf:cell>{{ phrase('start_date') }}</xf:cell>
			<xf:cell colspan="{{ $active ? 3 : 1 }}">{{ phrase('end_date') }}</xf:cell>
		</xf:datarow>
		<xf:foreach loop="$upgrades" value="$upgrade">
			<xf:datarow rowclass="dataList-row--noHover">
				<xf:cell>
					<xf:username user="{$upgrade.User}" defaultname="{{ phrase('unknown_user') }}" href="{{ link('users/edit', $upgrade.User) }}" />
				</xf:cell>
				<xf:cell>
					<a href="{{ link('user-upgrades/edit', $upgrade.Upgrade) }}">{$upgrade.Upgrade.title}</a>
				</xf:cell>
				<xf:cell>
					<xf:set var="$paymentProfile" value="{$upgrade.PurchaseRequest.PaymentProfile}" />
					<xf:if is="$paymentProfile">
						<a href="{{ link('payment-profiles/edit', $paymentProfile) }}">{$paymentProfile.title}</a>
					<xf:else />
						{{ phrase('n_a') }}
					</xf:if>
				</xf:cell>
				<xf:cell><xf:date time="{$upgrade.start_date}" /></xf:cell>
				<xf:cell>{{ $upgrade.end_date ? date($upgrade.end_date) : phrase('permanent') }}</xf:cell>
				<xf:if is="$active">
					<xf:action overlay="true" href="{{ link('user-upgrades/edit-active', null, {'user_upgrade_record_id': $upgrade.user_upgrade_record_id}) }}">{{ phrase('edit') }}</xf:action>
					<xf:action overlay="true" href="{{ link('user-upgrades/downgrade', null, {'user_upgrade_record_id': $upgrade.user_upgrade_record_id}) }}">{{ phrase('downgrade') }}</xf:action>
				</xf:if>
			</xf:datarow>
		</xf:foreach>
	</xf:datalist>
</xf:macro>