{{inherit "base.html"}}
<!--  -->
{{def navbar}}
<!-- Adapted from Pure CSS navbar : https://purecss.io/layouts/tucked-menu-vertical/ -->
<nav class="navbar pure-g fw-bold" id="menu" {{show_navbar|html}}>
  <script>
    var unique_id = "{{unique_id}}";
  </script>
  <div class="pure-u-1 pure-u-lg-1-8">
    <div class="pure-menu">
      <a href="#model-details-{{unique_id}}" class="pure-menu-heading">Home</a>
      <a href="#" class="custom-toggle" id="toggle"
        ><s class="bar"></s><s class="bar"></s
      ></a>
    </div>
  </div>
  <div class="pure-u-1 pure-u-lg-1-6">
    <div class="pure-menu pure-menu-horizontal custom-can-transform">
      <ul class="pure-menu-list">
        <li class="pure-menu-item">
          <a href="#model-details-{{unique_id}}" class="pure-menu-link"
            >Model details</a
          >
        </li>
        <li class="pure-menu-item">
          <a id="navbar-matrix-link-{{unique_id}}"
             href="#design-matrix-{{unique_id}}"
             class="pure-menu-link"
            >Design Matrix</a
          >
        </li>
        <li class="pure-menu-item">
          <a id="navbar-contrasts-link-{{unique_id}}"
             href="#contrasts-{{unique_id}}"
             class="pure-menu-link"
            >Contrasts</a
          >
        </li>
        <li class="pure-menu-item">
          <a href="#mask-{{unique_id}}" class="pure-menu-link">Mask</a>
        </li>
        <li class="pure-menu-item">
          <a href="#statistical-maps-{{unique_id}}" class="pure-menu-link"
            >Statistical Maps</a
          >
        </li>
        <li class="pure-menu-item">
          <a href="#about-{{unique_id}}" class="pure-menu-link">About</a>
        </li>
      </ul>
    </div>
  </div>
</nav>

<script>
  (function (window, document) {
    var menu = document.getElementById("menu"),
      rollback,
      WINDOW_CHANGE_EVENT =
        "onorientationchange" in window ? "orientationchange" : "resize";

    function toggleHorizontal() {
      menu.classList.remove("closing");
      [].forEach.call(
        document
          .getElementById("menu")
          .querySelectorAll(".custom-can-transform"),
        function (el) {
          el.classList.toggle("pure-menu-horizontal");
        },
      );
    }

    function toggleMenu() {
      // set timeout so that the panel has a chance to roll up
      // before the menu switches states
      if (menu.classList.contains("open")) {
        menu.classList.add("closing");
        rollBack = setTimeout(toggleHorizontal, 500);
      } else {
        if (menu.classList.contains("closing")) {
          clearTimeout(rollBack);
        } else {
          toggleHorizontal();
        }
      }
      menu.classList.toggle("open");
      document.getElementById("toggle").classList.toggle("x");
    }

    function closeMenu() {
      if (menu.classList.contains("open")) {
        toggleMenu();
      }
    }

    document.getElementById("toggle").addEventListener("click", function (e) {
      toggleMenu();
      e.preventDefault();
    });

    window.addEventListener(WINDOW_CHANGE_EVENT, closeMenu);
  })(this, this.document);
</script>

{{enddef}}
<!--  -->
{{def report}}

<div class="report">
  <section>
    <h2>Description</h2>
    {{ method_section|html }}
  </section>

  <section id="model-details-{{unique_id}}">
    <h2>Model details</h2>
    <div class="table-container">{{ parameters|html }}</div>
  </section>

  {{py: n_runs = len(displayed_runs)}}

  <div id="carousel-container-{{unique_id}}">

    {{if n_runs > 1}}
    <div class="pure-g d-flex justify-content-center align-items-stretch mt-1"
         id="carousel-navbar">
      <button class="btn pure-u-1-3 text-center rounded-2 carousel-navbar-element"
              id="prev-btn-{{unique_id}}">
        Previous Run
      </button>
      <!-- the content will be injected by javascript -->
      <h2 class="pure-u-1-4 py-3 text-center carousel-navbar-element"
          style="margin: 0px; padding: 0px">
        Run <span id="comp-{{unique_id}}"></span>
      </h2>
      <button class="btn pure-u-1-3 text-center rounded-2 carousel-navbar-element"
              id="next-btn-{{unique_id}}">
        Next Run
      </button>
    </div>
    <div class="d-flex justify-content-center align-items-stretch mt-2">
      <p>
        You can cycle through the different runs
        using your left and right arrow keys.
      </p>
    </div>
    {{endif}}


    <!--
      when there is more than one run
      all runs are set to display 'none',
      but initialization of the carousel
      will set the first one to be shown.
    -->
    {{for i_run, run_content in run_wise_dict.items()}}

    <div {{if n_runs> 1}}
      style="display: none"
      {{endif}}
      id="carousel-obj-{{unique_id}}-{{i_run}}"
      >

      <section id="design-matrix-{{unique_id}}-{{i_run}}">
        <h3>Design Matrix</h3>
        {{py: has_design_matrix = run_content.design_matrix_png is not None}}
        {{if has_design_matrix}}
        <div class="scroll-y">
          {{py: is_bytes = not run_content.design_matrix_png.endswith('.png')}}
          <img class="pure-img" src="{{if is_bytes}}data:image/png;base64,{{endif}}{{run_content.design_matrix_png}}"
            title="Plot of design matrix for {{i_run}}." alt="Plot of design matrix for {{i_run}}."
            style="min-width: 600px" />
        </div>

        {{py: has_correlation_matrix = run_content.correlation_matrix_png is not None}}
        <!--  -->
        {{if has_correlation_matrix}}
        <h3>correlation matrix</h3>
        <div class="scroll-y">
          {{py: is_bytes = not run_content.correlation_matrix_png.endswith('.png')}}
          <img class="pure-img"
            src="{{if is_bytes}}data:image/png;base64,{{endif}}{{run_content.correlation_matrix_png}}"
            title="Plot of correlation of design matrix for run {{i_run}}."
            alt="Plot of correlation of design matrix for run {{i_run}}." style="min-width: 600px" />
        </div>
        {{endif}}
        <!--  -->
        {{else}}
          <p>No design matrix was provided.</p>

        {{endif}}
      </section>

      <section id="contrasts-{{unique_id}}-{{i_run}}">
        <h3>Contrasts</h3>

        <div class="d-flex flex-column">
          {{py: has_contrasts = run_content.all_contrasts is not None}}
          {{if has_contrasts}}
          <!--  -->
          {{py: contrasts = run_content.all_contrasts.items()}}
          <!--  -->
          {{for contrast_name, contrast_plot in contrasts}}
          <div class="scroll-y">
            {{py: is_bytes = not contrast_plot.endswith('.png')}}
            <img class="pure-img" src="{{if is_bytes}}data:image/png;base64,{{endif}}{{contrast_plot}}"
              title="Plot of the contrast {{contrast_name}} (run {{ i_run }})."
              alt="Plot of the contrast {{contrast_name}} (run {{ i_run }})." style="min-width: 600px" />
          </div>
          {{endfor}}
          <!--  -->
          {{else}}
            <p>No contrast was provided.</p>
            {{endif}}
        </div>

      </section>

    </div>

    {{endfor}}

  </div>

  <section id="mask-{{unique_id}}">
    <h2>Mask</h2>
    {{if mask_plot}}
    <div class="scroll-y">
      <img
        class="pure-img"
        src="data:image/png;base64,{{mask_plot}}"
        alt="Mask image"
        title="Mask image"
        style="min-width: 600px"
      />
    </div>
    {{else}}
    <p>No mask was provided.</p>
    {{endif}}
    {{if n_elements }}
    <div class="pure-u-1 pure-u-md-3-3">
      <p>
        The mask includes {{ n_elements }} voxels ({{ coverage }} %) of the image.
      </p>
    </div>
    {{endif}}
  </section>

  <section id="statistical-maps-{{unique_id}}">
    <h2>Statistical Maps</h2>
    <div class="pure-g">
      {{if results}}
      <!--  -->
      {{py: results = results.items()}}
      <!--  -->
      {{for contrast_name, details in results}}
      <!--  -->

      <div class="pure-u-1">
        <h3>{{contrast_name}}</h3>

        <div class="d-flex flex-column">
          {{if details.stat_map_img }}
            <div class="scroll-y">
              <img
                class="pure-img"
                src="data:image/png;base64,{{ details.stat_map_img }}"
                alt="Stat map plot for the contrast: {{contrast_name}}"
                title="Stat map plot for the contrast: {{contrast_name}}"
                style="min-width: 600px"
              />
            </div>
          {{else}}
            <p style="text-align: center; font-size: 200%; color: grey">No suprathreshold cluster</p>
          {{endif}}

          <details>
            <summary class="pure-button button-small contrast-button">
              Cluster Table
            </summary>
            {{if details.cluster_table_details }}
            <!--  -->
            {{ details.cluster_table_details|html }}
            <!--  -->
            {{else}}
            <p>No cluster table parameter provided</p>
            {{endif}}
            <!--  -->
            {{if details.cluster_table }}
              {{ details.cluster_table|html }}
            {{else}}
              <p style="text-align: center; font-size: 200%; color: grey">No suprathreshold cluster</p>

            {{endif}}
          </details>
        </div>
      </div>
      {{endfor}}
      {{else}}
      <div class="d-flex flex-wrap justify-content-evenly">
        <p style="letter-spacing: normal">No statistical map was provided.</p>
      </div>

      {{endif}}
    </div>
  </section>

  <section id="about-{{unique_id}}" style="text-align: left">
    <h2>About</h2>
    <ul>
      <li>Date preprocessed: <time>{{date}}</time></li>
    </ul>
  </section>
</div>

{{if n_runs > 1}}
<script>
  {{ js_carousel | html }}
  document.addEventListener("DOMContentLoaded", function () {
    new Carousel("{{unique_id}}", {{ displayed_runs }}, false);
}
);
</script>
{{endif}}

{{enddef}}
