{% extends 'base.html' %}
{% load i18n %}

{% block title %}{% trans 'Search' %}{% endblock %}

{% block breadcrumb %}
    <ol class="breadcrumb">
        <li><span class="glyphicon glyphicon-home"></span></li>
        <li class="active">{% trans 'Search' %}</li>
    </ol>
{% endblock %}

{% block page-header %}
    {% trans 'Search' %}
{% endblock %}

{% block main %}
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">
                {% blocktrans trimmed with searchstring=s %}
                    Search by {{ searchstring }}
                {% endblocktrans %}
            </h3>
        </div>
        <div class="panel-body">
            <form role="form" action="{% url 'searchapp:home' %}" method="get">
                <div class="form-group">
                    <label for="srfield">{% trans 'Change search string there' %}</label>

                    <div class="input-group">
                    <span class="input-group-btn">
                        <button class="btn btn-default">
                            <span class="glyphicon glyphicon-search"></span> {% trans 'Find' %}
                        </button>
                    </span>
                        <input id="srfield" name="s" type="text" value="{{ s }}" class="form-control" autofocus>
                    </div>
                </div>
            </form>
            <div class="list-group">
                {% for ab in abons %}
                    <a href="{% url 'abonapp:abon_home' ab.group.id ab.username %}" class="list-group-item">
                        <h4 class="list-group-item-heading">
                            <span class="glyphicon glyphicon-user"></span>
                            {{ ab.username_display|safe }}
                        </h4>

                        <p class="list-group-item-text">
                        {{ ab.fio|safe }}
                        {% if ab.ip_address %}
                            <span>{{ ab.ip_address }}</span>
                        {% endif %}
                        {{ ab.telephone|safe }}
                        </p>
                    </a>
                {% empty %}
                    <a class="list-group-item">
                        <h4 class="list-group-item-heading">
                            <span class="glyphicon glyphicon-user"></span>
                            {% trans 'Nothing to found' %}
                        </h4>

                        <p class="list-group-item-text">
                            {% trans 'You can change search string and try again' %}
                        </p>
                    </a>
                {% endfor %}
                {% for dev in devices %}
                    {% if dev.group %}
                        {% url 'devapp:view' dev.group.id dev.pk as devviewlink %}
                    {% else %}
                        {% url 'devapp:fix_device_group' dev.pk as devviewlink %}
                    {% endif %}
                    <a href="{{ devviewlink }}" class="list-group-item">
                        <h4 class="list-group-item-heading">
                            <span class="glyphicon glyphicon-hdd"></span>
                            {{ dev.comment|safe }}
                        </h4>

                        <p class="list-group-item-text">
                            {% if dev.ip_address %}
                                <span>{{ dev.ip_address }}</span>,
                            {% endif %}
                            {% if dev.mac_addr %}
                                <span>{{ dev.mac_addr }}</span>,
                            {% endif %}
                            {{ dev.get_devtype_display }},
                            {% blocktrans trimmed with netw_status=dev.get_status_display %}
                                Network state is {{ netw_status }}
                            {% endblocktrans %}
                        </p>
                    </a>
                {% empty %}
                    <a class="list-group-item">
                        <h4 class="list-group-item-heading">
                            <span class="glyphicon glyphicon-hdd"></span>
                            {% trans 'Nothing to found' %}
                        </h4>

                        <p class="list-group-item-text">
                            {% trans 'You can change search string and try again' %}
                        </p>
                    </a>
                {% endfor %}
            </div>
        </div>
    </div>
{% endblock %}
