"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FreeTextColumnWizard = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const react_1 = require("react");
const OnePageAdaptableWizard_1 = require("../../Wizard/OnePageAdaptableWizard");
const Helper_1 = require("../../../Utilities/Helpers/Helper");
const FreeTextColumnSettingsWizardSection_1 = require("./FreeTextColumnSettingsWizardSection");
const ObjectFactory_1 = tslib_1.__importDefault(require("../../../Utilities/ObjectFactory"));
const FreeTextColumnRedux = tslib_1.__importStar(require("../../../Redux/ActionsReducers/FreeTextColumnRedux"));
const react_redux_1 = require("react-redux");
const ObjectTagsWizardSection_1 = require("../../Wizard/ObjectTagsWizardSection");
const AdaptableContext_1 = require("../../AdaptableContext");
const Flex_1 = require("../../../components/Flex");
const FreeTextColumnWizard = (props) => {
    const adaptable = (0, AdaptableContext_1.useAdaptable)();
    const allFreeTextColumns = (0, react_redux_1.useSelector)((state) => state.FreeTextColumn.FreeTextColumns);
    const [freeTextColumn, setFreeTextColumn] = (0, react_1.useState)(() => {
        if (props.data) {
            return (0, Helper_1.cloneObject)(props.data);
        }
        if (props.popupParams?.action === 'Edit' && props.popupParams?.column) {
            return allFreeTextColumns.find((column) => column.ColumnId === props.popupParams.column.columnId);
        }
        return ObjectFactory_1.default.CreateEmptyFreeTextColumn(adaptable.api.gridApi.internalApi.deriveSpecialColumnSettingsFromAgGridDefaultColDef());
    });
    const dispatch = (0, react_redux_1.useDispatch)();
    const isEdit = props.data || props.popupParams?.action === 'Edit';
    const handleFinish = () => {
        if (isEdit) {
            dispatch(FreeTextColumnRedux.FreeTextColumnEdit(freeTextColumn));
        }
        else {
            dispatch(FreeTextColumnRedux.FreeTextColumnAdd(freeTextColumn));
        }
        props.onFinishWizard(freeTextColumn);
    };
    return (React.createElement(OnePageAdaptableWizard_1.OnePageAdaptableWizard, { defaultCurrentSectionName: props.defaultCurrentSectionName, moduleInfo: props.moduleInfo, data: freeTextColumn, onHide: props.onCloseWizard, onFinish: handleFinish, sections: [
            {
                title: 'Settings',
                details: 'Configure the Free Text Column',
                isValid: FreeTextColumnSettingsWizardSection_1.isValidFreeTextColumn,
                render: () => {
                    return (React.createElement(Flex_1.Box, { className: "twa:p-2" },
                        React.createElement(FreeTextColumnSettingsWizardSection_1.FreeTextColumnSettingsWizardSection, { isEdit: Boolean(props.data), onChange: setFreeTextColumn })));
                },
            },
            {
                details: 'Select Free Text Column Tags',
                title: 'Tags',
                isVisible: (_, api) => api.internalApi.shouldDisplayTagSections(),
                render: () => (React.createElement(Flex_1.Box, { className: "twa:p-2" },
                    React.createElement(ObjectTagsWizardSection_1.ObjectTagsWizardSection, { onChange: setFreeTextColumn }))),
                renderSummary: ObjectTagsWizardSection_1.renderObjectTagsSummary,
            },
            '-',
            {
                details: 'Review the Free Text Column',
                renderSummary: FreeTextColumnSettingsWizardSection_1.renderFreeTextColumnSummary,
                render: () => {
                    return (React.createElement(Flex_1.Box, { className: "twa:p-2" },
                        React.createElement(OnePageAdaptableWizard_1.OnePageWizardSummary, null)));
                },
                title: 'Summary',
            },
        ] }));
};
exports.FreeTextColumnWizard = FreeTextColumnWizard;
