{# purpose of this template: routes list view #}
{% extends routeArea == 'admin' ? '@ZikulaRoutesModule/adminBase.html.twig' : '@ZikulaRoutesModule/base.html.twig' %}
{% block title own ? 'My custom routes'|trans : 'Custom routes list'|trans %}
{% block admin_page_icon 'list-alt' %}
{% block content %}
    <div class="zikularoutesmodule-route zikularoutesmodule-view">
        <div class="alert alert-warning">
            {% set title = 'JMSI18nRoutingBundle' %}
            {% set url = 'https://jmsyst.com/bundles/JMSI18nRoutingBundle/master/configuration' %}
            {% trans with {'%link%': '<a href="' ~ url ~ '">' ~ title ~ '</a>'|raw} %}Below you see your current routing configuration (see %link% for reference).{% endtrans %}
            {% set title = 'Localisation settings'|trans %}
            {% set url = path('zikulasettingsmodule_settings_locale') %}
            {% trans with {'%link%': '<a href="' ~ url ~ '">' ~ title ~ '</a>'|raw} %}You can change your routing configuration in the general settings: %link%.{% endtrans %}
            {% set title = 'reload installed languages'|trans %}
            {% set url = path('zikularoutesmodule_update_renew') %}
            {% trans with {'%action%': '<a href="' ~ url ~ '">' ~ title ~ '</a>'|raw} %}In case one or more installed languages are not listed below, %action%.{% endtrans %}
            <ul>
            {% for key, value in jms_i18n_routing %}
                <li><strong>{{ key }}:</strong> {{ value is iterable ? value|join(', ') : value }}</li>
            {% endfor %}
            </ul>
        </div>
        {% set viewActions = knp_menu_get('zikulaRoutesMenuViewActions', [], {objectType: 'route', area: routeArea}) %}
        {{ knp_menu_render(viewActions, {template: '@ZikulaMenuModule/Override/bootstrap_fontawesome.html.twig'}) }}

        {{ include('@ZikulaRoutesModule/Route/viewQuickNav.html.twig', {workflowStateFilter: false, schemesFilter: false, methodsFilter: false, sorting: false, pageSizeSelector: false}) }}{# see template file for available options #}

        {% if routeArea == 'admin' %}
        <form action="{{ path('zikularoutesmodule_route_' ~ routeArea ~ 'handleselectedentries') }}" method="post" id="routesViewForm">
            <div>
        {% endif %}
            {% set activateSortable = routeArea == 'admin' and sort.sort.class == 'sorted-asc' %}
            <div class="table-responsive">
            <table{% if activateSortable and items|length > 1 %} id="sortableTable" data-object-type="route" data-min="{{ items|first.sort }}" data-max="{{ items|last.sort }}"{% endif %} class="table table-striped table-bordered table-hover table-sm">
                <colgroup>
                    {% if routeArea == 'admin' %}
                        <col id="cSelect" />
                    {% endif %}
                    <col id="cItemActionsStart" />
                    {% if activateSortable %}
                        <col id="cSortable" />
                    {% endif %}
                    <col id="cBundle" />
                    <col id="cPath" />
                    <col id="cHost" />
                    <col id="cSchemes" />
                    <col id="cMethods" />
                    <col id="cPrependBundlePrefix" />
                    <col id="cTranslatable" />
                    <col id="cTranslationPrefix" />
                    <col id="cDescription" />
                </colgroup>
                <thead>
                <tr>
                    {% if routeArea == 'admin' %}
                        <th id="hSelect" scope="col" class="text-center">
                            <input type="checkbox" class="zikularoutes-mass-toggle" />
                        </th>
                    {% endif %}
                    <th id="hItemActionsStart" scope="col" class="">{% trans %}Actions{% endtrans %}</th>
                    {% if activateSortable %}
                        <th id="hSortable" scope="col" class="">{% trans %}Sorting{% endtrans %}</th>
                    {% endif %}
                    <th id="hBundle" scope="col" class="text-left">
                        <a href="{{ sort.bundle.url }}" title="{{ 'Sort by %fieldName%'|trans({'%fieldName%': 'bundle'})|e('html_attr') }}" class="{{ sort.bundle.class }}">{% trans %}Bundle{% endtrans %}</a>
                    </th>
                    <th id="hPath" scope="col" class="text-left">
                        <a href="{{ sort.path.url }}" title="{{ 'Sort by %fieldName%'|trans({'%fieldName%': 'path'})|e('html_attr') }}" class="{{ sort.path.class }}">{% trans %}Path{% endtrans %}</a>
                    </th>
                    <th id="hHost" scope="col" class="text-left">
                        <a href="{{ sort.host.url }}" title="{{ 'Sort by %fieldName%'|trans({'%fieldName%': 'host'})|e('html_attr') }}" class="{{ sort.host.class }}">{% trans %}Host{% endtrans %}</a>
                    </th>
                    <th id="hSchemes" scope="col" class="text-left">
                        <a href="{{ sort.schemes.url }}" title="{{ 'Sort by %fieldName%'|trans({'%fieldName%': 'schemes'})|e('html_attr') }}" class="{{ sort.schemes.class }}">{% trans %}Schemes{% endtrans %}</a>
                    </th>
                    <th id="hMethods" scope="col" class="text-left">
                        <a href="{{ sort.methods.url }}" title="{{ 'Sort by %fieldName%'|trans({'%fieldName%': 'methods'})|e('html_attr') }}" class="{{ sort.methods.class }}">{% trans %}Methods{% endtrans %}</a>
                    </th>
                    <th id="hPrependBundlePrefix" scope="col" class="text-center">
                        <a href="{{ sort.prependBundlePrefix.url }}" title="{{ 'Sort by %fieldName%'|trans({'%fieldName%': 'prepend bundle prefix'})|e('html_attr') }}" class="{{ sort.prependBundlePrefix.class }}">{% trans %}Prepend bundle prefix{% endtrans %}</a>
                    </th>
                    <th id="hTranslatable" scope="col" class="text-center">
                        <a href="{{ sort.translatable.url }}" title="{{ 'Sort by %fieldName%'|trans({'%fieldName%': 'translatable'})|e('html_attr') }}" class="{{ sort.translatable.class }}">{% trans %}Translatable{% endtrans %}</a>
                    </th>
                    <th id="hTranslationPrefix" scope="col" class="text-left">
                        <a href="{{ sort.translationPrefix.url }}" title="{{ 'Sort by %fieldName%'|trans({'%fieldName%': 'translation prefix'})|e('html_attr') }}" class="{{ sort.translationPrefix.class }}">{% trans %}Translation prefix{% endtrans %}</a>
                    </th>
                    <th id="hDescription" scope="col" class="text-left">
                        <a href="{{ sort.description.url }}" title="{{ 'Sort by %fieldName%'|trans({'%fieldName%': 'description'})|e('html_attr') }}" class="{{ sort.description.class }}">{% trans %}Description{% endtrans %}</a>
                    </th>
                </tr>
                </thead>
                <tbody>

            {% for route in items %}
                <tr{% if activateSortable %} data-item-id="{{ route.getKey() }}" class="sort-item"{% endif %}>
                    {% if routeArea == 'admin' %}
                        <td headers="hSelect" class="text-center">
                            <input type="checkbox" name="items[]" value="{{ route.getKey() }}" class="zikularoutes-toggle-checkbox" />
                        </td>
                    {% endif %}
                    <td id="itemActions{{ route.getKey() }}Start" headers="hItemActionsStart" class="actions">
                        {% set itemActions = knp_menu_get('zikulaRoutesMenuItemActions', [], {entity: route, area: routeArea, context: 'view'}) %}
                        <div class="dropdown item-actions">
                            <a id="itemActions{{ route.getKey() }}DropDownToggleStart" role="button" data-toggle="dropdown" href="javascript:void(0);" class="d-none dropdown-toggle"><i class="fas fa-tasks"></i></a>
                            {{ knp_menu_render(itemActions, {template: '@ZikulaMenuModule/Override/bootstrap_fontawesome.html.twig'}) }}
                        </div>
                    </td>
                    {% if activateSortable %}
                        <td headers="hSortable" class="text-center">
                            <i class="fas fa-arrows-alt sort-handle pointer" title="{{ 'Drag to reorder'|trans|e('html_attr') }}"></i>
                        </td>
                    {% endif %}
                    <td headers="hBundle" class="text-left">
                        <abbr title="{{ route.controller|e('html_attr') }} # {{ route.action|e('html_attr') }}">{{ route.bundle }}</abbr>
                    </td>
                    <td headers="hPath" class="text-left">
                        {{ route.path|zikularoutesmodule_pathToString(route) }}
                    </td>
                    <td headers="hHost" class="text-left">
                        {{ route.host }}
                    </td>
                    <td headers="hSchemes" class="text-left">
                        {{ route.schemes|zikularoutesmodule_listEntry('route', 'schemes') }}
                    </td>
                    <td headers="hMethods" class="text-left">
                        {{ route.methods|zikularoutesmodule_listEntry('route', 'methods') }}
                    </td>
                    <td headers="hPrependBundlePrefix" class="text-center">
                        {% if route.prependBundlePrefix %}
                            <i class="fas fa-check text-success" title="{{ 'Yes'|trans|e('html_attr') }}"></i>
                        {% else %}
                            <i class="fas fa-times text-danger" title="{{ 'No'|trans|e('html_attr') }}"></i>
                        {% endif %}
                    </td>
                    <td headers="hTranslatable" class="text-center">
                        {% if route.translatable %}
                            <i class="fas fa-check text-success" title="{{ 'Yes'|trans|e('html_attr') }}"></i>
                        {% else %}
                            <i class="fas fa-times text-danger" title="{{ 'No'|trans|e('html_attr') }}"></i>
                        {% endif %}
                    </td>
                    <td headers="hTranslationPrefix" class="text-left">
                        {{ route.translationPrefix }}
                    </td>
                    <td headers="hDescription" class="text-left">
                        {{ route.description|u.truncate(50, '…') }}
                    </td>
                </tr>
            {% else %}
                <tr class="table-info">
                    <td colspan="{% if routeArea == 'admin' %}12{% else %}10{% endif %}" class="text-center">
                {% trans %}No custom routes found.{% endtrans %}
                  </td>
                </tr>
            {% endfor %}

                </tbody>
            </table>
            </div>

            {% if all != 1 %}
                {{ include(paginator.template) }}
            {% endif %}
        {% if routeArea == 'admin' %}
                <fieldset class="my-3 pt-3">
                    <div class="row">
                        <label for="zikulaRoutesModuleAction" class="col-md-3 col-form-label">{% trans %}With selected routes{% endtrans %}</label>
                        <div class="col-md-6">
                            <select id="zikulaRoutesModuleAction" name="action" class="form-control form-control-sm">
                                <option value="">{% trans %}Choose action{% endtrans %}</option>
                                <option value="delete" title="{{ 'Delete content permanently.'|trans|e('html_attr') }}">{% trans %}Delete{% endtrans %}</option>
                            </select>
                        </div>
                        <div class="col-md-3">
                            <input type="submit" value="{{ 'Submit'|trans|e('html_attr') }}" class="btn btn-secondary btn-sm" />
                        </div>
                    </div>
                </fieldset>
            </div>
        </form>
        {% endif %}
    </div>
{% endblock %}
