{% extends 'base.html' %}
{% load static %}

{% block title %}{{ project_name }} - Catalog{% endblock %}

{% block content %}
<div class="container mt-5">
    <div class="d-flex justify-content-between align-items-center mb-5">
        <div class="text-center flex-grow-1">
            <h1 class="display-4">Public Library Catalog</h1>
            <p class="lead">Browse our collection of available books.</p>
        </div>
        <div>
            <a href="{% url 'add_book' %}" class="btn btn-primary me-2">Add Book</a>
            <a href="{% url 'transactions' %}" class="btn btn-info">View Transactions</a>
        </div>
    </div>

    <div class="table-responsive">
        <table class="table table-striped table-hover">
            <thead class="table-dark">
                <tr>
                    <th scope="col">Title</th>
                    <th scope="col">Author</th>
                    <th scope="col">ISBN</th>
                    <th scope="col">Available Copies</th>
                    <th scope="col">Actions</th>
                </tr>
            </thead>
            <tbody>
                {% for book in books %}
                <tr>
                    <td>{{ book.title }}</td>
                    <td>{{ book.author }}</td>
                    <td>{{ book.isbn }}</td>
                    <td>{{ book.available_copies }} / {{ book.total_copies }}</td>
                    <td>
                        {% if book.available_copies > 0 %}
                            <a href="{% url 'issue_book' book.id %}" class="btn btn-success btn-sm">Issue</a>
                        {% else %}
                            <button class="btn btn-secondary btn-sm" disabled>Issue</button>
                        {% endif %}
                    </td>
                </tr>
                {% empty %}
                <tr>
                    <td colspan="5" class="text-center">No books available at the moment.</td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</div>
{% endblock %}
