import { LowCodeModuleParser, IEvaledModule, LowcodeContext, getDefaultModule } from './base';

export class RendererParser implements LowCodeModuleParser {
  renderer: any;

  onStart(context: LowcodeContext) {
    this.renderer = {};
  }

  parseModule(pageId: string, mod: IEvaledModule) {
    if (mod.name === '____index____') return;

    const [, , folder] = mod.path?.split('/');
    if (folder) {
      this.renderer[pageId] = this.renderer[pageId] || {};
      this.renderer[pageId][folder] = getDefaultModule(mod.exports);
    } else this.renderer[pageId] = getDefaultModule(mod.exports);
  }

  onEnd(context: LowcodeContext) {
    context.renderer = this.renderer;
  }
}
