{% extends "layouts/base.html" %}
{% load i18n %}

{% block title %}{% trans "Acknowledgement Content" %}{% endblock %}

{% block content %}
<div class="container-fluid py-4">
    <!-- Page Header -->
    <div class="row mb-4">
        <div class="col-12">
            <div class="d-flex justify-content-between align-items-center">
                <div>
                    <h1 class="h3 mb-2">
                        <i class="bi bi-book me-2"></i>
                        {% trans "Acknowledgement Content Management" %}
                    </h1>
                    <p class="text-muted mb-0">
                        {% trans "Manage educational content for onboarding wizard" %}
                    </p>
                </div>
                <button type="button" class="btn btn-primary">
                    <i class="bi bi-plus me-2"></i>
                    {% trans "Add Content" %}
                </button>
            </div>
        </div>
    </div>

    <!-- Content List -->
    <div class="card shadow-sm">
        <div class="card-header bg-white py-3">
            <div class="d-flex justify-content-between align-items-center">
                <h5 class="mb-0">
                    <i class="bi bi-list me-2"></i>
                    {% trans "Content Sections" %}
                </h5>
                <div class="input-group" style="max-width: 300px;">
                    <input type="text" class="form-control" id="searchInput" placeholder="{% trans 'Search content...' %}">
                    <button class="btn btn-outline-secondary" type="button">
                        <i class="bi bi-search"></i>
                    </button>
                </div>
            </div>
        </div>
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover mb-0 align-middle" id="contentTable">
                    <thead class="table-light">
                        <tr>
                            <th width="50">{% trans "Icon" %}</th>
                            <th>{% trans "Title" %}</th>
                            <th>{% trans "Role" %}</th>
                            <th>{% trans "Order" %}</th>
                            <th>{% trans "Status" %}</th>
                            <th>{% trans "Created" %}</th>
                            <th>{% trans "Actions" %}</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for content in content_list %}
                        <tr>
                            <td class="text-center">
                                {% if content.icon %}
                                    <i class="{{ content.icon }} fa-lg text-{{ content.color|default:'primary' }}"></i>
                                {% else %}
                                    <i class="bi bi-file-text fa-lg text-muted"></i>
                                {% endif %}
                            </td>
                            <td>
                                <strong>{{ content.title_en }}</strong>
                                {% if content.code %}
                                    <span class="badge bg-light text-muted ms-2">{{ content.code }}</span>
                                {% endif %}
                            </td>
                            <td>
                                {% if content.role %}
                                    <span class="badge bg-info text-dark">
                                        {{ content.get_role_display }}
                                    </span>
                                {% else %}
                                    <span class="badge bg-secondary">{% trans "All Roles" %}</span>
                                {% endif %}
                            </td>
                            <td>{{ content.order }}</td>
                            <td>
                                {% if content.is_active %}
                                    <span class="badge bg-success">
                                        <i class="bi bi-check me-1"></i>
                                        {% trans "Active" %}
                                    </span>
                                {% else %}
                                    <span class="badge bg-secondary">
                                        <i class="bi bi-x me-1"></i>
                                        {% trans "Inactive" %}
                                    </span>
                                {% endif %}
                            </td>
                            <td>
                                <small>{{ content.created_at|date:"M d, Y" }}</small>
                            </td>
                            <td>
                                <div class="btn-group" role="group">
                                    <button class="btn btn-sm btn-outline-primary" title="{% trans 'Edit' %}">
                                        <i class="bi bi-pencil"></i>
                                    </button>
                                    <button class="btn btn-sm btn-outline-danger" title="{% trans 'Delete' %}">
                                        <i class="bi bi-trash"></i>
                                    </button>
                                </div>
                            </td>
                        </tr>
                        {% empty %}
                        <tr>
                            <td colspan="7" class="text-center py-5">
                                <i class="bi bi-folder2-open fa-3x text-muted mb-3"></i>
                                <p class="text-muted mb-0">
                                    {% trans "No content found" %}
                                </p>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<script>
// Search functionality
document.getElementById('searchInput').addEventListener('keyup', function() {
    const searchValue = this.value.toLowerCase();
    const table = document.getElementById('contentTable');
    const rows = table.getElementsByTagName('tr');
    
    for (let i = 1; i < rows.length; i++) {
        const row = rows[i];
        const cells = row.getElementsByTagName('td');
        let found = false;
        
        for (let j = 0; j < cells.length; j++) {
            const cellText = cells[j].textContent.toLowerCase();
            if (cellText.includes(searchValue)) {
                found = true;
                break;
            }
        }
        
        row.style.display = found ? '' : 'none';
    }
});
</script>
{% endblock %}
