/**
 * @packageDocumentation
 * @module async-data
 */
import { handlePixel } from '@alauda/ui';
import { ChangeDetectionStrategy, Component, ContentChild, EventEmitter, Input, Output, TemplateRef, } from '@angular/core';
import { combineLatest, merge, filter, map, mapTo } from 'rxjs';
import { publishRef } from '../../core/public-api';
import * as i0 from "@angular/core";
function PageStateComponent_ng_container_0_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵelementContainer(1, 2);
    i0.ɵɵpipe(2, "async");
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngTemplateOutlet", ctx_r0.template)("ngTemplateOutletContext", i0.ɵɵpipeBind1(2, 2, ctx_r0.context$));
} }
function PageStateComponent_div_2_ng_container_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵelement(1, "acl-loading-mask", 4);
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("loading", true);
} }
function PageStateComponent_div_2_ng_container_3_Template(rf, ctx) { if (rf & 1) {
    const _r5 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵelementStart(1, "acl-error-state", 5);
    i0.ɵɵlistener("reload", function PageStateComponent_div_2_ng_container_3_Template_acl_error_state_reload_1_listener() { i0.ɵɵrestoreView(_r5); const ctx_r4 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r4.adapter.reload()); })("redirect", function PageStateComponent_div_2_ng_container_3_Template_acl_error_state_redirect_1_listener() { i0.ɵɵrestoreView(_r5); const ctx_r6 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r6.redirect.emit()); });
    i0.ɵɵpipe(2, "async");
    i0.ɵɵelementEnd();
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r3 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("errorCode", i0.ɵɵpipeBind1(2, 4, ctx_r3.errorCode$))("autoRedirect", ctx_r3.autoRedirect)("showBackButton", ctx_r3.showBackButton)("backLink", ctx_r3.backLink);
} }
function PageStateComponent_div_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 3);
    i0.ɵɵtemplate(1, PageStateComponent_div_2_ng_container_1_Template, 2, 1, "ng-container", 0);
    i0.ɵɵpipe(2, "async");
    i0.ɵɵtemplate(3, PageStateComponent_div_2_ng_container_3_Template, 3, 6, "ng-container", 0);
    i0.ɵɵpipe(4, "async");
    i0.ɵɵpipe(5, "async");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵstyleProp("margin-top", ctx_r1.marginTop);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", i0.ɵɵpipeBind1(2, 4, ctx_r1.adapter.loading$));
    i0.ɵɵadvance(2);
    i0.ɵɵproperty("ngIf", !i0.ɵɵpipeBind1(4, 6, ctx_r1.adapter.loading$) && !!i0.ɵɵpipeBind1(5, 8, ctx_r1.errorCode$));
} }
export class PageStateComponent {
    constructor() {
        this.autoRedirect = true;
        this.showBackButton = true;
        this.redirect = new EventEmitter();
    }
    set top(top) {
        this.marginTop = handlePixel(top ?? 120);
    }
    /** @ignore */
    ngOnInit() {
        this.context$ = this.adapter.rawData$.pipe(map(data => ({ $implicit: data, ...data })), publishRef());
        this.errorCode$ = merge(combineLatest([this.adapter.rawData$, this.adapter.loading$]).pipe(filter(([data, loading]) => !data && !loading), mapTo(404)), this.adapter.error$.pipe(filter(error => !!error), map(error => {
            if (error.code && typeof error.code === 'number') {
                return error.code;
            }
            if (error.status && typeof error.status === 'number') {
                return error.status;
            }
            return 1;
        }))).pipe(publishRef());
    }
}
PageStateComponent.ɵfac = function PageStateComponent_Factory(t) { return new (t || PageStateComponent)(); };
PageStateComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: PageStateComponent, selectors: [["acl-page-state"]], contentQueries: function PageStateComponent_ContentQueries(rf, ctx, dirIndex) { if (rf & 1) {
        i0.ɵɵcontentQuery(dirIndex, TemplateRef, 7);
    } if (rf & 2) {
        let _t;
        i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.template = _t.first);
    } }, inputs: { adapter: "adapter", autoRedirect: "autoRedirect", showBackButton: "showBackButton", backLink: "backLink", top: "top" }, outputs: { redirect: "redirect" }, decls: 4, vars: 6, consts: [[4, "ngIf"], ["class", "acl-data-state", 3, "marginTop", 4, "ngIf"], [3, "ngTemplateOutlet", "ngTemplateOutletContext"], [1, "acl-data-state"], ["type", "module", 3, "loading"], [3, "errorCode", "autoRedirect", "showBackButton", "backLink", "reload", "redirect"]], template: function PageStateComponent_Template(rf, ctx) { if (rf & 1) {
        i0.ɵɵtemplate(0, PageStateComponent_ng_container_0_Template, 3, 4, "ng-container", 0);
        i0.ɵɵpipe(1, "async");
        i0.ɵɵtemplate(2, PageStateComponent_div_2_Template, 6, 10, "div", 1);
        i0.ɵɵpipe(3, "async");
    } if (rf & 2) {
        let tmp_0_0;
        let tmp_1_0;
        i0.ɵɵproperty("ngIf", (tmp_0_0 = i0.ɵɵpipeBind1(1, 2, ctx.context$)) == null ? null : tmp_0_0.$implicit);
        i0.ɵɵadvance(2);
        i0.ɵɵproperty("ngIf", !((tmp_1_0 = i0.ɵɵpipeBind1(3, 4, ctx.context$)) == null ? null : tmp_1_0.$implicit));
    } }, encapsulation: 2, changeDetection: 0 });
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(PageStateComponent, [{
        type: Component,
        args: [{ selector: 'acl-page-state', changeDetection: ChangeDetectionStrategy.OnPush, template: "<ng-container *ngIf=\"(context$ | async)?.$implicit\">\n  <ng-container\n    [ngTemplateOutlet]=\"template\"\n    [ngTemplateOutletContext]=\"context$ | async\"\n  ></ng-container>\n</ng-container>\n\n<div\n  *ngIf=\"!(context$ | async)?.$implicit\"\n  class=\"acl-data-state\"\n  [style.marginTop]=\"marginTop\"\n>\n  <ng-container *ngIf=\"adapter.loading$ | async\">\n    <acl-loading-mask\n      [loading]=\"true\"\n      type=\"module\"\n    ></acl-loading-mask>\n  </ng-container>\n  <ng-container *ngIf=\"!(adapter.loading$ | async) && !!(errorCode$ | async)\">\n    <acl-error-state\n      [errorCode]=\"errorCode$ | async\"\n      [autoRedirect]=\"autoRedirect\"\n      [showBackButton]=\"showBackButton\"\n      [backLink]=\"backLink\"\n      (reload)=\"adapter.reload()\"\n      (redirect)=\"redirect.emit()\"\n    ></acl-error-state>\n  </ng-container>\n</div>\n" }]
    }], null, { adapter: [{
            type: Input
        }], autoRedirect: [{
            type: Input
        }], showBackButton: [{
            type: Input
        }], backLink: [{
            type: Input
        }], top: [{
            type: Input
        }], redirect: [{
            type: Output
        }], template: [{
            type: ContentChild,
            args: [TemplateRef, { static: true }]
        }] }); })();
//# sourceMappingURL=data:application/json;base64, 