"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NamedQueryWizard = 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 OnePageAdaptableWizard_1 = require("../../Wizard/OnePageAdaptableWizard");
const NamedQuerySettingsWizardSection_1 = require("./NamedQuerySettingsWizardSection");
const Helper_1 = require("../../../Utilities/Helpers/Helper");
const NamedQueryExpressionWizardSection_1 = require("./NamedQueryExpressionWizardSection");
const ObjectFactory_1 = tslib_1.__importDefault(require("../../../Utilities/ObjectFactory"));
const react_redux_1 = require("react-redux");
const NamedQueryRedux = tslib_1.__importStar(require("../../../Redux/ActionsReducers/NamedQueryRedux"));
const ObjectTagsWizardSection_1 = require("../../Wizard/ObjectTagsWizardSection");
function NamedQueryWizard(props) {
    const [namedQuery, setNamedQuery] = (0, react_1.useState)(() => {
        const value = props.popupParams?.value ?? '';
        return props.data
            ? (0, Helper_1.cloneObject)(props.data)
            : ObjectFactory_1.default.CreateEmptyNamedQuery(value);
    });
    const dispatch = (0, react_redux_1.useDispatch)();
    const handleFinish = () => {
        if (props.data) {
            dispatch(NamedQueryRedux.NamedQueryEdit(namedQuery));
        }
        else {
            dispatch(NamedQueryRedux.NamedQueryAdd(namedQuery));
        }
        props.onFinishWizard(namedQuery);
    };
    return (React.createElement(OnePageAdaptableWizard_1.OnePageAdaptableWizard, { defaultCurrentSectionName: props.defaultCurrentSectionName, onFinish: handleFinish, sections: [
            {
                title: 'Expression',
                details: "Build the Named Query's Expression",
                renderSummary: NamedQueryExpressionWizardSection_1.renderNamedQueryExpressionSummary,
                isValid: NamedQueryExpressionWizardSection_1.isValidNamedQueryExpression,
                render: () => React.createElement(NamedQueryExpressionWizardSection_1.NamedQueryExpressionWizardSection, { onChange: setNamedQuery }),
            },
            {
                title: 'Query Name',
                details: 'Specify a unique Name for the Named Query',
                renderSummary: NamedQuerySettingsWizardSection_1.renderNamedQuerySettingsSummary,
                isValid: NamedQuerySettingsWizardSection_1.isValidNamedQuerySettings,
                render: () => {
                    return React.createElement(NamedQuerySettingsWizardSection_1.NamedQuerySettingsWizardSection, { onChange: setNamedQuery });
                },
            },
            {
                details: 'Select Named Query Tags',
                title: 'Tags',
                isVisible: (_, api) => api.internalApi.shouldDisplayTagSections(),
                render: () => (React.createElement(rebass_1.Box, { padding: 2 },
                    React.createElement(ObjectTagsWizardSection_1.ObjectTagsWizardSection, { onChange: setNamedQuery }))),
                renderSummary: ObjectTagsWizardSection_1.renderObjectTagsSummary,
            },
            '-',
            {
                title: 'Summary',
                details: 'Review your Named Query',
                render: () => {
                    return (React.createElement(rebass_1.Box, { padding: 2 },
                        React.createElement(OnePageAdaptableWizard_1.OnePageWizardSummary, null)));
                },
            },
        ], onHide: props.onCloseWizard, moduleInfo: props.moduleInfo, data: namedQuery }));
}
exports.NamedQueryWizard = NamedQueryWizard;
