<div class="row">
	<div class="col">
		<div class="view-customize">
			<h1 class="admin-heading">Authentication</h1>
			<h2 class="sub-heading">Choose user authentication mechanism</h2>
		</div>
	</div>
</div>

<div class="view-customize">
	<form class="mt-5">
		<div class="form-group row">
			<label class="col-sm-2 col-form-label">Provider</label>
			<div class="col-sm-10">
				{{#ui/ui-radio selected=isDocumizeProvider onClick=(action 'onDocumize')}} Documize &mdash; email/password{{/ui/ui-radio}}
				{{#ui/ui-radio selected=isKeycloakProvider onClick=(action 'onKeycloak')}} Keycloak &mdash; bring your own authentication server{{/ui/ui-radio}}
				<small class="form-text text-muted">
					External authentication servers, services must be accessible from the server running this Documize instance
				</small>
			</div>
		</div>

		{{#if isKeycloakProvider}}
			<div class="form-group row">
				<label for="keycloak-url" class="col-sm-2 col-form-label">Keycloak Server URL</label>
				<div class="col-sm-10">
					{{focus-input id="keycloak-url" type="text" value=keycloakConfig.url class=(if KeycloakUrlError 'form-control is-invalid' 'form-control')}}
					<small class="form-text text-muted">e.g. http://localhost:8888/auth</small>
				</div>
			</div>
			<div class="form-group row">
				<label for="keycloak-realm" class="col-sm-2 col-form-label">Keycloak Realm</label>
				<div class="col-sm-10">
					{{input id="keycloak-realm" type="text" value=keycloakConfig.realm class=(if keycloakRealmError 'form-control is-invalid' 'form-control')}}
					<small class="form-text text-muted">e.g. main</small>
				</div>
			</div>
			<div class="form-group row">
				<label for="keycloak-publicKey" class="col-sm-2 col-form-label">Keycloak Realm Public Key</label>
				<div class="col-sm-10">
					{{textarea id="keycloak-publicKey" type="text" value=keycloakConfig.publicKey rows=7 class=(if KeycloakPublicKeyError 'form-control is-invalid' 'form-control')}}
					<small class="form-text text-muted">Copy the RSA Public Key from Realm Settings &rarr; Keys</small>
				</div>
			</div>
			<div class="form-group row">
				<label for="keycloak-clientId" class="col-sm-2 col-form-label">Keycloak OIDC Client ID</label>
				<div class="col-sm-10">
					{{input id="keycloak-clientId" type="text" value=keycloakConfig.clientId class=(if KeycloakClientIdError 'form-control is-invalid' 'form-control')}}
					<small class="form-text text-muted">e.g. account</small>
				</div>
			</div>
			<div class="form-group row">
				<label for="keycloak-group" class="col-sm-2 col-form-label">Keycloak Group ID (Optional)</label>
				<div class="col-sm-10">
					{{input id="keycloak-group" type="text" value=keycloakConfig.group class="form-control"}}
					<small class="form-text text-muted">If you want to sync users in a particular Group (e.g. 'Documize Users'), provide the Group ID (e.g. 511d8b61-1ec8-45f6-bc8d-5de64d54c9d2)</small>
				</div>
			</div>
			<div class="form-group row">
				<label for="keycloak-admin-user" class="col-sm-2 col-form-label">Keycloak Username</label>
				<div class="col-sm-10">
					{{input id="keycloak-admin-user" type="text" value=keycloakConfig.adminUser class=(if KeycloakAdminUserError 'form-control is-invalid' 'form-control')}}
					<small class="form-text text-muted">Used to connect with Keycloak and sync users with Documize (create user under Master Realm and assign 'view-users' role
						against Realm specified above)</small>
				</div>
			</div>
			<div class="form-group row">
				<label for="keycloak-admin-password" class="col-sm-2 col-form-label">Keycloak Password</label>
				<div class="col-sm-10">
					{{input id="keycloak-admin-password" type="password" value=keycloakConfig.adminPassword class=(if KeycloakAdminPasswordError 'form-control is-invalid' 'form-control')}}
					<small class="form-text text-muted">Used to connect with Keycloak and sync users with Documize</small>
				</div>
			</div>
			<div class="form-group row">
				<label for="keycloak-admin-password" class="col-sm-2 col-form-label">Logout</label>
				<div class="col-sm-10">
					<div class="form-check">
						{{input type="checkbox" class="form-check-input" id="keycloak-logout" checked=keycloakConfig.disableLogout}}
						<label class="form-check-label" for="keycloak-logout">
							Hide the logout button for Keycloak users
						</label>
					</div>
				</div>
			</div>
			<div class="form-group row">
				<label for="keycloak-admin-password" class="col-sm-2 col-form-label">Space Permission</label>
				<div class="col-sm-10">
					<div class="form-check">
						{{input type="checkbox" class="form-check-input" id="keycloak-perm" checked=keycloakConfig.defaultPermissionAddSpace}}
						<label class="form-check-label" for="keycloak-perm">
							Can add spaces
						</label>
					</div>
				</div>
			</div>
		{{/if}}
		<div class="btn btn-success mt-4" {{action 'onSave'}}>Save</div>
	</form>
</div>