{%- extends 'nbconvert/templates/reveal/index.html.j2' -%}
{% import "log.macro.html.j2" as log %}
{% import "spinner.macro.html.j2" as spinner %}
{% from 'voila_setup.macro.html.j2' import voila_setup_helper_functions, voila_setup with context %}

{%- block html_head_js -%}
  {%- block html_head_js_requirejs -%}
  {{ resources.include_js("static/require.min.js") }}
  {%- endblock html_head_js_requirejs -%}
  {%- block html_head_js_logs -%}
    {{ log.js() }}
  {%- endblock html_head_js_logs -%}
  {%- block html_head_js_jquery -%}
    <script src="{{ resources.jquery_url }}"></script>
  {%- endblock html_head_js_jquery -%}

  {% block notebook_execute %}

    {# Copy so we do not modify the page_config with updates. #}
    {% set page_config_full = page_config.copy() %}

    {%- set kernel_id = kernel_start(nb) -%}

    {# Set a dummy variable - we just want the side effect of the update. #}
    {% set _ = page_config_full.update(baseUrl=resources.base_url, kernelId=kernel_id) %}

    <script id="jupyter-config-data" type="application/json">
      {{ page_config_full | tojson }}
    </script>
    {# from this point on, nb.cells contains output of the executed cells #}
    {% do notebook_execute(nb, kernel_id) %}
  {%- endblock notebook_execute -%}

{%- endblock html_head_js -%}

{%- block notebook_css -%}
  {{ resources.include_css("static/materialcolors.css") }}
  {{ resources.include_css("static/labvariables.css") }}
  {% if frontend == "voila" %}
    {{ resources.include_js("static/voila-style.js") }}
  {% endif %}

  {{ spinner.css() }}

  <style>
    /*Hide empty cells*/
    .jp-mod-noOutputs.jp-mod-noInput {
      display: none;
    }
    #rendered_cells {
      padding: 0px!important
    }
  </style>

  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@^5/css/all.min.css" type="text/css" />
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@^5/css/v4-shims.min.css" type="text/css" />

  {{ super() }}
{%- endblock notebook_css -%}

{%- block html_head_js_mathjax -%}
{# remove mathjax CDN #}
{%- endblock html_head_js_mathjax -%}

{% block body_header %}
{% if resources.theme == 'dark' %}
<body class="jp-Notebook" data-base-url="{{resources.base_url}}voila/" data-jp-theme-light="false" data-jp-theme-name="JupyterLab Dark">
{% else %}
<body class="jp-Notebook" data-base-url="{{resources.base_url}}voila/" data-jp-theme-light="true" data-jp-theme-name="JupyterLab Light">
{% endif %}
{{ spinner.html() }}
{{ voila_setup_helper_functions() }}
<div id="rendered_cells" style="display: none; height:100vh">
<div class="reveal">
<div class="slides">
{% endblock body_header %}

{% block data_priority scoped %}
{% if output %}
  <script type="application/vnd.voila.cell-output+json">
    {{ output | tojson }}
  </script>
{% endif %}
{% endblock data_priority %}

{%- block codecell -%}
  <div cell-index="{{cellloop.index}}">
    {{ super() }}
  </div>
{%- endblock codecell -%}

{%- block markdowncell -%}
  <div cell-index="{{cellloop.index}}">
    {{ super() }}
  </div>
{%- endblock markdowncell -%}

{%- block rawcell -%}
  <div cell-index="{{cellloop.index}}">
    {{ super() }}
  </div>
{%- endblock rawcell -%}

{%- block body_loop -%}
  {%- for cell in nb.cells -%}
    {% set cellloop = loop %}
      {%- block any_cell scoped -%}
          {{ super() }}
      {%- endblock any_cell -%}
  {%- endfor -%}
{%- endblock body_loop -%}

{%- block body_footer -%}
</div>
</div>
</div>
</body>
<script type="text/javascript">
  window.voila_finish();
</script>
{%- endblock body_footer -%}

{% block footer_js %}
  {{ voila_setup(resources.base_url, resources.labextensions) }}
  {{ super() }}
{% endblock footer_js %}
