(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('rxjs/operators'), require('rxjs'), require('@angular/core'), require('@angular/animations'), require('@bravobit/bb-foundation'), require('@bravobit/bb-foundation/elements'), require('@bravobit/bb-foundation/localize'), require('@angular/common')) :
    typeof define === 'function' && define.amd ? define('@bravobit/bb-foundation/dialog', ['exports', 'rxjs/operators', 'rxjs', '@angular/core', '@angular/animations', '@bravobit/bb-foundation', '@bravobit/bb-foundation/elements', '@bravobit/bb-foundation/localize', '@angular/common'], factory) :
    (global = global || self, factory((global.bravobit = global.bravobit || {}, global.bravobit['bb-foundation'] = global.bravobit['bb-foundation'] || {}, global.bravobit['bb-foundation'].dialog = {}), global.rxjs.operators, global.rxjs, global.ng.core, global.ng.animations, global.bravobit['bb-foundation'], global.bravobit['bb-foundation'].elements, global.bravobit['bb-foundation'].localize, global.ng.common));
}(this, (function (exports, operators, rxjs, core, animations, bbFoundation, elements, localize, common) { 'use strict';

    /*! *****************************************************************************
    Copyright (c) Microsoft Corporation. All rights reserved.
    Licensed under the Apache License, Version 2.0 (the "License"); you may not use
    this file except in compliance with the License. You may obtain a copy of the
    License at http://www.apache.org/licenses/LICENSE-2.0

    THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
    WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
    MERCHANTABLITY OR NON-INFRINGEMENT.

    See the Apache Version 2.0 License for specific language governing permissions
    and limitations under the License.
    ***************************************************************************** */
    /* global Reflect, Promise */

    var extendStatics = function(d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };

    function __extends(d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    }

    var __assign = function() {
        __assign = Object.assign || function __assign(t) {
            for (var s, i = 1, n = arguments.length; i < n; i++) {
                s = arguments[i];
                for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
            }
            return t;
        };
        return __assign.apply(this, arguments);
    };

    function __rest(s, e) {
        var t = {};
        for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
            t[p] = s[p];
        if (s != null && typeof Object.getOwnPropertySymbols === "function")
            for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
                if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                    t[p[i]] = s[p[i]];
            }
        return t;
    }

    function __decorate(decorators, target, key, desc) {
        var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
        if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
        else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
        return c > 3 && r && Object.defineProperty(target, key, r), r;
    }

    function __param(paramIndex, decorator) {
        return function (target, key) { decorator(target, key, paramIndex); }
    }

    function __metadata(metadataKey, metadataValue) {
        if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
    }

    function __awaiter(thisArg, _arguments, P, generator) {
        return new (P || (P = Promise))(function (resolve, reject) {
            function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
            function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
            function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
            step((generator = generator.apply(thisArg, _arguments || [])).next());
        });
    }

    function __generator(thisArg, body) {
        var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
        return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
        function verb(n) { return function (v) { return step([n, v]); }; }
        function step(op) {
            if (f) throw new TypeError("Generator is already executing.");
            while (_) try {
                if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
                if (y = 0, t) op = [op[0] & 2, t.value];
                switch (op[0]) {
                    case 0: case 1: t = op; break;
                    case 4: _.label++; return { value: op[1], done: false };
                    case 5: _.label++; y = op[1]; op = [0]; continue;
                    case 7: op = _.ops.pop(); _.trys.pop(); continue;
                    default:
                        if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                        if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                        if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                        if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                        if (t[2]) _.ops.pop();
                        _.trys.pop(); continue;
                }
                op = body.call(thisArg, _);
            } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
            if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
        }
    }

    function __exportStar(m, exports) {
        for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
    }

    function __values(o) {
        var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
        if (m) return m.call(o);
        return {
            next: function () {
                if (o && i >= o.length) o = void 0;
                return { value: o && o[i++], done: !o };
            }
        };
    }

    function __read(o, n) {
        var m = typeof Symbol === "function" && o[Symbol.iterator];
        if (!m) return o;
        var i = m.call(o), r, ar = [], e;
        try {
            while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
        }
        catch (error) { e = { error: error }; }
        finally {
            try {
                if (r && !r.done && (m = i["return"])) m.call(i);
            }
            finally { if (e) throw e.error; }
        }
        return ar;
    }

    function __spread() {
        for (var ar = [], i = 0; i < arguments.length; i++)
            ar = ar.concat(__read(arguments[i]));
        return ar;
    }

    function __spreadArrays() {
        for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
        for (var r = Array(s), k = 0, i = 0; i < il; i++)
            for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
                r[k] = a[j];
        return r;
    };

    function __await(v) {
        return this instanceof __await ? (this.v = v, this) : new __await(v);
    }

    function __asyncGenerator(thisArg, _arguments, generator) {
        if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
        var g = generator.apply(thisArg, _arguments || []), i, q = [];
        return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
        function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
        function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
        function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
        function fulfill(value) { resume("next", value); }
        function reject(value) { resume("throw", value); }
        function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
    }

    function __asyncDelegator(o) {
        var i, p;
        return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
        function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
    }

    function __asyncValues(o) {
        if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
        var m = o[Symbol.asyncIterator], i;
        return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
        function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
        function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
    }

    function __makeTemplateObject(cooked, raw) {
        if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
        return cooked;
    };

    function __importStar(mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
        result.default = mod;
        return result;
    }

    function __importDefault(mod) {
        return (mod && mod.__esModule) ? mod : { default: mod };
    }

    var BbDialogRef = /** @class */ (function () {
        function BbDialogRef() {
            // Data.
            this._afterClosed$ = new rxjs.Subject();
            this._overlayClicked$ = new rxjs.Subject();
        }
        Object.defineProperty(BbDialogRef.prototype, "afterClosed", {
            get: function () {
                return this._afterClosed$.pipe(operators.take(1));
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(BbDialogRef.prototype, "overlayClicked", {
            get: function () {
                return this._overlayClicked$.pipe(operators.take(1));
            },
            enumerable: true,
            configurable: true
        });
        BbDialogRef.prototype.onOverlayClicked = function () {
            this._overlayClicked$.next();
        };
        BbDialogRef.prototype.close = function (result) {
            this._afterClosed$.next(result);
        };
        return BbDialogRef;
    }());

    var BbDialogConfig = /** @class */ (function () {
        function BbDialogConfig() {
        }
        return BbDialogConfig;
    }());

    var BbDialogOverlay = /** @class */ (function () {
        function BbDialogOverlay(_elementRef) {
            this._elementRef = _elementRef;
            // Inputs.
            this.animations = true;
            // Outputs.
            this.closeRequested = new core.EventEmitter();
            // State.
            this._state = 'open';
            this._closed$ = new rxjs.Subject();
        }
        Object.defineProperty(BbDialogOverlay.prototype, "state", {
            get: function () {
                return this.animations
                    ? this._state
                    : 'none';
            },
            enumerable: true,
            configurable: true
        });
        BbDialogOverlay.prototype.ngAfterViewInit = function () {
            this.listenForClicks();
        };
        BbDialogOverlay.prototype.ngOnDestroy = function () {
            this._subscription && this._subscription.unsubscribe();
        };
        BbDialogOverlay.prototype.onKeyEvent = function (event) {
            if (event.key === 'Escape') {
                this.closeRequested.emit();
            }
        };
        BbDialogOverlay.prototype.onAnimationDone = function (event) {
            // Check if the dialog is being destroyed.
            if (!['close', 'none'].includes(event.toState)) {
                return;
            }
            this._closed$.next();
            this._closed$.complete();
        };
        BbDialogOverlay.prototype.close = function () {
            this._state = 'close';
            return this._closed$.pipe(operators.take(1)).toPromise();
        };
        BbDialogOverlay.prototype.listenForClicks = function () {
            var _this = this;
            if (!this._elementRef || !this._elementRef.nativeElement) {
                return;
            }
            var mouseDown$ = rxjs.fromEvent(this._elementRef.nativeElement, 'mousedown');
            var touchStart$ = rxjs.fromEvent(this._elementRef.nativeElement, 'touchstart');
            var start$ = rxjs.race([mouseDown$, touchStart$]);
            var mouseUp$ = rxjs.fromEvent(this._elementRef.nativeElement, 'mouseup');
            var touchEnd$ = rxjs.fromEvent(this._elementRef.nativeElement, 'touchend');
            var end$ = rxjs.race([mouseUp$, touchEnd$]);
            this._subscription = start$.pipe(operators.switchMap(function () { return end$; })).subscribe(function () {
                _this.closeRequested.next();
            });
        };
        BbDialogOverlay.ctorParameters = function () { return [
            { type: core.ElementRef }
        ]; };
        __decorate([
            core.Input()
        ], BbDialogOverlay.prototype, "animations", void 0);
        __decorate([
            core.Output()
        ], BbDialogOverlay.prototype, "closeRequested", void 0);
        __decorate([
            core.HostListener('window:keyup', ['$event'])
        ], BbDialogOverlay.prototype, "onKeyEvent", null);
        __decorate([
            core.HostListener('@bbDialogAnimation.done', ['$event'])
        ], BbDialogOverlay.prototype, "onAnimationDone", null);
        BbDialogOverlay = __decorate([
            core.Component({
                selector: 'bb-dialog-overlay',
                template: "<div class=\"bb-dialog-overlay-backdrop\"></div>\n\n<ng-content select=\"[bb-dialog-modal]\"></ng-content>\n",
                changeDetection: core.ChangeDetectionStrategy.OnPush,
                encapsulation: core.ViewEncapsulation.None,
                preserveWhitespaces: false,
                host: { 'class': 'bb-dialog-overlay', '[@bbDialogAnimation]': 'state' },
                animations: [
                    animations.trigger('bbDialogAnimation', [
                        animations.transition('* => none', []),
                        animations.transition(':enter, * => open', [
                            animations.group([
                                animations.query('.bb-dialog-overlay-backdrop', [
                                    animations.style({ opacity: 0 }),
                                    animations.animate('150ms cubic-bezier(0, 0, 0.2, 1)', animations.style({ opacity: 1 }))
                                ]),
                                animations.query('.bb-dialog-modal', [
                                    animations.style({ transform: 'scale(0.95)' }),
                                    animations.animate('150ms cubic-bezier(0, 0, 0.2, 1)', animations.style({ transform: 'scale(1)' }))
                                ])
                            ])
                        ]),
                        animations.transition(':leave, * => close', [
                            animations.group([
                                animations.query('.bb-dialog-overlay-backdrop', [
                                    animations.animate('150ms cubic-bezier(0, 0, 0.2, 1)', animations.style({ opacity: 0 }))
                                ]),
                                animations.query('.bb-dialog-modal', [
                                    animations.animate('150ms cubic-bezier(0, 0, 0.2, 1)', animations.style({ opacity: 0, transform: 'scale(0.95)' }))
                                ])
                            ])
                        ])
                    ])
                ],
                styles: [".bb-dialog-overlay,.bb-dialog-overlay-backdrop{top:0;left:0;right:0;bottom:0;display:-webkit-box;display:-ms-flexbox;display:flex;z-index:1000;position:fixed;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column}.bb-dialog-overlay{padding:20px}.bb-dialog-overlay-backdrop{background-color:rgba(0,0,0,.5)}.bb-dialog-overlay-component{z-index:1001;display:block;position:relative}"]
            })
        ], BbDialogOverlay);
        return BbDialogOverlay;
    }());

    var BbDialogModal = /** @class */ (function () {
        function BbDialogModal(_patch) {
            this._patch = _patch;
            // Styling.
            this.maxWidth = '420px';
        }
        BbDialogModal.prototype.onOverlayClickedEvent = function (event) {
            event.stopPropagation();
        };
        BbDialogModal.prototype.ngOnInit = function () {
            this._patch.mobileVerticalHeight();
        };
        BbDialogModal.ctorParameters = function () { return [
            { type: bbFoundation.Patch }
        ]; };
        __decorate([
            core.HostBinding('style.max-width'), core.Input()
        ], BbDialogModal.prototype, "maxWidth", void 0);
        __decorate([
            core.HostListener('click', ['$event']),
            core.HostListener('touchstart', ['$event']),
            core.HostListener('touchend', ['$event']),
            core.HostListener('mouseup', ['$event']),
            core.HostListener('mousedown', ['$event'])
        ], BbDialogModal.prototype, "onOverlayClickedEvent", null);
        BbDialogModal = __decorate([
            core.Component({
                selector: '[bb-dialog-modal]',
                template: "<ng-content select=\"[bb-dialog-header]\">\n\n</ng-content>\n\n<div class=\"bb-dialog-modal-body\">\n    <ng-content></ng-content>\n</div>\n\n<ng-content select=\"[bb-dialog-actions]\">\n\n</ng-content>\n",
                changeDetection: core.ChangeDetectionStrategy.OnPush,
                encapsulation: core.ViewEncapsulation.None,
                preserveWhitespaces: false,
                host: {
                    'class': 'bb-dialog-modal',
                    'role': 'dialog'
                },
                styles: [".bb-dialog-modal{width:100%;margin:auto;z-index:1001;display:-webkit-box;display:-ms-flexbox;display:flex;max-width:420px;border-radius:4px;position:relative;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column;background-color:#fff;max-height:calc((var(--vh,1vh) * 100) - 40px)}.bb-dialog-modal-body{padding:20px;color:#738694;font-size:13px;overflow-y:auto;line-height:1.4;background-color:#f1f3f6}"]
            })
        ], BbDialogModal);
        return BbDialogModal;
    }());

    var BbDialogHeader = /** @class */ (function () {
        function BbDialogHeader() {
            // Inputs.
            this.iconName = null;
            this.iconColor = 'black';
            // Outputs.
            this.closeRequested = new core.EventEmitter();
        }
        __decorate([
            core.Input()
        ], BbDialogHeader.prototype, "iconName", void 0);
        __decorate([
            core.Input()
        ], BbDialogHeader.prototype, "iconColor", void 0);
        __decorate([
            core.Output()
        ], BbDialogHeader.prototype, "closeRequested", void 0);
        BbDialogHeader = __decorate([
            core.Component({
                selector: '[bb-dialog-header]',
                template: "<div class=\"bb-dialog-header-row\">\n    <div *ngIf=\"iconName as icon\"\n         [style.color]=\"iconColor\"\n         class=\"bb-dialog-header-icon\">\n        <i class=\"material-icons\">{{ icon }}</i>\n    </div>\n\n    <div class=\"bb-dialog-header-content\">\n        <ng-content></ng-content>\n    </div>\n\n    <button *ngIf=\"closeRequested?.observers?.length > 0\"\n            (click)=\"closeRequested?.emit()\"\n            type=\"button\"\n            class=\"bb-dialog-header-close\">\n    </button>\n</div>\n\n<nav class=\"bb-dialog-header-navigation\">\n    <ng-content select=\"[bb-dialog-link]\"></ng-content>\n</nav>\n",
                changeDetection: core.ChangeDetectionStrategy.OnPush,
                encapsulation: core.ViewEncapsulation.None,
                preserveWhitespaces: false,
                host: { 'class': 'bb-dialog-header' },
                styles: [".bb-dialog-header{display:-webkit-box;display:-ms-flexbox;display:flex;min-height:60px;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;background-color:#fff;border-top-left-radius:4px;border-top-right-radius:4px;border-bottom:1px solid #d8d8d8}.bb-dialog-header .bb-dialog-header-content,.bb-dialog-header .bb-dialog-header-content h1{max-width:100%;font-size:20px;font-weight:500;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.bb-dialog-header-navigation,.bb-dialog-header-row{width:100%;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center}.bb-dialog-header-row{padding:10px 20px}.bb-dialog-header-navigation{width:100%;padding:0 20px;overflow-x:auto;white-space:nowrap}.bb-dialog-header-navigation:empty{margin:0;height:0;padding:0;visibility:hidden}.bb-dialog-header-content{-webkit-box-flex:1;-ms-flex:1;flex:1}.bb-dialog-header-icon{width:40px;height:40px;display:-webkit-box;display:-ms-flexbox;display:flex;min-width:40px;overflow:hidden;min-height:40px;margin-right:10px;border-radius:50%;position:relative;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center}.bb-dialog-header-icon:after{top:0;left:0;right:0;bottom:0;content:\"\";opacity:.14;position:absolute;background-color:currentColor}.bb-dialog-header-close{width:32px;height:32px;border:none;min-width:32px;min-height:32px;overflow:hidden;margin-left:10px;border-radius:4px;position:relative;margin-right:-10px;display:inline-block;background-color:transparent}.bb-dialog-header-close:after,.bb-dialog-header-close:before{top:50%;left:20%;width:60%;height:2px;content:\"\";margin-top:-1px;position:absolute;background-color:#a2a9ba}.bb-dialog-header-close:before{-webkit-transform:rotate(45deg);-ms-transform:rotate(45deg);transform:rotate(45deg)}.bb-dialog-header-close:after{-webkit-transform:rotate(-45deg);-ms-transform:rotate(-45deg);transform:rotate(-45deg)}.bb-dialog-header-close:hover{background-color:rgba(0,0,0,.08)}.bb-dialog-header-close:focus{background-color:rgba(0,0,0,.12)}.bb-dialog-header-close:active{background-color:rgba(0,0,0,.16)}"]
            })
        ], BbDialogHeader);
        return BbDialogHeader;
    }());

    var BbDialogLink = /** @class */ (function () {
        function BbDialogLink() {
        }
        BbDialogLink = __decorate([
            core.Component({
                selector: '[bb-dialog-link]',
                template: "<ng-content></ng-content>\n",
                changeDetection: core.ChangeDetectionStrategy.OnPush,
                encapsulation: core.ViewEncapsulation.None,
                preserveWhitespaces: false,
                host: { 'class': 'bb-dialog-link' },
                styles: [".bb-dialog-link{height:30px;display:-webkit-box;display:-ms-flexbox;display:flex;font-size:16px;font-weight:500;white-space:nowrap;-webkit-box-align:center;-ms-flex-align:center;align-items:center;color:#6b5c5c!important;background-color:transparent;text-decoration:none!important;border-bottom:2px solid transparent}.bb-dialog-link+.bb-dialog-link{margin-left:10px}.bb-dialog-link:hover:not(.disabled){border-bottom:2px solid rgba(117,119,148,.2)}.bb-dialog-link.active,.bb-dialog-link.active:hover{color:#5b53ff!important;border-bottom-color:#5b53ff}.bb-dialog-link.disabled,.bb-dialog-link.disabled:active,.bb-dialog-link.disabled:focus,.bb-dialog-link.disabled:hover{opacity:.4;cursor:default;box-shadow:none}"]
            })
        ], BbDialogLink);
        return BbDialogLink;
    }());

    var BbDialogActions = /** @class */ (function () {
        function BbDialogActions() {
        }
        BbDialogActions = __decorate([
            core.Component({
                selector: '[bb-dialog-actions]',
                template: "<bb-form-group class=\"end\">\n    <ng-content></ng-content>\n</bb-form-group>\n",
                changeDetection: core.ChangeDetectionStrategy.OnPush,
                encapsulation: core.ViewEncapsulation.None,
                preserveWhitespaces: false,
                host: { 'class': 'bb-dialog-actions' },
                styles: [".bb-dialog-actions{padding:20px;display:block;background-color:#fff;border-top:1px solid #d8d8d8;border-bottom-left-radius:4px;border-bottom-right-radius:4px}"]
            })
        ], BbDialogActions);
        return BbDialogActions;
    }());

    var BbDialogInsertion = /** @class */ (function () {
        function BbDialogInsertion(viewContainerRef) {
            this.viewContainerRef = viewContainerRef;
        }
        BbDialogInsertion.ctorParameters = function () { return [
            { type: core.ViewContainerRef }
        ]; };
        BbDialogInsertion = __decorate([
            core.Directive({
                selector: '[bbDialogInsertion]'
            })
        ], BbDialogInsertion);
        return BbDialogInsertion;
    }());

    var BbDialogContainer = /** @class */ (function () {
        function BbDialogContainer(_elementRef, _changeDetection, _componentFactoryResolver) {
            this._elementRef = _elementRef;
            this._changeDetection = _changeDetection;
            this._componentFactoryResolver = _componentFactoryResolver;
            // Data.
            this.componentRef = null;
            this.childComponentType = null;
            // State.
            this.overlayClicked$ = new rxjs.Subject();
        }
        Object.defineProperty(BbDialogContainer.prototype, "onOverlayClicked", {
            get: function () {
                return this.overlayClicked$.pipe(operators.take(1));
            },
            enumerable: true,
            configurable: true
        });
        BbDialogContainer.prototype.ngAfterViewInit = function () {
            // Load the child component.
            this.loadChildComponent(this.childComponentType);
            // Listen for mouse click on the dialog container.
            this.listenForClicks();
            // Detect changes to notify change detection.
            this._changeDetection.detectChanges();
        };
        BbDialogContainer.prototype.ngOnDestroy = function () {
            this._subscription && this._subscription.unsubscribe();
        };
        BbDialogContainer.prototype.onAnimationDone = function (event) {
            // Check if the dialog is being destroyed.
            if (event.toState !== 'void') {
                return;
            }
            // Destroy the ref if it exists.
            this.componentRef && this.componentRef.destroy();
        };
        BbDialogContainer.prototype.listenForClicks = function () {
            var _this = this;
            if (!this._elementRef || !this._elementRef.nativeElement) {
                return;
            }
            var mouseDown$ = rxjs.fromEvent(this._elementRef.nativeElement, 'mousedown');
            var touchStart$ = rxjs.fromEvent(this._elementRef.nativeElement, 'touchstart');
            var start$ = rxjs.race([mouseDown$, touchStart$]);
            var mouseUp$ = rxjs.fromEvent(this._elementRef.nativeElement, 'mouseup');
            var touchEnd$ = rxjs.fromEvent(this._elementRef.nativeElement, 'touchend');
            var end$ = rxjs.race([mouseUp$, touchEnd$]);
            this._subscription = start$.pipe(operators.switchMap(function () { return end$; })).subscribe(function () {
                _this.overlayClicked$.next();
            });
        };
        BbDialogContainer.prototype.loadChildComponent = function (componentType) {
            // Resolve the component.
            var componentFactory = this._componentFactoryResolver.resolveComponentFactory(componentType);
            // Get the view container ref and clear it.
            var viewContainerRef = this.insertion.viewContainerRef;
            viewContainerRef.clear();
            // Create an instance of the component.
            this.componentRef = viewContainerRef.createComponent(componentFactory);
        };
        BbDialogContainer.ctorParameters = function () { return [
            { type: core.ElementRef },
            { type: core.ChangeDetectorRef },
            { type: core.ComponentFactoryResolver }
        ]; };
        __decorate([
            core.ViewChild(BbDialogInsertion, { static: true })
        ], BbDialogContainer.prototype, "insertion", void 0);
        __decorate([
            core.HostListener('@bbDialogAnimation.done', ['$event'])
        ], BbDialogContainer.prototype, "onAnimationDone", null);
        BbDialogContainer = __decorate([
            core.Component({
                selector: 'bb-dialog-container',
                template: "<div class=\"bb-dialog-container-backdrop\">\n</div>\n\n<div class=\"bb-dialog-container-component\">\n    <ng-container bbDialogInsertion>\n    </ng-container>\n</div>\n",
                changeDetection: core.ChangeDetectionStrategy.OnPush,
                encapsulation: core.ViewEncapsulation.None,
                host: { 'class': 'bb-dialog-container', '[@bbDialogAnimation]': 'true' },
                preserveWhitespaces: false,
                animations: [
                    animations.trigger('bbDialogAnimation', [
                        animations.transition(':enter', [
                            animations.group([
                                animations.query('.bb-dialog-container-backdrop', [
                                    animations.style({
                                        opacity: 0
                                    }),
                                    animations.animate('150ms cubic-bezier(0, 0, 0.2, 1)', animations.style({
                                        opacity: 1
                                    }))
                                ]),
                                animations.query('.bb-dialog-container-component', [
                                    animations.style({
                                        transform: 'scale(0.95)'
                                    }),
                                    animations.animate('150ms cubic-bezier(0, 0, 0.2, 1)', animations.style({
                                        transform: 'scale(1)'
                                    }))
                                ])
                            ])
                        ]),
                        animations.transition(':leave', [
                            animations.group([
                                animations.query('.bb-dialog-container-backdrop', [
                                    animations.animate('150ms cubic-bezier(0, 0, 0.2, 1)', animations.style({
                                        opacity: 0
                                    }))
                                ]),
                                animations.query('.bb-dialog-container-component', [
                                    animations.animate('150ms cubic-bezier(0, 0, 0.2, 1)', animations.style({
                                        opacity: 0,
                                        transform: 'scale(0.95)'
                                    }))
                                ])
                            ])
                        ])
                    ])
                ],
                styles: [".bb-dialog-container,.bb-dialog-container-backdrop{top:0;left:0;right:0;bottom:0;z-index:1000;position:fixed}.bb-dialog-container{display:-webkit-box;display:-ms-flexbox;display:flex}.bb-dialog-container-backdrop{background-color:rgba(0,0,0,.5)}.bb-dialog-container-component{width:100%;margin:auto;padding:20px;z-index:1001;display:block}"]
            })
        ], BbDialogContainer);
        return BbDialogContainer;
    }());

    var nextUniqueId = 0;
    var BbDialogConfirm = /** @class */ (function () {
        function BbDialogConfirm(config, dialogRef) {
            this.config = config;
            this.dialogRef = dialogRef;
            // Id.
            this.dialogId = "bb-dialog-confirm-" + nextUniqueId++;
        }
        BbDialogConfirm.prototype.ngAfterViewInit = function () {
            // Initial focus the button.
            this.confirmButton.focus();
        };
        BbDialogConfirm.prototype.onClose = function (result) {
            this.dialogRef.close(result);
        };
        BbDialogConfirm.ctorParameters = function () { return [
            { type: BbDialogConfig },
            { type: BbDialogRef }
        ]; };
        __decorate([
            core.ViewChild('confirm', { read: elements.BbButton })
        ], BbDialogConfirm.prototype, "confirmButton", void 0);
        BbDialogConfirm = __decorate([
            core.Component({
                selector: 'bb-dialog-confirm',
                template: "<div [attr.aria-labelledby]=\"dialogId\"\n     bb-dialog-modal\n     bbFocusTrap>\n    <header bb-dialog-header>\n        <h1 *ngIf=\"config?.data?.title as title\"\n            [id]=\"dialogId\">\n            {{ title | bbLocalize:{optional: true} }}\n        </h1>\n    </header>\n\n    <p>\n        {{ config?.data?.description | bbLocalize:{optional: true} }}\n    </p>\n\n    <footer bb-dialog-actions>\n        <button *ngIf=\"config?.data?.cancelButtonText as cancelButtonText\"\n                (click)=\"onClose(false)\"\n                bb-button\n                type=\"button\">\n            {{ cancelButtonText | bbLocalize:{optional: true} }}\n        </button>\n        <button #confirm\n                *ngIf=\"config?.data?.confirmButtonText as confirmButtonText\"\n                (click)=\"onClose(true)\"\n                bb-button\n                type=\"button\"\n                class=\"destructive\">\n            {{ confirmButtonText | bbLocalize:{optional: true} }}\n        </button>\n    </footer>\n</div>\n",
                changeDetection: core.ChangeDetectionStrategy.OnPush,
                encapsulation: core.ViewEncapsulation.None,
                preserveWhitespaces: false,
                host: { 'class': 'bb-dialog-confirm' },
                styles: [".bb-dialog-confirm{display:block}"]
            })
        ], BbDialogConfirm);
        return BbDialogConfirm;
    }());

    var BbDialogInjector = /** @class */ (function () {
        function BbDialogInjector(_parentInjector, _additionalTokens) {
            this._parentInjector = _parentInjector;
            this._additionalTokens = _additionalTokens;
        }
        BbDialogInjector.prototype.get = function (token, notFoundValue) {
            // First check if the additional token
            // contains the token.
            var value = this._additionalTokens.get(token);
            // If that value exists return it.
            if (value) {
                return value;
            }
            // Else query the parent injector.
            return this._parentInjector.get(token, notFoundValue);
        };
        return BbDialogInjector;
    }());

    var Dialog = /** @class */ (function () {
        function Dialog(_injector, _applicationRef, _componentFactoryResolver) {
            this._injector = _injector;
            this._applicationRef = _applicationRef;
            this._componentFactoryResolver = _componentFactoryResolver;
        }
        Dialog.prototype.open = function (componentType, config) {
            return this.createDialog(componentType, config);
        };
        Dialog.prototype.confirm = function (title, description, options) {
            if (options === void 0) { options = {}; }
            return this.open(BbDialogConfirm, {
                data: {
                    title: title,
                    description: description,
                    cancelButtonText: options.cancelButtonText || 'dialog.default_cancel_button',
                    confirmButtonText: options.confirmButtonText || 'dialog.default_confirm_button'
                }
            });
        };
        Dialog.prototype.createDialog = function (componentType, config) {
            var _this = this;
            // Create a reference.
            var dialogRef = new BbDialogRef();
            // Create a map with the config.
            var map = new WeakMap();
            map.set(BbDialogConfig, config);
            map.set(BbDialogRef, dialogRef);
            // Create a custom injector.
            var dialogInjector = new BbDialogInjector(this._injector, map);
            // Resolve the dialog component reference.
            var dialogComponentRef = this._componentFactoryResolver
                .resolveComponentFactory(BbDialogContainer)
                .create(dialogInjector);
            // Attach the host view to the application.
            this._applicationRef.attachView(dialogComponentRef.hostView);
            try {
                // Remove the current focus.
                var activeElement = document.activeElement;
                activeElement.blur();
                // Append the element to the DOM.
                document.body.appendChild(dialogComponentRef.location.nativeElement);
            }
            catch (_a) {
                // Don't do anything, because it must've failed.
            }
            // Set the child component type on the component.
            dialogComponentRef.instance.childComponentType = componentType;
            dialogComponentRef.instance.onOverlayClicked.subscribe(function () { return dialogRef.onOverlayClicked(); });
            // Listen for close events.
            dialogRef.afterClosed.subscribe(function () { return _this.deleteDialog(dialogComponentRef); });
            // Return the reference.
            return dialogRef;
        };
        Dialog.prototype.deleteDialog = function (dialogComponentRef) {
            // Only continue if the dialog component ref exists.
            if (!dialogComponentRef) {
                return;
            }
            // Detach the dialog.
            this._applicationRef.detachView(dialogComponentRef.hostView);
            // Destroy the dialog.
            dialogComponentRef.destroy();
            dialogComponentRef = null;
        };
        Dialog.ctorParameters = function () { return [
            { type: core.Injector },
            { type: core.ApplicationRef },
            { type: core.ComponentFactoryResolver }
        ]; };
        Dialog = __decorate([
            core.Injectable()
        ], Dialog);
        return Dialog;
    }());

    var DialogModule = /** @class */ (function () {
        function DialogModule() {
        }
        DialogModule_1 = DialogModule;
        DialogModule.forRoot = function () {
            return {
                ngModule: DialogModule_1,
                providers: [Dialog]
            };
        };
        var DialogModule_1;
        DialogModule = DialogModule_1 = __decorate([
            core.NgModule({
                imports: [
                    common.CommonModule,
                    localize.LocalizeModule,
                    elements.ElementsModule
                ],
                declarations: [
                    BbDialogContainer,
                    BbDialogOverlay,
                    BbDialogModal,
                    BbDialogHeader,
                    BbDialogLink,
                    BbDialogActions,
                    BbDialogConfirm,
                    BbDialogInsertion
                ],
                entryComponents: [
                    BbDialogContainer,
                    BbDialogConfirm
                ],
                exports: [
                    BbDialogOverlay,
                    BbDialogModal,
                    BbDialogHeader,
                    BbDialogLink,
                    BbDialogActions
                ]
            })
        ], DialogModule);
        return DialogModule;
    }());

    exports.BbDialogActions = BbDialogActions;
    exports.BbDialogConfig = BbDialogConfig;
    exports.BbDialogHeader = BbDialogHeader;
    exports.BbDialogLink = BbDialogLink;
    exports.BbDialogModal = BbDialogModal;
    exports.BbDialogOverlay = BbDialogOverlay;
    exports.BbDialogRef = BbDialogRef;
    exports.Dialog = Dialog;
    exports.DialogModule = DialogModule;
    exports.ɵa = BbDialogContainer;
    exports.ɵb = BbDialogInsertion;
    exports.ɵc = BbDialogConfirm;

    Object.defineProperty(exports, '__esModule', { value: true });

})));
//# sourceMappingURL=bravobit-bb-foundation-dialog.umd.js.map
