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 { getMappingCompatibleClasses, } from '@finos/legend-graph';
import { QueryBuilderClassSelector } from '@finos/legend-query-builder';
import { observer } from 'mobx-react-lite';
import { CustomSelectorInput, PanelHeader, compareLabelFn, } from '@finos/legend-art';
import { returnUndefOnError } from '@finos/legend-shared';
const IsolatedDatabseQueryBuilderSetupPanelContext = observer((props) => {
    const { queryBuilderState } = props;
    const globalGraphManagerState = queryBuilderState.globalGraphManagerState;
    const getConnectionValue = (val) => returnUndefOnError(() => globalGraphManagerState.graph.getConnection(val));
    const database = queryBuilderState.database;
    const compConnections = queryBuilderState.compatibleConnections;
    const compConnectionsOptions = Array.from(compConnections.keys())
        .map((e) => ({ value: e, label: getConnectionValue(e)?.name ?? e }))
        .sort(compareLabelFn);
    const changeConnection = (val) => {
        if (val) {
            queryBuilderState.changeConnection(val.value);
        }
    };
    const connection = compConnections.get(queryBuilderState.connectionKey);
    const selectedConnection = connection
        ? {
            label: queryBuilderState.connectionKey,
            value: getConnectionValue(queryBuilderState.connectionKey)?.name ??
                queryBuilderState.connectionKey,
        }
        : undefined;
    const databaseOption = {
        value: database,
        label: database.path,
    };
    const classes = queryBuilderState.executionContextState.mapping
        ? getMappingCompatibleClasses(queryBuilderState.executionContextState.mapping, queryBuilderState.graphManagerState.usableClasses)
        : [];
    return (_jsxs("div", { className: "query-builder__setup__config-group", children: [_jsx(PanelHeader, { title: "properties" }), _jsxs("div", { className: "query-builder__setup__config-group__content", children: [_jsxs("div", { className: "query-builder__setup__config-group__item", children: [_jsx("label", { className: "btn--sm query-builder__setup__config-group__item__label", title: "store", htmlFor: "query-builder__setup__store-selector", children: "Store" }), _jsx(CustomSelectorInput, { inputId: "query-builder__setup__store-selector", className: "panel__content__form__section__dropdown query-builder__setup__config-group__item__selector", noMatchMessage: "No compatible mapping found for specified class", disabled: true, options: [], onChange: () => {
                                    // do nothing
                                }, value: databaseOption, darkMode: !queryBuilderState.applicationStore.layoutService
                                    .TEMPORARY__isLightColorThemeEnabled })] }), _jsxs("div", { className: "query-builder__setup__config-group__item", children: [_jsx("label", { className: "btn--sm query-builder__setup__config-group__item__label", title: "connection", htmlFor: "query-builder__setup__connection-selector", children: "Connection" }), _jsx(CustomSelectorInput, { inputId: "query-builder__setup__connection-selector", className: "panel__content__form__section__dropdown query-builder__setup__config-group__item__selector", noMatchMessage: "No compatible mapping found for specified class", disabled: compConnectionsOptions.length < 2, options: compConnectionsOptions, onChange: changeConnection, value: selectedConnection, darkMode: !queryBuilderState.applicationStore.layoutService
                                    .TEMPORARY__isLightColorThemeEnabled })] }), _jsx("div", { className: "query-builder__setup__config-group__item", children: _jsx(QueryBuilderClassSelector, { queryBuilderState: queryBuilderState, classes: classes, noMatchMessage: "No entities selected from" }) })] })] }));
});
export const renderDatabaseQueryBuilderSetupPanelContent = (queryBuilderState) => (_jsx(IsolatedDatabseQueryBuilderSetupPanelContext, { queryBuilderState: queryBuilderState }));
//# sourceMappingURL=IsolatedQueryDatabase.js.map