{% extends 'base.html' %}

{% block title %}Suppliers{% endblock %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
    <h1 class="h3 mb-0">
        <i class="bi bi-truck me-2"></i>
        Suppliers
    </h1>
    <a href="#" class="btn btn-primary">
        <i class="bi bi-plus-circle me-2"></i>
        New Supplier
    </a>
</div>

<div class="card">
    <div class="card-body">
        {% if suppliers %}
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead class="table-light">
                        <tr>
                            <th>Code</th>
                            <th>Name</th>
                            <th>Contact Person</th>
                            <th>Email</th>
                            <th>Phone</th>
                            <th>Rating</th>
                            <th>Credit Limit</th>
                            <th>Status</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for supplier in suppliers %}
                        <tr>
                            <td>
                                <strong>{{ supplier.code }}</strong>
                            </td>
                            <td>{{ supplier.name }}</td>
                            <td>{{ supplier.contact_person|default:"N/A" }}</td>
                            <td>{{ supplier.email|default:"N/A" }}</td>
                            <td>{{ supplier.phone|default:"N/A" }}</td>
                            <td>
                                <span class="badge bg-{% if supplier.rating >= 4 %}success{% elif supplier.rating >= 3 %}warning{% else %}danger{% endif %}">
                                    {{ supplier.rating }}/5
                                </span>
                            </td>
                            <td>Rp {{ supplier.credit_limit|floatformat:0 }}</td>
                            <td>
                                <span class="badge bg-{% if supplier.is_active %}success{% else %}secondary{% endif %}">
                                    {{ supplier.is_active|yesno:"Active,Inactive" }}
                                </span>
                            </td>
                            <td>
                                <a href="{% url 'inventory:supplier_detail' supplier.pk %}" class="btn btn-sm btn-outline-primary">
                                    <i class="bi bi-eye"></i>
                                </a>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
            
            {% if is_paginated %}
            <nav aria-label="Page navigation" class="mt-4">
                <ul class="pagination justify-content-center">
                    {% if page_obj.has_previous %}
                        <li class="page-item">
                            <a class="page-link" href="?page={{ page_obj.previous_page_number }}">Previous</a>
                        </li>
                    {% endif %}
                    
                    <li class="page-item active">
                        <span class="page-link">Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}</span>
                    </li>
                    
                    {% if page_obj.has_next %}
                        <li class="page-item">
                            <a class="page-link" href="?page={{ page_obj.next_page_number }}">Next</a>
                        </li>
                    {% endif %}
                </ul>
            </nav>
            {% endif %}
        {% else %}
            <div class="text-center py-5">
                <i class="bi bi-truck display-1 text-muted"></i>
                <h4 class="mt-3 text-muted">No Suppliers Found</h4>
                <p class="text-muted">Start by adding your first supplier.</p>
                <a href="#" class="btn btn-primary">
                    <i class="bi bi-plus-circle me-2"></i>
                    Add Supplier
                </a>
            </div>
        {% endif %}
    </div>
</div>
{% endblock %}
