import {AnalyticalScope, Behavior, TextField} from "@webbpm/base-package";
import {AuthorizationService} from "../../modules/app/service/authorization.service";

@AnalyticalScope("TextField")
export class SetCurrentUserIdAsDefValue extends Behavior {
  private textField: TextField;
  private authService: AuthorizationService;

  initialize() {
    super.initialize();
    this.textField = this.getScript('component.ControlWithValue');
    this.authService = this.injector.get(AuthorizationService);
  }

  start(): void {
    super.start();
    if (this.textField && this.textField.isPristine() && this.authService &&
        this.authService.getCurrentSession()) {
      this.textField.setValue(this.authService.getUserId());
      this.getContext().getChangeDetector().detectChanges();
    }
  }
}
