<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.coreg %}
            <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.coreg %}
        <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_filter_cov }}" alt="" style='max-width: 100%'/>
                <img src="{{ data.plt_filter_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: 70%; margin: auto">
                <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('coregistration')) {
        iframe = document.getElementById(figTag.concat('_iframe'));
        iframe.src = iframe.getAttribute('data-src');
        currentButton = 0;
    }
    if (figTag.includes('beamforming')) {
        currentButton = 1;
    }
    if (figTag.includes('parcellation')) {
        currentButton = 2;
    }
}

</script>
