{% extends 'djelmah/base.html' %}

{% block content %}

<!-- Filter -->
<form method="get" action="" class="form-inline my-3">
    <label>Host:</label>
    <select
        class="form-control form-control-sm ml-1 mr-2"
        name="host"
    >
        <option value="">All</option>
    {% for host in hosts %}
        <option
            value="{{ host }}"
        {% if host == selected_host %}
            selected
        {% endif %}
        >
            {{ host }}
        </option>
    {% endfor %}
    </select>

    <label>Start Date:</label>
    <input
        type="date"
        class="form-control form-control-sm ml-1 mr-2"
        value="{{ start_date|date:'Y-m-d'|default:'' }}"
        name="start_date"
    >

    <label>End Date:</label>
    <input
        type="date"
        class="form-control form-control-sm ml-1 mr-2"
        value="{{ end_date|date:'Y-m-d'|default:'' }}"
        name="end_date"
    >
    
    <button
        type="submit"
        class="btn btn-primary btn-sm mr-2"
    >
        Filter
    </button>
    <a
        href="/djelmah/logs"
        class="btn btn-outline-primary btn-sm"
    >
        Reset
    </a>
</form>

<!-- Logs -->
<table class="table table-bordered table-sm">
    <thead class="thead-light">
        <tr>
            <th>Host</th>
            <th>Code</th>
            <th>Type</th>
            <th>Error</th>
            <th>User</th>
            <th>Created</th>
            <th></th>
            <th class="text-center">
                <a
                    id="btn-test-log"
                    title="Test"
                    href="#"
                >
                    <i class="fas fa-plus"></i>
                </a>
            </th>
        </tr>
    </thead>
    <tbody>
    {% for log in logs %}
        <tr>
            <td>{{ log.host }}</td>
            <td>{{ log.status_code|default:"-" }}</td>
            <td>{{ log.error_type }}</td>
            <td>
                {{ log.error_message|default:"-" }}
            </td>
            <td>{{ log.username|default:"-" }}</td>
            <td>
                {{ log.datetime|date:"m/d/Y" }}
                {{ log.datetime|time:"h:i A" }}
            </td>
            <td class="text-center">
            {% if log.raw_html %}
                <a
                    title="Details"
                    href="/djelmah/logs/{{ log.id }}"
                    target="_blank"
                >
                    <i class="far fa-file"></i>
                </a>
            {% else %}
                -
            {% endif %}
            </td>
            <td class="text-center">
                <a
                    class="btn-delete-log"
                    data-id="{{ log.id }}"
                    title="Delete"
                    href="#"
                >
                    <i class="fas fa-times"></i>
                </a>
            </td>
        </tr>
    {% endfor %}
    </tbody>
</table>

{% endblock %}
