import { ReflectUtils } from "@dooboostore/core/reflect/ReflectUtils";
const ON_BEFORE_CONNECTED_METADATA_KEY = Symbol("simple-web-component:on-before-connected");
const ON_AFTER_CONNECTED_METADATA_KEY = Symbol("simple-web-component:on-after-connected");
const ON_BEFORE_DISCONNECTED_METADATA_KEY = Symbol("simple-web-component:on-before-disconnected");
const ON_AFTER_DISCONNECTED_METADATA_KEY = Symbol("simple-web-component:on-after-disconnected");
const ON_BEFORE_ADOPTED_METADATA_KEY = Symbol("simple-web-component:on-before-adopted");
const ON_AFTER_ADOPTED_METADATA_KEY = Symbol("simple-web-component:on-after-adopted");
const ON_ADD_EVENT_LISTENER_METADATA_KEY = Symbol("simple-web-component:on-add-event-listener");
const ON_ATTRIBUTE_CHANGED_METADATA_KEY = Symbol("simple-web-component:on-attribute-changed");
const ON_MUTATION_SUBSCRIBE_METADATA_KEY = Symbol("simple-web-component:on-mutation-observed");
const ATTRIBUTE_CHANGED_WILDCARD = "*";
function createLifecycleDecorator(metadataKey) {
  return (target, propertyKey) => {
    const constructor = target.constructor;
    let list = ReflectUtils.getMetadata(metadataKey, constructor);
    if (!list) {
      list = [];
      ReflectUtils.defineMetadata(metadataKey, list, constructor);
    }
    list.push(propertyKey);
  };
}
const onBeforeConnected = createLifecycleDecorator(ON_BEFORE_CONNECTED_METADATA_KEY);
const onAfterConnected = createLifecycleDecorator(ON_AFTER_CONNECTED_METADATA_KEY);
const onConnected = onAfterConnected;
const onBeforeDisconnected = createLifecycleDecorator(ON_BEFORE_DISCONNECTED_METADATA_KEY);
const onAfterDisconnected = createLifecycleDecorator(ON_AFTER_DISCONNECTED_METADATA_KEY);
const onDisconnected = onAfterDisconnected;
const onBeforeAdopted = createLifecycleDecorator(ON_BEFORE_ADOPTED_METADATA_KEY);
const onAfterAdopted = createLifecycleDecorator(ON_AFTER_ADOPTED_METADATA_KEY);
const onAdopted = onAfterAdopted;
const onAddEventListener = createLifecycleDecorator(ON_ADD_EVENT_LISTENER_METADATA_KEY);
function onAttributeChanged(arg1, arg2, arg3) {
  const decorator = (attributeName, target, propertyKey) => {
    const constructor = target.constructor;
    let meta = ReflectUtils.getMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, constructor);
    if (!meta) {
      meta = /* @__PURE__ */ new Map();
      ReflectUtils.defineMetadata(ON_ATTRIBUTE_CHANGED_METADATA_KEY, meta, constructor);
    }
    let methods = meta.get(attributeName);
    if (!methods) {
      methods = [];
      meta.set(attributeName, methods);
    }
    if (!methods.includes(propertyKey)) {
      methods.push(propertyKey);
    }
  };
  if (typeof arg1 === "string") {
    return (target, propertyKey) => {
      decorator(arg1, target, propertyKey);
    };
  } else if (Array.isArray(arg1)) {
    return (target, propertyKey) => {
      arg1.forEach((name) => decorator(name, target, propertyKey));
    };
  } else if (arg1 && arg2) {
    decorator(ATTRIBUTE_CHANGED_WILDCARD, arg1, arg2);
  }
}
const getLifecycleMetadata = (target, metadataKey) => {
  const constructor = target instanceof Function ? target : target.constructor;
  return ReflectUtils.getMetadata(metadataKey, constructor);
};
function onMutationSubscribe(arg1, arg2, arg3) {
  const register = (options, target, propertyKey) => {
    const constructor = target.constructor;
    let list = ReflectUtils.getMetadata(ON_MUTATION_SUBSCRIBE_METADATA_KEY, constructor);
    if (!list) {
      list = [];
      ReflectUtils.defineMetadata(ON_MUTATION_SUBSCRIBE_METADATA_KEY, list, constructor);
    }
    list.push({ propertyKey, options });
  };
  if (arg2 !== void 0) {
    register({ root: "auto" }, arg1, arg2);
    return;
  }
  return (target, propertyKey) => {
    register(arg1 || { root: "auto" }, target, propertyKey);
  };
}
const getMutationSubscribeMetadataList = (target) => {
  const constructor = target instanceof Function ? target : target.constructor;
  return ReflectUtils.getMetadata(ON_MUTATION_SUBSCRIBE_METADATA_KEY, constructor);
};
export {
  ATTRIBUTE_CHANGED_WILDCARD,
  ON_ADD_EVENT_LISTENER_METADATA_KEY,
  ON_AFTER_ADOPTED_METADATA_KEY,
  ON_AFTER_CONNECTED_METADATA_KEY,
  ON_AFTER_DISCONNECTED_METADATA_KEY,
  ON_ATTRIBUTE_CHANGED_METADATA_KEY,
  ON_BEFORE_ADOPTED_METADATA_KEY,
  ON_BEFORE_CONNECTED_METADATA_KEY,
  ON_BEFORE_DISCONNECTED_METADATA_KEY,
  ON_MUTATION_SUBSCRIBE_METADATA_KEY,
  getLifecycleMetadata,
  getMutationSubscribeMetadataList,
  onAddEventListener,
  onAdopted,
  onAfterAdopted,
  onAfterConnected,
  onAfterDisconnected,
  onAttributeChanged,
  onBeforeAdopted,
  onBeforeConnected,
  onBeforeDisconnected,
  onConnected,
  onDisconnected,
  onMutationSubscribe
};
//# sourceMappingURL=lifecycles.js.map
