"use strict";
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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ListReportFilterBar = exports.AnalyticalListPageFilterBar = exports.CommonFilterBar = exports.SelectionFields = exports.SelectionFieldDateSettings = exports.DefaultDateRange = exports.DateRange = void 0;
exports.importDateSettings = importDateSettings;
exports.exportDateSettings = exportDateSettings;
exports.exportDateSettingsField = exportDateSettingsField;
const decorators_1 = require("../../../common/decoration/decorators");
const decoration_1 = require("../../../common/decoration");
const application_1 = require("../../application");
const ux_specification_types_1 = require("@sap/ux-specification-types");
/**
 * Imports date settings from the provided manifest section.
 *
 * @param manifestSection - The manifest section containing date settings.
 * @returns The imported date settings as a DateRange object or undefined if not available.
 */
function importDateSettings(manifestSection) {
    if (!manifestSection || !manifestSection['dateSettings']) {
        return undefined;
    }
    const configPart = JSON.parse(JSON.stringify(manifestSection['dateSettings']));
    // converted CSV format to array of strings
    if (typeof manifestSection['dateSettings']['selectedValues'] === 'string') {
        configPart.selectedValues = manifestSection['dateSettings']['selectedValues'].split(',');
    }
    delete configPart['fields'];
    return configPart;
}
/**
 * Exports date settings to the manifest section.
 *
 * @param manifestSection - The manifest section to which the date settings will be exported.
 * @param configPart - The configuration part containing the date settings to export.
 * @param key - The key of the date settings to export.
 */
function exportDateSettings(manifestSection, configPart, key) {
    manifestSection[key] = JSON.parse(JSON.stringify(configPart[key]));
    //now convert enum array to joined string
    const field = configPart[key];
    if (key === 'selectedValues') {
        manifestSection[key] = field.join();
    }
}
/**
 * Imports date settings field from the provided manifest section.
 *
 * @param manifestSection - The manifest section containing the date settings field.
 * @param _sectionId - The section ID (not used in this function).
 * @param propertyKey - The key of the property to import.
 * @returns The imported date settings field as an array of DateRangeType or undefined if not available.
 */
function importDateSettingsField(manifestSection, _sectionId, propertyKey) {
    const configPart = manifestSection?.[propertyKey]
        ? JSON.parse(JSON.stringify(manifestSection?.[propertyKey]))
        : undefined;
    let selectionField;
    if (propertyKey === 'selectedValues' && typeof configPart === 'string') {
        selectionField = configPart.split(',');
    }
    if (propertyKey === 'filter' && typeof configPart === 'object') {
        selectionField = [];
        configPart.forEach((section, index) => {
            selectionField[index] = section;
            if (section['equals'] && typeof section['equals'] === 'string') {
                selectionField[index].equals = section['equals'].split(',');
            }
        });
    }
    return selectionField;
}
/**
 * Exports date settings to the manifest section.
 *
 * @param manifestSection - The manifest section to which the field will be exported.
 * @param configPart - The configuration part containing the field data to export.
 * @param key - The key of the field to export.
 */
function exportDateSettingsField(manifestSection, configPart, key) {
    manifestSection[key] = JSON.parse(JSON.stringify(configPart[key]));
    const field = configPart[key];
    if (key === 'selectedValues') {
        manifestSection[key] = field.join();
    }
    if (key === 'filter') {
        for (const filterKey in field) {
            const filterValue = field[filterKey];
            manifestSection[key][filterKey] = filterValue;
            if (filterValue.equals && Array.isArray(filterValue.equals)) {
                manifestSection[key][filterKey].equals = filterValue.equals.join();
            }
        }
    }
}
class DateRange {
}
exports.DateRange = DateRange;
__decorate([
    (0, decorators_1.syncRule)({
        manifest: {
            path: (pageKeys) => {
                return (0, application_1.getAppSettingPathV2)(pageKeys) + ux_specification_types_1.DATESETTINGSPATH;
            }
        }
    }),
    (0, decorators_1.validity)({
        since: '1.77.0'
    })
], DateRange.prototype, "useDateRange", void 0);
__decorate([
    (0, decorators_1.syncRule)({
        manifest: {
            path: (pageKeys) => (0, application_1.getAppSettingPathV2)(pageKeys) + ux_specification_types_1.DATESETTINGSPATH,
            import: importDateSettings,
            export: exportDateSettings
        }
    }),
    (0, decorators_1.validity)({
        since: '1.77.0'
    })
], DateRange.prototype, "selectedValues", void 0);
__decorate([
    (0, decorators_1.syncRule)({
        manifest: {
            path: (pageKeys) => (0, application_1.getAppSettingPathV2)(pageKeys) + ux_specification_types_1.DATESETTINGSPATH
        }
    }),
    (0, decorators_1.validity)({
        since: '1.77.0'
    })
], DateRange.prototype, "exclude", void 0);
const flexRuleForSmartFilterBar = {
    controlId: decoration_1.buildControlIdFromParent,
    controlType: () => ux_specification_types_1.ControlType.SmartFilterBar
};
const manifestRuleForSelectionField = {
    path: (pageKeys, _manifest, breadcrumbs) => `${(0, application_1.getAppSettingPathV2)(pageKeys)}${ux_specification_types_1.DATESETTINGSPATH}/fields/${breadcrumbs}`
};
const manifestRuleForSelectionFieldWithArrays = {
    ...manifestRuleForSelectionField,
    import: importDateSettingsField,
    export: exportDateSettingsField
};
class DefaultDateRange {
}
exports.DefaultDateRange = DefaultDateRange;
__decorate([
    (0, decorators_1.syncRule)({
        manifest: manifestRuleForSelectionField
    }),
    (0, decorators_1.validity)({
        since: '1.90.0'
    })
], DefaultDateRange.prototype, "operation", void 0);
class SelectionFieldDateSettings {
}
exports.SelectionFieldDateSettings = SelectionFieldDateSettings;
__decorate([
    (0, decorators_1.syncRule)({
        manifest: manifestRuleForSelectionFieldWithArrays
    }),
    (0, decorators_1.validity)({
        since: '1.77.0'
    })
], SelectionFieldDateSettings.prototype, "selectedValues", void 0);
__decorate([
    (0, decorators_1.syncRule)({
        manifest: manifestRuleForSelectionField
    }),
    (0, decorators_1.validity)({
        since: '1.77.0'
    })
], SelectionFieldDateSettings.prototype, "exclude", void 0);
__decorate([
    (0, decorators_1.syncRule)({
        manifest: manifestRuleForSelectionField
    }),
    (0, decorators_1.validity)({
        since: '1.77.0'
    })
], SelectionFieldDateSettings.prototype, "customDateRangeImplementation", void 0);
__decorate([
    (0, decorators_1.syncRule)({
        manifest: manifestRuleForSelectionFieldWithArrays
    }),
    (0, decorators_1.validity)({
        since: '1.77.0'
    })
], SelectionFieldDateSettings.prototype, "filter", void 0);
__decorate([
    (0, decorators_1.syncRule)({
        manifest: manifestRuleForSelectionField
    }),
    (0, decorators_1.validity)({
        since: '1.90.0'
    })
], SelectionFieldDateSettings.prototype, "defaultValue", void 0);
class SelectionFields {
}
exports.SelectionFields = SelectionFields;
class CommonFilterBar {
}
exports.CommonFilterBar = CommonFilterBar;
__decorate([
    (0, decorators_1.syncRule)({
        manifest: {
            path: (pageKeys) => (0, application_1.getAppSettingPathV2)(pageKeys)
        }
    }),
    (0, decorators_1.validity)({
        since: '1.38.0'
    })
], CommonFilterBar.prototype, "smartVariantManagement", void 0);
__decorate([
    (0, decorators_1.syncRule)({
        flex: flexRuleForSmartFilterBar
    }),
    (0, decorators_1.validity)({
        since: '1.40.0'
    })
], CommonFilterBar.prototype, "liveMode", void 0);
__decorate([
    (0, decorators_1.syncRule)({
        manifest: {
            path: (pageKeys) => (0, application_1.getAppSettingPathV2)(pageKeys)
        }
    }),
    (0, decorators_1.validity)({
        since: '1.48.0'
    })
], CommonFilterBar.prototype, "variantManagementHidden", void 0);
__decorate([
    (0, decorators_1.syncRule)({
        manifest: {
            path: (pageKeys) => (0, application_1.getAppSettingPathV2)(pageKeys)
        }
    }),
    (0, decorators_1.validity)({
        since: '1.52.0' // Available in 1.52 so exact validity information is not required
    })
], CommonFilterBar.prototype, "subTitleIfVariantMgmtHidden", void 0);
__decorate([
    (0, decorators_1.syncRule)({
        manifest: {
            path: (pageKeys) => (0, application_1.getAppSettingPathV2)(pageKeys) + '/filterSettings',
            import: importDateSettings
        }
    }),
    (0, decorators_1.validity)({
        since: '1.77.0'
    })
], CommonFilterBar.prototype, "dateSettings", void 0);
__decorate([
    (0, decorators_1.syncRule)({
        flex: flexRuleForSmartFilterBar
    }),
    (0, decorators_1.validity)({
        since: '1.28.0'
    })
], CommonFilterBar.prototype, "showClearOnFB", void 0);
__decorate([
    (0, decorators_1.syncRule)({
        flex: flexRuleForSmartFilterBar
    }),
    (0, decorators_1.validity)({
        since: '1.38.0'
    })
], CommonFilterBar.prototype, "showFilterConfiguration", void 0);
__decorate([
    (0, decorators_1.syncRule)({
        flex: flexRuleForSmartFilterBar
    }),
    (0, decorators_1.validity)({
        since: '1.28.0'
    })
], CommonFilterBar.prototype, "showRestoreOnFB", void 0);
class AnalyticalListPageFilterBar extends CommonFilterBar {
}
exports.AnalyticalListPageFilterBar = AnalyticalListPageFilterBar;
__decorate([
    (0, decorators_1.syncRule)({
        manifest: {
            path: (pageKeys) => (0, application_1.getAppSettingPathV2)(pageKeys)
        }
    })
], AnalyticalListPageFilterBar.prototype, "showGoButtonOnFilterBar", void 0);
__decorate([
    (0, decorators_1.syncRule)({
        manifest: {
            path: (pageKeys) => (0, application_1.getAppSettingPathV2)(pageKeys)
        }
    }),
    (0, decorators_1.validity)({
        since: '1.60.0'
    })
], AnalyticalListPageFilterBar.prototype, "filterDefaultsFromSelectionVariant", void 0);
class ListReportFilterBar extends CommonFilterBar {
}
exports.ListReportFilterBar = ListReportFilterBar;
__decorate([
    (0, decorators_1.syncRule)({
        manifest: {
            path: (pageKeys) => (0, application_1.getAppSettingPathV2)(pageKeys)
        }
    }),
    (0, decoration_1.descriptionSrcURL)('https://ui5.sap.com/sdk/#/topic/49a6ba5b8d6946208322a9f7e16837c2'),
    (0, decorators_1.validity)({
        since: '1.86.0'
    })
], ListReportFilterBar.prototype, "annotationPath", void 0);
//# sourceMappingURL=FilterBar.js.map