defmodule TransportWeb.ErrorView do
  use TransportWeb, :view

  def render("500.html", assigns) do
    render(__MODULE__, "internal_server_error.html", assigns)
  end

  def render("503.html", assigns) do
    assigns = assigns |> Map.put(:status_message, dgettext("errors", "503: Service Unavailable"))
    # Using 400 template because it is quite generic
    render(__MODULE__, "400_family_errors.html", assigns)
  end

  def render("400.html", assigns) do
    assigns =
      assigns
      |> Map.put(:status_message, dgettext("errors", "400: Bad Request"))

    render(__MODULE__, "400_family_errors.html", assigns)
  end

  def render("401.html", assigns) do
    assigns = assigns |> Map.put(:status_message, dgettext("errors", "401: Unauthorized"))
    render(__MODULE__, "400_family_errors.html", assigns)
  end

  def render("404.html", %{status_message: _status_message} = assigns) do
    render(__MODULE__, "400_family_errors.html", assigns)
  end

  def render("404.html", assigns) do
    assigns = assigns |> Map.put(:status_message, dgettext("errors", "404: Page not available"))
    render(__MODULE__, "400_family_errors.html", assigns)
  end
end
