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

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

{% block content %}
    <div class="row">
        <div class="col-lg-12">
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'search_box'|_ }}</h3>
                </div>
                <div class="box-body">
                    <p>
                        {{ 'search_box_intro'|_ }}
                    </p>
                    {# search form #}
                    <form class="form-horizontal" action="{{ route('search.index') }}" method="get">
                        <div class="form-group">
                            <label for="query" class="col-sm-1 control-label">{{ 'search_query'|_ }}</label>
                            <div class="col-sm-10">
                                <input autocomplete="off" type="text" name="search" id="query" value="{{ fullQuery }}" class="form-control" spellcheck="false"
                                       placeholder="{{ fullQuery }}">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-offset-1 col-sm-10">
                                <button type="submit" class="btn btn-info"><span class="fa fa-search"></span> {{ 'search'|_ }}</button>
                                {% if ruleId > 0 and ruleChanged %}
                                    <a href="{{ route('rules.edit', [ruleId]) }}?from_query={{ fullQuery }}"
                                       class="btn btn-default">{{ trans('firefly.update_rule_from_query', {rule: rule.title}) }}</a>
                                {% endif %}
                                <a href="{{ route('rules.create') }}?from_query={{ fullQuery }}" class="btn btn-default">{{ 'create_rule_from_query'|_ }}</a>
                            </div>
                        </div>
                        {% if 0 != ruleId %}
                            <input type="hidden" name="rule" value="{{ ruleId }}"/>
                        {% endif %}
                    </form>
                     <p>
                            {{ trans('firefly.search_for_overview') |raw }}
                    </p>
                    <ul>
                    {% if words|length > 0 %}
                        <li>
                            {{- trans('firefly.search_for_query', {
                                query: words
                                    |map(word => '<span class="search-word">' ~ word|escape ~ '</span>')
                                    |join(' ')
                            })|raw -}}
                        </li>
                    {% endif %}
                    {% if excludedWords|length > 0 %}
                        <li>
                                    {{- trans('firefly.search_for_excluded_words', {
                                        excluded_words: excludedWords
                                            |map(word => '<span class="search-word">' ~ word|escape ~ '</span>')
                                            |join(' ')
                                    })|raw -}}
                        </li>
                    {% endif %}

                    {% for operator in operators %}
                            {% if operator.prohibited %}
                                <li>{{- trans('firefly.search_modifier_not_'~operator.type, {value: operator.value}) -}}</li>
                            {% endif %}
                            {% if not operator.prohibited %}
                                <li>{{- trans('firefly.search_modifier_'~operator.type, {value: operator.value}) -}}</li>
                            {% endif %}
                    {% endfor %}
                    </ul>

                    {% if invalidOperators|length > 0 %}
                        <p>{{ trans('firefly.invalid_operators_list') }}</p>
                        <ul>
                            {% for operator in invalidOperators %}
                                <li class="text-danger">{{ operator.type }}:{{ operator.value }}</li>
                            {% endfor %}
                        </ul>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
    {% if query|length > 0 or words|length > 0 or excludedWords|length > 0 or operators|length > 0 %}
        <div class="row result_row">
            <div class="col-lg-12 col-md-12 col-sm-12">
                <div class="box search_box">
                    <div class="box-header with-border">
                        <h3 class="box-title">{{ 'transactions'|_ }}</h3>
                    </div>
                    <div class="box-body">
                        <p class="search_ongoing text-center">
                            {{ 'search_searching'|_ }}
                        </p>
                        <div class="search_results hidden"></div>
                        {# loading indicator #}
                        <div class="overlay">
                            <span class="fa fa-refresh fa-spin"></span>
                        </div>

                        <div class="row mass_edit_all hidden-xs hidden">
                            <div class="col-lg-6 col-md-12 col-sm-12 col-xs-12">
                                <div class="mass_button_options btn-group btn-group hidden">
                                    <a href="#" class="btn btn-default mass_edit"><span class="fa fa-fw fa-pencil"></span> <span>{{ 'edit_selected'|_ }}</span></a>
                                    <a href="#" class="btn btn-default bulk_edit"><span>{{ 'bulk_edit'|_ }}</span></a>
                                    <a href="#" class="btn btn-danger mass_delete"><span class="fa fa-fw fa-trash"></span>
                                        <span>{{ 'delete_selected'|_ }}</span></a>
                                </div>
                            </div>
                            <div class="col-lg-6 col-md-12 col-sm-12 col-xs-12 hidden-xs">

                                <div class="mass_buttons btn-group btn-group pull-right">
                                    <a href="#" class="btn btn-default mass_select"><span
                                            class="fa fa-fw fa-check-square-o"></span> {{ 'select_transactions'|_ }}</a>
                                    <a href="#" class="btn btn-default mass_stop_select hidden"><span class="fa faw-fw fa-square-o"
                                        ></span> {{ 'stop_selection'|_ }}</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row error_row hidden">
            <div class="col-lg-12 col-md-12 col-sm-12">
                <div class="box box-danger">
                    <div class="box-header with-border">
                        <h3 class="box-title">{{ 'search_error'|_ }}</h3>
                    </div>
                    <div class="box-body">
                        <p class="search_ongoing">
                            {{ 'general_search_error'|_ }}
                        </p>
                    </div>
                </div>
            </div>
        </div>
    {% endif %}
    {% if query|length == 0 and excludedWords|length == 0 and words|length == 0 and operators|length == 0 %}
        <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">{{ 'search_results'|_ }}</h3>
                    </div>
                    <div class="box-body">
                        <p>{{ 'no_results_for_empty_search'|_ }}</p>
                    </div>
                </div>
            </div>

        </div>
    {% endif %}
{% endblock %}
{% block scripts %}
    <script type="text/javascript" nonce="{{ JS_NONCE }}">
        var edit_selected_txt = "{{ trans('firefly.edit')|escape('js') }}";
        var delete_selected_txt = "{{ trans('firefly.delete')|escape('js') }}";
        var edit_bulk_selected_txt = "{{ trans('firefly.bulk_edit')|escape('js') }}";

        var searchQuery = "{{ fullQuery|escape('js') }}";
        var searchUrl = "{{ route('search.search') }}?page={{ page }}";
        var searchPage = {{ page }};
        var cloneGroupUrl = '{{ route('transactions.clone') }}';
        var cloneAndEditUrl = '{{ route('transactions.clone') }}?redirect=edit';
    </script>
    {# required for groups.twig #}
    <script type="text/javascript" src="v1/js/ff/list/groups.js?v={{ FF_BUILD_TIME }}" nonce="{{ JS_NONCE }}"></script>
    <script type="text/javascript" src="v1/js/ff/search/index.js?v={{ FF_BUILD_TIME }}" nonce="{{ JS_NONCE }}"></script>

{% endblock %}
