/**
 * @packageDocumentation
 * @module license
 */
import { ChangeDetectionStrategy, Component, Inject } from '@angular/core';
import { Router } from '@angular/router';
import { tap } from 'rxjs';
import { Reason } from '../../page-guard/public-api';
import { TranslateService } from '../../translate/public-api';
import { LICENSE_PRODUCT_NAME_TOKEN, LicenseService } from '../license.service';
import { LicenseStatus } from '../license.type';
import * as i0 from "@angular/core";
import * as i1 from "@angular/router";
import * as i2 from "../license.service";
import * as i3 from "../../translate/public-api";
function LicenseErrorComponent_ng_container_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵprojection(1);
    i0.ɵɵelementContainerEnd();
} }
function LicenseErrorComponent_div_2_ng_container_7_a_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "a", 6)(1, "button", 7);
    i0.ɵɵtext(2);
    i0.ɵɵpipe(3, "pure");
    i0.ɵɵpipe(4, "async");
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r3 = i0.ɵɵnextContext(3);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate1(" ", i0.ɵɵpipeBind3(3, 1, i0.ɵɵpipeBind1(4, 5, ctx_r3.errorStatus$), ctx_r3.getButtonText, ctx_r3.translate.locale), " ");
} }
function LicenseErrorComponent_div_2_ng_container_7_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵtemplate(1, LicenseErrorComponent_div_2_ng_container_7_a_1_Template, 5, 7, "a", 5);
    i0.ɵɵpipe(2, "pure");
    i0.ɵɵpipe(3, "async");
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r2 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", i0.ɵɵpipeBind2(2, 1, i0.ɵɵpipeBind1(3, 4, ctx_r2.errorStatus$), ctx_r2.shouldShowImport));
} }
function LicenseErrorComponent_div_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 2)(1, "acl-page-guard", 3);
    i0.ɵɵpipe(2, "translate");
    i0.ɵɵpipe(3, "pure");
    i0.ɵɵpipe(4, "async");
    i0.ɵɵpipe(5, "pure");
    i0.ɵɵpipe(6, "async");
    i0.ɵɵtemplate(7, LicenseErrorComponent_div_2_ng_container_7_Template, 4, 6, "ng-container", 4);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("allowed", false)("reason", ctx_r1.Reason.LicenseAbnormal)("title", i0.ɵɵpipeBind1(2, 4, i0.ɵɵpipeBind2(3, 6, i0.ɵɵpipeBind1(4, 9, ctx_r1.errorStatus$), ctx_r1.getErrorTitle)))("description", i0.ɵɵpipeBind3(5, 11, i0.ɵɵpipeBind1(6, 15, ctx_r1.errorStatus$), ctx_r1.getErrorContent, ctx_r1.translate.locale));
} }
const _c0 = ["*"];
const LICENSE_ERROR_TITLE_MAPPER = {
    expired: 'expired_license',
    no_permission: 'no_permission_license',
};
export class LicenseErrorComponent {
    constructor(router, licenseService, translate, productName) {
        this.router = router;
        this.licenseService = licenseService;
        this.translate = translate;
        this.productName = productName;
        this.Reason = Reason;
        this.errorStatus$ = this.licenseService.status$.pipe(
        // in case user input license-error url
        tap(status => {
            if (status === LicenseStatus.AUTHORIZED) {
                this.router.navigateByUrl('/');
            }
        }));
        this.LicenseStatus = LicenseStatus;
        this.getErrorContent = this.getErrorContent.bind(this);
        this.getButtonText = this.getButtonText.bind(this);
    }
    getErrorTitle(status) {
        return LICENSE_ERROR_TITLE_MAPPER[status];
    }
    getErrorContent(status, _locale) {
        return status === LicenseStatus.NO_PERMISSION
            ? this.translate.get('no_permission_license_hint')
            : status === LicenseStatus.UNAUTHORIZED
                ? this.translate.get('license_unauthorized_hint')
                : this.translate.get('license_error_hint', { product: this.productName });
    }
    shouldShowImport(status) {
        return status !== LicenseStatus.NO_PERMISSION;
    }
    getButtonText(status, _locale) {
        return this.translate.get(status === LicenseStatus.UNAUTHORIZED ? 'show_license' : 'import_now');
    }
}
LicenseErrorComponent.ɵfac = function LicenseErrorComponent_Factory(t) { return new (t || LicenseErrorComponent)(i0.ɵɵdirectiveInject(i1.Router), i0.ɵɵdirectiveInject(i2.LicenseService), i0.ɵɵdirectiveInject(i3.TranslateService), i0.ɵɵdirectiveInject(LICENSE_PRODUCT_NAME_TOKEN)); };
LicenseErrorComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: LicenseErrorComponent, selectors: [["acl-license-error"]], ngContentSelectors: _c0, decls: 3, vars: 0, consts: [[4, "aclPageHeader"], ["class", "layout-page-content", 4, "aclPageContent"], [1, "layout-page-content"], [3, "allowed", "reason", "title", "description"], [4, "aclPageGuardOperation"], ["href", "/console-platform/manage-platform/platform-setting/license", "target", "_blank", "noopener", "", "noreferrer", "", 4, "ngIf"], ["href", "/console-platform/manage-platform/platform-setting/license", "target", "_blank", "noopener", "", "noreferrer", ""], ["aui-button", "primary"]], template: function LicenseErrorComponent_Template(rf, ctx) { if (rf & 1) {
        i0.ɵɵprojectionDef();
        i0.ɵɵelementStart(0, "acl-page");
        i0.ɵɵtemplate(1, LicenseErrorComponent_ng_container_1_Template, 2, 0, "ng-container", 0);
        i0.ɵɵtemplate(2, LicenseErrorComponent_div_2_Template, 8, 17, "div", 1);
        i0.ɵɵelementEnd();
    } }, styles: [".layout-page-content[_ngcontent-%COMP%]{height:calc(100vh - 100px)}.error-page__wrapper[_ngcontent-%COMP%]{height:100%;display:flex;flex-direction:column;align-items:center}.error-page__wrapper[_ngcontent-%COMP%] > img[_ngcontent-%COMP%]{margin-top:102px;width:160px;height:160px}.error-page__title[_ngcontent-%COMP%]{font-size:18px;margin-top:16px}.error-page__content[_ngcontent-%COMP%]{color:rgb(var(--aui-color-help-text));margin-top:8px;margin-bottom:16px}"], changeDetection: 0 });
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(LicenseErrorComponent, [{
        type: Component,
        args: [{ selector: 'acl-license-error', changeDetection: ChangeDetectionStrategy.OnPush, template: "<acl-page>\n  <ng-container *aclPageHeader>\n    <ng-content></ng-content>\n  </ng-container>\n  <div\n    *aclPageContent\n    class=\"layout-page-content\"\n  >\n    <acl-page-guard\n      [allowed]=\"false\"\n      [reason]=\"Reason.LicenseAbnormal\"\n      [title]=\"errorStatus$ | async | pure: getErrorTitle | translate\"\n      [description]=\"\n        errorStatus$ | async | pure: getErrorContent:translate.locale\n      \"\n    >\n      <ng-container *aclPageGuardOperation>\n        <a\n          href=\"/console-platform/manage-platform/platform-setting/license\"\n          target=\"_blank\"\n          *ngIf=\"errorStatus$ | async | pure: shouldShowImport\"\n          noopener\n          noreferrer\n        >\n          <button aui-button=\"primary\">\n            {{ errorStatus$ | async | pure: getButtonText:translate.locale }}\n          </button>\n        </a>\n      </ng-container>\n    </acl-page-guard>\n  </div>\n</acl-page>\n", styles: [".layout-page-content{height:calc(100vh - 100px)}.error-page__wrapper{height:100%;display:flex;flex-direction:column;align-items:center}.error-page__wrapper>img{margin-top:102px;width:160px;height:160px}.error-page__title{font-size:18px;margin-top:16px}.error-page__content{color:rgb(var(--aui-color-help-text));margin-top:8px;margin-bottom:16px}\n"] }]
    }], function () { return [{ type: i1.Router }, { type: i2.LicenseService }, { type: i3.TranslateService }, { type: undefined, decorators: [{
                type: Inject,
                args: [LICENSE_PRODUCT_NAME_TOKEN]
            }] }]; }, null); })();
//# sourceMappingURL=data:application/json;base64, 