{% set page_title = _("Forums") %}

{% extends theme("management/management_layout.html") %}

{% block breadcrumb %}
<ol class="breadcrumb flaskbb-breadcrumb">
    <li class="breadcrumb-item"><a href="{{ url_for('forum.index') }}">{% trans %}Forum{% endtrans %}</a></li>
    <li class="breadcrumb-item"><a href="{{ url_for('management.overview') }}">{% trans %}Management{% endtrans %}</a></li>
    <li class="breadcrumb-item active">{% trans %}Forums{% endtrans %}</li>
</ol>
{% endblock %}

{% block management_content %}
{%- from theme('_macros/pagination.html') import render_pagination -%}
{%- from theme('_macros/navigation.html') import navlink with context -%}
{%- from theme('_macros/form.html') import action_confirm -%}

<div class="col-md-3 settings-col">
    <div class="nav-sidebar">
        <ul class="nav">
        {{ navlink('management.forums', _("Manage Forums")) }}
        {{ navlink('management.add_forum', _("Add Forum")) }}
        {{ navlink('management.add_category', _("Add Category")) }}
        </ul>
    </div>
</div>

<div class="col-md-9 settings-col with-left-border">
    <div class="card settings">
        <div class="card-header settings-header">
            <span class="fa fa-comments"></span> {% trans %}Manage Forums{% endtrans %}
        </div>
        <div class="card-body settings-body">
            <div class="settings-content">
                {% for category in categories %}
                <div class="card category">
                    <div class="card-header category-header">
                        <div class="row">
                            <div class="col-auto me-auto">
                                <a href="{{ category.url }}"><strong>{{ category.title }}</strong></a>
                            </div>

                            <div class="col-auto">
                                <a class="btn btn-sm btn-outline-dark" href="{{ url_for('management.add_forum', category_id=category.id) }}">
                                    <span class="fas fa-plus"></span> {% trans %}Add Forum{% endtrans %}
                                </a>
                                <a class="btn btn-sm btn-outline-success" href="{{ url_for('management.edit_category', category_id = category.id) }}">
                                    <span class="fas fa-edit"></span> {% trans %}Edit Category{% endtrans %}
                                </a>

                                {{
                                    action_confirm(
                                        url=url_for('management.delete_category', category_id=category.id),
                                        title=_("Delete Category"),
                                        icon="far fa-trash-alt",
                                        btn="btn btn-sm btn-outline-danger",
                                        icon_only=False
                                    )
                                }}

                            </div>
                        </div>
                    </div>

                    <div class="card-body category-body">
                        <div class="category-meta row m-0 ps-0">
                            <div class="col-md-5 col-sm-5 col-8 forum-name">{% trans %}Forum{% endtrans %}</div>
                            <div class="col-md-2 col-sm-2 d-none d-sm-block forum-stats">{% trans %}Topics / Posts{% endtrans %}</div>
                            <div class="col-md-5 col-sm-5 col-4 forum-last-post"></div>
                        </div>
                        {% for forum in category.forums %}
                        <div class="row category-row hover">

                            {% if forum.external %}
                            <div class="col-md-5 col-sm-5 col-8 forum-info ps-2">
                                <div class="row">
                                    <!-- Icon -->
                                    <div class="col-md-1 col-sm-2 col-2 forum-status h-100">
                                        <span class="fas fa-external-link-alt forum-external"></span>
                                    </div>

                                    <div class="col-md-11 col-sm-10 col-10">
                                        <!-- Forum Name -->
                                        <div class="forum-name">
                                            <span class="forum-link">{% trans %}Link to{% endtrans %}:</span> <a href="{{ forum.url }}">{{ forum.title }}</a>
                                        </div>

                                        <!-- Forum Description -->
                                        <div class="forum-description">
                                            {{ forum.description|nonpost_markup }}
                                        </div>
                                    </div>
                                </div>
                            </div> <!-- end forum-info -->

                            <!-- Post Count -->
                            <div class="col-md-2 col-sm-2 d-none d-sm-block forum-posts">
                                - -
                            </div>

                            <!-- Forum Actions -->
                            <div class="col-md-5 col-sm-5 col-4 forum-last-post">
                                <div class="forum-actions float-end">
                                    <a class="btn btn-sm btn-success" href="{{ url_for('management.edit_forum', forum_id = forum.id) }}">
                                        <span class="fas fa-edit"></span> {% trans %}Edit Link{% endtrans %}
                                    </a>

                                    {{
                                        action_confirm(
                                            url=url_for('management.delete_forum', forum_id=forum.id),
                                            title=_("Delete Link"),
                                            icon="far fa-trash-alt",
                                            btn="btn btn-sm btn-danger",
                                            icon_only=False
                                        )
                                    }}

                                </div>
                            </div>
                            {% else %}
                            <div class="col-md-5 col-sm-5 col-8 forum-info ps-2">

                                <!-- Icon -->
                                <div class="forum-status h-100">
                                    {% if forum.locked %}
                                        <span class="fas fa-lock forum-locked"></span>
                                    {% else %}
                                        <span class="far fa-comments forum-read"></span>
                                    {% endif %}
                                </div>

                                <!-- Forum Name -->
                                <div class="forum-name">
                                    <a href="{{ forum.url }}">{{ forum.title }}</a>
                                </div>

                                <!-- Forum Description -->
                                <div class="forum-description">
                                    {{ forum.description|nonpost_markup }}
                                </div>

                                <!-- Forum Moderators -->
                                {% if forum.show_moderators %}
                                <div class="forum-moderators">
                                    {% trans %}Moderators{% endtrans %}:
                                    {% for moderator in forum.moderators %}
                                    <a href="{{ url_for('user.profile', username=moderator.username) }}">{{ moderator.username }}</a>{% if not loop.last %}, {% endif %}
                                    {% endfor %}
                                </div>
                                {% endif %}

                            </div> <!-- end forum-info -->

                            <!-- Post Count -->
                            <div class="col-md-2 col-sm-2 d-none d-sm-block forum-topics">
                                {{ forum.topic_count }} / {{ forum.post_count }}
                            </div>

                            <!-- Forum Actions -->
                            <div class="col-md-5 col-sm-5 col-4 forum-last-post">
                                <div class="forum-actions float-end">
                                    <a class="btn btn-sm btn-primary" href="{{ url_for('management.edit_forum', forum_id = forum.id) }}">
                                        <span class="fas fa-edit"></span> {% trans %}Edit Forum{% endtrans %}
                                    </a>

                                    {{
                                        action_confirm(
                                            url=url_for('management.delete_forum', forum_id=forum.id),
                                            title=_("Delete Forum"),
                                            icon="far fa-trash-alt",
                                            btn="btn btn-sm btn-danger",
                                            icon_only=False
                                        )
                                    }}

                                </div>
                            </div>

                        {% endif %} {# endif forum.external #}
                        </div> <!-- end category-content -->

                        {% endfor %}
                    </div>
                </div>
                {% endfor %}
            </div>
        </div>
    </div>
</div>
{% include theme('_partials/confirm_dialog.html') %}
{% endblock %}
