{#
  Variables
    - items
    - filters
    - form
    - viewOnlyFields
    - page
    - totalCount
    - limit
    - tmpl
    - canDelete
#}
{% set isIndex = 'index' == tmpl ? true : false %}
{% set tmpl = 'list' %}
{% extends isIndex ? '@MauticCore/Default/content.html.twig' : '@MauticCore/Default/raw_output.html.twig' %}

{% block mauticContent %}formresult{% endblock %}

{% block preHeader %}
{{ include('@MauticCore/Helper/page_actions.html.twig', {
    'templateButtons': {
        'close': true,
    },
    'routeBase': 'form',
    'langVar': 'form',
    'targetLabel': 'mautic.form.forms'|trans
}) }}
{% endblock %}

{% block headerTitle %}
  {{ 'mautic.form.result.header.index'|trans({'%name%': form.name}) }}
{% endblock %}

{% block actions %}
  {% set buttons = [] %}
    {% if enableExportPermission is not empty %}
        {% set buttons = buttons|merge([{
            'attr': {
                'target': '_new',
                'data-toggle': '',
                'class': 'btn btn-ghost btn-nospin',
                'href': path('mautic_form_export', {'objectId': form.id, 'format': 'html'}),
            },
            'btnText': 'mautic.form.result.export.html'|trans,
            'iconClass': 'ri-file-code-line',
            'primary': true,
        }]) %}

        {% set buttons = buttons|merge([{
            'attr': {
                'data-toggle': '',
                'class': 'btn btn-ghost btn-nospin',
                'href': path('mautic_form_export', {'objectId': form.id, 'format': 'csv'}),
            },
            'btnText': 'mautic.form.result.export.csv'|trans,
            'iconClass': 'ri-file-text-line',
            'primary': true,
        }]) %}

        {# This is q quick way to check if the class exists, if the class exists add this btn #}
        {% if constant('\\PhpOffice\\PhpSpreadsheet\\Spreadsheet::VISIBILITY_VISIBLE') is defined %}
            {% set buttons = buttons|merge([{
                'attr': {
                    'data-toggle': '',
                    'class': 'btn btn-ghost btn-nospin',
                    'href': path('mautic_form_export', {'objectId': form.id, 'format': 'xlsx'}),
                },
                'btnText': 'mautic.form.result.export.xlsx'|trans,
                'iconClass': 'ri-file-excel-line',
                'primary': true,
            }]) %}
        {% endif %}
    {% endif %}

  {% if securityHasEntityAccess('form:forms:editown', 'form:forms:editother', form.createdBy) %}
      {% set buttons = buttons|merge([{
          'attr': {
              'class': 'btn btn-ghost',
              'href': path('mautic_form_action', {'objectAction': 'edit', 'objectId': form.id}),
              'data-toggle': 'ajax',
          },
          'iconClass': 'ri-edit-line',
          'btnText': 'mautic.core.form.edit'|trans,
      }]) %}
  {% endif %}

  {{ include('@MauticCore/Helper/page_actions.html.twig', {'customButtons': buttons}) }}
{% endblock %}

{% block content %}
  <div class="page-list">
    {% set bulkActionsCustom = [
        {
            'attr': {
                'class': 'btn btn-ghost btn-sm btn-nospin',
                'data-toggle': 'ajaxmodal',
                'data-target': '#MauticSharedModal',
                'href': path('mautic_form_results_add_segment', {'objectId': form.id}),
                'data-header': 'mautic.form.result.add_to_segment'|trans,
            },
            'btnText': 'mautic.form.result.add_to_segment'|trans,
            'iconClass': 'ri-pie-chart-line',
        }
      ] %}
          {{- include('@MauticCore/Helper/list_toolbar.html.twig', {
        'bulk_actions': {
            'target': '#formResultTable',
            'templateButtons': {
                'delete': canDelete
            },
            'customButtons': bulkActionsCustom|default([]),
            'routeBase': 'form_results',
            'langVar': 'mautic.form.result',
            'query': {'formId': form.id},
        }
    }) -}}
    {{ include('@MauticForm/Result/_list.html.twig') }}
  </div>
{% endblock %}
