<script>
pageMeta.fragmentClass = 'DeskPRO.Agent.PageFragment.SettingsPage.FilterEdit';

{% if filter %}
pageMeta.terms = {{filter.terms|json_encode|raw}};
{% endif %}

{% set baseId = el_uid() %}
pageMeta.baseId = '{{ baseId }}';
</script>
<header>
	<span class="close close-trigger">{{ phrase('agent.general.close_lc') }}</span>
	<div style="float:right; position: relative; right: 37px; top: 6px;">
		<button class="clean-white" id="{{baseId}}_delete_btn" data-delete-url="{{ path('agent_settings_ticketfilters_del', { 'filter_id': filter.id }) }}" data-filter-id="{{ filter.id }}">{{ phrase('agent.settings.delete_filter') }}</button>
	</div>
	<h1>{% if filter.id %}{{ phrase('agent.settings.edit_filter') }}{% else %}{{ phrase('agent.general.new_filter') }}{% endif %}</h1>
</header>
<article class="padded" data-width="1100" data-height="400">
	<form id="{{baseId}}_form" action="{{ path('agent_settings_ticketfilters_edit_save', { 'filter_id': filter.id|default(0) }) }}" method="post" accept-charset="utf-8">

	<div class="dp-form">
		<div class="dp-form-row">
			<div class="dp-form-label"><label>{{ phrase('agent.general.title') }}</label></div>
			<div class="dp-form-input">
				<input type="text" name="filter[title]" class="input-title" value="{{filter.title}}" />
			</div>
		</div>

		<div class="dp-form-row">
			<div class="dp-form-label"><label>{{ phrase('agent.general.criteria') }}</label></div>
			<div class="dp-form-input">
				<div class="search-form" id="{{baseId}}_criteria_list">
					{% if app.getSetting('core_tickets.use_archive') %}
						<div class="term">
							{{ phrase('agent.tickets.active_tickets_term') }}
							<span class="small-light-icon tipped" data-tipped-options="maxWidth: 250" title="{{ phrase('agent.tickets.active_tickets_term_explain') }}"></span>
						</div>
					{% endif %}
					<div class="search-terms"></div>
					<div class="term"><span class="add-term">+</span> {{ phrase('agent.general.add_criteria_term') }}</div>
				</div>
				{% include 'DeskPRO:Common:ticket-search-criteria.html.twig' with { 'classname': 'search-builder-tpl', 'id': baseId ~ '_criteria_tpl', 'term_options': term_options, 'search_context': 'filter' } %}
			</div>
		</div>
	</div>

	</form>
</article>
<footer>
	<button class="clean-white" id="{{baseId}}_save_btn">{{ phrase('agent.general.save') }}</button>
</footer>
