;
{
  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] = "0dd2b0fc-4ada-4dcc-999a-923f09b3fd35", e._sentryDebugIdIdentifier = "sentry-dbid-0dd2b0fc-4ada-4dcc-999a-923f09b3fd35");
  } catch (e) {
  }
}
;
import { g as getDataByFields } from "./utils-BFoyf7ch.js";
import { a2 as translateStringOrObject, ac as entriesOf } from "./StoreProvider-CqQrndhS.js";
const createFormUtils = (props, t) => ({
  getLabel: (field, fallbackLabelKey) => {
    let translationKey = props.labels?.[field] ?? fallbackLabelKey ?? field;
    if (props.labels && !props.labels?.[field] && Object.keys(props.labels).length) {
      const parentKey = Object.keys(props.labels).find(
        (fieldKey) => typeof props.labels?.[fieldKey] === "object"
      );
      if (parentKey) {
        const nestedLabel = props.labels[parentKey][field];
        translationKey = nestedLabel ?? translationKey;
      }
    }
    return t(($) => $[translationKey]);
  },
  getGuidanceText: (field, fallbackGuidanceTextKey) => {
    const translatable = fallbackGuidanceTextKey ? props.guidanceText?.[field] ?? fallbackGuidanceTextKey : props.guidanceText?.[field];
    return translatable ? translateStringOrObject(t, translatable) : void 0;
  },
  getMask: (field) => props.masks?.[field],
  isRequiredField: (field, showIfNotInRequiredFields = true) => props.requiredFields ? props.requiredFields.includes(field) && (field !== "role" || field === "role" && props.taskType !== "individual") : showIfNotInRequiredFields,
  isOptionalField: (field) => props.optionalFields?.includes(field) ?? false,
  isVisibleField(field, showIfNotInRequiredFields = true) {
    return this.isRequiredField(field, showIfNotInRequiredFields) || this.isOptionalField(field);
  },
  isReadOnly: (field) => props.readOnly || (props.readOnlyFields ? props.readOnlyFields.includes(field) : false),
  isObscured: (field) => props.obscuredFields ? props.obscuredFields.includes(field) : false,
  isTrusted: (field) => props.trustedFields ? props.trustedFields.includes(field) : false,
  getErrorMessage: (field, errors, fieldProblems) => {
    const errorMessage = errors?.[field]?.errorMessage;
    return errorMessage || Boolean(fieldProblems?.[field]);
  },
  getFieldData: (formData, fieldKeys) => getDataByFields(formData, fieldKeys),
  getFieldValid: (formValid, fieldKeys) => entriesOf(formValid).reduce(
    (acc, [key, val]) => fieldKeys.includes(key) ? { ...acc, [key]: val } : acc,
    {}
  ),
  getFieldErrors: (formErrors, fieldProblems, fieldKeys) => Object.keys(formErrors).reduce(
    (acc, key) => {
      if (fieldKeys.includes(key)) {
        const error = formErrors?.[key]?.errorMessage;
        return error ? { ...acc, [key]: error } : { ...acc, [key]: Boolean(fieldProblems?.[key]) };
      }
      return acc;
    },
    {}
  ),
  getFieldLabels: (fieldKeys, fallbackLabelKeys) => fieldKeys.reduce(
    (acc, field) => {
      let translationKey = props.labels?.[field] ?? fallbackLabelKeys?.[field] ?? field;
      if (props.labels && !props.labels?.[field] && Object.keys(props.labels).length) {
        const parentKey = Object.keys(props.labels).find(
          (fieldKey) => typeof props.labels?.[fieldKey] === "object"
        );
        if (parentKey) {
          const nestedLabel = props.labels[parentKey][field];
          translationKey = nestedLabel ?? translationKey;
        }
      }
      return { ...acc, [field]: t(($) => $[translationKey]) };
    },
    {}
  ),
  getFieldGuidanceText: (fieldKeys, fallbackGuidanceTextKeys) => fieldKeys.reduce(
    (acc, field) => {
      const translatable = fallbackGuidanceTextKeys?.[field] ? props.guidanceText?.[field] ?? fallbackGuidanceTextKeys?.[field] : props.guidanceText?.[field];
      return translatable ? { ...acc, [field]: translateStringOrObject(t, translatable) } : acc;
    },
    {}
  )
});
const mergeFieldMetadataIntoProps = (fieldName, metadata, otherProps) => {
  const existingProps = otherProps ?? {};
  return {
    ...existingProps,
    labels: {
      ...existingProps.labels,
      [fieldName]: metadata.label
    },
    guidanceText: {
      ...existingProps.guidanceText,
      [fieldName]: metadata.guidanceText
    },
    masks: {
      ...existingProps.masks,
      [fieldName]: metadata.mask
    },
    validators: {
      ...existingProps.validators,
      [fieldName]: metadata.validators
    }
  };
};
export {
  createFormUtils as c,
  mergeFieldMetadataIntoProps as m
};
