import { Component } from '@angular/core';
import { DataService } from 'src/services/data/data.service';
import { DetailsService } from 'src/services/details/details.service';
import { ProficiencyDetailsComponent } from './proficiency-details/proficiency-details.component';

@Component({
  selector: 'proficiency',
  templateUrl: './proficiency-field.component.html',
  styleUrls: ['./proficiency-field.component.scss'],
})
export class ProficiencyFieldComponent {
  public constructor(
    public dataAccessor: DataService,
    public detailsAccessor: DetailsService,
  ) {}

  public proficiency: number = 0;

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

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

  public updateValue(): void {
    this.dataAccessor.updateProficiencyBonus(this.proficiency);
  }

  public openDetails(): void {
    this.detailsAccessor.openPanel(ProficiencyDetailsComponent, {
      proficiency: this.proficiency,
    });
  }
}
