{% 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>
        <td id='acqu_date'>{{ image.getAcquisitionDate|date:"Y-m-d H:i:s" }}</td> <!-- TODO: Insight is m/d/yy h:min AM/PM -->
    </tr>
    {% endif %}
    <tr>
        <th>Import Date:</th>
        <td id='import_date'>{{ image.creationEventDate|date:"Y-m-d H:i:s" }}</td>
    </tr>
    <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 -->
                        <span class="originalButtons">
                            <button name="save" type="submit" value="save" title="Save channel names">Save</button>
                            <button name="apply" title="Save and apply to all images">Apply to All</button>
                        </span>
                        <span class="confirmButtons" style="display:none">
                            <div>Update channel names for all images 
                                in the <span class="ptype"></span>? <br />This cannot be undone.</div>
                            <button name="confirm_apply" type="submit" value="apply" title="Save and apply to all Images">Continue</button>
                        </span>
                        <button type="reset" name="cancel" title="Cancel">Cancel</button>
                    </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>