import { Injectable , Injector } from '@angular/core' ; import { OverlayModalComponent } from '../../common/components/overlay-modal/overlay-modal.component' ; import isMobile from '../../helpers/is-mobile' ; @ Injectable ( ) export class OverlayModalService { private container : OverlayModalComponent ; private _onDidDismissFn : Function ; protected stackable : boolean = false ; static _ ( ) { return new OverlayModalService ( ) ; } setContainer ( container ) { this . container = container ; return this ; } setRoot ( root ) { this . container . setRoot ( root ) ; return this ; } create ( component , data ? , opts ? , injector ? ) { if ( ! this . container ) { throw new Error ( 'Missing overlay container' ) ; } if ( opts && opts . stackable ) { this . stackable = true ; } this . _onDidDismissFn = void 0 ; this . container . create ( component , opts , injector ) ; this . container . setData ( data ) ; if ( opts ) { this . container . setOpts ( opts ) ; } return this ; } setData ( data ? ) { if ( ! this . container ) { throw new Error ( 'Missing overlay container' ) ; } this . container . setData ( data ) ; return this ; } onDidDismiss ( fn ? ) { if ( ! this . container ) { throw new Error ( 'Missing overlay container' ) ; } this . _onDidDismissFn = fn ; return this ; } _didDismiss ( data ? ) { if ( this . _onDidDismissFn ) { this . _onDidDismissFn ( data ) ; } } present ( ) { if ( ! this . container ) { throw new Error ( 'Missing overlay container' ) ; } this . container . present ( ) ; return this ; } dismiss ( data ? ) { if ( ! this . container ) { throw new Error ( 'Missing overlay container' ) ; } this . container . dismiss ( data ) ; this . _onDidDismissFn = void 0 ; return this ; } canOpenInModal ( ) { const isNotTablet = Math . min ( screen . width , screen . height ) < 768 ; const tooSmallForModal = screen . width < 768 ; if ( ( isMobile ( ) && isNotTablet ) || tooSmallForModal ) { return false ; } return true ; } }