import { Component, inject, input } from '@angular/core';
import { Publisher, PublisherDetails } from '../comic.model';
import { ComicPublishersListComponent } from '../comic-publishers-list/comic-publishers-list.component';
import { ActivatedRouteSnapshot, ResolveFn, RouterStateSnapshot } from '@angular/router';
import { PublisherService } from './publisher.service';
import { ComicPublisherComponent } from "../comic-publisher/comic-publisher.component";
import { ComicComicComponent } from "../comic-comic/comic-comic.component";

@Component({
  selector: 'app-comic-publishers',
  imports: [ComicPublishersListComponent, ComicPublisherComponent, ComicComicComponent],
  templateUrl: './comic-publishers.component.html',
  styleUrl: './comic-publishers.component.css'
})
export class ComicPublishersComponent {
  publisher = input.required<PublisherDetails>();
}

export const publisherResolver: ResolveFn<PublisherDetails> = (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => {
  const publisherService = inject(PublisherService);
  const publisherId = route.paramMap.get('publisherId');
  const publisherDetails = publisherService.loadPublisherDetails(publisherId);
  console.log(publisherDetails);
  return publisherDetails;
};
