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 { clsx, Dialog, CustomSelectorInput, CheckSquareIcon, SquareIcon, TimesIcon, Modal, ModalBody, ModalFooter, ModalHeader, ModalFooterButton, InputWithInlineValidation, PanelDivider, PanelDropZone, PanelFormSection, ArrowUpIcon, ArrowDownIcon, PanelFormBooleanField, PanelFormListItems, } from '@finos/legend-art';
import { SortColumnState } from '../../stores/fetch-structure/tds/QueryResultSetModifierState.js';
import { addUniqueEntry, clone, deepClone, deleteEntry, guaranteeNonNullable, isNonNullable, } from '@finos/legend-shared';
import { useApplicationStore } from '@finos/legend-application';
import { COLUMN_SORT_TYPE, QUERY_BUILDER_SUPPORTED_GET_ALL_FUNCTIONS, } from '../../graph/QueryBuilderMetaModelConst.js';
import { useCallback, useEffect, useState } from 'react';
import { QUERY_BUILDER_TEST_ID } from '../../__lib__/QueryBuilderTesting.js';
import { VariableSelector, VariableViewer, } from '../shared/QueryBuilderVariableSelector.js';
import { VariableExpression, PrimitiveType, Multiplicity, areMultiplicitiesEqual, PRIMITIVE_TYPE, MILESTONING_START_DATE_PARAMETER_NAME, GenericType, GenericTypeExplicitReference, MILESTONING_END_DATE_PARAMETER_NAME, getMilestoneTemporalStereotype, BUSINESS_DATE_MILESTONING_PROPERTY_NAME, PROCESSING_DATE_MILESTONING_PROPERTY_NAME, } from '@finos/legend-graph';
import { BasicValueSpecificationEditor, QUERY_BUILDER_VARIABLE_DND_TYPE, } from '../shared/BasicValueSpecificationEditor.js';
import { useDrop } from 'react-dnd';
import { MilestoningParameterEditor } from '../explorer/QueryBuilderMilestoningParameterEditor.js';
import { QueryBuilderSimpleConstantExpressionState } from '../../stores/QueryBuilderConstantsState.js';
import { LambdaParameterState } from '../../stores/shared/LambdaParameterState.js';
const ColumnSortEditor = observer((props) => {
    const { sortColumns, setSortColumns, sortState, tdsColumns } = props;
    const applicationStore = useApplicationStore();
    const projectionOptions = tdsColumns
        .filter((projectionCol) => projectionCol === sortState.columnState ||
        !sortColumns.some((sortCol) => sortCol.columnState === projectionCol))
        .map((projectionCol) => ({
        label: projectionCol.columnName,
        value: projectionCol,
    }));
    const value = {
        label: sortState.columnState.columnName,
        value: sortState.columnState,
    };
    const sortType = sortState.sortType;
    const onChange = (val) => {
        if (val !== null) {
            sortState.setColumnState(val.value);
        }
    };
    const deleteColumnSort = () => {
        const newSortColumns = [...sortColumns];
        deleteEntry(newSortColumns, sortState);
        setSortColumns(newSortColumns);
    };
    const changeSortBy = () => {
        if (sortState.sortType === COLUMN_SORT_TYPE.ASC) {
            sortState.setSortType(COLUMN_SORT_TYPE.DESC);
        }
        else {
            sortState.setSortType(COLUMN_SORT_TYPE.ASC);
        }
    };
    return (_jsxs("div", { className: "panel__content__form__section__list__item query-builder__projection__options__sort", children: [_jsx(CustomSelectorInput, { className: "query-builder__projection__options__sort__dropdown", options: projectionOptions, disabled: projectionOptions.length < 1 ||
                    (projectionOptions.length === 1 && Boolean(value)), onChange: onChange, value: value, darkMode: !applicationStore.layoutService.TEMPORARY__isLightColorThemeEnabled }), _jsx("div", { className: "query-builder__projection__options__sort__sortby", children: sortType.toLowerCase() }), _jsx("button", { className: "query-builder__projection__options__sort__sortby--btn btn--dark", tabIndex: -1, onClick: changeSortBy, title: "Choose SortBy Operator...", children: sortState.sortType === COLUMN_SORT_TYPE.ASC ? (_jsx(ArrowUpIcon, {})) : (_jsx(ArrowDownIcon, {})) }), _jsx("button", { className: "query-builder__projection__options__sort__remove-btn btn--dark btn--caution", onClick: deleteColumnSort, tabIndex: -1, title: "Remove", "data-testid": QUERY_BUILDER_TEST_ID.QUERY_BUILDER_RESULT_MODIFIER_PANEL_SORT_REMOVE_BTN, children: _jsx(TimesIcon, {}) })] }));
});
const ColumnsSortEditor = observer((props) => {
    const { projectionColumns, sortColumns, setSortColumns, tdsColumns } = props;
    const projectionOptions = projectionColumns
        .filter((projectionCol) => !sortColumns.some((sortCol) => sortCol.columnState === projectionCol))
        .map((projectionCol) => ({
        label: projectionCol.columnName,
        value: projectionCol,
    }));
    const addValue = () => {
        if (projectionOptions.length > 0) {
            const sortColumn = new SortColumnState(guaranteeNonNullable(projectionOptions[0]).value);
            const newSortColumns = [...sortColumns];
            addUniqueEntry(newSortColumns, sortColumn);
            setSortColumns(newSortColumns);
        }
    };
    return (_jsxs("div", { className: "panel__content__form__section", children: [_jsx("div", { className: "panel__content__form__section__header__label", children: "Sort and Order" }), _jsx("div", { className: "panel__content__form__section__header__prompt", children: "Choose the column(s) and order direction(s) that the results should be arranged by" }), _jsxs("div", { className: "panel__content__form__section__list", children: [_jsx("div", { className: "panel__content__form__section__list__items", children: sortColumns.map((value) => (_jsx(ColumnSortEditor, { sortColumns: sortColumns, setSortColumns: setSortColumns, sortState: value, tdsColumns: tdsColumns }, value.columnState.uuid))) }), _jsx("div", { className: "panel__content__form__section__list__new-item__add", children: _jsx("button", { className: "panel__content__form__section__list__new-item__add-btn btn btn--dark", disabled: !projectionOptions.length, onClick: addValue, tabIndex: -1, children: "Add Value" }) })] })] }));
});
const cloneSortColumnStateArray = (sortColumns) => sortColumns.map((sortColumn) => {
    const newSortColumn = new SortColumnState(sortColumn.columnState);
    newSortColumn.setSortType(sortColumn.sortType);
    return newSortColumn;
});
export const QueryResultModifierModal = observer((props) => {
    const { tdsState } = props;
    const applicationStore = tdsState.queryBuilderState.applicationStore;
    // Read current state
    const resultSetModifierState = tdsState.resultSetModifierState;
    const stateSortColumns = resultSetModifierState.sortColumns;
    const stateDistinct = resultSetModifierState.distinct;
    const stateLimitResults = resultSetModifierState.limit;
    const stateSlice = resultSetModifierState.slice;
    // Set up temp state for modal lifecycle
    const [sortColumns, setSortColumns] = useState(cloneSortColumnStateArray(stateSortColumns));
    const [distinct, setDistinct] = useState(stateDistinct);
    const [limitResults, setLimitResults] = useState(stateLimitResults);
    const [slice, setSlice] = useState(stateSlice ?? [undefined, undefined]);
    const watermarkState = tdsState.queryBuilderState.watermarkState;
    const [watermarkValue, setWatermarkValue] = useState(deepClone(watermarkState.value));
    // Sync temp state with tdsState when modal is opened/closed
    useEffect(() => {
        setSortColumns(cloneSortColumnStateArray(stateSortColumns));
        setDistinct(stateDistinct);
        setLimitResults(stateLimitResults);
        setSlice(stateSlice ?? [undefined, undefined]);
        setWatermarkValue(deepClone(watermarkState.value));
    }, [
        resultSetModifierState.showModal,
        watermarkState.value,
        stateSortColumns,
        stateDistinct,
        stateLimitResults,
        stateSlice,
    ]);
    const handleLimitResultsChange = (event) => {
        const val = event.target.value.replace(/[^0-9]/g, '');
        setLimitResults(val === '' ? undefined : parseInt(val, 10));
    };
    const handleSliceChange = (start, end) => {
        const newSlice = [start, end];
        setSlice(newSlice);
    };
    const changeSliceStart = (event) => {
        const val = event.target.value.replace(/[^0-9]/g, '');
        if (val === '') {
            handleSliceChange(undefined, slice[1]);
        }
        else {
            const start = typeof val === 'number' ? val : parseInt(val, 10);
            handleSliceChange(start, slice[1]);
        }
    };
    const changeSliceEnd = (event) => {
        const val = event.target.value.replace(/[^0-9]/g, '');
        if (val === '') {
            handleSliceChange(slice[0], undefined);
        }
        else {
            const end = typeof val === 'number' ? val : parseInt(val, 10);
            handleSliceChange(slice[0], end);
        }
    };
    // Error states
    const isInvalidSlice = (slice[0] === undefined && slice[1] !== undefined) ||
        (slice[0] !== undefined && slice[1] === undefined) ||
        (slice[0] !== undefined &&
            slice[1] !== undefined &&
            slice[0] >= slice[1]);
    // watermark
    const isParamaterCompatibleWithWaterMark = (parameter) => PrimitiveType.STRING === parameter.genericType?.value.rawType &&
        areMultiplicitiesEqual(parameter.multiplicity, Multiplicity.ONE);
    const handleDrop = useCallback((item) => {
        setWatermarkValue(item.variable);
    }, [setWatermarkValue]);
    const toggleWatermark = () => {
        if (watermarkValue) {
            setWatermarkValue(undefined);
        }
        else {
            setWatermarkValue(watermarkState.getDefaultValue());
        }
    };
    const [{ isParameterValueDragOver }, dropConnector] = useDrop(() => ({
        accept: [QUERY_BUILDER_VARIABLE_DND_TYPE],
        drop: (item, monitor) => {
            if (!monitor.didDrop() &&
                // Only allows parameters with muliplicity 1 and type string
                isParamaterCompatibleWithWaterMark(item.variable)) {
                handleDrop(item);
            } // prevent drop event propagation to accomondate for nested DnD
        },
        collect: (monitor) => ({
            isParameterValueDragOver: monitor.isOver({
                shallow: true,
            }),
        }),
    }), [handleDrop]);
    //milestoning config
    const isCompatibleMilestoningParameter = (variable) => variable.genericType?.value.rawType.name === PRIMITIVE_TYPE.STRICTDATE ||
        variable.genericType?.value.rawType.name === PRIMITIVE_TYPE.LATESTDATE ||
        variable.genericType?.value.rawType.name === PRIMITIVE_TYPE.DATE ||
        variable.genericType?.value.rawType.name === PRIMITIVE_TYPE.DATETIME;
    const milestoningState = tdsState.queryBuilderState.milestoningState;
    const [parameterStates, setParameterStates] = useState(milestoningState.queryBuilderState.parametersState.parameterStates);
    const filteredParameterStates = parameterStates.filter((p) => isCompatibleMilestoningParameter(p.parameter));
    const filteredConstantState = milestoningState.queryBuilderState.constantState.constants.filter((c) => isCompatibleMilestoningParameter(c.variable));
    const [isAllVersionsEnabled, setIsAllVersionsEnabled] = useState(milestoningState.isAllVersionsEnabled);
    const [isAllVersionsInRangeEnabled, setIsAllVersionsInRangeEnabled] = useState(milestoningState.isAllVersionsInRangeEnabled);
    const [businessDate, setBusinessDate] = useState(milestoningState.businessDate);
    const [processingDate, setProcessingDate] = useState(milestoningState.processingDate);
    const [startDate, setStartDate] = useState(milestoningState.startDate);
    const [endDate, setEndDate] = useState(milestoningState.endDate);
    const [businessDateValue, setBusinessDateValue] = useState(milestoningState.getMilestoningParameterValue(milestoningState.businessDate));
    const [processingDateValue, setProcessingDateValue] = useState(milestoningState.getMilestoningParameterValue(milestoningState.processingDate));
    const [startDateValue, setStartDateValue] = useState(milestoningState.getMilestoningParameterValue(milestoningState.startDate));
    const [endDateValue, setEndDateValue] = useState(milestoningState.getMilestoningParameterValue(milestoningState.endDate));
    const shouldFilterMilestoningParamIfNotUsed = (param, resetParameter) => {
        if (param && param instanceof VariableExpression) {
            if (!milestoningState.queryBuilderState.isVariableUsed(param, {
                exculdeMilestoningState: true,
            })) {
                resetParameter(undefined);
                return (lambdaParamState) => lambdaParamState.parameter.name !== param.name;
            }
        }
        return (lambdaParamState) => true;
    };
    const setAllVersions = (value) => {
        if (value) {
            //clean all unused milestoning parameters e.g. businessDate, ..., endDate.
            setParameterStates([
                ...parameterStates.filter((ps) => shouldFilterMilestoningParamIfNotUsed(businessDate, setBusinessDate)(ps) &&
                    shouldFilterMilestoningParamIfNotUsed(processingDate, setProcessingDate)(ps) &&
                    shouldFilterMilestoningParamIfNotUsed(startDate, setStartDate)(ps) &&
                    shouldFilterMilestoningParamIfNotUsed(endDate, setEndDate)(ps)),
            ]);
        }
        else {
            //get or initialize getAll() parameters
            setIsAllVersionsInRangeEnabled(false);
            let newParamStates = [];
            if ((!businessDate || !processingDate) &&
                milestoningState.queryBuilderState.class) {
                const stereotype = getMilestoneTemporalStereotype(milestoningState.queryBuilderState.class, milestoningState.queryBuilderState.graphManagerState.graph);
                if (stereotype) {
                    const existingParamStates = parameterStates.map((ps) => ps.variableName);
                    newParamStates = milestoningState
                        .getMilestoningImplementation(stereotype)
                        .buildParameterStatesFromMilestoningParameters()
                        .filter((ps) => !existingParamStates.includes(ps.parameter.name));
                }
            }
            const allParamStates = [...newParamStates, ...parameterStates].filter((ps) => shouldFilterMilestoningParamIfNotUsed(startDate, setStartDate)(ps) &&
                shouldFilterMilestoningParamIfNotUsed(endDate, setEndDate)(ps));
            setParameterStates(allParamStates);
            if (!businessDate) {
                const lambdaParamState = allParamStates.find((ps) => ps.variableName ===
                    (milestoningState.businessDate &&
                        milestoningState.businessDate instanceof VariableExpression
                        ? milestoningState.businessDate.name
                        : BUSINESS_DATE_MILESTONING_PROPERTY_NAME));
                setBusinessDate(lambdaParamState?.parameter);
                setBusinessDateValue(lambdaParamState?.value);
            }
            if (!processingDate) {
                const lambdaParamState = allParamStates.find((ps) => ps.variableName ===
                    (milestoningState.businessDate &&
                        milestoningState.processingDate instanceof VariableExpression
                        ? milestoningState.processingDate.name
                        : PROCESSING_DATE_MILESTONING_PROPERTY_NAME));
                setProcessingDate(lambdaParamState?.parameter);
                setProcessingDateValue(lambdaParamState?.value);
            }
        }
        setIsAllVersionsEnabled(Boolean(value));
    };
    const getOrCreateNewLambdaParameterState = (lamdaStates, varName) => {
        const lamdaState = lamdaStates.find((ls) => ls.variableName === varName);
        if (lamdaState) {
            return lamdaState;
        }
        else {
            const varExp = new VariableExpression(varName, Multiplicity.ONE, GenericTypeExplicitReference.create(new GenericType(PrimitiveType.DATE)));
            const newParamState = new LambdaParameterState(varExp, milestoningState.queryBuilderState.observerContext, milestoningState.queryBuilderState.graphManagerState.graph);
            newParamState.mockParameterValue();
            return newParamState;
        }
    };
    const buildAllVersionsInRangeParameters = () => {
        let startDateParameterState;
        let endDateParameterState;
        if (!(startDate && startDate instanceof VariableExpression)) {
            startDateParameterState = getOrCreateNewLambdaParameterState(parameterStates, MILESTONING_START_DATE_PARAMETER_NAME);
            setStartDate(startDateParameterState.parameter);
            setStartDateValue(startDateParameterState.value);
        }
        if (!(endDate && endDate instanceof VariableExpression)) {
            endDateParameterState = getOrCreateNewLambdaParameterState(parameterStates, MILESTONING_END_DATE_PARAMETER_NAME);
            setEndDate(endDateParameterState.parameter);
            setEndDateValue(endDateParameterState.value);
        }
        setParameterStates([
            ...new Set([
                ...parameterStates.filter((ps) => shouldFilterMilestoningParamIfNotUsed(businessDate, setBusinessDate)(ps) &&
                    shouldFilterMilestoningParamIfNotUsed(processingDate, setProcessingDate)(ps)),
                ...[startDateParameterState, endDateParameterState].filter(isNonNullable),
            ]),
        ]);
    };
    const setAllVersionsInRange = (value) => {
        if (value) {
            buildAllVersionsInRangeParameters();
        }
        else {
            setAllVersions(true);
        }
        setIsAllVersionsInRangeEnabled(Boolean(value));
    };
    const resetMilestoningConfig = () => {
        setIsAllVersionsEnabled(milestoningState.isAllVersionsEnabled);
        setIsAllVersionsInRangeEnabled(milestoningState.isAllVersionsInRangeEnabled);
        setStartDate(milestoningState.startDate);
        setEndDate(milestoningState.endDate);
        setBusinessDate(milestoningState.businessDate);
        setProcessingDate(milestoningState.processingDate);
        setParameterStates(milestoningState.queryBuilderState.parametersState.parameterStates);
        setStartDateValue(milestoningState.getMilestoningParameterValue(milestoningState.startDate));
        setEndDateValue(milestoningState.getMilestoningParameterValue(milestoningState.endDate));
        setProcessingDateValue(milestoningState.getMilestoningParameterValue(milestoningState.processingDate));
        setBusinessDateValue(milestoningState.getMilestoningParameterValue(milestoningState.businessDate));
    };
    // Handle user actions
    const closeModal = () => {
        resetMilestoningConfig();
        resultSetModifierState.setShowModal(false);
    };
    const applyChanges = () => {
        resultSetModifierState.setSortColumns(sortColumns);
        resultSetModifierState.setDistinct(distinct);
        resultSetModifierState.setLimit(limitResults);
        if (slice[0] !== undefined && slice[1] !== undefined) {
            resultSetModifierState.setSlice([slice[0], slice[1]]);
        }
        else {
            resultSetModifierState.setSlice(undefined);
        }
        resultSetModifierState.setShowModal(false);
        watermarkState.setValue(watermarkValue);
        milestoningState.queryBuilderState.parametersState.setParameters(parameterStates);
        if (isAllVersionsInRangeEnabled) {
            milestoningState.setStartDate(startDate);
            milestoningState.setEndDate(endDate);
            milestoningState.clearGetAllParameters();
            milestoningState.queryBuilderState.setGetAllFunction(QUERY_BUILDER_SUPPORTED_GET_ALL_FUNCTIONS.GET_ALL_VERSIONS_IN_RANGE);
            milestoningState.updateMilestoningParameterValue(startDate, startDateValue);
            milestoningState.updateMilestoningParameterValue(endDate, endDateValue);
        }
        else if (isAllVersionsEnabled) {
            milestoningState.clearGetAllParameters();
            milestoningState.queryBuilderState.setGetAllFunction(QUERY_BUILDER_SUPPORTED_GET_ALL_FUNCTIONS.GET_ALL_VERSIONS);
        }
        else if (tdsState.queryBuilderState.milestoningState.isMilestonedQuery) {
            milestoningState.clearAllVersionsInRangeParameters();
            milestoningState.setBusinessDate(businessDate);
            milestoningState.setProcessingDate(processingDate);
            milestoningState.queryBuilderState.setGetAllFunction(QUERY_BUILDER_SUPPORTED_GET_ALL_FUNCTIONS.GET_ALL);
            milestoningState.updateMilestoningParameterValue(processingDate, processingDateValue);
            milestoningState.updateMilestoningParameterValue(businessDate, businessDateValue);
        }
        milestoningState.updateQueryBuilderState();
    };
    useEffect(() => {
        setIsAllVersionsEnabled(milestoningState.isAllVersionsEnabled);
        setIsAllVersionsInRangeEnabled(milestoningState.isAllVersionsInRangeEnabled);
        setStartDate(milestoningState.startDate);
        setEndDate(milestoningState.endDate);
        setBusinessDate(milestoningState.businessDate);
        setProcessingDate(milestoningState.processingDate);
        setParameterStates(milestoningState.queryBuilderState.parametersState.parameterStates);
        setStartDateValue(milestoningState.getMilestoningParameterValue(milestoningState.startDate));
        setEndDateValue(milestoningState.getMilestoningParameterValue(milestoningState.endDate));
        setProcessingDateValue(milestoningState.getMilestoningParameterValue(milestoningState.processingDate));
        setBusinessDateValue(milestoningState.getMilestoningParameterValue(milestoningState.businessDate));
    }, [
        milestoningState,
        milestoningState.isAllVersionsEnabled,
        milestoningState.isAllVersionsInRangeEnabled,
        milestoningState.queryBuilderState.parametersState.parameterStates,
        milestoningState.businessDate,
        milestoningState.processingDate,
        milestoningState.startDate,
        milestoningState.endDate,
        milestoningState.queryBuilderState.class,
    ]);
    return (_jsx(Dialog, { open: Boolean(resultSetModifierState.showModal), onClose: closeModal, classes: {
            root: 'editor-modal__root-container',
            container: 'editor-modal__container',
            paper: 'editor-modal__content query-builder__projection__modal__content',
        }, "data-testid": QUERY_BUILDER_TEST_ID.QUERY_BUILDER_RESULT_MODIFIER_PANEL, children: _jsxs(Modal, { darkMode: !applicationStore.layoutService.TEMPORARY__isLightColorThemeEnabled, className: "editor-modal query-builder__projection__modal", children: [_jsx(ModalHeader, { className: "query-builder__projection__modal__header", title: "Query Options" }), _jsx(ModalBody, { className: "query-builder__projection__modal__body", children: _jsxs("div", { className: "query-builder__projection__options", children: [tdsState.queryBuilderState.milestoningState
                                .isMilestonedQuery && (_jsxs(_Fragment, { children: [_jsx("div", { className: "query-builder__projection__options__section-name", children: "Milestoning" }), milestoningState.isCurrentClassMilestoned && (_jsx(PanelFormBooleanField, { isReadOnly: false, value: isAllVersionsEnabled, name: "all Versions", prompt: "Query All Milestoned Versions of the Root Class", update: setAllVersions })), isAllVersionsEnabled &&
                                        milestoningState.isCurrentClassSupportsVersionsInRange && (_jsxs(_Fragment, { children: [_jsx(PanelFormBooleanField, { isReadOnly: false, value: isAllVersionsInRangeEnabled, name: " All Versions In Range", prompt: "Optionally apply a date range to get All Versions for", update: setAllVersionsInRange }), isAllVersionsInRangeEnabled &&
                                                startDate &&
                                                endDate && (_jsxs("div", { className: "query-builder__milestoning-panel__all-versions-in-range-editor", children: [_jsxs(PanelFormSection, { children: [_jsx("div", { className: "panel__content__form__section__header__label", children: "Start Date" }), _jsx("div", { className: "panel__content__form__section__header__prompt", children: "Choose a value for this milestoning parameter" }), _jsx(MilestoningParameterEditor, { queryBuilderState: milestoningState.queryBuilderState, parameter: startDate, setParameter: setStartDate, parameterValue: startDateValue, setParameterValue: setStartDateValue })] }), _jsxs(PanelFormSection, { children: [_jsx("div", { className: "panel__content__form__section__header__label", children: "End Date" }), _jsx("div", { className: "panel__content__form__section__header__prompt", children: "Choose a value for this milestoning parameter" }), _jsx(MilestoningParameterEditor, { queryBuilderState: milestoningState.queryBuilderState, parameter: endDate, setParameter: setEndDate, parameterValue: endDateValue, setParameterValue: setEndDateValue })] })] }))] })), !isAllVersionsEnabled && (_jsxs(_Fragment, { children: [processingDate && (_jsxs(PanelFormSection, { children: [_jsx("div", { className: "panel__content__form__section__header__label", children: "Processing Date" }), _jsx("div", { className: "panel__content__form__section__header__prompt", children: "Choose a value for this milestoning parameter" }), _jsx(MilestoningParameterEditor, { queryBuilderState: milestoningState.queryBuilderState, parameter: processingDate, setParameter: setProcessingDate, parameterValue: processingDateValue, setParameterValue: setProcessingDateValue })] })), businessDate && (_jsxs(PanelFormSection, { children: [_jsx("div", { className: "panel__content__form__section__header__label", children: "Business Date" }), _jsx("div", { className: "panel__content__form__section__header__prompt", children: "Choose a value for this milestoning parameter" }), _jsx(MilestoningParameterEditor, { queryBuilderState: milestoningState.queryBuilderState, parameter: businessDate, setParameter: setBusinessDate, parameterValue: businessDateValue, setParameterValue: setBusinessDateValue })] }))] })), !(isAllVersionsEnabled && !isAllVersionsInRangeEnabled) && (_jsxs(_Fragment, { children: [_jsx(PanelFormSection, { children: _jsx("div", { className: "panel__content__form__section__header__label", children: "List of compatible milestoning parameters" }) }), _jsxs("div", { className: "panel__content__form__section__list__items", children: [filteredParameterStates.length > 0 && (_jsx(PanelFormListItems, { title: "Available parameters", children: filteredParameterStates.map((pState) => (_jsx(VariableViewer, { variable: pState.parameter, isReadOnly: true, queryBuilderState: milestoningState.queryBuilderState, option: {
                                                                hideMilestoningParameterValueString: true,
                                                            } }, pState.uuid))) })), Boolean(filteredConstantState.length) && (_jsx(PanelFormListItems, { title: "Available constants", children: filteredConstantState.map((constantState) => (_jsx(VariableViewer, { variable: constantState.variable, value: {
                                                                val: constantState instanceof
                                                                    QueryBuilderSimpleConstantExpressionState
                                                                    ? constantState.value
                                                                    : undefined,
                                                            }, queryBuilderState: milestoningState.queryBuilderState, isReadOnly: true }, constantState.uuid))) }))] })] })), _jsx("div", { className: "query-builder__projection__options__section-name", children: "Other" })] })), _jsx(ColumnsSortEditor, { projectionColumns: tdsState.projectionColumns, sortColumns: sortColumns, setSortColumns: setSortColumns, tdsColumns: tdsState.tdsColumns }), _jsxs("div", { className: "panel__content__form__section", children: [_jsx("div", { className: "panel__content__form__section__header__label", children: "Eliminate Duplicate Rows" }), _jsxs("div", { className: "panel__content__form__section__toggler", onClick: () => setDistinct(!distinct), children: [_jsx("button", { className: clsx('panel__content__form__section__toggler__btn', {
                                                    'panel__content__form__section__toggler__btn--toggled': distinct,
                                                }), tabIndex: -1, children: distinct ? _jsx(CheckSquareIcon, {}) : _jsx(SquareIcon, {}) }), _jsx("div", { className: "panel__content__form__section__toggler__prompt", children: "Remove duplicate rows from the results" })] })] }), _jsxs("div", { className: "panel__content__form__section", children: [_jsx("label", { htmlFor: "query-builder__projection__modal__limit-results-input", className: "panel__content__form__section__header__label", children: "Limit Results" }), _jsx("div", { className: "panel__content__form__section__header__prompt", children: "Specify the maximum total number of rows the output will produce" }), _jsx("input", { id: "query-builder__projection__modal__limit-results-input", className: "panel__content__form__section__input panel__content__form__section__number-input", spellCheck: false, type: "text", value: limitResults ?? '', onChange: handleLimitResultsChange })] }), _jsxs("div", { className: "panel__content__form__section", children: [_jsx("label", { htmlFor: "query-builder__projection__modal__slice-start-input", className: "panel__content__form__section__header__label", children: "Slice" }), _jsx("div", { className: "panel__content__form__section__header__prompt", children: "Reduce the number of rows in the provided TDS, selecting the set of rows in the specified range between start and stop" }), _jsxs("div", { className: "query-builder__result__slice", children: [_jsx("div", { className: "query-builder__result__slice__input__wrapper", children: _jsx(InputWithInlineValidation, { id: "query-builder__projection__modal__slice-start-input", className: "input--dark query-builder__result__slice__input panel__content__form__section__input", spellCheck: false, value: slice[0] ?? '', onChange: changeSliceStart, type: "text", error: isInvalidSlice ? 'Invalid slice' : undefined }) }), _jsx("div", { className: "query-builder__result__slice__range", children: ".." }), _jsx("div", { className: "query-builder__result__slice__input__wrapper", children: _jsx(InputWithInlineValidation, { className: "input--dark query-builder__result__slice__input panel__content__form__section__input", spellCheck: false, value: slice[1] ?? '', onChange: changeSliceEnd, type: "text", error: isInvalidSlice ? 'Invalid slice' : undefined }) })] })] }), _jsxs(_Fragment, { children: [_jsxs(PanelFormSection, { children: [_jsx("label", { className: "panel__content__form__section__header__label", children: "Watermark" }), _jsxs("button", { className: clsx('panel__content__form__section__toggler', 'panel__content__form__section__toggler__btn', {
                                                    'panel__content__form__section__toggler__btn--toggled': watermarkValue,
                                                }), onClick: toggleWatermark, tabIndex: -1, children: [watermarkValue ? _jsx(CheckSquareIcon, {}) : _jsx(SquareIcon, {}), _jsx("div", { className: "panel__content__form__section__toggler__prompt", children: "Enable Watermark" })] })] }), watermarkValue && (_jsxs(_Fragment, { children: [_jsx(PanelFormSection, { children: _jsx("div", { className: "query-builder__variable-editor", "data-testid": QUERY_BUILDER_TEST_ID.QUERY_BUILDER_RESULT_MODIFIER_PANEL__WATERMAKR, children: _jsx(PanelDropZone, { isDragOver: isParameterValueDragOver, dropTargetConnector: dropConnector, children: _jsx(BasicValueSpecificationEditor, { valueSpecification: watermarkValue, setValueSpecification: (val) => {
                                                                setWatermarkValue(clone(val));
                                                            }, graph: watermarkState.queryBuilderState.graphManagerState
                                                                .graph, observerContext: watermarkState.queryBuilderState.observerContext, typeCheckOption: {
                                                                expectedType: PrimitiveType.STRING,
                                                            }, resetValue: () => setWatermarkValue(watermarkState.getDefaultValue()), isConstant: watermarkState.queryBuilderState.constantState.isValueSpecConstant(watermarkValue) }) }) }) }), _jsx(PanelDivider, {}), _jsx(VariableSelector, { filterBy: isParamaterCompatibleWithWaterMark, queryBuilderState: tdsState.queryBuilderState })] }))] })] }) }), _jsxs(ModalFooter, { children: [_jsx(ModalFooterButton, { onClick: applyChanges, text: "Apply", disabled: isInvalidSlice }), _jsx(ModalFooterButton, { onClick: closeModal, text: "Cancel", type: "secondary" })] })] }) }));
});
//# sourceMappingURL=QueryBuilderResultModifierPanel.js.map