import { Component, forwardRef, Input } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { TranslateService } from '@ngx-translate/core';

@Component({
  selector: 'value-box',
  templateUrl: './value-box.component.html',
  styleUrl: './value-box.component.scss',
  providers: [
    {
      provide: NG_VALUE_ACCESSOR,
      useExisting: forwardRef(() => ValueBoxComponent),
      multi: true,
    },
  ],
})
export class ValueBoxComponent {
  public data: any;
  @Input() value: any;
  @Input() label!: string;
  @Input() isInput: boolean = false;

  onChange: any = () => {};
  onTouched: any = () => {};

  constructor(public translate: TranslateService) {}

  writeValue(data: any): void {
    this.data = data;
  }

  registerOnChange(fn: any): void {
    this.onChange = fn;
  }

  registerOnTouched(fn: any): void {
    this.onTouched = fn;
  }
}
