<?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="''"/>
	
	<!-- helper vars -->
	<xsl:variable name="meal" select="xweb:x-data/xweb:x-model/eat:edit/eat:meal"/>
	<xsl:variable name="meal-recipe" select="xweb:x-data/xweb:x-model/eat:edit/eat:meal-recipe"/>

	<xsl:template match="xweb:x-data" mode="page-title">
		<xsl:value-of select="key('i18n','choose-meal-for-recipe.title')"/>
	</xsl:template>
	
	<xsl:template match="xweb:x-data" mode="page-body">
		<div class="intro">
			<xsl:value-of select="key('i18n','choose-meal-for-recipe.intro')" disable-output-escaping="yes"/>
		</div>
		
		<div class="formLabel">
			<xsl:value-of select="key('i18n','recipe.displayName')"/>
			<xsl:text>: </xsl:text>
		</div>
		
		<div class="read-only">
			<xsl:value-of select="$meal-recipe/eat:recipe/eat:name"/>
		</div>
		
		<br clear="left" />
	
		<form method="post" action="{$web-context}{$ctx/xweb:path}">
			<table class="form">
				<tr>
					<th>
						<xsl:value-of select="key('i18n','meal.displayName')"/>
					</th>
					<td>
						<select name="meal.mealId">
							<xsl:apply-templates select="$aux/*/eat:meal"/>
						</select>
					</td>
				</tr>
				<tr>
					<th>
						<xsl:value-of select="key('i18n','recipe.course.displayName')"/>
					</th>
					<td>
						<select name="mealRecipe.course.courseId">
							<xsl:apply-templates select="$aux/*/eat:course"/>
						</select>
						<br/>
						<span class="caption">
							<xsl:value-of select="key('i18n','mealRecipe.course.caption')"/>
						</span>
					</td>
				</tr>
				<tr>
					<th>
						<xsl:if test="$err[@field='mealRecipe.quantity']">
							<xsl:attribute name="class">error</xsl:attribute>
						</xsl:if>
						<xsl:value-of select="key('i18n','mealRecipe.quantity.displayName')"/>
					</th>
					<td>
						<input type="text" name="mealRecipe.quantity" 
							value="{$meal-recipe/@quantity}" class="vsmallnum"/>
						<br/>
						<span class="caption">
							<xsl:value-of select="key('i18n','mealRecipe.quantity.caption')" 
								disable-output-escaping="yes"/>
						</span>
					</td>
				</tr>
				<tr>
					<th/>
					<td>
						<input type="submit" name="_target1" value="{key('i18n','continue.displayName')}"/>
						<xsl:text> </xsl:text>
						<input type="submit" name="_cancel" value="{key('i18n','cancel.displayName')}"/>
					</td>
				</tr>
			</table>
		</form>                
	</xsl:template>
	
	<xsl:template match="eat:meal">
	    	<option value="{@mealId}">
	    		<xsl:if test="@mealId = $meal/@mealId">
	    			<xsl:attribute name="selected">selected</xsl:attribute>
	    		</xsl:if>
	    		<xsl:value-of select="eat:name"/>
	    	</option>
	</xsl:template>

    <xsl:template match="eat:course">
	    	<option value="{@courseId}">
	    		<xsl:if test="@courseId = $meal-recipe/eat:course/@courseId">
	    			<xsl:attribute name="selected">selected</xsl:attribute>
	    		</xsl:if>
	    		<xsl:value-of select="."/>
	    	</option>
    </xsl:template>

</xsl:stylesheet>