<div class="fif" style='max-width: 90%; margin: auto; margin-bottom: 40px; background: #f6f6f6; box-shadow: 10px 10px 5px grey; padding: 25px 25px 25px 0px;' id="{{ data.fif_id }}">

  <div>
    <h3>{{ data.fif_id }} &ensp; ({{ data.num }} of {{ data.total }})</h3>
  </div>

  <div class="flex-container" style="display: flex">

  <div class="flex-child" style="flex: 1">
    <div class="tab" style="display: grid">
        {% if data.compute_surfaces %}
            <button class="button1" onclick="openTab(event, '{{ data.fif_id }}_compute_surfaces', this.id)" style="border-top-style: solid">Surfaces</button>
        {% endif %}
        {% if data.coregister %}
            <button class="button1" onclick="openTab(event, '{{ data.fif_id }}_coregistration', this.id)" style="border-top-style: solid">Coregistration</button>
        {% endif %}
        {% if data.beamform or data.beamform_and_parcellate %}
            <button class="button1" onclick="openTab(event, '{{ data.fif_id }}_beamforming', this.id)" style="border-top-style: solid">Beamforming</button>
        {% endif %}
        {% if data.beamform_and_parcellate %}
            <button class="button1" onclick="openTab(event, '{{ data.fif_id }}_parcellation', this.id)" style="border-top-style: solid">Parcellation</button>
        {% endif %}
    </div>
  </div>

  <div class="flex-child" style="flex: 5; padding-left: 25px">

    {% if data.compute_surfaces %}
        <div class="tabpage" style='width: 100%' id={{ data.fif_id }}_compute_surfaces>
            <h3>Surfaces</h3>
            <div>Inskull</div>
            <div style="width: 70%; margin: auto">
                <img src="{{ data.plt_surfaces_inskull }}" alt="" style='max-width: 100%'/>
            </div>
            <br>
            <div>Outskull</div>
            <div style="width: 70%; margin: auto">
                <img src="{{ data.plt_surfaces_outskull }}" alt="" style='max-width: 100%'/>
            </div>
            <br>
            <div>Outskin</div>
            <div style="width: 70%; margin: auto">
                <img src="{{ data.plt_surfaces_outskin }}" alt="" style='max-width: 100%'/>
            </div>
            {% if data.plt_surfaces_outskin_plus_nose %}
                <br>
                <div>Outskin plus nose</div>
                <div style="width: 70%; margin: auto">
                    <img src="{{ data.plt_surfaces_outskin_plus_nose }}" alt="" style='max-width: 100%'/>
                </div>
            {% endif %}
        </div>
    {% endif %}

    {% if data.coregister %}
        <div class="tabpage" style='width: 100%' id={{ data.fif_id }}_coregistration>
            <h3>Coregistration</h3>
            <iframe data-src="{{ data.plt_coreg }}" width="525" height="525" id="{{ data.fif_id}}_coregistration_iframe"></iframe>
            <div>
                Red dots are headshape points.</br>
                Green blob is the scalp extracted from the structural MRI.</br>
                Yellow diamonds are fiducials extracted from the structural MRI.</br>
                Pink dots are polhemus fiducials.</br></br>
                <b>We want the headshape points to lie on/near th scalp and the fiducials to align.</b></br></br>
                Click and drag to rotate and scroll to zoom.
            </div>
        </div>
    {% endif %}

    {% if data.beamform or data.beamform_and_parcellate %}
        <div class="tabpage" style='width: 100%; display: none' id={{ data.fif_id }}_beamforming>
            <h3>Beamforming</h3>
            <div>LCMV Filter</div>
            <div style="width: 70%; margin: auto">
                <img src="{{ data.plt_filters_cov }}" alt="" style='max-width: 100%'/>
                <img src="{{ data.plt_filters_svd }}" alt="" style='max-width: 100%'/>
            </div>
        </div>
    {% endif %}

    {% if data.beamform_and_parcellate %}
        <div class="tabpage" style='width: 100%; display: none' id={{ data.fif_id }}_parcellation>
            <h3>Parcellation</h3>
            <div style="width: 50%; float: left">
                <div>Power Spectral Density</div>
                <img src="{{ data.plt_parc_psd }}" alt="" style='max-width: 100%'/>
            </div>
            <div style="width: 50%; float: right">
                <div>Correlation</div>
                <img src="{{ data.plt_parc_corr }}" alt="" style='max-width: 100%'/>
            </div>
        </div>
    {% endif %}

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

<script>

function openTab(event, figTag, button) {
    // Get all elements with class="tabpage" and hide them
    tabpage = document.getElementsByClassName("tabpage");
    for (i = 0; i < tabpage.length; i++) {
        tabpage[i].style.display = "none";
    }
    // Show the current tab
    document.getElementById(figTag).style.display = "block";
    if (figTag.includes('compute_surfaces')) {
        currentButton = 0;
    }
    if (figTag.includes('coregistration')) {
        iframe = document.getElementById(figTag.concat('_iframe'));
        iframe.src = iframe.getAttribute('data-src');
        currentButton = 1;
    }
    if (figTag.includes('beamforming')) {
        currentButton = 2;
    }
    if (figTag.includes('parcellation')) {
        currentButton = 3;
    }
}

</script>
