import Tool from "../core/tool"
import OrderEditLayer from "./order-edit-layer";



export default class OrderPlayTool extends Tool {
  orderEditLayer : OrderEditLayer;

  constructor(orderEditLayer : OrderEditLayer) {
    super('order-edit-play', 'pointer');
    this.orderEditLayer = orderEditLayer;
  }
  
  override onclick(evt: MouseEvent): void {
  
    if (!this.orderEditLayer) return; 

    console.log('OrderPlayTool@onclick');
    if (!this.orderEditLayer.playInterval) {
      this.orderEditLayer.playStep();
    }
  }

  override ondblclick(evt: MouseEvent): void {
    if (!this.orderEditLayer) return;

    console.log('OrderPlayTool@ondblclick');
    if (!this.orderEditLayer.playInterval) {
      this.orderEditLayer.playAuto();
    } else {
      this.orderEditLayer.playStop();
    }
  }

  override onSelect(): void {
    if (!this.orderEditLayer) return;

    this.orderEditLayer.invalidate();
    this.orderEditLayer.resetPlay();
    this.orderEditLayer.playAuto();
  }

}