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 { useApplicationStore } from '@finos/legend-application';
import { Dialog, Modal, ModalBody, ModalFooterButton, ModalFooter, ModalHeader, ModalFooterStatus, } from '@finos/legend-art';
import { PrimitiveType, } from '@finos/legend-graph';
import { prettyCONSTName } from '@finos/legend-shared';
import { observer } from 'mobx-react-lite';
import { useState } from 'react';
import { BasicValueSpecificationEditor } from './BasicValueSpecificationEditor.js';
// TODO we may want to further componentize this by removing the dialog wrapper
export const LambdaParameterValuesEditor = observer((props) => {
    const { lambdaParametersState, graph, observerContext } = props;
    const [isSubmitAction, setIsSubmitAction] = useState(false);
    const [isClosingAction, setIsClosingAction] = useState(false);
    const valuesEdtiorState = lambdaParametersState.parameterValuesEditorState;
    const close = () => {
        setIsClosingAction(true);
        valuesEdtiorState.close();
    };
    const applicationStore = useApplicationStore();
    const submitAction = valuesEdtiorState.submitAction;
    const submit = applicationStore.guardUnhandledError(async () => {
        if (submitAction) {
            setIsSubmitAction(true);
            close();
            await submitAction.handler();
        }
    });
    return (_jsx(Dialog, { open: Boolean(valuesEdtiorState.showModal), onClose: close, classes: {
            root: 'editor-modal__root-container',
            container: 'editor-modal__container',
            paper: 'editor-modal__content',
        }, children: _jsxs(Modal, { darkMode: !applicationStore.layoutService.TEMPORARY__isLightColorThemeEnabled, className: "editor-modal lambda-parameter-values__modal", children: [_jsx(ModalHeader, { title: "Set Parameter Values" }), _jsx(ModalBody, { className: "lambda-parameter-values__modal__body", children: lambdaParametersState.parameterStates.map((paramState) => {
                        const variableType = paramState.variableType ?? PrimitiveType.STRING;
                        return (_jsxs("div", { className: "panel__content__form__section", children: [_jsxs("div", { className: "lambda-parameter-values__value__label", children: [_jsx("div", { className: "lambda-parameter-values__value__label__name", children: paramState.parameter.name }), _jsx("div", { className: "lambda-parameter-values__value__label__type", children: variableType.name })] }), paramState.value && (_jsx(BasicValueSpecificationEditor, { valueSpecification: paramState.value, setValueSpecification: (val) => {
                                        paramState.setValue(val);
                                    }, graph: graph, observerContext: observerContext, typeCheckOption: {
                                        expectedType: variableType,
                                        match: variableType === PrimitiveType.DATETIME,
                                    }, className: "query-builder__parameters__value__editor", resetValue: () => paramState.mockParameterValue() }))] }, paramState.uuid));
                    }) }), _jsxs(ModalFooter, { children: [isClosingAction && (_jsx(ModalFooterStatus, { children: " Closing..." })), submitAction && (_jsx(ModalFooterButton, { inProgressText: isSubmitAction ? `${submitAction.label}...` : undefined, onClick: submit, text: prettyCONSTName(submitAction.label) })), _jsx(ModalFooterButton, { inProgressText: isClosingAction ? 'Closing...' : undefined, onClick: close, text: "Close", type: "secondary" })] })] }) }));
});
//# sourceMappingURL=LambdaParameterValuesEditor.js.map