var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var emitCustomEvent_exports = {};
__export(emitCustomEvent_exports, {
  EMIT_CUSTOM_EVENT_METADATA_KEY: () => EMIT_CUSTOM_EVENT_METADATA_KEY,
  emitCustomEvent: () => emitCustomEvent,
  getEmitCustomEventMetadataList: () => getEmitCustomEventMetadataList
});
module.exports = __toCommonJS(emitCustomEvent_exports);
var import_ReflectUtils = require("@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 = import_ReflectUtils.ReflectUtils.getMetadata(EMIT_CUSTOM_EVENT_METADATA_KEY, constructor);
    if (!list) {
      list = [];
      import_ReflectUtils.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 import_ReflectUtils.ReflectUtils.getMetadata(EMIT_CUSTOM_EVENT_METADATA_KEY, constructor);
};
//# sourceMappingURL=emitCustomEvent.js.map
