
/**
 *   VERSION: 2.239.0-alpha.0
 *   BUILD_TIMESTAMP: 1780012993002
 *   BUILD_DATE: Fri May 29 2026 00:03:13 GMT+0000 (Coordinated Universal Time)
 *   BUILD_COMMIT: 3344b6c0fd9fa858907db310cfb1ef5e0d224da2
 */
import { V as b, o as T, p as k, q as A, t as L, R as c, v as F, l as O } from "../sheerid.js";
async function $(l, e, o) {
  if (b[e]) {
    const n = T[e](o), r = await k(
      A(l, e),
      n
    );
    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, n) => o.key === e[n].key), U = ({
  verificationId: l,
  currentStep: e,
  viewModel: o,
  defaultRequiredFields: n = []
}) => {
  const r = L(), p = "status" in o ? o.status : void 0, [y, g] = c.useState(n), [h, C] = c.useState([]), [q, S] = c.useState(
    void 0
  ), m = (i) => y.some((s) => s.key === i), w = (i) => h.some((s) => s.key === i);
  return c.useEffect(() => {
    const i = new AbortController();
    return (async () => {
      try {
        const s = await $(
          l,
          e,
          o
        ), d = F(() => s.fieldsToCollect.required, []), u = F(() => s.fieldsToCollect.optional, []);
        i.signal.aborted || (g(
          (t) => f(t, d) ? t : d
        ), C(
          (t) => f(t, u) ? t : u
        ), S((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);
      }
    })(), () => {
      i.abort();
    };
  }, [o.countryChoice?.value, p]), { isFieldRequired: m, isFieldOptional: w, availableStatuses: q };
};
export {
  U as u
};
