import * as i0 from '@angular/core';
import { EventEmitter, Output, Input, Component, NgModule } from '@angular/core';
import '@aztrix/models';
import { BehaviorSubject, timer } from 'rxjs';
import * as i1 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i2 from '@aztrix/icons';
import { IconsModule } from '@aztrix/icons';
import * as i3 from '@aztrix/components/button';
import { ButtonModule } from '@aztrix/components/button';

class SnackbarComponent {
    constructor() {
        this.dismissible = true;
        this.open = true;
        this.didClose = new EventEmitter();
        this.openSubject$ = new BehaviorSubject(true);
    }
    ngOnChanges() {
        this.openSubject$.next(this.open);
        if (this.timeout > 0) {
            this._timer = timer(this.timeout);
            this._timer.subscribe(() => this.close());
        }
    }
    close() {
        this.openSubject$.next(false);
        if (this.type) {
            const snackBarItem = this.snackbarVisbility(`snackbar-${this.type}`, false);
            if (!snackBarItem) {
                localStorage.setItem(`snackbar-${this.type}`, 'false');
            }
        }
        this.didClose.emit();
    }
    get isSnackbarAlreadyClosed() {
        return !!localStorage.getItem(`${'snackbar-'}${this.type}`)?.length;
    }
    get backgroundColorClass() {
        switch (this.color) {
            case 'green':
                return 'm-snackbar--green';
            case 'red':
                return 'm-snackbar--red';
            case 'grey':
                return 'm-snackbar--grey';
            case 'orange':
                return 'm-snackbar--orange';
            default:
                return undefined;
        }
    }
    snackbarVisbility(type, value) {
        if (value != null) {
            localStorage.setItem(type, JSON.stringify(value));
        }
        const currentValue = localStorage.getItem(type);
        return currentValue == null ? true : JSON.parse(currentValue);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: SnackbarComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.12", type: SnackbarComponent, selector: "ax-snackbar", inputs: { type: "type", timeout: "timeout", dismissible: "dismissible", open: "open", icon: "icon", color: "color" }, outputs: { didClose: "didClose" }, usesOnChanges: true, ngImport: i0, template: "<div\n  class=\"m-snackbar__wrapper\"\n  *ngIf=\"!isSnackbarAlreadyClosed\"\n  [class.is-active]=\"openSubject$ | async\"\n>\n  <div [ngClass]=\"backgroundColorClass\" class=\"m-snackbar\">\n    <div class=\"container m-snackbar__content\">\n      <ax-icon\n        class=\"icon\"\n        [ngClass]=\"{'m-info-icon': icon === 'information-variant'}\"\n        *ngIf=\"icon\"\n        [name]=\"icon\"\n      ></ax-icon>\n      <ng-content></ng-content>\n\n      <button axButton *ngIf=\"dismissible\" class=\"m-snackbar__close\" icon-button>\n        <ax-icon class=\"icon\" (click)=\"close()\" name=\"close\"></ax-icon>\n      </button>\n    </div>\n  </div>\n</div>\n", styles: [":host{display:block}.m-snackbar ::ng-deep .m-snackbar__content p{margin:0}.m-snackbar__wrapper{width:100%;overflow:hidden;max-height:0;opacity:.5;transition:max-height 1s cubic-bezier(0,1,0,1),opacity .4s ease;will-change:max-height,opacity}.m-snackbar__wrapper.is-active{opacity:1;max-height:500px;transition:max-height 1s ease-in-out,opacity .4s ease-out}\n"], dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i2.IconComponent, selector: "ax-icon", inputs: ["name", "inline"] }, { kind: "directive", type: i3.ButtonDirective, selector: "[axButton]", inputs: ["color", "labelHideMobile", "smallButton", "bigButton", "fullWidth", "filled", "outline", "icon-button", "hoverLabel", "hover", "lowercase", "disabled"] }, { kind: "pipe", type: i1.AsyncPipe, name: "async" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: SnackbarComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-snackbar', template: "<div\n  class=\"m-snackbar__wrapper\"\n  *ngIf=\"!isSnackbarAlreadyClosed\"\n  [class.is-active]=\"openSubject$ | async\"\n>\n  <div [ngClass]=\"backgroundColorClass\" class=\"m-snackbar\">\n    <div class=\"container m-snackbar__content\">\n      <ax-icon\n        class=\"icon\"\n        [ngClass]=\"{'m-info-icon': icon === 'information-variant'}\"\n        *ngIf=\"icon\"\n        [name]=\"icon\"\n      ></ax-icon>\n      <ng-content></ng-content>\n\n      <button axButton *ngIf=\"dismissible\" class=\"m-snackbar__close\" icon-button>\n        <ax-icon class=\"icon\" (click)=\"close()\" name=\"close\"></ax-icon>\n      </button>\n    </div>\n  </div>\n</div>\n", styles: [":host{display:block}.m-snackbar ::ng-deep .m-snackbar__content p{margin:0}.m-snackbar__wrapper{width:100%;overflow:hidden;max-height:0;opacity:.5;transition:max-height 1s cubic-bezier(0,1,0,1),opacity .4s ease;will-change:max-height,opacity}.m-snackbar__wrapper.is-active{opacity:1;max-height:500px;transition:max-height 1s ease-in-out,opacity .4s ease-out}\n"] }]
        }], propDecorators: { type: [{
                type: Input
            }], timeout: [{
                type: Input
            }], dismissible: [{
                type: Input
            }], open: [{
                type: Input
            }], icon: [{
                type: Input
            }], color: [{
                type: Input
            }], didClose: [{
                type: Output
            }] } });

class SnackbarModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: SnackbarModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.12", ngImport: i0, type: SnackbarModule, declarations: [SnackbarComponent], imports: [CommonModule, IconsModule, ButtonModule], exports: [SnackbarComponent] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: SnackbarModule, imports: [CommonModule, IconsModule, ButtonModule] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: SnackbarModule, decorators: [{
            type: NgModule,
            args: [{
                    declarations: [SnackbarComponent],
                    imports: [CommonModule, IconsModule, ButtonModule],
                    exports: [SnackbarComponent],
                }]
        }] });

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

export { SnackbarComponent, SnackbarModule };
//# sourceMappingURL=aztrix-components-snackbar.mjs.map
