import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Resolve } from '@angular/router';
import { IBreadCrumbItem } from '@components/page/breadcrumds/page-breadcrumbs.component';
import { ScheduleBreadCrumbService } from '@schedule/services/bread-crumb.service';
import { ScheduleRequestDataResolver } from '@schedule/resolvers/request-data.resolver';

@Injectable()
export class ScheduleDetailsBreadCrumbsResolver
    implements Resolve<IBreadCrumbItem[]>
{
    constructor(
        private breadCrumbsService: ScheduleBreadCrumbService,
        private requestDataResolver: ScheduleRequestDataResolver,
    ) {}

    async resolve(route: ActivatedRouteSnapshot) {
        const requestData = this.requestDataResolver.resolve(route);
        const items = [this.breadCrumbsService.getRootBreadCrumb()];

        if (requestData) {
            const item = await this.breadCrumbsService.getSearchPageBreadCrumb(
                requestData.parsed.outbound,
            );
            items.push(item);
        }

        return items;
    }
}
