/**
 * @packageDocumentation
 * @module page-guard
 */
import { handlePixel, ThemeService } from '@alauda/ui';
import { ChangeDetectionStrategy, Component, ContentChild, Input, TemplateRef, } from '@angular/core';
import { isBoolean } from 'lodash-es';
import { map } from 'rxjs';
import { publishRef } from '../../core/public-api';
import { PageGuardContentDirective, PageGuardDescriptionDirective, PageGuardOperationDirective, } from './helper-directives';
import { DEFAULT_REASON, GuardStatus, REASON_MAP, Reason, } from './page-guard.type';
import * as i0 from "@angular/core";
import * as i1 from "@alauda/ui";
function PageGuardComponent_ng_container_0_ng_container_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainer(0, 3);
} if (rf & 2) {
    const ctx_r5 = i0.ɵɵnextContext(2);
    i0.ɵɵproperty("ngTemplateOutlet", ctx_r5.template);
} }
function PageGuardComponent_ng_container_0_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵtemplate(1, PageGuardComponent_ng_container_0_ng_container_1_Template, 1, 1, "ng-container", 2);
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r0.template);
} }
const _c0 = function (a0) { return { isFull: a0 }; };
function PageGuardComponent_ng_container_1_aui_card_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "aui-card", 5);
    i0.ɵɵelementContainer(1, 3);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r6 = i0.ɵɵnextContext(2);
    const _r3 = i0.ɵɵreference(4);
    i0.ɵɵproperty("divider", false)("ngClass", i0.ɵɵpureFunction1(3, _c0, ctx_r6.isFull));
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngTemplateOutlet", _r3);
} }
function PageGuardComponent_ng_container_1_ng_container_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainer(0, 3);
} if (rf & 2) {
    i0.ɵɵnextContext(2);
    const _r3 = i0.ɵɵreference(4);
    i0.ɵɵproperty("ngTemplateOutlet", _r3);
} }
function PageGuardComponent_ng_container_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵtemplate(1, PageGuardComponent_ng_container_1_aui_card_1_Template, 2, 5, "aui-card", 4);
    i0.ɵɵtemplate(2, PageGuardComponent_ng_container_1_ng_container_2_Template, 1, 1, "ng-container", 2);
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r1.context === "page");
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r1.context !== "page");
} }
function PageGuardComponent_ng_container_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵelementStart(1, "div", 6);
    i0.ɵɵelement(2, "acl-loading-mask", 7);
    i0.ɵɵelementEnd();
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    i0.ɵɵadvance(2);
    i0.ɵɵproperty("loading", true);
} }
function PageGuardComponent_ng_template_3_h3_4_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "h3", 13);
    i0.ɵɵtext(1);
    i0.ɵɵpipe(2, "translate");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r8 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate1(" ", ctx_r8.title || i0.ɵɵpipeBind1(2, 1, ctx_r8.reasonModel.title), " ");
} }
function PageGuardComponent_ng_template_3_div_5_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 14);
    i0.ɵɵelementContainer(1, 3);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r9 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngTemplateOutlet", ctx_r9.descriptionTpl);
} }
function PageGuardComponent_ng_template_3_ng_container_6_ng_container_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵelementStart(1, "p", 14);
    i0.ɵɵtext(2);
    i0.ɵɵelementEnd();
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r12 = i0.ɵɵnextContext(3);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(ctx_r12.description);
} }
function PageGuardComponent_ng_template_3_ng_container_6_ng_container_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵelementStart(1, "p", 14);
    i0.ɵɵtext(2);
    i0.ɵɵpipe(3, "translate");
    i0.ɵɵelementEnd();
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r13 = i0.ɵɵnextContext(3);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(i0.ɵɵpipeBind1(3, 1, ctx_r13.reasonModel.description));
} }
function PageGuardComponent_ng_template_3_ng_container_6_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵtemplate(1, PageGuardComponent_ng_template_3_ng_container_6_ng_container_1_Template, 3, 1, "ng-container", 0);
    i0.ɵɵtemplate(2, PageGuardComponent_ng_template_3_ng_container_6_ng_container_2_Template, 4, 3, "ng-container", 0);
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r10 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r10.isNonEmptyString(ctx_r10.description));
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r10.isUndefined(ctx_r10.description));
} }
function PageGuardComponent_ng_template_3_div_7_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 15);
    i0.ɵɵelementContainer(1, 3);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r11 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngTemplateOutlet", ctx_r11.operation);
} }
function PageGuardComponent_ng_template_3_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 8)(1, "div", 9);
    i0.ɵɵelement(2, "img");
    i0.ɵɵpipe(3, "async");
    i0.ɵɵtemplate(4, PageGuardComponent_ng_template_3_h3_4_Template, 3, 3, "h3", 10);
    i0.ɵɵtemplate(5, PageGuardComponent_ng_template_3_div_5_Template, 2, 1, "div", 11);
    i0.ɵɵtemplate(6, PageGuardComponent_ng_template_3_ng_container_6_Template, 3, 2, "ng-container", 0);
    i0.ɵɵtemplate(7, PageGuardComponent_ng_template_3_div_7_Template, 2, 1, "div", 12);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r4 = i0.ɵɵnextContext();
    i0.ɵɵstyleProp("margin-top", ctx_r4.handlePixel(ctx_r4.top));
    i0.ɵɵadvance(2);
    i0.ɵɵattribute("src", i0.ɵɵpipeBind1(3, 7, ctx_r4.reasonSrc$), i0.ɵɵsanitizeUrl);
    i0.ɵɵadvance(2);
    i0.ɵɵproperty("ngIf", ctx_r4.title || ctx_r4.reasonModel.title);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r4.descriptionTpl);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", !ctx_r4.descriptionTpl);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r4.isTemplateRef(ctx_r4.operation));
} }
export class PageGuardComponent {
    constructor(theme) {
        this.theme = theme;
        this.status = GuardStatus.Pending;
        this.title = '';
        this.context = 'page';
        this.reasonModel = DEFAULT_REASON;
        this.handlePixel = handlePixel;
        this.reasonSrc$ = this.theme.currentTheme$.pipe(map(theme => `images/${theme}/${this.reasonModel.src}`), publishRef());
    }
    get allowed() {
        return this.status === GuardStatus.Available;
    }
    set allowed(allowed) {
        if (isBoolean(allowed)) {
            this.status = allowed ? GuardStatus.Available : GuardStatus.Unavailable;
        }
        else {
            this.status = GuardStatus.Pending;
        }
    }
    set reason(reason) {
        if (reason) {
            this.reasonModel = REASON_MAP[reason] || DEFAULT_REASON;
        }
    }
    isNonEmptyString(value) {
        return typeof value === 'string' && value !== '';
    }
    isUndefined(value) {
        return typeof value === 'undefined';
    }
    isTemplateRef(value) {
        return value instanceof TemplateRef;
    }
}
PageGuardComponent.ɵfac = function PageGuardComponent_Factory(t) { return new (t || PageGuardComponent)(i0.ɵɵdirectiveInject(i1.ThemeService)); };
PageGuardComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: PageGuardComponent, selectors: [["acl-page-guard"]], contentQueries: function PageGuardComponent_ContentQueries(rf, ctx, dirIndex) { if (rf & 1) {
        i0.ɵɵcontentQuery(dirIndex, PageGuardDescriptionDirective, 5, TemplateRef);
        i0.ɵɵcontentQuery(dirIndex, PageGuardOperationDirective, 5, TemplateRef);
        i0.ɵɵcontentQuery(dirIndex, PageGuardContentDirective, 5, TemplateRef);
    } if (rf & 2) {
        let _t;
        i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.descriptionTpl = _t.first);
        i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.operation = _t.first);
        i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.template = _t.first);
    } }, inputs: { top: "top", isFull: "isFull", allowed: "allowed", status: "status", reason: "reason", title: "title", description: "description", context: "context" }, decls: 5, vars: 3, consts: [[4, "ngIf"], ["unavailable", ""], [3, "ngTemplateOutlet", 4, "ngIf"], [3, "ngTemplateOutlet"], ["class", "unavailable", 3, "divider", "ngClass", 4, "ngIf"], [1, "unavailable", 3, "divider", "ngClass"], [1, "acl-page-guard--pending"], ["type", "module", 3, "loading"], [1, "acl-page-guard--unavailable"], [1, "container"], ["class", "title", 4, "ngIf"], ["class", "description", 4, "ngIf"], ["class", "operation", 4, "ngIf"], [1, "title"], [1, "description"], [1, "operation"]], template: function PageGuardComponent_Template(rf, ctx) { if (rf & 1) {
        i0.ɵɵtemplate(0, PageGuardComponent_ng_container_0_Template, 2, 1, "ng-container", 0);
        i0.ɵɵtemplate(1, PageGuardComponent_ng_container_1_Template, 3, 2, "ng-container", 0);
        i0.ɵɵtemplate(2, PageGuardComponent_ng_container_2_Template, 3, 1, "ng-container", 0);
        i0.ɵɵtemplate(3, PageGuardComponent_ng_template_3_Template, 8, 9, "ng-template", null, 1, i0.ɵɵtemplateRefExtractor);
    } if (rf & 2) {
        i0.ɵɵproperty("ngIf", ctx.status === "available");
        i0.ɵɵadvance(1);
        i0.ɵɵproperty("ngIf", ctx.status === "unavailable");
        i0.ɵɵadvance(1);
        i0.ɵɵproperty("ngIf", ctx.status !== "available" && ctx.status !== "unavailable");
    } }, styles: ["aui-card.unavailable[_ngcontent-%COMP%]     .aui-card{padding-top:120px;padding-bottom:200px;height:calc(100vh - 124px);min-height:600px}aui-card.unavailable.isFull[_ngcontent-%COMP%]     .aui-card{height:calc(100vh - 40px)}.acl-page-guard--pending[_ngcontent-%COMP%], .acl-page-guard--unavailable[_ngcontent-%COMP%]{width:100%;height:100%;display:flex;justify-content:center;align-items:center}.acl-page-guard--unavailable[_ngcontent-%COMP%]   .container[_ngcontent-%COMP%]{display:flex;flex-direction:column;align-items:center}.acl-page-guard--unavailable[_ngcontent-%COMP%]   .container[_ngcontent-%COMP%]   img[_ngcontent-%COMP%]{height:200px}.acl-page-guard--unavailable[_ngcontent-%COMP%]   .container[_ngcontent-%COMP%]   .title[_ngcontent-%COMP%]{margin:var(--aui-spacing-xxl) 0 var(--aui-spacing-l) 0;font-size:var(--aui-font-size-xl);color:rgb(var(--aui-color-n-1));font-weight:var(--aui-font-weight-bold)}.acl-page-guard--unavailable[_ngcontent-%COMP%]   .container[_ngcontent-%COMP%]   .description[_ngcontent-%COMP%]{color:rgb(var(--aui-color-n-4));font-size:var(--aui-font-size-m);text-align:center;max-width:560px;margin:0}.acl-page-guard--unavailable[_ngcontent-%COMP%]   .container[_ngcontent-%COMP%]   .operation[_ngcontent-%COMP%]{margin-top:var(--aui-spacing-l)}"], changeDetection: 0 });
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(PageGuardComponent, [{
        type: Component,
        args: [{ selector: 'acl-page-guard', changeDetection: ChangeDetectionStrategy.OnPush, template: "<ng-container *ngIf=\"status === 'available'\">\n  <ng-container\n    *ngIf=\"template\"\n    [ngTemplateOutlet]=\"template\"\n  ></ng-container>\n</ng-container>\n\n<ng-container *ngIf=\"status === 'unavailable'\">\n  <aui-card\n    [divider]=\"false\"\n    class=\"unavailable\"\n    [ngClass]=\"{ isFull: isFull }\"\n    *ngIf=\"context === 'page'\"\n  >\n    <ng-container [ngTemplateOutlet]=\"unavailable\"></ng-container>\n  </aui-card>\n  <ng-container\n    *ngIf=\"context !== 'page'\"\n    [ngTemplateOutlet]=\"unavailable\"\n  ></ng-container>\n</ng-container>\n<ng-container *ngIf=\"status !== 'available' && status !== 'unavailable'\">\n  <div class=\"acl-page-guard--pending\">\n    <acl-loading-mask\n      [loading]=\"true\"\n      type=\"module\"\n    ></acl-loading-mask>\n  </div>\n</ng-container>\n\n<ng-template #unavailable>\n  <div\n    class=\"acl-page-guard--unavailable\"\n    [style.margin-top]=\"handlePixel(top)\"\n  >\n    <div class=\"container\">\n      <img [attr.src]=\"reasonSrc$ | async\" />\n      <h3\n        *ngIf=\"title || reasonModel.title\"\n        class=\"title\"\n      >\n        {{ title || (reasonModel.title | translate) }}\n      </h3>\n      <div\n        class=\"description\"\n        *ngIf=\"descriptionTpl\"\n      >\n        <ng-container [ngTemplateOutlet]=\"descriptionTpl\"></ng-container>\n      </div>\n      <ng-container *ngIf=\"!descriptionTpl\">\n        <ng-container *ngIf=\"isNonEmptyString(description)\">\n          <p class=\"description\">{{ description }}</p>\n        </ng-container>\n        <ng-container *ngIf=\"isUndefined(description)\">\n          <p class=\"description\">{{ reasonModel.description | translate }}</p>\n        </ng-container>\n      </ng-container>\n\n      <div\n        class=\"operation\"\n        *ngIf=\"isTemplateRef(operation)\"\n      >\n        <ng-container [ngTemplateOutlet]=\"operation\"></ng-container>\n      </div>\n    </div>\n  </div>\n</ng-template>\n", styles: ["aui-card.unavailable ::ng-deep .aui-card{padding-top:120px;padding-bottom:200px;height:calc(100vh - 124px);min-height:600px}aui-card.unavailable.isFull ::ng-deep .aui-card{height:calc(100vh - 40px)}.acl-page-guard--pending,.acl-page-guard--unavailable{width:100%;height:100%;display:flex;justify-content:center;align-items:center}.acl-page-guard--unavailable .container{display:flex;flex-direction:column;align-items:center}.acl-page-guard--unavailable .container img{height:200px}.acl-page-guard--unavailable .container .title{margin:var(--aui-spacing-xxl) 0 var(--aui-spacing-l) 0;font-size:var(--aui-font-size-xl);color:rgb(var(--aui-color-n-1));font-weight:var(--aui-font-weight-bold)}.acl-page-guard--unavailable .container .description{color:rgb(var(--aui-color-n-4));font-size:var(--aui-font-size-m);text-align:center;max-width:560px;margin:0}.acl-page-guard--unavailable .container .operation{margin-top:var(--aui-spacing-l)}\n"] }]
    }], function () { return [{ type: i1.ThemeService }]; }, { top: [{
            type: Input
        }], isFull: [{
            type: Input
        }], allowed: [{
            type: Input
        }], status: [{
            type: Input
        }], reason: [{
            type: Input
        }], title: [{
            type: Input
        }], description: [{
            type: Input
        }], context: [{
            type: Input
        }], descriptionTpl: [{
            type: ContentChild,
            args: [PageGuardDescriptionDirective, { read: TemplateRef }]
        }], operation: [{
            type: ContentChild,
            args: [PageGuardOperationDirective, { read: TemplateRef }]
        }], template: [{
            type: ContentChild,
            args: [PageGuardContentDirective, { read: TemplateRef }]
        }] }); })();
//# sourceMappingURL=data:application/json;base64, 