;
{
  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] = "28d72324-918b-47cf-9b18-c8d533894d16", e._sentryDebugIdIdentifier = "sentry-dbid-28d72324-918b-47cf-9b18-c8d533894d16");
  } catch (e) {
  }
}
;
function getTrustedFields(rootLegalEntity, apiMapping, provider) {
  const apiTrustedFields = getApiTrustedFields(rootLegalEntity);
  return parseTrustedFieldsIntoReadOnlyFields(apiTrustedFields, apiMapping);
}
function getTrustedEntityAssociations(rootLegalEntity, provider) {
  const apiTrustedFields = getApiTrustedFields(rootLegalEntity);
  return parseTrustedEntityAssociationsFromApiFields(apiTrustedFields);
}
function getTrustedFieldsProvider(rootLegalEntity) {
  return rootLegalEntity.trustedFields?.[0].provider;
}
const getApiTrustedFields = (rootLegalEntity, provider) => rootLegalEntity.trustedFields?.find((tf) => true)?.fields ?? [];
function parseTrustedFieldsIntoReadOnlyFields(trustedFields, mapping) {
  const formFieldsMapped = [];
  trustedFields.forEach((field) => {
    for (const [key, value] of Object.entries(mapping)) {
      if (value === field) {
        formFieldsMapped.push(key);
      }
    }
  });
  const readOnlyFields = {};
  formFieldsMapped.forEach((field) => {
    const tokenizedField = field.split(".");
    const formField = tokenizedField.pop();
    const formId = tokenizedField.pop();
    if (formField && formId) {
      if (formId in readOnlyFields) {
        readOnlyFields[formId].push(formField);
      } else {
        readOnlyFields[formId] = [formField];
      }
    }
  });
  return readOnlyFields;
}
function parseTrustedEntityAssociationsFromApiFields(trustedApiFields) {
  const rawTrustedEntityAssociations = trustedApiFields.filter((f) => f.startsWith("entityAssociations")) ?? [];
  const leIdMap = {};
  rawTrustedEntityAssociations.forEach((rtea) => {
    const [_, role, leId] = rtea.split(".");
    const trustedRole = role;
    if (!leIdMap[leId]) {
      leIdMap[leId] = { roles: [trustedRole] };
    } else {
      leIdMap[leId] = { roles: [...leIdMap[leId].roles, trustedRole] };
    }
  });
  return Object.keys(leIdMap).map((reference) => ({ reference, types: leIdMap[reference].roles }));
}
export {
  getTrustedEntityAssociations as a,
  getTrustedFields as b,
  getTrustedFieldsProvider as g
};
