"use strict";
/**
 * @file This file contains the classes implementing the interfaces defined in the corresponding types file.
 * Note that the logic for dealing with the multi-table scenario is implemented in the sibling file MultiTable.ts.
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CREATE_WITH_PARAMETER_DIALOG = exports.Table = exports.Fields4CreateWithParametersDialog = exports.CreateWithFilters = exports.DataLoadSettings = void 0;
exports.getDefaultTableType = getDefaultTableType;
exports.getTableType = getTableType;
exports.checkTableType = checkTableType;
exports.getManifestPathForTableSettings = getManifestPathForTableSettings;
exports.addEntityTypeFieldsAsEnum = addEntityTypeFieldsAsEnum;
const i18next_1 = __importDefault(require("i18next"));
const ux_specification_types_1 = require("@sap/ux-specification-types");
const v2 = __importStar(require("@sap/ux-specification-types/src/v2/genericSchemaHandling/controls/Table"));
const decoration_1 = require("../../../common/decoration");
const extensionLogger_1 = require("../../../../extensionLogger");
const utils_1 = require("../../generate/utils");
const MultiTable_1 = require("./MultiTable");
const MultiViewSingleTable_1 = require("./MultiViewSingleTable");
const manifestPropertyUtils_1 = require("../../generate/manifestPropertyUtils");
const utils_2 = require("../../utils");
const common_1 = require("../../../common");
const Action_1 = require("./Action");
const MultiEdit_1 = require("./MultiEdit");
const TableColumn_1 = require("./TableColumn");
/**
 * This function should return the information whether the given entity type is analytical.
 * Unfortunately this is currently impossible due to missing information provided by the annotation api.
 * As soon as the annotation api has been enhanced accordingly, this function should be enhanced.
 *
 * @param entityTypeDefinition - the entity type to be checked
 * @returns true if the entity type is analytical, false otherwise
 */
function isTypeAnalytical(entityTypeDefinition) {
    return false; // todo: enhance
}
/**
 * Returns the entity set applicable for the given table parameters.
 *
 * @param tableParams - the parameters describing the table
 * @param generateParameters - the parameters used for schema generation
 * @returns the entity set for the given table
 */
function getEntitySet(tableParams, generateParameters) {
    return tableParams.multiTableInfo?.variantInfo
        ? tableParams.multiTableInfo?.variantInfo.entitySetDefinition
        : generateParameters.entitySet;
}
/**
 * Returns the default table type used for tables for the given entity type (i.e. the table type which will be used by Fiori Elements if no manifest setting for the table type is available).
 *
 * @param entityTypeDefinition - the entity type for which the table is created
 * @returns the default table type for the given entity type
 */
function getDefaultTableType(entityTypeDefinition) {
    const isAnalytical = isTypeAnalytical(entityTypeDefinition);
    return isAnalytical ? v2.TableTypeV2Enum.AnalyticalTable : v2.TableTypeV2Enum.ResponsiveTable;
}
/**
 * Returns the table type valid for the artifact described by given parameters.
 *
 * @param tableParams - the parameters describing the table
 * @returns the table type for the given table
 */
function getTableType(tableParams) {
    if (tableParams.multiTableInfo?.variantInfo) {
        return tableParams.multiTableInfo.variantInfo.tableType;
    }
    const tableSettings = tableParams.settings?.tableSettings;
    const tableType = (tableSettings && tableSettings['type']) ||
        tableParams.settings?.tableType ||
        getDefaultTableType(tableParams.entityType);
    return tableType;
}
/**
 * Checks whether the table described by the given parameters is a responsive table.
 *
 * @param tableParams - the parameters describing the table
 * @returns true if the table is a responsive table, false otherwise
 */
function isResponsiveTable(tableParams) {
    return getTableType(tableParams) === v2.TableTypeV2Enum.ResponsiveTable;
}
/**
 * Checks whether the table described by the given parameters is a ui table.
 *
 * @param tableParams - the parameters describing the table
 * @returns true if the table is a ui table, false otherwise
 */
function isUiTable(tableParams) {
    return !isResponsiveTable(tableParams) && !tableParams.multiTableInfo?.variantInfo?.isChart;
}
/**
 * Get the tableSettings object from the manifest applicable to the specified table.
 *
 * @param tableParams - the parameters describing the table
 * @returns the tableSettings or undefined if no tableSettings are applicable
 */
function getTableSettings(tableParams) {
    return ((tableParams.multiTableInfo?.variantInfo &&
        tableParams.multiTableInfo.variantInfo.variantDefinition['tableSettings']) ||
        (tableParams.settings && tableParams.settings['tableSettings']));
}
/**
 * Returns whether the specified table is configured a multi-selection table.
 *
 * @param tableParams - the parameters describing the table
 * @returns whether the table is multi-select
 */
function isMultiSelect(tableParams) {
    const tableSettings = getTableSettings(tableParams);
    return tableSettings?.['multiSelect'] === true;
}
/**
 * Checks whether the table described by the given parameters has selectAll switched on.
 *
 * @param tableParams - the parameters describing the table
 * @returns true if the table has selectAll switched on, false otherwise
 */
function isSelectAll(tableParams) {
    const tableSettings = getTableSettings(tableParams);
    return isMultiSelect(tableParams) && tableSettings['selectAll'] !== false; // note that tableSettings are available if isMultiSelect is true
}
/**
 * Checks whether a given table type is valid. Thereby undefined and empty string are also considered as valid (they represent the default table type).
 *
 * @param tableType - the table type to be checked
 * @param logger - would log an error if tableType is invalid
 * @returns - information whether the tableType is valid
 */
function checkTableType(tableType, logger) {
    if (tableType === undefined ||
        tableType === '' ||
        Object.values(v2.TableTypeV2Enum).includes(tableType)) {
        return true;
    }
    (0, extensionLogger_1.log)(logger, {
        severity: "error" /* LogSeverity.Error */,
        message: i18next_1.default.t('ILLEGALTABLETYPE', {
            property: tableType
        })
    });
    return false;
}
/** SyncRule which should be used for all properties with artifact type 'FlexChange' belonging to the SmartTable. */
const syncRuleForFlexSmartTable = {
    flex: {
        controlType: () => ux_specification_types_1.ControlType.SmartTable
    },
    processingRuleAdapter: function (processingRule, schemaHandlingParams) {
        const tableParams = schemaHandlingParams.specificParams;
        const isPropertyValid = !((tableParams.multiTableInfo && !tableParams.multiTableInfo.variantInfo) ||
            tableParams.multiTableInfo?.variantInfo.isChart); // the property is invalid on top-level of a multi-table scenario and on a view displaying a chart
        if (isPropertyValid) {
            processingRule.controlId = tableParams.multiTableInfo
                ? tableParams.multiTableInfo.variantInfo.smartControlId
                : tableParams.tableId;
        }
        else {
            delete processingRule.element;
        }
    }
};
/**
 * Provide the syncRule for a property with artifact type 'FlexChange' belonging to the ResponsiveTable inside the SmartTable.
 *
 * @param addPatternForBinding information whether the addPatternForBindingChangeOfEnumLR should be added as generate property to the sync rule
 * @returns the syncRule
 */
function getSyncRuleForFlexResponsiveTable(addPatternForBinding) {
    const syncRule = {
        flex: {
            controlType: () => ux_specification_types_1.ControlType.Table
        },
        processingRuleAdapter: function (processingRule, schemaHandlingParams) {
            const tableParams = schemaHandlingParams.specificParams;
            if ((!tableParams.multiTableInfo || tableParams.multiTableInfo.variantInfo) &&
                isResponsiveTable(tableParams)) {
                // Replicate logic from sap.suite.ui.generic.template.lib.StableIdDefinition, type: ListReport, subType: ResponsiveTable
                const suffix = tableParams.multiTableInfo
                    ? `-${tableParams.multiTableInfo.variantInfo.variantDefinition['key']}`
                    : '';
                processingRule.controlId = `responsiveTable${suffix}`;
            }
            else {
                delete processingRule.element;
            }
        }
    };
    if (addPatternForBinding) {
        syncRule.generate = decoration_1.addPatternForBindingChangeOfEnumLR; // add option for bindings (already executed in the generation of the generic schema)
    }
    return syncRule;
}
/**
 * Helper functions for implementing a ProcessingRuleAdapter for a manifest-based property belonging to the tableSettings.
 * Returns the manifest path for the table settings for the specified table params (which may either be global or for a specific view in a multi-table scenario).
 *
 * @param schemaHandlingParams - the schema handling parameters passed to the ProcessingRuleAdapter
 * @param tableParams - the parameters describing the table
 * @returns the manifest path to the tableSettings of the specified table
 */
function getManifestPathForTableSettings(schemaHandlingParams, tableParams) {
    const suffix = [];
    if (tableParams.multiTableInfo?.variantInfo) {
        suffix.push('quickVariantSelectionX', 'variants', tableParams.multiTableInfo.variantInfo.accessor);
    }
    suffix.push('tableSettings');
    const manifestPath = (0, utils_2.getManifestPathToPageSettings)(schemaHandlingParams.pageInfo.pagePath, suffix);
    return manifestPath;
}
/**
 * This function adapts getSyncRuleForManifestProperty for properties belonging to the tableSettings of a table.
 *
 * @param property - the name of the property in tableSettings section of the manifest the SyncRule should be generated for
 * @param getDisallowReason - optional function to determine whether the property is disallowed for the given table params
 * @param adapt - an optional function that can be used to adapt the schema element representing the manifest property
 * @param provideReferenceAdaptation - an optional function that can be used to provide the ReferenceAdaptationInfo for the manifest property
 * @param expectedType - the expected type of the value of the property (if it is not undefined)
 * @returns the SyncRule for the tableSettings property
 */
function getSyncRuleForTableSettingsProperty(property, getDisallowReason, adapt, provideReferenceAdaptation, expectedType) {
    // Construct the analyze function for getSyncRuleForManifestProperty
    const analyze = function (element, schemaHandlingParams, generateParameters) {
        const tableParams = schemaHandlingParams.specificParams;
        let disallowedReason;
        // If the view is a chart view we can exclude the property generically. Otherwise check with function getDisallowedReason
        if (tableParams.multiTableInfo?.variantInfo?.isChart) {
            disallowedReason = i18next_1.default.t('NOCHARTPROPERTY', { property: property });
        }
        else if (getDisallowReason) {
            disallowedReason = getDisallowReason(tableParams, generateParameters, element);
        }
        const manifestPath = getManifestPathForTableSettings(schemaHandlingParams, tableParams);
        return { manifestPath, disallowedReason };
    };
    // Create a getReferenceAdaptation function with the correct signature for getSyncRuleForManifestProperty
    const provideReferenceAdaptationWrapper = provideReferenceAdaptation
        ? function (schemaHandlingParams, generateParameters) {
            const tableParams = schemaHandlingParams.specificParams;
            return provideReferenceAdaptation(tableParams, generateParameters);
        }
        : undefined;
    return (0, manifestPropertyUtils_1.getSyncRuleForManifestProperty)(property, analyze, adapt, provideReferenceAdaptationWrapper, expectedType);
}
/**
 * This function provides a SyncRule for manifest properties which are only allowed on the top-level of the table definition and not on the level of views in a multi-table scenario.
 * Moreover, these properties possess a parent property that is a child of the page settings (so they are no direct children of the page settings).
 *
 * @param property - the property name in the manifest
 * @param noWorklistI18nKey - the i18n key specifying the warning message in case the property is used in a worklist scenario
 * @param syncRuleProvider - the sync rule provider for the specified manifest property
 * @returns the syncRule for the specified manifest property
 */
function getOnlyTopLevelNotWorklistSyncRule(property, noWorklistI18nKey, syncRuleProvider) {
    return {
        processingRuleAdapter(processingRule, schemaHandlingParams, generateParameters) {
            const tableParams = schemaHandlingParams.specificParams;
            if (tableParams.multiTableInfo?.variantInfo) {
                delete processingRule.element; // ignore this property on level of single views in multi-table scenario
                return;
            }
            if (tableParams.settings?.isWorklist) {
                const disallowedReason = i18next_1.default.t(noWorklistI18nKey);
                const manifestPath = (0, utils_2.getManifestPathToPageSettings)(schemaHandlingParams.pageInfo.pagePath, []);
                const { value } = (0, utils_2.getManifestPropertyByPath)(generateParameters.manifest, manifestPath, property);
                (0, manifestPropertyUtils_1.handleDisallowedProperty)(disallowedReason, processingRule, value, manifestPath);
                return;
            }
            processingRule.referenceAdaptation = {
                syncRuleProvider: syncRuleProvider
            };
        }
    };
}
/**
 * Modifies a schema element such that the fields of the given entity type are added as enumeration values.
 *
 * @param element - the schema element to be modified
 * @param entityTypeDefinition - the entity type hosting the fields
 */
function addEntityTypeFieldsAsEnum(element, entityTypeDefinition) {
    const itemsEnum = entityTypeDefinition.entityProperties.map((property) => property.name);
    element.items = {
        type: 'string',
        enum: itemsEnum
    };
}
class DataLoadSettings {
}
exports.DataLoadSettings = DataLoadSettings;
__decorate([
    (0, decoration_1.descriptionSrcURL)('https://ui5.sap.com/sdk/#/topic/b736ab6ae3654789ba1f9630e5720af3?q=loadDataOnAppLaunch'),
    (0, decoration_1.syncRule)({
        manifest: {},
        processingRuleAdapter(processingRule, schemaHandlingParams) {
            const manifestPath = (0, utils_2.getManifestPathToPageSettings)(schemaHandlingParams.pageInfo.pagePath, [
                'dataLoadSettings'
            ]);
            processingRule.manifestPath = manifestPath;
            const tableParams = schemaHandlingParams.specificParams;
            if (tableParams.multiTableInfo && !tableParams.multiTableInfo.variantInfo) {
                processingRule.element.description += '\n' + i18next_1.default.t('LOADDATAONAPPLAUNCHMULTITABLE'); // add information to the description providing specific information in multi-table scenarios
            }
        }
    }),
    (0, decoration_1.validity)({
        since: '1.75.2'
    })
], DataLoadSettings.prototype, "loadDataOnAppLaunch", void 0);
class CreateWithFilters {
}
exports.CreateWithFilters = CreateWithFilters;
__decorate([
    (0, decoration_1.descriptionSrcURL)('https://ui5.sap.com/sdk/#/topic/189e2d8a59f04a2693a4fde7f4a91a65?q=createWithFilters'),
    (0, decoration_1.syncRule)({
        manifest: {},
        processingRuleAdapter(processingRule, schemaHandlingParams) {
            const manifestPath = (0, utils_2.getManifestPathToPageSettings)(schemaHandlingParams.pageInfo.pagePath, [
                'createWithFilters'
            ]);
            processingRule.manifestPath = manifestPath;
        }
    })
], CreateWithFilters.prototype, "strategy", void 0);
class Fields4CreateWithParametersDialog {
}
exports.Fields4CreateWithParametersDialog = Fields4CreateWithParametersDialog;
__decorate([
    (0, decoration_1.validity)({
        since: '1.77.0'
    }),
    (0, decoration_1.syncRule)({
        processingRuleAdapter(processingRule, schemaHandlingParams) {
            const entityTypeDefinition = schemaHandlingParams.specificParams;
            addEntityTypeFieldsAsEnum(processingRule.element, entityTypeDefinition);
        }
    })
], Fields4CreateWithParametersDialog.prototype, "fields", void 0);
class Table {
} // Table
exports.Table = Table;
__decorate([
    (0, decoration_1.syncRule)((0, MultiTable_1.getSyncRuleForMultiTableManifestProperty)('entitySet')),
    (0, decoration_1.descriptionSrcURL)('https://ui5.sap.com/sdk/#/topic/6698b80fc1a543ebb5c07e0781e9b93e')
], Table.prototype, "entitySet", void 0);
__decorate([
    (0, decoration_1.syncRule)((0, MultiTable_1.getSyncRuleForMultiTableManifestProperty)('annotationPath')),
    (0, decoration_1.descriptionSrcURL)('https://ui5.sap.com/sdk/#/topic/97dfeea4a8c346368cea6bf7a3e85478')
], Table.prototype, "annotationPath", void 0);
__decorate([
    (0, decoration_1.syncRule)((0, MultiTable_1.getSyncRuleForMultiTableManifestProperty)('showItemNavigationOnChart'))
], Table.prototype, "showItemNavigationOnChart", void 0);
__decorate([
    (0, decoration_1.syncRule)((0, MultiTable_1.getSyncRuleForMultiTableManifestProperty)('views'))
], Table.prototype, "views", void 0);
__decorate([
    (0, decoration_1.syncRule)((0, MultiViewSingleTable_1.getSyncRuleForQuickVariantSelection)())
], Table.prototype, "quickVariantSelection", void 0);
__decorate([
    (0, decoration_1.syncRule)(syncRuleForFlexSmartTable)
], Table.prototype, "showTablePersonalisation", void 0);
__decorate([
    (0, decoration_1.syncRule)(syncRuleForFlexSmartTable)
], Table.prototype, "exportType", void 0);
__decorate([
    (0, decoration_1.syncRule)(syncRuleForFlexSmartTable)
], Table.prototype, "useExportToExcel", void 0);
__decorate([
    (0, decoration_1.syncRule)(getSyncRuleForFlexResponsiveTable(false))
], Table.prototype, "growingThreshold", void 0);
__decorate([
    (0, decoration_1.syncRule)(getSyncRuleForFlexResponsiveTable(true))
], Table.prototype, "popinLayout", void 0);
__decorate([
    (0, decoration_1.syncRule)(getSyncRuleForFlexResponsiveTable(false))
], Table.prototype, "includeItemInSelection", void 0);
__decorate([
    (0, decoration_1.syncRule)((0, manifestPropertyUtils_1.getSyncRuleForManifestProperty)('tableType', 
    // analyze:
    function (element, schemaHandlingParams) {
        const tableParams = schemaHandlingParams.specificParams;
        const manifestPath = (0, utils_2.getManifestPathToPageSettings)(schemaHandlingParams.pageInfo.pagePath);
        // Property tableType is obsolete. For views in a multi-table scenario it was even never supported.
        const disallowedReason = tableParams.multiTableInfo?.variantInfo
            ? manifestPropertyUtils_1.DISALLOWED_WITHOUT_EXPLANATION
            : i18next_1.default.t('PROPERTYOBSOLETE', { property: 'tableType' });
        return {
            manifestPath,
            disallowedReason
        };
    } // analyze
    ))
], Table.prototype, "tableType", void 0);
__decorate([
    (0, decoration_1.syncRule)(getSyncRuleForTableSettingsProperty('type', undefined, 
    // adapt:
    function (element, schemaHandlingParams) {
        const tableParams = schemaHandlingParams.specificParams;
        // defaultTypeForMultiView is only set when we are on variant level and the generic level explicitly sets a type
        const defaultTypeForMultiView = tableParams.multiTableInfo?.variantInfo && tableParams.settings?.tableSettings
            ? tableParams.settings.tableSettings['type']
            : '';
        if (tableParams.multiTableInfo?.variantInfo &&
            tableParams.multiTableInfo.usedTableTypes.nonResponsive > 0 &&
            tableParams.multiTableInfo.usedTableTypes.responsive > 0) {
            // We have an illegal combination of responsive and non-responsive table types in a multi-view setting.
            // We will add this as an error to all instances that defer from the default.
            const defaultTableType = defaultTypeForMultiView || getDefaultTableType(tableParams.entityType);
            const isDefaultResponsive = defaultTableType === v2.TableTypeV2Enum.ResponsiveTable;
            if (isResponsiveTable(tableParams) !== isDefaultResponsive) {
                // This is a variant which defers from the default -> consider it as being a reason for the incorrect setup
                element[ux_specification_types_1.SchemaTag.messages] = [
                    {
                        text: i18next_1.default.t(isDefaultResponsive ? 'MULTITABLEONLYRESPONSIVE' : 'MULTITABLENORESPONSIVE'),
                        type: ux_specification_types_1.PropertyMessageType.Warning
                    }
                ];
            }
        }
        // The generic schema element points to TableTypeV2Enum which provides all possible table types as an enumeration.
        // In the following cases we need to reduce this enumeration:
        // 1. type for one view in a multi-table scenario in order to avoid combinations of responsive and non-responsive table types
        // 2. Remove AnalyticalTable in case the entity type is not analytical
        // As we cannot determine whether an entity type is analytical yet, we ignore the second case.
        if (tableParams.multiTableInfo?.variantInfo /* || !isTypeAnalytical(tableParams.entityType) */) {
            delete element.$ref; // Remove reference to TableTypeV2Enum
            const enumEntries = [];
            // When
            // - dealing with a variant of a multi-view scenario and
            // - the generic level sets a non-responsive type as default and
            // - there is indeed no responsive table variant yet and
            // - there is at least one other non-responsive table variant
            // In this case changing the type to responsive would automatically break the app, since it creates a mixture of responsive and non-responsive tables.
            // => Suppress responsive from the value-help. If the user really wants to change all variants to responsive he should first remove the explicit generic setting defaulting to non-responsive.
            if (!defaultTypeForMultiView ||
                defaultTypeForMultiView === v2.TableTypeV2Enum.ResponsiveTable ||
                tableParams.multiTableInfo.usedTableTypes.responsive > 0 ||
                tableParams.multiTableInfo.usedTableTypes.nonResponsive < 2) {
                // In all other cases add 'responsive' to the value-help
                enumEntries.push(v2.TableTypeV2Enum.ResponsiveTable);
            }
            if (defaultTypeForMultiView !== v2.TableTypeV2Enum.ResponsiveTable ||
                tableParams.multiTableInfo.usedTableTypes.nonResponsive > 0 ||
                tableParams.multiTableInfo.usedTableTypes.responsive < 2) {
                // Same as above, interchanging the roles of responsive and non-responsive.
                enumEntries.push(v2.TableTypeV2Enum.GridTable);
                //if (isAnalytical(tableParams.entityType)){ // todo: activate this condition
                enumEntries.push(v2.TableTypeV2Enum.AnalyticalTable);
                //}
                enumEntries.push(v2.TableTypeV2Enum.TreeTable);
            }
            (0, common_1.addEnumToSchema)(enumEntries, element);
        }
    }, // adapt
    undefined, 'string')),
    (0, decoration_1.descriptionSrcURL)('https://ui5.sap.com/sdk/#/topic/5d270547f113468e83e06dd7ee408a45')
], Table.prototype, "type", void 0);
__decorate([
    (0, decoration_1.syncRule)((0, manifestPropertyUtils_1.getSyncRuleForManifestProperty)('condensedTableLayout', 
    // analyze:
    function (element, schemaHandlingParams) {
        const tableParams = schemaHandlingParams.specificParams;
        const manifestPath = (0, utils_2.getManifestPathToPageSettings)(schemaHandlingParams.pageInfo.pagePath);
        let disallowedReason;
        if (tableParams.multiTableInfo?.variantInfo) {
            disallowedReason = manifestPropertyUtils_1.DISALLOWED_WITHOUT_EXPLANATION; // Setting is not allowed on level of views. Hence, ignore it here without any feedback.
        }
        else if (isResponsiveTable(tableParams)) {
            disallowedReason = i18next_1.default.t('CONDENSEDTABLELAYOUTNOEFFECT');
        }
        return {
            manifestPath,
            disallowedReason
        };
    } // analyze
    ))
], Table.prototype, "condensedTableLayout", void 0);
__decorate([
    (0, decoration_1.syncRule)((0, manifestPropertyUtils_1.getSyncRuleForManifestProperty)('enableTableFilterInPageVariant', 
    // analyze:
    function (element, schemaHandlingParams) {
        const tableParams = schemaHandlingParams.specificParams;
        const manifestPath = (0, utils_2.getManifestPathToPageSettings)(schemaHandlingParams.pageInfo.pagePath);
        let disallowedReason;
        if (tableParams.multiTableInfo?.variantInfo) {
            disallowedReason = manifestPropertyUtils_1.DISALLOWED_WITHOUT_EXPLANATION; // Setting is not allowed on level of views. Hence, ignore it here without any feedback.
        }
        else if (tableParams.settings?.isWorklist) {
            disallowedReason = i18next_1.default.t('ENABLETABLEFILTERINPAGEVARIANTWORKLIST');
        }
        else if (tableParams.settings?.smartVariantManagement === false) {
            disallowedReason = i18next_1.default.t('ENABLETABLEFILTERINPAGEVARIANTNOEFFECT');
        }
        return {
            manifestPath,
            disallowedReason
        };
    } // analyze
    ))
], Table.prototype, "enableTableFilterInPageVariant", void 0);
__decorate([
    (0, decoration_1.syncRule)(getSyncRuleForTableSettingsProperty('inlineDelete', 
    // getDisallowReason
    function (tableParams) {
        return isResponsiveTable(tableParams) ? undefined : i18next_1.default.t('INLINEDELETEONLYRESPONSIVE');
    }, // getDisallowedReason
    //adapt:
    function (element, schemaHandlingParams, generateParameters, value) {
        if (value === true && isMultiSelect(schemaHandlingParams.specificParams)) {
            element[ux_specification_types_1.SchemaTag.messages] = [
                {
                    text: i18next_1.default.t('NOINLINEDELETEANDMULTISELECT'),
                    deletable: true,
                    type: ux_specification_types_1.PropertyMessageType.Warning
                }
            ];
        }
    } // adapt
    ))
], Table.prototype, "inlineDelete", void 0);
__decorate([
    (0, decoration_1.syncRule)(getSyncRuleForTableSettingsProperty('multiSelect', undefined, // getDisallowedReason
    //adapt:
    function (element, schemaHandlingParams, generateParameters, value) {
        // Problematic scenario: multiSelect and inlineDelete switched on at the same time. Can only happen for responsive tables as inlineDelete is only available for responsive tables.
        const tableParams = schemaHandlingParams.specificParams;
        if (value !== true || !isResponsiveTable(tableParams)) {
            return;
        }
        const tableSettings = getTableSettings(tableParams);
        if (tableSettings?.['inlineDelete'] === true) {
            element[ux_specification_types_1.SchemaTag.messages] = [
                {
                    text: i18next_1.default.t('NOINLINEDELETEANDMULTISELECT'),
                    deletable: true,
                    type: ux_specification_types_1.PropertyMessageType.Warning
                }
            ];
        }
    } // adapt
    )),
    (0, decoration_1.descriptionSrcURL)('https://ui5.sap.com/sdk/#/topic/402fac73b4794a31983609ebdde580d2')
], Table.prototype, "multiSelect", void 0);
__decorate([
    (0, decoration_1.syncRule)(getSyncRuleForTableSettingsProperty('selectAll', 
    // getDisallowReason:
    function (tableParams, generateParameters, element) {
        if (!isMultiSelect(tableParams)) {
            // In this case the function returns a disallowedReason. Therefore, the adapt function will not be called.
            // Still the property may be shown to the user (in case it contains a value).
            // The description contains markups that allow the adapt function (below) to provide the correct text depending on the table type.
            // For the warning scenario we simply remove this part.
            element.description = element.description.split('\n')[0];
            return i18next_1.default.t('SELECTALLNOMULTISELECT');
        }
    }, // getDisallowReason
    // adapt:
    function (element, schemaHandlingParams) {
        // add table type dependent information to the description of the property.
        const tableParams = schemaHandlingParams.specificParams;
        const i18nForDefaultInfo = isUiTable(tableParams)
            ? 'SELECTALLDEFAULTINFOUITABLE'
            : 'SELECTALLDEFAULTINFORESPONSIVETABLE';
        element.description += '\n' + i18next_1.default.t(i18nForDefaultInfo);
    } // adapt
    ))
], Table.prototype, "selectAll", void 0);
__decorate([
    (0, decoration_1.syncRule)(getSyncRuleForTableSettingsProperty('selectionLimit', function (tableParams) {
        if (!isUiTable(tableParams) || !isMultiSelect(tableParams)) {
            return i18next_1.default.t('SELECTIONLIMITPREREQUISIT');
        }
        if (isSelectAll(tableParams)) {
            return i18next_1.default.t('SELECTIONLIMITNOSELECTALL');
        }
    })),
    (0, decoration_1.descriptionSrcURL)('https://ui5.sap.com/sdk/#/topic/116b5d82e8c545e2a56e1b51b8b0a9bd?q=selectionLimit')
], Table.prototype, "selectionLimit", void 0);
__decorate([
    (0, decoration_1.syncRule)(getSyncRuleForTableSettingsProperty('copy')),
    (0, decoration_1.validity)({
        since: '1.120.0'
    }),
    (0, decoration_1.descriptionSrcURL)('https://ui5.sap.com/sdk/#/topic/c0f6592a592e47f9bb6d09900de47412')
], Table.prototype, "copy", void 0);
__decorate([
    (0, decoration_1.syncRule)(getOnlyTopLevelNotWorklistSyncRule('dataLoadSettings', 'NODATALOADSETTINGSINWORKLIST', DataLoadSettings))
], Table.prototype, "dataLoadSettings", void 0);
__decorate([
    (0, decoration_1.syncRule)(getOnlyTopLevelNotWorklistSyncRule('createWithFilters', 'NOCREATEWITHFILTERSINWORKLIST', CreateWithFilters))
], Table.prototype, "createWithFilters", void 0);
__decorate([
    (0, decoration_1.validity)({
        since: '1.77.0'
    }),
    (0, decoration_1.descriptionSrcURL)('https://ui5.sap.com/sdk/#/topic/2d04f60da84a49f6bb8617fbf1d3d2aa'),
    (0, decoration_1.syncRule)(getSyncRuleForTableSettingsProperty('createWithParameterDialog', 
    // getDisallowReason:
    function (tableParams, generateParameters) {
        const entitySet = getEntitySet(tableParams, generateParameters);
        if (!entitySet) {
            return manifestPropertyUtils_1.DISALLOWED_WITHOUT_EXPLANATION;
        }
        const draftInfo = (0, utils_2.getDraftInfo)(entitySet);
        if (draftInfo.isDraft) {
            return i18next_1.default.t('CREATEWITHDIALOGDRAFT');
        }
    }, // getDisallowReason
    // adapt:
    function (element, schemaHandlingParams, generateParameters, value) {
        (0, utils_2.addConversionExit)(element, 'createWithParameterDialog', value);
    }, // adapt
    // provideReferenceAdaptation:
    function (tableParams) {
        return {
            syncRuleProvider: Fields4CreateWithParametersDialog,
            specificParams: tableParams.multiTableInfo?.variantInfo
                ? tableParams.multiTableInfo.variantInfo.entityTypeDefinition
                : tableParams.entityType,
            suffix: tableParams.multiTableInfo?.variantInfo
                ? tableParams.multiTableInfo.variantInfo.iconTabFilterKey
                : undefined
        };
    }, // provideReferenceAdaptation
    'object'))
], Table.prototype, "createWithParameterDialog", void 0);
__decorate([
    (0, decoration_1.validity)({
        since: '1.98.0'
    }),
    (0, decoration_1.descriptionSrcURL)('https://ui5.sap.com/sdk/#/topic/7cc4f04364c540c397130ff92f84c3ca'),
    (0, decoration_1.syncRule)(MultiEdit_1.syncRuleMultiEdit)
], Table.prototype, "multiEdit", void 0);
__decorate([
    (0, decoration_1.syncRule)({
        processingRuleAdapter(processingRule, schemaHandlingParams) {
            const tableParams = schemaHandlingParams.specificParams;
            if (tableParams.multiTableInfo && !tableParams.multiTableInfo.variantInfo) {
                delete processingRule.element; // no toolbar defined in the global table settings in the multi-table case
                return;
            }
            processingRule.element[ux_specification_types_1.SchemaTag.propertyIndex] = 0;
            const lineItemInfo = tableParams.multiTableInfo
                ? tableParams.multiTableInfo.variantInfo.lineItemInfo
                : tableParams.lineItemInfo;
            const isChart = tableParams.multiTableInfo?.variantInfo?.isChart;
            const iconTabFilterKey = tableParams.multiTableInfo?.variantInfo?.iconTabFilterKey;
            (0, Action_1.adaptProcessingRuleForToolbar)(processingRule, utils_1.DataFieldTarget.Toolbar, lineItemInfo?.dataFieldInfos ?? [], isChart, iconTabFilterKey);
        }
    })
], Table.prototype, "toolbar", void 0);
__decorate([
    (0, decoration_1.syncRule)(TableColumn_1.syncRuleColumns)
], Table.prototype, "columns", void 0);
/**
 * ConversionExit for property createWithParameterDialog of Table control.
 * Converts between the manifest representation (object with field names as keys) and the config representation (object with array of field names).
 */
exports.CREATE_WITH_PARAMETER_DIALOG = {
    appToConfig(appValue, parameters, fragments, definition, logger) {
        const hasTypeError = (0, manifestPropertyUtils_1.hasPropertyTypeError)(appValue, 'fields', logger, 'object');
        return appValue && !hasTypeError
            ? {
                fields: Object.keys(appValue['fields'])
            }
            : undefined;
    },
    configToApp(configValue, parameters, fragments, definition, oldAppValue) {
        const configFields = configValue?.['fields'];
        if (Array.isArray(configFields)) {
            const newAppValue = oldAppValue && typeof oldAppValue === 'object' ? { ...oldAppValue } : {};
            if (configFields.length === 0) {
                delete newAppValue['fields'];
                return (0, utils_2.isEmpty)(newAppValue) ? undefined : newAppValue;
            }
            const fields = {}; // the new entry for the fields-property
            const fieldsAsArray = configFields;
            fieldsAsArray.forEach(function (field) {
                fields[field] = { path: field };
            });
            newAppValue['fields'] = fields;
            return newAppValue;
        }
        return oldAppValue; // the fields-property in configValue was untouched (since every change would have converted it into an array). Hence, keep the old value.
    }
};
//# sourceMappingURL=Table.js.map