;
{
  try {
    let e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {}, n = new e.Error().stack;
    n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "33fae334-bea7-47d2-9e4a-442346532ea0", e._sentryDebugIdIdentifier = "sentry-dbid-33fae334-bea7-47d2-9e4a-442346532ea0");
  } catch (e) {
  }
}
;
import { skipToken } from "@tanstack/preact-query";
import { useMemo } from "preact/hooks";
import { a3 as createLogger, c as useLegalEntity } from "./StoreProvider-CqQrndhS.js";
const logger = createLogger();
function useAssociatedLegalEntity(parentLegalEntity, associationType) {
  const matchingAssociation = useMemo(() => {
    if (!parentLegalEntity) return void 0;
    const typesToFind = Array.isArray(associationType) ? associationType : [associationType];
    const matchingAssociations = parentLegalEntity.entityAssociations?.filter((entity) => typesToFind.includes(entity.type)) ?? [];
    if (matchingAssociations.length > 1) {
      logger.warn(
        `Multiple matching associations found for types: ${typesToFind.join(", ")} - returning the first.
        ${matchingAssociations.map((ass) => JSON.stringify(ass, null, 2)).join("\n")}`
      );
    }
    return matchingAssociations[0];
  }, [parentLegalEntity, associationType]);
  const { data, refetch, isLoading } = useLegalEntity(
    matchingAssociation?.legalEntityId ?? skipToken
  );
  return { data, refetch, isLoading };
}
export {
  useAssociatedLegalEntity as u
};
