{% extends './layout/default' %}
{% block breadcrumbs %}
    {{ Breadcrumbs.render(Route.getCurrentRoute.getName, recurrence) }}
{% endblock %}
{% block content %}

    <form method="post" action="{{ route('recurring.update', recurrence.id) }}" class="form-horizontal"
          accept-charset="UTF-8"
          enctype="multipart/form-data">
        <input type="hidden" name="_token" value="{{ csrf_token() }}"/>

        {# row with recurrence information #}
        <div class="row">

            <div class="col-lg-6 col-md-6 col-sm-12">
                {# mandatory recurrence stuff #}
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">{{ 'mandatory_for_recurring'|_ }}</h3>
                    </div>
                    <div class="box-body">
                        <input type="hidden" name="id" value="{{ array.id }}"/>
                        {{ ExpandedForm.text('title', array.title) }}
                        {{ ExpandedForm.date('first_date',array.first_date, {helpText: trans('firefly.help_first_date_no_past')}) }}
                        {{ ExpandedForm.select('repetition_type', [], null, {helpText: trans('firefly.change_date_other_options')}) }}
                        {{ ExpandedForm.integer('skip', array.repetitions[0].skip, {'helpText': trans('firefly.skip_help_text')}) }}
                        {{ ExpandedForm.select('weekend', weekendResponses, array.repetitions[0].weekend, {helpText: trans('firefly.help_weekend')}) }}
                        {{ ExpandedForm.select('repetition_end', repetitionEnds, repetitionEnd) }}
                        {{ ExpandedForm.date('repeat_until',array.repeat_until) }}
                        {{ ExpandedForm.integer('repetitions', array.nr_of_repetitions) }}

                        {# calendar in popup #}
                        <div class="form-group" id="calendar_holder">
                            <label for="ffInput_calendar"
                                   class="col-sm-4 control-label">{{ trans('form.calendar') }}</label>

                            <div class="col-sm-8">
                                <p class="form-control-static" id="ffInput_calendar">
                                    <a href="#" id="calendar-link">{{ 'click_for_calendar'|_ }}</a>
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="col-lg-6 col-md-6 col-sm-12">
                {# optional recurrence stuff #}
                <div class="box">
                    <div class="box-header with-border">
                        <h3 class="box-title">{{ 'optional_for_recurring'|_ }}</h3>
                    </div>
                    <div class="box-body">
                        {{ ExpandedForm.textarea('recurring_description',array.description) }}

                        {# only correct way to do active checkbox #}
                        {{ ExpandedForm.checkbox('active', 1, preFilled.active) }}
                        {{ ExpandedForm.checkbox('apply_rules', 1, preFilled.apply_rules) }}
                        {{ ExpandedForm.file('attachments[]', {'multiple': 'multiple','helpText': trans('firefly.upload_max_file_size', {'size': uploadSize|filesize}) }) }}
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-6 col-md-6 col-sm-12">
                {# mandatory transaction information #}
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">{{ 'mandatory_for_transaction'|_ }}</h3>
                    </div>
                    <div class="box-body">
                        <p><em>{{ 'mandatory_fields_for_tranaction'|_ }}</em></p>
                        {# three buttons to distinguish type of transaction #}
                        <div class="form-group" id="name_holder">
                            <label for="ffInput_type" class="col-sm-4 control-label">
                                {{ trans('form.transaction_type') }}
                            </label>

                            <div class="col-sm-8">
                                <div class="btn-group btn-group-sm">
                                    <a href="#" class="btn btn-default switch-button"
                                       data-value="withdrawal">{{ 'withdrawal'|_ }}</a>
                                    <a href="#" class="btn btn-default switch-button"
                                       data-value="deposit">{{ 'deposit'|_ }}</a>
                                    <a href="#" class="btn btn-default switch-button"
                                       data-value="transfer">{{ 'transfer'|_ }}</a>
                                </div>
                            </div>
                        </div>
                        <input type="hidden" name="transaction_type" value="">
                        {# end of three buttons #}
                        {{ ExpandedForm.text('transaction_description', array.transactions[0].description) }}
                        {# transaction information (mandatory) #}
                        {{ CurrencyForm.currencyList('transaction_currency_id', array.transactions[0].currency_id) }}
                        {{ ExpandedForm.amountNoCurrency('amount', array.transactions[0].amount) }}

                        {# source account if withdrawal, or if transfer: #}
                        {{ AccountForm.longAccountList('source_id', array.transactions[0].source_id, {label: trans('form.asset_source_account')}) }}

                        {# NEW for deposits, a drop down with revenue accounts, loan debt cash and mortgage #}
                        {{ AccountForm.activeDepositDestinations('deposit_source_id', preFilled.deposit_source_id, {label: trans('form.deposit_source_id')}) }}

                        {# destination if deposit or transfer: #}
                        {{ AccountForm.longAccountList('destination_id', array.transactions[0].destination_id, {label: trans('form.asset_destination_account')} ) }}

                        {# NEW for withdrawals, also a drop down with expense accounts, loans, debts, mortgages or (cash). #}
                        {{ AccountForm.activeWithdrawalDestinations('withdrawal_destination_id', preFilled.withdrawal_destination_id, {label: trans('form.withdrawal_destination_id')}) }}
                    </div>
                </div>
            </div>

            <div class="col-lg-6 col-md-6 col-sm-12">
                {# optional transaction information #}
                <div class="box">
                    <div class="box-header with-border">
                        <h3 class="box-title">{{ 'optional_for_transaction'|_ }}</h3>
                    </div>
                    <div class="box-body">
                        {# transaction information (optional) #}
                        {{ CurrencyForm.currencyListEmpty('foreign_currency_id', array.transactions[0].foreign_currency_id) }}
                        {{ ExpandedForm.amountNoCurrency('foreign_amount', array.transactions[0].foreign_amount) }}

                        {# BUDGET ONLY WHEN CREATING A WITHDRAWAL #}
                        {% if budgets|length > 1 %}
                            {{ ExpandedForm.select('budget_id', budgets, array.transactions[0].budget_id) }}
                        {% else %}
                            {{ ExpandedForm.select('budget_id', budgets, array.transactions[0].budget_id, {helpText: trans('firefly.no_budget_pointer', {link: route('budgets.index')})}) }}
                            {# budgets #}
                        {% endif %}

                        {# CATEGORY ALWAYS #}
                        {{ ExpandedForm.text('category',array.transactions[0].category_name) }}

                        {# BILL ONLY WHEN CREATING A WITHDRAWAL #}
                        {% if bills|length > 1 %}
                            {{ ExpandedForm.select('bill_id', bills, array.transactions[0].subscription_id) }}
                        {% else %}
                            {{ ExpandedForm.select('bill_id', bills, array.transactions[0].subscription_id, {helpText: trans('firefly.no_bill_pointer', {link: route('subscriptions.index')})}) }}
                        {% endif %}

                        {# TAGS #}
                        {{ ExpandedForm.text('tags', array.transactions[0].tags) }}

                        {# RELATE THIS TRANSFER TO A PIGGY BANK #}
                        {{ PiggyBankForm.piggyBankList('piggy_bank_id',array.transactions[0].piggy_bank_id) }}
                    </div>
                </div>
            </div>
        </div>

        {# row with submit stuff. #}
        <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">{{ 'options'|_ }}</h3>
                    </div>
                    <div class="box-body">
                        {{ ExpandedForm.optionsList('update','recurrence') }}
                    </div>
                    <div class="box-footer">
                        <button type="submit" class="btn pull-right btn-success">
                            {{ ('update_recurrence')|_ }}
                        </button>
                    </div>
                </div>
            </div>
        </div>
        {#
        <div class="row">
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'expected_repetitions'|_ }}</h3>
                </div>
                <div class="box-body">
                    Here.
                </div>
            </div>
        </div>
    </div>
    </div>
        #}
    </form>

    {# calendar modal #}
    <div class="modal fade" id="calendarModal" tabindex="-1" role="dialog">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title">{{ 'recurring_calendar_view'|_ }}</h4>
                </div>
                <div class="modal-body">
                    <div id="recurring_calendar" style="max-width: 400px;margin: 0 auto;">

                    </div>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
{% block scripts %}
    <script type="text/javascript" src="v1/js/lib/modernizr-custom.js?v={{ FF_BUILD_TIME }}"
            nonce="{{ JS_NONCE }}"></script>
    <script type="text/javascript" src="v1/js/lib/typeahead/typeahead.bundle.min.js?v={{ FF_BUILD_TIME }}"
            nonce="{{ JS_NONCE }}"></script>
    <script type="text/javascript" src="v1/js/ff/common/autocomplete.js?v={{ FF_BUILD_TIME }}"
            nonce="{{ JS_NONCE }}"></script>
    <script type="text/javascript" src="v1/js/lib/bootstrap-tagsinput.min.js?v={{ FF_BUILD_TIME }}"
            nonce="{{ JS_NONCE }}"></script>
    <script type="text/javascript" src="v1/js/lib/jquery-ui.min.js?v={{ FF_BUILD_TIME }}" nonce="{{ JS_NONCE }}"></script>
    <script type="text/javascript" src="v1/lib/fc/fullcalendar.min.js?v={{ FF_BUILD_TIME }}"
            nonce="{{ JS_NONCE }}"></script>
    <script type="text/javascript" nonce="{{ JS_NONCE }}">
        var transactionType = "{{ preFilled.transaction_type }}";
        var suggestUrl = "{{ route('recurring.suggest') }}";
        var eventsUrl = "{{ route('recurring.events') }}";
        var currentRepType = "{{ currentRepType }}";
    </script>
    <script type="text/javascript" src="v1/js/ff/recurring/edit.js?v={{ FF_BUILD_TIME }}" nonce="{{ JS_NONCE }}"></script>
{% endblock %}

{% block styles %}
    <link href="v1/css/bootstrap-tagsinput.css?v={{ FF_BUILD_TIME }}" type="text/css" rel="stylesheet" media="all"
          nonce="{{ JS_NONCE }}">
    <link href="v1/css/jquery-ui/jquery-ui.structure.min.css?v={{ FF_BUILD_TIME }}" type="text/css" rel="stylesheet"
          media="all" nonce="{{ JS_NONCE }}">
    <link href="v1/css/jquery-ui/jquery-ui.theme.min.css?v={{ FF_BUILD_TIME }}" type="text/css" rel="stylesheet"
          media="all" nonce="{{ JS_NONCE }}">
    <link href="v1/lib/fc/fullcalendar.min.css?v={{ FF_BUILD_TIME }}" type="text/css" rel="stylesheet" media="all"
          nonce="{{ JS_NONCE }}">
{% endblock %}
