{% set isIndex = tmpl == 'index' ? true : false %}
{% set tmpl = 'list' %}

{% extends isIndex ? '@MauticCore/Default/content.html.twig' : '@MauticCore/Default/raw_output.html.twig' %}

{% block headerTitle %}{{ 'mautic.campaign.campaigns'|trans }}{% endblock %}


{% block content %}
  {% if isIndex %}
    <div id="page-list-wrapper" class="{% if items|length > 0 or searchValue is not empty %}panel {% endif %}panel-default">
        {%- set pageButtons = [] %}
        {% if permissions['campaign:campaigns:create'] %}
            {% if permissions['campaign:imports:create'] %}
                {% set pageButtons = pageButtons|merge([
                    {
                        'attr': {
                            'href': path('mautic_campaign_import_action', {'objectAction': 'new'}),
                            'data-toggle': '0',
                        },
                        'iconClass': 'ri-import-line',
                        'btnText': 'mautic.campaign.campaign.import',
                    }
                ]) %}
            {% endif %}
        {% endif %}

        {{- include('@MauticCore/Helper/list_toolbar.html.twig', {
            'searchValue': searchValue,
            'action': currentRoute,
            'actionRoute': actionRoute,
            'indexRoute': indexRoute,
            'translationBase': translationBase,
            'preCustomButtons': toolBarButtons|default(null),
            'templateButtons': {
                'delete': permissions[permissionBase~':delete'],
            },
            'filters': filters|default([]),
            'page_actions': {
                'templateButtons': {
                    'new': permissions['campaign:campaigns:create'],
                },
                'routeBase': 'campaign',
                'langVar': 'campaign.campaigns',
                'customButtons': pageButtons,
            },
            'bulk_actions': {
                'routeBase': 'campaign',
                'templateButtons': {
                    'delete': permissions['campaign:campaigns:deleteown'] or permissions['campaign:campaigns:deleteother'],
                },
            },
            'quickFilters': [
                {
                    'search': 'mautic.core.searchcommand.ispublished',
                    'label': 'mautic.core.form.active',
                    'tooltip': 'mautic.core.searchcommand.ispublished.description',
                    'icon': 'ri-check-line'
                },
                {
                    'search': 'mautic.core.searchcommand.isunpublished',
                    'label': 'mautic.core.form.inactive',
                    'tooltip': 'mautic.core.searchcommand.isunpublished.description',
                    'icon': 'ri-close-line'
                },
                {
                    'search': 'mautic.core.searchcommand.isuncategorized',
                    'label': 'mautic.core.form.uncategorized',
                    'tooltip': 'mautic.core.searchcommand.isuncategorized.description',
                    'icon': 'ri-folder-unknow-line'
                },
                {
                    'search': 'mautic.core.searchcommand.ismine',
                    'label': 'mautic.core.searchcommand.ismine.label',
                    'tooltip': 'mautic.core.searchcommand.ismine.description',
                    'icon': 'ri-user-line'
                },
                {
                    'search': 'mautic.campaign.campaign.searchcommand.isexpired',
                    'label': 'mautic.core.form.no_longer_available',
                    'tooltip': 'mautic.campaign.campaign.searchcommand.isexpired.description',
                    'icon': 'ri-time-line'
                },
                {
                    'search': 'mautic.campaign.campaign.searchcommand.ispending',
                    'label': 'mautic.core.form.not_yet_available',
                    'tooltip': 'mautic.campaign.campaign.searchcommand.ispending.description',
                    'icon': 'ri-timer-line'
                }
            ]
        }) -}}
        <div class="page-list">
            {{- customContent('content.above', _context) -}}
  {% endif %}

  {% if items|length > 0 %}
    <div class="table-responsive">
        <table class="table table-hover campaign-list" id="campaignTable">
          <thead>
            <tr>
                {{ include('@MauticCore/Helper/tableheader.html.twig', {
                    'checkall': 'true',
                    'target': '#campaignTable',
                }) }}

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

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

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

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

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

              {{- include('@MauticCore/Helper/tableheader.html.twig', {
                  'sessionVar': 'campaign',
                  'orderBy': 'c.id',
                  'text': 'mautic.core.id',
                  'class': 'visible-md visible-lg col-campaign-id',
              }) -}}
            </tr>
          </thead>
          <tbody>
            {% for item in items %}
                <tr>
                    <td>
                      {{- include('@MauticCore/Helper/list_actions.html.twig', {
                          'item': item,
                          'templateButtons' : {
                          'edit': securityHasEntityAccess(
                                permissions['campaign:campaigns:editown'],
                                permissions['campaign:campaigns:editother'],
                                item.createdBy
                              ),
                          'clone': permissions['campaign:campaigns:create'],
                          'export': enableExportPermission,
                          'delete': securityHasEntityAccess(
                                permissions['campaign:campaigns:deleteown'],
                                permissions['campaign:campaigns:deleteother'],
                                item.createdBy
                              ),
                          },
                          'routeBase': 'campaign',
                      }) -}}
                    </td>
                    <td>
                        <div>
                          {{ include('@MauticCore/Helper/publishstatus_icon.html.twig', {
                              'item': item,
                              'model': 'campaign',
                              'onclick': item.onclickMethod,
                              'attributes': item.dataAttributes,
                              'transKeys': item.translationKeysDataAttributes,
                          }) }}
                            <a href="{{ path('mautic_campaign_action', {'objectAction': 'view', 'objectId': item.id}) }}" data-toggle="ajax">
                                {{- item.name -}}
                                {{- customContent('campaign.name', _context|merge({'item': item})) -}}
                            </a>
                            {{ include('@MauticProject/Modules/projects.html.twig') }}
                        </div>

                        {{ include('@MauticCore/Helper/description--inline.html.twig', {
                            'description': item.description
                        }) }}

                    </td>
                    <td class="visible-md visible-lg">
                        {{ include('@MauticCore/Modules/category--expanded.html.twig', {'category': item.category}) }}
                    </td>
                    <td class="visible-md visible-lg" title="{{ item.dateAdded ? dateToFullConcat(item.dateAdded) : '' }}">
                        {{ item.dateAdded ? dateToDate(item.dateAdded) : '' }}
                    </td>
                    <td class="visible-md visible-lg" title="{{ item.dateModified ? dateToFullConcat(item.dateModified) : '' }}">
                        {{ item.dateModified ? dateToDate(item.dateModified) : '' }}
                    </td>
                    <td class="visible-md visible-lg">{{ item.createdByUser }}</td>
                    <td class="visible-md visible-lg">{{ item.id }}</td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>
    <div class="panel-footer">
        {{- include('@MauticCore/Helper/pagination.html.twig', {
            'totalItems': items|length,
            'page': page,
            'limit': limit,
            'menuLinkId': 'mautic_campaign_index',
            'baseUrl': path('mautic_campaign_index'),
            'sessionVar': 'campaign',
        }) -}}
    </div>
  {% else %}
    {% if searchValue is not empty %}
        {{- include('@MauticCore/Helper/noresults.html.twig', {'tip' : 'mautic.campaign.noresults.tip'}) -}}
    {% 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="mt-32 mb-md">
                    {% include '@MauticCore/Components/pictogram.html.twig' with {
                        'pictogram': 'ibm--automation-platform',
                        'size': '80'
                    } %}
                </div>
            {% endset %}

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

  {% if isIndex %}
            {{- customContent('content.below', _context) -}}
        </div>
    </div>

    {{ include('@MauticCore/Modules/protip.html.twig', {
        tip: random(['mautic.protip.campaigns.reengagement', 'mautic.protip.campaigns.survey', 'mautic.protip.campaigns.crosssell', 'mautic.protip.campaigns.onboarding'])
    }) }}
  {% endif %}
{% endblock %}
