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

{% block breadcrumbs %}
    {{ Breadcrumbs.render(Route.getCurrentRoute.getName, piggyBank) }}
{% endblock %}

{% block content %}
    <div class="row">
        <div class="col-lg-8 col-md-8 col-sm-6">
            <div class="box" id="piggyChart">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'events'|_ }}</h3>
                </div>
                <div class="box-body">
                    <canvas id="piggy-bank-history" style="width:100%;height:400px;" height="400" width="100%"></canvas>
                </div>
            </div>
        </div>
        <div class="col-lg-4 col-md-4 col-sm-6">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'details'|_ }}</h3>
                    <div class="box-tools pull-right">
                        <div class="btn-group">
                            <button class="btn btn-box-tool dropdown-toggle" data-toggle="dropdown"><span class="fa fa-ellipsis-v"></span></button>
                            <ul class="dropdown-menu" role="menu">
                                <li><a href="{{ route('piggy-banks.edit', piggy.id) }}"><span class="fa fa-pencil fa-fw"></span> {{ 'edit'|_ }}</a></li>
                                <li><a href="{{ route('piggy-banks.delete', piggy.id) }}"><span class="fa fa-trash fa-fw"></span> {{ 'delete'|_ }}</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="box-body no-padding">
                    <table class="table table-responsive table-hover" id="piggyDetails">
                        <tr>
                            <td style="width:40%;">{{ 'saveOnAccounts'|_ }}</td>
                            <td>
                                {% for account in piggy.accounts %}
                                    <a href="{{ route('accounts.show', account.id) }}">{{ account.name }}</a><br>
                                {% endfor %}
                            </td>
                        </tr>
                        {% if piggy.object_group_title %}
                            <tr>
                                <td style="width:40%;">{{ 'object_group'|_ }}</td>
                                <td>{{ piggy.object_group_title }}</a></td>
                            </tr>
                        {% endif %}
                        {% if null != piggy.target_amount %}
                            <tr>
                                <td>{{ 'target_amount'|_ }}</td>
                                <td>
                                    {{ formatAmountBySymbol(piggy.target_amount, piggy.currency_symbol, piggy.currency_decimal_places) }}
                                </td>
                            </tr>
                        {% endif %}
                        {% for account in piggy.accounts %}
                            <tr>
                                <td>
                                    {{ 'saved_so_far'|_ }}
                                    (<a href="{{ route('accounts.show', account.id) }}">{{ account.name }}</a>)
                                </td>
                                <td>
                                    {{ formatAmountBySymbol(account.current_amount, piggy.currency_symbol, piggy.currency_decimal_places) }}
                                </td>
                            </tr>

                        {% endfor %}
                        <tr>
                            <td>{{ 'saved_so_far_total'|_ }}</td>
                            <td>
                                {{ formatAmountBySymbol(piggy.current_amount, piggy.currency_symbol, piggy.currency_decimal_places) }}
                            </td>
                        </tr>
                        {% if null != piggy.left_to_save %}
                            <tr>
                                <td>{{ 'left_to_save'|_ }}</td>
                                <td>
                                    {{ formatAmountBySymbol(piggy.left_to_save, piggy.currency_symbol, piggy.currency_decimal_places) }}
                                </td>
                            </tr>
                        {% endif %}
                        <tr>
                            <td>{{ 'start_date'|_ }}</td>
                            <td>
                                {% if piggyBank.start_date %}
                                    {{ piggyBank.start_date.isoFormat(monthAndDayFormat) }}
                                {% else %}
                                    <em>{{ 'no_start_date'|_ }}</em>
                                {% endif %}
                            </td>
                        </tr>
                        <tr>
                            <td>{{ 'target_date'|_ }}</td>
                            <td>
                                {% if piggyBank.target_date %}
                                    {{ piggyBank.target_date.isoFormat(monthAndDayFormat) }}
                                {% else %}
                                    <em>{{ 'no_target_date'|_ }}</em>
                                {% endif %}
                            </td>
                        </tr>
                        {% if piggyBank.target_date and piggy.save_per_month %}
                            <tr>
                                <td>{{ 'suggested_amount'|_ }}</td>
                                <td>
                                    {{ formatAmountBySymbol(piggy.save_per_month, piggy.currency_symbol, piggy.currency_decimal_places) }}

                                </td>
                            </tr>
                        {% endif %}
                    </table>
                </div>
            </div>
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'event_history'|_ }} (<a onclick="return confirm('{{ 'reset_history_confirm'|_|escape('js') }}');" class="reset-link" href="#">{{ 'reset_history'|_ }}</a>)</h3>
                </div>
                <div class="box-body no-padding" id="piggyEvents">
                    {% include 'list/piggy-bank-events' %}
                </div>
            </div>
        </div>
    </div>
    <div class="row">

        {% if piggy.notes %}
            <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">{{ trans('form.notes') }}</h3>
                    </div>
                    <div class="box-body markdown">{{ piggy.notes|default('')|markdown }}
                    </div>
                </div>

            </div>
        {% endif %}
        {% if attachments.count() > 0 %}
            <div class="col-lg-4 col-md-6 col-sm-12 col-xs-12">
                <div class="box">
                    <div class="box-header with-border">
                        <h3 class="box-title">
                            {{ 'attachments'|_ }}
                        </h3>
                    </div>
                    <div class="box-body no-padding">
                        {% include 'list.attachments' %}
                    </div>
                </div>
            </div>
        {% endif %}
    </div>
    <form id="reset-form" action="{{ route('piggy-banks.reset', [piggyBank.id]) }}" method="POST" style="display: none;">
        <input type="hidden" name="_token" value="{{ csrf_token() }}"/>
    </form>
{% endblock %}

{% block scripts %}
    <script type="text/javascript" nonce="{{ JS_NONCE }}">
        var piggyBankID = {{ piggyBank.id }};
    </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/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/piggy-banks/show.js?v={{ FF_BUILD_TIME }}" nonce="{{ JS_NONCE }}"></script>
{% endblock %}
