import { Injectable, inject } from '@angular/core';
import { Router } from '@angular/router';
import { BootstrapConfig } from '../../../shared/models/config';
import { PlatformRuntimeService } from '../../../core/runtime/platform-runtime.service';
import { LanguageService } from '../../../services/language.service';
import { UiRuntimeFacade } from '../../../facades/runtime/ui-runtime.facade';

@Injectable({ providedIn: 'root' })
export class ProjectEditorPreviewService {
  private readonly runtime = inject(PlatformRuntimeService);
  private readonly router = inject(Router);
  private readonly languageService = inject(LanguageService);
  private readonly uiRuntime = inject(UiRuntimeFacade);

  preview(bootstrap: BootstrapConfig): void {
    this.runtime.reloadFromBootstrap(bootstrap);
    this.uiRuntime.reloadFromBootstrap(bootstrap);
    void this.router.navigate([`/${this.languageService.currentLanguage()}`]);
  }
}
