{% extends "_layout.html" %}

{% import 'macros/_account_macros.html' as account_macros with context %}
{% import '_tree_table.html' as tree_table with context %}
{% import '_journal_table.html' as journal_table with context %}

{% set page_title = account_macros.account_name_header(account_name) %}
{% set short_title = account_name %}

{% set journal = subreport == 'journal' %}

{% block content %}
<div class="droptarget" data-account-name="{{ account_name }}">
  {{ charts.account_balance(account_name) }}
  {{ charts.interval_totals(g.interval, account_name, label=_('Changes')) }}

  {% if not journal %}
  {{ charts.hierarchy(account_name) }}
  {% endif %}

  <div class="headerline">
    <h3>{% if not journal %}<a href="{{ url_for('account', name=account_name) }}" title="{{ _('Journal of all entries for this Account and Sub-Accounts') }}">{{ _('Account Journal') }}</a>{% else %}{{ _('Account Journal') }}{% endif %}</h3>
    <h3>{% if subreport != 'changes' %}<a href="{{ url_for('account', name=account_name, subreport='changes') }}">{{ _('Changes') }} ({{ g.interval.label|lower }})</a>{% else %}{{ _('Changes') }} ({{ g.interval.label|lower }}){% endif %}</h3>
    <h3>{% if subreport != 'balances' %}<a href="{{ url_for('account', name=account_name, subreport='balances') }}">{{ _('Balances') }} ({{ g.interval.label|lower }})</a>{% else %}{{ _('Balances') }} ({{ g.interval.label|lower }}){% endif %}</h3>
  </div>

  {% if journal %}
  {% set entries = ledger.account_journal(account_name, with_journal_children=ledger.fava_options['account-journal-include-children']) %}
  {{ journal_table.journal_table(entries, show_change_and_balance=True) }}
  {% else %}
  {% set accumulate = subreport == 'balances' %}
  {% set interval_balances, dates = ledger.interval_balances(g.interval, account_name, accumulate) %}
  {% if interval_balances %}
  {% for begin_date, end_date in dates[:3] %}
  {{ charts.hierarchy(account_name, begin_date, end_date, label=begin_date|format_date) }}
  {% endfor %}
  {{ tree_table.account_tree(account_name, interval_balances, dates, accumulate) }}
  {% endif %}
  {% endif %}
</div>
{% endblock %}
