import { Component } from '@angular/core';
import { DataService } from 'src/services/data/data.service';

@Component({
  selector: 'app-initiative',
  templateUrl: './initiative.component.html',
  styleUrls: ['./initiative.component.scss'],
})
export class InitiativeComponent {
  public constructor(public dataAccessor: DataService) {}

  public initiative: number = 0;

  ngOnInit(): void {
    this.initAttributeSubscription();
  }

  private initAttributeSubscription(): void {
    this.dataAccessor.initiative$.subscribe((newValue: any) => {
      this.initiative = newValue.value;
    });
  }

  public updateValue(): void {
    this.dataAccessor.updateCharacterData({
      name: 'initiative',
      value: this.initiative,
    });
  }
}
