{% set page_handler = 'DeskPRO.Admin.ElementHandler.AgentGroupEditPage' %}
{% extends 'AdminBundle::layout.html.twig' %}
{% import 'AdminBundle:Common:design-macros.html.twig' as design %}
{% block pagebar %}
	{% if usergroup.id %}
	<nav>
		<ul>
			<li class="tools" id="tools_menu_trigger"><a></a><em></em></li>
		</ul>
	</nav>
	<ul id="tools_menu" style="display: none">
		<li id="delete_overlay_trigger">{{ phrase('admin.agents.delete_permission_group') }}</li>
	</ul>
	{% endif %}

	<ul>
		<li><a href="{{ path('admin_agents') }}">{{ phrase('agent.general.agents') }}</a></li>
		{% if usergroup.id %}
			<li>{{ phrase('admin.agents.edit_permission_group') }}</li>
		{% else %}
			<li>{{ phrase('admin.agents.new_permission_group') }}</li>
		{% endif %}
	</ul>
{% endblock %}
{% block html_head %}
<script type="text/javascript" src="{{ asset('javascripts/DeskPRO/Admin/ElementHandler/AgentGroupEditPage.js') }}"></script>
{% endblock %}
{% block page %}

<form action="{{ path('admin_agents_groups_edit', {'usergroup_id': usergroup.id|default(0)}) }}" method="post">
<input type="hidden" name="process" value="1" />

<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="usergroup[title]" value="{{usergroup.title}}" />
		</div>
	</div>
	<div class="dp-form-row">
		<div class="dp-form-label">
			<label>{{ phrase('agent.general.members') }}</label>
		</div>
		<div class="dp-form-input">
			<div class="checkbox-rows">
				<ul>
					{% for agent in agents %}
					<li>
						<label>
							<input type="checkbox" name="usergroup[members][]" value="{{ agent.id }}" {% if agent.id in members %}checked="checked"{% endif %} />
							{{ agent.display_name }}
						</label>
					</li>
					{% endfor %}
				</ul>
			</div>
		</div>
	</div>

	{##############################
	 # Permisssions
	 ##############################}
	<div class="dp-form-row">
		<div class="dp-form-label" id="permgroups">
			<label>{{ phrase('agent.general.permissions') }}</label>
			<div class="dp-form-input" id="permgroup_table">
				{% include 'AdminBundle:Agents:edit-agent-permtable.html.twig' with {is_team_editor: true} %}
			</div>
		</div>
	</div>
</div>

<button class="btn primary save-trigger">{{ phrase('agent.general.save') }}</button>
</form>

{% if usergroup.id %}
<div id="delete_overlay" style="width: 400px; height: 150px; display: none;">
	<div class="overlay-title">
		<span class="close-overlay"></span>
		<h4>{{ phrase('admin.agents.delete_agent') }}</h4>
	</div>
	<div class="overlay-content">
		<p>{{ phrase('admin.agents.notice_deleting_perm_group') }}</p>
	</div>
	<div class="overlay-footer">
		<form action="{{ path('admin_agents_groups_del', {'usergroup_id': usergroup.id, 'security_token': security_token('delete_group')}) }}" method="get">
			<button class="clean-white">
				{% set phrase_part %}<span class="agent-name">{{ usergroup.title }}</span>{% endset %}
                {{ phrase('admin.agents.delete_name', {'name':phrase_part}, true) }}
			</button>
		</form>
	</div>
</div>
{% endif %}
{% endblock %}
