import * as i0 from '@angular/core';
import { Pipe, EventEmitter, Component, Input, Output, NgModule, HostBinding, Injectable } from '@angular/core';
import * as i1 from '@angular/router';
import { NavigationStart, NavigationEnd, NavigationCancel, NavigationError } from '@angular/router';
import * as i2 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i3 from '@ionic/angular';
import { IonicModule } from '@ionic/angular';
import * as i3$1 from '@softpak/frontend-components-ng/dist/frontend-components-ng';
import { SpfModule } from '@softpak/frontend-components-ng/dist/frontend-components-ng';
import * as i6 from '@ngx-translate/core';
import { TranslateModule } from '@ngx-translate/core';
import * as i1$1 from '@ngrx/store';
import { createAction, props, union, createReducer, on, createSelector, select } from '@ngrx/store';

class SpfCapitalizePipe {
    transform(value, ..._args) {
        return value = value ? value.charAt(0).toUpperCase() + value.substr(1).toLowerCase() : '';
    }
}
SpfCapitalizePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpfCapitalizePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
SpfCapitalizePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "14.3.0", ngImport: i0, type: SpfCapitalizePipe, name: "capitalize" });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpfCapitalizePipe, decorators: [{
            type: Pipe,
            args: [{
                    name: 'capitalize'
                }]
        }] });

class SpaWelcomeComponent {
    constructor(router) {
        this.router = router;
        this.channels = [];
        this.channelSelected = new EventEmitter();
    }
    ngOnChanges() {
        this.productionChannels = this.channels.filter(connection => connection.isProduction);
        this.autoSelect();
    }
    onSelectChannel(channel) {
        this.channelSelected.emit(channel);
        this.router.navigate(['/']);
    }
    // Automatically select channel, if there is only one.
    autoSelect() {
        if (this.productionChannels.length === 1) {
            this.onSelectChannel(this.productionChannels.find((_, index) => index === 0));
        }
    }
}
SpaWelcomeComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpaWelcomeComponent, deps: [{ token: i1.Router }], target: i0.ɵɵFactoryTarget.Component });
SpaWelcomeComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.3.0", type: SpaWelcomeComponent, selector: "spa-welcome", inputs: { channels: "channels", txtTitle: "txtTitle" }, outputs: { channelSelected: "channelSelected" }, usesOnChanges: true, ngImport: i0, template: "<ion-header>\n  <ion-toolbar>\n      <ion-title>\n        {{ txtTitle | translate | capitalize }}\n      </ion-title>\n      <ion-buttons slot=\"end\">\n      </ion-buttons>\n  </ion-toolbar>\n</ion-header>\n<ion-content class=\"ion-padding\">\n  <spn-button class=\"block mb-2\" [spfFullWidth]=\"true\" *ngFor=\"let channel of productionChannels\" (click)=\"onSelectChannel(channel)\">\n      {{ channel.brand }}\n  </spn-button>\n</ion-content>\n", styles: [":host{display:block;height:100%}\n"], dependencies: [{ kind: "directive", type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "component", type: i3.IonButtons, selector: "ion-buttons", inputs: ["collapse"] }, { kind: "component", type: i3.IonContent, selector: "ion-content", inputs: ["color", "forceOverscroll", "fullscreen", "scrollEvents", "scrollX", "scrollY"] }, { kind: "component", type: i3.IonHeader, selector: "ion-header", inputs: ["collapse", "mode", "translucent"] }, { kind: "component", type: i3.IonTitle, selector: "ion-title", inputs: ["color", "size"] }, { kind: "component", type: i3.IonToolbar, selector: "ion-toolbar", inputs: ["color", "mode"] }, { kind: "component", type: i3$1.SpnButton, selector: "spn-button", inputs: ["spfClass", "spfClassObject", "spfDisabled", "spfForm", "spfFullHeight", "spfFullWidth", "spfSeverity", "spfSize", "spfTabIndex", "spfType"] }, { kind: "pipe", type: SpfCapitalizePipe, name: "capitalize" }, { kind: "pipe", type: i6.TranslatePipe, name: "translate" }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpaWelcomeComponent, decorators: [{
            type: Component,
            args: [{ selector: 'spa-welcome', template: "<ion-header>\n  <ion-toolbar>\n      <ion-title>\n        {{ txtTitle | translate | capitalize }}\n      </ion-title>\n      <ion-buttons slot=\"end\">\n      </ion-buttons>\n  </ion-toolbar>\n</ion-header>\n<ion-content class=\"ion-padding\">\n  <spn-button class=\"block mb-2\" [spfFullWidth]=\"true\" *ngFor=\"let channel of productionChannels\" (click)=\"onSelectChannel(channel)\">\n      {{ channel.brand }}\n  </spn-button>\n</ion-content>\n", styles: [":host{display:block;height:100%}\n"] }]
        }], ctorParameters: function () { return [{ type: i1.Router }]; }, propDecorators: { channels: [{
                type: Input
            }], txtTitle: [{
                type: Input
            }], channelSelected: [{
                type: Output
            }] } });

class SpfCapitalizeModule {
}
SpfCapitalizeModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpfCapitalizeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
SpfCapitalizeModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.3.0", ngImport: i0, type: SpfCapitalizeModule, declarations: [SpfCapitalizePipe], imports: [CommonModule], exports: [SpfCapitalizePipe] });
SpfCapitalizeModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpfCapitalizeModule, imports: [CommonModule] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpfCapitalizeModule, decorators: [{
            type: NgModule,
            args: [{
                    declarations: [
                        SpfCapitalizePipe
                    ],
                    imports: [
                        CommonModule,
                    ],
                    exports: [
                        SpfCapitalizePipe
                    ]
                }]
        }] });

class SpaWelcomeModule {
}
SpaWelcomeModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpaWelcomeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
SpaWelcomeModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.3.0", ngImport: i0, type: SpaWelcomeModule, declarations: [SpaWelcomeComponent], imports: [CommonModule,
        IonicModule,
        SpfCapitalizeModule,
        SpfModule,
        TranslateModule], exports: [SpaWelcomeComponent] });
SpaWelcomeModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpaWelcomeModule, imports: [CommonModule,
        IonicModule,
        SpfCapitalizeModule,
        SpfModule,
        TranslateModule] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpaWelcomeModule, decorators: [{
            type: NgModule,
            args: [{
                    declarations: [
                        SpaWelcomeComponent,
                    ],
                    imports: [
                        CommonModule,
                        IonicModule,
                        SpfCapitalizeModule,
                        SpfModule,
                        TranslateModule,
                    ],
                    exports: [
                        SpaWelcomeComponent,
                    ]
                }]
        }] });

/* eslint-disable max-len */
const INITIALIZE = createAction('[Shared / Navigation] Initialize', props());
const UPDATE = createAction('[Shared / Navigation] Update', props());
const all$2 = union({
    UPDATE
});

const thisReducer$2 = (state) => state.spfNavigation;
const initialState$2 = {
    navigationItems: [],
    menuItems: [],
    tabs: [],
};
const handleReducer$2 = createReducer(initialState$2, on(INITIALIZE, (state, { navigationItems }) => ({
    ...state,
    navigationItems: navigationItems,
    menuItems: navigationItems.filter(navigationItem => !navigationItem.signInRequired && (navigationItem.hasTile === undefined || navigationItem.hasTile)),
    tabs: navigationItems.filter(navigationItem => !navigationItem.signInRequired && navigationItem.hasTab),
})), on(UPDATE, (state, { accessList, signedIn }) => ({
    ...state,
    menuItems: state.navigationItems.filter(navigationItem => (!navigationItem.signInRequired || signedIn) && navigationItem?.hasTile !== false).filter(item => item.accessKey === undefined || accessList.includes(item.accessKey)),
    tabs: state.navigationItems.filter(navigationItem => (!navigationItem.signInRequired || signedIn) && navigationItem.hasTab).filter(item => item.accessKey === undefined || accessList.includes(item.accessKey)),
})));
function reducer$2(state, action) { return handleReducer$2(state, action); }
;
const selectState = createSelector(thisReducer$2, (state) => state);

class SpfMenuComponent {
    constructor(spfNavigation) {
        this.spfNavigation = spfNavigation;
        this.spfClick = new EventEmitter();
        this.navItems = [];
        this.subscription = {};
    }
    ngOnInit() {
        this.listenToMenuState();
    }
    ngOnDestroy() {
        this.subscription.menuState?.unsubscribe();
    }
    onNavigate(link) {
        this.spfClick.emit(link);
    }
    listenToMenuState() {
        this.subscription.menuState = this.spfNavigation.pipe(select(selectState)).subscribe(state => {
            this.navItems = state.menuItems.filter(navigationItem => !this.spfFilter || this.spfFilter(navigationItem));
        });
    }
}
SpfMenuComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpfMenuComponent, deps: [{ token: i1$1.Store }], target: i0.ɵɵFactoryTarget.Component });
SpfMenuComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.3.0", type: SpfMenuComponent, selector: "spf-menu", inputs: { spfFilter: "spfFilter" }, outputs: { spfClick: "spfClick" }, ngImport: i0, template: "<spn-home-tiles>\n  <spn-home-tile\n    *ngFor=\"let item of navItems\"\n    (click)=\"onNavigate(item.routerLink)\"\n    [attr.spn-home-tile--code]=\"item.code\"\n    [spfTitle]=\"item.title | translate | capitalize\">\n    <i class=\"fal\" [ngClass]=\"item.icon\"></i>\n  </spn-home-tile>\n</spn-home-tiles>\n", dependencies: [{ kind: "directive", type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "component", type: i3$1.SpnHomeTile, selector: "spn-home-tile", inputs: ["spfClass", "spfClassObject", "spfTitle"] }, { kind: "component", type: i3$1.SpnHomeTiles, selector: "spn-home-tiles" }, { kind: "pipe", type: SpfCapitalizePipe, name: "capitalize" }, { kind: "pipe", type: i6.TranslatePipe, name: "translate" }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpfMenuComponent, decorators: [{
            type: Component,
            args: [{ selector: 'spf-menu', template: "<spn-home-tiles>\n  <spn-home-tile\n    *ngFor=\"let item of navItems\"\n    (click)=\"onNavigate(item.routerLink)\"\n    [attr.spn-home-tile--code]=\"item.code\"\n    [spfTitle]=\"item.title | translate | capitalize\">\n    <i class=\"fal\" [ngClass]=\"item.icon\"></i>\n  </spn-home-tile>\n</spn-home-tiles>\n" }]
        }], ctorParameters: function () { return [{ type: i1$1.Store }]; }, propDecorators: { spfFilter: [{
                type: Input
            }], spfClick: [{
                type: Output
            }] } });

class SpfMenuModule {
}
SpfMenuModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpfMenuModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
SpfMenuModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.3.0", ngImport: i0, type: SpfMenuModule, declarations: [SpfMenuComponent], imports: [CommonModule,
        SpfModule,
        SpfCapitalizeModule,
        TranslateModule], exports: [SpfMenuComponent] });
SpfMenuModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpfMenuModule, imports: [CommonModule,
        SpfModule,
        SpfCapitalizeModule,
        TranslateModule] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpfMenuModule, decorators: [{
            type: NgModule,
            args: [{
                    declarations: [
                        SpfMenuComponent
                    ],
                    imports: [
                        CommonModule,
                        SpfModule,
                        SpfCapitalizeModule,
                        TranslateModule,
                    ],
                    exports: [
                        SpfMenuComponent
                    ]
                }]
        }] });

/* eslint-disable max-len */
const HIDE = createAction('[Spinner] Hide', props());
const SHOW = createAction('[Spinner] Show', props());
const all$1 = union({
    HIDE,
    SHOW
});

const thisReducer$1 = (state) => state.spinner;
const initialState$1 = {
    show: false,
};
const handleReducer$1 = createReducer(initialState$1, on(HIDE, (state) => {
    return {
        ...state,
        show: false
    };
}), on(SHOW, (state) => {
    return {
        ...state,
        show: true
    };
}));
function reducer$1(state, action) {
    return handleReducer$1(state, action);
}
const selectShow = createSelector(thisReducer$1, (state) => state.show);

class SpfSpinnerDisplayerComponent {
    constructor(reducer) {
        this.reducer = reducer;
        this.hostClass = true;
        this.show = false;
    }
    ngOnInit() {
        this.reducer.pipe(select(selectShow)).subscribe(show => {
            this.show = show;
        });
    }
}
SpfSpinnerDisplayerComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpfSpinnerDisplayerComponent, deps: [{ token: i1$1.Store }], target: i0.ɵɵFactoryTarget.Component });
SpfSpinnerDisplayerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.3.0", type: SpfSpinnerDisplayerComponent, selector: "spf-spinner-displayer", host: { properties: { "class.spf-spinner-displayer": "this.hostClass" } }, ngImport: i0, template: `<ng-container *ngIf="show"><ng-content></ng-content></ng-container>`, isInline: true, dependencies: [{ kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpfSpinnerDisplayerComponent, decorators: [{
            type: Component,
            args: [{ selector: 'spf-spinner-displayer', template: `<ng-container *ngIf="show"><ng-content></ng-content></ng-container>` }]
        }], ctorParameters: function () { return [{ type: i1$1.Store }]; }, propDecorators: { hostClass: [{
                type: HostBinding,
                args: ['class.spf-spinner-displayer']
            }] } });

class SpfSpinnerOnNavService {
    constructor(router, state) {
        this.router = router;
        this.state = state;
        this.eventsSubscription = router.events.subscribe((event) => {
            this.navigationInterceptor(event);
        });
    }
    navigationInterceptor(event) {
        if (event instanceof NavigationStart) {
            this.state.dispatch(SHOW({}));
        }
        if (event instanceof NavigationEnd || event instanceof NavigationCancel || event instanceof NavigationError) {
            this.state.dispatch(HIDE({}));
        }
    }
}
SpfSpinnerOnNavService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpfSpinnerOnNavService, deps: [{ token: i1.Router }, { token: i1$1.Store }], target: i0.ɵɵFactoryTarget.Injectable });
SpfSpinnerOnNavService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpfSpinnerOnNavService });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpfSpinnerOnNavService, decorators: [{
            type: Injectable
        }], ctorParameters: function () { return [{ type: i1.Router }, { type: i1$1.Store }]; } });

class SpfSpinnerModule {
    static forRoot() {
        return {
            ngModule: SpfSpinnerModule,
            providers: [
                { provide: SpfSpinnerOnNavService }
            ]
        };
    }
}
SpfSpinnerModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpfSpinnerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
SpfSpinnerModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.3.0", ngImport: i0, type: SpfSpinnerModule, declarations: [SpfSpinnerDisplayerComponent], imports: [CommonModule], exports: [SpfSpinnerDisplayerComponent] });
SpfSpinnerModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpfSpinnerModule, imports: [CommonModule] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpfSpinnerModule, decorators: [{
            type: NgModule,
            args: [{
                    declarations: [
                        SpfSpinnerDisplayerComponent
                    ],
                    imports: [
                        CommonModule
                    ],
                    exports: [
                        SpfSpinnerDisplayerComponent
                    ],
                }]
        }] });

var index$1 = /*#__PURE__*/Object.freeze({
    __proto__: null,
    HIDE: HIDE,
    SHOW: SHOW,
    initialState: initialState$1,
    reducer: reducer$1,
    selectShow: selectShow,
    SpfSpinnerDisplayerComponent: SpfSpinnerDisplayerComponent,
    SpfSpinnerModule: SpfSpinnerModule,
    SpfSpinnerOnNavService: SpfSpinnerOnNavService
});

var SpfToasterSeverityEnum;
(function (SpfToasterSeverityEnum) {
    SpfToasterSeverityEnum["ERROR"] = "error";
    SpfToasterSeverityEnum["INFO"] = "info";
    SpfToasterSeverityEnum["SUCCESS"] = "success";
    SpfToasterSeverityEnum["WARNING"] = "warning";
})(SpfToasterSeverityEnum || (SpfToasterSeverityEnum = {}));
var SpfToasterAutoCloseSpeedEnum;
(function (SpfToasterAutoCloseSpeedEnum) {
    SpfToasterAutoCloseSpeedEnum[SpfToasterAutoCloseSpeedEnum["DEFAULT"] = -1] = "DEFAULT";
    SpfToasterAutoCloseSpeedEnum[SpfToasterAutoCloseSpeedEnum["SLOW"] = -2] = "SLOW";
})(SpfToasterAutoCloseSpeedEnum || (SpfToasterAutoCloseSpeedEnum = {}));
function toasterAutocloseSpeed(autoCloseSpeed, messageText) {
    switch (autoCloseSpeed) {
        case SpfToasterAutoCloseSpeedEnum.DEFAULT:
            return Math.min(Math.max(messageText.length * 50, 2000), 7000);
        case SpfToasterAutoCloseSpeedEnum.SLOW:
            return Math.min(Math.max(messageText.length * 60, 3000), 10000);
        default:
            return autoCloseSpeed;
    }
}

class ToastsDisplayerComponent {
    constructor(toasterStore) {
        this.toasterStore = toasterStore;
        this.hostClass = true;
    }
    ngOnInit() {
        this.toasterStore.select(selectMessages).subscribe(messages => {
            this.messages = messages;
        });
    }
    doCloseMessage(id) {
        this.toasterStore.dispatch(CLEAR_MESSAGE({ id }));
    }
}
ToastsDisplayerComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: ToastsDisplayerComponent, deps: [{ token: i1$1.Store }], target: i0.ɵɵFactoryTarget.Component });
ToastsDisplayerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.3.0", type: ToastsDisplayerComponent, selector: "spf-toasts-displayer", inputs: { messages: "messages" }, host: { properties: { "class.spf-toasts-displayer": "this.hostClass" } }, ngImport: i0, template: `<spn-alert
        *ngFor="let message of messages"
        [spfAutoclose]="message.autoClose"
        [spfCloseable]="message.closeable"
        [spfSeverity]="message.severity"
        [spfTitle]="message.title"
        (spfClose)="doCloseMessage(message.id)">{{message.message}}</spn-alert>`, isInline: true, styles: [":host(.spf-toasts-displayer){display:block;position:fixed;bottom:85px;left:0;right:0;margin:0 auto;width:80%;z-index:500}spf-alert{box-shadow:0 7px 10px #00000040,0 10px 10px #00000038}spf-alert+spf-alert{margin-top:6px}\n"], dependencies: [{ kind: "directive", type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "component", type: i3$1.SpnAlert, selector: "spn-alert", inputs: ["spfAutoclose", "spfCloseable", "spfHideTitle", "spfMarginTop", "spfSeverity", "spfTitle"] }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: ToastsDisplayerComponent, decorators: [{
            type: Component,
            args: [{ selector: 'spf-toasts-displayer', template: `<spn-alert
        *ngFor="let message of messages"
        [spfAutoclose]="message.autoClose"
        [spfCloseable]="message.closeable"
        [spfSeverity]="message.severity"
        [spfTitle]="message.title"
        (spfClose)="doCloseMessage(message.id)">{{message.message}}</spn-alert>`, styles: [":host(.spf-toasts-displayer){display:block;position:fixed;bottom:85px;left:0;right:0;margin:0 auto;width:80%;z-index:500}spf-alert{box-shadow:0 7px 10px #00000040,0 10px 10px #00000038}spf-alert+spf-alert{margin-top:6px}\n"] }]
        }], ctorParameters: function () { return [{ type: i1$1.Store }]; }, propDecorators: { hostClass: [{
                type: HostBinding,
                args: ['class.spf-toasts-displayer']
            }], messages: [{
                type: Input
            }] } });

class ToasterMessageInterface {
}

// tslint:disable: max-line-length
const CLEAR_ALL = createAction('[Toaster] Clear All', props());
const CLEAR_ALL_ERRORS = createAction('[Toaster] Clear Errors', props());
const CLEAR_ALL_ERRORS_AND_WARNINGS = createAction('[Toaster] Clear Errors and Warnings', props());
const CLEAR_MESSAGE = createAction('[Toaster] Clear Message by ID', props());
const CREATE_ERROR = createAction('[Toaster] Create *Error*', props());
const CREATE_INFO = createAction('[Toaster] Create *Info*', props());
const CREATE_SUCCESS = createAction('[Toaster] Create *Success*', props());
const CREATE_WARNING = createAction('[Toaster] Create *Warning*', props());
const all = union({
    CLEAR_ALL,
    CLEAR_ALL_ERRORS,
    CLEAR_ALL_ERRORS_AND_WARNINGS,
    CLEAR_MESSAGE,
    CREATE_ERROR,
    CREATE_INFO,
    CREATE_SUCCESS,
    CREATE_WARNING,
});

const thisReducer = (state) => state.toaster;
const initialState = {
    messages: [],
    nextId: 1,
};
function addMessage(currentMessages, newMessage) {
    const messages = [{
            autoClose: newMessage.autoClose ? newMessage.autoClose : undefined,
            closeable: newMessage.closeable ? newMessage.closeable : true,
            id: newMessage.id,
            message: newMessage.message,
            title: newMessage.title,
            severity: newMessage.severity,
        }, ...currentMessages];
    if (messages.length > 5) {
        messages.length = 5;
    }
    return messages;
}
const handleReducer = createReducer(initialState, on(CLEAR_ALL, (state) => {
    return {
        ...state,
        messages: []
    };
}), on(CLEAR_ALL_ERRORS, (state) => {
    return {
        ...state,
        messages: [...state.messages.filter(msg => msg.severity !== SpfToasterSeverityEnum.ERROR)]
    };
}), on(CLEAR_ALL_ERRORS_AND_WARNINGS, (state) => {
    return {
        ...state,
        messages: [...state.messages.filter(msg => msg.severity !== SpfToasterSeverityEnum.ERROR &&
                msg.severity !== SpfToasterSeverityEnum.WARNING)]
    };
}), on(CLEAR_MESSAGE, (state, action) => {
    return {
        ...state,
        messages: [...state.messages.filter(msg => msg.id !== action.id)]
    };
}), on(CREATE_ERROR, (state, action) => {
    return {
        ...state,
        messages: addMessage(state.messages, {
            autoClose: action.autoClose ? toasterAutocloseSpeed(action.autoClose, action.messageText) : undefined,
            closeable: action.closeable ? action.closeable : true,
            id: state.nextId,
            message: action.messageText,
            severity: SpfToasterSeverityEnum.ERROR,
            title: action.title,
        }),
        nextId: state.nextId + 1
    };
}), on(CREATE_INFO, (state, action) => {
    return {
        ...state,
        messages: addMessage(state.messages, {
            autoClose: action.autoClose ? toasterAutocloseSpeed(action.autoClose, action.messageText) : undefined,
            closeable: action.closeable ? action.closeable : true,
            id: state.nextId,
            message: action.messageText,
            severity: SpfToasterSeverityEnum.INFO,
            title: action.title,
        }),
        nextId: state.nextId + 1
    };
}), on(CREATE_SUCCESS, (state, action) => {
    return {
        ...state,
        messages: addMessage(state.messages, {
            autoClose: action.autoClose ? toasterAutocloseSpeed(action.autoClose, action.messageText) : undefined,
            closeable: action.closeable ? action.closeable : true,
            id: state.nextId,
            message: action.messageText,
            severity: SpfToasterSeverityEnum.SUCCESS,
            title: action.title,
        }),
        nextId: state.nextId + 1
    };
}), on(CREATE_WARNING, (state, action) => {
    return {
        ...state,
        messages: addMessage(state.messages, {
            autoClose: action.autoClose ? toasterAutocloseSpeed(action.autoClose, action.messageText) : undefined,
            closeable: action.closeable ? action.closeable : true,
            id: state.nextId,
            message: action.messageText,
            severity: SpfToasterSeverityEnum.WARNING,
            title: action.title,
        }),
        nextId: state.nextId + 1
    };
}));
function reducer(state, action) {
    return handleReducer(state, action);
}
const selectMessages = createSelector(thisReducer, (state) => state.messages);

class SpfToasterService {
    constructor(toasterStore) {
        this.toasterStore = toasterStore;
        this.timeouts = {};
        this.autoCloseManager();
    }
    autoCloseManager() {
        this.toasterStore.select(selectMessages).subscribe(messages => {
            messages.forEach(message => {
                if (message.autoClose && this.timeouts[message.id] === undefined) {
                    this.timeouts[message.id] = setTimeout(() => {
                        this.toasterStore.dispatch(CLEAR_MESSAGE({ id: message.id }));
                    }, message.autoClose);
                }
            });
        });
    }
}
SpfToasterService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpfToasterService, deps: [{ token: i1$1.Store }], target: i0.ɵɵFactoryTarget.Injectable });
SpfToasterService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpfToasterService });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpfToasterService, decorators: [{
            type: Injectable
        }], ctorParameters: function () { return [{ type: i1$1.Store }]; } });

class SpfToasterModule {
    static forRoot() {
        return {
            ngModule: SpfToasterModule,
            providers: [
                { provide: SpfToasterService }
            ]
        };
    }
}
SpfToasterModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpfToasterModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
SpfToasterModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.3.0", ngImport: i0, type: SpfToasterModule, declarations: [ToastsDisplayerComponent], imports: [CommonModule,
        SpfModule], exports: [ToastsDisplayerComponent] });
SpfToasterModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpfToasterModule, imports: [CommonModule,
        SpfModule] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: SpfToasterModule, decorators: [{
            type: NgModule,
            args: [{
                    declarations: [
                        ToastsDisplayerComponent,
                    ],
                    imports: [
                        CommonModule,
                        SpfModule,
                    ],
                    exports: [
                        ToastsDisplayerComponent,
                    ]
                }]
        }] });

var index = /*#__PURE__*/Object.freeze({
    __proto__: null,
    get SpfToasterSeverityEnum () { return SpfToasterSeverityEnum; },
    get SpfToasterAutoCloseSpeedEnum () { return SpfToasterAutoCloseSpeedEnum; },
    toasterAutocloseSpeed: toasterAutocloseSpeed,
    ToastsDisplayerComponent: ToastsDisplayerComponent,
    ToasterMessageInterface: ToasterMessageInterface,
    CLEAR_ALL: CLEAR_ALL,
    CLEAR_ALL_ERRORS: CLEAR_ALL_ERRORS,
    CLEAR_ALL_ERRORS_AND_WARNINGS: CLEAR_ALL_ERRORS_AND_WARNINGS,
    CLEAR_MESSAGE: CLEAR_MESSAGE,
    CREATE_ERROR: CREATE_ERROR,
    CREATE_INFO: CREATE_INFO,
    CREATE_SUCCESS: CREATE_SUCCESS,
    CREATE_WARNING: CREATE_WARNING,
    SpfToasterModule: SpfToasterModule,
    initialState: initialState,
    addMessage: addMessage,
    reducer: reducer,
    selectMessages: selectMessages,
    SpfToasterService: SpfToasterService
});

/*
 * Public API Surface of angular-components
 */

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

export { INITIALIZE, SpaWelcomeComponent, SpaWelcomeModule, SpfCapitalizeModule, SpfCapitalizePipe, SpfMenuComponent, SpfMenuModule, UPDATE, initialState$2 as initialState, reducer$2 as reducer, selectState, index$1 as spinner, index as toaster };
//# sourceMappingURL=angular-components.mjs.map
