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

{% block breadcrumbs %}
    {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, rule) }}
{% endblock %}

{% block content %}
    {{ Form.model(rule, {'class' : 'form-horizontal','id' : 'store','url' : route('rules.update', rule.id)}) }}
    <input type="hidden" name="rule_group_id" value="{{ rule.rule_group_id }}"/>
    <div class="row">
        <div class="col-lg-6 col-md-6 col-sm-12">
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'mandatoryFields'|_ }}</h3>
                </div>
                <div class="box-body">
                    {{ ExpandedForm.text('title') }}
                    {{ ExpandedForm.select('trigger',allJournalTriggers(), primaryTrigger) }}
                    {{ ExpandedForm.checkbox('active',1,rule.active, {helpText: trans('firefly.rule_help_active')}) }}
                    {{ ExpandedForm.checkbox('stop_processing',1,rule.stop_processing, {helpText: trans('firefly.rule_help_stop_processing')}) }}
                </div>
            </div>
        </div>
        <div class="col-lg-6 col-md-6 col-sm-12">

            <!-- optional fields -->
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'optionalFields'|_ }}</h3>
                </div>
                <div class="box-body">
                    {{ ExpandedForm.textarea('description') }}
                </div>
            </div>
        </div>
    </div>

    <!-- RULE TRIGGERS -->
    <div class="row">
        <div class="col-lg-12 col-md-12 col-sm-12">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'rule_triggers'|_ }}</h3>
                </div>
                <!-- display any error -->
                <div class="box-body rule-trigger-box">
                    <table class="table table-condensed table-bordered table-striped">
                        <thead>
                        <tr>
                            <th colspan="2">{{ 'trigger'|_ }}</th>
                            <th>{{ 'trigger_value'|_ }}</th>
                            <th>{{ 'stop_processing_other_triggers'|_ }}</th>
                        </tr>
                        </thead>
                        <tbody class="rule-trigger-tbody">
                        {% for trigger in oldTriggers %}
                            {{ trigger|raw }}
                        {% endfor %}
                        </tbody>

                    </table>
                    <p>
                        <br/>
                        <a href="#" class="btn btn-default add_rule_trigger">{{ 'add_rule_trigger'|_ }}</a>
                        <a href="#" class="btn btn-default test_rule_triggers">{{ 'test_rule_triggers'|_ }}</a>
                    </p>
                </div>
            </div>
        </div>
    </div>

    {% include '/rules/partials/test-trigger-modal' %}

    <!-- RULE ACTIONS -->
    <div class="row">
        <div class="col-lg-12 col-md-12 col-sm-12">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'rule_actions'|_ }}</h3>
                </div>
                <div class="box-body">
                    <table class="table table-condensed table-bordered table-striped">
                        <thead>
                        <tr>
                            <th colspan="2">{{ 'action'|_ }}</th>
                            <th>{{ 'action_value'|_ }}</th>
                            <th>{{ 'stop_executing_other_actions'|_ }}</th>
                        </tr>
                        </thead>
                        <tbody class="rule-action-tbody">
                        {% for action in oldActions %}
                            {{ action|raw }}
                        {% endfor %}
                        </tbody>

                    </table>
                    <p>
                        <br/>
                        <a href="#" class="btn btn-default add_rule_action">{{ 'add_rule_action'|_ }}</a>
                    </p>
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-12 col-md-12 col-sm-12">
            <!-- panel for options -->
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'options'|_ }}</h3>
                </div>
                <div class="box-body">
                    {{ ExpandedForm.optionsList('update','rule') }}
                </div>
                <div class="box-footer">
                    <button type="submit" class="btn pull-right btn-success">{{ 'update_rule'|_ }}</button>
                </div>
            </div>

        </div>

    </div>
    {{ Form.close|raw }}


{% endblock %}
{% block scripts %}
    <script type="text/javascript" src="js/lib/bootstrap3-typeahead.min.js"></script>
    <script type="text/javascript">
        var triggerCount = {{ triggerCount }};
        var actionCount = {{ actionCount }};
    </script>
    <script type="text/javascript" src="js/ff/rules/create-edit.js"></script>

{% endblock %}
