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

import { ArticlePageData } from '@models';
import { ArticlesService } from '@services';

export const articleResolver: ResolveFn<ArticlePageData> = (
    route: ActivatedRouteSnapshot
) => {
    return inject(ArticlesService).get(route.params['slug']).pipe(take(1));
};