<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:eat="http://msqr.us/xsd/ieat"
	xmlns:xweb="http://msqr.us/xsd/jaxb-web"
	exclude-result-prefixes="eat xweb">
	
    <!-- imports -->
	<xsl:import href="tmpl/default-layout.xsl"/>
	<xsl:import href="tmpl/display-user.xsl"/>
	
	<!-- layout variables -->
	<xsl:variable name="layout.global.nav.page" select="''"/>
	
	<!-- helper vars -->
	<xsl:variable name="user" select="xweb:x-data/xweb:x-model/eat:search-results/eat:user"/>
	<xsl:variable name="index-section" 
		select="xweb:x-data/xweb:x-model/eat:search-results/eat:ui-index/eat:index-section[@selected = 'true']"/>
	
	<xsl:template match="xweb:x-data" mode="page-title">
		<xsl:value-of select="$user/eat:name"/>
	</xsl:template>
	
	<xsl:template match="xweb:x-data" mode="action-links">
		<xsl:if test="$acting-user/@userId = $user/eat:owner/@userId or 
				$acting-user/../@admin = 'true'">
			<a title="{key('i18n','link.user.edit.title')}">
				<xsl:attribute name="href">
					<xsl:value-of select="$web-context"/>
					<xsl:text>/editUser.do?userId=</xsl:text>
					<xsl:value-of select="$user/@userId"/>
					<xsl:apply-templates select="$index-section" mode="href"/>
				</xsl:attribute>
				<xsl:value-of select="key('i18n','link.user.edit')"/>
			</a>
			<xsl:text> - </xsl:text>
			<a title="{key('i18n','link.user.delete.title')}">
				<xsl:attribute name="href">
					<xsl:value-of select="$web-context"/>
					<xsl:text>/deleteUser.do?userId=</xsl:text>
					<xsl:value-of select="$user/@userId"/>
					<xsl:apply-templates select="$index-section" mode="href"/>
				</xsl:attribute>
				<xsl:value-of select="key('i18n','link.user.delete')"/>
			</a>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="xweb:x-data" mode="page-body">
		<xsl:if test="$index-section">
			<div class="return-nav">
				<a class="back">
					<xsl:attribute name="href">
						<xsl:value-of select="$web-context"/>
						<xsl:text>/users.do?</xsl:text>
						<xsl:apply-templates select="$index-section" mode="href-direct"/>
					</xsl:attribute>
					<xsl:value-of select="key('i18n','back.to')"/>
					<xsl:text> </xsl:text>
					<span class="index-link">
						<xsl:value-of select="$index-section/@index-key"/>
					</span>
				</a>
			</div>
		</xsl:if>
				
		<xsl:apply-templates select="$user" mode="display-internal"/>
	</xsl:template>
	
</xsl:stylesheet>