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

{% block breadcrumbs %}
    {{ Breadcrumbs.render }}
{% endblock %}
{% block content %}
    {% include 'partials.boxes' %}
    <div class="row">
        <div class="col-lg-8 col-md-12 col-sm-12">
            {# ACCOUNTS #}
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title"><a href="{{ route('accounts.index',['asset']) }}"
                                             title="{{ 'yourAccounts'|_ }}">{{ 'yourAccounts'|_ }}</a></h3>
                </div>
                <div class="box-body">
                    <canvas id="accounts-chart" style="width:100%;height:400px;" height="400" width="100%"></canvas>
                </div>
                <div class="box-footer">
                    <a href="{{ route('accounts.index',['asset']) }}" class="btn btn-default button-sm"><span
                            class="fa fa-money"></span> {{ 'go_to_asset_accounts'|_ }}</a>
                </div>
            </div>

            {# BUDGETS #}
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title"><a href="{{ route('budgets.index') }}"
                                             title="{{ 'budgetsAndSpending'|_ }}">{{ 'budgetsAndSpending'|_ }}</a></h3>
                </div>
                <div class="box-body">
                    <canvas id="budgets-chart" style="width:100%;height:400px;" height="400" width="100%"></canvas>
                </div>
                <div class="box-footer">
                    <a href="{{ route('budgets.index') }}" class="btn btn-default button-sm">
                        <span class="fa fa-pie-chart"></span>
                        <span>{{ 'go_to_budgets'|_ }}</span>
                    </a>
                </div>
            </div>
            {# CATEGORIES #}
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title"><a href="{{ route('categories.index') }}"
                                             title="{{ 'categories'|_ }}">{{ 'categories'|_ }}</a></h3>

                </div>
                <div class="box-body">
                    <canvas id="categories-chart" style="width:100%;height:400px;" height="400" width="100%"></canvas>
                </div>
                <div class="box-footer">
                    <a href="{{ route('categories.index') }}" class="btn btn-default button-sm">
                        <span class="fa fa-bookmark"></span>
                        <span>{{ 'go_to_categories'|_ }}</span>
                    </a>
                </div>
            </div>
        </div>
        <div class="col-lg-4 col-md-6 col-sm-12">

            {# TRANSACTIONS #}
            <div id="all_transactions">
                {% for data in transactions %}
                    <div class="box">
                        <div class="box-header with-border">
                            <h3 class="box-title"><a
                                    href="{{ route('accounts.show', [data.account.id]) }}">{{ data.account.name }}</a>
                            </h3>
                        </div>

                        {% if data.transactions|length > 0 %}
                            <div class="box-body no-padding">
                                {% include 'list.groups-tiny' with {'transactions': data.transactions,'account': data.account} %}
                            </div>
                        {% else %}
                            <div class="box-body">
                                <p>
                                    <em>
                                        {{ trans('firefly.no_transactions_account', {name: data.account.name}) }}
                                    </em>
                                </p>

                            </div>
                        {% endif %}

                        <div class="box-footer clearfix">
                            <!-- Single button -->
                            <div class="btn-group">
                                <a type="button" class="btn btn-success dropdown-toggle" data-toggle="dropdown"
                                   aria-haspopup="true" aria-expanded="false">
                                    {{ 'sidebar_frontpage_create'|_ }} <span class="caret"></span>
                                </a>
                                <ul class="dropdown-menu">
                                    <li>
                                        <a href="{{ route('transactions.create', ['withdrawal']) }}?source={{ data.account.id }}">{{ 'create_new_withdrawal'|_ }}</a>
                                    </li>
                                    <li>
                                        <a href="{{ route('transactions.create', ['deposit']) }}?destination={{ data.account.id }}">{{ 'create_new_deposit'|_ }}</a>
                                    </li>
                                    <li>
                                        <a href="{{ route('transactions.create', ['transfer']) }}?source={{ data.account.id }}">{{ 'create_new_transfer'|_ }}</a>
                                    </li>
                                </ul>
                            </div>
                            <div class="btn-group">
                                <a type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
                                   aria-haspopup="true" aria-expanded="false"
                                   href="{{ route('accounts.show', [data.account.id]) }}">{{ data.account|balance }}
                                    <span class="caret"></span>
                                </a>
                                <ul class="dropdown-menu">
                                    <li>
                                        <a href="{{ route('accounts.show', [data.account.id]) }}">{{ 'show'|_ }}</a>
                                    </li>
                                    <li>
                                        <a href="{{ route('accounts.reconcile', [data.account.id]) }}">{{ 'reconcile'|_ }}</a>
                                    </li>
                                    <li>
                                        <a href="{{ route('accounts.edit', [data.account.id]) }}">{{ 'edit'|_ }}</a>
                                    </li>
                                    <li>
                                        <a href="{{ route('accounts.delete', [data.account.id]) }}">{{ 'delete'|_ }}</a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                {% endfor %}
            </div>

            {% if billCount > 0 %}
                {# BILLS #}
                <div class="box">
                    <div class="box-header with-border">
                        <h3 class="box-title"><a href="{{ route('subscriptions.index') }}"
                                                 title="{{ 'bills'|_ }}">{{ 'bills'|_ }}</a></h3>

                    </div>
                    <div class="box-body">
                        <div style="width:100%;margin:0 auto;">
                            <canvas id="bills-chart" style="width:100%;height:200px;" height="200"></canvas>
                        </div>
                    </div>
                    <div class="box-footer">
                        <a href="{{ route('bills.index') }}" class="btn btn-default button-sm"><span
                                class="fa fa-calendar"></span> {{ 'go_to_bills'|_ }}</a>
                    </div>
                </div>
            {% endif %}

            {# box for piggy bank data (JSON) #}
            <div id="piggy_bank_overview">

            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12 col-md-12 col-sm-12">
            {# EXPENSE ACCOUNTS #}
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title"><a href="{{ route('accounts.index',['expense']) }}"
                                             title="{{ 'expense_accounts'|_ }}">{{ 'expense_accounts'|_ }}</a>
                    </h3>
                </div>
                <div class="box-body">
                    <canvas id="expense-accounts-chart" style="width:100%;height:400px;" height="400"
                            width="100%"></canvas>
                </div>
                <div class="box-footer">
                    <a href="{{ route('accounts.index', ['expense']) }}" class="btn btn-default button-sm"><span
                            class="fa fa-shopping-cart"></span> {{ 'go_to_expense_accounts'|_ }}</a>
                </div>
            </div>
            {# OPTIONAL REVENUE ACCOUNTS #}
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title"><a href="{{ route('accounts.index',['revenue']) }}"
                                             title="{{ 'revenue_accounts'|_ }}">{{ 'revenue_accounts'|_ }}</a></h3>

                </div>
                <div class="box-body">
                    <canvas id="revenue-accounts-chart" style="width:100%;height:400px;" height="400"
                            width="100%"></canvas>
                </div>
                <div class="box-footer">
                    <a href="{{ route('accounts.index', ['revenue']) }}" class="btn btn-default button-sm"><span
                            class="fa fa-download"></span> {{ 'go_to_revenue_accounts'|_ }}</a>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
{% block scripts %}
    <script type="text/javascript" nonce="{{ JS_NONCE }}">
        var lineColor = 'red';
        var lineTextColor = '#000';
        if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
            lineColor = '#a00';
            lineTextColor = '#bec5cb';
        }
        var billCount = {{ billCount }};
        var accountFrontpageUrl = '{{ route('chart.account.frontpage') }}';
        var accountRevenueUrl = '{{ route('chart.account.revenue') }}';
        var accountExpenseUrl = '{{ route('chart.account.expense') }}';
        var piggyInfoUrl = '{{ route('json.fp.piggy-banks') }}';
        var drawVerticalLine = '';
        {# render vertical line with text "today"  #}
        {% if start.lte(today) and end.gte(today) %}
        drawVerticalLine = '{{ today.isoFormat(monthAndDayFormat) }}';
        {% endif %}
    </script>

    <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/lib/chartjs-plugin-annotation.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/ff/index.js?v={{ FF_BUILD_TIME }}" nonce="{{ JS_NONCE }}"></script>
{% endblock %}
{% block styles %}
{% endblock %}
