"use client";

import { useTranslation } from "react-i18next";
import ModalInput from "@/components/ui/ModalInput";
import SelectInput from "@/components/ui/SelectInput";
import {
  FIELD_LABEL_CLASS,
} from "./registerVolunteerParts";
import type { SelectInputOption } from "@/components/ui/SelectInput";

/** A field group lifted out of the form of the same family. */
export default function RegisterVolunteerEmergencyFields({
  setFieldValue,
  relationshipOptions,
  relationshipLoading,
}: {
  setFieldValue: (field: string, value: unknown) => void;
  /* Numeric: these come straight from `/choices/`, whose ids are integers. */
  relationshipOptions: SelectInputOption<number>[];
  relationshipLoading: boolean;
}) {
  const { t } = useTranslation();

  return (
  <div className="grid grid-cols-2 mobilescreen:grid-cols-1 mobilescreen:gap-[0px] gap-[100px]">
    <div>
      <p className={FIELD_LABEL_CLASS}>
        {t("COMMON.EMERGENCY_CONTACT_NAME")}
      </p>
      <ModalInput
        name="emergency_contact_name"
        type="text"
        placeholder={t("COMMON.EMERGENCY_CONTACT_NAME")}
        lettersOnly
      />
    </div>
    <div>
      <p className={FIELD_LABEL_CLASS}>
        {t("COMMON.EMERGENCY_CONTACT_RELATIONSHIP")}
      </p>
      <SelectInput
        name="emergency_contact_relationship"
        label={t("COMMON.EMERGENCY_CONTACT_RELATIONSHIP")}
        options={relationshipOptions}
        onChange={(selectedOption) =>
          setFieldValue(
            "emergency_contact_relationship",
            selectedOption?.value || ""
          )
        }
        disabled={relationshipLoading}
      />
    </div>
  </div>
  );
}
