{% extends './layout/default' %}

{% block breadcrumbs %}
    {{ Breadcrumbs.render(Route.getCurrentRoute.getName, accountIds, doubleIds, start, end) }}
{% endblock %}

{% block content %}

    <div class="row">
        <div class="col-lg-6 col-md-12 col-sm-12 col-xs-12">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'in_out_accounts'|_ }}</h3>
                </div>
                <div class="box-body table-responsive no-padding" id="opsAccounts">
                    {# loading indicator #}
                    <div class="overlay">
                        <span class="fa fa-refresh fa-spin"></span>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-lg-6 col-md-12 col-sm-12 col-xs-12">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'in_out_accounts_per_asset'|_ }}</h3>
                </div>
                <div class="box-body table-responsive no-padding" id="opsAccountsAsset">
                    {# loading indicator #}
                    <div class="overlay">
                        <span class="fa fa-refresh fa-spin"></span>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-4 col-md-6">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'expense_per_category'|_ }}</h3>
                </div>
                <div class="box-body">
                    <div class="center-chart">
                        <canvas id="category-out-pie-chart" class="medium-chart" height="250"></canvas>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-4 col-md-6">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'income_per_category'|_ }}</h3>
                </div>
                <div class="box-body">
                    <div class="center-chart">
                        <canvas id="category-in-pie-chart" class="medium-chart" height="250"></canvas>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-4 col-md-6">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'expense_per_budget'|_ }}</h3>
                </div>
                <div class="box-body">
                    <div class="center-chart">
                        <canvas id="budgets-out-pie-chart" class="medium-chart" height="250"></canvas>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-6 col-md-6">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'expense_per_tag'|_ }}</h3>
                </div>
                <div class="box-body">
                    <div class="center-chart">
                        <canvas id="tag-out-pie-chart" class="medium-chart" height="250"></canvas>
                    </div>
                </div>
                <div class="box-footer">
                    <p class="text-info">
                        <em>{{ 'double_report_expenses_charted_once'|_ }}</em>
                    </p>
                </div>
            </div>
        </div>
        <div class="col-lg-6 col-md-6">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'income_per_tag'|_ }}</h3>
                </div>
                <div class="box-body">
                    <div class="center-chart">
                        <canvas id="tag-in-pie-chart" class="medium-chart" height="250"></canvas>
                    </div>
                </div>
                <div class="box-footer">
                    <p class="text-info">
                        <em>{{ 'double_report_expenses_charted_once'|_ }}</em>
                    </p>
                </div>
            </div>
        </div>
    </div>


    {% for account in doubles %}
        <div class="row">
            <div class="col-lg-12">
                <div class="box" id="incomeAndExpensesChart">
                    <div class="box-header with-border">
                        <h3 class="box-title">{{ 'income_and_expenses'|_ }} ({{ account.name }}) {% if account.iban %}({{ account.iban }}){% endif %}</h3>
                    </div>
                    <div class="box-body">
                        <canvas class="main_double_canvas"
                                data-url="{{ route('chart.double.main', [accountIds, account.id, start.format('Ymd'), end.format('Ymd')]) }}"
                                id="in-out-chart-{{ account.id }}" class="wide-chart" height="400" width="100%"></canvas>
                    </div>
                </div>
            </div>
        </div>
    {% endfor %}

    <div class="row">
        <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'expenses'|_ }} ({{ trans('firefly.topX', {number: listLength}) }})</h3>
                </div>
                <div class="box-body table-responsive no-padding" id="topExpensesHolder">
                    {# loading indicator #}
                    <div class="overlay">
                        <span class="fa fa-refresh fa-spin"></span>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'income'|_ }} ({{ trans('firefly.topX', {number: listLength}) }})</h3>
                </div>
                <div class="box-body table-responsive no-padding" id="topIncomeHolder">
                    {# loading indicator #}
                    <div class="overlay">
                        <span class="fa fa-refresh fa-spin"></span>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-6">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'average_spending_per_source'|_ }}</h3>
                </div>
                <div class="box-body table-responsive no-padding" id="avgExpensesHolder">
                </div>
                {# loading indicator #}
                <div class="overlay">
                    <span class="fa fa-refresh fa-spin"></span>
                </div>
            </div>
        </div>
        <div class="col-lg-6">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'average_earning_per_destination'|_ }}</h3>
                </div>
                <div class="box-body table-responsive no-padding" id="avgIncomeHolder">
                </div>
                {# loading indicator #}
                <div class="overlay">
                    <span class="fa fa-refresh fa-spin"></span>
                </div>
            </div>
        </div>
    </div>

{% endblock %}

{% block scripts %}
    <script type="text/javascript" src="v1/js/lib/Chart.bundle.min.js?v={{ FF_BUILD_TIME }}" nonce="{{ JS_NONCE }}"></script>
    <script type="text/javascript" src="v1/js/ff/charts.defaults.js?v={{ FF_BUILD_TIME }}" nonce="{{ JS_NONCE }}"></script>
    <script type="text/javascript" src="v1/js/ff/charts.js?v={{ FF_BUILD_TIME }}" nonce="{{ JS_NONCE }}"></script>
    <script type="text/javascript" src="v1/js/lib/bootstrap-sortable.js?v={{ FF_BUILD_TIME }}" nonce="{{ JS_NONCE }}"></script>

    <script type="text/javascript" nonce="{{ JS_NONCE }}">
        // to report another URL:
        var startDate = '{{ start.format('Ymd') }}';
        var endDate = '{{ end.format('Ymd') }}';
        var accountIds = '{{ accountIds }}';
        var doubleIds = '{{ doubleIds }}';


        // html blocks.
        var opsAccountsUrl = '{{ route('report-data.double.operations', [accountIds, doubleIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var opsAccountsAssetUrl = '{{ route('report-data.double.ops-asset', [accountIds, doubleIds, start.format('Ymd'), end.format('Ymd')]) }}';

        // pie charts:
        var categoryOutUrl = '{{ route('chart.double.category-expense', [accountIds, doubleIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var categoryInUrl = '{{ route('chart.double.category-income', [accountIds, doubleIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var budgetsOutUrl = '{{ route('chart.double.budget-expense', [accountIds, doubleIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var tagOutUrl = '{{ route('chart.double.tag-expense', [accountIds, doubleIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var tagInUrl = '{{ route('chart.double.tag-income', [accountIds, doubleIds, start.format('Ymd'), end.format('Ymd')]) }}';

        var avgExpensesUrl = '{{ route('report-data.double.avg-expenses', [accountIds, doubleIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var topExpensesUrl = '{{ route('report-data.double.top-expenses', [accountIds, doubleIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var avgIncomeUrl = '{{ route('report-data.double.avg-income', [accountIds, doubleIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var topIncomeUrl = '{{ route('report-data.double.top-income', [accountIds, doubleIds, start.format('Ymd'), end.format('Ymd')]) }}';

    </script>
    <script type="text/javascript" src="v1/js/ff/reports/all.js?v={{ FF_BUILD_TIME }}" nonce="{{ JS_NONCE }}"></script>
    <script type="text/javascript" src="v1/js/ff/reports/double/month.js?v={{ FF_BUILD_TIME }}" nonce="{{ JS_NONCE }}"></script>

{% endblock %}

{% block styles %}
    <link rel="stylesheet" href="v1/css/bootstrap-sortable.css?v={{ FF_BUILD_TIME }}" type="text/css" media="all" nonce="{{ JS_NONCE }}">
{% endblock %}
