import snow from "./eggs/snow"
import asteroids from "./eggs/asteroids/index"
import smoke from "./eggs/smoke"
import { $eventbus } from "@racletteCore/main"

const eggs = {
  asteroids: asteroids,
  xmas: snow,
}

const eggMe = (egg) => {
  if (!eggs[egg]) {
    return
  }

  return eggs[egg](() => {
    $eventbus.emit("ui/addToSnackbar", {
      i18n: "core.eggcontrols." + egg,
      color: "info",
    })
  })
}

const debounceHelper = (count, time = 800) => {
  let debounceTimer = false
  let triggered = 0

  return (func) => {
    triggered++
    clearTimeout(debounceTimer)
    debounceTimer = setTimeout(() => {
      if (func && triggered == count) {
        func()
      }
      triggered = 0
    }, time)
  }
}

export { eggMe, debounceHelper, smoke }
