import { DIALOG_DATA, DialogRef, MessageService, NotificationService, } from '@alauda/ui';
import { ChangeDetectionStrategy, Component, ContentChild, Directive, EventEmitter, Inject, Input, Optional, Output, TemplateRef, } from '@angular/core';
import { get } from 'lodash-es';
import { BehaviorSubject, combineLatest, from, Subject, finalize, map, takeUntil, } from 'rxjs';
import { errorColor } from '../../core/utils';
import * as i0 from "@angular/core";
import * as i1 from "@alauda/ui";
function ConfirmDeleteComponent_ng_container_6_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵtext(1);
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate(ctx_r0.deleteTips);
} }
function ConfirmDeleteComponent_ng_container_7_ng_container_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainer(0);
} }
function ConfirmDeleteComponent_ng_container_7_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵtemplate(1, ConfirmDeleteComponent_ng_container_7_ng_container_1_Template, 1, 0, "ng-container", 8);
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngTemplateOutlet", ctx_r1.deleteTipTemplate);
} }
function ConfirmDeleteComponent_ng_container_8_ng_container_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainer(0);
} }
function ConfirmDeleteComponent_ng_container_8_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵtemplate(1, ConfirmDeleteComponent_ng_container_8_ng_container_1_Template, 1, 0, "ng-container", 8);
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r2 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngTemplateOutlet", ctx_r2.contentTemplate);
} }
function ConfirmDeleteComponent_ng_container_10_ng_container_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainer(0);
} }
function ConfirmDeleteComponent_ng_container_10_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵtemplate(1, ConfirmDeleteComponent_ng_container_10_ng_container_1_Template, 1, 0, "ng-container", 8);
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r3 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngTemplateOutlet", ctx_r3.labelTemplate);
} }
function ConfirmDeleteComponent_ng_container_11_ng_container_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵtext(1);
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r8 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate1(" ", ctx_r8.confirmTips, " ");
} }
function ConfirmDeleteComponent_ng_container_11_ng_container_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵtext(1);
    i0.ɵɵpipe(2, "translate");
    i0.ɵɵelementStart(3, "span", 9);
    i0.ɵɵtext(4);
    i0.ɵɵelementEnd();
    i0.ɵɵtext(5);
    i0.ɵɵpipe(6, "translate");
    i0.ɵɵpipe(7, "translate");
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r9 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate1(" ", i0.ɵɵpipeBind1(2, 5, "please_enter"), " ");
    i0.ɵɵadvance(3);
    i0.ɵɵtextInterpolate(ctx_r9.resourceName);
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate3(" ", i0.ɵɵpipeBind1(6, 7, "determine_" + ctx_r9.type), "", ctx_r9.extraConfirmTips ? i0.ɵɵpipeBind1(7, 9, "period_symbol") : null, "", ctx_r9.extraConfirmTips, " ");
} }
function ConfirmDeleteComponent_ng_container_11_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵtemplate(1, ConfirmDeleteComponent_ng_container_11_ng_container_1_Template, 2, 1, "ng-container", 3);
    i0.ɵɵtemplate(2, ConfirmDeleteComponent_ng_container_11_ng_container_2_Template, 8, 11, "ng-container", 3);
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r4 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r4.confirmTips);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", !ctx_r4.confirmTips);
} }
export const DeleteType = {
    DELETE: 'delete',
    UNINSTALL: 'uninstall',
    QUIT: 'quit',
    UNBIND: 'unbind',
    UNMOUNT: 'unmount',
};
export class ConfirmDeleteTipDirective {
    constructor(templateRef) {
        this.templateRef = templateRef;
    }
}
ConfirmDeleteTipDirective.ɵfac = function ConfirmDeleteTipDirective_Factory(t) { return new (t || ConfirmDeleteTipDirective)(i0.ɵɵdirectiveInject(i0.TemplateRef)); };
ConfirmDeleteTipDirective.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: ConfirmDeleteTipDirective, selectors: [["", "aclConfirmDeleteTip", ""]] });
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(ConfirmDeleteTipDirective, [{
        type: Directive,
        args: [{
                selector: '[aclConfirmDeleteTip]',
            }]
    }], function () { return [{ type: i0.TemplateRef }]; }, null); })();
export class ConfirmDeleteContentDirective {
    constructor(templateRef) {
        this.templateRef = templateRef;
    }
}
ConfirmDeleteContentDirective.ɵfac = function ConfirmDeleteContentDirective_Factory(t) { return new (t || ConfirmDeleteContentDirective)(i0.ɵɵdirectiveInject(i0.TemplateRef)); };
ConfirmDeleteContentDirective.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: ConfirmDeleteContentDirective, selectors: [["", "aclConfirmDeleteContent", ""]] });
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(ConfirmDeleteContentDirective, [{
        type: Directive,
        args: [{
                selector: '[aclConfirmDeleteContent]',
            }]
    }], function () { return [{ type: i0.TemplateRef }]; }, null); })();
export class ConfirmDeleteLabelDirective {
    constructor(templateRef) {
        this.templateRef = templateRef;
    }
}
ConfirmDeleteLabelDirective.ɵfac = function ConfirmDeleteLabelDirective_Factory(t) { return new (t || ConfirmDeleteLabelDirective)(i0.ɵɵdirectiveInject(i0.TemplateRef)); };
ConfirmDeleteLabelDirective.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: ConfirmDeleteLabelDirective, selectors: [["", "aclConfirmDeleteLabel", ""]] });
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(ConfirmDeleteLabelDirective, [{
        type: Directive,
        args: [{
                selector: '[aclConfirmDeleteLabel]',
            }]
    }], function () { return [{ type: i0.TemplateRef }]; }, null); })();
export class ConfirmDeleteComponent {
    constructor(message, notification, dialogRef, data) {
        this.message = message;
        this.notification = notification;
        this.dialogRef = dialogRef;
        this.data = data;
        this.type = DeleteType.DELETE;
        // eslint-disable-next-line @angular-eslint/no-output-native
        this.close = new EventEmitter();
        this.inputValue = '';
        this.inputValue$$ = new BehaviorSubject(this.inputValue);
        this.deleting$$ = new BehaviorSubject(false);
        this.disabled$ = combineLatest([this.inputValue$$, this.deleting$$]).pipe(map(([inputValue, deleting]) => {
            const { resourceName } = this;
            return (deleting ||
                !(Array.isArray(resourceName)
                    ? resourceName.includes(inputValue)
                    : inputValue === resourceName));
        }));
        this.destroy$$ = new Subject();
        this.errorColor = errorColor;
        this.resolveData();
    }
    ngOnDestroy() {
        this.destroy$$.next();
        this.destroy$$.complete();
    }
    onConfirm() {
        this.deleting$$.next(true);
        const completed$$ = new Subject();
        from(this.deleteResourceApi.call(this.context, this.inputValue, this.deleteResourceParams))
            .pipe(finalize(() => this.deleting$$.next(false)), takeUntil(completed$$), takeUntil(this.destroy$$))
            .subscribe({
            next: result => {
                if (this.deleteSuccessMsg) {
                    this.message.success(this.deleteSuccessMsg);
                }
                this.closeDialog(result);
                completed$$.next();
            },
            error: (e) => {
                if (this.deleteFailMsg) {
                    this.notification.error({
                        title: this.deleteFailMsg,
                        content: get(e.error, 'message', e.message),
                    });
                }
                completed$$.next();
            },
        });
    }
    closeDialog(result) {
        if (this.dialogRef) {
            this.dialogRef.close(result);
        }
        else {
            this.close.emit(result);
        }
    }
    resolveData() {
        if (!this.data) {
            return;
        }
        Object.entries(this.data).forEach(([key, value]) => {
            if (value != null) {
                this[key] = value;
            }
        });
    }
}
ConfirmDeleteComponent.ɵfac = function ConfirmDeleteComponent_Factory(t) { return new (t || ConfirmDeleteComponent)(i0.ɵɵdirectiveInject(i1.MessageService), i0.ɵɵdirectiveInject(i1.NotificationService), i0.ɵɵdirectiveInject(i1.DialogRef, 8), i0.ɵɵdirectiveInject(DIALOG_DATA, 8)); };
ConfirmDeleteComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: ConfirmDeleteComponent, selectors: [["acl-confirm-delete"]], contentQueries: function ConfirmDeleteComponent_ContentQueries(rf, ctx, dirIndex) { if (rf & 1) {
        i0.ɵɵcontentQuery(dirIndex, ConfirmDeleteTipDirective, 5, TemplateRef);
        i0.ɵɵcontentQuery(dirIndex, ConfirmDeleteContentDirective, 5, TemplateRef);
        i0.ɵɵcontentQuery(dirIndex, ConfirmDeleteLabelDirective, 5, TemplateRef);
    } if (rf & 2) {
        let _t;
        i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.deleteTipTemplate = _t.first);
        i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.contentTemplate = _t.first);
        i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.labelTemplate = _t.first);
    } }, inputs: { context: "context", type: "type", title: "title", resourceName: "resourceName", deleteTips: "deleteTips", confirmTips: "confirmTips", extraConfirmTips: "extraConfirmTips", confirmText: "confirmText", deleteResourceApi: "deleteResourceApi", deleteResourceParams: "deleteResourceParams", deleteSuccessMsg: "deleteSuccessMsg", deleteFailMsg: "deleteFailMsg" }, outputs: { close: "close" }, decls: 22, vars: 19, consts: [[3, "ngSubmit"], ["icon", "exclamation_triangle_s", "background", "triangle", "size", "22", "color", "errorColor"], [1, "confirm-delete__tips"], [4, "ngIf"], [1, "confirm-delete__label"], ["auiFormItemControl", "", "aui-input", "", "name", "resource-name", 3, "ngModel", "ngModelChange"], ["aui-button", "danger", 3, "loading", "disabled"], ["aui-button", "", "type", "button", 3, "click"], [4, "ngTemplateOutlet"], [1, "name"]], template: function ConfirmDeleteComponent_Template(rf, ctx) { if (rf & 1) {
        i0.ɵɵelementStart(0, "form", 0);
        i0.ɵɵlistener("ngSubmit", function ConfirmDeleteComponent_Template_form_ngSubmit_0_listener() { return ctx.onConfirm(); });
        i0.ɵɵelementStart(1, "aui-dialog-header");
        i0.ɵɵelement(2, "aui-icon", 1);
        i0.ɵɵtext(3);
        i0.ɵɵelementEnd();
        i0.ɵɵelementStart(4, "aui-dialog-content")(5, "p", 2);
        i0.ɵɵtemplate(6, ConfirmDeleteComponent_ng_container_6_Template, 2, 1, "ng-container", 3);
        i0.ɵɵtemplate(7, ConfirmDeleteComponent_ng_container_7_Template, 2, 1, "ng-container", 3);
        i0.ɵɵelementEnd();
        i0.ɵɵtemplate(8, ConfirmDeleteComponent_ng_container_8_Template, 2, 1, "ng-container", 3);
        i0.ɵɵelementStart(9, "div", 4);
        i0.ɵɵtemplate(10, ConfirmDeleteComponent_ng_container_10_Template, 2, 1, "ng-container", 3);
        i0.ɵɵtemplate(11, ConfirmDeleteComponent_ng_container_11_Template, 3, 2, "ng-container", 3);
        i0.ɵɵelementEnd();
        i0.ɵɵelementStart(12, "input", 5);
        i0.ɵɵlistener("ngModelChange", function ConfirmDeleteComponent_Template_input_ngModelChange_12_listener($event) { return ctx.inputValue = $event; })("ngModelChange", function ConfirmDeleteComponent_Template_input_ngModelChange_12_listener($event) { return ctx.inputValue$$.next($event); });
        i0.ɵɵelementEnd()();
        i0.ɵɵelementStart(13, "aui-dialog-footer")(14, "button", 6);
        i0.ɵɵpipe(15, "async");
        i0.ɵɵpipe(16, "async");
        i0.ɵɵtext(17);
        i0.ɵɵpipe(18, "translate");
        i0.ɵɵelementEnd();
        i0.ɵɵelementStart(19, "button", 7);
        i0.ɵɵlistener("click", function ConfirmDeleteComponent_Template_button_click_19_listener() { return ctx.closeDialog(); });
        i0.ɵɵtext(20);
        i0.ɵɵpipe(21, "translate");
        i0.ɵɵelementEnd()()();
    } if (rf & 2) {
        i0.ɵɵadvance(3);
        i0.ɵɵtextInterpolate1(" ", ctx.title, " ");
        i0.ɵɵadvance(3);
        i0.ɵɵproperty("ngIf", ctx.deleteTips);
        i0.ɵɵadvance(1);
        i0.ɵɵproperty("ngIf", ctx.deleteTipTemplate);
        i0.ɵɵadvance(1);
        i0.ɵɵproperty("ngIf", ctx.contentTemplate);
        i0.ɵɵadvance(2);
        i0.ɵɵproperty("ngIf", ctx.labelTemplate);
        i0.ɵɵadvance(1);
        i0.ɵɵproperty("ngIf", !ctx.labelTemplate);
        i0.ɵɵadvance(1);
        i0.ɵɵproperty("ngModel", ctx.inputValue);
        i0.ɵɵadvance(2);
        i0.ɵɵproperty("loading", i0.ɵɵpipeBind1(15, 11, ctx.deleting$$))("disabled", i0.ɵɵpipeBind1(16, 13, ctx.disabled$));
        i0.ɵɵadvance(3);
        i0.ɵɵtextInterpolate1(" ", i0.ɵɵpipeBind1(18, 15, ctx.confirmText || ctx.type), " ");
        i0.ɵɵadvance(3);
        i0.ɵɵtextInterpolate1(" ", i0.ɵɵpipeBind1(21, 17, "cancel"), " ");
    } }, styles: [".confirm-delete__tips[_ngcontent-%COMP%]{margin-top:0;margin-bottom:12px;color:rgb(var(--aui-color-main-text));word-break:break-all}.confirm-delete__label[_ngcontent-%COMP%]{margin-bottom:4px;word-break:break-all;color:rgb(var(--aui-color-main-text))}.confirm-delete__label[_ngcontent-%COMP%]   .name[_ngcontent-%COMP%]{color:rgb(var(--aui-color-red))}"], changeDetection: 0 });
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(ConfirmDeleteComponent, [{
        type: Component,
        args: [{ selector: 'acl-confirm-delete', preserveWhitespaces: false, changeDetection: ChangeDetectionStrategy.OnPush, template: "<form (ngSubmit)=\"onConfirm()\">\n  <aui-dialog-header>\n    <aui-icon\n      icon=\"exclamation_triangle_s\"\n      background=\"triangle\"\n      size=\"22\"\n      color=\"errorColor\"\n    ></aui-icon>\n    {{ title }}\n  </aui-dialog-header>\n  <aui-dialog-content>\n    <p class=\"confirm-delete__tips\">\n      <ng-container *ngIf=\"deleteTips\">{{ deleteTips }}</ng-container>\n      <ng-container *ngIf=\"deleteTipTemplate\">\n        <ng-container *ngTemplateOutlet=\"deleteTipTemplate\"></ng-container>\n      </ng-container>\n    </p>\n    <ng-container *ngIf=\"contentTemplate\">\n      <ng-container *ngTemplateOutlet=\"contentTemplate\"></ng-container>\n    </ng-container>\n    <div class=\"confirm-delete__label\">\n      <ng-container *ngIf=\"labelTemplate\">\n        <ng-container *ngTemplateOutlet=\"labelTemplate\"></ng-container>\n      </ng-container>\n      <ng-container *ngIf=\"!labelTemplate\">\n        <ng-container *ngIf=\"confirmTips\">\n          {{ confirmTips }}\n        </ng-container>\n        <ng-container *ngIf=\"!confirmTips\">\n          {{ 'please_enter' | translate }}\n          <span class=\"name\">{{ resourceName }}</span>\n          {{ 'determine_' + type | translate\n          }}{{ extraConfirmTips ? ('period_symbol' | translate) : null\n          }}{{ extraConfirmTips }}\n        </ng-container>\n      </ng-container>\n    </div>\n    <input\n      auiFormItemControl\n      aui-input\n      name=\"resource-name\"\n      [(ngModel)]=\"inputValue\"\n      (ngModelChange)=\"inputValue$$.next($event)\"\n    />\n  </aui-dialog-content>\n  <aui-dialog-footer>\n    <button\n      aui-button=\"danger\"\n      [loading]=\"deleting$$ | async\"\n      [disabled]=\"disabled$ | async\"\n    >\n      {{ confirmText || type | translate }}\n    </button>\n    <button\n      aui-button\n      type=\"button\"\n      (click)=\"closeDialog()\"\n    >\n      {{ 'cancel' | translate }}\n    </button>\n  </aui-dialog-footer>\n</form>\n", styles: [".confirm-delete__tips{margin-top:0;margin-bottom:12px;color:rgb(var(--aui-color-main-text));word-break:break-all}.confirm-delete__label{margin-bottom:4px;word-break:break-all;color:rgb(var(--aui-color-main-text))}.confirm-delete__label .name{color:rgb(var(--aui-color-red))}\n"] }]
    }], function () { return [{ type: i1.MessageService }, { type: i1.NotificationService }, { type: i1.DialogRef, decorators: [{
                type: Optional
            }] }, { type: undefined, decorators: [{
                type: Optional
            }, {
                type: Inject,
                args: [DIALOG_DATA]
            }] }]; }, { context: [{
            type: Input
        }], type: [{
            type: Input
        }], title: [{
            type: Input
        }], resourceName: [{
            type: Input
        }], deleteTips: [{
            type: Input
        }], confirmTips: [{
            type: Input
        }], extraConfirmTips: [{
            type: Input
        }], confirmText: [{
            type: Input
        }], deleteResourceApi: [{
            type: Input
        }], deleteResourceParams: [{
            type: Input
        }], deleteSuccessMsg: [{
            type: Input
        }], deleteFailMsg: [{
            type: Input
        }], 
    // eslint-disable-next-line @angular-eslint/no-output-native
    close: [{
            type: Output
        }], deleteTipTemplate: [{
            type: ContentChild,
            args: [ConfirmDeleteTipDirective, {
                    read: TemplateRef,
                }]
        }], contentTemplate: [{
            type: ContentChild,
            args: [ConfirmDeleteContentDirective, {
                    read: TemplateRef,
                }]
        }], labelTemplate: [{
            type: ContentChild,
            args: [ConfirmDeleteLabelDirective, {
                    read: TemplateRef,
                }]
        }] }); })();
//# sourceMappingURL=data:application/json;base64, 