<?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"/>
	
	<!-- layout variables -->
	<xsl:variable name="layout.global.nav.page" select="'export-recipe'"/>
	
	<!-- helper vars -->
	<xsl:variable name="search-results" select="$aux/eat:ui/eat:search-results"/>
	<xsl:variable name="index-section" 
			select="$search-results/eat:ui-index/eat:index-section[@selected = 'true']"/>
	<xsl:variable name="recipe-criteria" select="$search-results/eat:recipe-criteria"/>
	<xsl:variable name="recipe" select="$aux/eat:ui/eat:recipe"/>

	<xsl:template match="xweb:x-data" mode="page-title">
		<xsl:value-of select="key('i18n','export-recipe.title')"/>
	</xsl:template>
	
	<xsl:template match="eat:recipe" mode="return-nav">
		<a class="back">
			<xsl:attribute name="href">
				<xsl:value-of select="$web-context"/>
				<xsl:text>/recipe.do?recipeId=</xsl:text>
				<xsl:value-of select="@recipeId"/>
				<xsl:apply-templates select="$index-section" mode="href"/>
				<xsl:apply-templates select="$recipe-criteria" mode="href"/>
			</xsl:attribute>
			<xsl:value-of select="key('i18n','back.to')"/>
			<xsl:text> </xsl:text>
			<xsl:value-of select="eat:name"/>
		</a>
	</xsl:template>
    
	<xsl:template match="xweb:x-data" mode="page-body">
		<div class="return-nav">
			<xsl:apply-templates select="$recipe" mode="return-nav"/>
		</div>
		<div class="intro">
			<xsl:value-of select="key('i18n','export-recipe.intro')" disable-output-escaping="yes"/>
		</div>
		<form method="post" action="{$web-context}{$ctx/xweb:path}">
			<table class="form">
				<tr>
					<th>
						<xsl:value-of select="key('i18n','recipe.displayName')"/>
					</th>
					<td>
						<xsl:value-of select="$recipe/eat:name"/>
					</td>
				</tr>
				<tr>
					<th>
						<xsl:value-of
							select="key('i18n','export.format.displayName')"/>
					</th>
					<td>
						<table class="form">
							<xsl:apply-templates select="$aux/eat:ui/eat:meta-support/eat:meta[@key='export-format']"/>
						</table>
					</td>
				</tr>
				<tr>
					<th/>
					<td>
						<input type="submit"
							value="{key('i18n','export.displayName')}"/>
					</td>
				</tr>
			</table>
			<input type="hidden" name="recipeId" value="{$recipe/@recipeId}"/>
		</form>
		<script type="text/javascript" xml:space="preserve">
			<xsl:comment>
			document.forms[0].elements['mode'][0].focus();
			//</xsl:comment>
		</script>
	</xsl:template>
	
	<xsl:template match="eat:meta">
		<tr>
			<td>
				<input type="radio" name="mode" value="{.}">
					<xsl:if test="position() = 1">
						<xsl:attribute name="checked">checked</xsl:attribute>
					</xsl:if>
				</input>
			</td>
			<td>
				<xsl:variable name="title-key">
					<xsl:text>export.format.</xsl:text>
					<xsl:value-of select="."/>
				</xsl:variable>
				<b>
					<xsl:value-of select="key('i18n',$title-key)"/>
				</b>
				<div>
					<xsl:variable name="explain-key">
						<xsl:value-of select="$title-key"/>
						<xsl:text>.explain</xsl:text>
					</xsl:variable>
					<xsl:value-of select="key('i18n',$explain-key)" disable-output-escaping="yes"/>
				</div>
			</td>
		</tr>
	</xsl:template>
	
</xsl:stylesheet>
