"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomSortWizard = 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 Helper_1 = require("../../../Utilities/Helpers/Helper");
const CustomSortColumnWizardSection_1 = require("./CustomSortColumnWizardSection");
const CustomSortValuesWizardSection_1 = require("./CustomSortValuesWizardSection");
const ObjectFactory_1 = tslib_1.__importDefault(require("../../../Utilities/ObjectFactory"));
const react_redux_1 = require("react-redux");
const CustomSortRedux = tslib_1.__importStar(require("../../../Redux/ActionsReducers/CustomSortRedux"));
const ObjectTagsWizardSection_1 = require("../../Wizard/ObjectTagsWizardSection");
const CustomSortWizard = (props) => {
    let data = props.data;
    const allCustomSorts = (0, react_redux_1.useSelector)((state) => state.CustomSort?.CustomSorts);
    if (props.popupParams?.action === 'Edit' && props.popupParams?.column) {
        data = allCustomSorts.find((x) => x.ColumnId == props.popupParams?.column.columnId);
    }
    const [customSort, setCustomSort] = (0, react_1.useState)(() => {
        if (data) {
            return (0, Helper_1.cloneObject)(data);
        }
        const newData = ObjectFactory_1.default.CreateEmptyCustomSort();
        if (props.popupParams?.column) {
            newData.ColumnId = props.popupParams?.column.columnId;
        }
        return newData;
    });
    const dispatch = (0, react_redux_1.useDispatch)();
    const handleFinish = () => {
        if (data) {
            dispatch(CustomSortRedux.CustomSortEdit(customSort));
        }
        else {
            dispatch(CustomSortRedux.CustomSortAdd(customSort));
        }
        props.onFinishWizard(customSort);
    };
    return (React.createElement(OnePageAdaptableWizard_1.OnePageAdaptableWizard, { defaultCurrentSectionName: props.defaultCurrentSectionName, moduleInfo: props.moduleInfo, data: customSort, onFinish: handleFinish, onHide: props.onCloseWizard, sections: [
            {
                isValid: CustomSortColumnWizardSection_1.isValidCustomSortColumn,
                renderSummary: CustomSortColumnWizardSection_1.renderCustomSortColumn,
                details: 'Select a Column for Custom Sort',
                render: () => {
                    return (React.createElement(rebass_1.Box, { padding: 2, style: { height: '100%' } },
                        React.createElement(CustomSortColumnWizardSection_1.CustomSortColumnWizardSection, { isNew: props.isNew, onChange: setCustomSort })));
                },
                title: 'Column',
            },
            {
                title: 'Sort Order',
                details: 'Specify Custom Sort order - drag selected items to modify order',
                isValid: CustomSortValuesWizardSection_1.isValidCustomSortOrder,
                renderSummary: CustomSortValuesWizardSection_1.renderCustomSortValuesSummary,
                render: () => (React.createElement(rebass_1.Box, { padding: 2, style: { height: '100%' } },
                    React.createElement(CustomSortValuesWizardSection_1.CustomSortValuesWizardSection, { onChange: setCustomSort }))),
            },
            {
                details: 'Select Custom Sort Tags',
                title: 'Tags',
                isVisible: (_, api) => api.internalApi.shouldDisplayTagSections(),
                render: () => (React.createElement(rebass_1.Box, { padding: 2 },
                    React.createElement(ObjectTagsWizardSection_1.ObjectTagsWizardSection, { onChange: setCustomSort }))),
                renderSummary: ObjectTagsWizardSection_1.renderObjectTagsSummary,
            },
            '-',
            {
                title: 'Summary',
                details: 'Review your Custom Sort',
                render: () => {
                    return (React.createElement(rebass_1.Box, { padding: 2 },
                        React.createElement(OnePageAdaptableWizard_1.OnePageWizardSummary, null)));
                },
            },
        ] }));
};
exports.CustomSortWizard = CustomSortWizard;
