import { Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core'
import { RemoteModuleLoaderService } from '../service/remote-module-loader.service'
import { ActivatedRoute, Router } from '@angular/router'
import { MySharedService } from 'my-shared'
import Autofit from 'autofit.js'
@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.scss'],
})
export class HomeComponent implements OnInit, OnDestroy {
  tasks = [
    { title: '到款认领系统', description: '商家到款认领专用查询入口', modulePath: '/home/mfe1' },
    { title: '财务管理系统', description: '财务新应用专用查询入口', modulePath: '/home/mfe2' },
    { title: '其他', description: '其他应用专用查询入口', modulePath: '/home/mfe3' },
  ]
  show: any
  constructor(
    private router: Router,
    private route: ActivatedRoute,
    private remoteModuleLoaderService: RemoteModuleLoaderService,
    public mySharedService: MySharedService
  ) {}
  @ViewChild('mainDiv')
  mainDiv!: ElementRef
  ngOnInit(): void {
    this.mySharedService.getData()
  }
  ngAfterViewInit(): void {
    Autofit.init(
      {
        dh: 1080,
        dw: 1920,
        el: '#mainDiv',
        resize: true,
      },
      false
    )
  }
  ngOnDestroy(): void {
    // console.log('Shell HomeComponent Destroy')
  }

  loadRemoteModule(modulePath: string, index: any) {
    this.show = index + 1
    this.router.navigate([modulePath])
  }

  goToTask(id: string) {
    this.router.navigate(['/task'])
  }

  goToShell(): void {
    this.router.navigate([''])
  }
}
