<xf:if is="$option.isInsert()">
	<xf:title>{{ phrase('add_option') }}</xf:title>
<xf:else />
	<xf:title>{{ phrase('edit_option:') }} {$option.title}</xf:title>
</xf:if>

<xf:if is="$group">
	<xf:breadcrumb href="{{ link('options/groups', $group) }}">{$group.title}</xf:breadcrumb>
</xf:if>

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

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

			<xf:textboxrow name="option_id" value="{$option.option_id}"
				label="{{ phrase('option_id') }}"
				hint="{{ phrase('a_z_0_9_and_underscore_only') }}"
				dir="ltr" />

			<xf:macro template="addon_macros" name="addon_edit" arg-addOnId="{$option.addon_id}" />

			<hr class="formRowSep" />

			<xf:textboxrow name="title" value="{{ $option.exists() ? $option.MasterTitle.phrase_text : '' }}"
				label="{{ phrase('title') }}" />

			<xf:textarearow name="explain" value="{{ $option.exists() ? $option.MasterExplain.phrase_text : '' }}" autosize="true"
				label="{{ phrase('explanation') }}"
				hint="{{ phrase('you_may_use_html') }}" />

			<hr class="formRowSep" />

			<xf:selectrow name="edit_format" value="{$option.edit_format}"
				label="{{ phrase('edit_format') }}">

				<xf:option value="textbox">{{ phrase('text_box') }}</xf:option>
				<xf:option value="spinbox">{{ phrase('number_box') }}</xf:option>
				<xf:option value="onoff">{{ phrase('on_off_check_box') }}</xf:option>
				<xf:option value="onofftextbox">{{ phrase('on_off_check_box_with_text_box') }}</xf:option>
				<xf:option value="radio">{{ phrase('radio_buttons') }}</xf:option>
				<xf:option value="select">{{ phrase('select_menu') }}</xf:option>
				<xf:option value="checkbox">{{ phrase('check_boxes') }}</xf:option>
				<xf:option value="template">{{ phrase('named_template') }}</xf:option>
				<xf:option value="callback">{{ phrase('php_callback') }}</xf:option>
				<xf:option value="username">{{ phrase('user_name_input') }}</xf:option>
			</xf:selectrow>

			<xf:textarearow name="edit_format_params" value="{$option.edit_format_params}" autosize="true"
				label="{{ phrase('format_parameters') }}"
				code="true" />

			<hr class="formRowSep" />

			<xf:selectrow name="data_type" value="{{ $option.data_type ?: 'string' }}"
				label="{{ phrase('data_type') }}">

				<xf:option value="boolean">{{ phrase('boolean') }}</xf:option>
				<xf:option value="string">{{ phrase('string') }}</xf:option>
				<xf:option value="integer">{{ phrase('integer') }}</xf:option>
				<xf:option value="unsigned_integer">{{ phrase('unsigned_integer') }}</xf:option>
				<xf:option value="positive_integer">{{ phrase('positive_integer') }}</xf:option>
				<xf:option value="numeric">{{ phrase('numeric') }}</xf:option>
				<xf:option value="unsigned_numeric">{{ phrase('unsigned_numeric') }}</xf:option>
				<xf:option value="array">{{ phrase('array') }}</xf:option>
			</xf:selectrow>

			<xf:textarearow name="default_value" value="{{ $option.data_type == 'array' ? $option.default_value|json : $option.default_value }}"
				autosize="true"
				label="{{ phrase('default_value') }}"
				code="true" />

			<xf:textarearow name="sub_options" autosize="true"
				value="{$option.sub_options|join('
')}"
				label="{{ phrase('array_sub_options') }}"
				dir="ltr" />

			<xf:formrow rowtype="input"
				label="{{ phrase('validation_callback') }}">
				<xf:macro template="helper_callback_fields" name="callback_fields"
					arg-namePrefix="validation"
					arg-data="{$option}" />
			</xf:formrow>

			<hr class="formRowSep" />

			<xf:checkboxrow listclass="listColumns"
				label="{{ phrase('display_in_groups') }}">

				<xf:foreach loop="$groups" value="$group">
					<xf:option name="relations[{$group.group_id}][selected]" selected="{$relations.{$group.group_id}} !== null"
						label="{$group.title}" data-hide="true">

						<xf:macro template="display_order_macros" name="input"
							arg-name="relations[{$group.group_id}][display_order]"
							arg-value="{$relations.{$group.group_id}|default(1)}" />
					</xf:option>
				</xf:foreach>

			</xf:checkboxrow>

			<hr class="formRowSep" />

			<xf:checkboxrow>
				<xf:option name="advanced" selected="{$option.advanced}"
					label="{{ phrase('show_in_advanced_mode_only') }}"
					hint="{{ phrase('option_advanced_mode_hint') }}" />
			</xf:checkboxrow>
		</div>
		<xf:submitrow icon="save" sticky="true" />
	</div>
	<xf:redirect url="{$redirect}" />
</xf:form>