import type { TableColumn } from "@/components/ui/Table";
import { shouldShowEmergencyContact } from "@/features/opportunities/registrationEmergencyContact";
import { type EmergencyContactSource } from "@/features/opportunities/registrationEmergencyContact";

/**
 * The four guardian columns, present only when at least one loaded row needs
 * them.
 *
 * Both registration lists had this block written out in full — same four keys,
 * same `type: "emergency"`, same `.some(...)` condition — so a fifth field or a
 * renamed key had to be remembered twice.
 *
 * The condition is per *list*: the columns exist because some row is a
 * minor-at-registration. Each cell re-checks per row, so an adult's row still
 * renders a dash rather than another volunteer's contact details.
 */
export function emergencyContactColumns(
  t: (key: string) => string,
  rows: EmergencyContactSource[]
): TableColumn[] {
  if (!rows.some((row) => shouldShowEmergencyContact(row))) return [];
  return [
    {
      label: t("COMMON.EMERGENCY_CONTACT_NAME"),
      key: "emergency_contact_name",
      type: "emergency",
    },
    {
      label: t("COMMON.EMERGENCY_CONTACT_PHONE"),
      key: "emergency_contact_phone",
      type: "emergency",
    },
    {
      label: t("COMMON.EMERGENCY_CONTACT_CIVIL_ID"),
      key: "emergency_contact_civil_id",
      type: "emergency",
    },
    {
      label: t("COMMON.EMERGENCY_CONTACT_RELATIONSHIP"),
      key: "emergency_contact_relationship",
      type: "emergency",
    },
  ];
}
