import { Component, OnInit }                        from "@angular/core";
import { Router, ActivatedRoute, Params }           from '@angular/router';

import { JobService }                               from '../../../services/svc.job'

@Component({
    moduleId: module.id+ '',
    selector: 'jobs',
    templateUrl: './tpl.jobs.pug',
    providers: [JobService]
})

export class JobView {

    jobs: any;
    title: string;

    constructor(
        private jobService: JobService,
        private route: ActivatedRoute
    ) {}

    ngOnInit(): void {
        this.route.params
            .switchMap((params: Params) => this.jobService.getSpecificJobPage(params['page']))
            .subscribe((response) => {
                this.jobs = response.list;
                
                this.title = this.createTitle(this.jobs[0].blockId);
            })
    }

    createTitle(title: string) {
        return title.replace('-', ' ');
    }
}