<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:ms="urn:schemas-microsoft-com:xslt"
                xmlns:xu1="urn:LineItemXmlUtil"
                xmlns:xu2="urn:PropertyXmlUtil">

   <xsl:template match="/">
      <html xmlns="http://www.w3.org/1999/xhtml">
         <div style='padding:11px; min-width:430px;'>
            <div style="border:solid 1px #a2a2a2;">
               <xsl:apply-templates select="mpcconfiguration/lineitem" />
            </div>
            <table class="xInner" cellpadding="3px" cellspacing="1px" style="background-color:#e9edf1;">
               <thead>
                  <tr>
                     <th></th>
                     <th></th>
                     <th style="width:30px;text-align:center"></th>
                     <th style="width:90px;text-align:right"></th>
                     <th style="width:90px;text-align:right;border-right:none;"></th>
                  </tr>
               </thead>
               <tr>
                  <td colspan="4" style="padding-top:15px; text-align:right;">Configurations:</td>
                  <td style="padding-top:15px; text-align:right;">
                     <xsl:value-of select="count(mpcconfiguration/lineitem)" />
                  </td>
               </tr>
               <tr>
                  <td colspan="4" style="padding-top:5px;text-align: right;">Total:</td>
                  <td style="padding-top:5px; text-align:right;">
                     <xsl:value-of select="format-number(sum(mpcconfiguration/lineitem/unitprice), '0.00')" />
                  </td>
               </tr>
            </table>
         </div>
      </html>
   </xsl:template>

   <xsl:template match="lineitem">
      <xsl:variable name="lineItemId">
         <xsl:value-of select="@id" />
      </xsl:variable>
      <xsl:variable name="seriesId">
         <xsl:value-of select="@seriesid" />
      </xsl:variable>
      <xsl:variable name="modelId">
         <xsl:value-of select="@modelid" />
      </xsl:variable>
      <xsl:variable name="seriesImageUrl">
         <xsl:value-of select="xu1:SeriesImageTag($lineItemId)" />
      </xsl:variable>
      <xsl:variable name="modelImageUrl">
         <xsl:value-of select="xu1:ModelImageTag($lineItemId)" />
      </xsl:variable>
      <xsl:variable name="hasErrors">
         <xsl:value-of select="@haserrors" />
      </xsl:variable>
      <xsl:variable name="isDraft">
         <xsl:value-of select="@isdraft" />
      </xsl:variable> 
      <xsl:variable name="isLocked">
         <xsl:value-of select="@islocked" />
      </xsl:variable>
      <xsl:variable name="forwardState">
         <xsl:value-of select="@forwardstate"/>
      </xsl:variable>


      <xsl:element name="div">
         <xsl:attribute name="option">1</xsl:attribute>
         <xsl:attribute name="class">xRgn</xsl:attribute>
         <xsl:attribute name="style">border: solid 0px</xsl:attribute>
         <xsl:if test="xu1:HasSnapshot($lineItemId)">
            <xsl:attribute name="snapshot">
               <xsl:value-of select="xu1:SnapshotDateStamp($lineItemId)" />
            </xsl:attribute>
         </xsl:if>

         <xsl:value-of select="xu1:InfoBar($lineItemId, $seriesId, $modelId, $hasErrors > 0, $isDraft > 0, $isLocked = 1, $forwardState)" disable-output-escaping="yes"/>
         <div class="xRgnHdrGL" style="border-top:none;">
            <xsl:text> </xsl:text>
            <xsl:value-of select="text()" />

            <span>
               <!-- Series Image Tag Example -->
               <!--<xsl:value-of select="xu1:SeriesImageTag($lineItemId, 0, 32)" disable-output-escaping="yes" />-->
               
               <!-- Model Image Tag Example -->
               <!--<xsl:value-of select="xu1:ModelImageTag($lineItemId, 0, 32)" disable-output-escaping="yes" />-->
               
               <xsl:choose>
                  <xsl:when test="xu1:HasConfigurationDisplayName($lineItemId) = true()">
                     <nobr>
                        <b>Name: </b>
                        <xsl:value-of select="xu1:GetConfigurationDisplayName($lineItemId)" disable-output-escaping="yes" />
                     </nobr>
                  </xsl:when>
                  <xsl:otherwise>
                     <nobr>
                        <b>Series: </b>
                        <xsl:choose>
                           <xsl:when test="not(seriesdesc)">
                              <xsl:value-of select="@seriesid" />
                           </xsl:when>
                           <xsl:otherwise>
                              <xsl:value-of select="seriesdesc" />
                           </xsl:otherwise>
                        </xsl:choose>
                     </nobr>
                     &#160;&#160;&#160;
                     <nobr>
                        <b>Model: </b>
                        <xsl:choose>
                           <xsl:when test="not(modeldesc)">
                              <xsl:value-of select="@modelid" />
                           </xsl:when>
                           <xsl:otherwise>
                              <xsl:value-of select="modeldesc" />
                           </xsl:otherwise>
                        </xsl:choose>
                     </nobr>
                  </xsl:otherwise>
               </xsl:choose>
            </span>
            <nobr style="float:right;">
               <xsl:value-of select="xu1:LineItemSelectorGL($lineItemId)" disable-output-escaping="yes" />
               <xsl:value-of select="xu1:EditButton($lineItemId, $seriesId, $modelId)" disable-output-escaping="yes" />
               <xsl:value-of select="xu1:DeleteButton($lineItemId)" disable-output-escaping="yes" />
               <xsl:value-of select="xu1:DuplicateButton($lineItemId)" disable-output-escaping="yes" />
               <xsl:value-of select="xu1:DuplicateWithEditButton($lineItemId)" disable-output-escaping="yes" />
               <xsl:value-of select="xu1:QuickViewButton($lineItemId)" disable-output-escaping="yes" />
            </nobr>
            <div style="clear:both;">&#160;</div>
         </div>
      </xsl:element>
      <div style="height:1%">
         <table class="xCatGrid" style="width:100%; border-bottom:solid 1px #a2a2a2;" cellpadding="3px" cellspacing="1px" id="configuration">
            <thead>
               <tr>
                  <th>Category</th>
                  <th style="border-right:none;">Description</th>
                  <th style="width:0;"></th>
                  <th style="width:30px;text-align:center;">Qty</th>
                  <th style="width:90px;text-align:right;border-right:none;">Price</th>
               </tr>
            </thead>
            <xsl:apply-templates select="category[not(@hide)]/option|category[@hide='0']/option" />
            <tr class="totalPrice">
               <td colspan="4" style="text-align:right">Total Price:</td>
               <td style="text-align:right">
                  <xsl:value-of select="xu2:FormatProperty($seriesId, 'Price', unitprice)" />
               </td>
            </tr>
         </table>
      </div>
   </xsl:template>

   <xsl:template match="option">
      <tr>
         <td align="left">
            <xsl:value-of select="../description" />
         </td>
         <td>
            <xsl:value-of select="description" />
         </td>
         <td></td>
         <td align="center">
            <xsl:value-of select="quantity" />
         </td>
         <td align="right">
            <xsl:value-of select="xu2:FormatProperty(../../@seriesid, 'Price', quantity * unitprice)" />
         </td>
      </tr>
      <!-- Un-comment the line below to also list all (printable) properties -->
      <!--<xsl:apply-templates select="property[not(@hide)]|property[@hide='0']" />-->
   </xsl:template>

   <xsl:template match="property">
      <tr parent="{generate-id(..)}">
         <td>&#160;</td>
         <td colspan="2" style="background-color:#ECECEC; padding-left:21px;">
            <xsl:value-of select="@label" />: &#160;<xsl:value-of select="xu2:FormatProperty(../../../@seriesid, @id, .)" />
         </td>
      </tr>
   </xsl:template>

</xsl:stylesheet>
