import { StringUtils } from "@/utils/string.utils";
import React, { forwardRef, useImperativeHandle, useState } from "react";
import { View } from "react-native";
import FormInput from "../form/FormInput";
import Question, { QuestionChildProps } from "./Question";

export interface NameQuestionRef {
  getAnswer: () => string;
  isOk: () => boolean;
}

export default forwardRef<any, QuestionChildProps>(({ ...props }, ref) => {
  const [answer, setAnswer] = useState<string>();

  useImperativeHandle(ref, () => ({
    getAnswer: () => answer,
    isOk: () => !StringUtils.IsNullOrEnptyWhiteSpace(answer ?? ""),
  }));

  return (
    <Question question="Quel est votre nom ?" {...props} {...ref}>
      <View className="gap-4">
        <FormInput
          beforeIcon="user"
          placeholder="Ex: Michel"
          label={"Prénom"}
          value={answer}
          onChangeText={setAnswer}
        />
      </View>
    </Question>
  );
});
