import { Component, OnInit,
    ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core'
import { ActivatedRoute, Router, ParamMap } from '@angular/router'

import { map, startWith, switchMap } from 'rxjs/operators'
import { Observable, of } from 'rxjs'

import { DataService } from '../_services/data.service'
import { ConfigService } from '../_services/config.service'
import { DataProvider } from '../openapi'

@Component({
    selector: 'gisaf-measures',
    templateUrl: './measures.component.html',
    styleUrls: ['./measures.component.scss'],
    changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MeasuresComponent implements OnInit {
    stores: DataProvider[] = []

    constructor(
        public configService: ConfigService,
        private _dataService: DataService,
        protected route: ActivatedRoute,
        protected router: Router,
        private cdr: ChangeDetectorRef,
    ) {}

    ngOnInit() {
        this._dataService.getResources().subscribe(
            data => {
                this.stores = data
                this.cdr.markForCheck()
            }
        )

        /*
        this.route.paramMap.subscribe(
            (params: ParamMap) => {
                // FIXME: the route is lost
                this.router.navigate(['/measures', this.conf['measures']['defaultStore']])
            }
        )
        */
    }
}
