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

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

{% block content %}

    <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">{{ 'accounts'|_ }}</h3>
                </div>
                <div class="box-body table-responsive no-padding" id="accountsHolder">
                </div>
                {# loading indicator #}
                <div class="overlay">
                    <span class="fa fa-refresh fa-spin"></span>
                </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">{{ 'budgets'|_ }}</h3>
                </div>
                <div class="box-body table-responsive no-padding" id="budgetsHolder">
                </div>
                {# loading indicator #}
                <div class="overlay">
                    <span class="fa fa-refresh fa-spin"></span>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'account_per_budget'|_ }}</h3>
                </div>
                <div class="box-body table-responsive no-padding" id="accountPerbudgetHolder">
                </div>
                {# loading indicator #}
                <div class="overlay">
                    <span class="fa fa-refresh fa-spin"></span>
                </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_budget'|_ }}</h3>
                </div>
                <div class="box-body">
                    <div style="width:100%;margin:0 auto;">
                        <canvas id="budgets-out-pie-chart" style="width:100%;height:250px;" height="250"></canvas>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-6 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 style="width:100%;margin:0 auto;">
                        <canvas id="categories-out-pie-chart" style="width:100%;height:250px;" 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_source_account'|_ }}</h3>
                </div>
                <div class="box-body">
                    <div style="width:100%;margin:0 auto;">
                        <canvas id="source-accounts-pie-chart" style="width:100%;height:250px;" height="250"></canvas>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-6 col-md-6">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'expense_per_destination_account'|_ }}</h3>
                </div>
                <div class="box-body">
                    <div style="width:100%;margin:0 auto;">
                        <canvas id="dest-accounts-pie-chart" style="width:100%;height:250px;" height="250"></canvas>
                    </div>
                </div>
            </div>
        </div>
    </div>

    {% for budget in budgets %}
        <div class="row">
            <div class="col-lg-12">
                <div class="box main_budget_chart">
                    <div class="box-header with-border">
                        <h3 class="box-title">{{ 'expenses'|_ }} ({{ budget.name }})</h3>
                    </div>
                    <div class="box-body">
                        <canvas class="main_budget_canvas" data-url="{{ route('chart.budget.main', [accountIds, budget.id, start.format('Ymd'), end.format('Ymd')]) }}" id="in-out-chart-{{ budget.id }}" style="width:100%;height:400px;" height="400" width="100%"></canvas>
                    </div>
                </div>
            </div>
        </div>
    {% endfor %}
    <div class="row">
        <div class="col-lg-6">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'average_spending_per_destination'|_ }}</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">{{ 'expenses'|_ }} ({{ trans('firefly.topX', {number: listLength}) }})</h3>
                </div>
                <div class="box-body table-responsive no-padding" id="topExpensesHolder">
                </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 budgetIds = '{{ budgetIds }}';

        // html block URL's:
        var accountsUrl = '{{ route('report-data.budget.accounts', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var budgetsUrl = '{{ route('report-data.budget.budgets', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var accountPerBudgetUrl = '{{ route('report-data.budget.account-per-budget', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var avgExpensesUrl = '{{ route('report-data.budget.avg-expenses', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var topExpensesUrl = '{{ route('report-data.budget.top-expenses', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd')]) }}';

        var budgetExpenseUrl = '{{ route('chart.budget.budget-expense', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var categoryExpenseUrl = '{{ route('chart.budget.category-expense', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var sourceExpenseUrl = '{{ route('chart.budget.source-account-expense', [accountIds, budgetIds, start.format('Ymd'), end.format('Ymd')]) }}';
        var destinationExpenseUrl = '{{ route('chart.budget.destination-account-expense', [accountIds, budgetIds, 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/budget/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 %}
