<xf:if is="$user.isInsert()">
	<xf:title>{{ phrase('add_user') }}</xf:title>
<xf:else />
	<xf:title>{{ phrase('edit_user:') }} {$user.username}</xf:title>
</xf:if>

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

		<xf:button class="menuTrigger" data-xf-click="menu" aria-expanded="false" aria-haspopup="true">{{ phrase('actions') }}</xf:button>
		<div class="menu" data-menu="menu" aria-hidden="true">
			<div class="menu-content">
				<h3 class="menu-header">{{ phrase('actions') }}</h3>
				<!--[XF:actions_menu:top]-->
				<a href="{{ link_type('public', 'members', $user) }}" class="menu-linkRow" target="_blank">{{ phrase('view_public_profile') }}</a>

				<xf:if is="$user.is_banned">
					<a href="{{ link('banning/users/lift', $user) }}" class="menu-linkRow" data-xf-click="overlay">{{ phrase('lift_ban') }}</a>
				<xf:elseif is="!$user.is_moderator AND !$user.is_admin" />
					<a href="{{ link('banning/users/add', $user) }}" class="menu-linkRow" data-xf-click="overlay">{{ phrase('ban_user') }}</a>
				</xf:if>

				<xf:if is="!$user.is_moderator AND !$user.is_admin">
					<a href="{{ link('users/merge', $user) }}" class="menu-linkRow" data-xf-click="overlay">{{ phrase('merge_with_user') }}</a>
					<a href="{{ link('users/delete-conversations', $user) }}" class="menu-linkRow" data-xf-click="overlay">{{ phrase('delete_conversations') }}</a>
				</xf:if>

				<xf:if is="!$user.is_super_admin AND $xf.options.editHistory.enabled">
					<a href="{{ link('users/revert-message-edit', $user) }}" class="menu-linkRow" data-xf-click="overlay">{{ phrase('revert_message_edits') }}</a>
				</xf:if>

				<xf:if is="!$user.is_super_admin">
					<a href="{{ link('users/remove-reactions', $user) }}" class="menu-linkRow" data-xf-click="overlay">{{ phrase('remove_reactions') }}</a>
					<a href="{{ link('users/manage-watched-threads', $user) }}" class="menu-linkRow" data-xf-click="overlay">{{ phrase('manage_watched_threads') }}</a>
				</xf:if>

				<xf:if is="$user.isAwaitingEmailConfirmation()">
					<a href="{{ link('users/resend-confirmation', $user) }}" class="menu-linkRow" data-xf-click="overlay">{{ phrase('resend_account_confirmation') }}</a>
				</xf:if>
				<!--[XF:actions_menu:bottom]-->
			</div>
		</div>
	</div>
</xf:pageaction>

<xf:if is="$success">
	<div class="blockMessage blockMessage--success blockMessage--iconic">{{ phrase('redirect_changes_saved_successfully') }}</div>
</xf:if>

<div class="block">
	<xf:if is="$user.user_id">
	<xf:if contentcheck="true">
		<div class="block-outer">
			<ul class="listInline listInline--bullet">
			<xf:contentcheck>
				<!--[XF:status_list:start]-->
				<xf:if is="$user.is_admin">
					<li><a href="{{ link('admins/edit', $user) }}">{{ $user.is_super_admin ?  phrase('super_administrator') : phrase('administrator') }}</a></li>
				</xf:if>
				<xf:if is="$user.is_moderator">
					<li><a href="{{ link('moderators') }}">{{ phrase('moderator') }}</a></li>
				</xf:if>
				<xf:if is="$user.Option.is_discouraged">
					<li>{{ phrase('discouraged') }}</li>
				</xf:if>
				<xf:if is="$user.is_banned">
					<li><a href="{{ link('banning/users/lift', $user) }}" data-xf-click="overlay">{{ phrase('banned') }}</a></li>
				</xf:if>
				<!--[XF:status_list:end]-->
			</xf:contentcheck>
			</ul>
		</div>
	</xf:if>
	</xf:if>

	<xf:form action="{{ link('users/save', $user) }}" ajax="true" class="block-container" novalidate="novalidate">
		<xf:if is="$user.is_super_admin">
			<div class="block-body">
				<xf:passwordboxrow name="visitor_password" label="{{ phrase('your_password') }}">
					<xf:explain>{{ phrase('you_must_enter_your_current_password_to_validate_this_request') }}</xf:explain>
				</xf:passwordboxrow>
			</div>
		</xf:if>

		<h2 class="block-tabHeader tabs hScroller" data-xf-init="tabs h-scroller" data-state="replace" role="tablist">
			<span class="hScroller-scroll">
				<!--[XF:tabs:start]-->
				<a class="tabs-tab is-active" role="tab" tabindex="0"
					id="user-details"
					aria-controls="user-details"
					href="{{ link('users/edit', $user) }}#user-details">{{ phrase('user_details') }}</a>
				<xf:if is="$user.user_id">
					<a class="tabs-tab" role="tab" tabindex="0"
						id="user-extras"
						aria-controls="user-extras"
						href="{{ link('users/edit', $user) }}#user-extras">{{ phrase('extra') }}</a>
					<a class="tabs-tab" role="tab" tabindex="0"
						id="user-ips"
						aria-controls="user-ips"
						href="{{ link('users/edit', $user) }}#user-ips">{{ phrase('ip_addresses') }}</a>
					<a class="tabs-tab" role="tab" tabindex="0"
						id="user-changes"
						aria-controls="user-changes"
						href="{{ link('users/edit', $user) }}#user-changes">{{ phrase('change_log') }}</a>
					<a class="tabs-tab" role="tab" tabindex="0"
						id="user-permissions"
						aria-controls="user-permissions"
						href="{{ link('users/edit', $user) }}#user-permissions">{{ phrase('permissions') }}</a>
				</xf:if>
				<!--[XF:tabs:end]-->
			</span>
		</h2>

		<ul class="tabPanes">
			<!--[XF:tab_panes:start]-->
			<li class="is-active" role="tabpanel" aria-labelledby="user-details">
				<div class="block-body">
					<xf:textboxrow name="user[username]" value="{$user.username}"
						maxlength="{{ $xf.options.usernameLength.max ?: max_length($user, 'username') }}"
						label="{{ phrase('user_name') }}">
						<xf:html><xf:if is="$user.exists()">
							<xf:checkbox style="margin-top: 5px;">
								<xf:option name="username_change_invisible">{{ phrase('do_not_display_username_change_publicly_if_changed') }}</xf:option>
							</xf:checkbox>
						</xf:if></xf:html>
					</xf:textboxrow>

					<xf:if is="$user.username_date">
						<xf:formrow label="{{ phrase('last_username_change') }}">
							<xf:date time="{$user.username_date}" />
						</xf:formrow>
					</xf:if>

					<xf:if is="$user.next_allowed_username_change">
						<xf:formrow label="{{ phrase('next_allowed_username_change') }}">
							<xf:date time="{$user.next_allowed_username_change}" />
						</xf:formrow>
					</xf:if>

					<xf:textboxrow name="user[email]" value="{$user.email}" type="email" dir="ltr"
						maxlength="{{ max_length($user, 'email') }}"
						label="{{ phrase('email') }}" />

					<xf:if is="$user.exists()">
						<xf:radiorow name="change_password"
							label="{{ phrase('password') }}"
							explain="{{ phrase('changing_users_password_will_reset_any_security_lock_on_their_account') }}">

							<xf:option value="" checked="checked"
								label="{{ phrase('do_not_change') }}" />
							<xf:option value="generate"
								label="{{ phrase('send_password_reset') }}"
								hint="{{ phrase('password_reset_confirmation_will_be_emailed_to_user') }}" />
							<xf:option value="change"
								label="{{ phrase('set_new_password:') }}">
								<xf:textbox name="password" autocomplete="off" />
							</xf:option>
						</xf:radiorow>
					<xf:else />
						<xf:textboxrow name="password" autocomplete="off"
							label="{{ phrase('password') }}" />
					</xf:if>

					<xf:if is="$user.user_id">
						<xf:formrow label="{{ phrase('two_step_verification') }}">
							<xf:if is="$user.Option.use_tfa">
								<ul class="inputChoices">
									<li class="inputChoices-choice inputChoices-plainChoice">{{ phrase('enabled') }}</li>
									<li class="inputChoices-choice"><xf:checkbox standalone="true"><xf:option name="disable_tfa"
										label="{{ phrase('disable_two_step_verification') }}" /></xf:checkbox></li>
								</ul>
							<xf:else />
								{{ phrase('disabled') }}
							</xf:if>
						</xf:formrow>

						<xf:formrow label="{{ phrase('avatar') }}" rowtype="button avatar">
							<xf:avatar user="$user" size="l" href="{{ link('users/avatar', $user) }}" data-xf-click="overlay" />
							<div>
								<xf:button href="{{ link('users/avatar', $user) }}" data-xf-click="overlay" class="button--link">{{ phrase('edit_avatar') }}</xf:button>
							</div>
						</xf:formrow>

						<xf:formrow label="{{ phrase('profile_banner') }}" rowtype="button memberProfileBanner">
							<xf:profilebanner user="$user" size="l" class="memberProfileBanner--small" href="{{ link('users/banner', $user) }}" overlay="true" hideempty="true" />
							<xf:button href="{{ link('users/banner', $user) }}" data-xf-click="overlay" class="button--link">{{ phrase('edit_profile_banner') }}</xf:button>
						</xf:formrow>

						<xf:formrow label="{{ phrase('joined') }}">
							<xf:date time="{$user.register_date}" />
						</xf:formrow>
						<xf:if is="$user.last_activity">
							<xf:formrow label="{{ phrase('last_activity') }}">
								<xf:date time="{$user.last_activity}" />
							</xf:formrow>
						</xf:if>
					</xf:if>

					<hr class="formRowSep" />

					<xf:set var="$_userChangesHtml">
						<xf:if is="$user.user_id">
							<xf:if is="!$user.is_moderator"><a href="{{ link('moderators') }}">{{ phrase('make_this_user_moderator') }}</a></xf:if>
							<xf:if is="!$user.is_admin AND !$user.is_moderator">/</xf:if>
							<xf:if is="!$user.is_admin"><a href="{{ link('admins') }}">{{ phrase('make_this_user_administrator') }}</a></xf:if>
						</xf:if>
					</xf:set>

					<xf:selectrow name="user[user_group_id]" value="{$user.user_group_id}"
						label="{{ phrase('user_group') }}">
						<xf:options source="$userGroups" />
						<xf:explain>{$_userChangesHtml|raw}</xf:explain>
					</xf:selectrow>

					<xf:checkboxrow name="user[secondary_group_ids]" value="{$user.secondary_group_ids}"
						listclass="listColumns"
						label="{{ phrase('secondary_user_groups') }}">
						<xf:options source="$userGroups" />
					</xf:checkboxrow>

					<xf:checkboxrow>
						<xf:option name="user[is_staff]" selected="$user.is_staff"
							label="{{ phrase('display_user_as_staff') }}"
							hint="{{ phrase('if_selected_this_user_will_be_listed_publicly_as_staff_member') }}" />
					</xf:checkboxrow>

					<xf:selectrow name="user[user_state]" value="{$user.user_state}"
						label="{{ phrase('user_state') }}">

						<xf:option value="valid">{{ phrase('valid') }}</xf:option>
						<xf:option value="email_confirm">{{ phrase('awaiting_email_confirmation') }}</xf:option>
						<xf:option value="email_confirm_edit">{{ phrase('awaiting_email_confirmation_from_edit') }}</xf:option>
						<xf:option value="email_bounce">{{ phrase('email_invalid_bounced') }}</xf:option>
						<xf:option value="moderated">{{ phrase('awaiting_approval') }}</xf:option>
						<xf:option value="rejected">{{ phrase('rejected') }}</xf:option>
						<xf:option value="disabled">{{ phrase('disabled') }}</xf:option>
						<xf:explain>
							{{ phrase('when_user_state_non_x_users_receive_permissions_guest_group', {'valid_state': phrase('valid'), 'guest': '<a href="' . link('user-groups/edit', {'user_group_id': 1, 'title': $userGroups.1}) . '" target="_blank">' . $userGroups.1 . '</a>'}) }}
						</xf:explain>
					</xf:selectrow>

					<xf:selectrow name="user[security_lock]" value="{$user.security_lock}"
						label="{{ phrase('security_lock') }}">

						<xf:option value="">{{ phrase('none') }}</xf:option>
						<xf:option value="change">{{ phrase('locked:') }} {{ phrase('user_must_change_password') }}</xf:option>
						<xf:option value="reset">{{ phrase('locked:') }} {{ phrase('user_must_reset_password') }}</xf:option>
						<xf:explain>
							{{ phrase('user_security_lock_explain') }}
						</xf:explain>
					</xf:selectrow>

					<hr class="formRowSep" />

					<xf:checkboxrow>
						<xf:option name="option[is_discouraged]" selected="$user.Option.is_discouraged"
							hint="{{ phrase('discouraged_hint') }}">{{ phrase('discouraged') }}</xf:option>
						<xf:explain><a href="{{ link('banning/discouraged-ips') }}">{{ phrase('alternatively_use_ip_discouragement') }}</a></xf:explain>
					</xf:checkboxrow>
				</div>

				<h3 class="block-formSectionHeader">
					<span class="collapseTrigger collapseTrigger--block" data-xf-click="toggle" data-target="< :up:next">
						<span class="block-formSectionHeader-aligner">{{ phrase('personal_details') }}</span>
					</span>
				</h3>
				<div class="block-body block-body--collapsible">
					<xf:macro template="public:helper_user_dob_edit" name="dob_edit" arg-dobData="{$user.Profile}" />

					<hr class="formRowSep" />

					<xf:textboxrow name="profile[location]" value="{$user.Profile.location_}"
						label="{{ phrase('location') }}" />
					<xf:textboxrow name="profile[website]" value="{$user.Profile.website_}" type="url"
						label="{{ phrase('website') }}"
						dir="ltr" />
					<xf:macro template="public:custom_fields_macros" name="custom_fields_edit"
						arg-type="users" arg-group="personal" arg-set="{$user.Profile.custom_fields}" arg-editMode="admin" />
					<xf:textarearow name="profile[about]" value="{$user.Profile.about_}" autosize="true"
						label="{{ phrase('about') }}"
						hint="{{ phrase('you_may_use_bb_code') }}" />
				</div>

				<h3 class="block-formSectionHeader">
					<span class="collapseTrigger collapseTrigger--block" data-xf-click="toggle" data-target="< :up:next">
						<span class="block-formSectionHeader-aligner">{{ phrase('profile_info') }}</span>
					</span>
				</h3>
				<div class="block-body block-body--collapsible">
					<xf:textboxrow name="user[custom_title]" value="{$user.custom_title_}"
						maxlength="{{ max_length($user, 'custom_title') }}"
						label="{{ phrase('custom_title') }}" />
					<xf:textarearow name="profile[signature]" value="{$user.Profile.signature_}" autosize="true"
						label="{{ phrase('signature') }}"
						hint="{{ phrase('you_may_use_bb_code') }}" />

					<hr class="formRowSep" />

					<xf:numberboxrow name="user[message_count]" value="{$user.message_count}" min="0"
						label="{{ phrase('messages') }}" />
					<xf:numberboxrow name="user[reaction_score]" value="{$user.reaction_score}"
						label="{{ phrase('reaction_score') }}" />
					<xf:numberboxrow name="user[trophy_points]" value="{$user.trophy_points}" min="0"
						label="{{ phrase('trophy_points') }}" />
				</div>

				<h3 class="block-formSectionHeader">
					<span class="collapseTrigger collapseTrigger--block" data-xf-click="toggle" data-target="< :up:next">
						<span class="block-formSectionHeader-aligner">{{ phrase('additional_contact') }}</span>
					</span>
				</h3>
				<div class="block-body block-body--collapsible">
					<xf:macro template="public:custom_fields_macros" name="custom_fields_edit"
						arg-type="users" arg-group="contact" arg-set="{$user.Profile.custom_fields}" arg-editMode="admin" />
				</div>

				<h3 class="block-formSectionHeader">
					<span class="collapseTrigger collapseTrigger--block" data-xf-click="toggle" data-target="< :up:next">
						<span class="block-formSectionHeader-aligner">{{ phrase('preferences') }}</span>
					</span>
				</h3>
				<div class="block-body block-body--collapsible">
					<xf:selectrow name="user[style_id]" value="{$user.style_id}"
						label="{{ phrase('style') }}">

						<xf:option value="0">{{ phrase('(use_default_style)') }}</xf:option>
						<xf:foreach loop="$styleTree.getFlattened(0)" value="$treeEntry">
							<xf:option value="{$treeEntry.record.style_id}">{{ repeat('--', $treeEntry.depth) }} {$treeEntry.record.title}</xf:option>
						</xf:foreach>
					</xf:selectrow>

					<hr class="formRowSep" />

					<xf:selectrow name="user[language_id]" value="{$user.language_id}"
						label="{{ phrase('language') }}">

						<xf:foreach loop="$languageTree.getFlattened(0)" value="$treeEntry">
							<xf:option value="{$treeEntry.record.language_id}">{{ repeat('--', $treeEntry.depth) }}
								{$treeEntry.record.title}</xf:option>
						</xf:foreach>
					</xf:selectrow>

					<xf:selectrow name="user[timezone]" value="{$user.timezone}"
						label="{{ phrase('time_zone') }}">

						<xf:options source="$timeZones" />
					</xf:selectrow>

					<hr class="formRowSep" />

					<xf:checkboxrow>
						<xf:option name="option[content_show_signature]" selected="$user.Option.content_show_signature">
							{{ phrase('show_signatures_with_messages') }}</xf:option>
						<xf:option name="option[receive_admin_email]" selected="$user.Option.receive_admin_email">
							{{ phrase('receive_site_mailings_option') }}
						</xf:option>
						<xf:option name="enable_activity_summary_email" selected="$user.last_summary_email_date !== null">
							{{ phrase('receive_summary_activity_email') }}
						</xf:option>
						<xf:option name="option[email_on_conversation]" selected="$user.Option.email_on_conversation">
							{{ phrase('receive_email_when_new_conversation_message_is_received') }}</xf:option>
					</xf:checkboxrow>

					<xf:selectrow name="option[creation_watch_state]" value="{$user.Option.creation_watch_state}"
						label="{{ phrase('watch_content_on_creation') }}">

						<xf:option value="watch_no_email">{{ phrase('yes') }}</xf:option>
						<xf:option value="watch_email">{{ phrase('yes_with_email') }}</xf:option>
						<xf:option value="">{{ phrase('no') }}</xf:option>
					</xf:selectrow>

					<xf:selectrow name="option[interaction_watch_state]" value="{$user.Option.interaction_watch_state}"
						label="{{ phrase('watch_content_on_interaction') }}">

						<xf:option value="watch_no_email">{{ phrase('yes') }}</xf:option>
						<xf:option value="watch_email">{{ phrase('yes_with_email') }}</xf:option>
						<xf:option value="">{{ phrase('no') }}</xf:option>
					</xf:selectrow>

					<xf:macro template="public:custom_fields_macros" name="custom_fields_edit"
						arg-type="users"
						arg-group="preferences"
						arg-set="{$user.Profile.custom_fields}"
						arg-editMode="admin" />
				</div>

				<h3 class="block-formSectionHeader">
					<span class="collapseTrigger collapseTrigger--block" data-xf-click="toggle" data-target="< :up:next">
						<span class="block-formSectionHeader-aligner">{{ phrase('privacy') }}</span>
					</span>
				</h3>
				<div class="block-body block-body--collapsible">
					<xf:checkboxrow label="{{ phrase('general_privacy') }}">
						<xf:option name="user[visible]" selected="$user.visible">
							<xf:label>{{ phrase('show_online_status') }}</xf:label>
							<xf:dependent>
								<xf:checkbox>
									<xf:option name="user[activity_visible]" selected="$user.activity_visible">
										{{ phrase('show_current_activity') }}
									</xf:option>
								</xf:checkbox>
							</xf:dependent>
						</xf:option>
						<xf:option name="option[show_dob_date]" selected="$user.Option.show_dob_date">
							{{ phrase('show_day_and_month_of_birth') }}
						</xf:option>
						<xf:option name="option[show_dob_year]" selected="$user.Option.show_dob_year">
							{{ phrase('show_year_of_birth') }}
						</xf:option>
					</xf:checkboxrow>

					<hr class="formRowSep" />

					<!--[XF:privacy_select:allow_view_profile]-->
					<xf:macro name="privacy_select"
						arg-name="allow_view_profile"
						arg-label="{{ phrase('view_this_users_profile_page_details') }}"
						arg-user="{$user}" />

					<!--[XF:privacy_select:allow_post_profile]-->
					<xf:macro name="privacy_select"
						arg-name="allow_post_profile"
						arg-label="{{ phrase('post_messages_on_this_users_profile_page') }}"
						arg-user="{$user}"
						arg-hideEveryone="{{true}}" />

					<!--[XF:privacy_select:allow_receive_news_feed]-->
					<xf:macro name="privacy_select"
						arg-name="allow_receive_news_feed"
						arg-label="{{ phrase('receive_this_users_news_feed') }}"
						arg-user="{$user}" />

					<hr class="formRowSep" />

					<!--[XF:privacy_select:allow_send_personal_conversation]-->
					<xf:macro name="privacy_select"
						arg-name="allow_send_personal_conversation"
						arg-label="{{ phrase('initiate_conversations_with_this_user') }}"
						arg-user="{$user}"
						arg-hideEveryone="{{true}}" />

					<!--[XF:privacy_select:allow_view_identities]-->
					<xf:macro name="privacy_select"
						arg-name="allow_view_identities"
						arg-label="{{ phrase('view_this_users_identities') }}"
						arg-user="{$user}" />
				</div>

				<xf:submitrow icon="save" sticky="true" />
			</li>

			<xf:if is="$user.user_id">
				<li data-href="{{ link('users/extra', $user) }}" role="tabpanel" aria-labelledby="user-extras">
					<div class="block-body block-row">{{ phrase('loading...') }}</div>
				</li>
			</xf:if>

			<xf:if is="$user.user_id">
				<li data-href="{{ link('users/user-ips', $user) }}" role="tabpanel" aria-labelledby="user-ips">
					<div class="block-body block-row">{{ phrase('loading...') }}</div>
				</li>
			</xf:if>

			<xf:if is="$user.user_id">
				<li data-href="{{ link('users/change-log', $user) }}" role="tabpanel" aria-labelledby="user-changes">
					<div class="block-body block-row">{{ phrase('loading...') }}</div>
				</li>
			</xf:if>

			<xf:if is="$user.user_id">
				<li data-href="{{ link('permissions/users', $user, {'tabbed':1}) }}" role="tabpanel" aria-labelledby="user-permissions">
					<div class="block-body block-row">{{ phrase('loading...') }}</div>
				</li>
			</xf:if>
			<!--[XF:tab_panes:end]-->
		</ul>
	</xf:form>
</div>

<xf:macro name="privacy_select" arg-name="!" arg-label="!" arg-user="!" arg-hideEveryone="{{false}}">
	<xf:selectrow name="privacy[{$name}]" value="{$user.Privacy.{$name}}"
		label="{$label}">

		<xf:option value="none">{{ phrase('nobody') }}</xf:option>
		<xf:if is="!$hideEveryone">
			<xf:option value="everyone">{{ phrase('all_visitors') }}</xf:option>
		</xf:if>
		<xf:option value="members">{{ phrase('members_only') }}</xf:option>
		<xf:option value="followed">{{ phrase('people_x_follows', {'name': ($user.username ? $user.username : '[' . phrase('user') . ']')}) }}</xf:option>
	</xf:selectrow>
</xf:macro>