import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
/**
 * Copyright (c) 2020-present, Goldman Sachs
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { useEffect } from 'react';
import { isNonNullable, prettyCONSTName } from '@finos/legend-shared';
import { observer } from 'mobx-react-lite';
import { ProjectConfigurationEditorState, CONFIGURATION_EDITOR_TAB, projectTypeTabFilter, } from '../../../../stores/editor/editor-state/project-configuration-editor-state/ProjectConfigurationEditorState.js';
import { clsx, PlusIcon, CheckCircleIcon, ExclamationCircleIcon, Panel, PanelForm, CheckSquareIcon, SquareIcon, ExclamationTriangleIcon, PanelFormSection, PanelListItem, Button, PencilEditIcon, PanelDivider, PanelHeaderActionItem, PanelHeaderActions, PanelContent, PanelHeader, PanelContentLists, PanelLoadingIndicator, } from '@finos/legend-art';
import { flowResult } from 'mobx';
import { PlatformConfiguration, ProjectDependency, ProjectType, } from '@finos/legend-server-sdlc';
import { useEditorStore } from '../../EditorStoreProvider.js';
import { ActionAlertActionType, ActionAlertType, shouldDisplayVirtualAssistantDocumentationEntry, useApplicationStore, } from '@finos/legend-application';
import { ProjectDependencyEditor } from './ProjectDependencyEditor.js';
import { LEGEND_STUDIO_DOCUMENTATION_KEY } from '../../../../__lib__/LegendStudioDocumentation.js';
import { DocumentationLink, DocumentationPreview, } from '@finos/legend-lego/application';
const isProjectConfigurationVersionOutdated = (projectConfig, latestVersion, isEmbeddedMode) => {
    if (!latestVersion) {
        return false;
    }
    const mainVersionOutdated = latestVersion.version > projectConfig.projectStructureVersion.version;
    if (isEmbeddedMode) {
        return mainVersionOutdated;
    }
    const currentProjectExtensionVersion = projectConfig.projectStructureVersion.extensionVersion ?? -1;
    const latestProjectExtensionVersion = latestVersion.extensionVersion ?? -1;
    return (mainVersionOutdated ||
        latestProjectExtensionVersion > currentProjectExtensionVersion);
};
const ProjectStructureEditor = observer((props) => {
    const { projectConfig, isReadOnly } = props;
    const editorStore = useEditorStore();
    const applicationStore = useApplicationStore();
    const latestVersion = editorStore.projectConfigurationEditorState.latestProjectStructureVersion;
    const isProjectStructureVersionOutdated = isProjectConfigurationVersionOutdated(projectConfig, latestVersion, editorStore.projectConfigurationEditorState.isInEmbeddedMode);
    const isGroupIdChanged = editorStore.projectConfigurationEditorState.isGroupIdChanged;
    const isArtifactIdChanged = editorStore.projectConfigurationEditorState.isArtifactIdChanged;
    const updateVersion = () => {
        flowResult(editorStore.projectConfigurationEditorState.updateToLatestStructure()).catch(applicationStore.alertUnhandledError);
    };
    const changeGroupId = (event) => {
        const stringValue = event.target.value;
        projectConfig.setGroupId(stringValue);
    };
    const changeArtifactId = (event) => {
        const stringValue = event.target.value;
        projectConfig.setArtifactId(stringValue);
    };
    return (_jsxs(PanelContentLists, { children: [_jsxs("div", { className: "project-configuration-editor__project__structure__version", children: [_jsxs("div", { className: "project-configuration-editor__project__structure__version__label", children: [_jsx("div", { className: "project-configuration-editor__project__structure__version__label__status", children: isProjectStructureVersionOutdated ? (_jsx(ExclamationCircleIcon, { className: "project-configuration-editor__project__structure__version__label__status--outdated", title: "Project structure is outdated" })) : (_jsx(CheckCircleIcon, { className: "project-configuration-editor__project__structure__version__label__status--up-to-date", title: "Project structure is up to date" })) }), _jsx("div", { className: "project-configuration-editor__project__structure__version__label__text", children: `PROJECT STRUCTURE VERSION ${projectConfig.projectStructureVersion.fullVersion}` })] }), isProjectStructureVersionOutdated && latestVersion && (_jsxs("button", { className: "project-configuration-editor__project__structure__version__update-btn", disabled: isReadOnly, onClick: updateVersion, tabIndex: -1, title: `Current project structure is outdated. Click to update to the latest version (v${latestVersion.fullVersion}})`, children: ["Update to version", ' ', editorStore.projectConfigurationEditorState.isInEmbeddedMode
                                ? latestVersion.version
                                : latestVersion.fullVersion] }))] }), _jsxs(PanelForm, { children: [_jsxs(PanelFormSection, { children: [_jsx("div", { className: "panel__content__form__section__header__label", children: "Group ID" }), _jsx("div", { className: "panel__content__form__section__header__prompt", children: "The domain for artifacts generated as part of the project build pipeline and published to an artifact repository" }), _jsx(PanelListItem, { children: _jsxs("div", { className: "input-group project-configuration-editor__input", children: [_jsx("input", { className: clsx('input input--dark input-group__input panel__content__form__section__input input--full', { 'input--caution': isGroupIdChanged }), title: "Group ID", spellCheck: false, disabled: isReadOnly, value: projectConfig.groupId, onChange: changeGroupId }), isGroupIdChanged && (_jsx(DocumentationLink, { documentationKey: LEGEND_STUDIO_DOCUMENTATION_KEY.QUESTION_HOW_TO_UPDATE_PROJECT_GAV_COORDINATES }))] }) })] }), _jsxs(PanelFormSection, { children: [_jsx("div", { className: "panel__content__form__section__header__label", children: "Artifact ID" }), _jsx("div", { className: "panel__content__form__section__header__prompt", children: "The identifier (within the domain specified by group ID) for artifacts generated as part of the project build pipeline and published to an artifact repository" }), _jsx(PanelListItem, { children: _jsxs("div", { className: "input-group project-configuration-editor__input", children: [_jsx("input", { className: clsx('input input--dark input-group__input panel__content__form__section__input input--full', { 'input--caution': isArtifactIdChanged }), title: "Artifact ID", spellCheck: false, disabled: isReadOnly, value: projectConfig.artifactId, onChange: changeArtifactId }), isArtifactIdChanged && (_jsx(DocumentationLink, { documentationKey: LEGEND_STUDIO_DOCUMENTATION_KEY.QUESTION_HOW_TO_UPDATE_PROJECT_GAV_COORDINATES }))] }) })] })] })] }));
});
const PlatformDependencyViewer = observer((props) => {
    const { platform, isDefault, isLatestVersion } = props;
    return (_jsx("div", { className: "platform-configurations-editor__dependency", children: _jsxs("div", { className: "platform-configurations-editor__dependency__label", children: [_jsxs("div", { className: "platform-configurations-editor__dependency__label__status", children: [isDefault && (_jsx(CheckCircleIcon, { className: "platform-configurations-editor__dependency__label__status--default", title: "Platform version is up to date" })), isLatestVersion !== undefined &&
                            (isLatestVersion ? (_jsx(CheckCircleIcon, { className: "platform-configurations-editor__dependency__label__status--up-to-date", title: "Platform version is up to date" })) : (_jsx(ExclamationTriangleIcon, { className: "platform-configurations-editor__dependency__label__status--outdated", title: "Platform version is outdated" })))] }), _jsx("div", { className: "platform-configurations-editor__dependency__label__text", children: platform.name }), _jsx("div", { className: clsx('platform-configurations-editor__dependency__label__version'), children: platform.version })] }) }));
});
const PlatformDependencyEditor = observer((props) => {
    const { platform } = props;
    return (_jsx("div", { className: "platform-configurations-editor__dependency", children: _jsxs("div", { className: "platform-configurations-editor__dependency__label", children: [_jsx("div", { className: "platform-configurations-editor__dependency__label__status" }), _jsx("div", { className: "platform-configurations-editor__dependency__label__text", children: platform.name }), _jsx("input", { className: "input input--dark", onChange: (event) => {
                        platform.setVersion(event.target.value);
                    }, value: platform.version, spellCheck: false })] }) }));
});
const ProjectPlatformVersionEditor = observer((props) => {
    const { projectConfig, isReadOnly } = props;
    const editorStore = useEditorStore();
    const applicationStore = useApplicationStore();
    const convertPlatformtoPlatformConfiguration = (platforms) => {
        if (platforms) {
            return platforms.map((platform) => new PlatformConfiguration(platform.name, platform.platformVersion));
        }
        else {
            return undefined;
        }
    };
    const platformConfigurations = projectConfig.platformConfigurations;
    const defaultPlatforms = convertPlatformtoPlatformConfiguration(editorStore.sdlcServerClient.platforms);
    const isUpToDate = platformConfigurations?.every((conf) => defaultPlatforms?.find((p) => p.name === conf.name)?.version ===
        conf.version);
    const updateLatestToLatestVersion = () => {
        if (platformConfigurations && defaultPlatforms) {
            projectConfig.setPlatformConfigurations(platformConfigurations.map((conf) => {
                const matchingPlatformConfig = defaultPlatforms.find((p) => p.name === conf.name);
                if (matchingPlatformConfig) {
                    return matchingPlatformConfig;
                }
                return conf;
            }));
        }
    };
    const toggleOverridePlatformConfigurations = () => {
        if (!projectConfig.platformConfigurations) {
            projectConfig.setPlatformConfigurations(defaultPlatforms);
        }
        else {
            projectConfig.setPlatformConfigurations(undefined);
        }
    };
    const toggleManualOverwrite = () => {
        if (!editorStore.projectConfigurationEditorState.manualOverwrite) {
            applicationStore.alertService.setActionAlertInfo({
                message: 'Clicking this will allow you to not just override and freeze platform versions but to input custom platform versions you would like manually and is not usually recommended except to temporarily unblock your project',
                prompt: 'Do you want to proceed?',
                type: ActionAlertType.CAUTION,
                actions: [
                    {
                        label: 'Continue',
                        type: ActionAlertActionType.PROCEED_WITH_CAUTION,
                        handler: () => editorStore.projectConfigurationEditorState.setManualOverwrite(true),
                    },
                    {
                        label: 'Cancel',
                        type: ActionAlertActionType.PROCEED,
                        default: true,
                    },
                ],
            });
        }
        else {
            editorStore.projectConfigurationEditorState.setManualOverwrite(false);
        }
    };
    return (_jsx(Panel, { children: _jsxs(PanelForm, { children: [_jsx(DocumentationPreview, { text: "By default, your project will use the latest platform\n              dependencies' versions (e.g. engine, sdlc, etc.) in the pipeline.\n              This might be undesirable when you want to produce stable\n              artifacts; in this case, you can freeze the platform dependencies'\n              versions", documentationKey: LEGEND_STUDIO_DOCUMENTATION_KEY.QUESTION_WHEN_TO_CONFIGURE_PLATFORM_VERSIONS }), _jsxs("div", { className: "platform-configurations-editor__dependencies", children: [_jsxs("div", { className: "platform-configurations-editor__dependencies__header", children: [_jsx("div", { className: "platform-configurations-editor__dependencies__header__left", children: _jsxs("div", { className: "platform-configurations-editor__toggler", onClick: toggleOverridePlatformConfigurations, children: [_jsx("button", { className: clsx('platform-configurations-editor__toggler__btn', {
                                                    'platform-configurations-editor__toggler__btn--toggled': Boolean(platformConfigurations),
                                                }), disabled: isReadOnly, tabIndex: -1, children: platformConfigurations ? (_jsx(CheckSquareIcon, {})) : (_jsx(SquareIcon, {})) }), _jsx("div", { className: "platform-configurations-editor__toggler__prompt", children: `Override platform dependencies' versions` })] }) }), _jsx("div", { className: "platform-configurations-editor__dependencies__header__right", children: _jsxs(PanelListItem, { children: [platformConfigurations &&
                                                !isUpToDate &&
                                                !editorStore.projectConfigurationEditorState
                                                    .manualOverwrite && (_jsx("div", { children: _jsx("button", { className: "btn btn--dark", tabIndex: -1, onClick: updateLatestToLatestVersion, children: "Update to the current latest platform version" }) })), _jsx(Button, { className: clsx('project-configuration-editor__manual-btn', {
                                                    'project-configuration-editor__manual-btn--active': editorStore.projectConfigurationEditorState
                                                        .manualOverwrite,
                                                }), title: "Manually overwrite platform configurations", disabled: isReadOnly, onClick: toggleManualOverwrite, children: _jsx(PencilEditIcon, {}) })] }) })] }), _jsx("div", { className: "platform-configurations-editor__dependencies__content", children: editorStore.projectConfigurationEditorState.manualOverwrite ? (_jsxs(_Fragment, { children: [!platformConfigurations &&
                                        defaultPlatforms?.map((p) => (_jsx(PlatformDependencyEditor, { platform: p }, p.name))), platformConfigurations?.map((p) => (_jsx(PlatformDependencyEditor, { platform: p }, p.name))), _jsx(PanelDivider, {}), _jsxs(PanelListItem, { children: [_jsx(Button, { className: "project-configuration-editor__manual-overwrite-btn", disabled: isReadOnly, onClick: () => {
                                                    editorStore.projectConfigurationEditorState.setManualOverwrite(false);
                                                }, title: "Cancel manual override", text: "Cancel" }), _jsx(Button, { className: "project-configuration-editor__manual-overwrite-btn", disabled: isReadOnly, onClick: () => {
                                                    if (!platformConfigurations) {
                                                        projectConfig.setPlatformConfigurations(defaultPlatforms);
                                                    }
                                                    else {
                                                        projectConfig.setPlatformConfigurations(platformConfigurations);
                                                    }
                                                    editorStore.projectConfigurationEditorState.setManualOverwrite(false);
                                                }, text: "Manual override" })] })] })) : (_jsxs(_Fragment, { children: [!platformConfigurations &&
                                        defaultPlatforms?.map((p) => (_jsx(PlatformDependencyViewer, { isDefault: true, platform: p }, p.name))), platformConfigurations?.map((p) => (_jsx(PlatformDependencyViewer, { platform: p, isDefault: false, isLatestVersion: isUpToDate }, p.name)))] })) })] })] }) }));
});
const ProjectAdvancedEditor = observer((props) => {
    const { projectConfig, isReadOnly, configState } = props;
    const editorStore = useEditorStore();
    const applicationStore = useApplicationStore();
    const currentProjectType = projectConfig.projectType ?? ProjectType.MANAGED;
    const isEmbeddedMode = currentProjectType === ProjectType.EMBEDDED;
    const managedModeBlurb = 'Managed Projects are managed by our SDLC server, which includes managing the build and deployment of your project.This enables rich features such as releasing and dependency management work within our ecosystem.This is the recommended mode and should not be changed unless your customized build is robust to handle these operations and you are aware of the different features our managed mode provides.';
    const embeddedModeBlurb = 'Embedded Projects have their own customized build. The build is managed directly on the underlying version system (gitlab, github etc) and the owners of the projects are responsible for managing their build and incorporating the necessary steps to enable features such as releasing and dependency management. Our SDLC server still manages the file structure of where the elements entities are located and correlate with the project structure version.';
    const managedToEmbedded = 'You are about to change from managed to embedded project type. This will cause your build files (pom, ci etc) to no longer be managed by our SDLC process. Your element folder structure will remain managed by us but your build will become your responsibility. Please ensure you understand the risks of changing over before continuing.';
    const embeddedToManaged = 'You are about to change from embedded to managed project type. Your build will now be managed by our SDLC sever in addition to your element folder structure. Your current build files will all be deleted and replaces with our own. Please ensure you understand the risks of changing over before continuing.';
    const runDependencyMessage = `In addition to running your own tests, you can also configure to run all tests in your dependency projects.  This should be rarely used and mostly helped mitigate when you have override your dependencies. You should aim to have most of your tests in your current project.`;
    const toggleRunDependency = () => {
        const newVal = !projectConfig.runDependencyTests;
        if (!newVal &&
            configState.originalConfig.runDependencyTests === undefined) {
            projectConfig.setRunDependencyTests(undefined);
        }
        else {
            projectConfig.setRunDependencyTests(newVal);
        }
    };
    const changeProjectType = () => {
        applicationStore.alertService.setActionAlertInfo({
            message: `${isEmbeddedMode ? embeddedToManaged : managedToEmbedded}`,
            prompt: 'Do you want to proceed?',
            type: ActionAlertType.CAUTION,
            actions: [
                {
                    label: 'Continue',
                    type: ActionAlertActionType.PROCEED_WITH_CAUTION,
                    handler: () => {
                        flowResult(editorStore.projectConfigurationEditorState.changeProjectType()).catch(applicationStore.alertUnhandledError);
                    },
                },
                {
                    label: 'Cancel',
                    type: ActionAlertActionType.PROCEED,
                    default: true,
                },
            ],
        });
    };
    return (_jsxs(Panel, { children: [_jsxs(PanelForm, { children: [_jsx("div", { className: "panel__content__form__section__header__label", children: `Dependency Tests` }), _jsx("div", { className: "documentation-preview", children: _jsx("div", { className: "documentation-preview__text", children: _jsx("div", { className: "project-configuration-editor__advanced__project-type__info", children: runDependencyMessage }) }) }), _jsx("div", { className: "platform-configurations-editor__dependencies", children: _jsx("div", { className: "platform-configurations-editor__dependencies__header", children: _jsx("div", { className: "platform-configurations-editor__dependencies__header__left", children: _jsxs("div", { className: "platform-configurations-editor__toggler", onClick: toggleRunDependency, children: [_jsx("button", { className: clsx('platform-configurations-editor__toggler__btn', {
                                                'platform-configurations-editor__toggler__btn--toggled': Boolean(projectConfig.runDependencyTests),
                                            }), disabled: isReadOnly, tabIndex: -1, children: projectConfig.runDependencyTests ? (_jsx(CheckSquareIcon, {})) : (_jsx(SquareIcon, {})) }), _jsx("div", { className: "platform-configurations-editor__toggler__prompt", children: `Run Dependency Tests` })] }) }) }) })] }), _jsxs(PanelForm, { children: [_jsx("div", { className: "panel__content__form__section__header__label", children: `Project Type: ${prettyCONSTName(currentProjectType)} ` }), _jsxs("div", { className: "documentation-preview", children: [_jsxs("div", { className: "documentation-preview__text", children: [_jsx("div", { className: "project-configuration-editor__advanced__project-type__info", children: managedModeBlurb }), _jsx("div", { className: "project-configuration-editor__advanced__project-type__info", children: embeddedModeBlurb })] }), _jsx("div", { className: "documentation-preview__hint", children: _jsx(DocumentationLink, { documentationKey: LEGEND_STUDIO_DOCUMENTATION_KEY.QUESTION_WHAT_IS_EMBEDDED_MODE_PROJECT_TYPE }) })] }), _jsx("div", { className: "platform-configurations-editor__dependencies", children: _jsx("div", { className: "platform-configurations-editor__dependencies__header", children: _jsx("button", { className: "btn--dark btn--conflict btn--important project-configuration-editor__advanced__caution__btn", onClick: changeProjectType, tabIndex: -1, children: `Change to ${isEmbeddedMode ? 'Managed Type' : 'Embedded Type'}` }) }) })] })] }));
});
export const ProjectConfigurationEditor = observer(() => {
    const editorStore = useEditorStore();
    const applicationStore = useApplicationStore();
    const configState = editorStore.tabManagerState.getCurrentEditorState(ProjectConfigurationEditorState);
    const projectType = configState.currentProjectConfiguration.projectType ?? ProjectType.MANAGED;
    const sdlcState = editorStore.sdlcState;
    const isReadOnly = editorStore.isInViewerMode;
    const selectedTab = configState.selectedTab;
    const dependencyEditorState = configState.projectDependencyEditorState;
    const tabs = [
        CONFIGURATION_EDITOR_TAB.PROJECT_STRUCTURE,
        CONFIGURATION_EDITOR_TAB.PROJECT_DEPENDENCIES,
        CONFIGURATION_EDITOR_TAB.PLATFORM_CONFIGURATIONS,
        CONFIGURATION_EDITOR_TAB.ADVANCED,
    ].filter((tab) => projectTypeTabFilter(projectType, tab));
    const changeTab = (tab) => () => configState.setSelectedTab(tab);
    let addButtonTitle = '';
    switch (selectedTab) {
        case CONFIGURATION_EDITOR_TAB.PROJECT_DEPENDENCIES:
            addButtonTitle = 'Add project dependencies';
            break;
        default:
            break;
    }
    const currentProjectConfiguration = configState.currentProjectConfiguration;
    const addValue = applicationStore.guardUnhandledError(async () => {
        if (!isReadOnly) {
            if (selectedTab === CONFIGURATION_EDITOR_TAB.PROJECT_DEPENDENCIES) {
                const currentProjects = Array.from(configState.projects.values());
                if (currentProjects.length) {
                    const projectToAdd = currentProjects[0];
                    const dependencyToAdd = new ProjectDependency(projectToAdd.coordinates);
                    const versions = await editorStore.depotServerClient.getVersions(projectToAdd.groupId, projectToAdd.artifactId, true);
                    configState.versions.set(dependencyToAdd.projectId, versions);
                    dependencyToAdd.setVersionId(versions[0] ?? '');
                    currentProjectConfiguration.addProjectDependency(dependencyToAdd);
                    flowResult(configState.projectDependencyEditorState.fetchDependencyReport()).catch(applicationStore.alertUnhandledError);
                }
                else {
                    currentProjectConfiguration.addProjectDependency(new ProjectDependency(''));
                }
            }
        }
    });
    const disableAddButton = selectedTab !== CONFIGURATION_EDITOR_TAB.PROJECT_DEPENDENCIES || isReadOnly;
    const updateGavConfigs = () => {
        const documentationEntry = applicationStore.documentationService.getDocEntry(LEGEND_STUDIO_DOCUMENTATION_KEY.QUESTION_HOW_TO_UPDATE_PROJECT_GAV_COORDINATES);
        editorStore.applicationStore.alertService.setActionAlertInfo({
            message: 'Please be cautious that modifying group ID or artifact ID (GAV coordinates) can potentially have a big downstream impact. Be aware that the project will lose all previous versions; also, any dependant projects can break too if the coordinates are not changed in a controlled way.',
            type: ActionAlertType.STANDARD,
            prompt: documentationEntry
                ? 'Please see the instructions for more guidance'
                : undefined,
            actions: [
                {
                    label: (_jsxs(_Fragment, { children: ["Acknowledge and Proceed", _jsx(DocumentationLink, { documentationKey: LEGEND_STUDIO_DOCUMENTATION_KEY.QUESTION_HOW_TO_UPDATE_PROJECT_GAV_COORDINATES })] })),
                    type: ActionAlertActionType.PROCEED_WITH_CAUTION,
                    handler: () => {
                        editorStore.localChangesState.alertUnsavedChanges(() => {
                            flowResult(configState.updateConfigs()).catch(applicationStore.alertUnhandledError);
                        });
                    },
                },
                documentationEntry && {
                    label: 'View Instructions',
                    default: true,
                    type: ActionAlertActionType.PROCEED,
                    handler: () => {
                        if (shouldDisplayVirtualAssistantDocumentationEntry(documentationEntry)) {
                            applicationStore.assistantService.openDocumentationEntry(documentationEntry.key);
                        }
                        else if (documentationEntry.url) {
                            applicationStore.navigationService.navigator.visitAddress(documentationEntry.url);
                        }
                    },
                },
                {
                    label: 'Cancel',
                    type: ActionAlertActionType.PROCEED,
                },
            ].filter(isNonNullable),
        });
    };
    const updateConfigs = () => {
        if (configState.isArtifactIdChanged || configState.isGroupIdChanged) {
            updateGavConfigs();
        }
        else {
            editorStore.localChangesState.alertUnsavedChanges(() => {
                flowResult(configState.updateConfigs()).catch(applicationStore.alertUnhandledError);
            });
        }
    };
    useEffect(() => {
        if (configState.projectConfiguration &&
            selectedTab === CONFIGURATION_EDITOR_TAB.PROJECT_DEPENDENCIES &&
            !configState.associatedProjectsAndVersionsFetched) {
            Promise.all([
                flowResult(configState.fectchAssociatedProjectsAndVersions()),
                flowResult(configState.projectDependencyEditorState.fetchDependencyReport()),
            ]).catch(applicationStore.alertUnhandledError);
        }
    }, [applicationStore, configState, selectedTab]);
    if (!configState.projectConfiguration) {
        return null;
    }
    const isLoading = configState.updatingConfigurationState.isInProgress ||
        configState.fetchingProjectVersionsState.isInProgress ||
        dependencyEditorState.fetchingDependencyInfoState.isInProgress;
    return (_jsx("div", { className: "project-configuration-editor", children: _jsxs(Panel, { children: [_jsxs(PanelHeader, { children: [_jsxs("div", { className: "panel__header__title", children: [_jsx("div", { className: "panel__header__title__label", children: "project configuration" }), _jsx("div", { className: "panel__header__title__content", children: sdlcState.currentProject?.name ?? '(unknown)' })] }), _jsx("button", { 
                            // TODO: remove this ugly button when we integrate project configuration into change detection flow
                            className: "project-configuration-editor__update-btn", disabled: isReadOnly ||
                                configState.updatingConfigurationState.isInProgress ||
                                currentProjectConfiguration.hashCode ===
                                    configState.originalConfig.hashCode, onClick: updateConfigs, tabIndex: -1, children: "Update" })] }), _jsxs(PanelHeader, { className: "project-configuration-editor__tabs__header", children: [_jsx("div", { className: "project-configuration-editor__tabs", children: tabs.map((tab) => (_jsx("button", { onClick: changeTab(tab), className: clsx('project-configuration-editor__tab', {
                                    'project-configuration-editor__tab--active': tab === selectedTab,
                                }), children: prettyCONSTName(tab) }, tab))) }), _jsx(PanelHeaderActions, { children: _jsx(PanelHeaderActionItem, { disabled: disableAddButton, onClick: addValue, title: addButtonTitle, children: _jsx(PlusIcon, {}) }) })] }), _jsxs(PanelContent, { className: "project-configuration-editor__content", children: [_jsx(PanelLoadingIndicator, { isLoading: isLoading }), selectedTab === CONFIGURATION_EDITOR_TAB.PROJECT_STRUCTURE && (_jsx(ProjectStructureEditor, { projectConfig: currentProjectConfiguration, isReadOnly: isReadOnly })), selectedTab === CONFIGURATION_EDITOR_TAB.PROJECT_DEPENDENCIES && (_jsx(ProjectDependencyEditor, {})), selectedTab === CONFIGURATION_EDITOR_TAB.PLATFORM_CONFIGURATIONS && (_jsx(ProjectPlatformVersionEditor, { projectConfig: currentProjectConfiguration, isReadOnly: isReadOnly })), selectedTab === CONFIGURATION_EDITOR_TAB.ADVANCED && (_jsx(ProjectAdvancedEditor, { projectConfig: currentProjectConfiguration, configState: configState, isReadOnly: isReadOnly }))] })] }) }));
});
//# sourceMappingURL=ProjectConfigurationEditor.js.map