{% extends 'django_ledger/layouts/content_layout_1.html' %}
{% load i18n %}
{% load static %}

{% block view_content %}
    <div class="columns is-centered is-multiline">
        <div class="column is-12">
            {% include 'django_ledger/journal_entry/includes/card_journal_entry.html' with journal_entry=journal_entry %}
        </div>
        <div class="column is-12">
            <div class="box">

                <form action="{{ view.request.path }}" method="post">
                    {% csrf_token %}

                    <div class="columns is-multiline">
                        <div class="column is-12">
                            {{ txs_formset.non_form_errors }}
                            {{ txs_formset.management_form }}
                        </div>
                        <div class="column is-12">
                            <table class="table is-fullwidth is-narrow is-striped is-bordered">
                                <tr>
                                    <th>Account</th>
                                    <th>TX Type</th>
                                    <th>Amount</th>
                                    <th>Description</th>
                                    {% if txs_formset.can_delete %}
                                        <th>Delete</th>
                                    {% endif %}
                                </tr>
                                {% for f in txs_formset %}
                                    <tr>
                                        <td>
                                            {% for hidden_field in f.hidden_fields %}
                                                {{ hidden_field }}
                                            {% endfor %}
                                            {{ f.account }}
                                        </td>
                                        <td>{{ f.tx_type }}</td>
                                        <td>{{ f.amount }}</td>
                                        <td>{{ f.description }}</td>
                                        <td>
                                            {% if txs_formset.can_delete %}
                                                {{ f.DELETE }}
                                            {% endif %}
                                        </td>
                                    </tr>
                                {% endfor %}

                            </table>
                        </div>
                        <div class="column is-12 has-text-centered">
                            <button class="button is-primary is-outlined">
                                {% trans 'Save' %}
                            </button>
                            <a class="button is-dark"
                               href="{{ journal_entry.get_journal_entry_list_url }}?next={{ request.path }}">
                                {% trans 'Done' %}
                            </a>
                            {% if journal_entry.can_lock %}
                                <a class="button is-dark is-danger"
                                   href="{{ journal_entry.get_action_lock_url }}?next={{ request.path }}">
                                    {% trans 'Lock' %}
                                </a>
                            {% endif %}
                            {% if journal_entry.can_unlock %}
                                <a class="button is-dark is-warning"
                                   href="{{ journal_entry.get_action_unlock_url }}?next={{ request.path }}">
                                    {% trans 'UnLock' %}
                                </a>
                            {% endif %}
                            {% if journal_entry.can_post %}
                                <a class="button is-dark is-danger"
                                   href="{{ journal_entry.get_action_post_url }}?next={{ request.path }}">
                                    {% trans 'Post' %}
                                </a>
                            {% endif %}
                            {% if journal_entry.can_unpost %}
                                <a class="button is-warning"
                                   href="{{ journal_entry.get_action_unpost_url }}?next={{ request.path }}">
                                    {% trans 'UnPost' %}
                                </a>
                            {% endif %}
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
{% endblock %}