"use client";

import React from "react";
import { useTranslation } from "react-i18next";
import BirthDateField from "@/components/ui/BirthDateField";
import SelectInput from "@/components/ui/SelectInput";
import type { FormikProps } from "formik";
import type { IndividualRegistrationValues } from "./individualRegistrationValues";
import type { SelectInputOption } from "@/components/ui/SelectInput";

/** A field group lifted out of the form of the same family. */
export default function IndividualDobGenderFields({
  setFieldValue,
  maxBirthDate,
  genderOptions,
  genderLoading,
}: {
  setFieldValue: FormikProps<IndividualRegistrationValues>["setFieldValue"];
  maxBirthDate: Date;
  /* Numeric: these come straight from `/choices/`, whose ids are integers. */
  genderOptions: SelectInputOption<number>[];
  genderLoading: boolean;
}) {
  const { t } = useTranslation();

  return (
  <div className="gap-5 mobilescreen:gap-0 grid grid-cols-2 mobilescreen:grid-cols-1 selectfiled">
    <BirthDateField
      name="dob"
      label={t("COMMON.DATE_OF_BIRTH")}
      maxDate={maxBirthDate}
    />
    <SelectInput
      name="gender"
      label={t("COMMON.GENDERPLACEHOLDER")}
      options={genderOptions}
      onChange={(selectedOption) =>
        setFieldValue("gender", selectedOption?.value || "")
      }
      disabled={genderLoading}
    />
  </div>
  );
}
