<!--                                                                  -->
<!--  Copyright (C) 2009 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="http://www.w3.org/TR/html4/strict.dtd" doctype-public="-//W3C//DTD HTML 4.01//EN" encoding="utf-8" />

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

    <xsl:template name="pickLayout">

        <link href="/production/css/bookpub/market.css?v=1" rel="stylesheet" type="text/css" />

<!--        <xsl:call-template name="productInfo" /> -->

        <div class="section" id="marketReport">
            <xsl:call-template name="reportOptions" />
            <xsl:call-template name="report" />
        </div>
    </xsl:template>

    <xsl:template name="productInfo">
        <xsl:if test="Query/productID &gt; 0">
            <div class="section">
                <table class="textChart">
                    <tr>
                        <th>Author</th>
                        <th>Title</th>
                        <th>Subtitle</th>
                        <th>Format</th>
                        <th>ISBN13</th>
                    </tr>
                    <tr class="row1">
                        <td><xsl:value-of select="Book/AuthorName" /></td>
                        <td><a href="catalog?c=show_book&amp;BookID={Book/BookID}"><xsl:value-of select="Book/Title" /></a></td>
                        <td><a href="catalog?c=show_book&amp;BookID={Book/BookID}"><xsl:value-of select="Book/Subtitle" /></a></td>
                        <td>
                            <a href="catalog?c=show_book_product&amp;ProductID={BookProduct/ProductID}">
                            <xsl:choose>
                                <xsl:when test="BookProduct/ProductFormat/BookFormatSubtype">
                                    <xsl:value-of select="BookProduct/ProductFormat/BookFormatSubtype/Description" />
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="BookProduct/ProductFormat/BookFormatType/Description" />
                                </xsl:otherwise>
                            </xsl:choose>
                            </a>
                        </td>
                        <td><a href="catalog?c=show_book_product&amp;ProductID={BookProduct/ProductID}"><xsl:value-of select="BookProduct/ISBN13" /></a></td>
                    </tr>
                </table>
            </div>
        </xsl:if>
    </xsl:template>

    <xsl:template name="reportOptions">
        <div class="reportOptions">
            <form method="get" action="/bookpub/market">
                <xsl:choose>
                   <xsl:when test="Query/productID &gt; 0">
                     <input type="hidden" name="productID" value="{Query/productID}" />
                     <input type="hidden" name="c" value="report" />
                   </xsl:when>
                   <xsl:otherwise>
                     <input type="hidden" name="c" value="report_full" />
                   </xsl:otherwise>
                </xsl:choose>
                <strong>Now Viewing: </strong>
                <select name="view">
                    <option value="current">
                        <xsl:if test="Query/view = 'current'">
                            <xsl:attribute name="selected">selected</xsl:attribute>
                        </xsl:if>
                        Current
                    </option>
                    <option value="resolved">
                        <xsl:if test="Query/view = 'resolved'">
                            <xsl:attribute name="selected">selected</xsl:attribute>
                        </xsl:if>
                        Resolved
                    </option>
                    <option value="all">
                        <xsl:if test="Query/view = 'all'">
                            <xsl:attribute name="selected">selected</xsl:attribute>
                        </xsl:if>
                        All
                    </option>
                </select>
                <xsl:text> </xsl:text>
                <select name="issue">
                    <option value="all">All</option>
                    <xsl:for-each select="ProductMonitorAlertTypes/ProductMonitorAlertType">
                        <option value="{Type}" >
                            <xsl:if test="/Root/Query/issue = Type">
                                <xsl:attribute name="selected">selected</xsl:attribute>
                            </xsl:if>
                            <xsl:value-of select="Text" /> (<xsl:value-of select="Count" />)
                        </option>
                    </xsl:for-each>
                </select>
                Issues for
                <select name="serviceID">
                    <option value="0">All Services</option>
                    <xsl:for-each select="ServiceList/Service">
                        <xsl:sort select="ServiceName" />
                        <option value="{ServiceID}" >
                            <xsl:if test="/Root/Query/serviceID = ServiceID">
                                <xsl:attribute name="selected">selected</xsl:attribute>
                            </xsl:if>
                            <xsl:value-of select="ServiceName" />
                        </option>
                    </xsl:for-each>
                </select>
                with
                <select name="pageSize">
                    <option value="25">
                        25
                    </option>
                    <option value="50">
                        <xsl:if test="PageSize = '50'">
                            <xsl:attribute name="selected">selected</xsl:attribute>
                        </xsl:if>
                        50
                    </option>
                    <option value="100">
                        <xsl:if test="PageSize = '100'">
                            <xsl:attribute name="selected">selected</xsl:attribute>
                        </xsl:if>
                        100
                    </option>
                </select>
                per page
                <input type="submit" value="Update" />
            </form>   

            <xsl:if test="ProductMonitorAlerts/ProductMonitorAlert">
            
                <xsl:call-template name="numericListNavSetup" />
            
                <a href="/bookpub/market?c=download&amp;serviceID={Query/serviceID}&amp;view={Query/view}&amp;issue={Query/issue}&amp;productID={Query/productID}" class="downloadLink" >
                    <img src="/production/images/icons/office/Document-(16x16).gif" height="16" width="16" /> Download Text File
                </a>
                
            </xsl:if>
            
            <br class="superBreak" />
            <br />
        </div>
    </xsl:template>


    <xsl:template name="report">

        <xsl:if test="ProductMonitorAlerts/ProductMonitorAlert">
            <table class="textChart">
                <tr>
                    <th class="dateCol">Date Reported</th>
                    <th>Service</th>
                    <th>Issue</th>
                    <th class="rankCol">Average Rank</th>
                    <th>Title</th>
                    <th>Author</th>
                    <th class="isbnCol">ISBN</th>
                    <th class="dateCol">Pub. Date</th>
                    <th class="priceCol">Catalog Price</th>
                    <th class="priceCol">Advertised Price</th>
                    <th class="dateCol">Date Resolved</th>
                </tr>
                <xsl:for-each select="ProductMonitorAlerts/ProductMonitorAlert" >
                    <tr class="row{position() mod 2}">
                        <td class="dateCol"><xsl:value-of select="substring(Alert/DateCreate,0,11)" /></td>
                        <td>
                            <xsl:variable name="serviceID" select="ServiceID" />
                            <xsl:value-of select="/Root/ServiceList/Service[ServiceID = $serviceID]/ServiceName" />
                        </td>
                        <td>
                            <xsl:value-of select="Alert/Text" />
                        </td>
                        <td class="rankCol"><xsl:value-of select="AverageRank" /></td>
                        <td>
                            <a href="/bookpub/catalog?c=show_book_product&amp;ProductID={ProductID}">
                                <xsl:value-of select="Book/Title" />
                            </a>
                        </td>
                        <td><xsl:value-of select="Book/AuthorName" /></td>
                        <td class="isbnCol"><xsl:value-of select="ISBN13" /></td>
                        <td class="dateCol"><xsl:value-of select="ReleaseDate" /></td>
                        <td class="priceCol"><xsl:value-of select="Alert/CatalogPrice" /></td>
                        <td class="priceCol"><xsl:value-of select="ProductMonitorItemPrice/Price" /></td>
                        <td class="dateCol">
                            <xsl:choose>
                                <xsl:when test="normalize-space(Alert/DateResolved)">
                                    <xsl:value-of select="substring(Alert/DateResolved,0,11)" />
                                </xsl:when>
                                <xsl:otherwise>--/--/----</xsl:otherwise>
                            </xsl:choose>
                        </td>
                    </tr>
                </xsl:for-each>
            </table>
        </xsl:if>
        
        <xsl:if test="not(ProductMonitorAlerts/ProductMonitorAlert)">
            <p><b><i>No alerts meet your criteria.</i></b></p>
        </xsl:if>

        <div class="lastUpdated">
            <strong>Last Updated: </strong><xsl:value-of select="LastUpdate" />
        </div>

        <br class="superBreak" />
        <br />

    </xsl:template>


    <xsl:template name="numericListNavSetup">
        <xsl:call-template name="numericListNav">
            <xsl:with-param name="pagination">/Root/ProductMonitorAlerts/Pagination</xsl:with-param>
        </xsl:call-template>
    </xsl:template>


    <xsl:template name="alertTypeDescription">
        <xsl:param name="type" />
        <xsl:if test="$type = 'price_mismatch'">Price Mismatch</xsl:if>
        <xsl:if test="$type = 'invalid_price'">Invalid Price</xsl:if>
        <xsl:if test="$type = 'available_too_soon'">Available Too Soon</xsl:if>
        <xsl:if test="$type = 'not_available'">Product Unavailable</xsl:if>
        <xsl:if test="$type = 'coverart_missing'">Cover Art Unavailable</xsl:if>
    </xsl:template>


</xsl:stylesheet>
