1. Constructor

constructor(
  private injector: Injector,
  public formid: any,
  public menuid: string = "",
  controls: { [key: string]: FormControl | null } = {}
) 

    -Injects necessary services (HttpClient, GBHttpService, ChangeDetectorRef).
    -Calls setFormGroup() to initialize the form based on formid.
    -The form ID can be a string (form configuration JSON filename) or an object.


-----------------------------------------------------------------------------
2. formGetPicklistValue(Url: string, Id: string): Observable<any>

public formGetPicklistValue(Url: string, Id: string): Observable<any> {
  let getUrl = Url + Id;
  return this.https.gbhttpget(getUrl);
}

    -Fetches picklist values from an API using GBHttpService.
    -Used for dropdown fields that require dynamic data.


-----------------------------------------------------------------------------
3. get bFormReady(): boolean (Getter)

public get bFormReady(): boolean {
  return Object.keys(this.controls).length > 0;
}

    -Returns true if form controls are initialized.
    -Helps determine if the form is ready to be used.


-----------------------------------------------------------------------------
4. _getObjectFormData(formObject: any): Observable<any>

private _getObjectFormData(formObject: any): any {
  let jsonFile: string;
  jsonFile = formjson/packset.json;
  return this.http.get(jsonFile)
    .pipe(
      map(res => {
        return (formObject as any);
      })
    );
}

    -Loads a JSON configuration file (packset.json).
    -Returns formObject as-is.
    -Used when the form ID is an object.


-----------------------------------------------------------------------------
5. _getFormData(id: string): Observable<any>

private _getFormData(id: string): Observable<any> {
  let name: string | null = sessionStorage.getItem('MenuObjectModelName');
  let s: any;
  if (name) {
    try {
      s = JSON.parse(name);
    } catch (error) {
      s = 'none';
    }
  } else {
    s = 'none';
  }

  let jsonFile: string;
  if (s.toString().toLowerCase() !== 'none') {
    jsonFile = formjson/ + s + .json;
  } else {
    jsonFile = formjson/ + id + .json;
  }

  return this.http.get(jsonFile).pipe(
    map((res) => {
      return res as any;
    })
  );
}

    -Fetches form data from a JSON file.
    -Uses sessionStorage to determine which JSON file to load.
    -Falls back to id.json if MenuObjectModelName is not set.
    -Converts API response into a form object.


-----------------------------------------------------------------------------
6. setFormGroup()

setFormGroup() {
  if (typeof this.formid == 'string') {
    this.Initialize().subscribe();
  } else {
    this.ObjectInitialize().subscribe();
  }
}

    -Calls either Initialize() (if formid is a string) or ObjectInitialize() (if formid is an object).
    -Ensures correct initialization of the form.


-----------------------------------------------------------------------------
7. ObjectInitialize(): Observable<boolean>

public ObjectInitialize(): Observable<boolean> {
  return this._getObjectFormData(this.formid).pipe(map(res => {
    const form: any = res;
    const formFields = form;
    for (const item of formFields) {
      const Formfield = item;
      if (Formfield.Type) {
        const control = new FormControl(Formfield.DefaultValue);
        (control as any).field = Formfield;
        this.addControl(Formfield.Name, control);
      }
    }
    this.cdr.detectChanges();
    return true;
  }));
}

    -Used when formid is an object.
    -Reads form field definitions from packset.json.
    -Creates form controls dynamically.
    -Uses ChangeDetectorRef.detectChanges() for zoneless change detection.


-----------------------------------------------------------------------------
8. Initialize(): Observable<boolean>

public Initialize(): Observable<boolean> {
  return this._getFormData(this.formid).pipe(
    map((res) => {
      const form: any = res;
      const formFields = form.ObjectFields;
      for (const item of formFields) {
        const Formfield = item;
        if (Formfield.Type) {
          const control = new FormControl(Formfield.DefaultValue);
          (control as any).field = Formfield;
          (control as any).MenuId = this.menuid
          this.addControl(Formfield.Name, control);
        }
      }
      this.cdr.detectChanges();
      return true;
    })
  );
}

    -Used when formid is a string (loads JSON).
    -Retrieves form fields from ObjectFields.
    -Dynamically creates form controls.
    -Associates MenuId with each control.

-----------------------------------------------------------------------------
9. reset()

public override reset() {
  Object.keys(this.controls).forEach((key) => {
    const FormControl = this.controls[key] as FormControl;
    let Control: any = FormControl;
    let Field = Control.field;
    FormControl.setValue(Field.DefaultValue);
  });
}

     -Resets all form controls to their default values.