<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html" encoding="utf-8" indent="yes"/>

    <!-- Parameters -->

    <xsl:param name="VERSION">1.0</xsl:param>
    <xsl:param name="PAGE-TITLE">User Summary</xsl:param>
    <xsl:param name="PAGE-NAME">userSummary</xsl:param>

    <!-- Main Template -->

    <xsl:template match="/">

        <script src="js/{$PAGE-NAME}.js?version={$VERSION}"/>   

        <div class="{$PAGE-NAME}">
      
            <div class="card">
        
                <div class="card-header bg-primary text-white p-1 ps-3">
          
                    <i class="bi bi-person me-2" aria-hidden="true"/>
                    <xsl:value-of select="$PAGE-TITLE"/>
          
                </div>
        
                <div class="card-body pb-0">

                    <!-- Details -->
          
                    <div class="card card-header rounded p-0 ms-0 me-0 mb-3">
            
                        <div class="card-body p-2">
              
                            <div class="row fs-875 lh-sm">

                                <div class="col-lg-6">

                                    <div class="row"> 

                                        <div class="col-3 fw-bold">
                                            Name
                                        </div>
                                        <div class="col-9">
                                            <xsl:value-of select="//users/record/user_name"/>
                                        </div>

                                    </div>

                                    <div class="row">

                                        <div class="col-3 fw-bold">
                                            Main Email:
                                        </div>
                                        <div class="col-9">
                                            <xsl:value-of select="//users/record/user_email"/>
                                        </div>

                                    </div>

                                    <div class="row">

                                        <div class="col-3 fw-bold">
                                            User Name:
                                        </div>
                                        <div class="col-9">
                                            <xsl:value-of select="//users/record/user_client_name"/>
                                        </div>

                                    </div>
                                    <div class="row">

                                        <div class="col-3 fw-bold">
                                            Role:
                                        </div>
                                        <div class="col-9">
                                            <xsl:value-of select="//users/record/user_role"/>
                                        </div>

                                    </div>
                                    <div class="row">

                                        <div class="col-3 fw-bold">
                                            Change Password?:
                                        </div>
                                        <div class="col-9">
                                            <xsl:choose>
                                                <xsl:when test="boolean(number(//users/record/user_change_password)) = true()">
                                                    <span class="badge bg-success">Yes</span>
                                                </xsl:when>
                                                <xsl:otherwise>
                                                    <span class="badge bg-danger">No</span>
                                                </xsl:otherwise>
                                            </xsl:choose>
                                        </div>

                                    </div>

                                </div>

                                <div class="col-lg-6">

                                    <div class="row">

                                        <div class="col-3 fw-bold">
                                            Created:
                                        </div>
                                        <div class="col-9">
                                            <xsl:value-of select="//users/record/user_created_verbose"/>
                                        </div>

                                    </div>

                                    <div class="row">

                                        <div class="col-3 fw-bold">
                                            Created By:
                                        </div>
                                        <div class="col-9">
                                            <xsl:value-of select="//users/record/user_creator"/>
                                        </div>

                                    </div>
                                    <div class="row">

                                        <div class="col-3 fw-bold">
                                            Changed:
                                        </div>
                                        <div class="col-9">
                                            <xsl:value-of select="//users/record/user_changed_verbose"/>
                                        </div>

                                    </div>

                                    <div class="row">

                                        <div class="col-3 fw-bold">
                                            Changed By:
                                        </div>
                                        <div class="col-9">
                                            <xsl:value-of select="//users/record/user_changed_user"/>
                                        </div>

                                    </div>
                                    
                                    <div class="row">

                                        <div class="col-3 fw-bold">
                                            Last Login:
                                        </div>
                                        <div class="col-9">
                                            <xsl:value-of select="//users/record/user_login_verbose"/>
                                        </div>

                                    </div>
                                    <div class="row align-items-baseline mt-1">

                                        <div class="col-3 fw-bold">
                                            Active Status:
                                        </div>
                                        
                                        <div class="col-3">
                                            <select class="form-select form-select-sm" name="user_active" id="user_active" size="1">
                                                
                                                <xsl:choose>
                                                    <xsl:when test="//users/record/user_active = 1">
                                                        <option value="1" selected="yes">Active</option>
                                                        <option value="0">Inactive</option>
                                                    </xsl:when>
                                                    <xsl:otherwise>
                                                        <option value="1">Active</option>
                                                        <option value="0" selected="yes">Inactive</option>
                                                    </xsl:otherwise>
                                                </xsl:choose>
                                            </select>
                                        </div>

                                    </div>

                                </div>

                            </div>
 
                        </div>
            
                    </div>

                    <hr class="mb-2"/>
 
                    <!-- Action Buttons --> 

                    <div class="buttons mt-1 mb-1">
            
                        <button type="button" class="btn btn-sm btn-primary me-1 mb-1 btnDone">
                            <i class="bi bi-box-arrow-left me-2"/>Done</button>
                        <button type="button" class="btn btn-sm btn-primary me-1 mb-1 btnEdit">
                            <i class="bi bi-pencil me-2"/>Edit</button>
                        <button type="button" class="btn btn-sm btn-primary me-1 mb-1 btnPrint">
                            <i class="bi bi-printer me-2"/>Print</button>
                        <button type="button" class="btn btn-sm btn-primary me-1 mb-1 btnResetPassword">
                            <i class="bi bi-unlock me-2"/>Reset Password</button>

                    </div>

                    <hr class="mt-1 mb-3"/> 

                    <!-- Tabs --> 
          
                    <div class="row">
                        <div class="col-12"> 
                            <div class="nav nav-tabs" id="nav-tabs" role="tablist">
                                <a class="nav-item nav-link active" id="tab-Subscriptions" data-bs-toggle="tab" href="#pane-Subscriptions" role="tab" data-tab="Subscriptions" aria-controls="st-Subscriptions">
                                    <i class="bi bi-list-check me-1"/>Subscriptions</a>
                                <a class="nav-item nav-link" id="tab-Notes" data-bs-toggle="tab" href="#pane-Notes" role="tab" data-tab="Notes" aria-controls="st-Notes">
                                    <i class="bi bi-chat-dots me-1"/>Notes</a>
                            </div>
                        </div>
                    </div>

                    <!-- Tab Content --> 

                    <div class="tab-content mb-3" id="tab-content"> 

                        <!-- Subscriptions --> 

                        <div class="tab-pane show active" id="pane-Subscriptions" role="tabpanel" aria-labelledby="tab-Subscriptions">            
 
                            <div class="card mb-0 mt-3">

                                <div class="card-body pt-2 pb-2">

                                    <xsl:choose>

                                        <xsl:when test="count(//usersubscriptions/record) = 0">
                                            <div class="col fs-6 text-danger fw-bold fst-italic mt-1 mb-1">
                                                <xsl:text>There are no Subscriptions....</xsl:text>
                                            </div>
                                        </xsl:when>

                                        <xsl:otherwise>

                                            <div class="table-responsive scrollable-30">
                                                <table class="table table-sm table-striped base-table table-auto" id="usersubscriptions-table">
                                                    <thead class="sticky-header">
                                                        <th>Description</th>
                                                        <th>End Date</th>
                                                        <th>Status</th>
                                                    </thead>
                                                    <tbody>
                                                        <xsl:apply-templates select="//usersubscriptions"/>
                                                    </tbody>
                                                </table>
                                            </div>

                                        </xsl:otherwise>

                                    </xsl:choose>

                                    <div class="buttons mt-2 mb-1">

                                        <button type="button" class="btn btn-sm btn-primary mt-2 me-1 mb-1 btnAddSubscription">
                                            <i class="bi bi-plus me-2"/>Add Subscription</button>

                                    </div>

                                </div>

                            </div>

                        </div>  <!-- Subscriptions -->
                        
                        <!-- Notes --> 

                        <div class="tab-pane" id="pane-Notes" role="tabpanel" aria-labelledby="tab-Notes">            
 
                            <div class="card mb-0 mt-3">

                                <div class="card-body pt-2 pb-2">

                                    <xsl:choose>

                                        <xsl:when test="count(//notes/record) = 0">
                                            <div class="col fs-6 text-danger fw-bold fst-italic mt-1 mb-1">
                                                <xsl:text>There are no Notes...</xsl:text>
                                            </div>
                                        </xsl:when>

                                        <xsl:otherwise>

                                            <div class="table-responsive scrollable-30">
                                                <table class="table table-sm table-striped base-table table-auto" id="notes-table">
                                                    <thead class="sticky-header">
                                                        <th>Date</th>
                                                        <th>User</th>
                                                        <th>Type</th>
                                                        <th>Note</th>
                                                    </thead>
                                                    <tbody>
                                                        <xsl:apply-templates select="//notes" />
                                                    </tbody>
                                                </table>
                                            </div>

                                        </xsl:otherwise>

                                    </xsl:choose>

                                    <div class="buttons mt-2 mb-1">
                                        <button type="button" class="btn btn-sm btn-primary mt-2 me-1 mb-1 btnAddNote">
                                            <i class="bi bi-plus me-2"/>Add Note</button>
                                    </div>

                                </div>

                            </div>

                        </div>  <!-- Notes -->
                        
                    </div>  <!-- Tab Content -->
          
                </div>
        
            </div>
      
        </div>

        <!-- Form to Print the User Summary -->
    
        <form style="display:inline;" id="PrintUserSummaryForm" method="post" action="" target="PrintTab">

            <input type="hidden" name="action"           value="print"/>
            <input type="hidden" name="report"           value="Print_UserSummary"/>
            <input type="hidden" name="user_serial" value=""/>

        </form>
                        
    </xsl:template>

    <!-- Template for Dropdowns -->

    <xsl:template name="dropdowns">
    
        <xsl:param name="dropdown-name"/>
        <xsl:param name="current-value"/>
    
        <option value="">Choose...</option>
    
        <xsl:for-each select="//dropdowns/record[dropdowntype_name = $dropdown-name]">
      
            <option value="{dropdown_serial}" data-tokens="{dropdown_value}">
                <xsl:if test="dropdown_serial = $current-value">
                    <xsl:attribute name="selected">selected</xsl:attribute>
                </xsl:if>
                <xsl:value-of select="dropdown_value" />
            </option>
      
        </xsl:for-each>
    
    </xsl:template>

    <!-- Template for Notes Tab -->

    <xsl:template match="notes/record">
    
        <tr class="hoverable note-row" data-note-serial="{note_serial}">
      
            <td class="note_timestamp text-nowrap">
                <xsl:value-of select="note_timestamp_verbose"/>
            </td>
            <td class="note_origin text-nowrap">
                <xsl:value-of select="note_origin"/>
            </td>
            <td class="note_type text-nowrap">
                <xsl:value-of select="note_type"/>
            </td>
            <td class="note_text pre-wrap">
                <xsl:value-of select="note_text"/>
            </td>

        </tr>
    
    </xsl:template>
    
    <!-- Template for Users Subscriptions Tab -->

    <xsl:template match="usersubscriptions/record">
    
        <tr class="usersubscription-row hoverable" data-usersubscription-serial="{usersubscription_serial}">
      
            <td class="subscription_title">
                <xsl:value-of select="concat(subscription_title, '-', subscription_description)"/>
            </td>
            <td class="usersubscription_stop_date_verbose">
                <xsl:value-of select="usersubscription_stop_date_verbose"/>
            </td>
            
            <xsl:choose>
                <xsl:when test="usersubscription_status = 'EXPIRED'">
                    <td class="usersubscription_status">
                        <span class="badge rounded-pill text-bg-danger">
                            <xsl:value-of select="usersubscription_status"/>
                        </span>
                    </td>
                </xsl:when>
                <xsl:otherwise>
                    <td class="usersubscription_status">
                        <span class="badge text-bg-success">
                            <xsl:value-of select="usersubscription_status"/>
                        </span>
                    </td>
                </xsl:otherwise>
            </xsl:choose>

        </tr>
    
    </xsl:template>
    
</xsl:stylesheet>
