const genderTranslationKeys = {
  female: "genders.female",
  male: "genders.male",
  other: "genders.not_informed",
  prefer_not_to_say: "genders.not_informed",
};

export const getProviderGenderLabel = (provider, translate) => {
  const providerData =
    provider?.provider ?? provider?.user?.provider ?? provider ?? {};
  const genderLabel =
    providerData.gender_label ?? provider?.provider_gender_label;
  const gender = providerData.gender ?? provider?.provider_gender;

  if (!gender && !genderLabel) return "";

  const translatedGender =
    typeof translate === "function" && genderTranslationKeys[gender]
      ? translate(genderTranslationKeys[gender])
      : genderLabel || gender;

  if (typeof translate !== "function") return translatedGender;

  return translate("common.terms.gender") + ": " + translatedGender;
};
