<!--                                                                  -->
<!--  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="lockedRecord">
        <xsl:choose>
            <xsl:when test="/Root/Form/LabelContract/Status = 2 or /Root/Form/LabelContract/Status = 3">1</xsl:when>
            <xsl:otherwise>0</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    <xsl:template name="contractShowLayout">
        <xsl:call-template name="contractShow" />
        <xsl:call-template name="buttons" />
        <xsl:call-template name="templates"/>
    </xsl:template>

    <xsl:template name="contractShow">
        <script type="text/javascript" src="/production/javascript/validate/labelContract.js?v=12" />

        <div class="ContractLabelShow Contract-label-block PageShow js-rs-html-content" id="contractShow">
            <xsl:call-template name="openRunStatusMessage" />
            <xsl:call-template name="successMessageGeneral">
                <xsl:with-param name="successMessage">Contract successfully updated!</xsl:with-param>
            </xsl:call-template>
            <section class="ContractLabelShow-main-contract" data-id="{Form/LabelContract/LabelContractID}">
                <xsl:call-template name="labelContractView" />
            </section>

            <xsl:for-each select="Form/LabelContract/GroupTermList/GroupTerm">
                <xsl:sort select="LabelContractGroupTermID" data-type="number" />

                <xsl:call-template name="termView">
                    <xsl:with-param name="term" select="." />
                </xsl:call-template>
            </xsl:for-each>

            <xsl:if test="$openRuns = 0">
                <div class="Table-add-row-button">
                    <xsl:call-template name="uiButton">
                        <xsl:with-param name="content" select="'Add Another Set of Terms'" />
                        <xsl:with-param name="iconLeftType" select="'add'" />
                        <xsl:with-param name="type" select="'text-inline'" />
                        <xsl:with-param name="className" select="'Form-button'" />
                        <xsl:with-param name="onClick" select="'LabelContractPage.addGroupTerm(true)'" />
                    </xsl:call-template>
                </div>
            </xsl:if>
        </div>
    </xsl:template>

    <xsl:template name="labelContractView">
        <section id="contractView" class="PageSection">
            <div class="ControlsHeader">
                <h2 class="ControlsHeader-text">Contract</h2>
                <xsl:if test="$openRuns = 0">
                    <div>
                        <xsl:call-template name="uiButton">
                            <xsl:with-param name="content" select="'Edit Contract'" />
                            <xsl:with-param name="className" select="'Form-button'" />
                            <xsl:with-param name="onClick" select="'LabelContractPage.editContract(this)'" />
                        </xsl:call-template>
                    </div>
                </xsl:if>
            </div>
            <table class="Table">
                <thead>
                    <tr class="Table-row Table-row-header">
                        <th class="Table-col">Contract Title</th>
                        <th class="Table-col">Contract ID</th>
                        <th class="Table-col">Payor</th>
                        <th class="Table-col">Payee</th>
                        <th class="Table-col">Issue Date</th>
                    </tr>
                </thead>
                <tbody>
                    <tr class="Table-row Table-row-data">
                        <td class="Table-col"><xsl:value-of select="Form/LabelContract/Title" /></td>
                        <td class="Table-col"><xsl:value-of select="Form/LabelContract/ClientContractID" /></td>
                        <td class="Table-col">
                            <xsl:value-of select="Form/PayorList/Payor[PayorID = /Root/Form/LabelContract/PayorID]/Name" />
                        </td>
                        <td class="Table-col">
                            <a href="/rps/label_payee?LabelPayeeID={Form/LabelContract/LabelPayeeID}&amp;c=show">
                                <xsl:value-of select="Form/LabelContract/LabelPayeeName" />
                            </a>
                        </td>
                        <td class="Table-col"><xsl:value-of select="Form/LabelContract/IssueDate" /></td>
                    </tr>
                </tbody>
            </table>
            <xsl:call-template name="lastModifiedCell" />
        </section>
    </xsl:template>

    <xsl:template name="lastModifiedCell">
        <div class="PageShow-last-modified">
            <p class="HelpText">
                Last Modified:&#160;<xsl:value-of select="Form/LabelContract/ModifiedDate" /><xsl:if test="normalize-space(Form/LabelContract/ModifiedBy)"> by <xsl:value-of select="Form/LabelContract/ModifiedBy" /></xsl:if>
            </p>
        </div>
    </xsl:template>

    <xsl:template name="termViewMessages">
        <xsl:call-template name="successMessageGeneral">
            <xsl:with-param name="successMessage" select="'Contract Terms successfully updated!'" />
            <xsl:with-param name="showDismiss" select="'true'" />
        </xsl:call-template>

        <xsl:if test="//Root/Deleted = 1">
            <xsl:call-template name="uiWarning">
                <xsl:with-param name="type" select="'success'" />
                <xsl:with-param name="description" select="'Contract Terms successfully deleted!'"/>
                <xsl:with-param name="showDismiss" select="'true'" />
            </xsl:call-template>
        </xsl:if>

        <xsl:if test="//Root/Deleted = 0">
            <xsl:call-template name="uiWarning">
                <xsl:with-param name="type" select="'error'" />
                <xsl:with-param name="description" select="'At least one set of terms must be associated with a label contract.'"/>
                <xsl:with-param name="showDismiss" select="'true'" />
            </xsl:call-template>
        </xsl:if>
    </xsl:template>

    <xsl:template name="termView">
        <xsl:param name="term" select="Form/GroupTerm" />

        <section class="Contract-terms-wrapper" data-id="{$term/LabelContractGroupTermID}" data-index="{position() - 1}">
            <xsl:call-template name="termViewMessages" />

            <xsl:if test="not(//Root/Deleted = 1)">
                <section id="groupTerm{$term/LabelContractGroupTermID}Section" class="PageSection Contract-terms-section">
                    <section class="ContractLabelShow-terms contractTerms" id="fieldSet{$term/LabelContractGroupTermID}">
                        <div class="ControlsHeader ControlsHeader-separated">
                            <h2 class="ControlsHeader-text">Contract Terms</h2>

                            <xsl:if test="$openRuns = 0">
                                <div>
                                    <xsl:call-template name="uiButton">
                                        <xsl:with-param name="type" select="'danger'" />
                                        <xsl:with-param name="content" select="'Delete Terms'" />
                                        <xsl:with-param name="name" select="'deleteTerms'" />
                                        <xsl:with-param name="className" select="'Form-button'" />
                                        <xsl:with-param name="onClick" select="'LabelContractPage.confirmDeleteTerm(this, event)'" />
                                    </xsl:call-template>

                                    <xsl:call-template name="uiButton">
                                        <xsl:with-param name="content" select="'Edit Terms'" />
                                        <xsl:with-param name="name" select="'editTerms'" />
                                        <xsl:with-param name="className" select="'Form-button'" />
                                        <xsl:with-param name="onClick" select="'LabelContractPage.editTerm(this)'" />
                                    </xsl:call-template>
                                </div>
                            </xsl:if>
                        </div>

                        <xsl:if test="$term/GroupTermLabelList/GroupTermLabel/LabelContractGroupTermLabelID">
                            <div class="ContractLabelShow-terms-item">
                                <div class="ValuePair labelTable ContractLabelShow-label-list">
                                    <div class="ValuePair-item">
                                        <span class="ValuePair-label ValuePair-label-for-list">Labels</span>
                                        <div class="ValuePair-value">
                                            <ul class="LinksList">
                                                <xsl:for-each select="$term/GroupTermLabelList/GroupTermLabel">
                                                    <xsl:sort select="LabelName" />
                                                    <li class="LinksList-item">
                                                        <a href="/rps/catalog?c=list&amp;label={LabelID}" class="js-tooltip" title="View albums"><xsl:value-of select="LabelName" /></a>
                                                    </li>
                                                </xsl:for-each>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </xsl:if>

                        <xsl:if test="not($term/GroupTermLabelList/GroupTermLabel/LabelContractGroupTermLabelID)">
                            <div class="ContractLabelShow-terms-item">
                                No labels have been associated with this set of terms.
                            </div>
                        </xsl:if>

                        <xsl:if test="$term/DistributionFee">
                            <div class="ContractLabelShow-terms-item">
                                <table class="Table ContractLabelShow-term-table Contract-label-term-table">
                                    <thead>
                                        <tr class="Table-row Table-row-header">
                                            <th class="Table-col">Service</th>
                                            <th class="Table-col">Country</th>
                                            <th class="Table-col">Distribution Fee</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr class="Table-row Table-row-data">
                                            <td class="Table-col">All</td>
                                            <td class="Table-col">All</td>
                                            <td class="Table-col"><xsl:value-of select="$term/DistributionFee" />%</td>
                                        </tr>
                                    </tbody>
                                </table>
                                <xsl:if test="$term/GroupTermExceptionList/GroupTermException/LabelContractGroupTermExceptionID">
                                    <p class="ContractLabelShow-terms-except">Except</p>
                                    <table class="Table ContractLabelShow-exception-table Contract-label-exception-table">
                                        <tbody>
                                            <xsl:for-each select="$term/GroupTermExceptionList/GroupTermException">
                                                <xsl:call-template name="exceptionRowView" />
                                            </xsl:for-each>
                                        </tbody>
                                    </table>
                                </xsl:if>
                            </div>
                        </xsl:if>

                    </section>
                </section>
            </xsl:if>
        </section>
    </xsl:template>

    <xsl:template name="exceptionRowView">
        <tr class="Table-row Table-row-data" id="exception{position()}">
            <td class="Table-col">
                <xsl:value-of select="ServiceName" />
            </td>
            <td class="Table-col">
                <xsl:value-of select="CountryName" />
            </td>
            <td class="Table-col">
                <xsl:value-of select="DistributionFee" />%
            </td>
        </tr>
    </xsl:template>
</xsl:stylesheet>
