import { ReflectUtils } from "@dooboostore/core/reflect/ReflectUtils";
const EMIT_CUSTOM_EVENT_METADATA_KEY = Symbol("simple-web-component:emit-custom-event");
function emitCustomEvent(typeOrOptions) {
  return (target, propertyKey, descriptor) => {
    const constructor = target.constructor;
    const options = typeof typeOrOptions === "string" ? { type: typeOrOptions } : typeOrOptions;
    if (!options.attributeName) {
      options.attributeName = `on${options.type}`;
    }
    if (options.bubbles === void 0) options.bubbles = true;
    if (options.composed === void 0) options.composed = true;
    let list = ReflectUtils.getMetadata(EMIT_CUSTOM_EVENT_METADATA_KEY, constructor);
    if (!list) {
      list = [];
      ReflectUtils.defineMetadata(EMIT_CUSTOM_EVENT_METADATA_KEY, list, constructor);
    }
    list.push({ propertyKey, options });
    const originalMethod = descriptor.value;
    descriptor.value = function(...args) {
      const detail = originalMethod.apply(this, args);
      const event = new CustomEvent(options.type, {
        detail,
        bubbles: options.bubbles,
        composed: options.composed,
        cancelable: options.cancelable
      });
      this.dispatchEvent(event);
      return detail;
    };
  };
}
const getEmitCustomEventMetadataList = (target) => {
  const constructor = target instanceof Function ? target : target.constructor;
  return ReflectUtils.getMetadata(EMIT_CUSTOM_EVENT_METADATA_KEY, constructor);
};
export {
  EMIT_CUSTOM_EVENT_METADATA_KEY,
  emitCustomEvent,
  getEmitCustomEventMetadataList
};
//# sourceMappingURL=emitCustomEvent.js.map
