// Metro module 11382 (f11383). import { createRef, useEffect } from "react"; import Module38 from "../../../_bundle/Module38"; import useInitialValue from "../../../hooks/useInitialValue"; import { $forInKeys } from "../../../_hermes/prelude"; function $mk87080($env) { return () => { let r18; const r6 = $env; const validState = r6[0].validState; const { refsByKey, keyOrder } = validState; let r10 = void 0; const r13 = $forInKeys(refsByKey); let r1 = 0; const length = r13.length; if (r13 !== void 0) { do { r10 = void 0; const r11 = r1 < length ? r13[r1++] : void 0; if (r11 === void 0) { break; } const r15 = refsByKey[r11]; const r4 = r15 == null; r18 = void 0; if (!r4) { const current = r15.current; r18 = current == null ? void 0 : current.isFocused(); } r10 = r11; } while (r18 !== true); } L14: { if (r10 != null) { const r22 = keyOrder.indexOf(r10); if (r22 !== -1 && !(r22 >= keyOrder.length - 1)) { const r32 = refsByKey[r6[0].validState.keyOrder[r22 + 1]]; if (r32 == null) { break L14; } const current2 = r32.current; if (current2 == null) { break L14; } current2.focus(); break L14; } const r36 = r6[0]; const onAddAnswer2 = r36.onAddAnswer; if (onAddAnswer2 != null) { onAddAnswer2.call(r36); } } } }; } function $mk87081($env) { return (a0) => { const r6 = $env[0].validState.refsByKey[a0]; if (r6 != null) { const current = r6.current; if (current != null) { current.focus(); } } }; } class FocusHelperState { constructor() { const r3 = { __proto__: new.target.prototype, refsByKey: {}, keyOrder: null }; r3.keyOrder = []; return r3; } } class FocusHelperImpl { constructor() { let env18793; const r1 = env18793 = {}; env18793[0] = this; const validState = { __proto__: FocusHelperState.prototype, refsByKey: {}, keyOrder: null }; validState.keyOrder = []; this.validState = validState; this.focusNext = $mk87080(r1); this.focus = $mk87081(r1); } restartState() { const pendingState = { __proto__: FocusHelperState.prototype, refsByKey: {}, keyOrder: null }; pendingState.keyOrder = []; this.pendingState = pendingState; } commitState() { const pendingState = this.pendingState; if (pendingState != null) { this.validState = pendingState; } this.pendingState = void 0; } refWithKey(a0) { const pendingState = this.pendingState; Module38(pendingState != null, "Called refWithKey without a valid state"); pendingState.keyOrder.push(a0); const r17 = pendingState.refsByKey[a0]; if (r17 != null) { return r17; } const ref = createRef(); pendingState.refsByKey[a0] = ref; return ref; } } export default function useFocusHelper(r1 = {}) { let c18794_1; const onAddAnswer = r1.onAddAnswer; c18794_1 = void 0; const initialValue = useInitialValue(() => { let env27051; const r7 = { __proto__: FocusHelperImpl.prototype }; const r8 = env27051 = {}; env27051[0] = r7; const validState = { __proto__: FocusHelperState.prototype, refsByKey: {}, keyOrder: null }; validState.keyOrder = []; r7.validState = validState; r7.focusNext = $mk87080(r8); r7.focus = $mk87081(r8); return r7; }); c18794_1 = initialValue; initialValue.restartState(); useEffect(() => { c18794_1.onAddAnswer = onAddAnswer; c18794_1.commitState(); }); return initialValue; };