// event-bus.js
import { createApp } from 'vue'

export const EventBus = {
  _events: {},

  on(event, callback) {
    if (!this._events[event]) {
      this._events[event] = []
    }
    this._events[event].push(callback)
  },

  off(event, callback) {
    if (!this._events[event]) return

    if (callback) {
      this._events[event] = this._events[event].filter((cb) => cb !== callback)
    } else {
      delete this._events[event]
    }
  },

  emit(event, data) {
    if (!this._events[event]) return

    this._events[event].forEach((callback) => {
      callback(data)
    })
  },
}
