<!--                                                                  -->
<!--  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/global.xsl" />

    <xsl:template name="pickLayout">
        <div class="CatalogSearch">
            <xsl:choose>
                <xsl:when test="not($cmd = 'search') and not( count(Album) )" >
                    <section class="Table-empty-results">
                        <p>No results matched your search.</p>
                    </section>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:call-template name="searchResults" />
                </xsl:otherwise>
            </xsl:choose>
        </div>
    </xsl:template>

    <xsl:template name="searchResults">
        <xsl:call-template name="searchResultsTitle" />
        <xsl:if test="Pagination/Total &gt; 0 or count(Book) != 0">
            <xsl:call-template name="bookResults" />
        </xsl:if>
        <div class="Table-controls Table-controls-bottom">
            <div class="Table-controls-item">
                <xsl:call-template name="pageSizeForm" />
            </div>
            <div class="Table-controls-item Table-controls-item-pagination">
                <xsl:call-template name="searchNavRecords" />
            </div>
        </div>
    </xsl:template>

    <xsl:template name="bookResults">
        <table class="Table Table-with-highlight">
            <thead>
                <tr class="Table-row Table-row-header">
                    <th class="Table-col">Title</th>
                    <th class="Table-col">Subtitle</th>
                    <th class="Table-col">Author</th>
                    <xsl:if test="/Root/ClientTypes/ClientType[ClientTypeID = 10]/IsClientTypeFlag = 1">
                        <th class="Table-col">Add&#160;to&#160;List</th>
                    </xsl:if>
                    <xsl:if test="Access/bookpub/catalog/edit_book">
                        <th class="Table-col Table-col-icon">Edit</th>
                    </xsl:if>
                </tr>
            </thead>
            <tbody>
                <xsl:for-each select="Book">
                    <tr class="Table-row Table-row-data">
                        <td class="Table-col"><a href="catalog?BookID={BookID}&amp;c=show_book"><xsl:value-of select="Title" /> (<xsl:value-of select="ProductCount" /> product<xsl:if test="ProductCount != 1">s</xsl:if>)</a></td>
                        <td class="Table-col"><a href="catalog?BookID={BookID}&amp;c=show_book"><xsl:value-of select="Subtitle" /></a></td>
                        <td class="Table-col"><xsl:value-of select="AuthorName" /></td>
                        <xsl:if test="/Root/Access/bookpub/catalog/edit_book">
                            <td class="Table-col Table-col-icon">
                                <a href="catalog?c=edit_book&amp;BookID={BookID}" class="js-tooltip" title="Edit">
                                    <xsl:call-template name="icon">
                                        <xsl:with-param name="type" select="'edit'" />
                                        <xsl:with-param name="role" select="'action'" />
                                    </xsl:call-template>
                                </a>
                            </td>
                        </xsl:if>
                    </tr>
                </xsl:for-each>
            </tbody>
        </table>
    </xsl:template>

    <xsl:template name="pageSizeForm">
        <form method="get" action="/bookpub/catalog">
            <input type="hidden" name="c" value="{/Root/Params/c}" />
            <input type="hidden" name="Query" value="{/Root/Params/Query}" />
            <xsl:if test="/Root/Pagination/CurrentRecord">
                <input type="hidden" name="Record" value="{/Root/Pagination/CurrentRecord}" />
            </xsl:if>
            <div class="Form-group Form-group-horizontal">
                <div class="Form-item Form-item-horizontal">
                    <label class="Form-label">
                        <span class="Form-label-caption">Results per page</span>
                        <div class="Form-input-wrapper">
                            <xsl:variable name="catalogSearchPerPageItems">
                                <map>
                                    <xsl:if test="Pagination/PageSize != 25 and Pagination/PageSize != 50 and Pagination/PageSize != 100">
                                        <mapEntry>
                                            <name><xsl:value-of select="Pagination/PageSize" /></name>
                                            <value><xsl:value-of select="Pagination/PageSize" /></value>
                                        </mapEntry>
                                    </xsl:if>
                                    <mapEntry><name>25</name><value>25</value></mapEntry>
                                    <mapEntry><name>50</name><value>50</value></mapEntry>
                                    <mapEntry><name>100</name><value>100</value></mapEntry>
                                </map>
                            </xsl:variable>
                            <xsl:call-template name="uiDropdown">
                                <xsl:with-param name="items" select="$catalogSearchPerPageItems"/>
                                <xsl:with-param name="name" select="'PageSize'"/>
                                <xsl:with-param name="active" select="Pagination/PageSize"/>
                                <xsl:with-param name="className" select="'Form-item-per-page-select'"/>
                            </xsl:call-template>
                        </div>
                    </label>
                </div>
                <div class="Form-item">
                    <xsl:call-template name="uiButton">
                        <xsl:with-param name="elemType" select="'submit'" />
                        <xsl:with-param name="content" select="'Update'" />
                    </xsl:call-template>
                </div>
            </div>
        </form>
    </xsl:template>

    <xsl:template name="searchResultsTitle" >
        <xsl:if test="$cmd = 'search'" >
            <h2>
                Search Results for <xsl:if test="string-length(Params/Query)">"<xsl:value-of select="Params/Query" />"</xsl:if>
                <xsl:if test="BookCount">
                    <p class="Heading-addition">
                        <strong><xsl:value-of select="BookCount" /></strong> book<xsl:if test="BookCount != 1">s</xsl:if>
                    </p>
                </xsl:if>
            </h2>
        </xsl:if>
    </xsl:template>

    <xsl:template name="searchNavRecords">
        <xsl:variable name="searchNavParams">
            <xsl:text>&amp;c=</xsl:text>
            <xsl:value-of select="Params/c" />
            <xsl:if test="Params/Query">
                <xsl:text>&amp;Query=</xsl:text>
                <xsl:value-of select="Params/Query" />
            </xsl:if>
            <xsl:if test="normalize-space(Params/AdminID)">
                <xsl:text>&amp;AdminID=</xsl:text>
                <xsl:value-of select="Params/AdminID" />
            </xsl:if>
            <xsl:if test="normalize-space(Params/gentID)">
                <xsl:text>&amp;AgentID=</xsl:text>
                <xsl:value-of select="Params/AgentID" />
            </xsl:if>
        </xsl:variable>
        <xsl:value-of select="Pagination/TotalCount" />
        <xsl:call-template name="uiPagination">
            <xsl:with-param name="lastPage" select="Pagination/TotalPages" />
            <xsl:with-param name="currentPage" select="Pagination/Current" />
            <xsl:with-param name="type" select="'record'" />
            <xsl:with-param name="searchParams" select="$searchNavParams" />
            <xsl:with-param name="pageSize" select="Pagination/PageSize" />
        </xsl:call-template>
    </xsl:template>

</xsl:stylesheet>
