import { HttpClient } from '@angular/common/http'; import { ChangeDetectorRef, KeyValueDiffers, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { TranslocoService } from '@jsverse/transloco'; import { BaseEntity, SchemaAwareConstructor } from '../../entities/base-entity'; import { SpiderlyMessageService } from '../../services/spiderly-message.service'; import { SpiderlyFormArray, SpiderlyFormControl, SpiderlyFormGroup } from '../spiderly-form-control/spiderly-form-control'; import { BaseFormService } from './../../services/base-form.service'; import * as i0 from "@angular/core"; export declare class BaseFormComponent implements OnInit { protected differs: KeyValueDiffers; protected http: HttpClient; protected messageService: SpiderlyMessageService; protected changeDetectorRef: ChangeDetectorRef; protected router: Router; protected route: ActivatedRoute; protected translocoService: TranslocoService; protected baseFormService: BaseFormService; /** * The root form group that holds all form controls, typed to `TSaveBody`. * Assign `saveObservableMethod` on it to define the HTTP call used for saving. * The form controls are built automatically from the `TSaveBody` schema when you call * `baseFormService.initFormGroup(this.parentFormGroup, saveBodyClass, saveBody)`. * * @example * ```ts * this.parentFormGroup.saveObservableMethod = this.apiService.saveProduct; * * this.baseFormService.initFormGroup( * this.parentFormGroup, * ProductSaveBody, * saveBody, * ); * ``` */ parentFormGroup: SpiderlyFormGroup; /** * The class reference for the main UI form entity (`TMainUIForm`). * This represents the shape of the data **returned by the API** after a save. * Used internally by `mapMainUIFormToSaveBody` to transform the API response back into `TSaveBody` * for form re-initialization. * * @example * ```ts * this.mainUIFormClass = ProductMainUIForm; * ``` */ mainUIFormClass: SchemaAwareConstructor; /** * The class reference for the save body entity (`TSaveBody`). * This represents the shape of the data **sent to the API** when saving. * Used internally to build form controls from the schema via `initFormGroup`, * and to locate the main DTO property (marked with `isSaveBodyMainDTO: true`) for extracting the saved entity's ID. * * @example * ```ts * this.saveBodyClass = ProductSaveBody; * ``` */ saveBodyClass: SchemaAwareConstructor; /** * The toast message displayed after a successful save. * Override this to customize the success notification text for a specific entity. * If you want to change the message for all entities, update the `SuccessfulSaveToastDescription` key * in your translation JSON file instead. * * @example * ```ts * this.successfulSaveToastDescription = 'Product saved successfully!'; * ``` */ successfulSaveToastDescription: string; private modelDiffer; constructor(differs: KeyValueDiffers, http: HttpClient, messageService: SpiderlyMessageService, changeDetectorRef: ChangeDetectorRef, router: Router, route: ActivatedRoute, translocoService: TranslocoService, baseFormService: BaseFormService); ngOnInit(): void; /** * Executes the save flow for the form. The execution order is: * 1. Builds the save body from the form's raw value. * 2. Calls {@link onBeforeSave} — use this to modify the save body before validation. * 3. Validates the form. If invalid, shows an error message and stops. * 4. Sends the save HTTP request via `saveObservableMethod`. * 5. Calls {@link onAfterSaveRequest} — fires immediately after the request is sent, before the response arrives. * 6. On successful response: shows a success toast, reroutes, and calls {@link onAfterSave}. The form is re-initialized only when `rerouteToParentSlugAfterSave` is `false`. * * @param rerouteToParentSlugAfterSave - When `true` (default), navigates to the parent URL after save. When `false`, re-initializes the form and navigates to the saved object's URL. * * @example * ```html * * ``` * * @example * ```html * * * ``` */ onSave: (rerouteToParentSlugAfterSave?: boolean) => void; /** * Handles navigation after a successful save. * Override this to customize the post-save navigation behavior. * By default, navigates to the parent URL when `rerouteId` is not provided, or to the saved object's URL otherwise. * * @param rerouteId - The ID of the saved object, used to build the target URL. When not provided, navigates to the parent URL. * * @example * ```ts * // Override to navigate to a custom route after save * override rerouteToSavedObject(rerouteId: number | string): void { * this.router.navigateByUrl(`/products/${rerouteId}/details`); * } * ``` */ rerouteToSavedObject(rerouteId: number | string): void; /** * Hook that runs **before** form validation and the save request. * Use this to modify the save body or perform any pre-save logic (e.g., transforming data, setting computed fields). * * @param saveBody - The current save body built from the form's raw value. Mutate it directly to change what gets sent to the server. * * @example * ```ts * onBeforeSave = (saveBody?: ProductSaveBody) => { * saveBody.productDTO.fullName = saveBody.productDTO.firstName + ' ' + saveBody.productDTO.lastName; * }; * ``` */ onBeforeSave: (saveBody?: TSaveBody) => void; /** * Hook that runs **after** a successful save response is received. * Use this for post-save side effects (e.g., refreshing related data, showing additional notifications). * * @example * ```ts * onAfterSave = () => { * this.loadRelatedProducts(); * }; * ``` */ onAfterSave: () => void; /** * Hook that runs immediately **after** the save HTTP request is sent, but **before** the response arrives. * Use this for side effects that should happen as soon as the request is dispatched (e.g., disabling UI elements, starting a loading indicator). * * @example * ```ts * onAfterSaveRequest = () => { * this.isSaving = true; * }; * ``` */ onAfterSaveRequest: () => void; getFormArrayControlByIndex(formControlName: keyof T & string, formArray: SpiderlyFormArray, index: number, filter?: (formGroups: SpiderlyFormGroup[]) => SpiderlyFormGroup[]): SpiderlyFormControl; getFormArrayControls(formControlName: keyof T & string, formArray: SpiderlyFormArray, filter?: (formGroups: SpiderlyFormGroup[]) => SpiderlyFormGroup[]): SpiderlyFormControl[]; removeFormControlsFromTheFormArray(formArray: SpiderlyFormArray, indexes: number[]): void; static ɵfac: i0.ɵɵFactoryDeclaration, never>; static ɵcmp: i0.ɵɵComponentDeclaration, "base-form", never, {}, {}, never, never, false, never>; }