import { ChangeDetectionStrategy, Component, Input, OnChanges } from '@angular/core';
import { Dossier, DossierState } from '@red/domain';
import { DossierStatesMapService } from '@services/entity-services/dossier-states-map.service';
import { Observable } from 'rxjs';

@Component({
    selector: 'redaction-dossier-state [dossier]',
    templateUrl: './dossier-state.component.html',
    styleUrls: ['./dossier-state.component.scss'],
    changeDetection: ChangeDetectionStrategy.OnPush,
})
export class DossierStateComponent implements OnChanges {
    @Input() dossier: Dossier;
    dossierState$: Observable<DossierState>;

    constructor(private readonly _dossierStatesMapService: DossierStatesMapService) {}

    ngOnChanges(): void {
        this.dossierState$ = this._dossierStatesMapService.watch$(this.dossier.dossierTemplateId, this.dossier.dossierStatusId);
    }
}
