
/**
 *   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.240.0-alpha.1
 *   BUILD_TIMESTAMP: 1780360182346
 *   BUILD_DATE: Tue Jun 02 2026 00:29:42 GMT+0000 (Coordinated Universal Time)
 *   BUILD_COMMIT: 758cedd37e00f49a728d704d9ed36884f0f12d79
 */
import { V as L, n as D, o as O, p as x, q as I, R as c, t as y, m as U } from "../_mysheerid-preview.js";
async function V(l, t, e) {
  if (L[t]) {
    const a = D[t](e), n = await O(
      x(l, t),
      a
    );
    if (n.currentStep === "error")
      throw new Error(`Failed to determine fields to collect: ${n}`);
    return n;
  }
  throw new Error(`Unknown step ${t}`);
}
const p = (l, t) => l.length === t.length && l.every((e, a) => e.key === t[a].key), v = ({
  verificationId: l,
  currentStep: t,
  viewModel: e,
  defaultRequiredFields: a = []
}) => {
  const n = I(), g = "status" in e ? e.status : void 0, [h, A] = c.useState(a), [C, m] = c.useState([]), [q, T] = c.useState(
    void 0
  ), E = (i) => h.some((s) => s.key === i), b = (i) => C.some((s) => s.key === i);
  return c.useEffect(() => {
    const i = new AbortController();
    return (async () => {
      try {
        const s = await V(
          l,
          t,
          e
        ), u = y(() => s.fieldsToCollect.required, []), d = y(() => s.fieldsToCollect.optional, []);
        if (!i.signal.aborted) {
          A(
            (o) => p(o, u) ? o : u
          ), m(
            (o) => p(o, d) ? o : d
          ), T((o) => {
            const r = s.availableStatuses;
            return o && r && o.length === r.length && o.every((R, k) => R === r[k]) ? o : r;
          }), n({
            type: "COLLECT_FIELDS",
            requiredFields: u,
            optionalFields: d
          });
          const F = e.statuses, w = e.status, f = Array.isArray(F) && F.length > 0 ? F[0] : w, S = s.availableStatuses;
          f && S && S.length > 0 && !S.includes(f) && n({ type: "STATUS_INVALIDATED" });
        }
      } catch (s) {
        U.error(`Failed to determine fields to collect: ${s}`, t);
      }
    })(), () => {
      i.abort();
    };
  }, [e.countryChoice?.value, g]), { isFieldRequired: E, isFieldOptional: b, availableStatuses: q };
};
export {
  v as u
};
