"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NamedQueryExpressionWizardSection = exports.renderNamedQueryExpressionSummary = exports.isValidNamedQueryExpression = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const react_1 = require("react");
const rebass_1 = require("rebass");
const ExpressionEditor_1 = require("../../../components/ExpressionEditor");
const Tag_1 = require("../../../components/Tag");
const ModuleConstants_1 = require("../../../Utilities/Constants/ModuleConstants");
const OnePageAdaptableWizard_1 = require("../../Wizard/OnePageAdaptableWizard");
const isValidNamedQueryExpression = (data, api) => {
    if (!data.BooleanExpression) {
        return 'Expression is empty';
    }
    const valid = api.expressionApi.isValidBooleanExpression(data.BooleanExpression, ModuleConstants_1.NamedQueryModuleId);
    if (!valid) {
        return 'Query is not a valid Boolean Query';
    }
    return valid;
};
exports.isValidNamedQueryExpression = isValidNamedQueryExpression;
const renderNamedQueryExpressionSummary = (data) => {
    const { api } = (0, OnePageAdaptableWizard_1.useOnePageAdaptableWizardContext)();
    return (React.createElement(rebass_1.Text, { fontSize: 2 },
        "Expression: ",
        React.createElement(Tag_1.Tag, null, api.internalApi.getAdaptableQueryExpressionText(data))));
};
exports.renderNamedQueryExpressionSummary = renderNamedQueryExpressionSummary;
const NamedQueryExpressionWizardSection = (props) => {
    const { data, moduleInfo, api } = (0, OnePageAdaptableWizard_1.useOnePageAdaptableWizardContext)();
    const initialData = (0, react_1.useMemo)(() => api.internalApi.getQueryPreviewData(), []);
    return (React.createElement(ExpressionEditor_1.ExpressionEditor, { allowSaveNamedQuery: false, showQueryBuilder: true, type: 'boolean', module: moduleInfo.ModuleName, value: data.BooleanExpression, onChange: (BooleanExpression) => {
            props.onChange(Object.assign(Object.assign({}, data), { BooleanExpression }));
        }, initialData: initialData, columns: api.columnApi.getQueryableColumns(), fields: api.expressionApi.internalApi.getAvailableFields(), namedQueries: api.namedQueryApi.getNamedQueries(), api: api }));
};
exports.NamedQueryExpressionWizardSection = NamedQueryExpressionWizardSection;
