import { useDomContext } from "@saasquatch/stencil-hooks";
import { useEffect, useState } from "@saasquatch/universal-hooks";
import { REGISTRATION_FORM_STATE_CONTEXT, } from "../sqm-portal-registration-form/useRegistrationFormState";
export function useCheckboxField(props) {
  var _a;
  const registrationFormState = useDomContext(REGISTRATION_FORM_STATE_CONTEXT);
  const [checked, setChecked] = useState(false);
  useEffect(() => {
    var _a, _b;
    if ((_a = registrationFormState === null || registrationFormState === void 0 ? void 0 : registrationFormState.initialData) === null || _a === void 0 ? void 0 : _a[props.checkboxName]) {
      setChecked(!!((_b = registrationFormState === null || registrationFormState === void 0 ? void 0 : registrationFormState.initialData) === null || _b === void 0 ? void 0 : _b[props.checkboxName]));
    }
  }, [(_a = registrationFormState === null || registrationFormState === void 0 ? void 0 : registrationFormState.initialData) === null || _a === void 0 ? void 0 : _a[props.checkboxName]]);
  return {
    states: {
      registrationFormState,
      checked,
    },
    callbacks: {
      setChecked,
    },
  };
}
