import { ChangeDetectionStrategy , ChangeDetectorRef , Component , Directive , ElementRef , HostListener , Input , OnChanges , OnInit , Optional , SimpleChanges , } from '@angular/core' ; import { SbbDialog } from './dialog' ; import { SbbDialogRef , _closeDialogVia } from './dialog-ref' ; /** Counter used to generate unique IDs for dialog elements. */ let dialogElementUid = 0 ; /**
 * Button that will close the current dialog.
 */ @ Directive ( { selector : '[sbb-dialog-close], [sbbDialogClose]' , exportAs : 'sbbDialogClose' , host : { '[attr.aria-label]' : 'ariaLabel || null' , '[attr.type]' : 'type' , } , } ) export class SbbDialogClose implements OnInit , OnChanges { /** Screenreader label for the button. */ @ Input ( 'aria-label' ) ariaLabel : string = typeof $localize === 'function' ? $localize `:Aria label to close a dialog@@sbbDialogCloseDialog:Close dialog` : 'Close dialog' ; /** Default to "button" to prevents accidental form submits. */ @ Input ( ) type : 'submit' | 'button' | 'reset' = 'button' ; /** Dialog close input. */ @ Input ( 'sbb-dialog-close' ) dialogResult : any ; @ Input ( 'sbbDialogClose' ) _sbbDialogClose : any ; constructor ( @ Optional ( ) private _dialogRef , private _elementRef , private _dialog ) { } ngOnInit ( ) { if ( ! this . _dialogRef ) { this . _dialogRef = getClosestDialog ( this . _elementRef , this . _dialog . openDialogs ) ! ; } } ngOnChanges ( changes ) { const proxiedChange = changes [ '_sbbDialogClose' ] || changes [ '_sbbDialogCloseResult' ] ; if ( proxiedChange ) { this . dialogResult = proxiedChange . currentValue ; } } @ HostListener ( 'click' , [ '$event' ] ) _onButtonClick ( event ) { _closeDialogVia ( this . _dialogRef , event . screenX === 0 && event . screenY === 0 ? 'keyboard' : 'mouse' , this . dialogResult ) ; } } /**
 * Base class for dialog title.
 */ @ Directive ( ) export class _SbbDialogTitleBase implements OnInit { /** Unique id for the dialog title. If none is supplied, it will be auto-generated. */ @ Input ( ) id : string = `sbb-dialog-title-${ dialogElementUid ++ }` ; /** Whether the close button is disabled for the dialog. */ _closeEnabled : boolean = false ; constructor ( @ Optional ( ) protected _dialogRef , private _elementRef , private _dialog , private _changeDetectorRef ) { } ngOnInit ( ) { if ( ! this . _dialogRef ) { this . _dialogRef = getClosestDialog ( this . _elementRef , this . _dialog . openDialogs ) ! ; } if ( this . _dialogRef ) { Promise . resolve ( ) . then ( ( ) => { const container = this . _dialogRef . _containerInstance ; if ( ! container ) { return ; } if ( ! container . _config . disableClose ) { this . _closeEnabled = true ; this . _changeDetectorRef . markForCheck ( ) ; } if ( ! container . _ariaLabelledBy ) { container . _ariaLabelledBy = this . id ; } } ) ; } } } /**
 * Title of a dialog element. Stays fixed to the top of the dialog when scrolling.
 */ @ Component ( { selector : 'sbb-dialog-title, [sbb-dialog-title], [sbbDialogTitle]' , exportAs : 'sbbDialogTitle' , template : `
    <ng-content></ng-content>
    <button
      *ngIf="_closeEnabled"
      sbb-dialog-close
      class="sbb-dialog-title-close-button sbb-button-reset-frameless"
    >
      <sbb-icon svgIcon="kom:cross-small"></sbb-icon>
    </button>
  ` , changeDetection : ChangeDetectionStrategy . OnPush , host : { class : 'sbb-dialog-title' , '[id]' : 'id' , } , } ) export class SbbDialogTitle extends _SbbDialogTitleBase { } /**
 * Scrollable content container of a dialog.
 */ @ Directive ( { selector : `[sbb-dialog-content], sbb-dialog-content, [sbbDialogContent]` , host : { class : 'sbb-dialog-content sbb-scrollbar' } , } ) export class SbbDialogContent { } /**
 * Container for the bottom action buttons in a dialog.
 * Stays fixed to the bottom when scrolling.
 */ @ Directive ( { selector : `[sbb-dialog-actions], sbb-dialog-actions, [sbbDialogActions]` , host : { class : 'sbb-dialog-actions' } , } ) export class SbbDialogActions { } param element param openDialogs function getClosestDialog ( element , openDialogs ) { let parent = element . nativeElement . parentElement ; while ( parent && ! parent . classList . contains ( 'sbb-dialog-container' ) && ! parent . classList . contains ( 'sbb-lightbox-container' ) ) { parent = parent . parentElement ; } return parent ? openDialogs . find ( ( dialog ) => dialog . id === parent ! . id ) : null ; }