import { ReflectUtils } from "@dooboostore/core/reflect/ReflectUtils";
const QUERY_METADATA_KEY = Symbol("simple-web-component:query");
function query(arg1, arg2) {
  const decorator = (selector, options, target, propertyKey, descriptor) => {
    const isMethod = !!descriptor;
    const constructor = target.constructor;
    let queries = ReflectUtils.getMetadata(QUERY_METADATA_KEY, constructor);
    if (!queries) {
      queries = [];
      ReflectUtils.defineMetadata(QUERY_METADATA_KEY, queries, constructor);
    }
    queries.push({ selector, options, propertyKey, isMethod });
    if (!isMethod) {
      Object.defineProperty(target, propertyKey, {
        get() {
          if (!selector)
            return this;
          let searchRoot = this;
          if (options.root === "shadow")
            searchRoot = this.shadowRoot || this;
          else if (options.root === "light")
            searchRoot = this;
          else
            searchRoot = this.shadowRoot || this;
          return searchRoot.querySelector(selector);
        },
        enumerable: true,
        configurable: true
      });
    }
  };
  if (arg1 && typeof arg2 === "string") {
    return decorator("", {}, arg1, arg2);
  }
  return (target, propertyKey, descriptor) => {
    let selector = "";
    let options = {};
    if (typeof arg1 === "string") {
      selector = arg1;
    } else if (typeof arg1 === "object") {
      options = arg1;
      selector = options.selector || "";
    }
    decorator(selector, options, target, propertyKey, descriptor);
  };
}
const getQueryMetadata = (target) => {
  const constructor = target instanceof Function ? target : target.constructor;
  return ReflectUtils.getMetadata(QUERY_METADATA_KEY, constructor);
};
export {
  QUERY_METADATA_KEY,
  getQueryMetadata,
  query
};
//# sourceMappingURL=query.js.map
