import { jsx as _jsx, jsxs as _jsxs } 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 { ResizablePanel, ResizablePanelGroup, ResizablePanelSplitter, ResizablePanelSplitterLine, clsx, PlusIcon, ContextMenu, BlankPanelPlaceholder, MenuContent, MenuContentItem, BlankPanelContent, PanelHeaderActionItem, PanelHeaderActions, Panel, PanelHeader, } from '@finos/legend-art';
import { observer } from 'mobx-react-lite';
import { ServiceTestDataEditor } from './ServiceTestDataEditor.js';
import { ServiceTestsEditor } from './ServiceTestsEditor.js';
import { forwardRef } from 'react';
import { testSuite_setId } from '../../../../../stores/graph-modifier/Testable_GraphModifierHelper.js';
import { guaranteeNonNullable } from '@finos/legend-shared';
import { useApplicationNavigationContext } from '@finos/legend-application';
import { LEGEND_STUDIO_APPLICATION_NAVIGATION_CONTEXT_KEY } from '../../../../../__lib__/LegendStudioApplicationNavigationContext.js';
import { RenameModal } from '../../testable/TestableSharedComponents.js';
export const ServiceTestSuiteEditor = observer((props) => {
    const { serviceTestSuiteState } = props;
    const serviceRuntime = serviceTestSuiteState.testableState.serviceEditorState.executionState
        .serviceExecutionParameters?.runtime;
    return (_jsx("div", { className: "service-test-suite-editor", children: serviceRuntime ? (_jsxs(ResizablePanelGroup, { orientation: "horizontal", children: [_jsxs(ResizablePanel, { size: 300, minSize: 28, children: [serviceTestSuiteState.testDataState && (_jsx(ServiceTestDataEditor, { testDataState: serviceTestSuiteState.testDataState })), !serviceTestSuiteState.testDataState && (_jsx(BlankPanelContent, { children: "No test data specified" }))] }), _jsx(ResizablePanelSplitter, { children: _jsx(ResizablePanelSplitterLine, { color: "var(--color-dark-grey-200)" }) }), _jsx(ResizablePanel, { minSize: 56, children: _jsx(ServiceTestsEditor, { suiteState: serviceTestSuiteState }) })] })) : (_jsx(ServiceTestsEditor, { suiteState: serviceTestSuiteState })) }));
});
const ServiceSuiteHeaderTabContextMenu = observer(forwardRef(function MappingEditorHeaderTabContextMenu(props, ref) {
    const { testSuite, testableState } = props;
    const deleteSuite = () => testableState.deleteSuite(testSuite);
    const rename = () => testableState.setSuiteToRename(testSuite);
    return (_jsxs(MenuContent, { ref: ref, children: [_jsx(MenuContentItem, { onClick: rename, children: "Rename" }), _jsx(MenuContentItem, { onClick: deleteSuite, children: "Delete" })] }));
}));
export const ServiceTestableEditor = observer((props) => {
    const { serviceTestableState } = props;
    const serviceEditorState = serviceTestableState.serviceEditorState;
    const service = serviceEditorState.service;
    const selectedSuite = serviceTestableState.selectedSuiteState?.suite;
    const changeSuite = (suite) => {
        serviceTestableState.changeSuite(suite);
    };
    const addSuite = () => serviceTestableState.addTestSuite();
    const isReadOnly = serviceEditorState.isReadOnly;
    const renameSuite = (val) => testSuite_setId(guaranteeNonNullable(serviceTestableState.suiteToRename), val);
    useApplicationNavigationContext(LEGEND_STUDIO_APPLICATION_NAVIGATION_CONTEXT_KEY.SERVICE_EDITOR_TEST);
    return (_jsxs(Panel, { className: "service-test-suite-editor", children: [_jsxs(PanelHeader, { children: [service.tests.length ? (_jsx(PanelHeader, { className: "service-test-suite-editor__header service-test-suite-editor__header--with-tabs", children: _jsx("div", { className: "uml-element-editor__tabs", children: service.tests.map((suite) => (_jsx("div", { onClick: () => changeSuite(suite), className: clsx('service-test-suite-editor__tab', {
                                    'service-test-suite-editor__tab--active': suite === selectedSuite,
                                }), children: _jsx(ContextMenu, { className: "mapping-editor__header__tab__content", content: _jsx(ServiceSuiteHeaderTabContextMenu, { testableState: serviceTestableState, testSuite: suite }), children: suite.id }) }, suite.id))) }) })) : (_jsx("div", {})), _jsx(PanelHeaderActions, { children: _jsx(PanelHeaderActionItem, { onClick: addSuite, title: "Add Service Suite", children: _jsx(PlusIcon, {}) }) })] }), _jsxs(Panel, { className: "service-test-suite-editor", children: [serviceTestableState.selectedSuiteState && (_jsx(ServiceTestSuiteEditor, { serviceTestSuiteState: serviceTestableState.selectedSuiteState })), !service.tests.length && (_jsx(BlankPanelPlaceholder, { text: "Add Test Suite", onClick: addSuite, clickActionType: "add", tooltipText: "Click to add test suite" })), serviceTestableState.suiteToRename && (_jsx(RenameModal, { val: serviceTestableState.suiteToRename.id, isReadOnly: isReadOnly, showModal: true, closeModal: () => serviceTestableState.setSuiteToRename(undefined), setValue: renameSuite }))] })] }));
});
//# sourceMappingURL=ServiceTestableEditor.js.map