import { useState } from "@saasquatch/universal-hooks";
import { validateNewPassword } from "./passwordValidation";
import { useDomContext } from "@saasquatch/stencil-hooks";
import { REGISTRATION_FORM_STATE_CONTEXT, } from "../sqm-portal-registration-form/useRegistrationFormState";
export function usePasswordField(props) {
  const registrationFormState = useDomContext(REGISTRATION_FORM_STATE_CONTEXT);
  const [dynamicValidation, setDynamicValidation] = useState("");
  function onInput(input) {
    const validation = validateNewPassword(input.target.value, props);
    setDynamicValidation(validation);
  }
  return {
    states: {
      enableValidation: !props.disableValidation,
      dynamicValidation,
      registrationFormState,
      content: {
        fieldLabel: props.fieldLabel,
      },
    },
    callbacks: {
      onInput,
    },
  };
}
