{% extends "panel.html" %}
{% load i18n %}
{% load inventree_extras %}
{% load plugin_extras %}

{% block label %}plugin{% endblock label %}

{% block heading %}
{% trans "Plugin Settings" %}
{% endblock heading %}

{% block content %}

<div class='alert alert-block alert-danger'>
    {% trans "Changing the settings below require you to immediately restart the server. Do not change this while under active usage." %}
</div>

{% include "pui_banner.html" with mode='admin' %}

<div class='table-responsive'>
<table class='table table-striped table-condensed'>
    <tbody>
        {% include "InvenTree/settings/setting.html" with key="ENABLE_PLUGINS_SCHEDULE" icon="fa-calendar-alt" %}
        {% include "InvenTree/settings/setting.html" with key="ENABLE_PLUGINS_EVENTS" icon="fa-reply-all" %}
        {% include "InvenTree/settings/setting.html" with key="ENABLE_PLUGINS_URL" icon="fa-link" %}
        {% include "InvenTree/settings/setting.html" with key="ENABLE_PLUGINS_NAVIGATION" icon="fa-sitemap" %}
        {% include "InvenTree/settings/setting.html" with key="ENABLE_PLUGINS_APP" icon="fa-rocket" %}
        {% include "InvenTree/settings/setting.html" with key="PLUGIN_ON_STARTUP" %}
    </tbody>
</table>
</div>

{% plugins_enabled as plug %}
{% plugins_install_disabled as plug_disabled %}

<div class='panel-heading'>
    <div class='d-flex flex-wrap'>
        <h4>{% trans "Plugins" %}</h4>
        {% include "spacer.html" %}
        <div class='btn-group' role='group'>
            {% admin_url user "plugin.pluginconfig" None as url %}
            {% include "admin_button.html" with url=url %}
            {% if plug %}
            <button class="btn btn-success" id="install-plugin" title="{% trans 'Install Plugin' %}"{% if plug_disabled %}disabled{% endif %}>
                <span class='fas fa-plus-circle'></span> {% trans "Install Plugin" %}
            </button>
            <button class='btn btn-success' id='reload-plugins' title='{% trans "Reload Plugins" %}'>
                <span class='fas fa-redo-alt'></span> {% trans "Reload Plugins" %}
            </button>
            </button>
            {% endif %}
        </div>
    </div>
</div>

{% if not plug %}
<div class='alert alert-warning alert-block'>
    {% trans "External plugins are not enabled for this InvenTree installation" %}<br>
</div>
{% endif %}

<div id='plugin-button-toolbar'>
    {% include "filter_list.html" with id="plugins" %}
</div>
<div class='table-responsive'>
    <table class='table table-striped table-condensed' id='plugin-table' data-toolbar='#plugin-button-toolbar'></table>
</div>

{% plugin_errors as pl_errors %}
{% if pl_errors %}
<div class='panel-heading'>
    <div class='d-flex flex-wrap'>
        <h4>{% trans "Plugin Error Stack" %}</h4>
        {% include "spacer.html" %}
    </div>
</div>

<div class='table-responsive'>
    <table class='table table-striped table-condensed'>
        <thead>
            <tr>
                <th>{% trans "Stage" %}</th>
                <th>{% trans "Name" %}</th>
                <th>{% trans "Message" %}</th>
            </tr>
        </thead>

        <tbody>
        {% for stage, errors in pl_errors.items %}
            {% for error_detail in errors %}
            {% for name, message in error_detail.items %}
            <tr>
                <td>{{ stage }}</td>
                <td>{{ name }}</td>
                <td>{{ message }}</td>
            </tr>
            {% endfor %}
            {% endfor %}
        {% endfor %}
        </tbody>
    </table>
    </div>
{% endif %}

{% endblock content %}
