{% extends 'base.html.twig' %}
{% import "macros/widgets.html.twig" as widgets %}
{% import "macros/datatables.html.twig" as tables %}

{% block page_title %}{{ 'menu.plugin'|trans }}{% endblock %}
{% block page_actions %}
    {% set event = actions(app.user, 'plugins', 'index') %}
    {{ widgets.page_actions(event.actions) }}
{% endblock %}

{% block main %}

    {% if plugins|length == 0 %}
        {{ widgets.callout('warning', 'plugin.none_installed'|trans({}, 'plugins')) }}
    {% else %}

        {% set columns = {
            'name': {'class': 'alwaysVisible'},
            'version': {'class': ' w-min'},
            'description': {'class': 'hidden-xs'},
            'required_version': {'class': 'hidden-xs hidden-sm w-min'},
            'actions': {'class': 'actions alwaysVisible'},
        } %}

        {% set tableName = 'plugins' %}

        {{ tables.datatable_header(tableName, columns, null, {}) }}
        {% for plugin in plugins|sort((p1, p2) => p1.name|lower <=> p2.name|lower) %}
            <tr>
                <td class="{{ tables.data_table_column_class(tableName, columns, 'name') }}">
                    {% if plugin.id != plugin.name %}
                        <span data-toggle="tooltip" data-placement="top" title="{{ plugin.id }}">{{ plugin.name }}</span>
                    {% else %}
                        {{ plugin.name }}
                    {% endif %}
                </td>
                <td class="{{ tables.data_table_column_class(tableName, columns, 'version') }}">{{ widgets.label(plugin.metadata.version, 'primary') }}</td>
                <td class="{{ tables.data_table_column_class(tableName, columns, 'description') }}">{{ plugin.metadata.description }}</td>
                <td class="{{ tables.data_table_column_class(tableName, columns, 'required_version') }}">
                    {% if plugin.metadata.kimaiVersion > constant('App\\Constants::VERSION') %}
                        {{ widgets.label(plugin.metadata.kimaiVersion, 'danger') }}
                    {% elseif plugin.metadata.kimaiVersion < constant('App\\Constants::VERSION') %}
                        {{ widgets.label(plugin.metadata.kimaiVersion, 'warning') }}
                    {% else %}
                        {{ widgets.label(plugin.metadata.kimaiVersion, 'success') }}
                    {% endif %}
                </td>
                <td class="{{ tables.data_table_column_class(tableName, columns, 'actions') }}">
                    {% set event = actions(app.user, 'plugin', 'index', {'plugin': plugin}) %}
                    {{ widgets.table_actions(event.actions) }}
                </td>
            </tr>
        {% endfor %}
        {{ tables.data_table_footer(plugins) }}

    {% endif %}

{% endblock %}
