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 { observer } from 'mobx-react-lite';
import { useEditorStore } from '../../EditorStoreProvider.js';
import { INTERNAL__UnknownFunctionActivatorEdtiorState } from '../../../../stores/editor/editor-state/element-editor-state/function-activator/INTERNAL__UnknownFunctionActivatorEditorState.js';
import { ArrowRightIcon, BlankPanelContent, Panel, PanelContent, PanelHeader, ControlledDropdownMenu, MenuContent, MenuContentItem, CaretDownIcon, PanelLoadingIndicator, } from '@finos/legend-art';
import { useApplicationStore } from '@finos/legend-application';
import { flowResult } from 'mobx';
import { ProtocolValueBuilder } from '../ProtocolValueBuilder.js';
import { extractAnnotatedElementDocumentation, generateFunctionPrettyName, getClassProperty, } from '@finos/legend-graph';
import { returnUndefOnError } from '@finos/legend-shared';
import { ActivatorArtifactViewer } from './ActivatorArtifactViewer.js';
export const INTERNAL__UnknownFunctionActivatorEdtior = observer(() => {
    const editorStore = useEditorStore();
    const applicationStore = useApplicationStore();
    const editorState = editorStore.tabManagerState.getCurrentEditorState(INTERNAL__UnknownFunctionActivatorEdtiorState);
    const validate = () => {
        flowResult(editorState.validate()).catch(applicationStore.alertUnhandledError);
    };
    const renderArtifact = () => {
        flowResult(editorState.renderArtifact()).catch(applicationStore.alertUnhandledError);
    };
    const publishToSandbox = () => {
        flowResult(editorState.publishToSandbox()).catch(applicationStore.alertUnhandledError);
    };
    // function
    const valueBuilderState = editorState.protocolValueBuilderState;
    const functionFieldProperty = valueBuilderState
        ? returnUndefOnError(() => getClassProperty(valueBuilderState.type, 'function'))
        : undefined;
    const functionFieldDocumentation = functionFieldProperty
        ? extractAnnotatedElementDocumentation(functionFieldProperty)
        : undefined;
    return (_jsx("div", { className: "function-activator-editor", children: _jsxs(Panel, { children: [_jsx(PanelHeader, { title: "function activator" }), _jsx(PanelLoadingIndicator, { isLoading: Boolean(editorState.validateState.isInProgress ||
                        editorState.renderArtifactState.isInProgress ||
                        editorState.publishToSandboxState.isInProgress) }), _jsxs(PanelContent, { children: [_jsxs("div", { className: "function-activator-editor__content", children: [valueBuilderState && (_jsxs(_Fragment, { children: [_jsxs("div", { className: "panel__content__form", children: [_jsxs("div", { className: "panel__content__form__section", children: [_jsx("div", { className: "panel__content__form__section__header__label", children: "Function" }), functionFieldDocumentation && (_jsx("div", { className: "panel__content__form__section__header__prompt", children: functionFieldDocumentation })), _jsxs("div", { className: "function-activator-editor__function-pointer", children: [_jsx("input", { className: "panel__content__form__section__input", spellCheck: false, disabled: true, value: generateFunctionPrettyName(editorState.activator.function.value, {
                                                                        fullPath: true,
                                                                        spacing: false,
                                                                    }) }), _jsx("button", { className: "function-activator-editor__function-pointer__visit-btn btn--dark", title: "Go to Function", onClick: () => editorStore.graphEditorMode.openElement(editorState.activator.function.value), children: _jsx(ArrowRightIcon, {}) })] })] }), _jsx("div", { className: "panel__content__form__section", children: _jsx("div", { className: "panel__content__form__section__divider" }) })] }), _jsx(ProtocolValueBuilder, { builderState: valueBuilderState })] })), !valueBuilderState && (_jsx(BlankPanelContent, { children: `Can't display function activator in form mode` }))] }), _jsxs("div", { className: "function-activator-editor__footer", children: [_jsxs("div", { className: "function-activator-editor__footer__actions btn__dropdown-combo--primary", children: [_jsx("button", { className: "function-activator-editor__footer__actions__action btn--dark", onClick: validate, disabled: editorState.validateState.isInProgress, tabIndex: -1, children: "Validate" }), _jsx(ControlledDropdownMenu, { className: "function-activator-editor__footer__actions btn__dropdown-combo btn__dropdown-combo__dropdown-btn", title: "activator-artifact-dropdown", content: _jsx(MenuContent, { children: _jsx(MenuContentItem, { className: "btn__dropdown-combo__option", onClick: renderArtifact, children: "Render Artifact" }) }), menuProps: {
                                                anchorOrigin: {
                                                    vertical: 'bottom',
                                                    horizontal: 'right',
                                                },
                                                transformOrigin: {
                                                    vertical: 'top',
                                                    horizontal: 'right',
                                                },
                                            }, children: _jsx(CaretDownIcon, {}) })] }), _jsx("div", { className: "function-activator-editor__footer__actions btn__dropdown-combo--primary", children: _jsx("button", { className: "function-activator-editor__footer__actions__action btn--dark", onClick: publishToSandbox, disabled: editorState.publishToSandboxState.isInProgress, tabIndex: -1, children: "Publish to Sandbox" }) })] }), _jsx(ActivatorArtifactViewer, { artifact: editorState.artifact, setArtifact: (value) => editorState.setArtifact(value), darkMode: !applicationStore.layoutService
                                .TEMPORARY__isLightColorThemeEnabled })] })] }) }));
});
//# sourceMappingURL=INTERNAL__UnknownFunctionActivatorEdtior.js.map