{% extends "./layout/default.twig" %}
{% block content %}
    {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName) }}
    <div class="row">
        <div class="col-lg-9 col-sm-8 col-md-8">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <i class="fa fa-calendar fa-fw"></i>
                    {{ Session.get('start').formatLocalized(monthFormat) }}
                </div>
                <div class="panel-body">
                    <div class="row">
                        <div class="col-lg-6 col-md-4 col-sm-3">
                            <small>{{ 'budgeted'|_ }}: <span id="budgetedAmount" class="text-success">{{ budgeted|formatAmountPlain }}</span></small>
                        </div>
                        <div class="col-lg-6 col-md-4 col-sm-3" style="text-align:right;">
                            <small>{{ trans('firefly.availableIn',{date : Session.get('start').formatLocalized(monthFormat) }) }}:
                                <a href="#" class="updateIncome"><span id="budgetIncomeTotal" data-value="{{ budgetIncomeTotal }}">{{ budgetIncomeTotal|formatAmount }}</span></a></small>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-lg-12 col-md-12 col-sm-12">
                            <div class="progress progress-striped budgetedBar">
                                <div class="progress-bar progress-bar-danger" id="progress-bar-danger" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0;"></div>
                                <div class="progress-bar progress-bar-warning" id="progress-bar-warning" role="progressbar" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100" style="width: 0;"></div>
                                <div class="progress-bar progress-bar-info" id="progress-bar-default" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0;"></div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-6 col-md-4 col-sm-3">
                            <small>{{ 'spent'|_ }}: {{ spent|formatAmount }}</small>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-12 col-md-12 col-sm-12">
                            <div class="progress progress-striped spentBar">
                                    <div class="progress-bar progress-bar-warning" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0;"></div>
                                    <div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0;"></div>
                                    <div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0;"></div>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
        <div class="col-lg-3 col-sm-4 col-md-4">

            <div class="panel panel-default">
                <div class="panel-heading">
                    <i class="fa fa-fw fa-tags"></i>
                    {{ 'transactionsWithoutBudget'|_ }}
                </div>
                <div class="panel-body">
                    <p>
                        <a href="{{ route('budgets.noBudget') }}">
                            {{ trans('firefly.transactionsWithoutBudgetDate', {date: Session.get('start').formatLocalized(monthFormat)}) }}
                        </a>
                    </p>
                </div>
            </div>
        </div>

    </div>

    <div class="row">
        {% for budget in budgets %}
            <div class="col-lg-3 col-sm-4 col-md-6" style="height:180px;">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <i class="fa fa-fw fa-tasks"></i>
                        <!-- link in header -->
                        {% if budget.currentRep %}
                            <a href="{{ route('budgets.show', [budget.id, budget.currentRep.id]) }}" class="budget-link" data-id="{{ budget.id }}">{{ budget.name }}</a>
                        {% else %}
                            <a href="{{ route('budgets.show',budget.id) }}" class="budget-link" data-id="{{ budget.id }}">{{ budget.name }}</a>
                        {% endif %}


                        <!-- ACTIONS MENU -->
                        <div class="pull-right">
                            <div class="btn-group">
                                <button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">
                                    {{ 'actions'|_ }}
                                    <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu pull-right" role="menu">
                                    <li><a href="{{ route('budgets.edit',budget.id) }}"><i class="fa fa-pencil fa-fw"></i> {{ 'edit'|_ }}</a></li>
                                    <li><a href="{{ route('budgets.delete',budget.id) }}"><i class="fa fa-trash fa-fw"></i> {{ 'delete'|_ }}</a></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                    <table class="table">
                        <tr>
                            <td style="width:40%;">{{ 'budgeted'|_ }}</td>
                            <td>
                                <div class="form-group" style="margin-bottom:0;">
                                    <div class="input-group">
                                        <div class="input-group-addon">{{ defaultCurrency.symbol|raw }}</div>
                                        <input type="hidden" name="balance_currency_id" value="1" />
                                        <input class="form-control budgetAmount" data-original="{{ budget.currentRep.amount|number_format(0,'','') }}" data-id="{{ budget.id }}" value="{{ budget.currentRep.amount|number_format(0,'','') }}" autocomplete="off" step="1" min="0" max="{{ budgetMaximum }}" name="amount" type="number">
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td style="width:50%;">{{ 'spent'|_ }}</td>
                            <td>{{ budget.spent|formatAmount }}</td>
                        </tr>
                    </table>
                </div>
        </div>
        {% endfor %}
        <div class="col-lg-3 col-sm-4 col-md-6">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <i class="fa fa-fw fa-plus-circle"></i>
                    {{ 'createBudget'|_ }}
                </div>
                <div class="panel-body">
                    <a href="{{ route('budgets.create') }}" class="btn btn-success"><i class="fa fa-fw fa-plus"></i> {{ 'createBudget'|_ }}</a>
                </div>
            </div>
        </div>
        {% if inactive|length > 0 %}
            <div class="col-lg-3 col-sm-4 col-md-6">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <i class="fa fa-fw fa-minus-circle"></i>
                        {{ 'inactiveBudgets'|_ }}
                    </div>
                    <div class="panel-body">
                        {% for index,budget in inactive %}
                            {% if index != inactive|length-1 %}
                                <a href="{{ route('budgets.show',budget.id) }}">{{ budget.name }}</a>,
                            {% else %}
                                <a href="{{ route('budgets.show',budget.id) }}">{{ budget.name }}</a>
                            {% endif %}
                        {% endfor %}
                    </div>
                </div>
            </div>
        {% endif %}
    </div>
{% endblock %}
{% block scripts %}
    <script type="text/javascript">
        // actually spent bar data:
        var spent = {{ spent }};
        var currencySymbol = "{{ getCurrencySymbol()|raw }}";

        // budgeted data:
        var budgeted = {{ budgeted }};
        var budgetIncomeTotal = {{ budgetIncomeTotal }};
    </script>

    <script type="text/javascript" src="js/budgets.js"></script>
{% endblock %}
