"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = update;
const devkit_1 = require("@nx/devkit");
async function update(tree) {
    devkit_1.logger.info('🔄 Starting WidgetName to widgetName migration...');
    let filesUpdated = 0;
    // Update TypeScript and TSX files in the workspace
    (0, devkit_1.visitNotIgnoredFiles)(tree, '.', (filePath) => {
        // Only process TypeScript and TSX files in unisphere directories
        if ((!filePath.endsWith('.ts') && !filePath.endsWith('.tsx')) ||
            !filePath.includes('unisphere/')) {
            return;
        }
        const content = tree.read(filePath, 'utf-8');
        if (!content)
            return;
        let hasChanges = false;
        let updatedContent = content;
        // Simple global replacement: WidgetName -> widgetName
        if (content.includes('WidgetName')) {
            updatedContent = updatedContent.replace(/WidgetName/g, 'widgetName');
            hasChanges = true;
        }
        if (hasChanges) {
            tree.write(filePath, updatedContent);
            filesUpdated++;
            devkit_1.logger.info(`✅ Updated WidgetName references in ${filePath}`);
        }
    });
    if (filesUpdated > 0) {
        await (0, devkit_1.formatFiles)(tree);
        devkit_1.logger.info(`✅ WidgetName to widgetName migration completed. Updated ${filesUpdated} files.`);
    }
    else {
        devkit_1.logger.info('ℹ️ No WidgetName references found to migrate.');
    }
}
