import {
  AbstractButton,
  AnalyticalScope,
  Behavior,
  ControlWithValue, NotNull, ObjectRef,
  StringUtils,
  Visible
} from "@webbpm/base-package";

@AnalyticalScope(AbstractButton)
export class ValueComposer extends Behavior {

  @NotNull()
  @ObjectRef()
  public valueSource: ControlWithValue;
  @NotNull()
  public expression: string;
  @NotNull()
  public pattern: string;

  @Visible()
  getValue(): string {
    let value: string = StringUtils.toString(this.valueSource.getPresentationValue());
    return this.expression.replace(this.pattern, value);
  }
}
