<xf:title>{{ phrase('analyze_permissions') }}</xf:title>
<xf:description>{{ phrase('analyze_permissions_description') }}</xf:description>

<xf:if is="$analysis">
	<xf:set var="$interfaceGroups" value="{$permissionData.interfaceGroups}" />
	<xf:set var="$permissionsGrouped" value="{$permissionData.permissionsGrouped}" />
	<xf:set var="$permissionsGroupedType" value="{$permissionData.permissionsGroupedType}" />

	<xf:foreach loop="$interfaceGroups" key="$interfaceGroupId" value="$interfaceGroup">
		<xf:if contentcheck="true">
			<div class="block">
				<div class="block-container">
					<h3 class="block-header">{$interfaceGroup.title}</h3>
					<div class="block-body">
			<xf:contentcheck>
			<xf:foreach loop="{$permissionsGrouped.{$interfaceGroupId}}" value="$permission">
				<xf:if is="{$analysis.{$permission.permission_group_id}.{$permission.permission_id}}">
					<xf:set var="$permAnalysis" value="{$analysis.{$permission.permission_group_id}.{$permission.permission_id}}" />
					<xf:formrow label="{$permission.title}">
						<xf:if is="$permission.permission_type == 'flag'">
							<xf:if is="$permAnalysis.final">
								{{ phrase('yes') }}
							<xf:else />
								{{ phrase('no') }}
							</xf:if>
						<xf:else />
							<xf:if is="$permAnalysis.final == -1">
								{{ phrase('unlimited') }}
							<xf:else />
								{$permAnalysis.final}
							</xf:if>
						</xf:if>
						<a data-xf-click="toggle" role="button" tabindex="0">{{ phrase('(details)') }}</a>

						<div class="toggleTarget">
							<xf:foreach loop="$permAnalysis.intermediates" value="$intermediate">
								<dl class="pairs pairs--columns">
									<dt><xf:trim>
										<xf:if is="$intermediate.type == 'system'">
											<xf:if is="$intermediate.contentId">
												{$intermediate.contentTitle} - {{ phrase('content_wide') }}
											<xf:else />
												{{ phrase('global_value') }}
											</xf:if>
										<xf:elseif is="$intermediate.type == 'group'" />
											<xf:if is="$intermediate.contentId">
												{$intermediate.contentTitle} - {$userGroupTitles.{$intermediate.typeId}}
											<xf:else />
												{$userGroupTitles.{$intermediate.typeId}}
											</xf:if>
										<xf:elseif is="$intermediate.type == 'user'" />
											<xf:if is="$intermediate.contentId">
												{$intermediate.contentTitle} - {{ phrase('user_value') }}
											<xf:else />
												{{ phrase('user_value') }}
											</xf:if>
										</xf:if>
									</xf:trim></dt>
									<dd>
										<xf:if is="$permission.permission_type == 'flag'">
											<xf:if is="$intermediate.value == 'deny'">{{ phrase('never') }}
											<xf:elseif is="$intermediate.value == 'content_allow'" />{{ phrase('yes') }}
											<xf:elseif is="$intermediate.value == 'reset'" />{{ phrase('no') }}
											<xf:elseif is="$intermediate.value == 'allow'" />{{ phrase('yes') }}
											<xf:elseif is="$intermediate.value == 'unset'" />{{ phrase('no') }}
											</xf:if>
										<xf:else />
											<xf:if is="$intermediate.value == -1">
												{{ phrase('unlimited') }}
											<xf:else />
												{$intermediate.value}
											</xf:if>
										</xf:if>
									</dd>
								</dl>
							</xf:foreach>
							<xf:if is="$permAnalysis.dependChange">
								<xf:set var="$parentPermission" value="{$permissionsGroupedType.{$permission.permission_group_id}.{$permAnalysis.dependChange.by}}" />
								<div>
									<xf:fa icon="fa-exclamation-triangle" class="u-accentText" />
									{{ phrase('requires_x_permission', {'title': $parentPermission.title}) }}
								</div>
							</xf:if>
						</div>
					</xf:formrow>
				</xf:if>
			</xf:foreach>
			</xf:contentcheck>
					</div>
				</div>
			</div>
		</xf:if>
	</xf:foreach>

</xf:if>

<div class="block">
	<div class="block-container">
		<h2 class="block-tabHeader tabs hScroller" data-xf-init="tabs h-scroller" role="tablist">
			<span class="hScroller-scroll">
				<a class="tabs-tab {{ $contentType == '' ? 'is-active' : '' }}"
					role="tab" tabindex="0" aria-controls="analyze-global-permissions">{{ phrase('global_permissions') }}</a>

				<xf:foreach loop="$contentOptions" key="$_contentType" value="$_contentPermission" if="$_contentPermission.content">
					<a class="tabs-tab {{ $contentType == $_contentType ? 'is-active' : '' }}"
						role="tab" tabindex="0" aria-controls="analyze-{$contentType}">{$_contentPermission.title}</a>
				</xf:foreach>
			</span>
		</h2>

		<ul class="tabPanes">
			<li class="{{ $contentType == '' ? 'is-active' : '' }}" role="tabpanel" id="analyze-global-permissions">
				<xf:form action="{{ link('permissions/analyze') }}">
					<div class="block-body">
						<xf:textboxrow name="username" value="{$username}" ac="single"
							label="{{ phrase('user_name') }}" />
					</div>
					<xf:submitrow submit="{{ phrase('analyze') }}" />
				</xf:form>
			</li>
			<xf:foreach loop="$contentOptions" key="$_contentType" value="$_contentPermission" if="$_contentPermission.content">
				<li class="{{ $contentType == $_contentType ? 'is-active' : '' }}" role="tabpanel" id="analyze-{$_contentType}">
					<xf:form action="{{ link('permissions/analyze') }}">
						<div class="block-body">
							<xf:textboxrow name="username" value="{$username}" ac="single"
								label="{{ phrase('user_name') }}" />

							<xf:selectrow name="content_id" value="{{ $contentType == $_contentType ? $contentId : 0 }}"
								label="{{ phrase('content') }}">

								<xf:option value="0">&nbsp;</xf:option>
								<xf:options source="$_contentPermission.content" />
							</xf:selectrow>
						</div>

						<xf:submitrow submit="{{ phrase('analyze') }}" />
						<xf:hiddenval name="content_type">{$_contentType}</xf:hiddenval>
					</xf:form>
				</li>
			</xf:foreach>
		</ul>
	</div>
</div>