defmodule MvWeb.Translations.MemberFields do
  @moduledoc """
  Helper module to dynamically translate member field names.

  ## Features
  - Translates technical field names (atoms) to human-friendly localized text
  - Used primarily in the field visibility dropdown component

  ## Example

      iex> MvWeb.Translations.MemberFields.label(:first_name)
      "Vorname"  # when locale is "de"

      iex> MvWeb.Translations.MemberFields.label(:first_name)
      "First Name"  # when locale is "en"
  """
  use Gettext, backend: MvWeb.Gettext

  @spec label(atom()) :: String.t()
  def label(:first_name), do: gettext("First Name")
  def label(:last_name), do: gettext("Last Name")
  def label(:email), do: gettext("Email")
  def label(:join_date), do: gettext("Join Date")
  def label(:exit_date), do: gettext("Exit Date")
  def label(:notes), do: gettext("Notes")
  def label(:city), do: gettext("City")
  def label(:street), do: gettext("Street")
  def label(:house_number), do: gettext("House Number")
  def label(:postal_code), do: gettext("Postal Code")
  def label(:membership_fee_start_date), do: gettext("Membership Fee Start Date")
  def label(:membership_fee_status), do: gettext("Membership Fee Status")
  def label(:groups), do: gettext("Groups")

  # Fallback for unknown fields
  def label(field) do
    field
    |> to_string()
    |> String.replace("_", " ")
    |> String.split()
    |> Enum.map_join(" ", &String.capitalize/1)
  end
end
