import { Component, OnInit, Input, ViewChild,
    ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core'

import { FullInfo, InfoDataService } from '../info-data.service'
import { MapControlService } from '../../map/map-control.service'
import { Tag, TagActions } from './tags.service'
import { TagFormComponent } from './tag-form.component'

@Component({
    selector: 'gisaf-tags',
    templateUrl: './tags.component.html',
    styleUrls: ['./tags.component.css'],
    changeDetection: ChangeDetectionStrategy.OnPush,
})
export class InfoTagsComponent implements OnInit {
    @ViewChild(TagFormComponent, {static: true}) form: TagFormComponent
    _source: FullInfo
    @Input() set source(_source: FullInfo) {
        this._source = _source
        this.cdr.markForCheck()
    }
    tags: Tag[] = []
    links: TagActions[] = []

    constructor(
        protected infoDataService: InfoDataService,
        protected mapControlService: MapControlService,
        private cdr: ChangeDetectorRef,
    ) {}

    ngOnInit() {
        this.infoDataService.dataProviderService$.subscribe(
            source => {
                this._source = source
                this.tags = this._source.featureInfo.tags
                this.cdr.markForCheck()
            }
        )
    }
}
