<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--  $Id$  -->
<!--                                                                  -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

    <xsl:variable name="canEditAlbums">
        <xsl:if test="/Root/Access/rps/catalog/edit or /Root/Access/rps/catalog/da_edit">1</xsl:if>
    </xsl:variable>


    <xsl:template name="catalogMainLayout">
        <div id="catalogMain">
            <xsl:if test="Access/rps/distribution/show and $canEditAlbums = 1">
                <xsl:attribute name="class">withDistribution</xsl:attribute>
            </xsl:if>

            <xsl:call-template name="errorMessageBox">
                <xsl:with-param name="errorMessage" select="Messages/Message/Code" />
            </xsl:call-template>

            <div class="CatalogMain-wrapper">
            <xsl:call-template name="successMessageGeneral">
                <xsl:with-param name="successMessage">
                    <xsl:if test="Messages/Message/Code = 'delete_success'">Album successfully deleted!</xsl:if>
                </xsl:with-param>
            </xsl:call-template>
                <section class="CatalogMain-section CatalogMain-section-main">
                    <div class="CatalogMain-section-col CatalogMain-section-col-view">
                        <xsl:call-template name="byLabelList" />
                    </div>
                </section>
                <section class="CatalogMain-section CatalogMain-section-recent">
                    <xsl:call-template name="recentList" />
                </section>
            </div>
        </div>
    </xsl:template>

    <xsl:template name="recentList">
        <div class="CatalogMain-albums-list">
            <h3>Recently Viewed Albums</h3>
            <xsl:call-template name="catalogListTable">
                <xsl:with-param name="albums" select="RecentlyViewed/Item/Album[AlbumID != '']" />
                    <xsl:with-param name="emptyMessage" select="'No albums exist in your viewing history.'" />
            </xsl:call-template>
        </div>
    </xsl:template>

    <xsl:template name="byLabelList">
        <div class="CatalogMain-albums-list">
            <div class="Table-controls Table-controls-top">
                <div class="Table-controls-item">
                    <xsl:if test="LabelList/Label">
                        <xsl:call-template name="labelSelectForm" />
                    </xsl:if>
                </div>
                <div class="Table-controls-item Table-controls-item-additive Form-group Form-group-horizontal">
                    <div class="Form-item">
                        <xsl:call-template name="uiButton">
                            <xsl:with-param name="iconLeftType" select="'add'" />
                            <xsl:with-param name="content" select="'New Album'" />
                            <xsl:with-param name="url" select="'/rps/catalog?c=edit'" />
                            <xsl:with-param name="disabled">
                                <xsl:choose>
                                    <xsl:when test="$canEditAlbums = 1">
                                        <xsl:text>false</xsl:text>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:text>true</xsl:text>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:with-param>
                        </xsl:call-template>
                    </div>
                    <div class="Form-item">
                        <xsl:if test="Access/rps/distribution/show">
                            <xsl:call-template name="uiButton">
                                <xsl:with-param name="iconLeftType" select="'upload'" />
                                <xsl:with-param name="content" select="'Import New Album'" />
                                <xsl:with-param name="url" select="'/rps/distribution'" />
                                <xsl:with-param name="disabled">
                                    <xsl:choose>
                                        <xsl:when test="$canEditAlbums = 1">
                                            <xsl:text>false</xsl:text>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:text>true</xsl:text>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </xsl:with-param>
                            </xsl:call-template>
                        </xsl:if>
                    </div>
                </div>
            </div>

            <xsl:call-template name="catalogListTable">
                <xsl:with-param name="albums" select="/Root/AlbumList/Item/Album" />
                <xsl:with-param name="emptyMessage" select="'No albums are available under this heading.'" />
            </xsl:call-template>

            <xsl:if test="Pagination/TotalPages > 1">
                <div class="Table-controls Table-controls-bottom">
                    <div class="Table-controls-item Table-controls-item-pagination">
                        <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="searchParams"><xsl:if test="/Root/Params/label">&amp;label=<xsl:value-of select="/Root/Params/label" /></xsl:if></xsl:with-param>
                        </xsl:call-template>
                    </div>
                </div>
            </xsl:if>
        </div>
    </xsl:template>

    <xsl:template name="catalogListTable">
        <xsl:param name="albums" />
        <xsl:param name="emptyMessage" />

        <xsl:choose>
            <xsl:when test="$albums">
                <table class="Table Table-with-highlight">
                    <thead>
                        <xsl:call-template name="catalogListHeaderRow" />
                    </thead>
                    <tbody>
                        <xsl:for-each select="$albums">
                            <xsl:call-template name="catalogListRow" />
                        </xsl:for-each>
                    </tbody>
                </table>
            </xsl:when>
            <xsl:otherwise>
                <section class="Table-empty-results">
                    <p><xsl:value-of select="$emptyMessage" /></p>
                </section>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template name="catalogListHeaderRow">
        <tr class="Table-row Table-row-header">
            <th class="Table-col CatalogMain-col-title">Title</th>
            <th class="Table-col CatalogMain-col-catalog">Catalog #</th>
            <th class="Table-col CatalogMain-col-artist">Artist</th>
            <xsl:if test="LabelList/Label">
                <th class="Table-col CatalogMain-col-label">Label</th>
            </xsl:if>
            <th class="Table-col CatalogMain-col-status">Status</th>
            <xsl:if test="Access/rps/catalog/edit or Access/rps/catalog/da_edit">
                <th class="Table-col Table-col-icon CatalogMain-col-edit">Edit</th>
            </xsl:if>
        </tr>
    </xsl:template>

    <xsl:template name="catalogListRow">
        <tr class="Table-row Table-row-data">
            <td class="Table-col CatalogMain-col-title">
                <a href="catalog?AlbumID={AlbumID}&amp;c=show"><xsl:value-of select="Title" /><xsl:if test="TitleVersion != ''"> (<xsl:value-of select="TitleVersion" />)</xsl:if></a>
            </td>
            <td class="Table-col CatalogMain-col-catalog"><xsl:value-of select="CatalogNumber" /></td>
            <td class="Table-col CatalogMain-col-artist">
                <xsl:value-of select="ArtistName" />
                <xsl:if test="count(AdditionalArtistList/AdditionalArtist) != 0">
                    &#160;<a class="js-tooltip">
                        <xsl:attribute name="title">
                            <xsl:for-each select="AdditionalArtistList/AdditionalArtist">
                                <xsl:sort select="AdditionalArtistID" data-type="number" />
                                <xsl:call-template name="escapeJavascript">
                                    <xsl:with-param name="string" select="Name" />
                                </xsl:call-template> (<xsl:value-of select="Role/Role" />)<xsl:value-of select="$tipBreak" />
                            </xsl:for-each>
                        </xsl:attribute>
                        <xsl:call-template name="icon">
                            <xsl:with-param name="type" select="'more'" />
                        </xsl:call-template>
                    </a>
                </xsl:if>
            </td>
            <xsl:if test="/Root/LabelList/Label">
                <xsl:variable name="albumLabelID"><xsl:value-of select="LabelID" /></xsl:variable>
                <td class="Table-col CatalogMain-col-label">
                    <xsl:value-of select="/Root/LabelList/Label[LabelID = $albumLabelID]/LabelName" />
                </td>
            </xsl:if>
            <td class="Table-col CatalogMain-col-status">
                <xsl:call-template name="albumStatus">
                    <xsl:with-param name="status" select="Status" />
                </xsl:call-template>
            </td>

            <xsl:if test="/Root/Access/rps/catalog/edit or /Root/Access/rps/catalog/da_edit">
                <td class="Table-col Table-col-icon CatalogMain-col-edit">
                    <a href="catalog?c=edit&amp;AlbumID={AlbumID}" 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:template>

</xsl:stylesheet>
