{% extends "layout.html.twig" %}

{% block title %}Manage Borrow Requests - LocalLendables{% endblock %}

{% block content %}
    <section class="container pt-1 mt-1 mt-sm-3">
        <div class="row">
            <div class="col-12">

            </div>
        </div>

        <div class="row">
            <div class="col-12">
                <h1 class="giantish mb-4">Manage Borrow Requests</h1>
                
                {% if borrowRequests and borrowRequests|length > 0 %}
                    <div class="row">
                        {% for request in borrowRequests %}
                        <div class="col-12 col-md-6 col-lg-4 mb-4">
                            <div class="card h-100 {% if request.status == 'pending' %}border-warning{% elseif request.status == 'approved' %}border-success{% elseif request.status == 'rejected' %}border-danger{% endif %}">
                                <div class="card-header d-flex justify-content-between align-items-center">
                                    <span class="small fw-bold">{{ request.itemName }}</span>
                                    {% if request.status == 'pending' %}
                                        <span class="badge bg-warning text-dark">Pending</span>
                                    {% elseif request.status == 'approved' %}
                                        <span class="badge bg-success">Approved</span>
                                    {% elseif request.status == 'rejected' %}
                                        <span class="badge bg-danger">Rejected</span>
                                    {% endif %}
                                </div>
                                <div class="card-body">
                                    <div class="mb-2">
                                        <div class="small text-muted">Requested by:</div>
                                        <div class="small fw-bold">{{ request.borrowerName }}</div>
                                    </div>
                                    
                                    <div class="mb-2">
                                        <div class="small text-muted">Dates:</div>
                                        <div class="small">{{ request.startDate|date("M j") }} - {{ request.endDate|date("M j, Y") }}</div>
                                    </div>
                                    
                                    {% if request.message %}
                                    <div class="mb-3">
                                        <div class="small text-muted">Message:</div>
                                        <div class="midi">"{{ request.message }}"</div>
                                    </div>
                                    {% endif %}
                                    
                                    <div class="mb-2">
                                        <div class="small text-muted">Requested:</div>
                                        <div class="small">{{ request.createdAt|date("M j, Y g:i A") }}</div>
                                    </div>
                                    
                                    {% if request.expiresAt %}
                                    <div class="mb-3">
                                        <div class="small text-muted">Expires:</div>
                                        <div class="small text-danger">{{ request.expiresAt|date("M j, Y g:i A") }}</div>
                                    </div>
                                    {% endif %}
                                </div>
                                
                                {% if request.status == 'pending' %}
                                <div class="card-footer">
                                    <div class="d-flex gap-2">
                                        <form method="POST" action="/owner/requests/{{ request.id }}/approve" class="flex-fill">
                                            <button type="submit" class="btn btn-success btn-sm w-100 medium">
                                                Approve Request
                                            </button>
                                        </form>
                                        <form method="POST" action="/owner/requests/{{ request.id }}/reject" class="flex-fill">
                                            <button type="submit" class="btn btn-danger btn-sm w-100 medium">
                                                Reject Request
                                            </button>
                                        </form>
                                    </div>
                                    <div class="mt-2">
                                        <a href="/item/{{ request.itemId }}" class="btn btn-outline-primary btn-sm w-100 medium">
                                            View Item Details
                                        </a>
                                    </div>
                                </div>
                                {% endif %}
                            </div>
                        </div>
                        {% endfor %}
                    </div>
                {% else %}
                    <div class="text-center py-5">
                        <i class="fas fa-inbox fa-3x text-muted mb-3"></i>
                        <h3 class="medium text-muted">No borrow requests yet</h3>
                        <p class="small text-muted">When people request to borrow your items, they'll appear here.</p>
                        <a href="/browse" class="btn btn-primary medium">Browse All Items</a>
                    </div>
                {% endif %}
            </div>
        </div>
    </section>
{% endblock %}