type TranslateFn = (...args: any[]) => any;

function normalizeEnumValue(value?: string) {
  return (value || "").trim().toLowerCase();
}

export function isFamilyStatusActive(status?: string) {
  return normalizeEnumValue(status) === "active";
}

export function isFamilyRoleOwner(role?: string) {
  return normalizeEnumValue(role) === "owner";
}

export function isFamilyMemberStatusActive(status?: string) {
  return normalizeEnumValue(status) === "active";
}

export function getFamilyStatusLabel(t: TranslateFn, status?: string) {
  const normalized = normalizeEnumValue(status);
  if (!normalized) return "--";

  switch (normalized) {
    case "active":
      return t("statusActive", "Active");
    case "disabled":
      return t("familyDisabled", "Disabled");
    default:
      return status || "--";
  }
}

export function getFamilyRoleLabel(t: TranslateFn, role?: string) {
  const normalized = normalizeEnumValue(role);
  if (!normalized) return "--";

  switch (normalized) {
    case "owner":
      return t("owner", "Owner");
    case "member":
      return t("familyMember", "Member");
    default:
      return role || "--";
  }
}

export function getFamilyMemberStatusLabel(t: TranslateFn, status?: string) {
  const normalized = normalizeEnumValue(status);
  if (!normalized) return "--";

  switch (normalized) {
    case "active":
      return t("statusActive", "Active");
    case "left":
      return t("familyMemberLeft", "Left");
    case "removed":
      return t("familyMemberRemoved", "Removed");
    default:
      return status || "--";
  }
}

export function getFamilyJoinSourceLabel(t: TranslateFn, joinSource?: string) {
  const normalized = normalizeEnumValue(joinSource);
  if (!normalized) return "--";

  switch (normalized) {
    case "owner_init":
      return t("familyJoinSourceOwnerInit", "Owner Initialization");
    case "bind_email_with_verification":
      return t(
        "familyJoinSourceBindEmailWithVerification",
        "Bind Email With Verification"
      );
    default:
      return joinSource || "--";
  }
}
