import {Component, Input, OnInit} from '@angular/core';
import {BehaviorSubject} from 'rxjs';
import {Pentest} from '@shared/models/pentest.model';
import {getPentestInfoForObjective} from '@shared/functions/infos/get-pentest-info-for-objective';
import {getTitleKeyForRefNumber} from '@shared/functions/categories/get-title-key-for-ref-number.function';
import {ProjectState} from '@shared/stores/project-state/project-state';
import {UntilDestroy, untilDestroyed} from '@ngneat/until-destroy';
import {Store} from '@ngxs/store';

@UntilDestroy()
@Component({
  selector: 'app-pentest-info',
  templateUrl: './pentest-info.component.html',
  styleUrls: ['./pentest-info.component.scss']
})
export class PentestInfoComponent implements OnInit {

  pentestInfo$: BehaviorSubject<Pentest> = new BehaviorSubject<Pentest>(null);

  constructor(private store: Store) { }

  ngOnInit(): void {
    this.store.selectOnce(ProjectState.pentest).pipe(
      untilDestroyed(this)
    ).subscribe({
      next: (selectedPentest: Pentest) => {
        this.pentestInfo$.next(selectedPentest);
      },
      error: err => {
        console.error(err);
      }
    });
  }

  getPentestHeaderForObjective(refNumber: string): string {
    return getTitleKeyForRefNumber(refNumber);
  }

  getPentestInfoForObjective(refNumber: string): string {
    return getPentestInfoForObjective(refNumber);
  }

}
