import { proxyCustomElement, HTMLElement, h, Fragment, Host } from '@stencil/core/internal/client';
import { g as getIconPath } from './mer-animated-dots.js';
import 'lit';
import 'lit/directives/when.js';
import 'lit/directives/if-defined.js';
import { L as Locale } from './locale.js';
import { d as defineCustomElement$2 } from './gx-ide-empty-state2.js';

const teamDevPreviewCss = ":host{display:grid;block-size:100%}.opacity-0{opacity:0}.gxi-hidden{display:none !important}.align-center{display:flex;align-items:center}.align-end{display:flex;align-items:end}.overflow-auto{overflow:auto}:host(.gx-ide-component){height:100% !important;display:flex !important;flex-direction:column !important}.gx-ide-main-wrapper{color:var(--gx-ide-component-text-color);font-weight:var(--font-style-regular);font-size:var(--font-size-body-m);font-family:var(--font-family-body);height:100%;display:flex;flex-direction:column;flex-grow:1;box-sizing:border-box}.buttons-container{display:flex;gap:var(--spacing-gap-m)}.giu-static-pill-icon-and-text,.giu-static-pill{background-color:var(--elevation-background-color, var(--color-accent-surface-elevation-1));padding-inline:var(--spacing-padding-m);color:var(--color-text-neutral-default);font-size:var(--font-size-body-s);line-height:var(--line-height-relaxed);font-weight:var(--font-style-regular);border-radius:4px;min-block-size:25px;display:inline-grid;align-items:center;pointer-events:none;inline-size:max-content}.giu-static-pill-icon-and-text{display:inline-grid;grid-auto-flow:column;grid-auto-columns:max-content;gap:var(--spacing-gap-m)}.tab-full-width-buttons::part(tab-list block-start),.tab-full-width-buttons::part(tab-list block-end){grid-auto-columns:1fr}.tab-full-width-buttons::part(tab block-start){justify-content:center}.tree-view::part(item__header){--icon__system_warning_warning--disabled:var(\n    --icon__system_warning_warning--enabled\n  )}.tabular-grid{--focus-outline-width:1px}:host{display:grid;block-size:100%}.main-container{display:grid;gap:var(--spacing-gap-xl);grid-template-rows:max-content 1fr max-content;overflow:auto}.main-container .local-changes-container{display:grid;gap:var(--spacing-gap-m);grid-template-rows:max-content max-content max-content 1fr;padding-inline:0}.main-container .remote-changes-container{display:grid;gap:var(--spacing-gap-m);grid-template-rows:max-content max-content 1fr;padding-inline:0}.dialog-footer-with-border.open-window-container{--dialog-footer-justify-content:flex-start}.loader-icon{animation:spin 1s linear infinite}@keyframes spin{100%{transform:rotate(360deg)}}.empty-state{overflow:hidden}.giu-static-pill-icon-and-text{background-color:var(--color-accent-surface-elevation-2)}.tab{overflow:auto;row-gap:var(--spacing-gap-m)}.tab.border-style-none{border-style:none}.empty-state-button{inline-size:100%;max-inline-size:300px}.button-tertiary.team-dev-button{text-decoration:underline;color:var(--color-text-neutral-default)}.button-tertiary.refresh-button,.button-tertiary.open-full-dialog-button{justify-self:start}.commit-message-textarea{block-size:65px}.empty-state-container{display:grid;gap:var(--spacing-gap-m);grid-template-rows:max-content max-content}ch-tree-view-render::part(change-item item__header){padding-inline-start:0}ch-tree-view-render::part(root-item item__header){padding-inline-start:0;font-weight:var(--font-style-semi-bold);font-size:var(--font-size-body-s);line-height:var(--line-height-tight)}.version-pill{overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.giu-static-pill-icon-and-text.version{grid-auto-columns:unset}";

var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
    if (kind === "a" && !f)
        throw new TypeError("Private accessor was defined without a getter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
        throw new TypeError("Cannot read private member from an object whose class did not declare it");
    return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
    if (kind === "m")
        throw new TypeError("Private method is not writable");
    if (kind === "a" && !f)
        throw new TypeError("Private accessor was defined without a setter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
        throw new TypeError("Cannot write private member to an object whose class did not declare it");
    return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var _GxIdeTeamDevPreview_componentLocale, _GxIdeTeamDevPreview_isPendingReloadLocalChanges, _GxIdeTeamDevPreview_isPendingReloadRemoteChanges, _GxIdeTeamDevPreview_commitData, _GxIdeTeamDevPreview_updateData, _GxIdeTeamDevPreview_prevVersionName, _GxIdeTeamDevPreview_isTeamDevOptionsEnabled, _GxIdeTeamDevPreview_emptyStateConfig, _GxIdeTeamDevPreview_localChangesTreeEL, _GxIdeTeamDevPreview_remoteChangesTreeEL, _GxIdeTeamDevPreview_setEmptyStateConfig, _GxIdeTeamDevPreview_setTeamDevOptionsStatus, _GxIdeTeamDevPreview_loadChanges, _GxIdeTeamDevPreview_convertDataToTreeView, _GxIdeTeamDevPreview_checkedItemsChangeHandler, _GxIdeTeamDevPreview_shareKBToServerHandler, _GxIdeTeamDevPreview_createKBFromServerHandler, _GxIdeTeamDevPreview_openFullDialogHandler, _GxIdeTeamDevPreview_commitChangesHandler, _GxIdeTeamDevPreview_commitMessageInputHandler, _GxIdeTeamDevPreview_updateRemoteChangesHandler, _GxIdeTeamDevPreview_tabSelectionChangedHandler, _GxIdeTeamDevPreview_openTeamDevInfoHandler, _GxIdeTeamDevPreview_reconnectHandler, _GxIdeTeamDevPreview_renderIcon, _GxIdeTeamDevPreview_disableConfirmButton, _GxIdeTeamDevPreview_updateTabModel, _GxIdeTeamDevPreview_getEmptyStateTitle, _GxIdeTeamDevPreview_getEmptyStateDescription, _GxIdeTeamDevPreview_getEmptyStateButtonText, _GxIdeTeamDevPreview_getEmptyStateButtonHandler, _GxIdeTeamDevPreview_renderEmptyStateButton, _GxIdeTeamDevPreview_renderReloadChangesButton, _GxIdeTeamDevPreview_renderEmptyState, _GxIdeTeamDevPreview_renderTreeChanges, _GxIdeTeamDevPreview_renderConfirmButton, _GxIdeTeamDevPreview_renderLocalChanges, _GxIdeTeamDevPreview_renderRemoteChanges;
var TeamDevEmptyState;
(function (TeamDevEmptyState) {
    TeamDevEmptyState[TeamDevEmptyState["NoKBOpen"] = 0] = "NoKBOpen";
    TeamDevEmptyState[TeamDevEmptyState["NoConnectedKB"] = 1] = "NoConnectedKB";
    TeamDevEmptyState[TeamDevEmptyState["NoConnectedGXServer"] = 2] = "NoConnectedGXServer";
    TeamDevEmptyState[TeamDevEmptyState["NoLinkedVersion"] = 3] = "NoLinkedVersion";
    TeamDevEmptyState[TeamDevEmptyState["FrozenVersion"] = 4] = "FrozenVersion";
    TeamDevEmptyState[TeamDevEmptyState["None"] = 5] = "None";
})(TeamDevEmptyState || (TeamDevEmptyState = {}));
const CSS_BUNDLES = [
    "resets/box-sizing",
    "utils/form--full",
    "utils/layout",
    "utils/typography",
    "utils/spacing",
    "chameleon/scrollbar",
    "components/tree-view",
    "components/tab"
];
const VERSION_ICON = getIconPath({
    category: "system",
    name: "version",
    colorType: "on-surface"
});
const ADD_ICON = getIconPath({
    category: "system",
    name: "add",
    colorType: "success"
});
const EDITED_ICON = getIconPath({
    category: "system",
    name: "edit",
    colorType: "warning"
});
const SUBTRACT_ICON = getIconPath({
    category: "system",
    name: "substract",
    colorType: "error"
});
const REFRESH_ICON = getIconPath({
    category: "system",
    name: "refresh",
    colorType: "primary"
});
const WARNING_ICON = getIconPath({
    category: "system",
    name: "warning",
    colorType: "warning"
});
const OPEN_WINDOW_ICON = getIconPath({
    category: "gemini-tools",
    name: "open-window",
    colorType: "on-surface"
});
const LOADER_ICON = getIconPath({
    category: "system",
    name: "loading",
    colorType: "primary"
});
const ERROR_ICON = getIconPath({
    category: "system",
    name: "error",
    colorType: "on-surface"
});
const REMOTE_CHANGES_TAB = "remote-changes-tab";
const LOCAL_CHANGES_TAB = "local-changes-tab";
const GxIdeTeamDevPreview$1 = /*@__PURE__*/ proxyCustomElement(class GxIdeTeamDevPreview extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        this.__attachShadow();
        _GxIdeTeamDevPreview_componentLocale.set(this, void 0);
        _GxIdeTeamDevPreview_isPendingReloadLocalChanges.set(this, false);
        _GxIdeTeamDevPreview_isPendingReloadRemoteChanges.set(this, false);
        _GxIdeTeamDevPreview_commitData.set(this, void 0);
        _GxIdeTeamDevPreview_updateData.set(this, void 0);
        _GxIdeTeamDevPreview_prevVersionName.set(this, void 0);
        _GxIdeTeamDevPreview_isTeamDevOptionsEnabled.set(this, false);
        _GxIdeTeamDevPreview_emptyStateConfig.set(this, {});
        _GxIdeTeamDevPreview_localChangesTreeEL.set(this, void 0);
        _GxIdeTeamDevPreview_remoteChangesTreeEL.set(this, void 0);
        _GxIdeTeamDevPreview_setEmptyStateConfig.set(this, () => {
            __classPrivateFieldSet(this, _GxIdeTeamDevPreview_emptyStateConfig, {
                [TeamDevEmptyState.NoKBOpen]: {
                    title: __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").emptyState.noConnectedKBTitle,
                    description: __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").emptyState.noOpenKBDescription,
                    buttonText: __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").buttons.createKBFromServer,
                    buttonHandler: __classPrivateFieldGet(this, _GxIdeTeamDevPreview_createKBFromServerHandler, "f"),
                    showButton: true
                },
                [TeamDevEmptyState.NoConnectedKB]: {
                    title: __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").emptyState.noConnectedKBTitle,
                    description: __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").emptyState.noConnectedKBDescription,
                    buttonText: __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").buttons.shareKBToServer,
                    buttonHandler: __classPrivateFieldGet(this, _GxIdeTeamDevPreview_shareKBToServerHandler, "f"),
                    showButton: true
                },
                [TeamDevEmptyState.NoConnectedGXServer]: {
                    title: __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").emptyState.noConnectedGXServerTitle,
                    description: __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").emptyState.noConnectedGXServerDescription,
                    buttonText: __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").buttons.reconnect,
                    buttonHandler: __classPrivateFieldGet(this, _GxIdeTeamDevPreview_reconnectHandler, "f"),
                    showButton: true
                },
                [TeamDevEmptyState.NoLinkedVersion]: {
                    title: __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").emptyState.noLinkedVersionTitle,
                    description: __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").emptyState.noLinkedVersionDescription,
                    buttonText: "",
                    buttonHandler: undefined,
                    showButton: false
                },
                [TeamDevEmptyState.FrozenVersion]: {
                    title: __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").emptyState.frozenVersionTitle,
                    description: __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").emptyState.frozenVersionDescription,
                    buttonText: "",
                    buttonHandler: undefined,
                    showButton: false
                },
                [TeamDevEmptyState.None]: {
                    title: "",
                    description: "",
                    buttonText: "",
                    buttonHandler: undefined,
                    showButton: false
                }
            }, "f");
        });
        _GxIdeTeamDevPreview_setTeamDevOptionsStatus.set(this, () => {
            if (this.teamDevPreviewData.isKBOpen &&
                this.teamDevPreviewData.isLinkedKB &&
                this.teamDevPreviewData.isLinkedVersion &&
                !this.teamDevPreviewData.isFrozenVersion &&
                this.teamDevPreviewData.existsGXServerSession) {
                __classPrivateFieldSet(this, _GxIdeTeamDevPreview_isTeamDevOptionsEnabled, true, "f");
                return;
            }
            __classPrivateFieldSet(this, _GxIdeTeamDevPreview_isTeamDevOptionsEnabled, false, "f");
        });
        _GxIdeTeamDevPreview_loadChanges.set(this, async (type) => {
            if (type === "local") {
                this.loadingLocalChanges = true;
                __classPrivateFieldSet(this, _GxIdeTeamDevPreview_commitData, await this.loadLocalChangesCallback(), "f");
                __classPrivateFieldGet(this, _GxIdeTeamDevPreview_convertDataToTreeView, "f").call(this, "local");
                this.loadingLocalChanges = false;
                __classPrivateFieldSet(this, _GxIdeTeamDevPreview_isPendingReloadLocalChanges, false, "f");
            }
            else {
                this.loadingRemoteChanges = true;
                __classPrivateFieldSet(this, _GxIdeTeamDevPreview_updateData, await this.loadRemoteChangesCallback(), "f");
                __classPrivateFieldGet(this, _GxIdeTeamDevPreview_convertDataToTreeView, "f").call(this, "remote");
                this.loadingRemoteChanges = false;
                __classPrivateFieldSet(this, _GxIdeTeamDevPreview_isPendingReloadRemoteChanges, false, "f");
            }
        });
        _GxIdeTeamDevPreview_convertDataToTreeView.set(this, (type) => {
            var _a, _b, _c, _d;
            let rootItemName = "";
            let data;
            const isLocal = type === "local";
            if (isLocal) {
                this.pendingCommitChangesCount =
                    ((_b = (_a = __classPrivateFieldGet(this, _GxIdeTeamDevPreview_commitData, "f")) === null || _a === void 0 ? void 0 : _a.pendingForCommit) === null || _b === void 0 ? void 0 : _b.length) || 0;
                rootItemName = `${__classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").captions.localChanges} (${this.pendingCommitChangesCount})`;
                data = __classPrivateFieldGet(this, _GxIdeTeamDevPreview_commitData, "f").pendingForCommit;
            }
            else {
                this.pendingRemoteChangesCount =
                    ((_d = (_c = __classPrivateFieldGet(this, _GxIdeTeamDevPreview_updateData, "f")) === null || _c === void 0 ? void 0 : _c.pendingForUpdate) === null || _d === void 0 ? void 0 : _d.length) || 0;
                rootItemName = `${__classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").captions.remoteChanges} (${this.pendingRemoteChangesCount})`;
                data = __classPrivateFieldGet(this, _GxIdeTeamDevPreview_updateData, "f").pendingForUpdate;
            }
            const treeViewModel = [
                {
                    id: "root",
                    caption: rootItemName,
                    expanded: true,
                    parts: "root-item",
                    items: data === null || data === void 0 ? void 0 : data.map(item => ({
                        id: item.id,
                        startImgSrc: isLocal
                            ? item.type.icon
                            : item.typeIcon,
                        endImgSrc: isLocal
                            ? __classPrivateFieldGet(this, _GxIdeTeamDevPreview_renderIcon, "f").call(this, item.state)
                            : __classPrivateFieldGet(this, _GxIdeTeamDevPreview_renderIcon, "f").call(this, item.action),
                        caption: (
                        //WA: Used to apply different styles to the item caption and path
                        h("div", { style: {
                                display: "flex"
                            } }, h("span", null, item.name), h("span", { style: {
                                color: "var(--color-text-neutral-disabled)",
                                marginLeft: "4px"
                            } }, item.module))),
                        leaf: true,
                        parts: "change-item"
                    }))
                }
            ];
            if (isLocal) {
                this.localChangesTreeViewModel = treeViewModel;
                __classPrivateFieldGet(this, _GxIdeTeamDevPreview_updateTabModel, "f").call(this, LOCAL_CHANGES_TAB);
            }
            else {
                this.remoteChangesTreeViewModel = treeViewModel;
                __classPrivateFieldGet(this, _GxIdeTeamDevPreview_updateTabModel, "f").call(this, REMOTE_CHANGES_TAB);
            }
        });
        _GxIdeTeamDevPreview_checkedItemsChangeHandler.set(this, async (event, type) => {
            const checkedNodesIds = Array.from(event.detail.values())
                .filter(node => node.item.checked && node.item.id !== "root")
                .map(node => node.item.id);
            if (type === "local") {
                this.localChangesCheckedNodesIds = checkedNodesIds;
                __classPrivateFieldGet(this, _GxIdeTeamDevPreview_localChangesTreeEL, "f").updateItemsProperties(["root"], {
                    caption: `${__classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").captions.localChanges} (${this.localChangesCheckedNodesIds.length}/${this.pendingCommitChangesCount})`
                });
            }
            else {
                this.remoteChangesCheckedNodesIds = checkedNodesIds;
                __classPrivateFieldGet(this, _GxIdeTeamDevPreview_remoteChangesTreeEL, "f").updateItemsProperties(["root"], {
                    caption: `${__classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").captions.remoteChanges} (${this.remoteChangesCheckedNodesIds.length}/${this.pendingRemoteChangesCount})`
                });
            }
        });
        _GxIdeTeamDevPreview_shareKBToServerHandler.set(this, async () => {
            await this.shareKBToServerCallback();
        });
        _GxIdeTeamDevPreview_createKBFromServerHandler.set(this, async () => {
            await this.createKBFromServerCallback();
        });
        _GxIdeTeamDevPreview_openFullDialogHandler.set(this, async () => {
            await this.openFullDialogCallback();
        });
        _GxIdeTeamDevPreview_commitChangesHandler.set(this, async () => {
            this.committingChanges = true;
            await this.commitCallback(this.localChangesCheckedNodesIds, this.commitMessage);
            this.commitMessage = "";
            this.committingChanges = false;
        });
        _GxIdeTeamDevPreview_commitMessageInputHandler.set(this, (event) => {
            this.commitMessage = event.detail || "";
        });
        _GxIdeTeamDevPreview_updateRemoteChangesHandler.set(this, async () => {
            this.updatingChanges = true;
            await this.updateCallback(this.remoteChangesCheckedNodesIds);
            this.updatingChanges = false;
            this.remoteChangesCheckedNodesIds = [];
        });
        _GxIdeTeamDevPreview_tabSelectionChangedHandler.set(this, async (event) => {
            this.selectedTabId = event.detail.newSelectedId;
            if (this.selectedTabId === LOCAL_CHANGES_TAB &&
                __classPrivateFieldGet(this, _GxIdeTeamDevPreview_isPendingReloadLocalChanges, "f")) {
                await __classPrivateFieldGet(this, _GxIdeTeamDevPreview_loadChanges, "f").call(this, "local");
            }
            if (this.selectedTabId === REMOTE_CHANGES_TAB &&
                __classPrivateFieldGet(this, _GxIdeTeamDevPreview_isPendingReloadRemoteChanges, "f")) {
                await __classPrivateFieldGet(this, _GxIdeTeamDevPreview_loadChanges, "f").call(this, "remote");
            }
        });
        _GxIdeTeamDevPreview_openTeamDevInfoHandler.set(this, async () => {
            await this.openTeamDevInfoCallback();
        });
        _GxIdeTeamDevPreview_reconnectHandler.set(this, async () => {
            await this.reconnectCallback();
        });
        _GxIdeTeamDevPreview_renderIcon.set(this, (value) => {
            const iconMap = {
                "inserted": ADD_ICON,
                "modified": EDITED_ICON,
                "deleted": SUBTRACT_ICON,
                "conflicted": WARNING_ICON,
                "modified-with-conflicts": WARNING_ICON
            };
            return iconMap[value] || null;
        });
        _GxIdeTeamDevPreview_disableConfirmButton.set(this, (type) => {
            const isLocal = type === "local";
            if (isLocal) {
                return (this.loadingLocalChanges ||
                    !this.commitMessage.trim().length ||
                    this.localChangesCheckedNodesIds.length === 0 ||
                    this.committingChanges ||
                    this.serverOperationsDisabled);
            }
            else {
                return (this.loadingRemoteChanges ||
                    this.remoteChangesCheckedNodesIds.length === 0 ||
                    this.updatingChanges ||
                    this.serverOperationsDisabled);
            }
        });
        _GxIdeTeamDevPreview_updateTabModel.set(this, (tabId) => {
            this.tabModel = this.tabModel.map(tab => tab.id === tabId
                ? Object.assign(Object.assign({}, tab), { name: tabId === LOCAL_CHANGES_TAB
                        ? `${__classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").captions.localChanges} (${this.pendingCommitChangesCount})`
                        : `${__classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").captions.remoteChanges} (${this.pendingRemoteChangesCount})` }) : tab);
        });
        _GxIdeTeamDevPreview_getEmptyStateTitle.set(this, () => __classPrivateFieldGet(this, _GxIdeTeamDevPreview_emptyStateConfig, "f")[this.getEmptyStateType()].title);
        _GxIdeTeamDevPreview_getEmptyStateDescription.set(this, () => __classPrivateFieldGet(this, _GxIdeTeamDevPreview_emptyStateConfig, "f")[this.getEmptyStateType()].description);
        _GxIdeTeamDevPreview_getEmptyStateButtonText.set(this, () => __classPrivateFieldGet(this, _GxIdeTeamDevPreview_emptyStateConfig, "f")[this.getEmptyStateType()].buttonText);
        _GxIdeTeamDevPreview_getEmptyStateButtonHandler.set(this, () => __classPrivateFieldGet(this, _GxIdeTeamDevPreview_emptyStateConfig, "f")[this.getEmptyStateType()].buttonHandler);
        _GxIdeTeamDevPreview_renderEmptyStateButton.set(this, () => __classPrivateFieldGet(this, _GxIdeTeamDevPreview_emptyStateConfig, "f")[this.getEmptyStateType()].showButton);
        _GxIdeTeamDevPreview_renderReloadChangesButton.set(this, (type) => {
            let isLoading = false;
            let isConfirmationInProcess = false;
            let reloadCaption;
            let reloadingCaption;
            const isLocal = type === "local";
            if (isLocal) {
                isLoading = this.loadingLocalChanges;
                isConfirmationInProcess = this.committingChanges;
                reloadCaption = __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").buttons.reloadLocal;
                reloadingCaption = __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").buttons.reloadingLocal;
            }
            else {
                isLoading = this.loadingRemoteChanges;
                isConfirmationInProcess = this.updatingChanges;
                reloadCaption = __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").buttons.reloadRemote;
                reloadingCaption = __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").buttons.reloadingRemote;
            }
            return (h("button", { class: "button-tertiary button-icon-and-text body-regular-s refresh-button", type: "button", onClick: isLocal
                    ? () => __classPrivateFieldGet(this, _GxIdeTeamDevPreview_loadChanges, "f").call(this, "local")
                    : () => __classPrivateFieldGet(this, _GxIdeTeamDevPreview_loadChanges, "f").call(this, "remote"), disabled: isLoading || isConfirmationInProcess || this.serverOperationsDisabled }, h("ch-image", { class: {
                    "icon-m": true,
                    "loader-icon": isLoading
                }, src: isLoading ? LOADER_ICON : REFRESH_ICON, type: "mask" }), isLoading ? reloadingCaption : reloadCaption));
        });
        _GxIdeTeamDevPreview_renderEmptyState.set(this, (type) => {
            let show = false;
            let message = "";
            if (type === "local" && this.pendingCommitChangesCount === 0) {
                show = true;
                message = __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").emptyState.noLocalChanges;
            }
            else if (type === "remote" && this.pendingRemoteChangesCount === 0) {
                show = true;
                message = __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").emptyState.noRemoteChanges;
            }
            return show ? (h("div", { class: "empty-state-container" }, h("p", { class: "body-regular-s" }, message), __classPrivateFieldGet(this, _GxIdeTeamDevPreview_renderReloadChangesButton, "f").call(this, type))) : null;
        });
        _GxIdeTeamDevPreview_renderTreeChanges.set(this, (type) => {
            const isLocal = type === "local";
            if (isLocal) {
                return (h(Fragment, null, __classPrivateFieldGet(this, _GxIdeTeamDevPreview_renderReloadChangesButton, "f").call(this, type), !this.loadingLocalChanges && !this.committingChanges && (h("ch-tree-view-render", { checkbox: true, checked: true, class: "tree-view", model: this.localChangesTreeViewModel, toggleCheckboxes: true, onCheckedItemsChange: event => __classPrivateFieldGet(this, _GxIdeTeamDevPreview_checkedItemsChangeHandler, "f").call(this, event, type), expandableButton: "no", expandOnClick: false, ref: el => (__classPrivateFieldSet(this, _GxIdeTeamDevPreview_localChangesTreeEL, el, "f")) }))));
            }
            else {
                return (h(Fragment, null, __classPrivateFieldGet(this, _GxIdeTeamDevPreview_renderReloadChangesButton, "f").call(this, type), !this.loadingRemoteChanges && !this.updatingChanges && (h("ch-tree-view-render", { checkbox: true, checked: true, class: "tree-view", model: this.remoteChangesTreeViewModel, toggleCheckboxes: true, onCheckedItemsChange: event => __classPrivateFieldGet(this, _GxIdeTeamDevPreview_checkedItemsChangeHandler, "f").call(this, event, type), expandableButton: "no", expandOnClick: false, ref: el => (__classPrivateFieldSet(this, _GxIdeTeamDevPreview_remoteChangesTreeEL, el, "f")) }))));
            }
        });
        _GxIdeTeamDevPreview_renderConfirmButton.set(this, (type) => {
            const isLocal = type === "local";
            let isConfirmationInProcess = false;
            let id = "";
            if (isLocal) {
                isConfirmationInProcess = this.committingChanges;
                id = "commit-changes-button";
            }
            else {
                isConfirmationInProcess = this.updatingChanges;
                id = "update-remote-changes-button";
            }
            return (h("button", { id: id, class: {
                    "button-primary": true,
                    "button-icon-and-text": isConfirmationInProcess
                }, type: "button", disabled: __classPrivateFieldGet(this, _GxIdeTeamDevPreview_disableConfirmButton, "f").call(this, type), onClick: isLocal
                    ? __classPrivateFieldGet(this, _GxIdeTeamDevPreview_commitChangesHandler, "f")
                    : __classPrivateFieldGet(this, _GxIdeTeamDevPreview_updateRemoteChangesHandler, "f") }, isConfirmationInProcess && (h("ch-image", { class: "icon-m loader-icon", src: LOADER_ICON, type: "mask" })), isConfirmationInProcess
                ? isLocal
                    ? __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").buttons.committing
                    : __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").buttons.updating
                : isLocal
                    ? __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").buttons.commit
                    : __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").buttons.update));
        });
        _GxIdeTeamDevPreview_renderLocalChanges.set(this, () => {
            if (this.pendingCommitChangesCount > 0) {
                return (h(Fragment, null, h("ch-edit", { id: "commit-message-input", class: "input commit-message-textarea", value: this.commitMessage, accessibleName: __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").accessibleNames.commitMessage, placeholder: __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").placeholders.commitMessage, disabled: this.loadingLocalChanges, onInput: __classPrivateFieldGet(this, _GxIdeTeamDevPreview_commitMessageInputHandler, "f"), multiline: true }), __classPrivateFieldGet(this, _GxIdeTeamDevPreview_renderConfirmButton, "f").call(this, "local"), __classPrivateFieldGet(this, _GxIdeTeamDevPreview_renderTreeChanges, "f").call(this, "local")));
            }
        });
        _GxIdeTeamDevPreview_renderRemoteChanges.set(this, () => {
            if (this.pendingRemoteChangesCount > 0) {
                return (h(Fragment, null, __classPrivateFieldGet(this, _GxIdeTeamDevPreview_renderConfirmButton, "f").call(this, "remote"), __classPrivateFieldGet(this, _GxIdeTeamDevPreview_renderTreeChanges, "f").call(this, "remote")));
            }
        });
        this.loadingRemoteChanges = false;
        this.loadingLocalChanges = true;
        this.tabModel = [];
        this.selectedTabId = LOCAL_CHANGES_TAB;
        this.pendingCommitChangesCount = 0;
        this.pendingRemoteChangesCount = 0;
        this.remoteChangesTreeViewModel = [];
        this.localChangesTreeViewModel = [];
        this.remoteChangesCheckedNodesIds = [];
        this.localChangesCheckedNodesIds = [];
        this.commitMessage = "";
        this.committingChanges = false;
        this.updatingChanges = false;
        this.serverOperationsDisabled = false;
        this.teamDevPreviewData = undefined;
        this.loadRemoteChangesCallback = undefined;
        this.loadLocalChangesCallback = undefined;
        this.commitCallback = undefined;
        this.updateCallback = undefined;
        this.openFullDialogCallback = undefined;
        this.shareKBToServerCallback = undefined;
        this.createKBFromServerCallback = undefined;
        this.openTeamDevInfoCallback = undefined;
        this.reconnectCallback = undefined;
    }
    async onTeamDevPreviewDataChanged() {
        const { versionName } = this.teamDevPreviewData;
        let versionChanged = false;
        __classPrivateFieldGet(this, _GxIdeTeamDevPreview_setTeamDevOptionsStatus, "f").call(this);
        if (__classPrivateFieldGet(this, _GxIdeTeamDevPreview_prevVersionName, "f") !== versionName) {
            __classPrivateFieldSet(this, _GxIdeTeamDevPreview_prevVersionName, versionName, "f");
            versionChanged = true;
        }
        if (__classPrivateFieldGet(this, _GxIdeTeamDevPreview_isTeamDevOptionsEnabled, "f") && versionChanged) {
            await this.reloadChanges("local");
            await this.reloadChanges("remote");
        }
    }
    async componentWillLoad() {
        __classPrivateFieldGet(this, _GxIdeTeamDevPreview_setTeamDevOptionsStatus, "f").call(this);
        __classPrivateFieldSet(this, _GxIdeTeamDevPreview_componentLocale, await Locale.getComponentStrings(this.el), "f");
        this.tabModel = [
            {
                id: LOCAL_CHANGES_TAB,
                name: `${__classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").captions.localChanges}`
            },
            {
                id: REMOTE_CHANGES_TAB,
                name: `${__classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").captions.remoteChanges}`
            }
        ];
        __classPrivateFieldGet(this, _GxIdeTeamDevPreview_setEmptyStateConfig, "f").call(this);
    }
    async componentDidLoad() {
        if (__classPrivateFieldGet(this, _GxIdeTeamDevPreview_isTeamDevOptionsEnabled, "f")) {
            await __classPrivateFieldGet(this, _GxIdeTeamDevPreview_loadChanges, "f").call(this, "local");
            __classPrivateFieldSet(this, _GxIdeTeamDevPreview_isPendingReloadRemoteChanges, true, "f");
        }
        this.loadingLocalChanges = false;
    }
    /**
     * Used by the host to reload remote or local changes
     */
    async reloadChanges(type) {
        const isLocal = type === "local";
        const isActiveTab = isLocal
            ? this.selectedTabId === LOCAL_CHANGES_TAB
            : this.selectedTabId === REMOTE_CHANGES_TAB;
        if (!isActiveTab) {
            if (isLocal) {
                __classPrivateFieldSet(this, _GxIdeTeamDevPreview_isPendingReloadLocalChanges, true, "f");
            }
            else {
                __classPrivateFieldSet(this, _GxIdeTeamDevPreview_isPendingReloadRemoteChanges, true, "f");
            }
            return;
        }
        isLocal
            ? await __classPrivateFieldGet(this, _GxIdeTeamDevPreview_loadChanges, "f").call(this, "local")
            : await __classPrivateFieldGet(this, _GxIdeTeamDevPreview_loadChanges, "f").call(this, "remote");
    }
    /**
     * Used by the host to instruct the component to disable the commit/update button.
     */
    async disableServerOperations(value) {
        this.serverOperationsDisabled = value;
    }
    getEmptyStateType() {
        const { isFrozenVersion, existsGXServerSession, isKBOpen, isLinkedVersion, isLinkedKB } = this.teamDevPreviewData;
        if (!isKBOpen) {
            return TeamDevEmptyState.NoKBOpen;
        }
        if (isKBOpen && !isLinkedKB) {
            return TeamDevEmptyState.NoConnectedKB;
        }
        if (isKBOpen && isLinkedKB && !isLinkedVersion && !existsGXServerSession) {
            return TeamDevEmptyState.NoConnectedGXServer;
        }
        if (isKBOpen && isLinkedKB && !isLinkedVersion) {
            return TeamDevEmptyState.NoLinkedVersion;
        }
        if (isKBOpen && isLinkedKB && existsGXServerSession && isFrozenVersion) {
            return TeamDevEmptyState.FrozenVersion;
        }
        if (isKBOpen && isLinkedKB && !existsGXServerSession) {
            return TeamDevEmptyState.NoConnectedGXServer;
        }
        return TeamDevEmptyState.None;
    }
    render() {
        const { existsGXServerSession } = this.teamDevPreviewData;
        return (h(Host, { class: {
                "widget": true,
                "empty-state": !__classPrivateFieldGet(this, _GxIdeTeamDevPreview_isTeamDevOptionsEnabled, "f")
            } }, h("ch-theme", { model: CSS_BUNDLES }), !__classPrivateFieldGet(this, _GxIdeTeamDevPreview_isTeamDevOptionsEnabled, "f") || !existsGXServerSession ? (h("gx-ide-empty-state", { isAnimated: true, stateIconSrc: ERROR_ICON, stateTitle: __classPrivateFieldGet(this, _GxIdeTeamDevPreview_getEmptyStateTitle, "f").call(this), stateDescription: __classPrivateFieldGet(this, _GxIdeTeamDevPreview_getEmptyStateDescription, "f").call(this) }, __classPrivateFieldGet(this, _GxIdeTeamDevPreview_renderEmptyStateButton, "f").call(this) && (h("button", { class: "button-primary empty-state-button", onClick: __classPrivateFieldGet(this, _GxIdeTeamDevPreview_getEmptyStateButtonHandler, "f").call(this) }, __classPrivateFieldGet(this, _GxIdeTeamDevPreview_getEmptyStateButtonText, "f").call(this))), h("div", null, h("p", { class: "body-regular-s" }, __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").emptyState.about), h("button", { class: "button-tertiary button-icon-and-text team-dev-button body-semi-bold-s", type: "button", onClick: __classPrivateFieldGet(this, _GxIdeTeamDevPreview_openTeamDevInfoHandler, "f") }, __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").buttons.teamDev, h("ch-image", { class: "icon-m", src: OPEN_WINDOW_ICON, type: "mask" }))))) : (h("div", { class: "main-container spacing-body scrollable" }, h("p", { class: "giu-static-pill-icon-and-text version giu-static-pill-icon-and-text--version elevation-02" }, h("ch-image", { class: "icon-m", type: "mask", src: VERSION_ICON }), h("span", { class: "version-pill" }, this.teamDevPreviewData.versionName)), h("ch-tab-render", { class: "tab tab-full-width-buttons scrollable border-style-none", model: this.tabModel, selectedId: this.selectedTabId, tabListPosition: "block-start", onSelectedItemChange: __classPrivateFieldGet(this, _GxIdeTeamDevPreview_tabSelectionChangedHandler, "f") }, h("div", { class: "local-changes-container", slot: LOCAL_CHANGES_TAB }, __classPrivateFieldGet(this, _GxIdeTeamDevPreview_renderEmptyState, "f").call(this, "local"), __classPrivateFieldGet(this, _GxIdeTeamDevPreview_renderLocalChanges, "f").call(this)), h("div", { class: "remote-changes-container", slot: REMOTE_CHANGES_TAB }, __classPrivateFieldGet(this, _GxIdeTeamDevPreview_renderEmptyState, "f").call(this, "remote"), __classPrivateFieldGet(this, _GxIdeTeamDevPreview_renderRemoteChanges, "f").call(this))), h("footer", { class: "dialog-footer-with-border open-window-container" }, h("div", { class: "buttons-spacer" }, h("button", { class: "button-tertiary button-icon-and-text open-full-dialog-button", onClick: __classPrivateFieldGet(this, _GxIdeTeamDevPreview_openFullDialogHandler, "f") }, h("ch-image", { class: "icon-m", src: OPEN_WINDOW_ICON, type: "mask" }), __classPrivateFieldGet(this, _GxIdeTeamDevPreview_componentLocale, "f").footer.openFullDialog)))))));
    }
    static get assetsDirs() { return ["gx-ide-assets/team-dev-preview"]; }
    get el() { return this; }
    static get watchers() { return {
        "teamDevPreviewData": ["onTeamDevPreviewDataChanged"]
    }; }
    static get style() { return teamDevPreviewCss; }
}, [1, "gx-ide-team-dev-preview", {
        "teamDevPreviewData": [16],
        "loadRemoteChangesCallback": [16],
        "loadLocalChangesCallback": [16],
        "commitCallback": [16],
        "updateCallback": [16],
        "openFullDialogCallback": [16],
        "shareKBToServerCallback": [16],
        "createKBFromServerCallback": [16],
        "openTeamDevInfoCallback": [16],
        "reconnectCallback": [16],
        "loadingRemoteChanges": [32],
        "loadingLocalChanges": [32],
        "tabModel": [32],
        "selectedTabId": [32],
        "pendingCommitChangesCount": [32],
        "pendingRemoteChangesCount": [32],
        "remoteChangesTreeViewModel": [32],
        "localChangesTreeViewModel": [32],
        "remoteChangesCheckedNodesIds": [32],
        "localChangesCheckedNodesIds": [32],
        "commitMessage": [32],
        "committingChanges": [32],
        "updatingChanges": [32],
        "serverOperationsDisabled": [32],
        "reloadChanges": [64],
        "disableServerOperations": [64]
    }, undefined, {
        "teamDevPreviewData": ["onTeamDevPreviewDataChanged"]
    }]);
_GxIdeTeamDevPreview_componentLocale = new WeakMap(), _GxIdeTeamDevPreview_isPendingReloadLocalChanges = new WeakMap(), _GxIdeTeamDevPreview_isPendingReloadRemoteChanges = new WeakMap(), _GxIdeTeamDevPreview_commitData = new WeakMap(), _GxIdeTeamDevPreview_updateData = new WeakMap(), _GxIdeTeamDevPreview_prevVersionName = new WeakMap(), _GxIdeTeamDevPreview_isTeamDevOptionsEnabled = new WeakMap(), _GxIdeTeamDevPreview_emptyStateConfig = new WeakMap(), _GxIdeTeamDevPreview_localChangesTreeEL = new WeakMap(), _GxIdeTeamDevPreview_remoteChangesTreeEL = new WeakMap(), _GxIdeTeamDevPreview_setEmptyStateConfig = new WeakMap(), _GxIdeTeamDevPreview_setTeamDevOptionsStatus = new WeakMap(), _GxIdeTeamDevPreview_loadChanges = new WeakMap(), _GxIdeTeamDevPreview_convertDataToTreeView = new WeakMap(), _GxIdeTeamDevPreview_checkedItemsChangeHandler = new WeakMap(), _GxIdeTeamDevPreview_shareKBToServerHandler = new WeakMap(), _GxIdeTeamDevPreview_createKBFromServerHandler = new WeakMap(), _GxIdeTeamDevPreview_openFullDialogHandler = new WeakMap(), _GxIdeTeamDevPreview_commitChangesHandler = new WeakMap(), _GxIdeTeamDevPreview_commitMessageInputHandler = new WeakMap(), _GxIdeTeamDevPreview_updateRemoteChangesHandler = new WeakMap(), _GxIdeTeamDevPreview_tabSelectionChangedHandler = new WeakMap(), _GxIdeTeamDevPreview_openTeamDevInfoHandler = new WeakMap(), _GxIdeTeamDevPreview_reconnectHandler = new WeakMap(), _GxIdeTeamDevPreview_renderIcon = new WeakMap(), _GxIdeTeamDevPreview_disableConfirmButton = new WeakMap(), _GxIdeTeamDevPreview_updateTabModel = new WeakMap(), _GxIdeTeamDevPreview_getEmptyStateTitle = new WeakMap(), _GxIdeTeamDevPreview_getEmptyStateDescription = new WeakMap(), _GxIdeTeamDevPreview_getEmptyStateButtonText = new WeakMap(), _GxIdeTeamDevPreview_getEmptyStateButtonHandler = new WeakMap(), _GxIdeTeamDevPreview_renderEmptyStateButton = new WeakMap(), _GxIdeTeamDevPreview_renderReloadChangesButton = new WeakMap(), _GxIdeTeamDevPreview_renderEmptyState = new WeakMap(), _GxIdeTeamDevPreview_renderTreeChanges = new WeakMap(), _GxIdeTeamDevPreview_renderConfirmButton = new WeakMap(), _GxIdeTeamDevPreview_renderLocalChanges = new WeakMap(), _GxIdeTeamDevPreview_renderRemoteChanges = new WeakMap();
function defineCustomElement$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["gx-ide-team-dev-preview", "gx-ide-empty-state"];
    components.forEach(tagName => { switch (tagName) {
        case "gx-ide-team-dev-preview":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, GxIdeTeamDevPreview$1);
            }
            break;
        case "gx-ide-empty-state":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
    } });
}

const GxIdeTeamDevPreview = GxIdeTeamDevPreview$1;
const defineCustomElement = defineCustomElement$1;

export { GxIdeTeamDevPreview, defineCustomElement };

//# sourceMappingURL=gx-ide-team-dev-preview.js.map