<xf:if is="$ad.isInsert()">
	<xf:title>{{ phrase('add_advertisement') }}</xf:title>
<xf:else />
	<xf:title>{{ phrase('edit_advertisement:') }} {$ad.title}</xf:title>
</xf:if>

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

<xf:form action="{{ link('advertising/save', $ad) }}" class="block" ajax="true">
	<div class="block-container">
		<div class="block-body">

			<xf:textboxrow name="title" value="{$ad.title}" maxlength="{{ max_length($ad, 'title') }}"
				label="{{ phrase('title') }}"
				explain="{{ phrase('provide_short_title_for_this_advertisement') }}" />

			<xf:selectrow name="position_id" value="{$ad.position_id}"
				data-xf-init="desc-loader"
				data-desc-url="{{ link('advertising/get-position-description') }}"
				label="{{ phrase('position') }}">
				<xf:option />
				<xf:options source="{$advertisingPositions}" />
				<xf:html>
					<div class="js-descTarget formRow-explain">{$ad.AdvertisingPosition.description|raw}</div>
				</xf:html>
			</xf:selectrow>

			<xf:codeeditorrow name="ad_html" value="{$ad.ad_html}" class="codeEditor--short" mode="html"
				label="{{ phrase('html') }}"
				explain="{{ phrase('you_may_use_xenforo_template_syntax_here') }}" />

			<xf:checkboxrow
				label="{{ phrase('display_criteria') }}"
				explain="{{ phrase('use_above_criteria_to_restrict_display_of_this_advertisement') }}">

				<xf:option selected="{$ad.display_criteria.user_groups}"
					label="{{ phrase('user_is_member_of_any_of_selected_user_groups:') }}">

					<xf:select name="display_criteria[user_groups]" size="4" multiple="true" value="{$ad.display_criteria.user_groups}">
						<xf:foreach loop="$userGroups" key="$userGroupId" value="$userGroupTitle">
							<xf:option value="{$userGroupId}">{$userGroupTitle}</xf:option>
						</xf:foreach>
					</xf:select>
				</xf:option>

				<xf:option selected="{$ad.display_criteria.not_user_groups}"
					label="{{ phrase('user_is_not_member_of_any_of_selected_user_groups:') }}">

					<xf:select name="display_criteria[not_user_groups]" size="4" multiple="true" value="{$ad.display_criteria.not_user_groups}">
						<xf:foreach loop="$userGroups" key="$userGroupId" value="$userGroupTitle">
							<xf:option value="{$userGroupId}">{$userGroupTitle}</xf:option>
						</xf:foreach>
					</xf:select>
				</xf:option>
			</xf:checkboxrow>

			<xf:macro template="display_order_macros" name="row"
				arg-value="{$ad.display_order}"
				arg-explain="{{ phrase('enter_display_order_relative_to_other_ads_in_same_position') }}" />

			<xf:checkboxrow>
				<xf:option name="active" value="1" selected="$ad.active">{{ phrase('advertisement_is_active') }}</xf:option>
			</xf:checkboxrow>
		</div>
		<xf:submitrow sticky="true" icon="save" />
	</div>
</xf:form>