{% extends "base.html" %}
{% block title %}Manage All Apps{% endblock %}
{% block content %}
<div class="container mt-4">
    <h1>Manage All Apps</h1>
    {% if apps %}
        <table class="table table-hover">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Developer</th>
                    <th>Submitted By</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
                {% for app in apps %}
                    <tr>
                        <td>{{ app.name }}</td>
                        <td>{{ app.developer }}</td>
                        <td>{{ app.user.username if app.user else 'Unknown' }}</td>
                        <td>
                            <a href="{{ url_for('gallery.app_detail', app_id=app.id) }}" class="btn btn-primary btn-sm">View</a>
                            <a href="{{ url_for('gallery.edit_app', app_id=app.id) }}" class="btn btn-warning btn-sm">Edit</a>
                            <form action="{{ url_for('gallery.delete_app', app_id=app.id) }}" method="POST" class="d-inline">
                                <button type="submit" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure you want to delete {{ app.name }}?')">Delete</button>
                            </form>
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% else %}
        <p>No apps registered yet.</p>
    {% endif %}
</div>
{% endblock %}