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 { observer } from 'mobx-react-lite';
import { clsx, BlankPanelContent, Panel, PanelContent, PanelHeader, PanelHeaderActions, } from '@finos/legend-art';
import { prettyCONSTName } from '@finos/legend-shared';
import { QueryBuilderTDSPanel } from './QueryBuilderTDSPanel.js';
import { QueryBuilderGraphFetchPanel } from './QueryBuilderGraphFetchTreePanel.js';
import { QueryBuilderTDSState } from '../../stores/fetch-structure/tds/QueryBuilderTDSState.js';
import { QueryBuilderGraphFetchTreeState } from '../../stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeState.js';
import { QueryBuilderPanelIssueCountBadge } from '../shared/QueryBuilderPanelIssueCountBadge.js';
import { FETCH_STRUCTURE_IMPLEMENTATION } from '../../stores/fetch-structure/QueryBuilderFetchStructureImplementationState.js';
import { QUERY_BUILDER_TEST_ID } from '../../__lib__/QueryBuilderTesting.js';
import { onChangeFetchStructureImplementation } from '../../stores/fetch-structure/QueryBuilderFetchStructureState.js';
const QueryBuilderFetchStructureEditor = observer((props) => {
    const { queryBuilderState } = props;
    const fetchStructureState = queryBuilderState.fetchStructureState;
    const fetchStructureImplementation = fetchStructureState.implementation;
    if (fetchStructureImplementation instanceof QueryBuilderTDSState) {
        return _jsx(QueryBuilderTDSPanel, { tdsState: fetchStructureImplementation });
    }
    else if (fetchStructureImplementation instanceof QueryBuilderGraphFetchTreeState) {
        return (_jsx(QueryBuilderGraphFetchPanel, { graphFetchTreeState: fetchStructureImplementation }));
    }
    return (_jsx(PanelContent, { children: _jsx(BlankPanelContent, { children: _jsx("div", { className: "query-builder__unsupported-view__main", children: _jsx("div", { className: "query-builder__unsupported-view__summary", children: "Unsupported fetch structure" }) }) }) }));
});
export const QueryBuilderFetchStructurePanel = observer((props) => {
    const { queryBuilderState } = props;
    const fetchStructureState = queryBuilderState.fetchStructureState;
    const fetchConfig = queryBuilderState.workflowState.getFetchStructureLayoutConfig(queryBuilderState);
    return (_jsxs(Panel, { "data-testid": QUERY_BUILDER_TEST_ID.QUERY_BUILDER_FETCH_STRUCTURE, children: [_jsxs(PanelHeader, { children: [_jsxs("div", { className: "panel__header__title", children: [_jsx("div", { className: "panel__header__title__label", children: fetchConfig.label }), fetchStructureState.implementation.fetchStructureValidationIssues
                                .length !== 0 && (_jsx(QueryBuilderPanelIssueCountBadge, { issues: fetchStructureState.implementation
                                    .fetchStructureValidationIssues }))] }), fetchConfig.showInFetchPanel ? (_jsx(PanelHeaderActions, { children: _jsx("div", { className: "query-builder__fetch__structure__modes", children: Object.values(FETCH_STRUCTURE_IMPLEMENTATION).map((type) => (_jsx("button", { onClick: onChangeFetchStructureImplementation(type, fetchStructureState), className: clsx('query-builder__fetch__structure__mode', {
                                    'query-builder__fetch__structure__mode--selected': type === fetchStructureState.implementation.type,
                                }), children: prettyCONSTName(type) }, type))) }) })) : null] }), _jsx(QueryBuilderFetchStructureEditor, { queryBuilderState: queryBuilderState })] }));
});
//# sourceMappingURL=QueryBuilderFetchStructurePanel.js.map