{% extends 'core/page.html' %}
{% load i18n %}
{% load core_tags %}

{% block content %}

<div class="container">
    <div class="row">
        <form method="post">
            {% csrf_token %}

            <input type="hidden" name="method" value="{{ method }}" />
            <input type="hidden" name="source" value="{{ source }}" />

            <div class="page col-md-9">
                {% if not current_project %}
                <h1>
                    {% blocktrans %}Create project from {{ source_title }}{% endblocktrans %}
                </h1>

                    {% if source_project %}
                    <table class="table table-bordered table-break-word">
                        <tbody>
                            <tr>
                                <td style="width: 20%">{% trans 'Title' %}</td><td>{{ source_project.title }}</td>
                            </tr>
                            <tr>
                                <td style="width: 20%">{% trans 'Description' %}</td><td>{{ source_project.description }}</td>
                            </tr>
                            <tr>
                                <td style="width: 20%">{% trans 'Catalog' %}</td><td>{{ source_project.catalog.title }}</td>
                            </tr>
                            <tr>
                                <td style="width: 20%">{% trans 'Created' %}</td><td>{{ source_project.created }}</td>
                            </tr>
                        </tbody>
                    </table>
                    {% endif %}

                {% else %}
                <h1>
                    {% blocktrans %}Import from {{ source_title }}{% endblocktrans %}
                </h1>
                {% endif %}

                {% if values %}
                <table class="table table-bordered table-break-word">
                    <thead>
                        <tr>
                            <th>{% trans 'Question' %}</th>
                            {% if current_project %}
                            <th>{% trans 'Current answer' %}</th>
                            {% endif %}
                            <th>{% trans 'Imported answer' %}</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for value in values %}
                        <tr>
                            <td>
                                {% if value.question %}
                                {{ value.question.text }}
                                {% elif value.attribute.key == 'id' %}
                                <i>{% trans 'Title of a set.' %}</i>
                                {% else %}
                                <i>{% trans 'Not available in this catalog.' %}</i>
                                {% endif %}
                            </td>
                            {% if current_project %}
                            <td style="width: 30%">{{ value.current.value_and_unit }}</td>
                            <td style="width: 30%">{% firstof value.value_and_unit value.file_import.name %}</td>
                            {% else %}
                            <td style="width: 60%">{% firstof value.value_and_unit value.file_import.name %}</td>
                            {% endif %}
                            <td style="width: 1%" class="import-checkbox">
                                {% if value.attribute.uri %}
                                <input class="import-checkbox" type="checkbox"
                                    name="{{ value.attribute.uri }}[{{value.set_prefix}}][{{value.set_index}}][{{value.collection_index}}]" checked />
                                {% else %}
                                <i class="fa fa-ban" title="{% trans 'This Answer cannot be imported.' %}"></i>
                                {% endif %}
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
                {% endif %}

                {% if snapshots %}
                {% for snapshot in snapshots %}

                <h2>{% trans 'Snapshot' %}: {{ snapshot.title }}</h2>

                <table class="table table-bordered table-break-word">
                    <tbody>
                        <tr>
                            <td style="width: 20%">{% trans 'Title' %}</td><td>{{ snapshot.title }}</td>
                        </tr>
                        <tr>
                            <td style="width: 20%">{% trans 'Description' %}</td><td>{{ snapshot.description }}</td>
                        </tr>
                        <tr>
                            <td style="width: 20%">{% trans 'Created' %}</td><td>{{ snapshot.created }}</td>
                        </tr>
                    </tbody>
                </table>

                {% if snapshot.snapshot_values %}
                <table class="table table-bordered table-break-word">
                    <thead>
                        <tr>
                            <th>Question</th>
                            {% if current_project %}
                            <th>{% trans 'Current answer' %}</th>
                            {% endif %}
                            <th>{% trans 'Imported answer' %}</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for value in snapshot.snapshot_values %}
                        <tr>
                            <td>
                                {% if value.question %}
                                {{ value.question.text }}
                                {% elif value.attribute.key == 'id' %}
                                <i>{% trans 'Title of a set.' %}</i>
                                {% else %}
                                <i>{% trans 'Not available in this catalog.' %}</i>
                                {% endif %}
                            </td>
                            {% if current_project %}
                            <td style="width: 30%">{{ value.current.value_and_unit }}</td>
                            <td style="width: 30%">{% firstof value.value_and_unit value.file_import.name %}</td>
                            {% else %}
                            <td style="width: 60%">{% firstof value.value_and_unit value.file_import.name %}</td>
                            {% endif %}
                            <td style="width: 1%" class="import-checkbox">
                                {% if value.attribute.uri %}
                                <input type="checkbox" checked
                                    name="{{ value.attribute.uri }}[{{snapshot.snapshot_index}}][{{value.set_prefix}}][{{value.set_index}}][{{value.collection_index}}]" />
                                {% else %}
                                <i class="fa fa-ban" title="{% trans 'This Answer cannot be imported.' %}"></i>
                                {% endif %}
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
                {% endif %}
                {% endfor %}
                {% endif %}
            </div>
            <div class="sidebar col-md-3">
                {% if current_project %}
                <input type="submit" value="{% trans 'Import values' %}" class="btn btn-success btn-import"></submit>
                {% else %}
                <input type="submit" value="{% trans 'Import project' %}" class="btn btn-success btn-import"></submit>
                {% endif %}
            </div>
        </form>
    </div>
</div>

{% endblock %}
