import { Component, inject, input } from '@angular/core';
import { ComicArtistsListComponent } from '../comic-artists-list/comic-artists-list.component';
import { ActivatedRouteSnapshot, ResolveFn, RouterStateSnapshot } from '@angular/router';
import { ArtistService } from './artist.service';
import { ComicComicComponent } from "../comic-comic/comic-comic.component";
import { ComicWorktypeComponent } from "../comic-worktype/comic-worktype.component";
import { ArtistDetails } from '../comic.model';

@Component({
  selector: 'app-comic-artists',
  imports: [ComicArtistsListComponent, ComicComicComponent, ComicWorktypeComponent],
  templateUrl: './comic-artists.component.html',
  styleUrl: './comic-artists.component.css'
})
export class ComicArtistsComponent {
  artist = input.required<ArtistDetails>();
}

export const artistResolver: ResolveFn<ArtistDetails> = (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => {
  const artistService = inject(ArtistService);
  const artistId = route.paramMap.get('artistId');
  const artistDetails = artistService.loadArtistDetails(artistId);
  console.log(artistDetails);
  return artistDetails;
};
