"use client";

import { useTranslation } from "react-i18next";
import Input from "@/components/ui/Input";
import PhoneInput from "@/components/ui/PhoneInput";
import CountryCodeSelect from "./volunteerMandateParts";
import type { FormikProps } from "formik";
import type { MandateFormValues } from "./volunteerMandateParts";

/**
 * The guardian's phone, shown only when the volunteer is under 18.
 *
 * The parent decides visibility — this renders unconditionally, so the
 * under-18 rule stays in one place.
 */
export default function MandateGuardianFields({
  values,
  setFieldValue,
}: {
  values: MandateFormValues;
  setFieldValue: FormikProps<MandateFormValues>["setFieldValue"];
}) {
  const { t } = useTranslation();

  return (
  <div className="grid grid-cols-2 mobilescreen:grid-cols-1 mobilescreen:gap-0 gap-6">
    <div className="flex gap-2">
      <div>
        <CountryCodeSelect
          name="emergency_contact_country_code"
          className="w-full"
          onChange={(value: string) =>
            setFieldValue(
              "emergency_contact_country_code",
              value
            )
          }
        />
      </div>
      <div className="w-full">
        <PhoneInput
          name="emergency_contact_phone"
          label={t("COMMON.EMERGENCY_CONTACT_PHONE")}
          className="w-full"
          countryCode={values.emergency_contact_country_code}
        />
      </div>
    </div>

    <Input
      name="emergency_contact_civil_id"
      type="text"
      label={t("COMMON.EMERGENCY_CONTACT_CIVIL_ID")}
      maxLength={12}
      digitsOnly
    />
  </div>
  );
}
