<!--                                                                  -->
<!--  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="" encoding="utf-8" />

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

    <xsl:variable name="canEditBooks">
        <xsl:if test="/Root/Access/bookpub/catalog/edit_book">1</xsl:if>
    </xsl:variable>

    <xsl:template name="pickLayout">
        <div id="catalogMain">
            <xsl:call-template name="errorMessageBox">
                <xsl:with-param name="errorMessage" select="Messages/Message/Code" />
            </xsl:call-template>
            <xsl:call-template name="successMessageLarge">
                <xsl:with-param name="successMessage" select="Messages/Message/Code" />
            </xsl:call-template>
            <xsl:choose>
                <xsl:when test="$canEditBooks = 1">
                    <section class="CatalogMain-section CatalogMain-section-bookpub CatalogMain-section-main">
                        <div class="CatalogMain-section-col CatalogMain-section-col-add">
                            <xsl:call-template name="addSection" />
                        </div>
                        <div class="CatalogMain-section-col CatalogMain-section-col-view">
                            <xsl:call-template name="viewSection" />
                        </div>
                    </section>
                </xsl:when>
                <xsl:otherwise>
                    <section class="CatalogMain-section CatalogMain-section-bookpub CatalogMain-section-main">
                        <div class="CatalogMain-section-col CatalogMain-section-col-view-cant">
                            <xsl:call-template name="viewSection" />
                        </div>
                    </section>
                </xsl:otherwise>
            </xsl:choose>
            <section class="CatalogMain-section CatalogMain-section-bookpub">
                <xsl:call-template name="recentList" />
            </section>
        </div>
    </xsl:template>

    <xsl:template name="addSection">
        <div class="CatalogMain-add-album">
            <h3>Add Book</h3>
            <ul class="CatalogMain-add-list ControlsList">
                <li class="CatalogMain-add-item ControlsList-item">
                    <xsl:call-template name="uiButton">
                        <xsl:with-param name="iconLeftType" select="'add'" />
                        <xsl:with-param name="content" select="'Add New Book'" />
                        <xsl:with-param name="url" select="'/bookpub/catalog?c=edit_book'" />
                        <xsl:with-param name="type" select="'text-inline'" />
                        <xsl:with-param name="size" select="'large'" />
                    </xsl:call-template>
                </li>
            </ul>
        </div>
    </xsl:template>

    <xsl:template name="viewSection">
        <div class="CatalogMain-view-albums">
            <h3>View Books</h3>
            <form class="Form" action="/bookpub/catalog" method="get">
                <input type="hidden" name="c" value="list_books" />
                <xsl:choose>
                    <xsl:when test="ImprintList/Imprint">
                        <div class="Form-group Form-group-horizontal">
                            <div class="Form-item CatalogMain-view-album-select">
                                <label class="Form-label">
                                    <span class="Form-label-caption">
                                        By Imprint
                                        <xsl:call-template name="helpIcon">
                                            <xsl:with-param name="tip">
                                                View books for a specific imprint
                                            </xsl:with-param>
                                        </xsl:call-template>
                                    </span>
                                    <div class="Form-input-wrapper">
                                        <xsl:variable name="labelListItems">
                                            <map>
                                                <mapEntry>
                                                    <name>
                                                        All Imprints
                                                    </name>
                                                    <value></value>
                                                </mapEntry>
                                                <xsl:for-each select="ImprintList/Imprint">
                                                    <mapEntry>
                                                        <name>
                                                            <xsl:value-of select="substring(Name,1,50)" /><xsl:if test="substring(Name,51,1)">&#8230;</xsl:if>
                                                        </name>
                                                        <value>
                                                            <xsl:value-of select="ImprintID" />
                                                        </value>
                                                    </mapEntry>
                                                </xsl:for-each>
                                            </map>
                                        </xsl:variable>
                                        <xsl:call-template name="uiDropdown">
                                            <xsl:with-param name="name" select="'ImprintID'" />
                                            <xsl:with-param name="id" select="'imprintView'" />
                                            <xsl:with-param name="items" select="$labelListItems" />
                                        </xsl:call-template>
                                    </div>
                                </label>
                            </div>
                            <div class="Form-item">
                                <xsl:call-template name="uiButton">
                                    <xsl:with-param name="content" select="'View'" />
                                    <xsl:with-param name="elemType" select="'submit'" />
                                    <xsl:with-param name="type" select="'default'" />
                                    <xsl:with-param name="name" select="'go'" />
                                </xsl:call-template>
                            </div>
                        </div>
                    </xsl:when>
                    <xsl:otherwise>
                        <a class="CatalogMain-all-albums-link" href="/bookpub/catalog?c=list_books">
                            All Books
                            <xsl:call-template name="helpIcon">
                                <xsl:with-param name="tip">
                                    View all books
                                </xsl:with-param>
                            </xsl:call-template>
                        </a>
                    </xsl:otherwise>
                </xsl:choose>
            </form>
        </div>
    </xsl:template>

    <xsl:template name="recentList">
        <div class="CatalogMain-table">
            <h3>Most Recently Accessed Books</h3>
            <xsl:if test="RecentlyViewed/Item">
                <table class="Table Table-with-highlight">
                    <thead>
                        <tr class="Table-row Table-row-header">
                            <th class="Table-col Table-col-header">Title</th>
                            <th class="Table-col Table-col-header">Subtitle</th>
                            <th class="Table-col Table-col-header">Author</th>
                            <xsl:if test="/Root/ClientTypes/ClientType[ClientTypeID = 10]/IsClientTypeFlag = 1">
                                <th class="Table-col Table-col-icon Table-col-header">Add&#160;to&#160;List</th>
                            </xsl:if>
                            <xsl:if test="$canEditBooks = 1">
                                <th class="Table-col Table-col-icon Table-col-header">Edit</th>
                            </xsl:if>
                        </tr>
                    </thead>
                    <tbody>
                        <xsl:for-each select="RecentlyViewed/Item/Book[BookID != '']">
                            <tr class="Table-row Table-row-data">
                                <td class="Table-col Table-col-data">
                                    <a href="catalog?BookID={BookID}&amp;c=show_book"><xsl:value-of select="Title" /><xsl:if test="TitleVersion != ''"> (<xsl:value-of select="TitleVersion" />)</xsl:if> (<xsl:value-of select="ProductCount" /> product<xsl:if test="ProductCount != 1">s</xsl:if>)</a>
                                </td>
                                <td class="Table-col Table-col-data">
                                    <xsl:value-of select="Subtitle" />
                                </td>
                                <td class="Table-col Table-col-data">
                                    <xsl:value-of select="AuthorName" />
                                </td>
                                <xsl:if test="$canEditBooks = 1">
                                    <td class="Table-col Table-col-icon Table-col-data">
                                        <a href="catalog?c=edit_book&amp;BookID={BookID}" title="Edit" class="js-tooltip">
                                            <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:if>
            <xsl:if test="not(RecentlyViewed/Item)">
                <p>No books exist in your viewing history.</p>
            </xsl:if>
        </div>
    </xsl:template>

</xsl:stylesheet>
