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

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

export const productResolver: ResolveFn<ProductPageData> = (
    route: ActivatedRouteSnapshot
) => {
    return inject(ProductsService).getProductBySlug(route.params['slug']).pipe(take(1));
};