{% extends "base.html" %}
{% load static %}
{% block title %}Tag 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">Tag Management</div>
</div>

<div class="row">
    <hr>
    <div class="card">
        <div class="card-body">
            <div class="table-responsive">
                <table id="tag_management_table" class="table table-striped table-bordered table-hover align-middle" style="width:100%">
                    <thead>
                        <tr>
                            <th>Booking ID</th>
                            <th>Customer Name </th>
                            <th>Total Quantity</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for booking in bookings %}
                        <tr>
                            <td>{{ booking.booking_id|default:'-' }}</td>
                            <td>
                                {{ booking.user.first_name }} {{ booking.user.last_name }}
                                <br>
                                <small class="text-muted">{{ booking.contact_mobile }}</small>
                            </td>
                            <td>{{ booking.total_quantity }}</td>
                            <td>
                                <div class="d-flex gap-2">
                                    <a href="{% url 'booking-tags' booking.id %}" class="btn btn-sm btn-info" title="View Tags">
                                        <i class="bi bi-eye"></i> View / Edit Tags
                                    </a>
                                    <a href="{% url 'booking-edit' booking.id %}" class="btn btn-sm btn-warning" title="Edit Tags">
                                        <i class="bi bi-pencil"></i> Edit Booking
                                    </a>
                                </div>
                            </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() {
            $('#tag_management_table').DataTable({
                dom: 'Bfrtip',
                buttons: [
                    { extend: 'csv', exportOptions: { columns: ':not(:last-child)' } },
                    { extend: 'pdf', exportOptions: { columns: ':not(:last-child)' } },
                ]
            });
        });
    </script>
{% endblock %}
