import { NgComponentOutlet } from '@angular/common'; import { ChangeDetectionStrategy, Component, forwardRef, inject, input, type OnDestroy, type OnInit, signal, type TemplateRef, type Type, viewChild } from '@angular/core'; import { toSignal } from '@angular/core/rxjs-interop'; import { KcSanitizePipe } from '@keycloakify/angular/lib/pipes/kc-sanitize'; import { USE_DEFAULT_CSS } from '@keycloakify/angular/lib/tokens/use-default-css'; import { ComponentReference } from '@keycloakify/angular/login/classes/component-reference'; import type { TemplateSlots } from '@keycloakify/angular/login/classes/template-slots'; import { type UserProfileFormFieldsComponent } from '@keycloakify/angular/login/components/user-profile-form-fields'; import { KcClassDirective } from '@keycloakify/angular/login/directives/kc-class'; import type { I18n } from '@keycloakify/angular/login/i18n'; import type { KcContext } from '@keycloakify/angular/login/KcContext'; import { UserProfileFormService } from '@keycloakify/angular/login/services/user-profile-form'; import { LOGIN_CLASSES } from '@keycloakify/angular/login/tokens/classes'; import { LOGIN_I18N } from '@keycloakify/angular/login/tokens/i18n'; import { KC_LOGIN_CONTEXT } from '@keycloakify/angular/login/tokens/kc-context'; import type { ClassKey } from 'keycloakify/login/lib/kcClsx'; import { map } from 'rxjs'; @Component({ selector: 'kc-register', templateUrl: 'register.component.html', changeDetection: ChangeDetectionStrategy.OnPush, imports: [KcClassDirective, KcSanitizePipe, NgComponentOutlet], providers: [ { provide: ComponentReference, useExisting: forwardRef(() => RegisterComponent) } ] }) export class RegisterComponent extends ComponentReference implements OnInit, OnDestroy, TemplateSlots { #userProfileFormService = inject(UserProfileFormService); kcContext = inject>(KC_LOGIN_CONTEXT); i18n = inject(LOGIN_I18N); override doUseDefaultCss = inject(USE_DEFAULT_CSS); override classes = inject>>(LOGIN_CLASSES); documentTitle: string | undefined; bodyClassName: string | undefined; displayRequiredFields = false; displayInfo = false; displayMessage = !this.kcContext?.messagesPerField?.existsError('global'); headerNode = viewChild>('headerNode'); infoNode = viewChild>('infoNode'); socialProvidersNode = viewChild>('socialProvidersNode'); isFormSubmittable = toSignal(this.#userProfileFormService.formState$.pipe(map(s => s.isFormSubmittable)), { initialValue: false }); areTermsAccepted = signal(false); userProfileFormFields = input>(); ngOnInit(): void { // eslint-disable-next-line @typescript-eslint/no-explicit-any (window as any)['onSubmitRecaptcha'] = () => { // @ts-expect-error: from native code document.getElementById('kc-register-form').requestSubmit(); }; } ngOnDestroy(): void { // eslint-disable-next-line delete (window as any)['onSubmitRecaptcha']; } }