<xf:if is="$client.isInsert()">
	<xf:title>{{ phrase('add_oauth2_client') }}</xf:title>
<xf:else />
	<xf:title>{{ phrase('edit_oauth2_client') }} {$client.title}</xf:title>
</xf:if>

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

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

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

			<hr class="formRowSep" />

			<xf:if is="$client.isUpdate()">
				<xf:formrow label="{{ phrase('client_id') }}">
					<code class="js-clientIdCopyTarget">{$client.client_id}</code>
					<xf:button icon="copy"
						data-xf-init="copy-to-clipboard"
						data-copy-target=".js-clientIdCopyTarget"
						data-success="{{ phrase('client_id_copied_to_clipboard') }}"
						class="button--link is-hidden" />
				</xf:formrow>
				<xf:formrow label="{{ phrase('client_secret') }}" rowtype="button">
					<code>{$client.client_secret_snippet}</code>
					<xf:button href="{{ link('oauth2/clients/view-secret', $client) }}"
						data-xf-click="overlay"
						class="button--link">{{ phrase('view_secret') }}
					</xf:button>

					<xf:button href="{{ link('oauth2/clients/regenerate', $client) }}"
						data-xf-click="overlay"
						class="button--link">{{ phrase('regenerate_secret') }}
					</xf:button>
				</xf:formrow>
			</xf:if>

			<xf:radiorow name="client_type" value="{$client}"
				label="{{ phrase('client_type') }}">
				<xf:option value="confidential">{{ phrase('confidential') }}</xf:option>
				<xf:option value="public">{{ phrase('public') }}</xf:option>
			</xf:radiorow>

			<hr class="formRowSep" />

			<xf:formrow label="{{ phrase('authorization_endpoint') }}">{{ link_type('public', 'canonical:oauth2/authorize') }}</xf:formrow>
			<xf:formrow label="{{ phrase('token_endpoint') }}">{{ link_type('api', 'canonical:oauth2/token') }}</xf:formrow>
			<xf:formrow label="{{ phrase('token_revocation_endpoint') }}">{{ link_type('api', 'canonical:oauth2/revoke') }}</xf:formrow>

			<hr class="formRowSep" />

			<xf:formrow name="redirect_uris" value="{$client}"
				label="{{ phrase('redirect_uris') }}"
				explain="{{ phrase('list_of_uris_that_may_be_used_for_redirecting_users_back_to_your_application') }}">
				<ul class="listPlain inputGroup-container">
					<xf:foreach loop="{$client.redirect_uris}" key="$counter" value="$uri">
						<li class="inputGroup">
							<xf:textbox name="redirect_uris[{$counter}]" value="{$uri}" />
						</li>
					</xf:foreach>
					<li class="inputGroup" data-xf-init="field-adder" dir="ltr" >
						<xf:textbox name="redirect_uris[]" />
					</li>
				</ul>
			</xf:formrow>

			<hr class="formRowSep" />

			<xf:textboxrow name="homepage_url" value="{$client}"
				label="{{ phrase('homepage_url') }}"
				explain="{{ phrase('optional_url_to_homepage_or_information_page_for_this_application') }}" />

			<xf:assetuploadrow name="image_url" value="{$client}" asset="applications"
				label="{{ phrase('image_url') }}" />

			<hr class="formRowSep" />

			<xf:checkboxrow name="allowed_scopes" value="{$client.allowed_scopes}"
				label="{{ phrase('allowed_scopes') }}"
				explain="{{ phrase('scopes_allow_oauth2_client_to_only_access_certain_parts_of_api') }}">

				<xf:foreach loop="$scopes" value="$scope">
					<xf:option value="{$scope.api_scope_id}" label="{$scope.api_scope_id}" hint="{$scope.description}" />
				</xf:foreach>
			</xf:checkboxrow>

			<hr class="formRowSep" />

			<xf:checkboxrow>
				<xf:option name="active" value="1" selected="$client.active">{{ phrase('client_is_active') }}</xf:option>
			</xf:checkboxrow>
		</div>

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