defmodule WhoNeedHelpWeb.FormParams do
  @moduledoc false

  @live_view_unused_prefix "_unused_"

  def drop_unused_structured_fields(%{"structured_data" => data} = params)
      when is_map(data) do
    data =
      Map.reject(data, fn {key, _value} ->
        key
        |> to_string()
        |> String.starts_with?(@live_view_unused_prefix)
      end)

    Map.put(params, "structured_data", data)
  end

  def drop_unused_structured_fields(params), do: params
end
