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

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

{% block muaticContent %}category
{% endblock %}
{% block headerTitle %}
	{% trans %}mautic.category.header.index{% endtrans %}
{% endblock %}

{% block content %}
	{% if isIndex %}
		<div id="page-list-wrapper" class="{% if items|length > 0 or searchValue is not empty %}panel {% endif %}panel-default">
			{# //TODO - Restore these buttons to the listactions when custom content is supported #}
			{# <div class="btn-group">
                    <button type="button" class="btn btn-ghost"><i class="ri-upload-line"></i></button>
                    <button type="button" class="btn btn-ghost"><i class="ri-archive-2-line"></i></button>
                </div> #}
            {{- include('@MauticCore/Helper/list_toolbar.html.twig', {
                'searchValue': searchValue,
                'filters': {
                    'bundle': {
                        'options': categoryTypes,
                        'values': {0: bundle},
                        'translateLabels': true,
                    },
                },
                'action': currentRoute,
                'page_actions': {
                    'templateButtons': {
                        'new': permissions[permissionBase ~ ":create"]
                    },
                    'routeBase': 'category',
                    'query': {
                        'bundle': bundle,
                        'show_bundle_select': true,
                    },
                    'editMode': 'ajaxModal',
                    'editAttr': {
                        'data-target': '#MauticSharedModal',
                        'data-header': 'mautic.category.header.new'|trans,
                        'data-toggle': 'ajaxmodal',
                    },
                },
                'bulk_actions': {
                    'routeBase': 'category',
                    'templateButtons': {
                        'delete': permissions[permissionBase ~ ':delete']
                    },
                    'query': {
                        'bundle': bundle
                    }
                },
                'quickFilters': [
                    {
                        'search': 'mautic.core.searchcommand.ispublished',
                        'label': 'mautic.core.form.available',
                        'tooltip': 'mautic.core.searchcommand.ispublished.description',
                        'icon': 'ri-check-line'
                    },
                    {
                        'search': 'mautic.core.searchcommand.isunpublished',
                        'label': 'mautic.core.form.unavailable',
                        'tooltip': 'mautic.core.searchcommand.isunpublished.description',
                        'icon': 'ri-close-line'
                    }
                ]
            }) -}}
            <div class="page-list">
                {{ block('listResults') }}
			</div>
		</div>
	{% else %}
		{{ block('listResults') }}
	{% endif %}

{% endblock %}


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

						{{- include(
                        '@MauticCore/Helper/tableheader.html.twig',
                            {
                                'sessionVar' :  'category',
                                'text'       :  '',
                                'class'      :  'col-category-color',
                            }
                        ) -}}

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

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

						{{- include('@MauticCore/Helper/tableheader.html.twig', {
                            'sessionVar' :  'category',
                            'orderBy'    :  'c.id',
                            'text'       :  'mautic.core.id',
                            'class'      :  'visible-md visible-lg col-page-id',
                        }) -}}
					</tr>
				</thead>
				<tbody>
					{% for item in items %}
						<tr>
							<td>
								{% set title = 'mautic.category.header.edit'|trans({'%type%' :  ('mautic.' ~ item.getBundle() ~ '.' ~ item.getBundle())|trans, '%name%' :  item.getTitle()}) %}
								{{- include('@MauticCore/Helper/list_actions.html.twig', {
                                'item'            :  item,
                                'templateButtons' :  {
                                    'edit'   :  permissions[permissionBase ~ ':edit'],
                                    'delete' :  permissions[permissionBase ~ ':delete'],
                                },
                                'editMode' :  'ajaxmodal',
                                'editAttr' :  {
                                    'data-target' :  '#MauticSharedModal',
                                    'data-header' :  title,
                                    'data-toggle' :  'ajaxmodal',
                                },
                                'routeBase' :  'category',
                                'query'     :  {
                                    'bundle' :  bundle,
                                },
                            }) -}}
							</td>
							<td>
								{% set color = item.getColor() %}
								<span class="label label-gray label-category" style="background: {{ '#' not in color ? '#' : ''}}{{ color }};"> </span>
							</td>
							<td>
                                <div>
                                    {{- include('@MauticCore/Helper/publishstatus_icon.html.twig',
                                        {'item' :  item, 'model' :  'category', 'query' :  'bundle=' ~ bundle}) -}}
                                    {% if permissions[permissionBase ~ ':edit'] %}
                                        <a href="{{ path('mautic_category_action',
                                            {'bundle' :  bundle, 'objectAction' :  'edit', 'objectId' :  item.getId()}) }}" data-toggle="ajaxmodal" data-target="#MauticSharedModal" data-header="{{ title }}"
                                    {% endif %}
                                    <span>{{ item.getTitle() }} ({{ item.getAlias() }})</span>
                                    {% if permissions[permissionBase ~ ':edit'] %}
                                        </a>
                                    {% endif %}
                                    {{ customContent('category.name', _context) }}
                                </div>
                                {% set description = item.getDescription() %}
                                {{ include('@MauticCore/Helper/description--inline.html.twig', {
                                    'description': item.description
                                }) }}
                            </td>
                            <td class="visible-md visible-lg">
                                {% if categoryTypes[item.getBundle()] is defined %}
                                    {{ categoryTypes[item.getBundle()]|trans }}
                                {% endif %}
                            </td>
                            <td class="visible-md visible-lg">{{ item.getId() }}</td>
						</tr>
                        {% endfor %}
					</table>
					<div class="panel-footer">
						{{- include('@MauticCore/Helper/pagination.html.twig',
                {
                    'totalItems' :  items|length,
                    'page'       :  page,
                    'limit'      :  limit,
                    'menuLinkId' :  'mautic_category_index',
                    'baseUrl'    :  path(
                        'mautic_category_index',
                        {
                            'bundle' :  ('category' == bundle) ? 'all' : bundle,
                        }
                    ),
                    'sessionVar' :  'category',
                }) -}}</div>
				</tbody>
			</div>
		{% else %}
            {% if searchValue is not empty %}
                {{- include('@MauticCore/Helper/noresults.html.twig', {'tip' : 'mautic.category.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': 'folder',
                                'size': '80'
                            } %}
                        </div>
                    {% endset %}
        
                    {{ include('@MauticCore/Components/content-block.html.twig', {
                        heading: 'mautic.category.contentblock.heading',
                        subheading: 'mautic.category.contentblock.subheading',
                        copy: 'mautic.category.contentblock.copy',
                        childContainer: childContainer,
                    }) }}
                </div>
            {% endif %}
		{% endif %}
	{% endblock %}
