"use client";

import {
  type CompleteDetailsValues,
  type SocialUserData,
} from "./completeDetailsTypes";
import { useTranslation } from "react-i18next";
import PhoneInput from "@/components/ui/PhoneInput";
import SelectInput from "@/components/ui/SelectInput";
import {
  CountryCodeSelect,
  } from "./completeDetailsTypes";
import type { NicknameAvailability } from "@/features/shared/nicknameAvailability";

/**
 * The completion form's field grid.
 *
 * One column when a volunteer is joining a team — that path asks for fewer
 * details — and two otherwise.
 */
export default function CompleteDetailsFields({
  isVolunteerTeamJoin,
  visibleOrgTypeOptions,
  orgTypeLoading,
  setFieldValue,
  values,
}: {
  isVolunteerTeamJoin: boolean;
  userData: SocialUserData | null;
  visibleOrgTypeOptions: { label: string; value: string }[];
  orgTypeLoading: boolean;
  nicknameAvailability: NicknameAvailability;
  checkNicknameAvailability: (nickname: string) => void;
  setFieldValue: (field: string, value: unknown) => void;
  values: CompleteDetailsValues;
}) {
  const { t } = useTranslation();

  return (
  <div
    className={`grid ${
      isVolunteerTeamJoin ? "grid-cols-1" : "grid-cols-2"
    } mobilescreen:grid-cols-1 mobilescreen:gap-0 gap-6 xs:block selectfiled`}
  >
    {!isVolunteerTeamJoin && (
      <SelectInput
        name="organizer_type"
        label={t("COMMON.ORGANIZER.TYPE")}
        options={visibleOrgTypeOptions}
        onChange={(selectedOption) =>
          setFieldValue(
            "organizer_type",
            String(selectedOption?.value ?? "")
          )
        }
        disabled={orgTypeLoading}
      />
    )}
    <div className="flex gap-2">
      <div>
        <CountryCodeSelect
          name="country_code"
          className="w-full"
          onChange={(value: string) =>
            setFieldValue("country_code", value)
          }
        />
      </div>
      <div className="w-full">
        <PhoneInput
          name="phone_number"
          label={t("COMMON.ENTER_PHONE_NUMBER")}
          className="w-full"
          countryCode={values.country_code}
        />
      </div>
    </div>
  </div>
  );
}
