{#
  Variables
    - searchValue
    - items
    - totalItems
    - page
    - limit
    - permissions
    - security
    - tmpl
#}
{% if items|length > 0 %}
    <div class="table-responsive">
        <table class="table table-hover" id="formTable">
            <thead>
            <tr>
                {{ include('@MauticCore/Helper/tableheader.html.twig', {
                        'checkall': 'true',
                        'target': '#formTable',
                        'routeBase': 'form',
                        'templateButtons': {
                            'delete': permissions['form:forms:deleteown'] or permissions['form:forms:deleteother'],
                        },
                        'customButtons': [
                            {
                                'confirm': {
                                    'message': 'mautic.form.confirm_batch_rebuild'|trans,
                                    'confirmText': 'mautic.form.rebuild'|trans,
                                    'confirmAction': path('mautic_form_action', {'objectAction': 'batchRebuildHtml'}),
                                    'iconClass': 'fa ri-fw ri-refresh-line',
                                    'btnText': 'mautic.form.rebuild'|trans,
                                    'precheck': 'batchActionPrecheck',
                                    'confirmCallback': 'executeBatchAction',
                                },
                                'primary': true,
                            },
                        ],
                }) }}

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

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

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

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

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

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

                {{ include('@MauticCore/Helper/tableheader.html.twig', {
                        'sessionVar': 'form',
                        'orderBy': 'f.id',
                        'text': 'mautic.core.id',
                        'class': 'visible-md visible-lg col-form-id',
                }) }}
            </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['form:forms:editown'], permissions['form:forms:editother'], item.createdBy),
                                    'clone': permissions['form:forms:create'],
                                    'delete': securityHasEntityAccess(permissions['form:forms:deleteown'], permissions['form:forms:deleteother'], item.createdBy),
                                },
                                'routeBase': 'form',
                                'customButtons': [
                                    {
                                        'attr': {
                                            'data-toggle': '',
                                            'target': '_blank',
                                            'href': path('mautic_form_action', {'objectAction': 'preview', 'objectId': item.id}),
                                        },
                                        'iconClass': 'ri-eye-line',
                                        'btnText': 'mautic.form.form.preview',
                                    },
                                    {
                                        'attr': {
                                            'data-toggle': 'ajax',
                                            'href': path('mautic_form_action', {'objectAction': 'results', 'objectId': item.id}),
                                        },
                                        'iconClass': 'ri-list-view',
                                        'btnText': 'mautic.form.form.results',
                                    },
                                ],
                        }) }}
                    </td>
                    <td>
                        <div>
                            {{ include('@MauticCore/Helper/publishstatus_icon.html.twig', {'item': item, 'model': 'form.form'}) }}
                            <a href="{{ path('mautic_form_action', {'objectAction': 'view', 'objectId': item.id}) }}" data-toggle="ajax" data-menu-link="mautic_form_index">
                                {{ item.name }}
                                {% if 'campaign' == item.formType %}
                                    <span data-toggle="tooltip" title="{{ 'mautic.form.icon_tooltip.campaign_form'|trans }}"><i class="ri-fw ri-megaphone-fill fs-14"></i></span>
                                {% endif %}
                            </a>
                        </div>
                        {% if item.description %}
                            <div class="text-muted mt-4">
                                <small>{{ item.description|purify }}</small>
                            </div>
                        {% endif %}
                    </td>
                    <td class="visible-md visible-lg">
                        {% set category = item.category %}
                        {% set catName = category ? category.title : 'mautic.core.form.uncategorized'|trans %}
                        {% set color = category ? '#' ~ category.color : '' %}
                        <div class="d-flex ai-center gap-xs"><span class="label label-gray label-category" style="background: {{ color }};"> </span> {{ catName }}</div>
                    </td>
                    <td class="visible-md visible-lg">
                        <a href="{{ path('mautic_form_action', {'objectAction': '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">{% if item.dateAdded %}{{ dateToFull(item.dateAdded) }}{% endif %}</td>
                    <td class="visible-md visible-lg">{% if item.dateModified %}{{ dateToFull(item.dateModified) }}{% endif %}</td>
                    <td class="visible-md visible-lg">{{ item.createdByUser }}</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': totalItems,
                    'page': page,
                    'limit': limit,
                    'baseUrl': path('mautic_form_index'),
                    'sessionVar': 'form',
            }) }}
        </div>
    </div>
{% else %}
    {{ include('@MauticCore/Helper/noresults.html.twig', {'tip': 'mautic.form.noresults.tip'}) }}
{% endif %}
