text: /**
   * @fileoverview added by tsickle
   * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
   */
  /**
   * @license
   * Copyright Google LLC All Rights Reserved.
   *
   * Use of this source code is governed by an MIT-style license that can be
   * found in the LICENSE file at https://angular.io/license
   */
  import { Directionality } from '@angular/cdk/bidi';
  import { Overlay, OverlayConfig } from '@angular/cdk/overlay';
  import { ComponentPortal, PortalInjector, TemplatePortal } from '@angular/cdk/portal';
  import { Injectable, Injector, Optional, SkipSelf, TemplateRef, InjectionToken, Inject, } from '@angular/core';
  import { Location } from '@angular/common';
  import { of as observableOf } from 'rxjs';
  import { MAT_BOTTOM_SHEET_DATA, MatBottomSheetConfig } from './bottom-sheet-config';
  import { MatBottomSheetContainer } from './bottom-sheet-container';
  import { MatBottomSheetModule } from './bottom-sheet-module';
  import { MatBottomSheetRef } from './bottom-sheet-ref';
  import * as i0 from "@angular/core";
  import * as i1 from "@angular/cdk/overlay";
  import * as i2 from "@angular/common";
  import * as i3 from "./bottom-sheet-module";
  /**
   * Injection token that can be used to specify default bottom sheet options.
   * @type {?}
   */
  export const MAT_BOTTOM_SHEET_DEFAULT_OPTIONS = new InjectionToken('mat-bottom-sheet-default-options');
  /**
   * Service to trigger Material Design bottom sheets.
   */
  export class MatBottomSheet {
      /**
       * @param {?} _overlay
       * @param {?} _injector
       * @param {?} _parentBottomSheet
       * @param {?=} _location
       * @param {?=} _defaultOptions
       */
      constructor(_overlay, _injector, _parentBottomSheet, _location, _defaultOptions) {
          this._overlay = _overlay;
          this._injector = _injector;
          this._parentBottomSheet = _parentBottomSheet;
          this._location = _location;
          this._defaultOptions = _defaultOptions;
          this._bottomSheetRefAtThisLevel = null;
      }
      /**
       * Reference to the currently opened bottom sheet.
       * @return {?}
       */
      get _openedBottomSheetRef() {
          /** @type {?} */
          const parent = this._parentBottomSheet;
          return parent ? parent._openedBottomSheetRef : this._bottomSheetRefAtThisLevel;
      }
      /**
       * @param {?} value
       * @return {?}
       */
      set _openedBottomSheetRef(value) {
          if (this._parentBottomSheet) {
              this._parentBottomSheet._openedBottomSheetRef = value;
          }
          else {
              this._bottomSheetRefAtThisLevel = value;
          }
      }
      /**
       * @template T, D, R
       * @param {?} componentOrTemplateRef
       * @param {?=} config
       * @return {?}
       */
      open(componentOrTemplateRef, config) {
          /** @type {?} */
          const _config = _applyConfigDefaults(this._defaultOptions || new MatBottomSheetConfig(), config);
          /** @type {?} */
          const overlayRef = this._createOverlay(_config);
          /** @type {?} */
          const container = this._attachContainer(overlayRef, _config);
          /** @type {?} */
          const ref = new MatBottomSheetRef(container, overlayRef, this._location);
          if (componentOrTemplateRef instanceof TemplateRef) {
              container.attachTemplatePortal(new TemplatePortal(componentOrTemplateRef, (/** @type {?} */ (null)), (/** @type {?} */ ({
                  $implicit: _config.data,
                  bottomSheetRef: ref
              }))));
          }
          else {
              /** @type {?} */
              const portal = new ComponentPortal(componentOrTemplateRef, undefined, this._createInjector(_config, ref));
              /** @type {?} */
              const contentRef = container.attachComponentPortal(portal);
              ref.instance = contentRef.instance;
          }
          // When the bottom sheet is dismissed, clear the reference to it.
          ref.afterDismissed().subscribe((/**
           * @return {?}
           */
          () => {
              // Clear the bottom sheet ref if it hasn't already been replaced by a newer one.
              if (this._openedBottomSheetRef == ref) {
                  this._openedBottomSheetRef = null;
              }
          }));
          if (this._openedBottomSheetRef) {
              // If a bottom sheet is already in view, dismiss it and enter the
              // new bottom sheet after exit animation is complete.
              this._openedBottomSheetRef.afterDismissed().subscribe((/**
               * @return {?}
               */
              () => ref.containerInstance.enter()));
              this._openedBottomSheetRef.dismiss();
          }
          else {
              // If no bottom sheet is in view, enter the new bottom sheet.
              ref.containerInstance.enter();
          }
          this._openedBottomSheetRef = ref;
          return ref;
      }
      /**
       * Dismisses the currently-visible bottom sheet.
       * @return {?}
       */
      dismiss() {
          if (this._openedBottomSheetRef) {
              this._openedBottomSheetRef.dismiss();
          }
      }
      /**
       * @return {?}
       */
      ngOnDestroy() {
          if (this._bottomSheetRefAtThisLevel) {
              this._bottomSheetRefAtThisLevel.dismiss();
          }
      }
      /**
       * Attaches the bottom sheet container component to the overlay.
       * @private
       * @param {?} overlayRef
       * @param {?} config
       * @return {?}
       */
      _attachContainer(overlayRef, config) {
          /** @type {?} */
          const userInjector = config && config.viewContainerRef && config.viewContainerRef.injector;
          /** @type {?} */
          const injector = new PortalInjector(userInjector || this._injector, new WeakMap([
              [MatBottomSheetConfig, config]
          ]));
          /** @type {?} */
          const containerPortal = new ComponentPortal(MatBottomSheetContainer, config.viewContainerRef, injector);
          /** @type {?} */
          const containerRef = overlayRef.attach(containerPortal);
          return containerRef.instance;
      }
      /**
       * Creates a new overlay and places it in the correct location.
       * @private
       * @param {?} config The user-specified bottom sheet config.
       * @return {?}
       */
      _createOverlay(config) {
          /** @type {?} */
          const overlayConfig = new OverlayConfig({
              direction: config.direction,
              hasBackdrop: config.hasBackdrop,
              disposeOnNavigation: config.closeOnNavigation,
              maxWidth: '100%',
              scrollStrategy: config.scrollStrategy || this._overlay.scrollStrategies.block(),
              positionStrategy: this._overlay.position().global().centerHorizontally().bottom('0')
          });
          if (config.backdropClass) {
              overlayConfig.backdropClass = config.backdropClass;
          }
          return this._overlay.create(overlayConfig);
      }
      /**
       * Creates an injector to be used inside of a bottom sheet component.
       * @private
       * @template T
       * @param {?} config Config that was used to create the bottom sheet.
       * @param {?} bottomSheetRef Reference to the bottom sheet.
       * @return {?}
       */
      _createInjector(config, bottomSheetRef) {
          /** @type {?} */
          const userInjector = config && config.viewContainerRef && config.viewContainerRef.injector;
          /** @type {?} */
          const injectionTokens = new WeakMap([
              [MatBottomSheetRef, bottomSheetRef],
              [MAT_BOTTOM_SHEET_DATA, config.data]
          ]);
          if (config.direction &&
              (!userInjector || !userInjector.get(Directionality, null))) {
              injectionTokens.set(Directionality, {
                  value: config.direction,
                  change: observableOf()
              });
          }
          return new PortalInjector(userInjector || this._injector, injectionTokens);
      }
  }
  MatBottomSheet.decorators = [
      { type: Injectable, args: [{ providedIn: MatBottomSheetModule },] },
  ];
  /** @nocollapse */
  MatBottomSheet.ctorParameters = () => [
      { type: Overlay },
      { type: Injector },
      { type: MatBottomSheet, decorators: [{ type: Optional }, { type: SkipSelf }] },
      { type: Location, decorators: [{ type: Optional }] },
      { type: MatBottomSheetConfig, decorators: [{ type: Optional }, { type: Inject, args: [MAT_BOTTOM_SHEET_DEFAULT_OPTIONS,] }] }
  ];
  /** @nocollapse */ MatBottomSheet.ngInjectableDef = i0.ɵɵdefineInjectable({ factory: function MatBottomSheet_Factory() { return new MatBottomSheet(i0.ɵɵinject(i1.Overlay), i0.ɵɵinject(i0.INJECTOR), i0.ɵɵinject(MatBottomSheet, 12), i0.ɵɵinject(i2.Location, 8), i0.ɵɵinject(MAT_BOTTOM_SHEET_DEFAULT_OPTIONS, 8)); }, token: MatBottomSheet, providedIn: i3.MatBottomSheetModule });
  if (false) {
      /**
       * @type {?}
       * @private
       */
      MatBottomSheet.prototype._bottomSheetRefAtThisLevel;
      /**
       * @type {?}
       * @private
       */
      MatBottomSheet.prototype._overlay;
      /**
       * @type {?}
       * @private
       */
      MatBottomSheet.prototype._injector;
      /**
       * @type {?}
       * @private
       */
      MatBottomSheet.prototype._parentBottomSheet;
      /**
       * @type {?}
       * @private
       */
      MatBottomSheet.prototype._location;
      /**
       * @type {?}
       * @private
       */
      MatBottomSheet.prototype._defaultOptions;
  }
  /**
   * Applies default options to the bottom sheet config.
   * @param {?} defaults Object containing the default values to which to fall back.
   * @param {?=} config The configuration to which the defaults will be applied.
   * @return {?} The new configuration object with defaults applied.
   */
  function _applyConfigDefaults(defaults, config) {
      return Object.assign({}, defaults, config);
  }
  //# sourceMappingURL=bottom-sheet.js.map