import { Text } from "pixi.js"
import { System } from "ecsy"
import globals from "../../globals"

// InfoSystem
export class TooltipSystem extends System {
  priority = 61

  tooltip: Text
  source: any
  active = false

  init() {
    this.tooltip = new Text("Lorem Ipsum", {
      fontFamily: "babyblocks",
      fontSize: 8,
      fill: 0x000000,

      stroke: 0xeec39a,
      strokeThickness: 2,
    })
    globals.app.stage.addChild(this.tooltip)
    this.tooltip.anchor.set(0, 1)
    this.tooltip.zIndex = 1100
    this.tooltip.visible = false
  }

  showTooltip(text: string, source: any) {
    this.active = true
    this.source = source
    this.tooltip.text = text
    this.tooltip.visible = true
    this.updatePosition()
  }

  cancelTooltip(source: any) {
    if (this.source === source) {
      this.active = false
      this.tooltip.visible = false
    }
  }

  execute(delta: number) {
    if (this.active) {
      this.updatePosition()
    }
  }

  updatePosition() {
    let pos = globals.app.renderer.plugins.interaction.mouse.global
    this.tooltip.position = pos
  }

  static queries = {}
  queries: any
}
