<!--                                                                  -->
<!--  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>
                <div class="MainBaseSection">
                    <xsl:call-template name="searchResults" />
                </div>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template name="searchResults">
        <div class="ArtistContractSearch">
            <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">
                    <section class="Table-empty-results">
                        <p>No contracts have been created.</p>
                    </section>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:choose>
                        <xsl:when test="Params/_inline">
                            <xsl:call-template name="resultsList" />
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:call-template name="resultsFullList" />
                        </xsl:otherwise>
                    </xsl:choose>
                </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:with-param name="type" select="'stick'" />
            </xsl:call-template>
        </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="form">artist_contractSearch</xsl:with-param>
            <xsl:with-param name="area">artist_contract</xsl:with-param>
            <xsl:with-param name="withText">true</xsl:with-param>
        </xsl:call-template>

        <xsl:if test="count($searchItem) != 0">
            <xsl:call-template name="contractListInlineTable" />
        </xsl:if>
    </xsl:template>

    <xsl:template name="resultsFullList">
        <xsl:if test="Params/Query">
            <h2>Search Results</h2>
        </xsl:if>

        <xsl:choose>
            <xsl:when test="count($searchItem) != 0">
                <xsl:if test="Pagination/TotalPages > 1">
                    <div class="Table-controls Table-controls-top">
                        <div class="Table-controls-item Table-controls-item-pagination">
                            <xsl:call-template name="searchNavRecords" />
                        </div>
                    </div>
                </xsl:if>
                <xsl:call-template name="contractListTable" />
                <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="searchNavRecords" />
                        </div>
                    </div>
                </xsl:if>
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="searchNoResult" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template name="contractListInlineTable">
        <table class="Table InlineSearch-table" id="resultsHeader">
            <thead>
                <xsl:call-template name="resultsHeader" />
            </thead>
        </table>
        <div class="Table-wrapper Table-wrapper-srolltop">
            <table class="InlineSearch-table Table">
                <tbody>
                    <xsl:for-each select="$searchItem">
                        <xsl:call-template name="contractListTableRow" />
                    </xsl:for-each>
                </tbody>
            </table>
        </div>
    </xsl:template>

    <xsl:template name="contractListTable">
        <table class="Table Table-with-highlight">
            <thead>
                <xsl:call-template name="resultsHeader" />
            </thead>
            <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 | /Root/TrackContractList/TrackContract">
                    <xsl:if test="(ContractID = $contractID) and (Status != 2)">1</xsl:if>
                </xsl:for-each>
            </xsl:variable>
            <xsl:attribute name="class">
                <xsl:text>Table-row Table-row-data</xsl:text>
                <xsl:if test="string-length($disableContract) > 0">
                    <xsl:text> disabledRow</xsl:text>
                </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="string-length($disableContract) > 0">
                                <xsl:text>true</xsl:text>
                            </xsl:if>
                        </xsl:with-param>
                        <xsl:with-param name="name" select="'ArtistContractIDs'"/>
                        <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:choose>
                    <xsl:when test="not(/Root/Params/AlbumID or /Root/Params/TrackID)">
                        <a href="artist_contract?ArtistContractID={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 ArtistContractSearch-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/artist_contract/edit = 1">
                <td class="Table-col Table-col-icon">
                    <a href="artist_contract?c=edit&amp;ArtistContractID={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">
        <tr class="Table-row Table-row-header">
            <xsl:if test="Params/_inline">
                <th class="Table-col Table-col-select Table-col-select-wide">Select</th>
            </xsl:if>
            <th class="Table-col InlineSearch-title-col">
                Contract Title
            </th>
            <th class="Table-col ArtistContractSearch-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/artist_contract/edit = 1">
                <th class="Table-col Table-col-icon">Edit</th>
            </xsl:if>
        </tr>
    </xsl:template>

</xsl:stylesheet>
