"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomSortModule = void 0;
const tslib_1 = require("tslib");
const AdaptableModuleBase_1 = require("./AdaptableModuleBase");
const ModuleConstants = tslib_1.__importStar(require("../Utilities/Constants/ModuleConstants"));
const CustomSortRedux = tslib_1.__importStar(require("../Redux/ActionsReducers/CustomSortRedux"));
const CustomSortWizard_1 = require("../View/CustomSort/Wizard/CustomSortWizard");
const getCustomSortColumnViewItems_1 = require("./Utilities/CustomSort/getCustomSortColumnViewItems");
const getCustomSortSortOrderViewItems_1 = require("./Utilities/CustomSort/getCustomSortSortOrderViewItems");
const getObjectTagsViewItems_1 = require("../Utilities/getObjectTagsViewItems");
class CustomSortModule extends AdaptableModuleBase_1.AdaptableModuleBase {
    constructor(api) {
        super(ModuleConstants.CustomSortModuleId, ModuleConstants.CustomSortFriendlyName, 'import-export', 'CustomSortPopup', 'Provide bespoke sorting information for Columns (in place of alphabetical sorting)', api);
    }
    getModuleAdaptableObjects(config) {
        return this.api.customSortApi.getCustomSorts(config);
    }
    getExplicitlyReferencedColumnIds(customSort) {
        return [customSort.ColumnId];
    }
    hasNamedQueryReferences() {
        return false;
    }
    createColumnMenuItems(column) {
        if (column && this.isModuleEditable() && column.sortable) {
            if (!this.api.customSortApi.internalApi.columnHasCustomSortComparer(column.columnId)) {
                let customSort = this.api.customSortApi
                    .getCustomSorts()
                    .find((x) => x.ColumnId == column.columnId);
                let label = customSort ? 'Edit ' : 'Create ';
                let popupParam = {
                    column: column,
                    action: customSort ? 'Edit' : 'New',
                    source: 'ColumnMenu',
                };
                let name = customSort ? 'custom-sort-edit' : 'custom-sort-add';
                return [
                    this.createMenuItemShowPopup(name, label + 'Custom Sort', this.moduleInfo.Popup, this.moduleInfo.Glyph, popupParam),
                ];
            }
        }
    }
    getTeamSharingAction() {
        return {
            ModuleEntities: this.api.customSortApi.getCustomSorts(),
            AddAction: CustomSortRedux.CustomSortAdd,
            EditAction: CustomSortRedux.CustomSortEdit,
        };
    }
    toView(customSort) {
        return {
            items: [
                {
                    name: 'Name',
                    values: [customSort.Name],
                },
                (0, getCustomSortColumnViewItems_1.getCustomSortColumnViewItems)(customSort, this.api),
                (0, getCustomSortSortOrderViewItems_1.getCustomSortSortOrderViewItems)(customSort),
                (0, getObjectTagsViewItems_1.getObjectTagsViewItems)(customSort, this.api),
            ],
            abObject: customSort,
        };
    }
    toViewAll() {
        return this.getModuleAdaptableObjects({
            includeLayoutNotExtendedObjects: this.showLayoutNonExtendedObjects(),
        }).map((customSort) => this.toView(customSort));
    }
    getViewProperties() {
        return {
            getEditAction: CustomSortRedux.CustomSortEdit,
            getDeleteAction: CustomSortRedux.CustomSortDelete,
            getSuspendAction: CustomSortRedux.CustomSortSuspend,
            getUnSuspendAction: CustomSortRedux.CustomSortUnSuspend,
            getSuspendAllAction: CustomSortRedux.CustomSortSuspendAll,
            getUnSuspendAllAction: CustomSortRedux.CustomSortUnSuspendAll,
            emptyView: "Click 'New' to create a custom Sort Order for a selected Column",
            getEditWizard() {
                return CustomSortWizard_1.CustomSortWizard;
            },
        };
    }
    containsLayoutExtensions() {
        return true;
    }
}
exports.CustomSortModule = CustomSortModule;
