'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var node_path = require('node:path');
var process = require('node:process');
var ts = require('typescript');
var utils_angularParsing = require('../../utils/angular-parsing.js');
var utils_packageConfig = require('../../utils/package-config.js');
var utils_typescript = require('../../utils/typescript.js');
require('path');
require('../../utils/ast.js');
require('@angular-devkit/schematics');
require('@schematics/angular/utility');
require('../../utils/messages.js');

function _interopNamespaceDefault(e) {
    var n = Object.create(null);
    if (e) {
        Object.keys(e).forEach(function (k) {
            if (k !== 'default') {
                var d = Object.getOwnPropertyDescriptor(e, k);
                Object.defineProperty(n, k, d.get ? d : {
                    enumerable: true,
                    get: function () { return e[k]; }
                });
            }
        });
    }
    n.default = e;
    return Object.freeze(n);
}

var process__namespace = /*#__PURE__*/_interopNamespaceDefault(process);

const migrationData = {
    elementName: 'kbq-loader-overlay',
    attrs: {
        key: {
            from: 'compact',
            to: 'size'
        },
        value: {
            replacements: [
                { from: 'true', to: 'compact' },
                { from: 'false', to: 'big' }
            ],
            default: 'big'
        }
    }
};
function migrate(options) {
    return async (tree, context) => {
        const { project } = options;
        const { tsPaths, templatePaths, projectDefinition } = await utils_packageConfig.getParsingInfo(project, tree);
        const program = ts.createProgram(Array.from(tsPaths, (item) => node_path.resolve(projectDefinition.root, `.${item}`)), {
            baseUrl: projectDefinition.root,
            rootDir: projectDefinition.root,
            _enableTemplateTypeChecker: true, // Required for the template type checker to work.
            compileNonExportedClasses: true, // We want to migrate non-exported classes too.
            // Avoid checking libraries to speed up the migration.
            skipLibCheck: true,
            skipDefaultLibCheck: true
        });
        // Update external html
        await utils_angularParsing.migrateTemplate(tree, Array.from(templatePaths), context, migrationData);
        // Update inline html
        await utils_angularParsing.migrateTs(tree, program.getSourceFiles().filter((sourceFile) => utils_typescript.canMigrateFile(sourceFile, program)), process__namespace.cwd(), context, migrationData);
        context.logger.warn('Warning! Run linter in updated files since line breaks or indents maybe be broken.');
    };
}

exports.default = migrate;
exports.migrationData = migrationData;
