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

{% 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 %}Plugins{% endtrans %}</li>
</ol>
{% endblock %}

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

<div class="col-md-12 settings-col">
    <div class="card settings">
        <div class="card-header settings-header">
            <span class="fa fa-puzzle-piece"></span> {% trans %}Manage Plugins{% endtrans %}
        </div>
        <div class="card-body settings-body">
            <div class="settings-content">
                <div class="settings-meta">
                    <div class="row settings-row">
                        <div class="col-md-4 col-sm-4 col-4 meta-item">{% trans %}Plugin{% endtrans %}</div>
                        <div class="col-md-4 col-sm-4 col-4 meta-item">{% trans %}Information{% endtrans %}</div>
                        <div class="col-md-4 col-sm-4 col-4 meta-item">{% trans %}Manage{% endtrans %}</div>
                    </div>
                </div>
                {% for plugin in plugins %}
                <div class="row settings-row hover with-border-bottom">
                    <div class="col-md-4 col-sm-4 col-4">
                    {{ plugin.name.title() }}
                    (
                    {%- if plugin.info.get('home_page') -%}
                        <a href="{{ plugin.info.get('home_page') }}">{{ plugin.info.get("name") }}</a>
                    {%- else -%}
                        {{ plugin.info.get("name") }}
                    {%- endif -%}
                    )

                    </div>
                    <div class="col-md-4 col-sm-4 col-4">
                        <div class="plugin-version">{% trans %}Version{% endtrans %}: {{ plugin.info.get('version') }}</div>
                        <div class="plugin-description">{{ plugin.info.get('summary') }}</div>
                        <div class="plugin-author">{% trans %}by{% endtrans %} {{ plugin.info.get('author') }}</div>
                    </div>
                    <div class="col-md-4 col-sm-4 col-4">
                        {% if not plugin.enabled %}
                        <form class="d-inline" method="post" action="{{ url_for('management.enable_plugin', name=plugin.name) }}">
                            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
                            <button class="btn btn-success">{% trans %}Enable{% endtrans %}</button>
                        </form>
                        {% else %}
                        <form class="d-inline" method="post" action="{{ url_for('management.disable_plugin', name=plugin.name) }}">
                            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
                            <button class="btn btn-warning">{% trans %}Disable{% endtrans %}</button>
                        </form>
                        {% endif %}

                        {% if plugin.is_installable and not plugin.is_installed %}

                            {{
                                action_confirm(
                                    id="plugin-inst-" ~ plugin.name,
                                    url=url_for('management.install_plugin', name=plugin.name),
                                    title=_("Install"),
                                    btn="btn btn-info",
                                    icon_only=False
                                )
                            }}

                        {% elif plugin.is_installable and plugin.is_installed %}

                            {{
                                action_confirm(
                                    id="plugin-uninst-" ~ plugin.name,
                                    url=url_for('management.uninstall_plugin', name=plugin.name),
                                    title=_("Uninstall"),
                                    btn="btn btn-danger",
                                    icon_only=False
                                )
                            }}

                        <a class="btn btn-outline-dark" href="{{ url_for('management.settings', plugin=plugin.name) }}">Settings</a>
                        {% endif %}
                    </div>
                </div>
                {% endfor %}
            </div>
        </div>
    </div>
</div>
{% include theme('_partials/confirm_dialog.html') %}
{% endblock %}
