<!--                                                                  -->
<!--  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="searchItem" select="/Root/Contract" />

    <xsl:template name="contractSearchLayout">
        <xsl:choose>
            <xsl:when test="Params/_inline">
                <xsl:call-template name="searchFormInline" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="searchResults" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template name="searchResults">
        <div class="ContractSearch">
            <xsl:if test="not(Params/_inline)">
                <xsl:attribute name="id">contractSearchFull</xsl:attribute>
            </xsl:if>
            <xsl:choose>
                <xsl:when test="not(Params/Query) and count(Contract) = 0">
                    <p>No contracts have been created.</p>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:call-template name="resultsList" />
                </xsl:otherwise>
            </xsl:choose>
        </div>
        <xsl:if test="(Params/AlbumID or Params/TrackID) and count(Contract) &gt; 0 and Params/Query">
            <xsl:call-template name="buttons" />
        </xsl:if>
    </xsl:template>

    <xsl:template name="resultsList">
        <xsl:if test="Params/Query">
            <h4>Search Results</h4>
        </xsl:if>
        <xsl:call-template name="searchNoResult" />
        <xsl:call-template name="searchNav">
            <xsl:with-param name="withText">true</xsl:with-param>
        </xsl:call-template>

        <xsl:if test="count($searchItem) != 0">
            <xsl:call-template name="resultsHeader" />
            <div class="Table-wrapper Table-wrapper-srolltop">
                <xsl:call-template name="contractListTable" />
            </div>
        </xsl:if>
        <xsl:call-template name="searchNav" />
        <xsl:if test="normalize-space(Pagination/Previous) or normalize-space(Pagination/Next)">
            <br class="superBreak" />
            <br />
        </xsl:if>
    </xsl:template>

    <xsl:template name="contractListTable">
        <table>
            <xsl:attribute name="class">
                <xsl:if test="Params/_inline">Table</xsl:if>
                <xsl:if test="not(Params/_inline)">
                    Table Table-with-highlight
                </xsl:if>
            </xsl:attribute>
            <tbody>
                <xsl:for-each select="$searchItem">
                    <xsl:call-template name="contractListTableRow" />
                </xsl:for-each>
            </tbody>
        </table>
    </xsl:template>

    <xsl:template name="contractListTableRow">
        <tr class="Table-row Table-row-data">
            <xsl:variable name="contractID" select="ArtistContractID" />
            <xsl:variable name="disableContract">
                <xsl:for-each select="/Root/AlbumContractList/AlbumContract">
                    <xsl:if test="ContractID = $contractID">1</xsl:if>
                </xsl:for-each>
                <xsl:for-each select="/Root/TrackContractList/TrackContract">
                    <xsl:if test="ContractID = $contractID">1</xsl:if>
                </xsl:for-each>
            </xsl:variable>
            <xsl:attribute name="class">
                row<xsl:value-of select="position() mod 2" /><xsl:text> </xsl:text><xsl:if test="position() = 1">firstRow</xsl:if><xsl:text> </xsl:text><xsl:if test="$disableContract = 1">disabledRow</xsl:if>
            </xsl:attribute>
            <xsl:if test="/Root/Params/AlbumID or /Root/Params/TrackID">
                <td class="Table-col Table-col-select Table-col-select-wide">

                    <xsl:call-template name="uiRadio">
                        <xsl:with-param name="disabled">
                            <xsl:if test="$disableContract = 1">
                                <xsl:text>yes</xsl:text>
                            </xsl:if>
                        </xsl:with-param>
                        <xsl:with-param name="name" select="'ArtistContractID'"/>
                        <xsl:with-param name="onClick">
                            <xsl:text>modifyField('selectMatch','enable'); modifyFieldValue('ContractID',this.value);</xsl:text>
                        </xsl:with-param>
                        <xsl:with-param name="value" select="ArtistContractID"/>
                    </xsl:call-template>
                </td>
            </xsl:if>
            <td class="Table-col InlineSearch-title-col">
                <xsl:if test="not(/Root/Params/AlbumID or /Root/Params/TrackID)">
                    <xsl:attribute name="class">rowLeft left</xsl:attribute>
                </xsl:if>
                <xsl:choose>
                    <xsl:when test="not(/Root/Params/AlbumID or /Root/Params/TrackID)">
                        <a href="contract?ContractID={ArtistContractID}&amp;c=show"><xsl:value-of select="Title" /></a>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="Title" />
                    </xsl:otherwise>
                </xsl:choose>
            </td>
            <td class="Table-col InlineSearch-artist-col"><xsl:value-of select="ArtistDescription" /></td>
            <td class="Table-col InlineSearch-contract-col"><xsl:value-of select="ClientContractID" /></td>
            <xsl:if test="not(/Root/Params/_inline)">
                <xsl:variable name="payorID" select="PayorID" />
                <td class="Table-col"><xsl:value-of select="/Root/PayorList/Payor[PayorID = $payorID]/Name" /></td>
                <td class="Table-col"><xsl:value-of select="ArtistPayee/Name" /></td>
            </xsl:if>
            <xsl:if test="not(/Root/Params/AlbumID or /Root/Params/TrackID) and /Root/Access/rps/contract/edit = 1">
                <td class="Table-col Table-col-icon">
                    <a href="contract?c=edit&amp;ContractID={ArtistContractID}" 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:template>

    <xsl:template name="resultsHeader">
        <table class="Table" id="resultsHeader">
            <thead>
                <tr class="Table-row Table-row-header">
                    <xsl:if test="Params/_inline">
                        <xsl:attribute name="class">textChartTop</xsl:attribute>
                        <th class="Table-col Table-col-select Table-col-select-wide">Select</th>
                    </xsl:if>
                    <th class="Table-col InlineSearch-title-col">
                        <xsl:if test="not(Params/_inline)">
                            <xsl:attribute name="class">rowLeft</xsl:attribute>
                        </xsl:if>
                        Contract Title
                    </th>
                    <th class="Table-col InlineSearch-artist-col">Artist</th>
                    <th class="Table-col InlineSearch-contract-col">Contract ID</th>
                    <xsl:if test="not(Params/_inline)">
                        <th class="Table-col">Payor</th>
                        <th class="Table-col">Payee</th>
                    </xsl:if>
                    <xsl:if test="not(Params/_inline) and /Root/Access/rps/contract/edit = 1">
                        <th class="Table-col Table-col-icon">Edit</th>
                    </xsl:if>
                </tr>
            </thead>
        </table>
    </xsl:template>

</xsl:stylesheet>
