import { inject } from '@angular/core';
import { ActivatedRouteSnapshot, ResolveFn } from '@angular/router';
import { take } from 'rxjs/operators';

import { ProductsPageData } from '@models';
import { ProductsService } from '@services';

export const productsResolver: ResolveFn<ProductsPageData> = (
    route: ActivatedRouteSnapshot
) => {
    return inject(ProductsService).getAllByCategory(route.params['category']).pipe(take(1));
};