<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0" 
    xmlns:eg="http://www.tei-c.org/ns/Examples"
    xmlns:tei="http://www.tei-c.org/ns/1.0" 
    xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
    xmlns:exsl="http://exslt.org/common"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:fn="http://www.w3.org/2005/xpath-functions"
    extension-element-prefixes="exsl msxsl"
    xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:html="http://www.w3.org/1999/xhtml" 
    exclude-result-prefixes="xsl tei xd eg fn #default">
    
    <!-- import teibp.xsl, which allows templates, 
         variables, and parameters from teibp.xsl 
         to be overridden here. -->
    <xsl:import href="teibp.xsl"/>
    
    <xsl:variable name="omekaItemURL" select="//tei:publicationStmt/tei:ab"/>
    
    <xsl:param name="pbNote"><text>p. </text></xsl:param>
    
    <xsl:param name="transcription" select="concat($filePrefix,'/css/transcription.css')"/>
    <xsl:param name="edition" select="concat($filePrefix,'/css/edition.css')"/>
    <xsl:param name="edition_markup" select="concat($filePrefix,'/css/edition_markup.css')"/>
    <xsl:param name="edition_semantic" select="concat($filePrefix,'/css/edition_semantic.css')"/>
    <!-- The following tells selector which to use  -->
    <xsl:param name="switchCSS" select="concat($filePrefix,'/css/edition.css')"/>


    <!-- The following creates the CSS switching toolbox. It overrides the same in teibp.xsl-->
    
     <xsl:template name="teibpToolbox">
        <div id="teibpToolbox">
            <div>
                <!-- <h1>Display Options</h1> -->
                <table>
                    <tr><td>
                <input type="checkbox" id="pbToggle" checked="true"/> 
                 <!--   </td>
                        <td> -->
                        <label for="pbToggle" class="tooltip">Images <seg class="tooltiptext">Show document images</seg></label>
                    </td>
     
                        
                
                <!-- this is what I'm adding, 11-24-20 -->
                 
                <!--
                <label for="headNoteToggle">Hide head note</label>
                <input type="checkbox" id="headNoteToggle" />
                -->
                <!-- end addition -->
                
                <!-- this is what I'm adding -->
                        <!--
                        <td>
                            <input type="checkbox" id="edNoteToggle" checked="true"/> 
                        </td>
                        
                        <td>
                            <label for="edNoteToggle">Editorial notes</label>
                        </td>
                        -->
                       
                        

                        <!--
                <td>
                    <input type="checkbox" id="noteToggle" checked="true"/> 
                </td>
                        <td>
                <label for="noteToggle">Annotations</label>
                </td>
                -->
                <!-- end addition -->
                <td>
                    <!--
                    <h3>Select Text View:</h3>
                    -->
                    <span class="tooltip"> <seg class="tooltiptext">Select text view</seg>
               <!--   <select style="display:inline;" id="themeBox" onchange="switchTextView(this);" > -->
                      <!-- this works to turn them off when using selector, but javascript still can't clear them when using checkbox -->
                     <!--   <select style="display:inline;" id="themeBox" onchange="switchTextView(this);clearAllNotes();" > -->
                        <select style="display:inline;" id="themeBox" onchange="switchTextView(this);setNotes(this.value);" > 
                        <option value="{$edition}">Reading</option>
                        <option value="{$edition_markup}">Intermediate</option>
                        <option value="{$edition_semantic}">Semantic</option>
                        <option value="{$transcription}">Transcription</option>
                    </select>           </span>
            </td>
               <!--     </tr>
  
                </table>  -->
                        <!-- add --> <td>
                <div n="readingVersionKey">
                    <table>
                        <tr>
                    <td>
                        <input type="checkbox" id="allNoteToggle" checked="true"/> 
                    </td>
                    <td>
                        <label for="allNoteToggle" class="tooltip">Notes<seg class="tooltiptext">Show all notes</seg>
                        </label>
                    </td>
                        <td>
                    
                    <div n="readingVersionNoteList" style="center" >
                    <table>
                        <tr>
                            <td id="geoNoteTD">
                        <input type="checkbox" id="geoNoteToggle" checked="true"/> 
                                <!--     </td>
                    <td>-->
                                <label for="geoNoteToggle" class="tooltip">Geo.<seg class="tooltiptext">Geographical notes</seg></label>
                    </td>
                    
                    <td id="histNoteTD">
                        <input type="checkbox" id="histNoteToggle" checked="true"/> 
               <!--     </td>
                    <td>-->
                        <label for="histNoteToggle" class="tooltip">Hist.<seg class="tooltiptext">Historical notes</seg></label>
                    </td>
                    
                            <td id="bioNoteTD">
                        <input type="checkbox" id="bioNoteToggle" checked="true"/> 
                                <!--     </td>
                    <td>-->
                                <label for="bioNoteToggle" class="tooltip">Bio.<seg class="tooltiptext">Biographical notes</seg></label>
                    </td>
                    
                            <td id="lexNoteTD"> 
                        <input type="checkbox" id="lexNoteToggle" checked="true"/> 
                                <!--     </td>
                    <td>-->
                                <label for="lexNoteToggle" class="tooltip">Lex.<seg class="tooltiptext">Lexical notes</seg></label>
                    </td>
                    
                            <td id="geneticNoteTD">
                        <input type="checkbox" id="geneticNoteToggle" checked="true"/> 
                                <!--     </td>
                    <td>-->
                                <label for="geneticNoteToggle" class="tooltip">Gen.<seg class="tooltiptext">Genetic notes</seg></label>
                    </td>
                    
                            <td id="generalNoteTD">
                        <input type="checkbox" id="generalNoteToggle" checked="true"/> 
                                <!--     </td>
                    <td>-->
                                <label for="generalNoteToggle" class="tooltip">Misc.<seg class="tooltiptext">Miscellaneous notes</seg></label>
                    </td>
                            
                        </tr>
                    </table>
                    </div>
                    </td>
                            
                </tr>
                </table> 
             
                
                </div> 
                        
                            
                <div n="transcriptionKey"><table><tr>
                    <td id="transNoteTD">
                        <input type="checkbox" id="transNoteToggle" checked="true"/> 
                  <!--  </td>
                    <td> -->
                        <label for="transNoteToggle">Notes</label>
                    </td>
                
                    <td><spacer><!-- trying to create space --></spacer></td>
                    <td id="transUnclearTD">difficult to read</td><td id="transSicTD">thus in original</td><td id="transSuppliedTD">added by editor</td>
                </tr></table></div>
                
       
                            
                            <div n="intermediateKey"><table><tr>
                                <td id="intermediateSicTD">Thus in original</td>
                                <td id="intermediateCorrTD">corrected</td>
                                <td id="intermediateOrigTD">original form</td>
                                <td id="intermediateRegTD">regularized form</td>
                                <td id="intermediateAbbrTD">abbreviation</td>
                                <td id="intermediateExpanTD">expansion of abbreviation</td>
                            </tr></table></div>
                
                            <div n="semanticKey"><table><tr>
                                <td id="semanticPersonTD"><name type="person">person</name></td>
                                <td id="semanticPlaceTD"><name type="place">place</name></td>
                                <td id="semanticInstitutionTD"><name type="institution">institution</name></td>
                                <td id="semanticEventTD"><name type="event">event</name></td>
                                <td id="semanticDateTD">date</td>
                            </tr></table></div>
                
                            </td>
                        </tr>
                    </table>
            </div>
        </div>

    </xsl:template>

    <!--  -->
    <xd:doc>
        <xd:desc>
            <xd:p>This constructs the pretend-HTML head of the document.  The main change from teibp.xsl is that I've added a javascript function switchTextView(theme) and a CSS line calling $switchCSS from above.</xd:p>
        </xd:desc>
    </xd:doc>
    <xsl:template name="htmlHead">
        <head>
            <meta charset="UTF-8"/>
            <link id="maincss" rel="stylesheet" type="text/css" href="{$teibpCSS}"/>
            <!-- 20211202 I am adding to try to get css animations to work -->
            <!--<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"/> -->
            <!-- end 20211202 -->
            <link id="customcss" rel="stylesheet" type="text/css" href="{$customCSS}"/>
            <link id="switchcss" rel="stylesheet" type="text/css" href="{$switchCSS}" />
            <!-- I am adding this line to try to get refs to open in same window. not working -->
            <base target="_self"/>
            <script type="text/javascript" src="{$jqueryJS}"></script>
            <script type="text/javascript" src="{$jqueryBlockUIJS}"></script>
            <script type="text/javascript" src="{$teibpJS}"></script>
            <script type="text/javascript">
                $(document).ready(function() {
                    $("html > head > title").text($("TEI > teiHeader > fileDesc > titleStmt > title:first").text());
                    $.unblockUI();  
                });
                <!-- cm adding 
                $(document).ready(function() {
                $("html > head > title").text($("TEI > teiHeader > fileDesc > publicationStmt > p").text());
                $.unblockUI();  
                });
                
                 end cm add -->
                function switchTextView(theme) {
                    document.getElementById('switchcss').href=theme.options[theme.selectedIndex].value;
                }
            </script>
            <xsl:call-template name="tagUsage2style"/>
            <xsl:call-template name="rendition2style"/>
            <title><!-- don't leave empty. --></title>
        </head>
    </xsl:template>
    
    <!-- I have copied this from teipb.xsl and added target="_self", to try to open links in same window, but not working) -->
    <xd:doc>
        <xd:desc>
            <xd:p>Transforms TEI ref element to html a (link) element. </xd:p>
        </xd:desc>
    </xd:doc>
 <!--   <xsl:template match="tei:ref[@target]" priority="99"> -->
        <xsl:template match="ref[@target]" priority="99">
        <a href="{@target}" target="_self">
            <xsl:apply-templates select="@*"/>
            <xsl:call-template name="rendition"/>
            <xsl:apply-templates select="node()"/>
        </a>
    </xsl:template>
    
    <!-- trying with div instead of span. Works the same as span; js can't turn notes on and off
    <xd:doc>
        <xd:desc>
            <xd:p>Wraps note inside span to enable tooltips, adds tooltip text</xd:p>
        </xd:desc>
    </xd:doc>
    <xsl:template match="tei:note">
            <div class="tooltip" type="wrapperForTooltip">
                <xsl:copy-of select="."/>
                
                <seg class="tooltiptext"><xsl:value-of select="@subtype"/> note</seg>
            </div> 
    </xsl:template>
      -->
    
    <!-- trying to add class attribute to note instead. Doesn't work because note has no class attribute?
    <xd:doc>
        <xd:desc>
            <xd:p>add class attribute to note, add tooltip text</xd:p>
        </xd:desc>
    </xd:doc>
    <xsl:template match="tei:note">
        
        <xsl:choose>
            <xsl:when test="@subtype='genetic'">
                
                    <xsl:copy-of select="."/>
                <xsl:attribute name="class">
                    <xsl:value-of select="tooltip"/>
                </xsl:attribute>
                   
                
            </xsl:when>
        </xsl:choose>
    </xsl:template> -->
    
    <!-- i tried wrapping in a span with specific subtype, to see if I could access that from js, but doesn't work either 
    <xd:doc>
        <xd:desc>
            <xd:p>Wraps note inside span to enable tooltips, adds tooltip text</xd:p>
        </xd:desc>
    </xd:doc>
    <xsl:template match="tei:note">
        
            <xsl:choose>
                <xsl:when test="@subtype='genetic'">
                    <span class="tooltip" type="wrapperForTooltip">
                        <xsl:copy-of select="."/>
                        <seg class="tooltiptext" type="genetic"><xsl:value-of select="@subtype"/> note</seg>
                    </span>
                </xsl:when>
        </xsl:choose>
    </xsl:template>
    -->
    <!-- The note element generated by the XSLT for some reason can't be accessed from javascript, perhaps because of one of the attributes this is for some reason added (@xmlns and @anchored are inserted). So I am coding the note elements myself, and this works, except that I need to now make the enclosing note disappear.  -->
    
    <xd:doc>
        <xd:desc>
            <xd:p>Wraps note inside span to enable tooltips, adds tooltip text</xd:p>
        </xd:desc>
    </xd:doc>
    <xsl:template match="tei:note">
        <xsl:choose>
            <xsl:when test="@subtype='geographical'">
                <span class="tooltip" type="wrapperForContextualGeographicalTooltip"><!--<note type="contextual" subtype="geographical">-->
                    <xsl:copy-of select="."/>
                    <seg class="tooltiptext"><xsl:value-of select="@subtype"/> note</seg>
                <!--</note>-->
                </span> 
            </xsl:when>
            <xsl:when test="@subtype='historical'">
                <span class="tooltip" type="wrapperForContextualHistoricalTooltip"><!--<note type="contextual" subtype="historical">-->
                    <xsl:copy-of select="."/>
                    <seg class="tooltiptext"><xsl:value-of select="@subtype"/> note</seg>
                <!--</note>-->
                </span> 
            </xsl:when>
            <xsl:when test="@subtype='biographical'">
                <span class="tooltip" type="wrapperForContextualBiographicalTooltip"><!--<note type="contextual" subtype="biographical">-->
                    <xsl:copy-of select="."/>
                    <seg class="tooltiptext"><xsl:value-of select="@subtype"/> note</seg>
                <!--</note>-->
                </span> 
            </xsl:when>
            <xsl:when test="@subtype='lexical'">
                <span class="tooltip" type="wrapperForContextualLexicalTooltip"><!--<note type="contextual" subtype="lexical">-->
                    <xsl:copy-of select="."/>
                    <seg class="tooltiptext"><xsl:value-of select="@subtype"/> note</seg>
              <!--  </note> -->
                </span> 
            </xsl:when>
            <xsl:when test="@subtype='genetic'">
                <!-- If I made this wrapperForGeneticTooltip, I could turn on and off the span in the respective function, instead of the enclosing note, and eliminate that enclosing note. Would need to do it for each category of contetxual note. I thnk this is true because if I comment out enclosing note, these still turn on and off with clearAllContextuallNotes, since that's using the span -->
                <span class="tooltip" type="wrapperForContextualGeneticTooltip"><!--<note type="contextual" subtype="genetic">--> 
                    <!--<span class="w3-container w3-center w3-animate-opacity">-->
                    <xsl:copy-of select="."/>
                    <seg class="tooltiptext"><xsl:value-of select="@subtype"/> note</seg>
                <!--</note>-->
              <!--  </span> -->
                </span>
        </xsl:when>
            <xsl:when test="@subtype='general'">
                <span class="tooltip" type="wrapperForContextualGeneralTooltip"><!-- <note type="contextual" subtype="general"> -->
                    <xsl:copy-of select="."/>
                    <seg class="tooltiptext"><xsl:value-of select="@subtype"/> note</seg>
               <!-- </note> -->
                </span> 
            </xsl:when>
            <!-- for trans notes we must look at type, not subtype -->
            <xsl:when test="@type='transcription'">
                <span class="tooltip" type="wrapperForTranscriptionTooltip"><!--<note type="transcription">-->
                    <xsl:copy-of select="."/>
                    <seg class="tooltiptext"><xsl:value-of select="@type"/> note</seg>
                <!--</note>-->
                </span> 
            </xsl:when>
        </xsl:choose>
    </xsl:template>
    
   
    <!-- the following all work, but the notes that are copied over by XSLT aren't suppressed, as the javascript can't seem them. Once I remove them somehow, these should work. Except that elements that are double-coded, like a name inside a choice, give unpredictable results. -->
   
    <xd:doc>
        <xd:desc>
            <xd:p>Wraps orig inside span to enable tooltip, adds tooltip text</xd:p>
        </xd:desc>
    </xd:doc>
    <xsl:template match="tei:orig">
        <span class="tooltip" type="inlineWrapperForIntermediateTooltip">
            <xsl:copy-of select="."/>
            <seg class="tooltiptext" type="intermediateTooltipText">original form</seg>
        </span> 
    </xsl:template>
    

    <xd:doc>
        <xd:desc>
            <xd:p>Wraps reg inside span to enable tooltip, adds tooltip text</xd:p>
        </xd:desc>
    </xd:doc>
    <xsl:template match="tei:reg">
        <span class="tooltip" type="inlineWrapperForIntermediateTooltip">
            <xsl:copy-of select="."/>
            <seg class="tooltiptext" type="intermediateTooltipText">regularized form</seg>
        </span> 
    </xsl:template>
    
 
    
    <xd:doc>
        <xd:desc>
            <xd:p>Wraps corr inside span to enable tooltip, adds tooltip text</xd:p>
        </xd:desc>
    </xd:doc>
    <xsl:template match="tei:corr">
        <span class="tooltip" type="inlineWrapperForIntermediateTooltip">
            <xsl:copy-of select="."/>
            <seg class="tooltiptext" type="intermediateTooltipText">corrected</seg>
        </span> 
    </xsl:template>
    
    <xd:doc>
        <xd:desc>
            <xd:p>Wraps abbr inside span to enable tooltip, adds tooltip text</xd:p>
        </xd:desc>
    </xd:doc>
    <xsl:template match="tei:abbr">
        <span class="tooltip" type="inlineWrapperForIntermediateTooltip">
            <xsl:copy-of select="."/>
            <seg class="tooltiptext" type="intermediateTooltipText">abbreviation</seg>
        </span> 
    </xsl:template>
    
    <xd:doc>
        <xd:desc>
            <xd:p>Wraps expan inside span to enable tooltip, adds tooltip text</xd:p>
        </xd:desc>
    </xd:doc>
    <xsl:template match="tei:expan">
        <span class="tooltip" type="inlineWrapperForIntermediateTooltip">
            <xsl:copy-of select="."/>
            <seg class="tooltiptext" type="intermediateTooltipText">expansion of abbreviation</seg>
        </span> 
    </xsl:template>
    
    <!-- the following three use generic inlineWrapperForTooltip, and don't need to be turned on and off like semantic and intermediate? -->
    <xd:doc>
        <xd:desc>
            <xd:p>Wraps unclear inside span to enable tooltip, adds tooltip text</xd:p>
        </xd:desc>
    </xd:doc>
    <xsl:template match="tei:unclear">
        <span class="tooltip" type="inlineWrapperForTooltip">
            <xsl:copy-of select="."/>
            <seg class="tooltiptext">difficult to read</seg>
        </span> 
    </xsl:template>
    
    <xd:doc>
        <xd:desc>
            <xd:p>Wraps supplied inside span to enable tooltip, adds tooltip text</xd:p>
        </xd:desc>
    </xd:doc>
    <xsl:template match="tei:supplied">
        <span class="tooltip" type="inlineWrapperForTooltip">
            <xsl:copy-of select="."/>
            <seg class="tooltiptext">supplied by editor</seg>
        </span> 
    </xsl:template>
    
    
    <xd:doc>
        <xd:desc>
            <xd:p>Wraps sic inside span to enable tooltip, adds tooltip text.</xd:p>
        </xd:desc>
    </xd:doc>
    <xsl:template match="tei:sic">
        <span class="tooltip" type="inlineWrapperForTooltip">
            <xsl:copy-of select="."/>
            <seg class="tooltiptext">thus in original</seg>
        </span> 
    </xsl:template>
    
    <xd:doc>
        <xd:desc>
            <xd:p>Wraps name inside span to enable tooltip, adds tooltip text</xd:p>
        </xd:desc>
    </xd:doc>
    <xsl:template match="tei:name">
        <span class="tooltip" type="inlineWrapperForSemanticTooltip">
            <xsl:copy-of select="."/>
            <xsl:choose>
                <xsl:when test="@type='person'">
                    <seg class="tooltiptext" type="semanticTooltipText"><xsl:value-of select="@type"/><spacer/><xsl:value-of select="@subtype"/></seg>
                </xsl:when>
                <xsl:when test="@type='place'">
                    <seg class="tooltiptext" type="semanticTooltipText"><xsl:value-of select="@type"/>: <xsl:value-of select="@subtype"/></seg>
                </xsl:when>
                <xsl:when test="@type='event'">
                    <seg class="tooltiptext" type="semanticTooltipText">event</seg>
                </xsl:when>
                <xsl:when test="@type='institution'">
                    <seg class="tooltiptext" type="semanticTooltipText"><xsl:value-of select="@type"/>: <xsl:value-of select="@subtype"/></seg>
                </xsl:when>
            </xsl:choose>
        </span> 
    </xsl:template>
    
    
    <xd:doc>
        <xd:desc>
            <xd:p>Wraps date inside span to enable tooltips, adds tooltip text</xd:p>
        </xd:desc>
    </xd:doc>
    <xsl:template match="tei:date" >
        <span class="tooltip" type="inlineWrapperForSemanticTooltip">
            <xsl:copy-of select="."/>
            
            <seg class="tooltiptext" type="semanticTooltipText">date</seg>
        </span> 
    </xsl:template>
    
    

    <!-- I've copied this over and commented out function calls, to make title disappear from top of page. This works.
    <xsl:template match="tei:teiHeader//tei:title">
        <tei-title>
            <xsl:call-template name="addID"/>
            <xsl:apply-templates select="@*|node()"/> 
        </tei-title>
    </xsl:template>
-->
    <xd:doc xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl">
        <xd:desc>
            <xd:p>Template for adding footer to html document.</xd:p>
        </xd:desc>
    </xd:doc>
    
    <xsl:variable name="htmlFooter">
        
        <footer> 
          <!--  <p><xsl:copy-of select="//tei:publicationStmt/tei:p"/></p> -->
            <p>Produced as part of the <a href="https://violamuse.unfdhi.org/">Viola Muse Digital Edition</a>, based at the University of North Florida. See the <a href="{string($omekaItemURL)}">complete metadata for this item</a>.</p>
            
            <!--<p><xsl:copy-of select="{$omekaItemURL}"/></p> -->
            <p> Powered by <a href="{$teibpHome}">TEI Boilerplate</a>. TEI Boilerplate is licensed under a <a
            href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0
                Unported License</a>. <!--<a href="http://creativecommons.org/licenses/by/3.0/"><img
                alt="Creative Commons License" style="border-width:0;"
                src="http://i.creativecommons.org/l/by/3.0/80x15.png"/></a>-->
        </p>
            
        </footer>
    </xsl:variable>
</xsl:stylesheet>