<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.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">
   <!--This template includes categories, options, and properties-->
   <xsl:template match="/">
      <html xmlns="http://www.w3.org/1999/xhtml">
         <xsl:apply-templates select="mpcconfiguration/lineitem" />
         <table>
            <tbody>
               <tr>
                  <td style="font-weight:bold">
                     Sum Total:
                     <xsl:value-of select="format-number(sum(mpcconfiguration/lineitem/unitprice), '0.00')"/>
                     &#160;&#160;&#160;
                  </td>
                  <td style="font-weight:bold">
                     Number of Configurations:
                     <xsl:value-of select="count(mpcconfiguration/lineitem)"/>
                     &#160;&#160;&#160;
                  </td>
                  <td style="font-weight:bold">
                     Total Quantity of Items in all Configurations:
                     <xsl:value-of select="sum(//quantity)"/>
                  </td>
               </tr>
            </tbody>
         </table>
      </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, 0, 200)" />
      </xsl:variable>
      <xsl:variable name="modelImageUrl">
         <xsl:value-of select="xu1:ModelImageTag($lineItemId, 0, 200)" />
      </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>

      <div class="xRgn">
         <table class="xInner">
            <tr>
               <td class="col">
                  <xsl:element name="div">
                     <xsl:attribute name="class">xOB</xsl:attribute>
                     <xsl:value-of select="xu1:InfoBar($lineItemId, $seriesId, $modelId, $hasErrors > 0, $isDraft > 0, $isLocked = 1, $forwardState)" disable-output-escaping="yes"/>
                     <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:LineItemSelector($lineItemId)" disable-output-escaping="yes"/>
                     <br />
                     <xsl:if test="not($modelImageUrl='')">
                        <!-- this will need to be switched to $seriesImageUrl if using series.-->
                        <!-- Series Image Tag Example, will need to change the if test to $seriesImageUrl -->
                        <!--<xsl:value-of select="$seriesImageUrl" disable-output-escaping="yes" />-->
                        <!-- Model Image Tag Example -->
                        <xsl:value-of select="$modelImageUrl" disable-output-escaping="yes" />
                     </xsl:if>
                     <div style="float:left; margin:3px">
                        <xsl:choose>
                           <xsl:when test="xu1:HasConfigurationDisplayName($lineItemId) = true()">
                              <span style="width: 50px">
                                 <b>Name: </b>
                                 <xsl:value-of select="xu1:GetConfigurationDisplayName($lineItemId)" disable-output-escaping="yes" />
                              </span>
                           </xsl:when>
                           <xsl:otherwise>
                              <span style="width: 50px">
                                 <b>Series: </b>
                              </span>
                              <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>
                              <br />
                              <span style="width: 50px">
                                 <b>Model: </b>
                              </span>
                              <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>
                           </xsl:otherwise>
                        </xsl:choose>
                        <br />
                        <span style="width: 50px">
                           <b>Total Quantity of Items: </b>
                        </span>
                        <xsl:value-of select="sum(category/option/quantity)"/>
                        <br />
                        <span style="width: 50px">
                           <b>Total Price: </b>
                        </span>
                        <xsl:value-of select="xu2:FormatProperty($seriesId, 'Price', unitprice)" />
                        <br />
                        <span style="width: 50px">
                           <b>Date Saved: </b>
                        </span>
                        <xsl:value-of select="xu1:ToLocalTime(@modifiedon, 'yyyy/MM/dd')"/>
                        <br/>
                        <span style="width: 50px">
                           <b>Date Created: </b>
                        </span>
                        <xsl:value-of select="xu1:ToLocalTime(@createdon, 'yyyy/MM/dd')"/>
                        <blockquote>
                           <xsl:value-of select="xu1:QuickViewLink($lineItemId)" disable-output-escaping="yes"/>
                           <br />
                           <!--If the series is not published, the Edit link will not appear.-->
                           <xsl:value-of select="xu1:EditLink($lineItemId, $seriesId, $modelId)" disable-output-escaping="yes"/>
                           <br />
                           <xsl:value-of select="xu1:DeleteLink($lineItemId)" disable-output-escaping="yes"/>
                           <br />
                           <xsl:value-of select="xu1:DuplicateLink($lineItemId)" disable-output-escaping="yes"/>
                           <br />
                        </blockquote>
                     </div>
                  </xsl:element>
               </td>
            </tr>
         </table>
      </div>
   </xsl:template>
</xsl:stylesheet>
