'use strict';

var vue = require('vue');

function createEventBus(config) {
  const options = typeof config === "string" ? { name: config, strict: true } : config;
  const injectionKey = /* @__PURE__ */ Symbol(`eventBus:${options.name}`);
  return {
    /**
     * 在顶层组件中提供事件处理器
     */
    provideEvents(handlers, app) {
      if (app) {
        app.provide(injectionKey, handlers);
      } else {
        vue.provide(injectionKey, handlers);
      }
    },
    /**
     * 在子组件中注入事件处理器
     */
    useEvents() {
      const events = vue.inject(injectionKey);
      if (options.strict && !events) {
        console.warn(
          `[EventBus] \u26A0\uFE0F "${options.name}" \u672A\u627E\u5230 provide\uFF01
\u8BF7\u786E\u4FDD\u5728\u9876\u5C42\u7EC4\u4EF6\u4E2D\u8C03\u7528\u4E86 provideEvents()`
        );
      }
      return events || options.defaultHandlers || {};
    },
    /**
     * 获取注入键（用于高级场景）
     */
    getKey() {
      return injectionKey;
    }
  };
}

exports.createEventBus = createEventBus;
