import { jsx as _jsx, Fragment as _Fragment, 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 { HammerIcon, ResizablePanelGroup, ResizablePanel, ResizablePanelSplitter, HackerIcon, ControlledDropdownMenu, MenuContent, MenuContentItem, MenuContentItemIcon, MenuContentItemLabel, CheckIcon, CaretDownIcon, DiffIcon, MenuContentDivider, Dialog, Modal, ModalBody, ModalFooter, ModalHeader, BlankPanelContent, ModalFooterButton, CalendarClockIcon, ChatIcon, PanelLoadingIndicator, SerializeIcon, DataAccessIcon, AssistantIcon, clsx, DocumentationIcon, CodeIcon, QuestionIcon, } from '@finos/legend-art';
import { QueryBuilderFilterPanel } from './filter/QueryBuilderFilterPanel.js';
import { QueryBuilderExplorerPanel } from './explorer/QueryBuilderExplorerPanel.js';
import { QueryBuilderSidebar } from './QueryBuilderSideBar.js';
import { QueryBuilderResultPanel } from './result/QueryBuilderResultPanel.js';
import { QueryBuilderTextEditor } from './QueryBuilderTextEditor.js';
import { QUERY_BUILDER_LAMBDA_WRITER_MODE, } from '../stores/QueryBuilderState.js';
import { QueryBuilderTextEditorMode } from '../stores/QueryBuilderTextEditorState.js';
import { QueryBuilderFetchStructurePanel } from './fetch-structure/QueryBuilderFetchStructurePanel.js';
import { QUERY_BUILDER_TEST_ID } from '../__lib__/QueryBuilderTesting.js';
import { flowResult } from 'mobx';
import { QueryBuilderUnsupportedQueryEditor } from './QueryBuilderUnsupportedQueryEditor.js';
import { BackdropContainer, useCommands, ActionAlertActionType, ActionAlertType, useApplicationStore, } from '@finos/legend-application';
import { QueryBuilderParametersPanel } from './QueryBuilderParametersPanel.js';
import { QueryBuilderFunctionsExplorerPanel } from './explorer/QueryBuilderFunctionsExplorerPanel.js';
import { QueryBuilderTDSState } from '../stores/fetch-structure/tds/QueryBuilderTDSState.js';
import { QueryBuilderDiffViewPanelDiaglog } from './QueryBuilderDiffPanel.js';
import { guaranteeType, returnUndefOnError } from '@finos/legend-shared';
import { QueryBuilderGraphFetchTreeState } from '../stores/fetch-structure/graph-fetch/QueryBuilderGraphFetchTreeState.js';
import { QueryBuilderPostTDSPanel } from './fetch-structure/QueryBuilderPostTDSPanel.js';
import { QueryBuilderConstantExpressionPanel } from './QueryBuilderConstantExpressionPanel.js';
import { QUERY_BUILDER_SETTING_KEY } from '../__lib__/QueryBuilderSetting.js';
import { QUERY_BUILDER_COMPONENT_ELEMENT_ID } from './QueryBuilderComponentElement.js';
import { DataAccessOverview } from './data-access/DataAccessOverview.js';
import { QueryChat } from './QueryChat.js';
import { Fragment, useEffect, useRef } from 'react';
import { RedoButton, UndoButton } from '@finos/legend-lego/application';
import { FETCH_STRUCTURE_IMPLEMENTATION } from '../stores/fetch-structure/QueryBuilderFetchStructureImplementationState.js';
import { onChangeFetchStructureImplementation } from '../stores/fetch-structure/QueryBuilderFetchStructureState.js';
import { QUERY_BUILDER_DOCUMENTATION_KEY } from '../__lib__/QueryBuilderDocumentation.js';
import { QueryBuilderTelemetryHelper } from '../__lib__/QueryBuilderTelemetryHelper.js';
import { QueryDataCubeViewer } from './data-cube/QueryBuilderDataCube.js';
const QueryBuilderPostGraphFetchPanel = observer((props) => {
    const { graphFetchState } = props;
    if (!graphFetchState.TEMPORARY__showPostFetchStructurePanel) {
        return null;
    }
    return (_jsx(QueryBuilderFilterPanel, { queryBuilderState: graphFetchState.queryBuilderState }));
});
const QueryBuilderStatusBar = observer((props) => {
    const { queryBuilderState } = props;
    const applicationStore = useApplicationStore();
    const showDiff = () => queryBuilderState.changeDetectionState.showDiffViewPanel();
    const openLambdaEditor = (mode) => queryBuilderState.textEditorState.openModal(mode);
    const compile = applicationStore.guardUnhandledError(() => flowResult(queryBuilderState.compileQuery()));
    const toggleAssistant = () => applicationStore.assistantService.toggleAssistant();
    const openQueryChat = () => queryBuilderState.setIsQueryChatOpened(true);
    return (_jsxs("div", { className: "query-builder__status-bar", children: [_jsx("div", { className: "query-builder__status-bar__left" }), _jsxs("div", { className: "query-builder__status-bar__right", children: [queryBuilderState.changeDetectionState.initState.hasCompleted && (_jsxs(_Fragment, { children: [_jsx("button", { className: clsx('query-builder__status-bar__action query-builder__status-bar__view-diff-btn'), disabled: !queryBuilderState.changeDetectionState.hasChanged ||
                                    !queryBuilderState.canBuildQuery, onClick: showDiff, tabIndex: -1, title: !queryBuilderState.canBuildQuery
                                    ? 'Please fix query errors to show changes'
                                    : queryBuilderState.changeDetectionState.hasChanged
                                        ? 'Show changes'
                                        : 'Query has not been changed', children: _jsx(DiffIcon, {}) }), queryBuilderState.changeDetectionState.diffViewState && (_jsx(QueryBuilderDiffViewPanelDiaglog, { diffViewState: queryBuilderState.changeDetectionState.diffViewState }))] })), queryBuilderState.isQueryChatOpened && (_jsx(QueryChat, { queryBuilderState: queryBuilderState })), !queryBuilderState.config?.TEMPORARY__disableQueryBuilderChat && (_jsx("button", { className: clsx('query-builder__status-bar__action query-builder__status-bar__action__toggler', {
                            'query-builder__status-bar__action__toggler--toggled': queryBuilderState.isQueryChatOpened === true,
                        }), onClick: openQueryChat, tabIndex: -1, title: "Open Query Chat", children: _jsx(ChatIcon, {}) })), _jsx("button", { className: clsx('query-builder__status-bar__action query-builder__status-bar__compile-btn', {
                            'query-builder__status-bar__compile-btn--wiggling': queryBuilderState.queryCompileState.isInProgress,
                        }), disabled: queryBuilderState.queryCompileState.isInProgress, onClick: compile, tabIndex: -1, title: "Compile (F9)", children: _jsx(HammerIcon, {}) }), _jsx("button", { className: clsx('query-builder__status-bar__action query-builder__status-bar__action__toggler', {
                            'query-builder__status-bar__action__toggler--toggled': queryBuilderState.textEditorState.mode ===
                                QueryBuilderTextEditorMode.JSON,
                        }), onClick: () => openLambdaEditor(QueryBuilderTextEditorMode.JSON), tabIndex: -1, disabled: !queryBuilderState.canBuildQuery, title: !queryBuilderState.canBuildQuery
                            ? 'Please fix query errors to show query protocol'
                            : 'Show Query Protocol', children: `{ }` }), _jsx("button", { className: clsx('query-builder__status-bar__action query-builder__status-bar__action__toggler', {
                            'query-builder__status-bar__action__toggler--toggled': queryBuilderState.textEditorState.mode ===
                                QueryBuilderTextEditorMode.TEXT,
                        }), onClick: () => openLambdaEditor(QueryBuilderTextEditorMode.TEXT), tabIndex: -1, disabled: !queryBuilderState.canBuildQuery, title: !queryBuilderState.canBuildQuery
                            ? 'Please fix query errors to edit in Pure'
                            : 'Edit Pure', children: _jsx(HackerIcon, {}) }), _jsx("button", { className: clsx('query-builder__status-bar__action query-builder__status-bar__action__toggler', {
                            'query-builder__status-bar__action__toggler--toggled': !applicationStore.assistantService.isHidden,
                        }), onClick: toggleAssistant, tabIndex: -1, disabled: queryBuilderState.applicationStore.assistantService.isDisabled, title: queryBuilderState.applicationStore.assistantService.isDisabled
                            ? 'Virtual Assistant is disabled'
                            : 'Toggle assistant', children: _jsx(AssistantIcon, {}) })] })] }));
});
export const QueryBuilder = observer((props) => {
    const { queryBuilderState } = props;
    const applicationStore = queryBuilderState.applicationStore;
    const ref = useRef(null);
    const isQuerySupported = queryBuilderState.isQuerySupported;
    const fetchStructureState = queryBuilderState.fetchStructureState;
    const isTDSState = fetchStructureState.implementation instanceof QueryBuilderTDSState;
    const openLambdaEditor = (mode) => queryBuilderState.textEditorState.openModal(mode);
    const openPure = () => queryBuilderState.textEditorState.openModal(QueryBuilderTextEditorMode.TEXT, true);
    const toggleShowFunctionPanel = () => {
        QueryBuilderTelemetryHelper.logEvent_TogglePanelFunctionExplorer(applicationStore.telemetryService);
        queryBuilderState.setShowFunctionsExplorerPanel(!queryBuilderState.showFunctionsExplorerPanel);
    };
    const toggleShowParameterPanel = () => {
        queryBuilderState.setShowParametersPanel(!queryBuilderState.showParametersPanel);
    };
    const toggleConstantPanel = () => {
        queryBuilderState.constantState.setShowConstantPanel(!queryBuilderState.constantState.showConstantPanel);
    };
    const toggleShowFilterPanel = () => {
        queryBuilderState.filterState.setShowPanel(!queryBuilderState.filterState.showPanel);
    };
    const toggleShowPostFilterPanel = () => {
        if (queryBuilderState.fetchStructureState.implementation instanceof
            QueryBuilderTDSState) {
            const tdsState = queryBuilderState.fetchStructureState.implementation;
            tdsState.setShowPostFilterPanel(!tdsState.showPostFilterPanel);
            queryBuilderState.applicationStore.settingService.persistValue(QUERY_BUILDER_SETTING_KEY.SHOW_POST_FILTER_PANEL, tdsState.showPostFilterPanel);
        }
    };
    const toggleEnableCalendar = () => {
        if (queryBuilderState.isCalendarEnabled) {
            queryBuilderState.applicationStore.alertService.setActionAlertInfo({
                message: 'You are about to disable calendar aggregation operations. This will remove all the calendar aggreagtions you added to the query.',
                prompt: ' Do you want to proceed?',
                type: ActionAlertType.CAUTION,
                actions: [
                    {
                        label: 'Proceed',
                        type: ActionAlertActionType.PROCEED_WITH_CAUTION,
                        handler: () => {
                            if (queryBuilderState.fetchStructureState
                                .implementation instanceof QueryBuilderTDSState) {
                                queryBuilderState.fetchStructureState.implementation.aggregationState.disableCalendar();
                            }
                        },
                    },
                    {
                        label: 'Cancel',
                        type: ActionAlertActionType.PROCEED,
                        default: true,
                    },
                ],
            });
        }
        else {
            queryBuilderState.applicationStore.alertService.setActionAlertInfo({
                message: 'You are about to enable calendar aggregation operations. This will let you add calendar functions to the aggregation operations that you perform on projection columns, but this would require your calendar database to be included in your database.',
                prompt: ' Do you want to proceed?',
                type: ActionAlertType.CAUTION,
                actions: [
                    {
                        label: 'Proceed',
                        type: ActionAlertActionType.PROCEED_WITH_CAUTION,
                        handler: () => queryBuilderState.setIsCalendarEnabled(true),
                    },
                    {
                        label: 'Cancel',
                        type: ActionAlertActionType.PROCEED,
                        default: true,
                    },
                ],
            });
        }
    };
    const toggleTypedRelation = () => {
        if (queryBuilderState.isFetchStructureTyped) {
            queryBuilderState.setLambdaWriteMode(QUERY_BUILDER_LAMBDA_WRITER_MODE.STANDARD);
        }
        else {
            queryBuilderState.applicationStore.alertService.setActionAlertInfo({
                message: 'You are about to change to use typed TDS functions. Please proceed with caution as this is still an experimental feature.',
                prompt: ' Do you want to proceed?',
                type: ActionAlertType.CAUTION,
                actions: [
                    {
                        label: 'Proceed',
                        type: ActionAlertActionType.PROCEED_WITH_CAUTION,
                        handler: () => queryBuilderState.setLambdaWriteMode(QUERY_BUILDER_LAMBDA_WRITER_MODE.TYPED_FETCH_STRUCTURE),
                    },
                    {
                        label: 'Cancel',
                        type: ActionAlertActionType.PROCEED,
                        default: true,
                    },
                ],
            });
        }
    };
    const editPure = () => {
        openLambdaEditor(QueryBuilderTextEditorMode.TEXT);
    };
    const showPure = () => {
        openPure();
    };
    const showProtocol = () => {
        openLambdaEditor(QueryBuilderTextEditorMode.JSON);
    };
    const openCheckEntitlmentsEditor = () => {
        queryBuilderState.checkEntitlementsState.setShowCheckEntitlementsViewer(true);
    };
    const handleClose = () => {
        queryBuilderState.checkEntitlementsState.setShowCheckEntitlementsViewer(false);
    };
    useCommands(queryBuilderState);
    const toggleShowOLAPGroupByPanel = () => {
        if (isTDSState) {
            const tdsState = guaranteeType(queryBuilderState.fetchStructureState.implementation, QueryBuilderTDSState);
            tdsState.setShowWindowFuncPanel(!tdsState.showWindowFuncPanel);
        }
    };
    const showPostFetchStructurePanel = queryBuilderState.fetchStructureState.implementation
        .TEMPORARY__showPostFetchStructurePanel;
    const renderPostFetchStructure = () => {
        if (fetchStructureState.implementation instanceof QueryBuilderTDSState) {
            return (_jsx(QueryBuilderPostTDSPanel, { tdsState: fetchStructureState.implementation }));
        }
        else if (fetchStructureState.implementation instanceof
            QueryBuilderGraphFetchTreeState) {
            return (_jsx(QueryBuilderPostGraphFetchPanel, { graphFetchState: fetchStructureState.implementation }));
        }
        return null;
    };
    const undo = () => {
        queryBuilderState.changeHistoryState.undo();
    };
    const redo = () => {
        queryBuilderState.changeHistoryState.redo();
    };
    const queryDocEntry = applicationStore.documentationService.getDocEntry(QUERY_BUILDER_DOCUMENTATION_KEY.TUTORIAL_QUERY_BUILDER);
    const frequentlyAskedQuestionEntry = applicationStore.documentationService.getDocEntry(QUERY_BUILDER_DOCUMENTATION_KEY.FREQUENTLY_ASKED_QUESTIONS);
    const supportTicketsEntry = applicationStore.documentationService.getDocEntry(QUERY_BUILDER_DOCUMENTATION_KEY.SUPPORT_TICKETS_LINK);
    const openQueryTutorial = () => {
        if (queryDocEntry?.url) {
            applicationStore.navigationService.navigator.visitAddress(queryDocEntry.url);
        }
    };
    const openFrequentlyAskedQuestions = () => {
        if (frequentlyAskedQuestionEntry?.url) {
            applicationStore.navigationService.navigator.visitAddress(frequentlyAskedQuestionEntry.url);
        }
    };
    const openSupportTickets = () => {
        if (supportTicketsEntry?.url) {
            applicationStore.navigationService.navigator.visitAddress(supportTicketsEntry.url);
        }
    };
    const toggleAssistant = () => applicationStore.assistantService.toggleAssistant();
    const extraHelpMenuContentItems = applicationStore.pluginManager
        .getApplicationPlugins()
        .flatMap((plugin) => plugin.getExtraQueryBuilderHelpMenuActionConfigurations?.() ?? [])
        .filter((item) => !item.disableFunc?.(queryBuilderState))
        .map((item) => (_jsxs(MenuContentItem, { title: item.title ?? '', disabled: item.disableFunc?.(queryBuilderState) ?? false, onClick: () => item.onClick(queryBuilderState), children: [item.icon && _jsx(MenuContentItemIcon, { children: item.icon }), _jsx(MenuContentItemLabel, { children: item.label })] }, item.key)));
    const compileQuery = applicationStore.guardUnhandledError(() => flowResult(queryBuilderState.compileQuery()));
    const showDiff = () => queryBuilderState.changeDetectionState.showDiffViewPanel();
    useEffect(() => {
        // this condition is for passing all exisitng tests because when we initialize a queryBuilderState for a test,
        // we use an empty RawLambda with an empty class and this useEffect is called earlier than initializeWithQuery()
        if (queryBuilderState.isQuerySupported &&
            queryBuilderState.sourceElement &&
            queryBuilderState.canBuildQuery) {
            const calculatedQuery = returnUndefOnError(() => queryBuilderState.buildQuery());
            if (calculatedQuery) {
                queryBuilderState.changeHistoryState.cacheNewQuery(calculatedQuery);
            }
        }
    }, [queryBuilderState, queryBuilderState.hashCode]);
    return (_jsxs("div", { "data-testid": QUERY_BUILDER_TEST_ID.QUERY_BUILDER, className: "query-builder", ref: ref, children: [_jsx(BackdropContainer, { elementId: QUERY_BUILDER_COMPONENT_ELEMENT_ID.BACKDROP_CONTAINER }), _jsxs("div", { className: clsx('query-builder__body', {
                    'query-builder__body__status-bar': queryBuilderState.workflowState.showStatusBar,
                }), children: [_jsx(PanelLoadingIndicator, { isLoading: queryBuilderState.resultState.exportState.isInProgress }), _jsxs("div", { className: "query-builder__content", children: [_jsxs("div", { "data-testid": QUERY_BUILDER_TEST_ID.QUERY_BUILDER_ACTIONS, className: "query-builder__header", children: [_jsxs("div", { className: "query-builder__header__statuses", children: [queryBuilderState.isCalendarEnabled && (_jsx("div", { className: "query-builder__header__status", title: "Used calendar aggregation", children: _jsx(CalendarClockIcon, { className: "query-builder__header__status__icon--calendar" }) })), applicationStore.pluginManager
                                                .getApplicationPlugins()
                                                .flatMap((plugin) => plugin.getExtraQueryBuilderHeaderTitleConfigurations?.() ?? [])
                                                .map((actionConfig) => (_jsx(Fragment, { children: actionConfig.renderer(queryBuilderState) }, actionConfig.key)))] }), _jsxs("div", { className: "query-builder__header__actions", children: [_jsxs("div", { className: "query-builder__header__actions__undo-redo", children: [_jsx(UndoButton, { parent: ref, canUndo: queryBuilderState.changeHistoryState.canUndo &&
                                                            queryBuilderState.isQuerySupported, undo: undo }), _jsx(RedoButton, { parent: ref, canRedo: queryBuilderState.changeHistoryState.canRedo &&
                                                            queryBuilderState.isQuerySupported, redo: redo })] }), applicationStore.pluginManager
                                                .getApplicationPlugins()
                                                .flatMap((plugin) => plugin.getExtraQueryBuilderHeaderActionConfigurations?.() ??
                                                [])
                                                .sort((A, B) => B.category - A.category)
                                                .map((actionConfig) => (_jsx(Fragment, { children: actionConfig.renderer(queryBuilderState) }, actionConfig.key))), _jsxs(ControlledDropdownMenu, { className: "query-builder__header__advanced-dropdown", title: "Show Advanced Menu...", content: _jsxs(MenuContent, { children: [_jsxs(MenuContentItem, { onClick: toggleShowFunctionPanel, disabled: !queryBuilderState.isQuerySupported, children: [_jsx(MenuContentItemIcon, { children: queryBuilderState.showFunctionsExplorerPanel ? (_jsx(CheckIcon, {})) : null }), _jsx(MenuContentItemLabel, { children: "Show Function(s)" })] }), !queryBuilderState.isParameterSupportDisabled && (_jsxs(MenuContentItem, { onClick: toggleShowParameterPanel, disabled: !queryBuilderState.isQuerySupported ||
                                                                queryBuilderState.parametersState.parameterStates.filter((paramState) => !queryBuilderState.milestoningState.isMilestoningParameter(paramState.parameter)).length > 0, children: [_jsx(MenuContentItemIcon, { children: queryBuilderState.showParametersPanel ? (_jsx(CheckIcon, {})) : null }), _jsx(MenuContentItemLabel, { children: "Show Parameter(s)" })] })), _jsxs(MenuContentItem, { onClick: toggleConstantPanel, disabled: !queryBuilderState.isQuerySupported ||
                                                                queryBuilderState.constantState.constants.length > 0, children: [_jsx(MenuContentItemIcon, { children: queryBuilderState.constantState
                                                                        .showConstantPanel ? (_jsx(CheckIcon, {})) : null }), _jsx(MenuContentItemLabel, { children: "Show Constant(s)" })] }), _jsxs(MenuContentItem, { onClick: toggleShowFilterPanel, disabled: !queryBuilderState.isQuerySupported ||
                                                                Array.from(queryBuilderState.filterState.nodes.values()).length > 0, children: [_jsx(MenuContentItemIcon, { children: queryBuilderState.filterState.showPanel ? (_jsx(CheckIcon, {})) : null }), _jsx(MenuContentItemLabel, { children: "Show Filter" })] }), _jsxs(MenuContentItem, { onClick: onChangeFetchStructureImplementation(isTDSState
                                                                ? FETCH_STRUCTURE_IMPLEMENTATION.GRAPH_FETCH
                                                                : FETCH_STRUCTURE_IMPLEMENTATION.TABULAR_DATA_STRUCTURE, fetchStructureState), disabled: !queryBuilderState.isQuerySupported, children: [_jsx(MenuContentItemIcon, { children: isTDSState ? _jsx(CheckIcon, {}) : null }), _jsx(MenuContentItemLabel, { children: "Tabular Data Structure" })] }), _jsx(MenuContentDivider, {}), _jsxs(MenuContentItem, { onClick: toggleShowOLAPGroupByPanel, disabled: !queryBuilderState.isQuerySupported ||
                                                                !(queryBuilderState.fetchStructureState
                                                                    .implementation instanceof QueryBuilderTDSState) ||
                                                                queryBuilderState.fetchStructureState.implementation
                                                                    .windowState.windowColumns.length > 0, children: [_jsx(MenuContentItemIcon, { children: isTDSState &&
                                                                        guaranteeType(queryBuilderState.fetchStructureState
                                                                            .implementation, QueryBuilderTDSState).showWindowFuncPanel ? (_jsx(CheckIcon, {})) : null }), _jsx(MenuContentItemLabel, { children: "Show Window Function(s)" })] }), _jsxs(MenuContentItem, { onClick: toggleShowPostFilterPanel, disabled: !queryBuilderState.isQuerySupported ||
                                                                !(queryBuilderState.fetchStructureState
                                                                    .implementation instanceof QueryBuilderTDSState) ||
                                                                Array.from(queryBuilderState.fetchStructureState.implementation.postFilterState.nodes.values()).length > 0, children: [_jsx(MenuContentItemIcon, { children: queryBuilderState.fetchStructureState
                                                                        .implementation instanceof QueryBuilderTDSState &&
                                                                        queryBuilderState.fetchStructureState.implementation
                                                                            .showPostFilterPanel ? (_jsx(CheckIcon, {})) : null }), _jsx(MenuContentItemLabel, { children: "Show Post-Filter" })] }), _jsxs(MenuContentItem, { onClick: toggleEnableCalendar, disabled: !queryBuilderState.isQuerySupported ||
                                                                !(queryBuilderState.fetchStructureState
                                                                    .implementation instanceof QueryBuilderTDSState), children: [_jsx(MenuContentItemIcon, { children: queryBuilderState.isCalendarEnabled ? (_jsx(CheckIcon, {})) : (_jsx(CalendarClockIcon, {})) }), _jsx(MenuContentItemLabel, { children: "Enable Calendar" })] }), _jsxs(MenuContentItem, { onClick: toggleTypedRelation, disabled: !queryBuilderState.isQuerySupported ||
                                                                !(queryBuilderState.fetchStructureState
                                                                    .implementation instanceof QueryBuilderTDSState), children: [_jsx(MenuContentItemIcon, { children: queryBuilderState.isFetchStructureTyped ? (_jsx(CheckIcon, {})) : null }), _jsx(MenuContentItemLabel, { children: "Enable Typed TDS (BETA)" })] }), _jsx(MenuContentDivider, {}), _jsxs(MenuContentItem, { onClick: openCheckEntitlmentsEditor, disabled: (queryBuilderState.isQuerySupported &&
                                                                queryBuilderState.fetchStructureState
                                                                    .implementation instanceof QueryBuilderTDSState &&
                                                                queryBuilderState.fetchStructureState.implementation
                                                                    .projectionColumns.length === 0) ||
                                                                !queryBuilderState.canBuildQuery, title: !queryBuilderState.canBuildQuery
                                                                ? 'Please fix query errors to check entitlements'
                                                                : '', children: [_jsx(MenuContentItemIcon, { children: _jsx(DataAccessIcon, {}) }), _jsx(MenuContentItemLabel, { children: "Check Entitlements" })] }), _jsxs(MenuContentItem, { onClick: editPure, disabled: !queryBuilderState.canBuildQuery, title: !queryBuilderState.canBuildQuery
                                                                ? 'Please fix query errors to edit in Pure'
                                                                : undefined, children: [_jsx(MenuContentItemIcon, { children: _jsx(HackerIcon, {}) }), _jsx(MenuContentItemLabel, { children: "Edit Pure" })] }), _jsxs(MenuContentItem, { onClick: showPure, disabled: !queryBuilderState.canBuildQuery, title: !queryBuilderState.canBuildQuery
                                                                ? 'Please fix query errors to edit in Pure'
                                                                : undefined, children: [_jsx(MenuContentItemIcon, { children: _jsx(CodeIcon, {}) }), _jsx(MenuContentItemLabel, { children: "Show Pure" })] }), _jsxs(MenuContentItem, { onClick: showProtocol, disabled: !queryBuilderState.canBuildQuery, title: !queryBuilderState.canBuildQuery
                                                                ? 'Please fix query errors to show query protocol'
                                                                : undefined, children: [_jsx(MenuContentItemIcon, { children: _jsx(SerializeIcon, {}) }), _jsx(MenuContentItemLabel, { children: "Show Protocol" })] }), _jsxs(MenuContentItem, { onClick: compileQuery, children: [_jsx(MenuContentItemIcon, { children: _jsx(HammerIcon, {}) }), _jsx(MenuContentItemLabel, { children: "Compile Query (F9)" })] }), queryBuilderState.changeDetectionState.initState
                                                            .hasCompleted && (_jsxs(MenuContentItem, { disabled: !queryBuilderState.changeDetectionState.hasChanged, onClick: showDiff, title: queryBuilderState.changeDetectionState.hasChanged
                                                                ? 'Show changes'
                                                                : 'Query has not been changed', children: [_jsx(MenuContentItemIcon, { children: _jsx(DiffIcon, {}) }), _jsx(MenuContentItemLabel, { children: "Show Query Diff" })] }))] }), menuProps: {
                                                    anchorOrigin: { vertical: 'bottom', horizontal: 'right' },
                                                    transformOrigin: { vertical: 'top', horizontal: 'right' },
                                                    elevation: 7,
                                                }, children: [_jsx("div", { className: "query-builder__header__advanced-dropdown__label", children: "Advanced" }), _jsx(CaretDownIcon, { className: "query-builder__header__advanced-dropdown__icon" })] }), _jsxs(ControlledDropdownMenu, { className: "query-builder__header__advanced-dropdown", content: _jsxs(MenuContent, { children: [extraHelpMenuContentItems, queryDocEntry && (_jsxs(MenuContentItem, { onClick: openQueryTutorial, children: [_jsx(MenuContentItemIcon, { children: _jsx(DocumentationIcon, {}) }), _jsx(MenuContentItemLabel, { children: "Open Documentation" })] })), frequentlyAskedQuestionEntry && (_jsxs(MenuContentItem, { onClick: openFrequentlyAskedQuestions, children: [_jsx(MenuContentItemIcon, { children: _jsx(QuestionIcon, {}) }), _jsx(MenuContentItemLabel, { children: "Frequently Asked Questions" })] })), supportTicketsEntry && (_jsxs(MenuContentItem, { onClick: openSupportTickets, children: [_jsx(MenuContentItemIcon, { children: _jsx(QuestionIcon, {}) }), _jsx(MenuContentItemLabel, { children: "Open Support Tickets" })] })), _jsxs(MenuContentItem, { onClick: toggleAssistant, disabled: queryBuilderState.applicationStore.assistantService
                                                                .isDisabled, title: queryBuilderState.applicationStore.assistantService
                                                                .isDisabled
                                                                ? 'Virtual Assistant is disabled'
                                                                : '', children: [_jsx(MenuContentItemIcon, { children: !applicationStore.assistantService.isHidden ? (_jsx(CheckIcon, {})) : (_jsx(AssistantIcon, {})) }), _jsx(MenuContentItemLabel, { children: "Show Virtual Assistant" })] })] }), children: [_jsx("div", { className: "query-builder__header__advanced-dropdown__label", title: "See more options", children: "Help..." }), _jsx(CaretDownIcon, { className: "query-builder__header__advanced-dropdown__icon" })] })] })] }), _jsx("div", { className: "query-builder__main", children: _jsxs(ResizablePanelGroup, { orientation: "horizontal", children: [_jsx(ResizablePanel, { minSize: 120, children: isQuerySupported ? (_jsxs(ResizablePanelGroup, { orientation: "vertical", children: [_jsx(ResizablePanel, { size: 450, minSize: 300, children: _jsx(QueryBuilderSidebar, { queryBuilderState: queryBuilderState, children: _jsxs(ResizablePanelGroup, { orientation: "horizontal", children: [_jsx(ResizablePanel, { minSize: 40, direction: 1, children: _jsx(QueryBuilderExplorerPanel, { queryBuilderState: queryBuilderState }) }), queryBuilderState.showFunctionsExplorerPanel && (_jsx(ResizablePanelSplitter, {})), queryBuilderState.showFunctionsExplorerPanel && (_jsx(ResizablePanel, { minSize: 40, direction: queryBuilderState.showParametersPanel
                                                                            ? [1, -1]
                                                                            : -1, children: _jsx(QueryBuilderFunctionsExplorerPanel, { queryBuilderState: queryBuilderState }) })), queryBuilderState.showParametersPanel && (_jsx(ResizablePanelSplitter, {})), queryBuilderState.showParametersPanel && (_jsx(ResizablePanel, { minSize: 40, direction: -1, children: _jsx(QueryBuilderParametersPanel, { queryBuilderState: queryBuilderState }) })), queryBuilderState.constantState
                                                                        .showConstantPanel && _jsx(ResizablePanelSplitter, {}), queryBuilderState.constantState
                                                                        .showConstantPanel && (_jsx(ResizablePanel, { minSize: 40, direction: -1, children: _jsx(QueryBuilderConstantExpressionPanel, { queryBuilderState: queryBuilderState }) }))] }) }) }), _jsx(ResizablePanelSplitter, {}), _jsx(ResizablePanel, { minSize: 300, children: _jsx(QueryBuilderFetchStructurePanel, { queryBuilderState: queryBuilderState }) }), showPostFetchStructurePanel && (_jsx(ResizablePanelSplitter, {})), showPostFetchStructurePanel && (_jsx(ResizablePanel, { minSize: 300, children: renderPostFetchStructure() })), queryBuilderState.isQueryChatOpened && (_jsx(ResizablePanelSplitter, {})), queryBuilderState.isQueryChatOpened && (_jsx(ResizablePanel, { size: 450, children: _jsx(QueryChat, { queryBuilderState: queryBuilderState }) }))] })) : (_jsx(QueryBuilderUnsupportedQueryEditor, { queryBuilderState: queryBuilderState })) }), queryBuilderState.isResultPanelHidden ? null : (_jsx(ResizablePanelSplitter, {})), queryBuilderState.isResultPanelHidden ? null : (_jsx(ResizablePanel, { size: 300, minSize: 40, children: _jsx(QueryBuilderResultPanel, { queryBuilderState: queryBuilderState }) }))] }) })] }), queryBuilderState.textEditorState.mode && (_jsx(QueryBuilderTextEditor, { queryBuilderState: queryBuilderState })), queryBuilderState.changeDetectionState.diffViewState && (_jsx(QueryBuilderDiffViewPanelDiaglog, { diffViewState: queryBuilderState.changeDetectionState.diffViewState })), queryBuilderState.checkEntitlementsState
                        .showCheckEntitlementsViewer && (_jsx(Dialog, { open: queryBuilderState.checkEntitlementsState
                            .showCheckEntitlementsViewer, onClose: handleClose, 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", children: [_jsx(ModalHeader, { title: "Query Entitlements" }), _jsx(ModalBody, { className: "query-builder__data-access-overview", children: _jsx("div", { className: "query-builder__data-access-overview__container", children: queryBuilderState.checkEntitlementsState
                                            .dataAccessState ? (_jsx(DataAccessOverview, { dataAccessState: queryBuilderState.checkEntitlementsState
                                                .dataAccessState })) : (_jsx(BlankPanelContent, { children: "No data access information available" })) }) }), _jsx(ModalFooter, { children: _jsx(ModalFooterButton, { text: "Close", onClick: handleClose, type: "secondary" }) })] }) })), queryBuilderState.dataCubeViewerState && (_jsx(QueryDataCubeViewer, { state: queryBuilderState.dataCubeViewerState, close: () => queryBuilderState.setDataCubeViewerState(undefined) }))] }), queryBuilderState.workflowState.showStatusBar ? (_jsx(QueryBuilderStatusBar, { queryBuilderState: queryBuilderState })) : null] }));
});
//# sourceMappingURL=QueryBuilder.js.map