<xf:if is="$webhook.isInsert()">
	<xf:title>{{ phrase('add_webhook') }}</xf:title>
<xf:else />
	<xf:title>{{ phrase('edit_webhook:') }} {$webhook.title}</xf:title>
</xf:if>

<xf:pageaction if="$webhook.isUpdate()">
	<xf:button href="{{ link('webhooks/delete', $webhook) }}" icon="delete" overlay="true" />
</xf:pageaction>

<xf:form action="{{ link('webhooks/save', $webhook) }}" class="block" ajax="true">
	<div class="block-container">
		<div class="block-body">
			<xf:textboxrow name="title" value="{$webhook}" label="{{ phrase('title') }}" />

			<xf:textarearow name="description" value="{$webhook}" autosize="true"
				label="{{ phrase('description') }}"
				explain="{{ phrase('webhook_description_explain') }}" />

			<xf:textboxrow name="url" value="{$webhook}" label="{{ phrase('target_url') }}" />

			<xf:textboxrow name="secret" value="{$webhook}" label="{{ phrase('secret') }}" explain="{{ phrase('if_specified_this_value_will_be_included_in_xf_webhook_secret_request') }}" />

			<xf:foreach loop="$contentTypeHandlers" key="$contentType" value="$handler">
				<h3 class="block-formSectionHeader">
					<span class="collapseTrigger collapseTrigger--block {{ {$webhook.events.{$contentType}} ? 'is-active' : '' }}" data-xf-click="toggle" data-target="< :up:next">
						<span class="block-formSectionHeader-aligner">{$handler.getTitle()}</span>
					</span>
					<span class="block-desc">
						{{ phrase('x_events', {'count': count($handler.getEvents())}) }}
					</span>
				</h3>
				<div class="block-body block-body--collapsible {{ {$webhook.events.{$contentType}} ? 'is-active' : '' }}">
					<xf:radiorow name="send_mode[{$contentType}]" label="{{ phrase('events') }}">
						<xf:option value="none" label="{{ phrase('dont_send_for_any_events') }}" selected="{{ !{$webhook.events.{$contentType}} }} "/>
						<xf:option value="all" label="{{ phrase('send_all_events') }}" selected="{{ {$webhook.events.{$contentType}} === '*' }}"/>
						<xf:if is="{{ count($handler.getEvents()) }}">
							<xf:option value="specific" data-hide="true" data-xf-init="disabler" data-container=".js-webhookEvents-{$contentType}"
								label="{{ phrase('send_only_specific_events') }}" selected="{{ is_array($webhook.events.{$contentType}) }}">
								<xf:dependent>
									<div class="js-webhookEvents-{$contentType}">
										<xf:checkbox name="events[{$contentType}][]" listclass="listColumns" value="{$webhook.events.{$contentType}}">
											<xf:foreach loop="$handler.getEvents()" value="$event">
												<xf:option label="{$handler.getEventName($event)}" hint="{$handler.getEventHint($event)}" value="{$event}" />
											</xf:foreach>
										</xf:checkbox>
									</div>
								</xf:dependent>
							</xf:option>
						</xf:if>
					</xf:radiorow>

					<hr class="formRowSep" />

					<div class="webhookCriteria-{$contentType}">
						{$handler.renderCriteria($webhook)|raw}
					</div>
				</div>
			</xf:foreach>

			<hr class="block-separator" />

			<xf:selectrow name="content_type" value="{$webhook}" label="{{ phrase('content_type') }}">
				<xf:option value="json">{{ phrase('application_json') }}</xf:option>
				<xf:option value="form_params">{{ phrase('x_www_form_urlencoded') }}</xf:option>
			</xf:selectrow>

			<xf:checkboxrow>
				<xf:option name="ssl_verify" selected="$webhook.ssl_verify"
					label="{{ phrase('enable_ssl_verification') }}"
					hint="{{ phrase('we_do_not_recommend_disabling_this_as_it_is_insecure') }}" />
			</xf:checkboxrow>

			<hr class="formRowSep" />

			<xf:checkboxrow>
				<xf:option name="active" selected="$webhook.active"
					label="{{ phrase('webhook_is_active') }}"
					hint="{{ phrase('use_this_to_disable_webhook') }}" />
			</xf:checkboxrow>

			<xf:submitrow icon="save" />
		</div>
	</div>
</xf:form>