{% extends "base.html" %}

{% block title %}Logs - Backup Monitor{% endblock %}

{% block content %}
<div class="container mt-4">
    <!-- Header -->
    <div class="row mb-4">
        <div class="col-12">
            <h1 class="display-5">
                <i class="fas fa-file-alt text-primary me-3"></i>
                Backup Logs
            </h1>
            <p class="lead text-muted">View and monitor backup operation logs</p>
        </div>
    </div>

    <!-- Filter -->
    <div class="row mb-4">
        <div class="col-12">
            <div class="card">
                <div class="card-body">
                    <form method="GET" class="d-flex align-items-center">
                        <label class="form-label me-2 mb-0">Filter by service:</label>
                        <select name="service" class="form-select me-2" style="width: auto;">
                            <option value="">All Services</option>
                            <option value="plex" {{ 'selected' if filter_service == 'plex' }}>Plex</option>
                            <option value="immich" {{ 'selected' if filter_service == 'immich' }}>Immich</option>
                            <option value="docker" {{ 'selected' if filter_service == 'docker' }}>Docker</option>
                            <option value="env-files" {{ 'selected' if filter_service == 'env-files' }}>Environment Files</option>
                        </select>
                        <button type="submit" class="btn btn-outline-primary">
                            <i class="fas fa-filter me-1"></i>Filter
                        </button>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <!-- Log Files -->
    <div class="row">
        <div class="col-12">
            {% if logs %}
                <div class="card">
                    <div class="card-header">
                        <h5 class="mb-0">Available Log Files</h5>
                    </div>
                    <div class="card-body p-0">
                        <div class="table-responsive">
                            <table class="table table-hover mb-0">
                                <thead class="table-light">
                                    <tr>
                                        <th>Service</th>
                                        <th>Log File</th>
                                        <th>Size</th>
                                        <th>Modified</th>
                                        <th>Actions</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for log in logs %}
                                    <tr>
                                        <td>
                                            <span class="badge bg-primary">{{ log.service | title }}</span>
                                        </td>
                                        <td>
                                            <code>{{ log.name }}</code>
                                        </td>
                                        <td>{{ log.size_formatted }}</td>
                                        <td>{{ log.modified_time }}</td>
                                        <td>
                                            <div class="btn-group btn-group-sm">
                                                <a href="{{ url_for('view_log', filename=log.name) }}" 
                                                   class="btn btn-outline-primary">
                                                    <i class="fas fa-eye me-1"></i>View
                                                </a>
                                            </div>
                                            <div class="mt-1">
                                                <small class="text-muted">
                                                    <i class="fas fa-folder me-1"></i>
                                                    <code>{{ log.path }}</code>
                                                </small>
                                            </div>
                                        </td>
                                    </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            {% else %}
                <div class="text-center py-5">
                    <i class="fas fa-file-alt fa-4x text-muted mb-3"></i>
                    <h3 class="text-muted">No log files found</h3>
                    <p class="text-muted">
                        {% if filter_service %}
                            No log files found for service: <strong>{{ filter_service }}</strong>
                        {% else %}
                            No backup log files are available at this time.
                        {% endif %}
                    </p>
                    {% if filter_service %}
                    <a href="{{ url_for('logs_view') }}" class="btn btn-outline-primary">
                        <i class="fas fa-times me-1"></i>Clear Filter
                    </a>
                    {% endif %}
                </div>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}
