{% macro navlink(display, tab_id, style='') %}
<a href="#"
   class="tablink {{ style }}"
   onclick="openTab('{{ tab_id }}')"
   >{{ display }}</a>
{% endmacro %}

{% macro cdn_jslib(local_filename, cdn_url, libobj, integrity=None) %}
<script src="{{ cdn_url }}" crossorigin="anonymous"
        {% if integrity is not none %}
        integrity="{{ integrity }}"
        {% endif %}
        ></script>
<script>jsFallbackFromCDN('{{ libobj }}', '{{ local_filename }}');</script>
{% endmacro %}

{% macro embed_jslib(local_filename) %}
<!-- INSERTED {{ local_filename }} -->
<script type="text/javascript">{{ offline_file(local_filename) }}</script>
{% endmacro %}

{% macro cdn_stylesheet(local_filename, cdn_url) %}
<link rel="stylesheet" href="{{ cdn_url }}">
<link rel="stylesheet" href="{{ static_ref(local_filename) }}">
{% endmacro %}

{% macro embed_stylesheet(local_filename) %}
<!-- INSERTED {{ local_filename }} -->
<style>{{ offline_file(local_filename) }}</style>
{% endmacro %}

<!DOCTYPE html>
<html>
    <head>
        <title>{{ title }}</title>
        <meta charset="utf-8">

        <link rel="icon" type="image/png" sizes="16x16" href="{{ static_ref('images/favicon-16x16.png') }}">
        <link rel="icon" type="image/png" sizes="32x32" href="{{ static_ref('images/favicon-32x32.png') }}">
        <link rel="icon" type="image/png" sizes="96x96" href="{{ static_ref('images/favicon-96x96.png') }}">

        <script>
          function jsFallbackFromCDN(libname_to_check, localFilename) {
              var parts = libname_to_check.split('.')
              if (((parts.length == 1) && (typeof window[parts[0]] == "undefined")) ||
                  ((parts.length == 2) && (typeof window[parts[0]][parts[1]] == "undefined"))) {
                  console.log(`***Failed to load ${localFilename} from CDN. Falling back to local offline version.***`);
                  document.write(unescape(`%3Cscript src="./offline/${localFilename}" type="text/javascript"%3E%3C/script%3E`));
              }
            }
        </script>
        
        {{ cdn_jslib("jquery-3.6.4.min.js", "https://code.jquery.com/jquery-3.6.4.min.js", "jQuery",
        integrity="sha256-oP6HI9z1XaZNBrJURtCoUT5SUnxFr8s3BzRl+cbzUq8=") }}

        {{ cdn_jslib("jquery-ui.min.js", "https://code.jquery.com/ui/1.12.1/jquery-ui.min.js", "jQuery.ui",
        integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=") }}

        {{ cdn_jslib("plotly-3.0.1.min.js", "https://cdn.plot.ly/plotly-3.0.1.min.js", "Plotly") }}
        {{ cdn_jslib("katex.min.js", "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.1/katex.min.js", "katex") }}
        {{ cdn_jslib("auto-render.min.js", "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.1/contrib/auto-render.min.js", "renderMathInElement") }}
        {{ embed_jslib("pygsti_plotly_ex.js") }}
        {{ embed_jslib("pygsti_dashboard.js") }}

        {{ cdn_stylesheet("smoothness-jquery-ui.css", "https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css") }}
        {{ cdn_stylesheet("katex.css", "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.1/katex.min.css") }}
        {{ embed_stylesheet("pygsti_dataviz.css") }}
        {{ embed_stylesheet("pygsti_dashboard.css") }}
        {{ embed_stylesheet("pygsti_fonts.css") }}

    </head>
  
    <body>

      <div id="content-wrapper">
        <div id="theSidenav" class="sidenav loadable notloaded">
          <a href="javascript:void(0)" id="tackbtn" title="Toggle navigation bar auto-hide" onclick="tackNav()">&#8859;</a>
          <div class="linkgroup">
            {{ navlink('Custom', 'Custom', style='linkgroupheading active') }}
          </div>
        </div>

        <div id="main-wrapper">
          <header class="header" role="banner">
      	    <H1 class="title">{{ title }}</h1>
	        <h2 class="author">generated by pyGSTi on {{ date }}</h2>
          </header>
          <div id="main">

            <div id="Custom" class="tabcontent">
	          <h1>Custom Report</h1>

	          <figure id="targetGatesBoxTable" class='tbl'>
	            <figcaption><span class="captiontitle">Test figure.</span> <span class="captiondetail">This is how you could put a figure in a custom report.</span></figcaption>
                {{ targetGatesBoxTable|render }}
	          </figure>

      
            </div> <!-- end tab content -->
            <div id="status">
              No message
            </div>
          </div>
        </div>
    </body>
    
    <script>
      $(document).ready(function() {
          initNav(); // so sidebar is loaded and can hide/show
          initBanner(); // so banner can hide/show
          openTab('Custom'); // the active tab (see 'active' class above)
      });
    </script>
</html>
