{#
  Variables
    - searchValue
    - items
    - categories
    - page
    - limit
    - permissions
    - model
    - tmpl
    - security
#}
{% if items|length > 0 %}
    <div class="table-responsive page-list">
        <table class="table table-hover pagetable-list" id="pageTable">
            <thead>
            <tr>
                {{ include('@MauticCore/Helper/tableheader.html.twig', {
                    'checkall': 'true',
                    'target': '#pageTable',
                }) }}

                {{ include('@MauticCore/Helper/tableheader.html.twig', {
                        'sessionVar': 'page',
                        'orderBy': 'p.title',
                        'text': 'mautic.core.title',
                        'class': 'col-page-title',
                }) }}

                {{ include('@MauticCore/Helper/tableheader.html.twig', {
                        'sessionVar': 'page',
                        'orderBy': 'c.title',
                        'text': 'mautic.core.category',
                        'class': 'visible-md visible-lg col-page-category',
                }) }}

                {{ include('@MauticCore/Helper/tableheader.html.twig', {
                        'sessionVar': 'page',
                        'orderBy': 'p.template',
                        'text': 'mautic.core.form.theme',
                        'class': 'visible-md visible-lg col-page-template',
                }) }}

                {{ include('@MauticCore/Helper/tableheader.html.twig', {
                        'sessionVar': 'page',
                        'orderBy': 'p.hits',
                        'text': 'mautic.page.thead.hits',
                        'class': 'col-page-hits visible-md visible-lg',
                }) }}

                {{ include('@MauticCore/Helper/tableheader.html.twig', {
                        'sessionVar': 'page',
                        'orderBy': 'p.dateAdded',
                        'text': 'mautic.lead.import.label.dateAdded',
                        'class': 'col-page-dateAdded visible-md visible-lg',
                }) }}

                {{ include('@MauticCore/Helper/tableheader.html.twig', {
                        'sessionVar': 'page',
                        'orderBy': 'p.dateModified',
                        'text': 'mautic.lead.import.label.dateModified',
                        'class': 'col-page-dateModified visible-md visible-lg',
                        'default': true,
                }) }}

                {{ include('@MauticCore/Helper/tableheader.html.twig', {
                        'sessionVar': 'page',
                        'orderBy': 'p.createdByUser',
                        'text': 'mautic.core.createdby',
                        'class': 'col-page-createdByUser visible-md visible-lg',
                }) }}

                {{ include('@MauticCore/Helper/tableheader.html.twig', {
                        'sessionVar': 'page',
                        'orderBy': 'submission_count',
                        'text': 'mautic.form.form.results',
                        'class': 'visible-md visible-lg col-page-submissions',
                }) }}

                {{ include('@MauticCore/Helper/tableheader.html.twig', {
                        'sessionVar': 'page',
                        'orderBy': 'p.id',
                        'text': 'mautic.core.id',
                        'class': 'col-page-id visible-md visible-lg',
                }) }}
            </tr>
            </thead>
            <tbody>
            {% for i in items %}
                {% set item = i[0] %}
                <tr>
                    <td>
                        {{ include('@MauticCore/Helper/list_actions.html.twig', {
                                'item': item,
                                'templateButtons': {
                                    'edit': securityHasEntityAccess(permissions['page:pages:editown'], permissions['page:pages:editother'], item.createdBy),
                                    'clone': permissions['page:pages:create'],
                                    'delete': securityHasEntityAccess(permissions['page:pages:deleteown'], permissions['page:pages:deleteother'], item.createdBy),
                                },
                                'routeBase': 'page',
                                'nameGetter': 'getTitle',
                                'customButtons': {
                                    'preview': {
                                        'attr': {
                                            'class': 'btn btn-ghost btn-sm btn-nospin',
                                            'href': path('mautic_page_preview', {'id': item.id}),
                                            'target': '_blank',
                                            'data-toggle': '',
                                        },
                                        'iconClass': 'ri-external-link-line',
                                        'btnText': 'mautic.core.open_link'|trans,
                                        'priority': 100
                                    },
                                    'results': {
                                        'attr': {
                                            'class': 'btn btn-ghost btn-sm btn-nospin',
                                            'href': path('mautic_page_results', {'objectId': item.id}),
                                            'data-toggle': 'ajax',
                                            'data-menu-link': 'mautic_form_index'
                                        },
                                        'iconClass': 'ri-bar-chart-line',
                                        'btnText': 'mautic.form.form.results'|trans,
                                        'priority': 80
                                    }
                                }|merge(not item.isPreferenceCenter ? {
                                    'copy': {
                                        'attr': {
                                            'data-copy': url('mautic_page_public', {'slug': item.alias}),
                                            'data-toggle': 'none',
                                        },
                                        'btnText': 'mautic.core.copy_page_link'|trans,
                                        'iconClass': 'ri-clipboard-line',
                                        'priority': 90
                                    }
                                } : {})
                        }) }}
                    </td>
                    <td>
                        {{ include('@MauticCore/Helper/publishstatus_icon.html.twig', {'item': item, 'model': 'page.page'}) }}
                        <a href="{{ path('mautic_page_action', {'objectAction': 'view', 'objectId': item.id}) }}" data-toggle="ajax">
                            {{ item.title }} ({{ item.alias }})
                            {% if item.isVariant or item.isTranslation or item.isPreferenceCenter or pageConfig.isDraftEnabled %}
                                <span>
                                    {% if item.isVariant %}
                                        <span data-toggle="tooltip" title="{{ 'mautic.core.icon_tooltip.ab_test'|trans }}">
                                            <i class="ri-fw ri-organization-chart"></i>
                                        </span>
                                    {% endif %}
                                    {% if item.isTranslation %}
                                        <span data-toggle="tooltip" title="{{ 'mautic.core.icon_tooltip.translation'|trans }}">
                                            <i class="ri-fw ri-translate"></i>
                                        </span>
                                    {% endif %}
                                    {% if item.isPreferenceCenter %}
                                        <span data-toggle="tooltip" title="{{ 'mautic.core.icon_tooltip.preference_center'|trans }}">
                                            <i class="ri-settings-5-line"></i>
                                        </span>
                                    {% endif %}
                                    {% if pageConfig.isDraftEnabled and item.hasDraft %}
                                        <span data-toggle="tooltip" title="{{ 'mautic.email.icon_tooltip.has_draft'|trans }}">
                                    <i class="fa fa-fw fa-file"></i>
                                </span>
                                    {% endif %}
                                </span>
                            {% endif %}
                        </a>
                        {{ customContent('page.name', _context) }}
                        {{ include('@MauticProject/Modules/projects.html.twig') }}
                    </td>
                    <td class="visible-md visible-lg">
                        {{ include('@MauticCore/Modules/category--expanded.html.twig', {'category': item.category}) }}
                    </td>
                    <td class="visible-md visible-lg">
                        {% if item.template %}
                            {{ getThemeName(item.template) }}
                        {% else %}
                            <span class="text-muted">{{ 'mautic.core.form.default'|trans }}</span>
                        {% endif %}
                    </td>
                    <td class="visible-md visible-lg">{{ item.hits }}</td>
                    <td class="visible-md visible-lg" title="{% if item.dateAdded %}{{ dateToFullConcat(item.dateAdded) }}{% endif %}">
                        {% if item.dateAdded %}{{ dateToDate(item.dateAdded) }}{% endif %}
                    </td>
                    <td class="visible-md visible-lg" title="{% if item.dateModified %}{{ dateToFullConcat(item.dateModified) }}{% endif %}">
                        {% if item.dateModified %}{{ dateToDate(item.dateModified) }}{% endif %}
                    </td>
                    <td class="visible-md visible-lg">{{ item.createdByUser }}</td>
                    <td class="visible-md visible-lg">
                        <a href="{{ path('mautic_page_results', {'objectId': item.id}) }}" data-toggle="ajax" data-menu-link="mautic_form_index" size="sm" class="label label-gray" {% if 0 == i.submission_count %}disabled="disabled"{% endif %}>
                            {{- 'mautic.form.form.viewresults'|trans({'%count%': i.submission_count}) -}}
                        </a>
                    </td>
                    <td class="visible-md visible-lg">{{ item.id }}</td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
        <div class="panel-footer">
            {{ include('@MauticCore/Helper/pagination.html.twig', {
                    'totalItems': items|length,
                    'page': page,
                    'limit': limit,
                    'menuLinkId': 'mautic_page_index',
                    'baseUrl': path('mautic_page_index'),
                    'sessionVar': 'page',
            }) }}
        </div>
    </div>
{% else %}
    {% if searchValue is not empty %}
        {{ include('@MauticCore/Helper/noresults.html.twig') }}
    {% else %}
        <div class="mt-80 col-md-offset-2 col-lg-offset-3 col-md-8 col-lg-5 height-auto">
            {% set childContainer %}
                <div class="mb-md">
                    {% include '@MauticCore/Components/pictogram.html.twig' with {
                        'pictogram': 'landing-page',
                        'size': '80'
                    } %}
                </div>
            {% endset %}

            {{ include('@MauticCore/Components/content-block.html.twig', {
                heading: 'mautic.page.contentblock.heading',
                subheading: 'mautic.page.contentblock.subheading',
                childContainer: childContainer,
            }) }}
        </div>
    {% endif %}
{% endif %}
