<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
                xmlns:hav="http://www.HopAndVineHull.co.uk/Requests"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:param name="Username"/>
  <xsl:output method="html" indent="yes"/>

  
  <xsl:template match="hav:Requests">

    <xsl:if test="hav:Request[not(@SatisfiedDate)]">
      <table cellspacing="0" style="width: 48em;">
        <xsl:call-template name="tableHeader">
          <xsl:with-param name="heading">Outstanding Requests</xsl:with-param>
        </xsl:call-template>
        <xsl:apply-templates select="hav:Request[not(@SatisfiedDate)]">
          <xsl:sort select="@Product"/>
        </xsl:apply-templates>
      </table>
    </xsl:if>

    <p/>
    <p/>

    <xsl:if test="hav:Request[@SatisfiedDate]">
      <table cellspacing="0" style="width: 48em;">
        <xsl:call-template name="tableHeader">
          <xsl:with-param name="heading">
            <xsl:text>Satisfied Requests (</xsl:text>
            <xsl:value-of select="count(hav:Request[@SatisfiedDate])"/>
            <xsl:text>)</xsl:text>
          </xsl:with-param>
        </xsl:call-template>
        <xsl:apply-templates select="hav:Request[@SatisfiedDate]">
          <xsl:sort select="@Product"/>
        </xsl:apply-templates>
      </table>
      <p/>
    </xsl:if>

  </xsl:template>

  
  <xsl:template match="hav:Request">

    <xsl:variable name="style">
      <xsl:if test="position() mod 2 = 1">
        <xsl:text>background-color: #FFE4B5;</xsl:text>
      </xsl:if>
      <xsl:if test="@Disabled = 'true' and @Username = $Username">
        <xsl:text>color: #555;</xsl:text>
      </xsl:if>
    </xsl:variable>

    <tr>
      <td style="width:  1em; background-color: #FFEFD5;">
        <xsl:choose>
          <xsl:when test="@Product = 'Beer'">
            <img src="../images/history/beermug.gif" alt="beer mug"/>
          </xsl:when>
          <xsl:otherwise>
            <img src="../images/history/cidermug.gif" alt="cider mug"/>
          </xsl:otherwise>
        </xsl:choose>
      </td>
      
      <td style="width: 29em; {$style}">
        <xsl:if test="@SatisfiedDate">
          <xsl:value-of select="@SatisfiedDate"/>
          <xsl:text>: </xsl:text>
        </xsl:if>
        <b><xsl:value-of select="@Brewery"/></b>
        <xsl:text> </xsl:text>
        <xsl:if test="not(@Beer)">
          <i>[anything]</i>
        </xsl:if>
        <xsl:value-of select="@Beer"/>
      </td>
      <td style="width:  7em; {$style}"><xsl:value-of select="@Nickname"/></td>
      <td style="width:  6em; {$style}"><xsl:value-of select="@RequestDate"/></td>
      <td style="width:  8em; {$style} text-align: right; font-size: 70%;">
        <xsl:choose>
          <xsl:when test="$Username = @Username">
            <xsl:choose>
              <xsl:when test="not(@SatisfiedDate)">
                <a href="../Interact/Requests.aspx?Action=Edit&amp;Id={@Id}">Edit</a>
                <xsl:text> &#160; </xsl:text>
                <a href="../Interact/Requests.aspx?Action=Delete&amp;Id={@Id}">Delete</a>
              </xsl:when>
              <xsl:otherwise>
                <xsl:choose>
                  <xsl:when test="@Disabled = 'true' and @Username = $Username">
                    <a href="../Interact/Requests.aspx?Action=Deactivate&amp;Id={@Id}">Re-enable</a>
                  </xsl:when>
                  <xsl:otherwise>
                    <a href="../Interact/Requests.aspx?Action=Deactivate&amp;Id={@Id}">Disable</a>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:when>
          <xsl:otherwise>
            <xsl:if test="not(@SatisfiedDate)">
              <a href="../Interact/Requests.aspx?Action=ReportAbuse&amp;Id={@Id}">Report Abuse</a>
            </xsl:if>
          </xsl:otherwise>
        </xsl:choose>
      </td>
    </tr>
  </xsl:template>


  <xsl:template name="tableHeader">
    <xsl:param name="heading"/>

    <xsl:variable name="DateHeading">
      <xsl:choose>
        <xsl:when test="starts-with($heading, 'Satisfied')">Requested</xsl:when>
        <xsl:otherwise>Date</xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    
    <tr style="background-color: #800000; color: #FFEFD5;">
      <th align="left" colspan="2"><xsl:value-of select="$heading"/></th>
      <th align="left" style="border-bottom: #800000 solid 1pt;">Requestor</th>
      <th align="left" style="border-bottom: #800000 solid 1pt;">
        <xsl:value-of select="$DateHeading"/>
      </th>
      <th align="right" style="border-bottom: #800000 solid 1pt;">&#160;</th>
    </tr>
  </xsl:template>



</xsl:stylesheet>