import { __awaiter, __generator } from "tslib";
import { Component } from '@angular/core';
import { AlConduitClient, AlSession, AlStopwatch, AlLocatorService, AlLocation } from '@al/core';
import * as i0 from "@angular/core";
import * as i1 from "primeng-lts/dialog";
import * as i2 from "primeng-lts/api";
import * as i3 from "@angular/common";
import * as i4 from "primeng-lts/galleria";
import * as i5 from "../directives/al-external-html.directive";
function AlWelcomeDialogComponent_div_6_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "div", 17);
} if (rf & 2) {
    var ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵproperty("alExternalHtml", ctx_r0.manifest.introContentId);
} }
function AlWelcomeDialogComponent_ng_template_10_Template(rf, ctx) { if (rf & 1) {
    var _r7 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 18);
    i0.ɵɵlistener("click", function AlWelcomeDialogComponent_ng_template_10_Template_div_click_0_listener() { i0.ɵɵrestoreView(_r7); var item_r5 = ctx.$implicit; var ctx_r6 = i0.ɵɵnextContext(); return ctx_r6.openURL(item_r5.url); });
    i0.ɵɵelementStart(1, "div", 19);
    i0.ɵɵtext(2);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(3, "div", 20);
    i0.ɵɵtext(4);
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
} if (rf & 2) {
    var item_r5 = ctx.$implicit;
    var ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵstyleProp("background", ctx_r1.galleriaUrls[ctx_r1.indexGalleria], i0.ɵɵdefaultStyleSanitizer);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(item_r5.title);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(item_r5.subtitle);
} }
var _c0 = function (a0) { return { "active-item-galleria": a0 }; };
function AlWelcomeDialogComponent_div_12_Template(rf, ctx) { if (rf & 1) {
    var _r11 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 21);
    i0.ɵɵlistener("click", function AlWelcomeDialogComponent_div_12_Template_div_click_0_listener() { i0.ɵɵrestoreView(_r11); var i_r9 = ctx.index; var ctx_r10 = i0.ɵɵnextContext(); return ctx_r10.changeIndex(i_r9); });
    i0.ɵɵelementStart(1, "i", 22);
    i0.ɵɵtext(2, "brightness_1");
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
} if (rf & 2) {
    var i_r9 = ctx.index;
    var ctx_r2 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngClass", i0.ɵɵpureFunction1(1, _c0, ctx_r2.indexGalleria === i_r9));
} }
function AlWelcomeDialogComponent_div_16_Template(rf, ctx) { if (rf & 1) {
    var _r14 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div");
    i0.ɵɵelementStart(1, "div", 23);
    i0.ɵɵelementStart(2, "span", 24);
    i0.ɵɵtext(3, "east");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(4, "div", 25);
    i0.ɵɵlistener("click", function AlWelcomeDialogComponent_div_16_Template_div_click_4_listener() { i0.ɵɵrestoreView(_r14); var item_r12 = ctx.$implicit; var ctx_r13 = i0.ɵɵnextContext(); return ctx_r13.openURL(item_r12.url); });
    i0.ɵɵtext(5);
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
} if (rf & 2) {
    var item_r12 = ctx.$implicit;
    i0.ɵɵadvance(5);
    i0.ɵɵtextInterpolate(item_r12.title);
} }
function AlWelcomeDialogComponent_div_21_Template(rf, ctx) { if (rf & 1) {
    var _r18 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div", 26);
    i0.ɵɵlistener("click", function AlWelcomeDialogComponent_div_21_Template_div_click_0_listener() { i0.ɵɵrestoreView(_r18); var videoItem_r15 = ctx.$implicit; var ctx_r17 = i0.ɵɵnextContext(); return ctx_r17.openURL(videoItem_r15.url); });
    i0.ɵɵelement(1, "img", 27);
    i0.ɵɵelementStart(2, "div", 28);
    i0.ɵɵtext(3);
    i0.ɵɵelementEnd();
    i0.ɵɵelementEnd();
} if (rf & 2) {
    var videoItem_r15 = ctx.$implicit;
    var i_r16 = ctx.index;
    var ctx_r4 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("src", ctx_r4.videosUrls[i_r16], i0.ɵɵsanitizeUrl);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(videoItem_r15.title);
} }
var _c1 = function () { return { "max-width": "100%" }; };
var AlWelcomeDialogComponent = /** @class */ (function () {
    function AlWelcomeDialogComponent() {
        this.display = false;
        this.title = 'Welcome';
        this.galleriaItems = [];
        this.innovations = [];
        this.videoTutorials = [];
        this.hideDialog = false;
        this.indexGalleria = 0;
        this.maxIndexGalleria = 0;
        this.logoSourceName = "logo-horizontal-light.svg";
        this.logoUrl = "";
        this.galleriaUrls = [];
        this.videosUrls = [];
        this.state = {
            sessionExpiration: AlSession.getTokenExpiry(),
            lastDisplayedVersion: 0,
            displayUpdatesOnly: false
        };
        this.conduit = new AlConduitClient();
    }
    AlWelcomeDialogComponent.prototype.changeIndex = function (index) {
        this.indexGalleria = index;
    };
    AlWelcomeDialogComponent.prototype.openURL = function (url) {
        window.open(url, "_blank");
    };
    AlWelcomeDialogComponent.prototype.getURLThumbnail = function (urlImage) {
        return 'url(' + urlImage + ')';
    };
    AlWelcomeDialogComponent.prototype.getFullUrlImage = function (imageUrl) {
        var multimediaUrlPath = AlLocatorService.resolveURL(AlLocation.AccountsUI, "/assets/static/welcomePage/img/");
        return multimediaUrlPath + imageUrl;
    };
    AlWelcomeDialogComponent.prototype.shouldDisplay = function (manifest) {
        return __awaiter(this, void 0, void 0, function () {
            var state, currentTimestamp;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        if (this.display) {
                            //  Already displayed
                            return [2 /*return*/, false];
                        }
                        return [4 /*yield*/, this.conduit.getGlobalSetting("welcomePage")];
                    case 1:
                        state = _a.sent();
                        if (state) {
                            this.state = state;
                        }
                        this.hideDialog = this.state.displayUpdatesOnly;
                        currentTimestamp = Math.floor(new Date().getTime() / 1000);
                        if (currentTimestamp < this.state.sessionExpiration) {
                            return [2 /*return*/, false];
                        }
                        if (this.state.displayUpdatesOnly && this.state.lastDisplayedVersion >= manifest.version) {
                            return [2 /*return*/, false];
                        }
                        return [2 /*return*/, true];
                }
            });
        });
    };
    AlWelcomeDialogComponent.prototype.startDisplay = function (manifest) {
        var _this = this;
        this.manifest = manifest;
        this.logoUrl = this.getFullUrlImage(this.logoSourceName);
        this.title = manifest.title || "Welcome";
        this.galleriaUrls = [];
        this.videosUrls = [];
        if ('featured' in manifest.sections) {
            this.galleriaItems = manifest.sections.featured.items.filter(function (item) {
                if (item.imageUrl) {
                    _this.galleriaUrls.push(_this.getURLThumbnail(_this.getFullUrlImage(item.imageUrl)));
                }
                return item.visible;
            });
        }
        if ('innovations' in manifest.sections) {
            this.innovations = manifest.sections.innovations.items;
        }
        if ('videos' in manifest.sections) {
            this.videoTutorials = manifest.sections.videos.items.filter(function (item) {
                if (item.imageUrl) {
                    _this.videosUrls.push(_this.getFullUrlImage(item.imageUrl));
                }
                return item.visible;
            });
        }
        this.display = true;
        AlStopwatch.once(function () {
            _this.state.sessionExpiration = AlSession.getTokenExpiry();
            _this.state.lastDisplayedVersion = manifest.version;
            _this.conduit.setGlobalSetting("welcomePage", _this.state);
        }, 1000);
    };
    AlWelcomeDialogComponent.prototype.welcomeDisplayChanged = function (event) {
        var _this = this;
        this.state.displayUpdatesOnly = this.hideDialog;
        AlStopwatch.once(function () {
            _this.conduit.setGlobalSetting("welcomePage", _this.state);
        }, 1000);
    };
    /** @nocollapse */ AlWelcomeDialogComponent.ɵfac = function AlWelcomeDialogComponent_Factory(t) { return new (t || AlWelcomeDialogComponent)(); };
    /** @nocollapse */ AlWelcomeDialogComponent.ɵcmp = i0.ɵɵdefineComponent({ type: AlWelcomeDialogComponent, selectors: [["al-welcome-dialog"]], decls: 22, vars: 19, consts: [[3, "visible", "styleClass", "draggable", "modal", "blockScroll", "transitionOptions", "visibleChange"], [1, "dialog-title"], ["alt", "AL logo", 1, "al-header-logo", 3, "src"], [1, "welcome-label"], [3, "alExternalHtml", 4, "ngIf"], [1, "p-grid"], [1, "galleria-innovations"], [3, "value", "containerStyle", "autoPlay", "circular", "transitionInterval", "showThumbnailNavigators", "activeIndex", "activeIndexChange"], ["pTemplate", "item"], [1, "indicator-gallery"], ["class", "indicator", 3, "click", 4, "ngFor", "ngForOf"], [1, "innovations-section"], [1, "subtitle"], [4, "ngFor", "ngForOf"], [1, "video-tutorials-section"], [1, "video-list"], ["class", "video-item", 3, "click", 4, "ngFor", "ngForOf"], [3, "alExternalHtml"], [1, "galleria-slide", 3, "click"], [1, "title-slide"], [1, "subtitle-slide"], [1, "indicator", 3, "click"], [1, "material-icons", 3, "ngClass"], [1, "info-item"], [1, "material-icons"], [1, "label-item", 3, "click"], [1, "video-item", 3, "click"], ["alt", "Preview Video", 3, "src"], [1, "video-label"]], template: function AlWelcomeDialogComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "p-dialog", 0);
            i0.ɵɵlistener("visibleChange", function AlWelcomeDialogComponent_Template_p_dialog_visibleChange_0_listener($event) { return ctx.display = $event; });
            i0.ɵɵelementStart(1, "p-header");
            i0.ɵɵelementStart(2, "div", 1);
            i0.ɵɵelement(3, "img", 2);
            i0.ɵɵelementStart(4, "div", 3);
            i0.ɵɵtext(5, "What's New");
            i0.ɵɵelementEnd();
            i0.ɵɵelementEnd();
            i0.ɵɵtemplate(6, AlWelcomeDialogComponent_div_6_Template, 1, 1, "div", 4);
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(7, "div", 5);
            i0.ɵɵelementStart(8, "div", 6);
            i0.ɵɵelementStart(9, "p-galleria", 7);
            i0.ɵɵlistener("activeIndexChange", function AlWelcomeDialogComponent_Template_p_galleria_activeIndexChange_9_listener($event) { return ctx.indexGalleria = $event; });
            i0.ɵɵtemplate(10, AlWelcomeDialogComponent_ng_template_10_Template, 5, 4, "ng-template", 8);
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(11, "div", 9);
            i0.ɵɵtemplate(12, AlWelcomeDialogComponent_div_12_Template, 3, 3, "div", 10);
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(13, "div", 11);
            i0.ɵɵelementStart(14, "div", 12);
            i0.ɵɵtext(15, "Alert Logic Innovations");
            i0.ɵɵelementEnd();
            i0.ɵɵtemplate(16, AlWelcomeDialogComponent_div_16_Template, 6, 1, "div", 13);
            i0.ɵɵelementEnd();
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(17, "div", 14);
            i0.ɵɵelementStart(18, "div", 12);
            i0.ɵɵtext(19, "Video Tutorials");
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(20, "div", 15);
            i0.ɵɵtemplate(21, AlWelcomeDialogComponent_div_21_Template, 4, 2, "div", 16);
            i0.ɵɵelementEnd();
            i0.ɵɵelementEnd();
            i0.ɵɵelementEnd();
            i0.ɵɵelementEnd();
        } if (rf & 2) {
            i0.ɵɵproperty("visible", ctx.display)("styleClass", "welcome-dialog")("draggable", false)("modal", true)("blockScroll", true)("transitionOptions", "250ms");
            i0.ɵɵadvance(3);
            i0.ɵɵproperty("src", ctx.logoUrl, i0.ɵɵsanitizeUrl);
            i0.ɵɵadvance(3);
            i0.ɵɵproperty("ngIf", ctx.manifest && ctx.manifest.introContentId);
            i0.ɵɵadvance(3);
            i0.ɵɵproperty("value", ctx.galleriaItems)("containerStyle", i0.ɵɵpureFunction0(18, _c1))("autoPlay", true)("circular", true)("transitionInterval", 6000)("showThumbnailNavigators", false)("activeIndex", ctx.indexGalleria);
            i0.ɵɵadvance(3);
            i0.ɵɵproperty("ngForOf", ctx.galleriaItems);
            i0.ɵɵadvance(4);
            i0.ɵɵproperty("ngForOf", ctx.innovations);
            i0.ɵɵadvance(5);
            i0.ɵɵproperty("ngForOf", ctx.videoTutorials);
        } }, directives: [i1.Dialog, i2.Header, i3.NgIf, i4.Galleria, i2.PrimeTemplate, i3.NgForOf, i5.AlExternalHtmlDirective, i3.NgClass], styles: ["[_nghost-%COMP%]     .welcome-dialog{background-color:#000;border:1px solid #000;border-radius:7px}[_nghost-%COMP%]     .welcome-dialog .ui-dialog-content, [_nghost-%COMP%]     .welcome-dialog .ui-dialog-titlebar{width:800px;background-color:#000;color:#fff}[_nghost-%COMP%]     .welcome-dialog .ui-dialog-titlebar{height:108px;padding:20px 24px 0;border-radius:7px}[_nghost-%COMP%]     .welcome-dialog .ui-dialog-content{height:470px;min-height:470px;overflow-y:hidden;border-radius:7px}[_nghost-%COMP%]     .welcome-dialog .dialog-title{display:flex;flex-direction:column;align-items:center}[_nghost-%COMP%]     .welcome-dialog .welcome-label{max-height:40px;font-size:2.1rem}[_nghost-%COMP%]     .welcome-dialog .galleria-slide{width:100%;height:250px;text-align:center;background-color:#2e2e2e;background-size:100% 250px!important;display:flex;flex-direction:column;justify-content:center;padding:0 20px;opacity:0;animation-name:fade;animation-duration:6s;animation-iteration-count:infinite;cursor:pointer}@keyframes fade{0%,100%{opacity:0}25%,50%,75%{opacity:1}}[_nghost-%COMP%]     .welcome-dialog .galleria-slide .title-slide{font-size:22px}[_nghost-%COMP%]     .welcome-dialog .galleria-slide .subtitle-slide{font-size:16px}[_nghost-%COMP%]     .welcome-dialog .galleria-slide .subtitle-slide, [_nghost-%COMP%]     .welcome-dialog .galleria-slide .title-slide{text-align:initial;width:50%}[_nghost-%COMP%]     .welcome-dialog .galleria-innovations{width:66%;margin-left:16px}[_nghost-%COMP%]     .welcome-dialog .innovations-section{width:100%}[_nghost-%COMP%]     .welcome-dialog .innovations-section .subtitle{margin-bottom:5px}[_nghost-%COMP%]     .welcome-dialog .video-tutorials-section{width:26%;margin-left:4%}[_nghost-%COMP%]     .welcome-dialog .video-tutorials-section .subtitle{margin-bottom:0}[_nghost-%COMP%]     .welcome-dialog .p-col-12{padding:0}[_nghost-%COMP%]     .welcome-dialog .subtitle{font-size:1.4rem}[_nghost-%COMP%]     .welcome-dialog .subtitle, [_nghost-%COMP%]     .welcome-dialog .welcome-label{font-weight:200}[_nghost-%COMP%]     .welcome-dialog .info-item{display:flex;padding:6px 0;max-height:30px;align-items:center;cursor:pointer}[_nghost-%COMP%]     .welcome-dialog .info-item span{color:#f57c00;margin-right:5px;font-size:16px}[_nghost-%COMP%]     .welcome-dialog .info-item .label-item{transition:.3s}[_nghost-%COMP%]     .welcome-dialog .info-item :hover{color:#868686}[_nghost-%COMP%]     .welcome-dialog .info-item, [_nghost-%COMP%]     .welcome-dialog .info-phrase, [_nghost-%COMP%]     .welcome-dialog .subtitle, [_nghost-%COMP%]     .welcome-dialog .subtitle-slide, [_nghost-%COMP%]     .welcome-dialog .title-slide{color:#ededed}[_nghost-%COMP%]     .welcome-dialog .info-phrase, [_nghost-%COMP%]     .welcome-dialog .label-item{font-size:1.15rem}[_nghost-%COMP%]     .welcome-dialog .hide-option{display:flex;padding-left:10px;align-items:center}[_nghost-%COMP%]     .welcome-dialog .hide-option .hide-label{font-size:1rem;padding-left:5px}[_nghost-%COMP%]     .welcome-dialog .hide-option input{display:flex!important}[_nghost-%COMP%]     .welcome-dialog .indicator-gallery{display:flex;cursor:pointer;justify-content:center;font-size:15px;padding:8px 0 6px;color:#868686}[_nghost-%COMP%]     .welcome-dialog .indicator-gallery .indicator{margin:0 12px}[_nghost-%COMP%]     .welcome-dialog .indicator-gallery .indicator .material-icons{font-size:6px}[_nghost-%COMP%]     .welcome-dialog .indicator-gallery :hover{color:#fff}[_nghost-%COMP%]     .welcome-dialog .active-item-galleria{color:#fff}[_nghost-%COMP%]     .welcome-dialog .video-list{max-width:226px;margin-top:10px;overflow-y:scroll;max-height:400px;scrollbar-color:rgba(255,255,255,.4) rgba(77,74,74,.6);scrollbar-width:thin}[_nghost-%COMP%]     .welcome-dialog .video-list .video-item{display:flex;flex-direction:row;align-items:center;cursor:pointer;margin:0 5px 12px 0}[_nghost-%COMP%]     .welcome-dialog .video-list .video-item :hover{color:#868686}[_nghost-%COMP%]     .welcome-dialog .video-list .video-item img{margin-right:12px;max-width:70px;max-height:50px}[_nghost-%COMP%]     .welcome-dialog .video-list iframe{pointer-events:none}[_nghost-%COMP%]     .welcome-dialog .video-list .video-label{cursor:pointer;font-size:13px;font-weight:700;transition:.3s}[_nghost-%COMP%]     .ui-dialog-mask.ui-widget-overlay{overflow-y:auto;-webkit-backdrop-filter:blur(5px);backdrop-filter:blur(5px);background:rgba(0,0,0,.75)}[_nghost-%COMP%]     .al-header-logo{background-repeat:no-repeat;background-position:center;width:130px;height:39px;min-height:39px}[_nghost-%COMP%]     .ui-dialog-titlebar-close{position:absolute;right:24px;top:15px}[_ngcontent-%COMP%]::-webkit-scrollbar{width:8px}[_ngcontent-%COMP%]::-webkit-scrollbar-track{background:#202020;border-radius:10px}[_ngcontent-%COMP%]::-webkit-scrollbar-thumb{border-radius:10px;background:rgba(77,74,74,.6)}[_ngcontent-%COMP%]::-webkit-scrollbar-thumb:window-inactive{background:rgba(255,255,255,.4)}"] });
    return AlWelcomeDialogComponent;
}());
export { AlWelcomeDialogComponent };
/*@__PURE__*/ (function () { i0.ɵsetClassMetadata(AlWelcomeDialogComponent, [{
        type: Component,
        args: [{
                selector: 'al-welcome-dialog',
                templateUrl: './al-welcome-dialog.component.html',
                styleUrls: ['./al-welcome-dialog.component.scss']
            }]
    }], null, null); })();
//# sourceMappingURL=data:application/json;base64, 