import { Component, ComponentNames } from ".";
import { Direction } from "../interfaces";

export class Highlight extends Component {
  public isHighlighted: boolean;
  private onHighlight: Function;
  private onUnhighlight: Function;

  constructor(
    onHighlight: (direction: Direction) => void,
    onUnhighlight: () => void,
    isHighlighted: boolean = false
  ) {
    super(ComponentNames.Highlight);

    this.isHighlighted = isHighlighted;
    this.onHighlight = onHighlight;
    this.onUnhighlight = onUnhighlight;
  }

  public highlight(direction: Direction) {
    if (!this.isHighlighted) {
      this.isHighlighted = true;
      this.onHighlight(direction);
    }
  }

  public unhighlight() {
    if (this.isHighlighted) {
      this.isHighlighted = false;
      this.onUnhighlight();
    }
  }
}
