{######################################################################################################################}
{# METADATA #}
{######################################################################################################################}
{{ set_tplvar('baseId', el_uid()) }}
<script>
{% if filter %}
	{% if filter.sys_name %}
		pageMeta.url_fragment = '{{ url_fragment('agent_ticketsearch_runnamedfilter', {'filter_name': filter.sys_name}) }}';
	{% else %}
		pageMeta.url_fragment = '{{ url_fragment('agent_ticketsearch_runfilter', {'filter_id': filter.id}) }}';
	{% endif %}

	pageMeta.filter_id = {{filter_id}};
	pageMeta.fragmentClass = 'DeskPRO.Agent.PageFragment.List.TicketList';
	pageMeta.refreshUrl = '{{ path('agent_ticketsearch_runfilter', {'filter_id': filter_id}) }}?set_group_term={{ set_group_term }}&set_group_option={{ set_group_option }}&group_by={{ group_by }}&grouping_option={{ grouping_option }}&view_name={{ view_name }}';
	pageMeta.refreshSubgroupCounts = '{{ path('agent_ticketsearch_getsubgroupcounts') }}?filter_id={{ filter_id }}&set_group_term={{ set_group_term }}&set_group_option={{ set_group_option }}&group_by={{ group_by }}&grouping_option={{ grouping_option }}';
	pageMeta.viewTypeUrl = '{{ path('agent_ticketsearch_runfilter', {'filter_id': filter_id}) }}?set_group_term={{ set_group_term }}&set_group_option={{ set_group_option }}&group_by={{ group_by }}&grouping_option={{ grouping_option }}&view_type=$view_type&view_name={{ view_name }}';
	pageMeta.refreshCursorUrl = '{{ path('agent_ticketsearch_runfilter', {'filter_id': filter_id}) }}?set_group_term={{ set_group_term }}&set_group_option={{ set_group_option }}&group_by={{ group_by }}&grouping_option={{ grouping_option }}&view_type=json&cursor=$cursor&view_name={{ view_name }}';
	pageMeta.loadSingleUrl = '{{ path('agent_ticketsearch_singleticketrow', {'content_type': 'filter', 'content_id': filter_id|default('0')}) }}?ticket_id=$ticket_id&view_type=$view_type&view_name={{ view_name }}';
	pageMeta.resultTypeName = 'filter';
	pageMeta.resultTypeId = {{ filter.id|default(0) }};
{% elseif sla_id %}
	pageMeta.url_fragment = '{{ url_fragment('agent_ticketsearch_runsla', {'sla_id': sla_id, 'sla_status': sla_status}) }}';

	pageMeta.sla_id = {{sla_id}};
	pageMeta.sla_status = '{{ sla_status }}';
	pageMeta.sla_filter = '{{ sla_filter }}';
	pageMeta.fragmentClass = 'DeskPRO.Agent.PageFragment.List.TicketList';
	pageMeta.refreshUrl = '{{ path('agent_ticketsearch_runsla', {'sla_id': sla_id, 'sla_status': sla_status}) }}?set_group_term={{ set_group_term }}&set_group_option={{ set_group_option }}&group_by={{ group_by }}&grouping_option={{ grouping_option }}&view_name={{ view_name }}';
	pageMeta.refreshSubgroupCounts = '{{ path('agent_ticketsearch_getsubgroupcounts') }}?sla_id={{ sla_id }}&sla_status={{ sla_status }}&set_group_term={{ set_group_term }}&set_group_option={{ set_group_option }}&group_by={{ group_by }}&grouping_option={{ grouping_option }}';
	pageMeta.viewTypeUrl = '{{ path('agent_ticketsearch_runsla', {'sla_id': sla_id, 'sla_status': sla_status}) }}?set_group_term={{ set_group_term }}&set_group_option={{ set_group_option }}&group_by={{ group_by }}&grouping_option={{ grouping_option }}&view_type=$view_type&view_name={{ view_name }}';
	pageMeta.refreshCursorUrl = '{{ path('agent_ticketsearch_runsla', {'sla_id': sla_id, 'sla_status': sla_status}) }}?set_group_term={{ set_group_term }}&set_group_option={{ set_group_option }}&group_by={{ group_by }}&grouping_option={{ grouping_option }}&view_type=json&cursor=$cursor&view_name={{ view_name }}';
	pageMeta.loadSingleUrl = '{{ path('agent_ticketsearch_singleticketrow', {'content_type': 'sla', 'content_id': sla_id|default('0')}) }}?ticket_id=$ticket_id&view_type=$view_type&view_name={{ view_name }}';
	pageMeta.resultTypeName = 'sla';
	pageMeta.resultTypeId = {{ sla_id|default(0) }};

{% else %}
	pageMeta.cache_id = {{cache_id}};
	pageMeta.fragmentClass = 'DeskPRO.Agent.PageFragment.List.TicketList';
	pageMeta.refreshUrl = '{{ path('agent_ticketsearch_runcustomfilter', {'cache_id': cache_id}) }}?set_group_term={{ set_group_term }}&set_group_option={{ set_group_option }}&group_by={{ group_by }}&grouping_option={{ grouping_option }}';
	pageMeta.viewTypeUrl = '{{ path('agent_ticketsearch_runcustomfilter', {'cache_id': cache_id}) }}?set_group_term={{ set_group_term }}&set_group_option={{ set_group_option }}&group_by={{ group_by }}&grouping_option={{ grouping_option }}&view_type=$view_type&view_name={{ view_name }}';
	pageMeta.refreshCursorUrl = '{{ path('agent_ticketsearch_runcustomfilter', {'cache_id': cache_id}) }}?set_group_term={{ set_group_term }}&set_group_option={{ set_group_option }}&group_by={{ group_by }}&grouping_option={{ grouping_option }}&view_type=json&cursor=$cursor&view_name={{ view_name }}';
	pageMeta.loadSingleUrl = '{{ path('agent_ticketsearch_singleticketrow', {'content_type': 'filter', 'content_id': filter_id|default('0')}) }}?ticket_id=$ticket_id&view_type=$view_type&view_name={{ view_name }}';

	pageMeta.resultTypeName = 'basic';
	pageMeta.resultTypeId = 'general';
{% endif %}
{% if not tickets %}
	pageMeta.noResults = true;
{% endif %}
pageMeta.fetchResultsUrl = '{{ path('agent_ticketsearch_getpage') }}';

{% if filter.sys_name == 'agent' %}pageMeta.groupingIgnore=["agent","agent_team"];{% endif %}
{% if filter.sys_name == 'agent_team' %}pageMeta.groupingIgnore=["agent","agent_team"];{% endif %}
{% if filter.sys_name == 'unassigned' %}pageMeta.groupingIgnore=["agent"];{% endif %}

pageMeta.perPage = {{ per_page }};
pageMeta.currentPage = {{ page|default(1) }};
pageMeta.ticketResultIds = {{ ticket_ids|json_encode|raw }};
pageMeta.display_fields = {{ display_fields|json_encode|raw }};
pageMeta.view_name = '{{ view_name }}';

{% if set_group_term  %}
	pageMeta.topGroupingTerm = '{{ set_group_term }}';
	pageMeta.topGroupingOption = '{{ set_group_option }}';
{% endif %}

{% if group_by %}
	pageMeta.groupBy = '{{ group_by }}';
	pageMeta.groupByOption = '{{ grouping_option }}';
{% endif %}

pageMeta.orderBy    = '{{ order_by[0] }}';
pageMeta.orderByDir = '{{ order_by[1] }}';

pageMeta.baseId = '{{ tplvars.baseId }}';
</script>
<script id="{{ tplvars.baseId }}_ticket_json" type="application/json">{{ ticket_json|raw }}</script>
<script id="{{ tplvars.baseId }}_ticket_ids_json" type="application/json">{{ all_ticket_ids|json_encode|raw }}</script>
<div id="{{ tplvars.baseId }}_ng_attach">{% include 'AgentBundle:TicketSearch:ticket-list.html.twig' %}</div>