{% extends "base.html" %}
{% load static %}
{% block title %}Brand Management{% endblock %}

{% block extra_css %}
    <link href="{% static 'assets/plugins/datatable/css/dataTables.bootstrap5.min.css' %}" rel="stylesheet" />
{% endblock %}

{% block content %}
<div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
    <div class="breadcrumb-title pe-3">Brand Management</div>
    <div class="ms-auto">
        <a href="{% url 'brand-create' %}" class="btn btn-primary">Add New Brand</a>
    </div>
</div>

<div class="card">
    <div class="card-body">
        <div class="table-responsive">
            <table id="brand_table" class="table table-striped table-bordered" style="width:100%">
                <thead>
                    <tr>
                        <th>Image</th>
                        <th>Name</th>
                        <th>Description</th>
                        <th>Status</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    {% for brand in brands %}
                    <tr>
                        <td>
                            {% if brand.brand_image %}
                                <img src="{{ brand.brand_image.url }}" alt="{{ brand.brand_name }}" width="50" height="50" class="rounded-circle">
                            {% else %}
                                <span class="text-muted">No Image</span>
                            {% endif %}
                        </td>
                        <td>{{ brand.brand_name }}</td>
                        <td>{{ brand.brand_description|truncatechars:50 }}</td>
                        <td>
                            {% if brand.status == 'active' %}
                                <span class="badge bg-success">Active</span>
                            {% else %}
                                <span class="badge bg-secondary">Inactive</span>
                            {% endif %}
                        </td>
                        <td>
                            <div class="d-flex gap-2">
                                <a href="{% url 'brand-edit' brand.pk %}" class="btn btn-sm btn-warning"><i class="bi bi-pencil"></i></a>
                                <form action="{% url 'brand-delete' brand.pk %}" method="post" onsubmit="return confirm('Are you sure you want to delete this brand?');">
                                    {% csrf_token %}
                                    <button type="submit" class="btn btn-sm btn-danger"><i class="bi bi-trash"></i></button>
                                </form>
                            </div>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_js %}
    <script src="{% static 'assets/plugins/datatable/js/jquery.dataTables.min.js' %}"></script>
    <script src="{% static 'assets/plugins/datatable/js/dataTables.bootstrap5.min.js' %}"></script>
    <script>
        $(document).ready(function() {
            $('#brand_table').DataTable();
        });
    </script>
{% endblock %}
