{% extends "base.html" %}
{% load static %}
{% block title %}Banner 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-1 justify-content-between">
    <div class="breadcrumb-title pe-3">Banner Management</div>
    <a href="{% url 'banner-create' %}" class="btn btn-success ms-auto">Add Banner</a>
</div>
<div class="row">
    <hr>
    <div class="card">
        <div class="card-body">
            <div class="table-responsive">
                <table id="banner_management" class="table table-striped table-bordered" style="width:100%">
                    <thead>
                        <tr>
                            <th>Title</th>
                            <th>Description</th>
                            <th>Image</th>
                            <th>Status</th>
                            <th>Created</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for banner in banners %}
                        <tr>
                            <td>{{ banner.title }}</td>
                            <td>{{ banner.description }}</td>
                            <td>{% if banner.image %}<img src="{{ banner.image.url }}" width="60" style="object-fit:cover;max-height:60px;max-width:100px;border-radius:4px;">{% endif %}</td>
                            <td>
                                {% if banner.status == 'active' %}
                                    <span class="badge bg-success">Active</span>
                                {% else %}
                                    <span class="badge bg-secondary">Inactive</span>
                                {% endif %}
                            </td>
                            <td>{{ banner.created_at }}</td>
                            <td>
                                <a href="{% url 'banner-view' banner.id %}" class="btn btn-info btn-sm" title="View">
                                    <i class="bi bi-eye"></i>
                                </a>
                                <a href="{% url 'banner-edit' banner.id %}" class="btn btn-warning btn-sm" title="Edit">
                                    <i class="bi bi-pencil"></i>
                                </a>
                                <form method="post" action="{% url 'banner-delete' banner.id %}" style="display:inline;">
                                    {% csrf_token %}
                                    <button type="submit" class="btn btn-danger btn-sm" title="Delete" onclick="return confirm('Are you sure you want to delete this banner?');">
                                        <i class="bi bi-trash"></i>
                                    </button>
                                </form>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </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 () {
        $('#banner_management').DataTable();
    });
</script>
{% endblock %}
