import { __decorate, __metadata } from "tslib";
import { ChangeDetectionStrategy, Component, ContentChild, Directive, EventEmitter, Input, Output, QueryList, TemplateRef, ViewChildren, } from '@angular/core';
import { ValueHook } from '../../core/utils';
import { ConnectionStatus } from '../constants';
import { TerminalComponent } from '../terminal/component';
import * as i0 from "@angular/core";
function TerminalGroupComponent_aui_tab_group_0_aui_tab_1_div_1_aui_icon_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "aui-icon", 11);
    i0.ɵɵpipe(1, "translate");
} if (rf & 2) {
    i0.ɵɵproperty("auiTooltip", i0.ɵɵpipeBind1(1, 1, "exec_connecting"));
} }
const _c0 = function (a0) { return { index: a0 }; };
function TerminalGroupComponent_aui_tab_group_0_aui_tab_1_div_1_aui_icon_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "aui-icon", 12);
} if (rf & 2) {
    const i_r5 = i0.ɵɵnextContext(2).index;
    i0.ɵɵnextContext(2);
    const _r1 = i0.ɵɵreference(2);
    i0.ɵɵproperty("auiTooltip", _r1)("auiTooltipContext", i0.ɵɵpureFunction1(2, _c0, i_r5));
} }
function TerminalGroupComponent_aui_tab_group_0_aui_tab_1_div_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 7);
    i0.ɵɵtemplate(1, TerminalGroupComponent_aui_tab_group_0_aui_tab_1_div_1_aui_icon_1_Template, 2, 3, "aui-icon", 8);
    i0.ɵɵtemplate(2, TerminalGroupComponent_aui_tab_group_0_aui_tab_1_div_1_aui_icon_2_Template, 1, 4, "aui-icon", 9);
    i0.ɵɵelement(3, "acl-text-ellipsis", 10);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const option_r4 = i0.ɵɵnextContext().$implicit;
    const ctx_r6 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r6.statusMap.get(option_r4) === ctx_r6.ConnectionStatus.Connecting);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", ctx_r6.statusMap.get(option_r4) === ctx_r6.ConnectionStatus.Disconnected);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("text", option_r4.label || option_r4.pod)("tailLength", 6);
} }
function TerminalGroupComponent_aui_tab_group_0_aui_tab_1_Template(rf, ctx) { if (rf & 1) {
    const _r12 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "aui-tab", 4);
    i0.ɵɵlistener("close", function TerminalGroupComponent_aui_tab_group_0_aui_tab_1_Template_aui_tab_close_0_listener() { const restoredCtx = i0.ɵɵrestoreView(_r12); const i_r5 = restoredCtx.index; const ctx_r11 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r11.removeTerminal(i_r5)); });
    i0.ɵɵtemplate(1, TerminalGroupComponent_aui_tab_group_0_aui_tab_1_div_1_Template, 4, 4, "div", 5);
    i0.ɵɵelementStart(2, "acl-terminal", 6);
    i0.ɵɵlistener("connectionStatusChange", function TerminalGroupComponent_aui_tab_group_0_aui_tab_1_Template_acl_terminal_connectionStatusChange_2_listener($event) { const restoredCtx = i0.ɵɵrestoreView(_r12); const option_r4 = restoredCtx.$implicit; const ctx_r13 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r13.handleConnectionStatusChange(option_r4, $event)); })("socketReady", function TerminalGroupComponent_aui_tab_group_0_aui_tab_1_Template_acl_terminal_socketReady_2_listener($event) { const restoredCtx = i0.ɵɵrestoreView(_r12); const option_r4 = restoredCtx.$implicit; const i_r5 = restoredCtx.index; const ctx_r14 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r14.socketReady.emit({ option: option_r4, socket: $event, index: i_r5 })); })("fallbackShell", function TerminalGroupComponent_aui_tab_group_0_aui_tab_1_Template_acl_terminal_fallbackShell_2_listener($event) { const restoredCtx = i0.ɵɵrestoreView(_r12); const option_r4 = restoredCtx.$implicit; const ctx_r15 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r15.fallbackShell.emit({ option: option_r4, shell: $event })); });
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const option_r4 = ctx.$implicit;
    const i_r5 = ctx.index;
    const ctx_r3 = i0.ɵɵnextContext(2);
    i0.ɵɵproperty("closeable", true);
    i0.ɵɵadvance(2);
    i0.ɵɵproperty("option", option_r4)("index", i_r5)("extraContent", ctx_r3.terminalExtraContentRef);
} }
function TerminalGroupComponent_aui_tab_group_0_Template(rf, ctx) { if (rf & 1) {
    const _r17 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "aui-tab-group", 2);
    i0.ɵɵlistener("selectedIndexChange", function TerminalGroupComponent_aui_tab_group_0_Template_aui_tab_group_selectedIndexChange_0_listener($event) { i0.ɵɵrestoreView(_r17); const ctx_r16 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r16.selectedIndexChange.emit($event)); });
    i0.ɵɵtemplate(1, TerminalGroupComponent_aui_tab_group_0_aui_tab_1_Template, 3, 4, "aui-tab", 3);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵproperty("lazy", true)("selectedIndex", ctx_r0.selectedIndex);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngForOf", ctx_r0.terminalOptions)("ngForTrackBy", ctx_r0.trackByOption);
} }
function TerminalGroupComponent_ng_template_1_Template(rf, ctx) { if (rf & 1) {
    const _r20 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "span");
    i0.ɵɵtext(1);
    i0.ɵɵpipe(2, "translate");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(3, "button", 13);
    i0.ɵɵlistener("click", function TerminalGroupComponent_ng_template_1_Template_button_click_3_listener() { const restoredCtx = i0.ɵɵrestoreView(_r20); const i_r18 = restoredCtx.index; const ctx_r19 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r19.reconnect(i_r18)); });
    i0.ɵɵtext(4);
    i0.ɵɵpipe(5, "translate");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    i0.ɵɵadvance(1);
    i0.ɵɵtextInterpolate(i0.ɵɵpipeBind1(2, 2, "exec_disconnected_tip"));
    i0.ɵɵadvance(3);
    i0.ɵɵtextInterpolate1(" ", i0.ɵɵpipeBind1(5, 4, "reconnect"), " ");
} }
export class TerminalExtraContentDirective {
}
TerminalExtraContentDirective.ɵfac = function TerminalExtraContentDirective_Factory(t) { return new (t || TerminalExtraContentDirective)(); };
TerminalExtraContentDirective.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: TerminalExtraContentDirective, selectors: [["", "aclTerminalExtraContent", ""]] });
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(TerminalExtraContentDirective, [{
        type: Directive,
        args: [{
                selector: '[aclTerminalExtraContent]',
            }]
    }], null, null); })();
export class TerminalGroupComponent {
    constructor() {
        this.ConnectionStatus = ConnectionStatus;
        this.selectedIndex = 0;
        this.terminalOptions = [];
        this.selectedIndexChange = new EventEmitter();
        this.terminalOptionsChange = new EventEmitter();
        this.socketReady = new EventEmitter();
        this.fallbackShell = new EventEmitter();
        this.statusMap = new Map();
    }
    removeTerminal(index) {
        this.terminalOptionsChange.emit([
            ...this.terminalOptions.slice(0, index),
            ...this.terminalOptions.slice(index + 1),
        ]);
    }
    trackByOption(_, option) {
        return option;
    }
    handleConnectionStatusChange(option, status) {
        this.statusMap.set(option, status);
    }
    reconnect(index) {
        this.terminals.get(index).reconnect();
    }
}
TerminalGroupComponent.ɵfac = function TerminalGroupComponent_Factory(t) { return new (t || TerminalGroupComponent)(); };
TerminalGroupComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: TerminalGroupComponent, selectors: [["acl-terminal-group"]], contentQueries: function TerminalGroupComponent_ContentQueries(rf, ctx, dirIndex) { if (rf & 1) {
        i0.ɵɵcontentQuery(dirIndex, TerminalExtraContentDirective, 5, TemplateRef);
    } if (rf & 2) {
        let _t;
        i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.terminalExtraContentRef = _t.first);
    } }, viewQuery: function TerminalGroupComponent_Query(rf, ctx) { if (rf & 1) {
        i0.ɵɵviewQuery(TerminalComponent, 5);
    } if (rf & 2) {
        let _t;
        i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.terminals = _t);
    } }, inputs: { selectedIndex: "selectedIndex", terminalOptions: "terminalOptions" }, outputs: { selectedIndexChange: "selectedIndexChange", terminalOptionsChange: "terminalOptionsChange", socketReady: "socketReady", fallbackShell: "fallbackShell" }, decls: 3, vars: 1, consts: [["type", "card", 3, "lazy", "selectedIndex", "selectedIndexChange", 4, "ngIf"], ["disconnectedTip", ""], ["type", "card", 3, "lazy", "selectedIndex", "selectedIndexChange"], [3, "closeable", "close", 4, "ngFor", "ngForOf", "ngForTrackBy"], [3, "closeable", "close"], ["class", "tw-flex", 4, "auiTabLabel"], [3, "option", "index", "extraContent", "connectionStatusChange", "socketReady", "fallbackShell"], [1, "tw-flex"], ["class", "tw-mr-4 tw-icon-l tw-text-primary", "icon", "spinner", 3, "auiTooltip", 4, "ngIf"], ["class", "tw-mr-4 tw-icon-l tw-text-red", "icon", "exclamation_triangle_s", "background", "triangle", 3, "auiTooltip", "auiTooltipContext", 4, "ngIf"], [3, "text", "tailLength"], ["icon", "spinner", 1, "tw-mr-4", "tw-icon-l", "tw-text-primary", 3, "auiTooltip"], ["icon", "exclamation_triangle_s", "background", "triangle", 1, "tw-mr-4", "tw-icon-l", "tw-text-red", 3, "auiTooltip", "auiTooltipContext"], ["aui-button", "text", "size", "mini", 3, "click"]], template: function TerminalGroupComponent_Template(rf, ctx) { if (rf & 1) {
        i0.ɵɵtemplate(0, TerminalGroupComponent_aui_tab_group_0_Template, 2, 4, "aui-tab-group", 0);
        i0.ɵɵtemplate(1, TerminalGroupComponent_ng_template_1_Template, 6, 6, "ng-template", null, 1, i0.ɵɵtemplateRefExtractor);
    } if (rf & 2) {
        i0.ɵɵproperty("ngIf", ctx.terminalOptions == null ? null : ctx.terminalOptions.length);
    } }, styles: ["[_nghost-%COMP%]     aui-tab-body, [_nghost-%COMP%]     .aui-tab-body{display:block;width:100%;min-height:100%}[_nghost-%COMP%]    >aui-tab-group>.aui-tab-group .aui-tab-group__body-wrapper{display:flex;flex:1}[_nghost-%COMP%]     .aui-tab-body{display:flex}[_nghost-%COMP%]     .aui-tab-body__content{display:flex;flex-direction:column;flex:1}[_nghost-%COMP%]   acl-terminal[_ngcontent-%COMP%]{flex:1}"], changeDetection: 0 });
__decorate([
    ValueHook(function (index) {
        this.terminals?.get(index)?.focus();
    }),
    __metadata("design:type", Object)
], TerminalGroupComponent.prototype, "selectedIndex", void 0);
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(TerminalGroupComponent, [{
        type: Component,
        args: [{ selector: 'acl-terminal-group', changeDetection: ChangeDetectionStrategy.OnPush, template: "<aui-tab-group\n  *ngIf=\"terminalOptions?.length\"\n  type=\"card\"\n  [lazy]=\"true\"\n  [selectedIndex]=\"selectedIndex\"\n  (selectedIndexChange)=\"selectedIndexChange.emit($event)\"\n>\n  <aui-tab\n    *ngFor=\"\n      let option of terminalOptions;\n      let i = index;\n      trackBy: trackByOption\n    \"\n    [closeable]=\"true\"\n    (close)=\"removeTerminal(i)\"\n  >\n    <div\n      *auiTabLabel\n      class=\"tw-flex\"\n    >\n      <aui-icon\n        *ngIf=\"statusMap.get(option) === ConnectionStatus.Connecting\"\n        class=\"tw-mr-4 tw-icon-l tw-text-primary\"\n        icon=\"spinner\"\n        [auiTooltip]=\"'exec_connecting' | translate\"\n      ></aui-icon>\n      <aui-icon\n        *ngIf=\"statusMap.get(option) === ConnectionStatus.Disconnected\"\n        class=\"tw-mr-4 tw-icon-l tw-text-red\"\n        icon=\"exclamation_triangle_s\"\n        background=\"triangle\"\n        [auiTooltip]=\"disconnectedTip\"\n        [auiTooltipContext]=\"{ index: i }\"\n      ></aui-icon>\n      <acl-text-ellipsis\n        [text]=\"option.label || option.pod\"\n        [tailLength]=\"6\"\n      ></acl-text-ellipsis>\n    </div>\n    <acl-terminal\n      [option]=\"option\"\n      [index]=\"i\"\n      [extraContent]=\"terminalExtraContentRef\"\n      (connectionStatusChange)=\"handleConnectionStatusChange(option, $event)\"\n      (socketReady)=\"\n        socketReady.emit({\n          option,\n          socket: $event,\n          index: i\n        })\n      \"\n      (fallbackShell)=\"\n        fallbackShell.emit({\n          option,\n          shell: $event\n        })\n      \"\n    ></acl-terminal>\n  </aui-tab>\n</aui-tab-group>\n\n<ng-template\n  #disconnectedTip\n  let-i=\"index\"\n>\n  <span>{{ 'exec_disconnected_tip' | translate }}</span>\n  <button\n    aui-button=\"text\"\n    size=\"mini\"\n    (click)=\"reconnect(i)\"\n  >\n    {{ 'reconnect' | translate }}\n  </button>\n</ng-template>\n", styles: [":host ::ng-deep aui-tab-body,:host ::ng-deep .aui-tab-body{display:block;width:100%;min-height:100%}:host ::ng-deep>aui-tab-group>.aui-tab-group .aui-tab-group__body-wrapper{display:flex;flex:1}:host ::ng-deep .aui-tab-body{display:flex}:host ::ng-deep .aui-tab-body__content{display:flex;flex-direction:column;flex:1}:host acl-terminal{flex:1}\n"] }]
    }], null, { selectedIndex: [{
            type: Input
        }], terminalOptions: [{
            type: Input
        }], terminalExtraContentRef: [{
            type: ContentChild,
            args: [TerminalExtraContentDirective, {
                    read: TemplateRef,
                }]
        }], selectedIndexChange: [{
            type: Output
        }], terminalOptionsChange: [{
            type: Output
        }], socketReady: [{
            type: Output
        }], fallbackShell: [{
            type: Output
        }], terminals: [{
            type: ViewChildren,
            args: [TerminalComponent]
        }] }); })();
//# sourceMappingURL=data:application/json;base64, 