{% extends 'base.html' %}

{% block content %}
<div class="container-fluid mt-0">
    <h1>{{ _("Maintenances") }}</h1>
    <h2>{{ _("This system page configures the possible maintenances actions of the machines") }}</h2>
    <a href="{{ url_for('add_maintenance') }}" class="btn btn-primary mb-3">{{ _("Add Maintenance") }}</a>
    <form method="GET" action="{{ url_for('maintenances') }}">
        <div class="form-group">
            <label for="machineFilter">{{ _("Filter Machines") }}:</label>
            <select id="machineFilter" name="machine" class="form-control">
                <option value="">{{ _("--Select Machine--") }}</option>
                {% for machine in machines %}
                <option value="{{ machine.machine_id }}" {% if request.args.get('machine')|int==machine.machine_id
                    %}selected{% endif %}>{{ machine.machine_name }}</option>
                {% endfor %}
            </select>
        </div>
        <div class="form-group">
            <label for="descriptionFilter">{{ _("Filter Description") }}:</label>
            <input type="text" id="descriptionFilter" name="description" class="form-control"
                value="{{ request.args.get('description', '') }}">
        </div>
        <button type="submit" class="btn btn-info">{{ _("Apply Filters") }}</button>
    </form>
    <ul class="list-group">
        {% for maintenance in maintenances %}
        <li class="list-group-item d-flex justify-content-between align-items-center">
            <div>
                <strong>{{ _("Description") }}: {{ maintenance.description }}</strong><br/>
                {{ _("Lcd message")}}: {{ maintenance.lcd_message }} <br/>
                {{ _("Hours Between") }}: {{ maintenance.hours_between }}<br/>
                {{ _("Machine") }} {{ maintenance.machine.machine_name }}<br/>
                {% if maintenance.instructions_url %}
                    {{ _("Instructions URL") }}: <a href="{{ maintenance.instructions_url }}">{{ maintenance.instructions_url }}</a>
                {% endif %}
            </div>
            <div>
                <a href="{{ url_for('edit_maintenance', maintenance_id=maintenance.maintenance_id) }}"
                    class="btn btn-warning">{{ _("Edit") }}</a>
                <a href="{{ url_for('delete_maintenance', maintenance_id=maintenance.maintenance_id) }}"
                    class="btn btn-danger">{{ _("Delete") }}</a>
            </div>
        </li>
        {% endfor %}
    </ul>
</div>
{% endblock %}