<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--                                                                  -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:dyn="http://exslt.org/dynamic" extension-element-prefixes="dyn">
    <xsl:output method="html" indent="no" doctype-system="" encoding="utf-8" />

    <xsl:include href="/app/tools/bookpub/templates/ajax_request.xsl" />
    <xsl:include href="/app/tools/bookpub/templates/id_to_name.xsl" />


    <xsl:template name="pickLayout">
        <div class="PriceHistory">
            <section class="PriceHistory-information">
                <h2><xsl:value-of select="Book/Title" /></h2>
                <h4><xsl:value-of select="Book/Subtitle" /></h4>

                <xsl:variable name="mainContributorRoleID" select="Book/ContributorHash/Contributor/ContributorRoleID" />

                <div class="ValuePair ValuePair-line-view">
                    <div class="ValuePair-item">
                        <div class="ValuePair-label">Contributor</div>
                        <div class="ValuePair-value">
                            <xsl:value-of select="Book/ContributorHash/Contributor/Name" />&#160;(<xsl:value-of select="/Root/ContributorRoleList/ContributorRole[ContributorRoleID = $mainContributorRoleID]/Description" />)
                        </div>
                    </div>

                    <xsl:for-each select="Book/ContributorHash/Contributor[@i != 0]">
                        <xsl:variable name="contributorRoleID" select="ContributorRoleID" />
                        <div class="ValuePair-item">
                            <div class="ValuePair-label"></div>
                            <div class="ValuePair-value">
                                <xsl:value-of select="Name" />&#160;(<xsl:value-of select="/Root/ContributorRoleList/ContributorRole[ContributorRoleID = $contributorRoleID]/Description" />)</div>
                        </div>
                    </xsl:for-each>

                    <xsl:variable name="imprintID" select="Product/ImprintID" />
                    <div class="ValuePair-item">
                        <div class="ValuePair-label">Imprint</div>
                        <div class="ValuePair-value">
                            <xsl:value-of select="/Root/ImprintList/Imprint[ImprintID = $imprintID]/Name" />
                        </div>
                    </div>
                </div>
                <div class="ValuePair ValuePair-line-view">

                    <div class="ValuePair-item">
                        <div class="ValuePair-label">Format</div>
                        <div class="ValuePair-value">
                            <xsl:value-of select="Product/ProductFormat/BookFormatType/Description" />&#160;<xsl:value-of select="Product/ProductFormat/BookFormatSubtype/Description" />
                        </div>
                    </div>

                    <div class="ValuePair-item">
                        <div class="ValuePair-label ValuePair-label-top">Identifiers</div>
                        <div class="ValuePair-value">
                            <ul class="ValuePair-values-list">
                                <xsl:if test="normalize-space(Product/ISBN13)">
                                    <li class="ValuePair-values-item">
                                        ISBN 13: <a href="/bookpub/catalog?c=show_book_product&amp;ProductID={Product/ProductID}" target="_blank"><xsl:value-of select="Product/ISBN13" /></a>
                                    </li>
                                </xsl:if>
                                <xsl:if test="normalize-space(Product/ISBN10)">
                                    <li class="ValuePair-values-item">
                                        ISBN 10: <xsl:value-of select="Product/ISBN10" />
                                    </li>
                                </xsl:if>
                                <xsl:if test="normalize-space(Product/WorkID)">
                                    <li class="ValuePair-values-item">
                                        Work ID: <xsl:value-of select="Product/WorkID" />
                                    </li>
                                </xsl:if>
                            </ul>
                        </div>
                    </div>
                </div>
            </section>
            <xsl:choose>
                <xsl:when test="PriceHistory/Prices/ProductMarketPrice">
                    <section class="PriceHistory-prices">

                        <h4><xsl:value-of select="PriceHistory/Prices/ProductMarketPrice/CurrencyCodeName" />s (<xsl:value-of select="PriceHistory/CurrencyCode" />)</h4>

                        <xsl:variable name="effectivePriceID" select="ProductMarketPriceID" />
                        
                        <table class="Table">
                            <tr class="Table-row Table-row-header">
                                <th class="Table-col Catalog-col-status" style="width: 210px">Effective</th>
                                <th class="Table-col Catalog-col-price">Price</th>                                
                                <th class="Table-col Catalog-col-type">Type</th>
                                <th class="Table-col Catalog-col-qualifier" style="width: 125px">Qualifier</th>
                                <th class="Table-col Catalog-col-country">Country</th>
                            </tr>
                            <xsl:for-each select="PriceHistory/Prices/ProductMarketPrice">
                                <tr class="Table-row Table-row-data">
                                    <xsl:if test="ProductMarketPriceID = $effectivePriceID">
                                        <xsl:attribute name="class">effective</xsl:attribute>
                                    </xsl:if>
                                    <td class="Table-col">
                                        <xsl:choose>
                                            <xsl:when test="Status = 'current' and not(normalize-space(StartDate))">
                                                Current
                                            </xsl:when>
                                            <xsl:when test="Status = 'current'">
                                                <xsl:value-of select="StartDate" /> - Current
                                            </xsl:when>
                                            <xsl:when test="not(normalize-space(StartDate)) and normalize-space(EndDate)">
                                                Initial Delivery - <xsl:value-of select="EndDate" />
                                            </xsl:when>
                                            <xsl:otherwise>
                                                <xsl:value-of select="StartDate" /> - <xsl:value-of select="EndDate" />
                                            </xsl:otherwise>
                                        </xsl:choose>
                                    </td>                                    
                                    <td class="Table-col">
                                        <xsl:value-of select="Price" />
                                    </td>
                                    <td class="Table-col">
                                        <xsl:variable name="priceTypeID" select="PriceTypeID" />
                                        <xsl:value-of select="/Root/PriceTypes/PriceType[PriceTypeID = $priceTypeID]/Display" />
                                    </td>
                                    <td class="Table-col">
                                        <xsl:call-template name="priceTypeQualifierName">
                                            <xsl:with-param name="id" select="PriceTypeQualifierID" />
                                        </xsl:call-template>
                                    </td>  
                                    <td class="Table-col">
                                        <xsl:variable name="regionID" select="RegionID" />
                                        <xsl:value-of select="/Root/Regions/Region[RegionID = $regionID]/Display" />
                                        
                                        <xsl:if test="/Root/Regions/Region[RegionID = $regionID]/Included/Country/@size > 12">
                                            
                                            <xsl:variable name="fullRegionList">
                                                <xsl:for-each select="/Root/Regions/Region[RegionID = $regionID]/Included/Country">
                                                    <xsl:if test="position() != 1">, </xsl:if><xsl:value-of select="." />
                                                </xsl:for-each>
                                            </xsl:variable> 
                                            
                                            <a title="Full Country List" class="HelpIcon js-tooltip" onClick="$('#regionList{/Root/Params/SaleID}_{ProductMarketPriceID}').toggle()">
                                                <svg id="" class="Icon Icon-info Icon-default-role Icon-default-size HelpIcon-icon"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/production/redesign/assets/icons/sprite.svg#info"></use></svg>
                                            </a>
                                            
                                            <div class="hidden" id="regionList{/Root/Params/SaleID}_{ProductMarketPriceID}">
                                                <xsl:value-of select="$fullRegionList" />                        
                                            </div>
                                            
                                        </xsl:if>
                                    </td>                                                                      
                                </tr>
                            </xsl:for-each>
                        </table>
                    </section>
                </xsl:when>
                <xsl:otherwise>
                    <section class="Table-empty-results">No price history to display.</section>
                </xsl:otherwise>
            </xsl:choose>
        </div>
    </xsl:template>

</xsl:stylesheet>
