import { __decorate, __metadata } from "tslib";
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { sortBy } from 'lodash-es';
import { BehaviorSubject, combineLatest, Observable, map } from 'rxjs';
import { ObservableInput } from '../../core/utils/decorators';
import { stringify, yamlFilterField } from '../../core/utils/yaml';
import { viewActions, yamlReadOptions } from '../code-editor-configs';
import * as i0 from "@angular/core";
function ResourceYamlDisplayComponent_aui_card_0_ng_container_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainer(0);
} }
function ResourceYamlDisplayComponent_aui_card_0_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "aui-card");
    i0.ɵɵtemplate(1, ResourceYamlDisplayComponent_aui_card_0_ng_container_1_Template, 1, 0, "ng-container", 2);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    i0.ɵɵnextContext();
    const _r1 = i0.ɵɵreference(2);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngTemplateOutlet", _r1);
} }
function ResourceYamlDisplayComponent_ng_template_1_Template(rf, ctx) { if (rf & 1) {
    const _r5 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "aui-code-editor", 3);
    i0.ɵɵpipe(1, "async");
    i0.ɵɵelementContainerStart(2, 4);
    i0.ɵɵelementStart(3, "aui-checkbox", 5);
    i0.ɵɵlistener("ngModelChange", function ResourceYamlDisplayComponent_ng_template_1_Template_aui_checkbox_ngModelChange_3_listener($event) { i0.ɵɵrestoreView(_r5); const ctx_r4 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r4.reduce$$.next($event)); });
    i0.ɵɵpipe(4, "async");
    i0.ɵɵtext(5);
    i0.ɵɵpipe(6, "translate");
    i0.ɵɵelementEnd();
    i0.ɵɵelementContainerEnd();
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r2 = i0.ɵɵnextContext();
    i0.ɵɵproperty("ngModel", i0.ɵɵpipeBind1(1, 5, ctx_r2.yaml$))("options", ctx_r2.editorOptions)("actionsConfig", ctx_r2.viewActions);
    i0.ɵɵadvance(3);
    i0.ɵɵproperty("ngModel", i0.ɵɵpipeBind1(4, 7, ctx_r2.reduce$$));
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate1(" ", i0.ɵɵpipeBind1(6, 9, "hide_managefields_field"), " ");
} }
export class ResourceYamlDisplayComponent {
    constructor() {
        this.reduce$$ = new BehaviorSubject(true);
        this.hasWrapper = true;
        this.yaml$ = combineLatest([this.resource$, this.reduce$$]).pipe(map(([resource, reduce]) => sortBy(Array.isArray(resource) ? resource : [resource], 'kind')
            .map((resource) => reduce
            ? yamlFilterField(resource, ['metadata.managedFields'])
            : resource)
            .map(res => stringify(res, {
            strict: false,
            sortMapEntries: true,
        }))
            .join('\n---\r\n\n')));
        this.editorOptions = yamlReadOptions;
        this.viewActions = viewActions;
    }
}
ResourceYamlDisplayComponent.ɵfac = function ResourceYamlDisplayComponent_Factory(t) { return new (t || ResourceYamlDisplayComponent)(); };
ResourceYamlDisplayComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: ResourceYamlDisplayComponent, selectors: [["acl-resource-yaml-display"]], inputs: { hasWrapper: "hasWrapper", resource: "resource" }, decls: 3, vars: 2, consts: [[4, "ngIf", "ngIfElse"], ["content", ""], [4, "ngTemplateOutlet"], ["name", "yaml", 3, "ngModel", "options", "actionsConfig"], ["auiCodeEditorToolbarLeft", ""], [1, "aui-code-editor-toolbar__control-button", 3, "ngModel", "ngModelChange"]], template: function ResourceYamlDisplayComponent_Template(rf, ctx) { if (rf & 1) {
        i0.ɵɵtemplate(0, ResourceYamlDisplayComponent_aui_card_0_Template, 2, 1, "aui-card", 0);
        i0.ɵɵtemplate(1, ResourceYamlDisplayComponent_ng_template_1_Template, 7, 11, "ng-template", null, 1, i0.ɵɵtemplateRefExtractor);
    } if (rf & 2) {
        const _r1 = i0.ɵɵreference(2);
        i0.ɵɵproperty("ngIf", ctx.hasWrapper)("ngIfElse", _r1);
    } }, styles: ["[_nghost-%COMP%]:not(.dialog-content){display:block;height:calc(100vh - 265px)}[_nghost-%COMP%]:not(.dialog-content)     .aui-code-editor{min-height:100%}[_nghost-%COMP%]:not(.dialog-content) > .aui-card[_ngcontent-%COMP%]{height:100%}[_nghost-%COMP%]:not(.dialog-content) > .aui-card[_ngcontent-%COMP%]   .aui-card__content[_ngcontent-%COMP%], [_nghost-%COMP%]:not(.dialog-content) > .aui-card[_ngcontent-%COMP%]   aui-code-editor[_ngcontent-%COMP%], [_nghost-%COMP%]:not(.dialog-content) > .aui-card[_ngcontent-%COMP%]   .aui-code-editor[_ngcontent-%COMP%]{height:100%;min-height:100%}[_nghost-%COMP%]{display:block}[_nghost-%COMP%]     aui-card, [_nghost-%COMP%]     .aui-card, [_nghost-%COMP%]     .aui-card__content{height:100%}[_nghost-%COMP%]   aui-code-editor[_ngcontent-%COMP%]{height:100%}"], changeDetection: 0 });
__decorate([
    ObservableInput(),
    __metadata("design:type", Observable)
], ResourceYamlDisplayComponent.prototype, "resource$", void 0);
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(ResourceYamlDisplayComponent, [{
        type: Component,
        args: [{ selector: 'acl-resource-yaml-display', template: `<aui-card *ngIf="hasWrapper; else content">
      <ng-container *ngTemplateOutlet="content"></ng-container>
    </aui-card>
    <ng-template #content
      ><aui-code-editor
        name="yaml"
        [ngModel]="yaml$ | async"
        [options]="editorOptions"
        [actionsConfig]="viewActions"
      >
        <ng-container auiCodeEditorToolbarLeft>
          <aui-checkbox
            class="aui-code-editor-toolbar__control-button"
            [ngModel]="reduce$$ | async"
            (ngModelChange)="reduce$$.next($event)"
          >
            {{ 'hide_managefields_field' | translate }}
          </aui-checkbox>
        </ng-container></aui-code-editor
      ></ng-template
    > `, preserveWhitespaces: false, changeDetection: ChangeDetectionStrategy.OnPush, styles: [":host(:not(.dialog-content)){display:block;height:calc(100vh - 265px)}:host(:not(.dialog-content)) ::ng-deep .aui-code-editor{min-height:100%}:host(:not(.dialog-content))>.aui-card{height:100%}:host(:not(.dialog-content))>.aui-card .aui-card__content,:host(:not(.dialog-content))>.aui-card aui-code-editor,:host(:not(.dialog-content))>.aui-card .aui-code-editor{height:100%;min-height:100%}:host{display:block}:host ::ng-deep aui-card,:host ::ng-deep .aui-card,:host ::ng-deep .aui-card__content{height:100%}:host aui-code-editor{height:100%}\n"] }]
    }], null, { hasWrapper: [{
            type: Input
        }], resource: [{
            type: Input
        }], resource$: [] }); })();
//# sourceMappingURL=data:application/json;base64, 