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';
import { SmallChipComponent } from '@common-ui/shared';
import { AsyncPipe } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';

@Component({
    selector: 'redaction-dossier-state [dossier]',
    templateUrl: './dossier-state.component.html',
    styleUrls: ['./dossier-state.component.scss'],
    changeDetection: ChangeDetectionStrategy.OnPush,
    standalone: true,
    imports: [SmallChipComponent, AsyncPipe, TranslateModule],
})
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);
    }
}
