
/**
 *   WARNING: This file is intended to be used within MySheerID.
 *   This file is not intended for use in other contexts and there are no guarantees about its behavior outside of MySheerID.
 */ 
/**
 *   VERSION: 2.239.0-alpha.0
 *   BUILD_TIMESTAMP: 1780013005605
 *   BUILD_DATE: Fri May 29 2026 00:03:25 GMT+0000 (Coordinated Universal Time)
 *   BUILD_COMMIT: 3344b6c0fd9fa858907db310cfb1ef5e0d224da2
 */
import { V as b, l as T, m as k, n as A, o as L, R as c, p as F, q as O } from "../_mysheerid-preview.js";
async function $(l, e, o) {
  if (b[e]) {
    const i = T[e](o), r = await k(
      A(l, e),
      i
    );
    if (r.currentStep === "error")
      throw new Error(`Failed to determine fields to collect: ${r}`);
    return r;
  }
  throw new Error(`Unknown step ${e}`);
}
const f = (l, e) => l.length === e.length && l.every((o, i) => o.key === e[i].key), U = ({
  verificationId: l,
  currentStep: e,
  viewModel: o,
  defaultRequiredFields: i = []
}) => {
  const r = L(), p = "status" in o ? o.status : void 0, [y, g] = c.useState(i), [h, C] = c.useState([]), [m, q] = c.useState(
    void 0
  ), S = (n) => y.some((s) => s.key === n), w = (n) => h.some((s) => s.key === n);
  return c.useEffect(() => {
    const n = new AbortController();
    return (async () => {
      try {
        const s = await $(
          l,
          e,
          o
        ), d = F(() => s.fieldsToCollect.required, []), u = F(() => s.fieldsToCollect.optional, []);
        n.signal.aborted || (g(
          (t) => f(t, d) ? t : d
        ), C(
          (t) => f(t, u) ? t : u
        ), q((t) => {
          const a = s.availableStatuses;
          return t && a && t.length === a.length && t.every((E, R) => E === a[R]) ? t : a;
        }), r({
          type: "COLLECT_FIELDS",
          requiredFields: d,
          optionalFields: u
        }));
      } catch (s) {
        O.error(`Failed to determine fields to collect: ${s}`, e);
      }
    })(), () => {
      n.abort();
    };
  }, [o.countryChoice?.value, p]), { isFieldRequired: S, isFieldOptional: w, availableStatuses: m };
};
export {
  U as u
};
