{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Manage Rental Bikes | Robert's Bike Rentals</title>

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootswatch@5.3.2/dist/lux/bootstrap.min.css">
    <link rel="stylesheet" href="{% static 'styling/custom.css' %}">
</head>

<body class="bg-light">

    <nav class="navbar navbar-expand-lg navbar-dark bg-primary mb-4">
        <div class="container">
            <a class="navbar-brand" href="/home">Robert's Rentals</a>
            <div class="d-flex border-start ps-3">
                <a href="/home" class="btn btn-outline-light btn-sm me-2">Home</a>
                <a href="/about-roberts-rentals" class="btn btn-outline-light btn-sm me-2">About</a>
                <a href="/bike-accessories" class="btn btn-outline-light btn-sm me-2">Accessories</a>
                <a href="/bike/" class="btn btn-outline-light btn-sm me-2">Reserve</a>
                <a href="/accounts/login/" class="btn btn-secondary btn-sm">Log In</a>
            </div>
        </div>
    </nav>

    <div class="container">
        <header class="pb-3 mb-4 border-bottom">
            <h1 class="display-5 fw-bold text-dark">Manage Rental Bikes <small class="text-muted fs-6">[admin]</small></h1>
        </header>

        <div class="row align-items-md-stretch">
            <div class="col-md-5">
                <div class="card border-0 shadow-sm mb-4">
                    <img src="{% static 'img/close-up-bicycle-gears.jpg' %}" class="card-img-top img-fluid rounded" alt="Bicycle Gears">
                </div>
            </div>
            <div class="col-md-7">
                <div class="h-100 p-5 bg-white border rounded-3 shadow-sm">
                    <h2>Fleet Overview</h2>
                    <p>Use this administrative dashboard to monitor the status of our rental fleet. You can process returns for bikes currently checked out by customers.</p>
                    {% if status_message %}
                        <div class="alert alert-info">{{ status_message }}</div>
                    {% endif %}
                </div>
            </div>
        </div>

        <div class="card shadow-sm mt-4">
            <div class="card-body p-0">
                <div class="table-responsive">
                    <table class="table table-hover mb-0">
                        <thead class="table-dark">
                            <tr>
                                <th class="ps-4">Name</th>
                                <th>Description</th>
                                <th>Rental Price</th>
                                <th>Renter ID</th>
                                <th class="text-center">Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% if latest_question_list %}
                                {% for question in latest_question_list %}
                                    <tr class="align-middle">
                                        <td class="fw-bold ps-4">{{ question.name }}</td>
                                        <td>{{ question.description }}</td>
                                        <td><span class="badge bg-success">&euro; {{ question.rental_price }}</span></td>
                                        <td>
                                            {% if question.rented_user_id != 0 %}
                                                <span class="text-primary fw-bold">{{ question.rented_user_id }}</span>
                                            {% else %}
                                                <span class="text-muted small">Available</span>
                                            {% endif %}
                                        </td>
                                        <td class="text-center">
                                            {% if question.rented_user_id != 0 %}
                                                <a href="/bike/return/{{question.id}}/{{user.pk}}" class="btn btn-primary btn-sm px-3">
                                                    Return Bike
                                                </a>
                                            {% else %}
                                                <button type="button" class="btn btn-outline-secondary btn-sm disabled" disabled>
                                                    In Stock
                                                </button>
                                            {% endif %}
                                        </td>
                                    </tr>
                                {% endfor %}
                            {% else %}
                                <tr>
                                    <td colspan="5" class="text-center py-5 text-muted">
                                        <h3>No bikes are available.</h3>
                                    </td>
                                </tr>
                            {% endif %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>

        <footer class="pt-5 my-5 text-muted border-top text-center">
            Robert's Bike Rental created by <a href="https://github.com/gomsur" class="text-decoration-none">Robert</a>.
            <br>
            <small>Image by <a href="https://www.freepik.com" class="text-decoration-none">jcomp</a> on Freepik.</small>
        </footer>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
