import { _ } from 'tnp-core/lib';
import { Helpers, HelpersTaon, UtilsTypescript } from 'tnp-helpers/lib';
import { appTsFromSrc, srcMainProject, } from '../../constants';
import { EnvOptions } from '../../options';
import { BaseCli } from './base-cli';
//#endregion
// @ts-ignore TODO weird inheritance problem
export class $Refactor extends BaseCli {
    //#region refactor
    async _() {
        Helpers.info(`Initing before refactor...`);
        // this._exit();
        await this.project.init(EnvOptions.from({ purpose: 'initing before refactor' }));
        Helpers.taskStarted('Refactoring...');
        await this.project.refactor.ALL({
            fixSpecificFile: this.firstArg,
        });
        Helpers.taskDone(`Done refactoring...`);
        this._exit();
    }
    //#endregion
    //#region prettier
    async prettier() {
        Helpers.info(`Initing before prettier...`);
        await this.project.init(EnvOptions.from({ purpose: 'initing before prettier' }));
        await this.project.refactor.prettier({
            fixSpecificFile: this.firstArg,
        });
        this._exit();
    }
    //#endregion
    //#region eslint
    async eslint() {
        Helpers.info(`Initing before eslint fix...`);
        await this.project.init(EnvOptions.from({ purpose: 'initing before eslint fix' }));
        await this.project.refactor.eslint({
            fixSpecificFile: this.firstArg,
        });
        this._exit();
    }
    //#endregion
    //#region removeBrowserRegion
    async removeBrowserRegion() {
        Helpers.info(`Initing before removing browser region...`);
        await this.project.init(EnvOptions.from({ purpose: 'initing before removing browser region' }));
        await this.project.refactor.removeBrowserRegion({
            fixSpecificFile: this.firstArg,
        });
        this._exit();
    }
    //#endregion
    //#region changeCssToScss
    async changeCssToScss() {
        Helpers.info(`Initing before changing css to scss...`);
        await this.project.init(EnvOptions.from({ purpose: 'initing before changing css to scss' }));
        await this.project.refactor.changeCssToScss({
            fixSpecificFile: this.firstArg,
        });
        this._exit();
    }
    //#endregion
    //#region properStandaloneNg19
    async properStandaloneNg19() {
        Helpers.info(`Initing before changing standalone property..`);
        await this.project.init(EnvOptions.from({
            purpose: 'initing before changing standalone property',
        }));
        await this.project.refactor.properStandaloneNg19({
            fixSpecificFile: this.firstArg,
        });
        this._exit();
    }
    //#endregion
    //#region imports region wrap
    async importsWrap() {
        Helpers.info(`Initing before wrapping imports..`);
        await this.project.init(EnvOptions.from({ purpose: 'initing before wrapping imports' }));
        await this.project.refactor.importsWrap({
            fixSpecificFile: this.firstArg,
        });
        this._exit();
    }
    //#endregion
    //#region flatten imports
    async flattenImports() {
        Helpers.info(`Initing before flattening imports..`);
        await this.project.init(EnvOptions.from({ purpose: 'initing before flattening imports' }));
        await this.project.refactor.flattenImports({
            fixSpecificFile: this.firstArg,
        });
        this._exit();
    }
    //#endregion
    //#region refactor taon names
    async taonNames() {
        await this.project.refactor.taonNames({
            fixSpecificFile: this.firstArg,
        });
        this._exit();
    }
    //#endregion
    //#region ng21 update
    async ng21() {
        //#region @backendFunc
        Helpers.info(`Initing before migrating to Angular v21 standalone...`);
        const appFile = this.project.pathFor([srcMainProject, appTsFromSrc]);
        let tsFileContent = await Helpers.readFile(appFile);
        tsFileContent = UtilsTypescript.migrateFromNgModulesToStandaloneV21(tsFileContent, _.upperFirst(_.camelCase(this.project.name)));
        // import { RenderMode, ServerRoute } from '@angular/ssr';
        tsFileContent = UtilsTypescript.addOrUpdateImportIfNotExists(tsFileContent, ['RenderMode', 'ServerRoute', 'provideServerRendering', 'withRoutes'], '@angular/ssr');
        tsFileContent = UtilsTypescript.addOrUpdateImportIfNotExists(tsFileContent, [
            'ApplicationConfig',
            'mergeApplicationConfig',
            'provideBrowserGlobalErrorListeners',
            'APP_INITIALIZER',
            'isDevMode',
        ], '@angular/core');
        tsFileContent = UtilsTypescript.addOrUpdateImportIfNotExists(tsFileContent, ['provideClientHydration', 'withEventReplay'], '@angular/platform-browser');
        // import { provideServiceWorker } from '@angular/service-worker';
        tsFileContent = UtilsTypescript.addOrUpdateImportIfNotExists(tsFileContent, ['provideServiceWorker'], '@angular/service-worker');
        // provideRouter
        tsFileContent = UtilsTypescript.addOrUpdateImportIfNotExists(tsFileContent, ['provideRouter'], '@angular/router');
        await Helpers.writeFile(appFile, tsFileContent);
        UtilsTypescript.formatFile(appFile);
        Helpers.info(`Migrated to Angular v21 standalone in ${appFile}`);
        this._exit();
        //#endregion
    }
    //#endregion
    async selfImports() {
        await this.project.refactor.selfImports({
            fixSpecificFile: this.firstArg,
        });
        this._exit();
    }
    async classIntoNs() {
        await this.project.refactor.classIntoNs({
            fixSpecificFile: this.firstArg,
        });
        this._exit();
    }
}
export default {
    $Refactor: HelpersTaon.CLIWRAP($Refactor, '$Refactor'),
};
//# sourceMappingURL=cli-REFACTOR.js.map