{% load common_filters %}
{% comment %}
<!--
  Copyright (C) 2012-2014 University of Dundee & Open Microscopy Environment.
  All rights reserved.

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU Affero General Public License as
  published by the Free Software Foundation, either version 3 of the
  License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU Affero General Public License for more details.

  You should have received a copy of the GNU Affero General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->
{% endcomment %}


<table class="core_metadata">
    {% if image.getAcquisitionDate %}
    <tr>
        <th>Acquisition Date:</th>
        <!-- acqu_date and import_date formatted by OME.formatDate() see metadata_general.html -->
        <td id='acqu_date' data-isodate='{{ image.getAcquisitionDate|date:"r" }}'></td>
    </tr>
    {% endif %}
    <tr>
        <th>Import Date:</th>
        <td id='import_date' data-isodate='{{ image.creationEventDate|date:"r" }}'></td>
    </tr>
    {% if image.archived %}
    <tr>
        <th>Archived:</th>
        <td id='is_archived'>{{ image.archived }}</td>
    </tr>
    {% endif %}
    <tr>
        <th>Dimensions (XY):</th>
        <td id='dims_xy'>{{ image.getSizeX }} x {{ image.getSizeY }}</td>
    </tr>
    <tr>
        <th>Pixels Type:</th>
        <td id='pixels_type'>{{ image.getPixelsType }}</td>
    </tr>
    <tr>
        {% with psX=image.getPixelSizeXWithUnits psY=image.getPixelSizeYWithUnits psZ=image.getPixelSizeZWithUnits %}
            {% with vX=psX.0 vY=psY.0 vZ=psZ.0 uX=psX.1 uY=psY.1 uZ=psZ.1 %}
        <th>Pixels Size (XYZ){% if uX == uY and uX == uZ %} ({{ uX }}){% endif %}:</th>
        <td id='pixels_size'>
            <div class='tooltip'>
                {% if vX or vY or vZ %}
                    {{ vX|floatformat:2|default:'-' }} {% if vX %}{% if uX != uY or uX != uZ %}({{ uX }}){% endif %}{% endif %}
                    x {{ vY|floatformat:2|default:'-' }} {% if vY %}{% if uX != uY or uX != uZ %}({{ uY }}){% endif %}{% endif %}
                    x {{ vZ|floatformat:2|default:'-' }} {% if vZ %}{% if uX != uY or uX != uZ %}({{ uZ }}){% endif %}{% endif %}
                {% else %}-{% endif %}
            </div>
            <span class="tooltip_html" style='display:none'>
                {% if vX or vY or vZ %}
                    {{ vX|default:'-' }} {% if vX %}({{ uX }}){% endif %}
                    x {{ vY|default:'-' }} {% if vY %}({{ uY }}){% endif %}
                    x {{ vZ|default:'-' }} {% if vZ %}({{ uZ }}){% endif %}
                {% else %}
                Physical pixel sizes not available
                {% endif %}
            </span>
        </td>
            {% endwith %}
        {% endwith %}
    </tr>
    <tr>
        <th>Z-sections/Timepoints:</th>
        <td id='dims_zt'>{{ image.getSizeZ }} x {{ image.getSizeT }}</td>
    </tr>
    <tr>
        <th>Channels:</th>
        <td id='channel_names'>
            <div>
                {% with channelLabels=image.getChannelLabels %}
                {% if channelLabels %}
                    <div id="channel_names_display">
                    {% for label in channelLabels %}{% if not forloop.first %}, {% endif %}<span>{{ label|escape }}</span>{% endfor %}
                    </div>
                    <!-- form for editing channel names (initially hidden)-->
                    <form action="{% url 'edit_channel_names' image.id %}" method="POST" id="channel_names_edit" style="display:none">
                        {% for label in channelLabels %}
                            <input type="text" name="channel{{ forloop.counter0 }}" value="{{ label }}" size=20/><br/>
                        {% endfor %}
                        <!-- hidden input for 'apply to dataset' options -->
                        <input type="text" name="parentId" size=5 style="display:none" />
                        <!-- buttons -->
                        <div class="buttons">
                            <button class="originalButtons" name="save" type="submit" value="save" title="Save channel names">
                                Save
                            </button>
                            <button class="originalButtons" name="apply" title="Save and apply to all images">
                                Apply to All
                            </button>
                            <div class="confirmButtons">Update channel names for all images 
                                in the <span class="ptype"></span>? <br />This cannot be undone.</div>
                            <button class="confirmButtons" name="confirm_apply" type="submit" value="apply" title="Save and apply to all Images">
                                Continue
                            </button>
                            <button type="reset" name="cancel" title="Cancel">
                                Cancel
                            </button>
                        </div>
                    </form>
                    {% if image.canEdit %}
                        <button id="editChannelNames" class="btn silver btn_edit" 
                            title="Edit Channel Names">
                            <span></span>
                        </button>
                    {% endif %}
                {% else %}
                    <span class="error">No channel specified</span>
                {% endif %}
                {% endwith %}
            </div>
        </td>
    </tr>
    <tr>
        <th>ROI Count:</th>
        <td>{{ image.getROICount }}</td>
    </tr>
</table>