All files / lib/form form.component.ts

97.06% Statements 826/851
94.64% Branches 106/112
89.13% Functions 41/46
97.06% Lines 826/851

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 8521x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 1x 1x 1x 1x 1x 1x 5749x 5749x 5749x 1x 1x 42x 3x 42x 42x 42x 1x 1x 1x 1x 1x 1806x 1806x 1806x 1x 1x 43x 43x 1x 1x 1x 1x 1x 1x 1x 1x 1813x 1813x 1813x 1x 1x 40x 40x 40x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 46x 46x 46x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 46x 46x 46x 46x 46x 46x 1x 1x 1x 1x 1x 9x 9x 9x 9x 1x 1x 1x 1x 1x 83x 49x 49x 50x 83x 83x 83x 1x 1x 1x 1x 1x 1806x 1806x 1x 1x 1x 1x 1x 2452x 2452x 2452x 2452x 2452x 1x 1x 1x 420x 420x 420x 420x 420x 420x 420x 420x 420x 1x 1x 1x 1x 1x 515x 515x 515x 515x 515x 515x 515x 1x 1x 1x 4x 4x 1x 1x 1x               1x 1x 1x 30x 30x 30x 14x 30x 30x 30x 30x 30x 30x 30x 1x 1x 1x 28x 28x 28x 28x 1x 1x 1x 1x 1x 1036x 3x 1033x 1033x 1033x 25x 25x 1008x 1008x 1036x 1036x 1x 1x 1x 7x 7x 1x 1x 1x 382x 3x   3x 3x 3x 3x 379x 379x 379x 382x 1x 1x 1x 382x 314x 16x 298x 298x 68x 68x 382x 1x 1x 1x 1x 1x 2x 2x 1x 1x 1x 1x 1x 42x 42x 1x 1x 1x 30x 30x 30x 30x 30x 30x 30x 30x 30x 1x 1x 1x 1554x 1554x 1x 1x 1x 1030x 1030x 1x 1x 1x     1x 1x 1x 18x 18x 18x 18x 18x 18x 1x 1x 1x 9x 9x 1x 1x 1x 66x 66x 66x 66x 66x 1x 1x 1x 1x 1x 73x 73x 73x 73x 73x 1x 1x 1x 1x 1x 66x 66x 66x 66x 66x 66x 66x 66x 66x 1x 1x 1x 1x 1x 66x 66x 66x 7x 59x 2x 57x 57x 66x 66x 1x 1x 1x 1x 1x 115x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 97x 115x 1x 1x 1x 1x 1x 97x 97x 97x 97x 97x 97x 200x 200x 97x 97x 97x 200x 200x 97x 97x 97x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 2x 2x 101x 4x 3x 1x 1x 97x 97x 97x 103x 103x 97x 97x 97x 1x 1x 1x 1x 1x 103x 103x 103x 103x 103x 103x 103x 115x 115x 112x 110x 110x 110x 110x 110x 110x 110x 103x 103x 103x 1x 1x 1x 1x 1x 40x 40x 40x 40x 40x 40x 40x 40x 40x 40x 40x 40x 40x 40x 40x 40x 40x 40x 3x 3x 40x 1x 1x 1x 1x 1x     1x 1x 40x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x                   1x 1x 1x 1x 1x     1x  
/*******************************************************************************
 * Copyright bei
 * Entwicklungs- und Pflegeverbund für das gemeinsame Fachverfahren gefa
 *
 *******************************************************************************/
import {
  Component,
  ElementRef,
  EventEmitter,
  Input,
  NgZone,
  OnChanges,
  OnDestroy,
  OnInit,
  Output,
  QueryList,
  SimpleChanges,
  TemplateRef,
  ViewChild,
  ViewChildren,
} from '@angular/core';
 
import { badgeListAsString, observeSize } from '../utils/internal-utils';
import {
  BadgeItem,
  Callback,
  Item,
  Key,
  LinkItem,
  Nullable,
  SlotItem,
} from '../utils/util.types';
import { SoundType, playSound } from '../utils/utilities';
 
import { ComponentMapperDirective } from '../internal/component-mapper.directive';
 
import {
  ButtonComponent,
  ButtonContentDisplay,
} from '../button/button.component';
import {
  DynamicHeadingLevelPassthroughService,
  DynamicHeadingLevelService,
} from '../dynamic-heading/dynamic-heading-level.service';
 
/**
 * Slot where the item is shown:
 * - header: in the header area
 * - footer: in the footer area
 */
export type FormSlots = 'header' | 'footer';
 
type ResponsiveButtonState = 'default' | 'icon-only' | 'in-menu';
 
/**
 * Control the undo/redo buttons
 */
export interface UndoRedoTexts {
  /** text displayed on the undo button, null means disabled */
  readonly undo: string | null;
  /** text displayed on the redo button, null means disabled */
  readonly redo: string | null;
}
 
/**
 * Types of the status which the form can have.
 */
export type FormStatus = 'success' | 'in-progress' | 'default' | 'loading';
 
/**
 * `gc-form` is a layout container used to display input forms.
 */
@Component({
  selector: 'gc-form',
  templateUrl: './form.component.html',
  styleUrls: ['./form.component.css'],
  providers: [DynamicHeadingLevelService],
  viewProviders: [
    {
      provide: DynamicHeadingLevelService,
      useClass: DynamicHeadingLevelPassthroughService,
    },
  ],
})
export class FormComponent implements OnInit, OnDestroy, OnChanges {
  /**
   * @ignore
   */
  @ViewChild('errorElement', { read: ElementRef })
  public errorElement?: ElementRef<HTMLElement>;
 
  /**
   * @ignore
   */
  @ViewChild('formContent')
  public contentElement?: ElementRef<HTMLElement>;
 
  /**
   * @ignore
   */
  @ViewChild('formContainer')
  public containerElement!: ElementRef<HTMLElement>;
 
  /**
   * @ignore
   */
  @ViewChild('gc_ref_undo')
  public undoElement?: ButtonComponent;
 
  /**
   * @ignore
   */
  @ViewChild('gc_ref_redo')
  public redoElement?: ButtonComponent;
 
  /**
   * Title displayed in the header
   */
  @Input()
  public label = '';
 
  /**
   * Title displayed in the header above the label
   */
  @Input()
  public subLabel = '';
 
  /**
   * Actions shown in the form.
   */
  @Input()
  public actions: readonly SlotItem<FormSlots>[] = [];
 
  /**
   * key of the primary action shown in the footer
   */
  @Input()
  public primaryFooterActionKey = '';
 
  /**
   * Footer actions which are rendered with icons for the responsive design. Actual icons must be provided via `footerActionIconTemplate`.
   */
  @Input()
  public footerActionIconKeys: ReadonlySet<string> = new Set();
 
  /**
   * A template that contains all icons for the menu items for the responsive design
   */
  @Input()
  public footerActionIconTemplate?: TemplateRef<unknown>;
 
  /**
   * List of items that will appear in the error section as buttons
   */
  @Input()
  public errorItems: readonly Item[] = [];
 
  /**
   * List of InfoItem elements that will be rendered as hint items below the form header.
   */
  @Input()
  public topInfo: readonly LinkItem[] = [];
 
  /**
   * Title of the top hint section.
   */
  @Input()
  public topInfoTitle = '';
 
  /**
   * List of InfoItem elements that will be rendered as hint items above the form footer.
   */
  @Input()
  public bottomInfo: readonly LinkItem[] = [];
 
  /**
   * Title of the bottom hint section.
   */
  @Input()
  public bottomInfoTitle = '';
 
  /**
   * Title of the error section
   */
  @Input()
  public errorTitle = '';
 
  /**
   * List of items that will appear in the header section as badges
   */
  @Input()
  public badgeItems: readonly BadgeItem[] = [];
 
  /**
   * Text that can be used as a descriptive message for the status.
   */
  @Input()
  public statusText = '';
 
  /**
   * Keys of error items, which are changed in the form
   */
  @Input()
  public changedErrorItemKeys: readonly string[] = [];
 
  /** Optional icon provider to use for menu-items in the form-header */
  @Input()
  public headerMenuItemIconProvider?: TemplateRef<unknown>;
 
  /**
   * Event emitted when Undo-Button is pressed
   */
  @Output()
  public readonly onUndo: EventEmitter<unknown> = new EventEmitter();
 
  /**
   * Event emitted when Redo-Button is pressed
   */
  @Output()
  public readonly onRedo: EventEmitter<unknown> = new EventEmitter();
 
  /**
   * Event emitted when an item is selected
   */
  @Output()
  public readonly onItemAction: EventEmitter<SlotItem<FormSlots>> =
    new EventEmitter<SlotItem<FormSlots>>();
 
  /**
   * Event emitted when an error item is pressed
   */
  @Output()
  public readonly onErrorItemAction: EventEmitter<Item> =
    new EventEmitter<Item>();
 
  /**
   * @ignore
   */
  @ViewChild('footerButtonsLeft')
  private footerButtonsLeftContainer?: ElementRef<HTMLDivElement>;
 
  /**
   * @ignore
   */
  @ViewChild('footerButtonsRightResponsiveCalc')
  private footerButtonsRightContainer?: ElementRef<HTMLDivElement>;
 
  /** @ignore */
  @ViewChildren('footerActionButton', { read: ComponentMapperDirective })
  private footerActionButtons?: QueryList<
    ComponentMapperDirective<ButtonComponent>
  >;
 
  /** @ignore */
  @ViewChildren('footerActionButtonCalc', { read: ElementRef })
  private footerActionButtonsCalc?: QueryList<ElementRef<HTMLElement>>;
 
  /**
   * Current status of the form.
   */
  @Input()
  public get status(): FormStatus {
    return this._status;
  }
 
  public set status(value: FormStatus) {
    if (value === 'success') {
      void playSound(SoundType.SUCCESS);
    }
    this._status = value;
  }
 
  /**
   * keys of all disabled actions
   */
  @Input()
  public get disabledActionKeys(): ReadonlySet<string> {
    return this._disabledActionKeys;
  }
 
  public set disabledActionKeys(value: ReadonlySet<string>) {
    this._disabledActionKeys = value;
  }
 
  /**
   * Update the undo/redo information
   * - null: no undo/redo buttons are shown
   * - { undo: '...', redo: null }: undo enabled, redo disabled
   * - { undo: null, redo: '...' }: undo disabled, redo enabled
   */
  @Input()
  public get undoRedoTexts(): Nullable<UndoRedoTexts> {
    return this._undoRedoTexts;
  }
 
  public set undoRedoTexts(value: Nullable<UndoRedoTexts>) {
    this._undoRedoTexts = value;
    this.refreshUndoRedoState();
  }
 
  /**
   * @ignore
   */
  _errorSectionSmall = false;
 
  /**
   * @ignore
   */
  public _showHeaderSeparator = false;
 
  /**
   * @ignore
   */
  public _undoDisabled = false;
 
  /**
   * @ignore
   */
  public _redoDisabled = false;
 
  /** @ignore */
  protected _responsiveType: 'default' | 'medium' | 'small' = 'default';
 
  /**
   * @ignore
   */
  protected _footerMenuButtonEnabled = false;
 
  /**
   * @ignore
   */
  protected _footerPrimaryButtonWrap = false;
 
  /**
   * @ignore
   */
  protected _footerButtonsResponsiveState: Map<Key, ResponsiveButtonState> =
    new Map();
 
  /**
   * @ignore
   */
  private _disabledActionKeys: ReadonlySet<string> = new Set<string>();
 
  /**
   * @ignore
   */
  private resizeObserver?: Callback;
 
  /**
   * @ignore
   */
  private _status: FormStatus = 'default';
 
  /**
   * @ignore
   */
  private _undoRedoTexts: Nullable<UndoRedoTexts> = null;
 
  /** @ignore */
  private _disabledElements: Map<Element, string | null> = new Map<
    Element,
    string | null
  >();
 
  constructor(
    private el: ElementRef<HTMLElement>,
    private zone: NgZone,
  ) {}
 
  /**
   * Focus the element which corresponds to triggering a specific action.
   *
   * Note that this currently only works for footer actions.
   *
   * @param key the key of the `action` to focus
   * @returns `true` if focus has been transferred
   */
  public focusAction(key: string): boolean {
    const button = this.footerActionButtons?.find(
      i => i.key === key,
    )?.component;
    if (button) {
      return button.focusChild();
    } else {
      return false;
    }
  }
 
  /**
   * Moves the focus to the error section
   *
   * @returns `true` if the focus has been transfered
   */
  public moveFocusToError(): boolean {
    if (this.errorElement) {
      this.errorElement.nativeElement.focus();
      return true;
    }
    return false;
  }
 
  /**
   * @ignore
   */
  ngOnInit(): void {
    this.resizeObserver = observeSize(
      this.el,
      this.zone,
      this.resizeObserverCallback.bind(this),
    );
  }
 
  /**
   * @ignore
   */
  ngOnDestroy(): void {
    if (this.resizeObserver) {
      this.resizeObserver();
    }
  }
 
  /**
   * @ignore
   */
  ngOnChanges(changes: SimpleChanges): void {
    if ('actions' in changes) {
      // wait for new actions to be rendered in footerButtonsRightResponsiveCalc, before calculating new responsive design
      setTimeout(() => {
        this.recomputeResponsiveFooter();
      });
    }
  }
 
  /**
   * @ignore
   */
  _isItemDisabled(item: SlotItem<FormSlots>): boolean {
    return this.disabledActionKeys.has(item.key);
  }
 
  /**
   * @ignore
   */
  public _filterSlot(
    items: readonly SlotItem<FormSlots>[],
    slot: FormSlots,
  ): readonly SlotItem<FormSlots>[] {
    return items.filter(item => item.slot === slot);
  }
 
  /** @ignore */
  protected _filterSlotDisabledKeys(
    items: readonly SlotItem<FormSlots>[],
    slot: FormSlots,
  ): Set<Key> {
    return new Set(
      this._filterSlot(items, slot)
        .filter(i => this._isItemDisabled(i))
        .map(i => i.key),
    );
  }
 
  /**
   * @ignore
   */
  protected _filterSlotVisibleButtons(
    items: readonly SlotItem<FormSlots>[],
    slot: FormSlots,
  ): readonly SlotItem<FormSlots>[] {
    return this._filterSlot(items, slot).filter(
      i => this._footerButtonsResponsiveState.get(i.key) !== 'in-menu',
    );
  }
 
  /** @ignore */
  protected _handleHeaderAction(item: Item): void {
    this.onItemAction.emit(item as SlotItem<FormSlots>);
  }
 
  /** @ignore */
  protected _handleFooterMenuAction(key: string): void {
    if (key === 'undo') {
      this.onUndo.emit();
    }
    if (key === 'redo') {
      this.onRedo.emit();
    }
  }
 
  /** @ignore */
  protected _getDisabledFooterMenuItemKeys(): ReadonlySet<string> {
    const disabledKeys = this._filterSlotDisabledKeys(this.actions, 'footer');
 
    if (this._undoDisabled) {
      disabledKeys.add('undo');
    }
    if (this._redoDisabled) {
      disabledKeys.add('redo');
    }
 
    return disabledKeys;
  }
 
  /** @ignore */
  protected _checkErrorItemsKeys(): boolean {
    return this.errorItems.every(i =>
      this.changedErrorItemKeys.includes(i.key),
    );
  }
 
  /**
   * @ignore
   */
  protected _getFooterButtonContentDisplay(key: string): ButtonContentDisplay {
    if (this._footerButtonsResponsiveState.get(key) === 'icon-only') {
      return 'icon-only';
    } else if (
      this.primaryFooterActionKey === key &&
      this.status !== 'default'
    ) {
      return 'status';
    } else {
      return 'text-only';
    }
  }
 
  /** @ignore */
  protected _handleContentScroll(): void {
    this.recomputeHeader();
  }
 
  /** @ignore */
  protected _redoText(plain?: boolean): string {
    if (typeof this.undoRedoTexts?.redo === 'string') {
      if (plain) {
        return this.undoRedoTexts.redo;
      }
      return this.undoRedoTexts.redo.replace(
        'Wiederherstellen',
        '**Wiederherstellen**',
      );
    }
    return 'Wiederherstellen';
  }
 
  /** @ignore */
  protected _undoText(plain?: boolean): string {
    if (typeof this.undoRedoTexts?.undo === 'string') {
      if (plain) {
        return this.undoRedoTexts.undo;
      }
      return this.undoRedoTexts.undo.replace('Rückgängig', '**Rückgängig**');
    }
    return 'Rückgängig';
  }
 
  /**
   * @ignore
   */
  protected _handleErrorItemAction(item: Item): void {
    this.onErrorItemAction.emit(item);
  }
 
  /**
   * @ignore
   */
  protected hasCorrespondingFieldChanged(itemKey: string): boolean {
    return this.changedErrorItemKeys.some(v => v === itemKey);
  }
 
  /** @ignore */
  protected _footerMenuItems(): readonly Item[] {
    return [
      ...this.actions.filter(
        action =>
          this._footerButtonsResponsiveState.get(action.key) === 'in-menu',
      ),
      { key: 'undo', label: this._undoText(true) },
      { key: 'redo', label: this._redoText(true) },
    ];
  }
 
  /** @ignore */
  protected _hasCriticalBadge() {
    return this.badgeItems.findIndex(b => b.status === 'critical') != -1;
  }
 
  /** @ignore */
  protected _hasDefaultBadge() {
    return this.badgeItems.findIndex(b => b.status !== 'critical') != -1;
  }
 
  /** @ignore */
  protected _defaultBadgeItems() {
    return this.badgeItems.filter(b => b.status !== 'critical');
  }
 
  /** @ignore */
  protected _criticalBadgeItems(): BadgeItem[] {
    return this.badgeItems
      .filter(b => b.status === 'critical')
      .map(b => {
        return { ...b, showIcon: true } satisfies BadgeItem;
      });
  }
 
  /** @ignore */
  protected _badgeString(items: BadgeItem[]) {
    return badgeListAsString(items);
  }
 
  /** @ignore */
  private resizeObserverCallback(): void {
    this.recomputeErrorSection();
    this.recomputeHeader();
    this.recomputeResponsiveFooter();
    this.computeScrollareas();
  }
 
  /**
   * @ignore
   */
  private recomputeHeader() {
    if (this.contentElement?.nativeElement) {
      this._showHeaderSeparator =
        this.contentElement.nativeElement.scrollTop > 0;
    }
  }
 
  /**
   * @ignore
   */
  private recomputeErrorSection(): void {
    if (
      this.contentElement?.nativeElement &&
      this.contentElement.nativeElement.getBoundingClientRect().width < 400
    ) {
      this._errorSectionSmall = true;
    } else {
      this._errorSectionSmall = false;
    }
  }
 
  /**
   * @ignore
   */
  private computeScrollareas() {
    const formHeight = this.el.nativeElement.getBoundingClientRect().height;
 
    if (formHeight <= 432) {
      this._responsiveType = 'small';
    } else if (formHeight <= 672) {
      this._responsiveType = 'medium';
    } else {
      this._responsiveType = 'default';
    }
  }
 
  /**
   * @ignore
   */
  private recomputeResponsiveFooter(): void {
    if (this.footerButtonsLeftContainer && this.footerButtonsRightContainer) {
      if (this.undoRedoTexts === null) {
        return;
      }
 
      const formWidth = this.el.nativeElement.getBoundingClientRect().width;
      const footerButtonsRightContainerWidth =
        this.footerButtonsRightContainer.nativeElement.getBoundingClientRect()
          .width;
      const computedMargin = Number.parseFloat(
        getComputedStyle(this.el.nativeElement).getPropertyValue(
          '--gc-form-box-margin',
        ),
      );
 
      const margin = isNaN(computedMargin) ? 0 : computedMargin;
      const horizontalPadding = 16;
      const availableWidth = formWidth - 2 * horizontalPadding - margin * 2;
 
      const iconButtonWidth = 40;
      const buttonSpacing = 16;
      const undoRedoArea = iconButtonWidth * 2 + buttonSpacing;
 
      const total =
        footerButtonsRightContainerWidth + buttonSpacing + undoRedoArea;
 
      this._footerMenuButtonEnabled = total > availableWidth;
      this._footerButtonsResponsiveState =
        this.updateResponsiveFooterButtons(availableWidth);
      this._footerPrimaryButtonWrap = [
        ...this._footerButtonsResponsiveState,
      ].every(([, val]) => {
        return val === 'in-menu';
      });
    }
  }
 
  /**
   * @ignore
   */
  private updateResponsiveFooterButtons(
    availableWidth: number,
  ): Map<string, ResponsiveButtonState> {
    const buttonSpacing = 16;
    const iconButtonWidth = 40;
    const primaryButtonWidth = this.footerActionButtonsCalc?.find(
      i =>
        i.nativeElement.dataset.formResponsiveCalcButtonKey ===
        this.primaryFooterActionKey,
    )?.nativeElement.clientWidth;
    const responsiveButtons: Map<Key, ResponsiveButtonState> = new Map();
    this._filterSlot(this.actions, 'footer').forEach(action => {
      if (action.key !== this.primaryFooterActionKey) {
        responsiveButtons.set(action.key, 'default');
      }
    });
    responsiveButtons.forEach((_value, key) => {
      if (
        key !== this.primaryFooterActionKey &&
        this.footerButtonsRightContainer &&
        primaryButtonWidth
      ) {
        const footerRigthWidth =
          this.calcResponsiveFooterWidth(responsiveButtons);
        const requiredWidth =
          iconButtonWidth +
          buttonSpacing +
          footerRigthWidth +
          primaryButtonWidth;
        const fullButtonWidth = this.footerActionButtonsCalc?.find(
          i => i.nativeElement.dataset.formResponsiveCalcButtonKey === key,
        )?.nativeElement.clientWidth;
 
        if (
          fullButtonWidth &&
          requiredWidth - fullButtonWidth + iconButtonWidth > availableWidth
        ) {
          responsiveButtons.set(key, 'in-menu');
        } else if (requiredWidth > availableWidth) {
          if (this.footerActionIconKeys.has(key)) {
            responsiveButtons.set(key, 'icon-only');
          } else {
            responsiveButtons.set(key, 'in-menu');
          }
        } else {
          responsiveButtons.set(key, 'default');
        }
      }
    });
    return responsiveButtons;
  }
 
  /**
   * @ignore
   */
  private calcResponsiveFooterWidth(
    responsiveState: Map<string, ResponsiveButtonState>,
  ) {
    const iconButtonWidth = 40;
    const buttonSpacing = 16;
    let width = 0;
 
    responsiveState.forEach((state, key) => {
      if (state === 'icon-only') {
        width = width + iconButtonWidth + buttonSpacing;
      } else if (state === 'default') {
        const buttonWidth = this.footerActionButtonsCalc?.find(
          i => i.nativeElement.dataset.formResponsiveCalcButtonKey === key,
        )?.nativeElement.clientWidth;
        if (buttonWidth !== undefined) {
          width = width + buttonWidth + buttonSpacing;
        }
      }
    });
    return width;
  }
 
  /**
   * @ignore
   */
  private refreshUndoRedoState() {
    if (this.undoRedoTexts === null) {
      return;
    }
 
    const newUndo = this.undoRedoTexts.undo === null;
    const newRedo = this.undoRedoTexts.redo === null;
 
    const curUndo = this._undoDisabled;
    const curRedo = this._redoDisabled;
 
    this._undoDisabled = newUndo;
    this._redoDisabled = newRedo;
 
    const undoElement = this.undoElement;
    const redoElement = this.redoElement;
 
    if (
      undoElement !== undefined &&
      redoElement !== undefined &&
      ((!curUndo && newUndo) || (!curRedo && newRedo))
    ) {
      const undoFocused = undoElement.hasFocus;
      const redoFocused = redoElement.hasFocus;
 
      if (undoFocused && !curUndo && newUndo) {
        this.updateUndoFocus();
      } else if (redoFocused && !curRedo && newRedo) {
        this.updateRedoFocus();
      }
    }
  }
 
  /**
   * @ignore
   */
  private updateUndoFocus() {
    if (
      (this._undoDisabled && this._redoDisabled) ||
      this.redoElement === undefined
    ) {
      this.shiftFocusToOutside();
    } else if (this._undoDisabled && !this._redoDisabled) {
      this.redoElement.focusChild();
    }
  }
 
  /**
   * @ignore
   */
  private updateRedoFocus() {
    if (
      (this._undoDisabled && this._redoDisabled) ||
      this.undoElement === undefined
    ) {
      this.shiftFocusToOutside();
    } else if (this._redoDisabled && !this._undoDisabled) {
      this.undoElement.focusChild();
    }
  }
 
  /**
   * @ignore
   */
  private shiftFocusToOutside() {
    console.info('Unable to move focus to undo/redo button');
  }
}