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

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

  public armorClass: number = 0;

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

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

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