<xf:if is="$upgrade.isInsert()">
	<xf:title>{{ phrase('add_user_upgrade') }}</xf:title>
<xf:else />
	<xf:title>{{ phrase('edit_user_upgrade:') }} {$upgrade.title}</xf:title>
</xf:if>

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

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

			<xf:textarearow name="description" value="{$upgrade.description}" autosize="true"
				label="{{ phrase('description') }}"
				hint="{{ phrase('you_may_use_html') }}" />

			<xf:macro template="display_order_macros" name="row"
				arg-value="{{ $upgrade.display_order ?: 1 }}" />

			<xf:formrow rowtype="input"
				label="{{ phrase('cost') }}">

				<div class="inputGroup">
					<xf:textbox name="cost_amount" value="{{ $upgrade.cost_amount ?: 5 }}" style="width: 120px" />
					<span class="inputGroup-splitter"></span>
					<xf:macro template="public:currency_macros" name="currency_list"
						arg-value="{{ $upgrade.cost_currency ?: 'USD' }}"
						arg-class="input--autoSize" />
				</div>

				<div class="formRow-explain">{{ phrase('cost_currency_explain') }}</div>
			</xf:formrow>

			<xf:radiorow name="length_type" label="{{ phrase('length') }}">
				<xf:option value="permanent" selected="$upgrade.length_unit == ''">{{ phrase('permanent') }}</xf:option>
				<xf:option value="timed" selected="$upgrade.length_unit != ''" label="{{ phrase('for_length:') }}">
					<xf:dependent>
						<div class="inputGroup">
							<xf:numberbox name="length_amount" value="{{ $upgrade.length_amount ?: 1 }}" min="1" />
							<span class="inputGroup-splitter"></span>
							<xf:select name="length_unit" value="{{ ($upgrade.length_unit == 'permanent' OR !$upgrade.length_amount) ? 'months' : $upgrade.length_unit }}" class="input--inline">
								<xf:option value="day">{{ phrase('days') }}</xf:option>
								<xf:option value="month">{{ phrase('months') }}</xf:option>
								<xf:option value="year">{{ phrase('years') }}</xf:option>
							</xf:select>
						</div>

					</xf:dependent>
					<xf:dependent>
						<xf:checkbox>
							<xf:option name="recurring" value="1" selected="$upgrade.recurring"
								label="{{ phrase('recurring_payments') }}"
								hint="{{ phrase('recurring_payments_explain') }}" />
						</xf:checkbox>
					</xf:dependent>
				</xf:option>
			</xf:radiorow>

			<xf:checkboxrow name="payment_profile_ids" value="{$upgrade.payment_profile_ids}"
				label="{{ phrase('payment_profile') }}">

				<xf:foreach loop="$profiles" key="$profileId" value="$profile">
					<xf:option value="{$profileId}" label="{{ $profile.Provider.title !== $profile.title ? $profile.Provider.title . ' - ' . $profile.title : $profile.Provider.title }}" />
				</xf:foreach>
			</xf:checkboxrow>

			<xf:checkboxrow name="extra_group_ids" value="{$upgrade.extra_group_ids}" listclass="listColumns"
				label="{{ phrase('additional_user_groups') }}"
				explain="{{ phrase('additional_user_groups_explain') }}">
				<xf:options source="$userGroups" />
			</xf:checkboxrow>

			<xf:if is="$upgrades is not empty">
				<xf:checkboxrow name="disabled_upgrade_ids" value="{$upgrade.disabled_upgrade_ids}" listclass="listColumns"
					label="{{ phrase('disabled_user_upgrades') }}"
					explain="{{ phrase('disabled_user_upgrades_explain') }}">
					<xf:options source="$upgrades" />
				</xf:checkboxrow>
			</xf:if>

			<xf:checkboxrow>
				<xf:option name="can_purchase" selected="$upgrade.can_purchase">{{ phrase('can_be_purchased') }}</xf:option>
			</xf:checkboxrow>
		</div>
		<xf:submitrow icon="save" sticky="true" />
	</div>
</xf:form>