"use strict";
/**
 * Migration: Update runtime logger call from warn to log
 *
 * Updates runtime.tsx files to change logger.warn to logger.log
 * for the missing Kaltura analytics app id message.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = update;
const devkit_1 = require("@nx/devkit");
async function update(tree) {
    devkit_1.logger.info('🔄 Updating runtime logger calls...');
    const runtimesDir = 'unisphere/runtimes';
    if (!tree.exists(runtimesDir)) {
        devkit_1.logger.info('ℹ️ No runtimes directory found');
        return;
    }
    let updatedCount = 0;
    // Find all runtime.tsx files
    (0, devkit_1.visitNotIgnoredFiles)(tree, runtimesDir, (filePath) => {
        if (filePath.endsWith('/src/lib/runtime.tsx')) {
            const content = tree.read(filePath, 'utf-8');
            if (!content) {
                return;
            }
            // Check if the old pattern exists
            const oldPattern = 'this._logger.warn(`missing kaltura analytics app id, cannot register application to analytics service`)';
            if (content.includes(oldPattern)) {
                const newPattern = 'this._logger.log(`missing kaltura analytics app id, skip application registration to analytics service`)';
                const updatedContent = content.replace(oldPattern, newPattern);
                tree.write(filePath, updatedContent);
                updatedCount++;
                devkit_1.logger.info(`  ✅ Updated ${filePath}`);
            }
        }
    });
    if (updatedCount === 0) {
        devkit_1.logger.info('ℹ️ No runtime files found with the old logger pattern');
    }
    else {
        devkit_1.logger.info(`✅ Updated ${updatedCount} runtime file(s)`);
    }
    await (0, devkit_1.formatFiles)(tree);
}
