"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tsUtils_1 = require("../common/tsUtils");
const UpdateChanges_1 = require("../common/UpdateChanges");
const version = '11.1.0';
exports.default = () => (host, context) => {
    var _a;
    context.logger.info(`Applying migration for Ignite UI for Angular to version ${version}`);
    const update = new UpdateChanges_1.UpdateChanges(__dirname, host, context);
    const tsFiles = update.tsFiles;
    const targetEnum = 'GridPagingMode';
    const changes = [
        { member: 'remote', replaceWith: 'Remote', definedIn: [targetEnum] },
        { member: 'local', replaceWith: 'Local', definedIn: [targetEnum] }
    ];
    for (const entryPath of tsFiles) {
        const ls = update.getDefaultLanguageService(entryPath);
        let content = host.read(entryPath).toString();
        for (const change of changes) {
            const matches = tsUtils_1.findMatches(content, change);
            for (const position of matches) {
                const definition = (_a = ls.getDefinitionAndBoundSpan(entryPath, position - 1)) === null || _a === void 0 ? void 0 : _a.definitions[0];
                if (definition
                    && definition.kind === 'enum'
                    && definition.name === targetEnum
                    && definition.fileName.includes('igniteui-angular')) {
                    content = tsUtils_1.replaceMatch(content, change.member, change.replaceWith, position);
                    host.overwrite(entryPath, content);
                }
            }
        }
    }
    update.applyChanges();
};
