{% load i18n %}

{% load icons_tags %}
{% load search_tags %}
{% load smart_settings_tags %}

{% icons_get_icon "mayan.apps.dynamic_search.icons.icon_search" as icon_search %}
{% icons_get_icon "mayan.apps.dynamic_search.icons.icon_search_advanced" as icon_search_advanced %}
{% search_get_default_search_model as default_search_model %}
{% search_get_search_models as search_models %}
{% smart_setting global_name="SEARCH_DISABLE_SIMPLE_SEARCH" as setting_disable_simple_search %}

{% if setting_disable_simple_search %}
    <div class="row">
        <div class="col-xs-6 col-xs-offset-3">
{% endif %}

            <div class="well center-block">
                <div class="row">
                    <div class="col-xs-12">
                        <form action="{% url 'search:search_results' %}" class="form-horizontal" id="formSearch" method="get" role="search">
                            {% if setting_disable_simple_search == False %}
                                <div class="col-sm-2">
                            {% else %}
                                <div class="col-sm-8">
                            {% endif %}
                                <select class="form-control search-select-search-model" name="{% search_get_search_model_name_query_variable %}">
                                    {% for search_model in search_models %}
                                    {{ search_model.self.full_name }}
                                        <option {% if search_model.full_name == default_search_model.full_name %}selected{% endif %} value="{{ search_model.full_name }}">{{ search_model }}</option>
                                    {% endfor %}
                                </select>
                            </div>

                            {% if setting_disable_simple_search == False %}
                                <div class="col-sm-10">
                            {% else %}
                                <div class="col-sm-4">
                            {% endif %}

                                <div class="input-group">
                                    {% if setting_disable_simple_search == False %}
                                        <input class="form-control" name="{% search_get_query_parameter_any_field %}" placeholder="{% trans 'Search terms' %}" type="search" value="{{ search_terms|default:'' }}">
                                    {% endif %}
                                    <span class="input-group-btn">
                                        {% if setting_disable_simple_search == False %}
                                            <button alt="{% trans 'Search' %}" class="btn btn-default" type="submit">{{ icon_search }} {% trans 'Search' %}</button>
                                        {% endif %}
                                        <a alt="{% trans 'Advanced search' %}" class="btn btn-primary search-anchor-search-advanced" href="{% url 'search:search_advanced' %}?{% search_get_search_model_name_query_variable %}={{ default_search_model.full_name }}" id="search-button-search-advanced">{{ icon_search_advanced }} {% if setting_disable_simple_search == False %}{% trans 'Advanced' %}{% else %}{% trans 'Advanced search' %}{% endif %}</a>
                                    </span>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>

{% if setting_disable_simple_search %}
        </div>
    </div>
{% endif %}
