{% extends "@FerienpassAdmin/page/tools/_settings.html.twig" %}
{% trans_default_domain 'admin' %}


{% set translationPrefix = app.request.get('_route')|split('_')[1] %}
{% set action = (app.request.get('_route')|split('.')|first)|split('_')[2] %}

{% block main %}


    {% set headline = "#{translationPrefix}.#{action}.title"|trans %}

    <div class="flex justify-between">

        <h1 class="text-gray-900 dark:text-gray-50 tracking-tight text-3xl font-extrabold">{{ (headline == "#{translationPrefix}.#{action}.title") ? "#{translationPrefix}.title"|trans : headline }}</h1>

        <div class="flex space-x-3 justify-end">

            {% block headline_actions %}

                {% if exports is defined %}

                    <twig:Admin:Dropdown>
                        <twig:block name="toggle">
                            <twig:Admin:Button variant="ghost" size="sm" title="Exportieren">
                                <span class="sr-only">Exportieren</span>
                                <span class="size-5 block" aria-hidden="true">
                                    <twig:ux:icon name="ph:export"/>
                                </span>
                            </twig:Admin:Button>
                        </twig:block>
                        <twig:block name="dropdown">
                            {% for format in exports %}
                                <twig:Admin:DropdownItem
                                        href="{{ path(app.current_route, app.request.query.all|merge(app.request.get('_route_params'))|merge({ '_suffix': ".#{format}" })) }}">
                                    {% set fileIcons = {'pdf': 'file-pdf', 'xlsx': 'file-xls', 'docx': 'file-doc', 'xml': 'file-code', 'csv': 'file-csv'} %}
                                    <span class="mr-1.5 h-5 w-5 text-gray-400 flex-shrink-0">{{ ux_icon('ph:'~(fileIcons[format]|default('file'))) }}</span>
                                    <span class="text-left leading-tight">{{ format|upper }}</span>
                                </twig:Admin:DropdownItem>
                            {% endfor %}
                        </twig:block>
                    </twig:Admin:Dropdown>

                {% endif %}

                {% if createUrl|default(null) is not null %}
                    <twig:Admin:Button href="{{ createUrl }}" variant="primary">
                        <span class="flex items-center space-x-1">
                            <span class="h-5 w-5">
                                <twig:ux:icon name="ph:plus"/>
                            </span>
                            <span>Neu anlegen</span>
                        </span>
                    </twig:Admin:Button>
                {% endif %}

            {% endblock %}

        </div>

    </div>


    {{ component('Admin:SearchableQueryableList', {
        qb: qb,
        routeName: app.current_route,
        routeParameters: app.current_route_parameters|merge(app.request.query.all),
        viewKey: 'admin_accessCodes',
        viewPathPrefix: '/admin/system/zugangscodes',
        config: {
            title: '{{ item.name|default("") }}',
            info: [
                "{{ item.codes|length }} Codes"
            ]
        }
    }) }}

{% endblock %}