(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@alyle/ui'), require('rxjs')) :
    typeof define === 'function' && define.amd ? define('@alyle/ui/snack-bar', ['exports', '@angular/core', '@alyle/ui', 'rxjs'], factory) :
    (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.ly = global.ly || {}, global.ly['snack-Bar'] = {}), global.ng.core, global.ly.core, global.rxjs));
}(this, (function (exports, i0, ui, rxjs) { 'use strict';

    function _interopNamespace(e) {
        if (e && e.__esModule) return e;
        var n = Object.create(null);
        if (e) {
            Object.keys(e).forEach(function (k) {
                if (k !== 'default') {
                    var d = Object.getOwnPropertyDescriptor(e, k);
                    Object.defineProperty(n, k, d.get ? d : {
                        enumerable: true,
                        get: function () {
                            return e[k];
                        }
                    });
                }
            });
        }
        n['default'] = e;
        return Object.freeze(n);
    }

    var i0__namespace = /*#__PURE__*/_interopNamespace(i0);

    var LySnackBarService = /** @class */ (function () {
        function LySnackBarService() {
        }
        return LySnackBarService;
    }());
    LySnackBarService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function LySnackBarService_Factory() { return new LySnackBarService(); }, token: LySnackBarService, providedIn: "root" });
    LySnackBarService.decorators = [
        { type: i0.Injectable, args: [{
                    providedIn: 'root'
                },] }
    ];

    var DEFAULT_DURATION = 6e3;
    var LySnackBarRef = /** @class */ (function () {
        function LySnackBarRef(_snackBarService, _overlay, _afterDismissedEventEmitter, duration, _theme) {
            var _this = this;
            this._snackBarService = _snackBarService;
            this._overlay = _overlay;
            this._afterDismissedEventEmitter = _afterDismissedEventEmitter;
            this._theme = _theme;
            this._dismissedByAction = false;
            /** Subject for notifying the user that the snack bar has been dismissed. */
            this._afterDismissed = new rxjs.Subject();
            if (duration !== 'Infinity') {
                this._timer = setTimeout(function () {
                    _this.dismiss();
                }, duration || DEFAULT_DURATION);
            }
        }
        /** Gets an observable that is notified when the snack bar is finished closing. */
        LySnackBarRef.prototype.afterDismissed = function () {
            return this._afterDismissed.asObservable();
        };
        LySnackBarRef.prototype.dismiss = function () {
            var snackBar = this._overlay;
            var timer = this._timer;
            this._afterDismissedEventEmitter.emit({ dismissedByAction: this._dismissedByAction });
            this._afterDismissed.next();
            this._afterDismissed.complete();
            if (snackBar) {
                if (timer) {
                    // clear previous timer
                    clearTimeout(timer);
                }
                snackBar.containerElement.classList.remove(this._theme.selectorOf('SnackBar:open'));
                setTimeout(function () {
                    snackBar.destroy();
                }, 350);
                this._snackBarService._currentSnackBar = null;
                this._overlay = null;
            }
        };
        LySnackBarRef.prototype.dismissWithAction = function () {
            var snackBar = this._overlay;
            if (snackBar) {
                this._dismissedByAction = true;
                this.dismiss();
            }
        };
        return LySnackBarRef;
    }());

    var STYLE_PRIORITY = -2;
    var DEFAULT_HORIZONTAL_POSITION = ui.XPosition.after;
    var DEFAULT_VERTICAL_POSITION = ui.YPosition.below;
    var STYLES = function (theme) { return ({
        $priority: STYLE_PRIORITY,
        root: function (className) { return className + "{border-radius:4px;display:flex;justify-content:space-between;align-items:center;margin:8px;padding:0 16px;min-height:48px;min-width:320px;max-width:320px;opacity:0;transition:opacity " + theme.animations.curves.standard + " 350ms, transform " + theme.animations.curves.deceleration + " 350ms;font-size:" + theme.pxToRem(theme.typography.fontSize) + ";box-sizing:border-box;}" + ui.st2c(((theme.snackBar
            && theme.snackBar.root) || null), "" + className) + "@media " + theme.breakpoints['XSmall'] + "{" + className + "{width:calc(100% - 16px);min-width:calc(100% - 16px);}}"; }
    }); };
    var LySnackBar = /** @class */ (function () {
        function LySnackBar(_templateRef, _theme, _overlay, _snackBarService) {
            this._templateRef = _templateRef;
            this._theme = _theme;
            this._overlay = _overlay;
            this._snackBarService = _snackBarService;
            this.classes = this._theme.renderStyleSheet(STYLES);
            this.afterDismissed = new i0.EventEmitter();
        }
        LySnackBar.prototype.ngOnDestroy = function () {
            this.dismiss();
        };
        /**
         * Open a LySnackBar template
         * @param snackBarData Data to be passed to the snack-bark.
         */
        LySnackBar.prototype.open = function (snackBarData) {
            var _this = this;
            // close previous snackBar if exist
            var sbrPrev = this._snackBarService._currentSnackBar;
            if (sbrPrev) {
                sbrPrev.dismiss();
            }
            var duration = this.duration;
            var horizontalPosition = this.horizontalPosition || DEFAULT_HORIZONTAL_POSITION;
            var verticalPosition = this.verticalPosition || DEFAULT_VERTICAL_POSITION;
            var snackBar = this._overlay.create(this._templateRef, snackBarData, {
                styles: {
                    // this remove previous style
                    justifyContent: null
                },
                hasBackdrop: false,
                classes: [
                    this.classes.root,
                    this._theme.renderStyle("SnackBar.hp:" + horizontalPosition + ".vp:" + verticalPosition, function (theme) {
                        var marginLeft;
                        var left;
                        var marginRight;
                        var right;
                        var transform;
                        var top;
                        var bottom;
                        var hp;
                        if (verticalPosition === ui.YPosition.above) {
                            transform = 'translateY(-180%)';
                            top = 0;
                        }
                        if (verticalPosition === ui.YPosition.below) {
                            transform = 'translateY(180%)';
                            bottom = 0;
                        }
                        if (horizontalPosition === 'center') {
                            marginRight = marginLeft = 'auto';
                            left = right = 0;
                        }
                        else {
                            hp = theme.getDirection(horizontalPosition);
                        }
                        return function (className) { return className + "{margin-left:" + marginLeft + ";left:" + left + ";margin-right:" + marginRight + ";right:" + right + ";transform:" + transform + ";top:" + top + ";bottom:" + bottom + ";" + hp + ":0;}"; };
                    }, STYLE_PRIORITY)
                ]
            });
            this._theme.requestAnimationFrame(function () {
                var newClass = _this._theme.renderStyle('SnackBar:open', function () { return (function (className) { return className + "{opacity:1;transform:translateY(0);}"; }); }, STYLE_PRIORITY);
                snackBar.containerElement.classList.add(newClass);
            });
            window.getComputedStyle(snackBar.containerElement).getPropertyValue('opacity');
            var sbr = new LySnackBarRef(this._snackBarService, snackBar, this.afterDismissed, duration, this._theme);
            this._snackBarService._currentSnackBar = sbr;
            return sbr;
        };
        /** Dismiss snackBar */
        LySnackBar.prototype.dismiss = function () {
            var sbr = this._snackBarService._currentSnackBar;
            if (sbr) {
                sbr.dismissWithAction();
            }
        };
        return LySnackBar;
    }());
    LySnackBar.decorators = [
        { type: i0.Directive, args: [{
                    selector: 'ng-template[ly-snack-bar]',
                    exportAs: 'lySnackBar'
                },] }
    ];
    LySnackBar.ctorParameters = function () { return [
        { type: i0.TemplateRef },
        { type: ui.LyTheme2 },
        { type: ui.LyOverlay },
        { type: LySnackBarService }
    ]; };
    LySnackBar.propDecorators = {
        duration: [{ type: i0.Input }],
        horizontalPosition: [{ type: i0.Input }],
        verticalPosition: [{ type: i0.Input }],
        afterDismissed: [{ type: i0.Output }]
    };

    var LySnackBarModule = /** @class */ (function () {
        function LySnackBarModule() {
        }
        return LySnackBarModule;
    }());
    LySnackBarModule.decorators = [
        { type: i0.NgModule, args: [{
                    imports: [ui.LyOverlayModule],
                    declarations: [LySnackBar],
                    exports: [LySnackBar]
                },] }
    ];

    /**
     * Generated bundle index. Do not edit.
     */

    exports.LySnackBar = LySnackBar;
    exports.LySnackBarModule = LySnackBarModule;
    exports.STYLES = STYLES;
    exports.ɵa = LySnackBarService;

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

})));
//# sourceMappingURL=alyle-ui-snack-bar.umd.js.map
